diff options
Diffstat (limited to 'core/bindings.rs')
-rw-r--r-- | core/bindings.rs | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/core/bindings.rs b/core/bindings.rs index 2c879c21a..6e85a57d4 100644 --- a/core/bindings.rs +++ b/core/bindings.rs @@ -153,9 +153,6 @@ pub fn initialize_context<'s>( let scope = &mut v8::ContextScope::new(scope, context); - let deno_key = v8::String::new(scope, "Deno").unwrap(); - let core_key = v8::String::new(scope, "core").unwrap(); - let ops_key = v8::String::new(scope, "ops").unwrap(); // Snapshot already registered `Deno.core.ops` but // extensions may provide ops that aren't part of the snapshot. // @@ -164,30 +161,18 @@ pub fn initialize_context<'s>( // tsc ops are static at snapshot time. if snapshot_loaded { // Grab Deno.core.ops object - let deno_val = global.get(scope, deno_key.into()).unwrap(); - let deno_val = v8::Local::<v8::Object>::try_from(deno_val) - .expect("`Deno` not in global scope."); - let core_val = deno_val.get(scope, core_key.into()).unwrap(); - let core_val = v8::Local::<v8::Object>::try_from(core_val) - .expect("`Deno.core` not in global scope"); - let ops_val = core_val.get(scope, ops_key.into()).unwrap(); - let ops_val = v8::Local::<v8::Object>::try_from(ops_val) - .expect("`Deno.core.ops` not in global scope"); + let ops_obj = JsRuntime::grab_global::<v8::Object>(scope, "Deno.core.ops") + .expect("Deno.core.ops to exist"); let raw_op_state = Rc::as_ptr(&op_state) as *const c_void; for op in ops { - set_func_raw(scope, ops_val, op.name, op.v8_fn_ptr, raw_op_state); + set_func_raw(scope, ops_obj, op.name, op.v8_fn_ptr, raw_op_state); } return scope.escape(context); } - // global.Deno = { core: { ops: {} } }; - let deno_val = v8::Object::new(scope); - global.set(scope, deno_key.into(), deno_val.into()); - let core_val = v8::Object::new(scope); - deno_val.set(scope, core_key.into(), core_val.into()); - let ops_val = v8::Object::new(scope); - core_val.set(scope, ops_key.into(), ops_val.into()); + // global.Deno = { core: { } }; + let core_val = JsRuntime::ensure_objs(scope, global, "Deno.core").unwrap(); // Bind functions to Deno.core.* set_func(scope, core_val, "refOp_", ref_op); @@ -245,6 +230,7 @@ pub fn initialize_context<'s>( set_func(scope, global, "queueMicrotask", queue_microtask); // Bind functions to Deno.core.ops.* + let ops_val = JsRuntime::ensure_objs(scope, global, "Deno.core.ops").unwrap(); let raw_op_state = Rc::as_ptr(&op_state) as *const c_void; for op in ops { set_func_raw(scope, ops_val, op.name, op.v8_fn_ptr, raw_op_state); |