diff options
Diffstat (limited to 'core/ops_builtin_v8.rs')
-rw-r--r-- | core/ops_builtin_v8.rs | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/core/ops_builtin_v8.rs b/core/ops_builtin_v8.rs index 8629bbdbe..29ba4ec2b 100644 --- a/core/ops_builtin_v8.rs +++ b/core/ops_builtin_v8.rs @@ -8,7 +8,6 @@ use crate::ops_builtin::WasmStreamingResource; use crate::resolve_url_or_path; use crate::serde_v8::from_v8; use crate::source_map::apply_source_map as apply_source_map_; -use crate::JsRealm; use crate::JsRuntime; use crate::OpDecl; use crate::ZeroCopyBuf; @@ -74,14 +73,14 @@ fn to_v8_local_fn( #[op(v8)] fn op_ref_op(scope: &mut v8::HandleScope, promise_id: i32) { - let context_state = JsRealm::state_from_scope(scope); - context_state.borrow_mut().unrefed_ops.remove(&promise_id); + let state_rc = JsRuntime::state(scope); + state_rc.borrow_mut().unrefed_ops.remove(&promise_id); } #[op(v8)] fn op_unref_op(scope: &mut v8::HandleScope, promise_id: i32) { - let context_state = JsRealm::state_from_scope(scope); - context_state.borrow_mut().unrefed_ops.insert(promise_id); + let state_rc = JsRuntime::state(scope); + state_rc.borrow_mut().unrefed_ops.insert(promise_id); } #[op(v8)] @@ -112,8 +111,8 @@ fn op_set_promise_reject_callback<'a>( cb: serde_v8::Value, ) -> Result<Option<serde_v8::Value<'a>>, Error> { let cb = to_v8_fn(scope, cb)?; - let realm_state_rc = JsRealm::state_from_scope(scope); - let old = realm_state_rc.borrow_mut().js_promise_reject_cb.replace(cb); + let state_rc = JsRuntime::state(scope); + let old = state_rc.borrow_mut().js_promise_reject_cb.replace(cb); let old = old.map(|v| v8::Local::new(scope, v)); Ok(old.map(|v| from_v8(scope, v.into()).unwrap())) } @@ -675,28 +674,22 @@ fn op_set_wasm_streaming_callback( cb: serde_v8::Value, ) -> Result<(), Error> { let cb = to_v8_fn(scope, cb)?; - let realm_state_rc = JsRealm::state_from_scope(scope); - let mut realm_state = realm_state_rc.borrow_mut(); + let state_rc = JsRuntime::state(scope); + let mut state = state_rc.borrow_mut(); // The callback to pass to the v8 API has to be a unit type, so it can't // borrow or move any local variables. Therefore, we're storing the JS // callback in a JsRuntimeState slot. - if realm_state.js_wasm_streaming_cb.is_some() { + if state.js_wasm_streaming_cb.is_some() { return Err(type_error("op_set_wasm_streaming_callback already called")); } - realm_state.js_wasm_streaming_cb = Some(cb); + state.js_wasm_streaming_cb = Some(cb); scope.set_wasm_streaming_callback(|scope, arg, wasm_streaming| { let (cb_handle, streaming_rid) = { - let realm_state_rc = JsRealm::state_from_scope(scope); - let cb_handle = realm_state_rc - .borrow() - .js_wasm_streaming_cb - .as_ref() - .unwrap() - .clone(); let state_rc = JsRuntime::state(scope); - let streaming_rid = state_rc - .borrow() + let state = state_rc.borrow(); + let cb_handle = state.js_wasm_streaming_cb.as_ref().unwrap().clone(); + let streaming_rid = state .op_state .borrow_mut() .resource_table @@ -829,11 +822,8 @@ fn op_set_format_exception_callback<'a>( cb: serde_v8::Value<'a>, ) -> Result<Option<serde_v8::Value<'a>>, Error> { let cb = to_v8_fn(scope, cb)?; - let realm_state_rc = JsRealm::state_from_scope(scope); - let old = realm_state_rc - .borrow_mut() - .js_format_exception_cb - .replace(cb); + let state_rc = JsRuntime::state(scope); + let old = state_rc.borrow_mut().js_format_exception_cb.replace(cb); let old = old.map(|v| v8::Local::new(scope, v)); Ok(old.map(|v| from_v8(scope, v.into()).unwrap())) } |