summaryrefslogtreecommitdiff
path: root/core/bindings.rs
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2022-11-07 17:39:48 -0800
committerGitHub <noreply@github.com>2022-11-08 02:39:48 +0100
commit3019c45f87c1825d10ab033e1c51832cafefd5b1 (patch)
tree37227c4f2a52192e11b6e5ad6103bd770a983041 /core/bindings.rs
parent0d52945d43601c6ca228d89f5b4f9cb0acb84794 (diff)
refactor: simplify deno_core's grab_global and ensure_objs (#16564)
- refactor: remove JsRuntime::ensure_objs - refactor: Replace JsRuntime::grab_global with JsRuntime::eval
Diffstat (limited to 'core/bindings.rs')
-rw-r--r--core/bindings.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/core/bindings.rs b/core/bindings.rs
index d7df613c5..82cce7102 100644
--- a/core/bindings.rs
+++ b/core/bindings.rs
@@ -110,7 +110,7 @@ pub fn initialize_context<'s>(
// extensions may provide ops that aren't part of the snapshot.
if snapshot_options.loaded() {
// Grab the Deno.core.ops object & init it
- let ops_obj = JsRuntime::grab_global::<v8::Object>(scope, "Deno.core.ops")
+ let ops_obj = JsRuntime::eval::<v8::Object>(scope, "Deno.core.ops")
.expect("Deno.core.ops to exist");
initialize_ops(scope, ops_obj, op_ctxs, snapshot_options);
if snapshot_options != SnapshotOptions::CreateFromExisting {
@@ -120,13 +120,22 @@ pub fn initialize_context<'s>(
}
// global.Deno = { core: { } };
- let core_val = JsRuntime::ensure_objs(scope, global, "Deno.core").unwrap();
+ let deno_obj = v8::Object::new(scope);
+ let deno_str = v8::String::new(scope, "Deno").unwrap();
+ global.set(scope, deno_str.into(), deno_obj.into());
+
+ let core_obj = v8::Object::new(scope);
+ let core_str = v8::String::new(scope, "core").unwrap();
+ deno_obj.set(scope, core_str.into(), core_obj.into());
// Bind functions to Deno.core.*
- set_func(scope, core_val, "callConsole", call_console);
+ set_func(scope, core_obj, "callConsole", call_console);
// Bind functions to Deno.core.ops.*
- let ops_obj = JsRuntime::ensure_objs(scope, global, "Deno.core.ops").unwrap();
+ let ops_obj = v8::Object::new(scope);
+ let ops_str = v8::String::new(scope, "ops").unwrap();
+ core_obj.set(scope, ops_str.into(), ops_obj.into());
+
if !snapshot_options.will_snapshot() {
initialize_async_ops_info(scope, ops_obj, op_ctxs);
}