diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/bindings.rs | 46 | ||||
-rw-r--r-- | core/runtime.rs | 23 |
2 files changed, 40 insertions, 29 deletions
diff --git a/core/bindings.rs b/core/bindings.rs index 5650b78f3..95e78b6cd 100644 --- a/core/bindings.rs +++ b/core/bindings.rs @@ -160,30 +160,41 @@ pub(crate) fn initialize_context<'s>( if matches!(snapshot_options, SnapshotOptions::Load) { // Only register ops that have `force_registration` flag set to true, - // the remaining ones should already be in the snapshot. - for op_ctx in op_ctxs - .iter() - .filter(|op_ctx| op_ctx.decl.force_registration) - { - add_op_to_deno_core_ops(scope, ops_obj, op_ctx); + // the remaining ones should already be in the snapshot. Ignore ops that + // are disabled. + for op_ctx in op_ctxs { + if op_ctx.decl.enabled { + if op_ctx.decl.force_registration { + add_op_to_deno_core_ops(scope, ops_obj, op_ctx); + } + } else { + delete_op_from_deno_core_ops(scope, ops_obj, op_ctx) + } } } else if matches!(snapshot_options, SnapshotOptions::CreateFromExisting) { - // Register all ops, probing for which ones are already registered. + // Register all enabled ops, probing for which ones are already registered. for op_ctx in op_ctxs { let key = v8::String::new_external_onebyte_static( scope, op_ctx.decl.name.as_bytes(), ) .unwrap(); - if ops_obj.get(scope, key.into()).is_some() { - continue; + + if op_ctx.decl.enabled { + if ops_obj.get(scope, key.into()).is_some() { + continue; + } + add_op_to_deno_core_ops(scope, ops_obj, op_ctx); + } else { + delete_op_from_deno_core_ops(scope, ops_obj, op_ctx) } - add_op_to_deno_core_ops(scope, ops_obj, op_ctx); } } else { - // In other cases register all ops unconditionally. + // In other cases register all ops enabled unconditionally. for op_ctx in op_ctxs { - add_op_to_deno_core_ops(scope, ops_obj, op_ctx); + if op_ctx.decl.enabled { + add_op_to_deno_core_ops(scope, ops_obj, op_ctx); + } } } @@ -203,6 +214,17 @@ fn set_func( obj.set(scope, key.into(), val.into()); } +fn delete_op_from_deno_core_ops( + scope: &mut v8::HandleScope<'_>, + obj: v8::Local<v8::Object>, + op_ctx: &OpCtx, +) { + let key = + v8::String::new_external_onebyte_static(scope, op_ctx.decl.name.as_bytes()) + .unwrap(); + obj.delete(scope, key.into()); +} + fn add_op_to_deno_core_ops( scope: &mut v8::HandleScope<'_>, obj: v8::Local<v8::Object>, diff --git a/core/runtime.rs b/core/runtime.rs index 27fd82496..923caaea9 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -15,8 +15,6 @@ use crate::modules::ModuleId; use crate::modules::ModuleLoadId; use crate::modules::ModuleLoader; use crate::modules::ModuleMap; -use crate::op_void_async; -use crate::op_void_sync; use crate::ops::*; use crate::realm::ContextState; use crate::realm::JsRealm; @@ -773,16 +771,6 @@ impl JsRuntime { name: d.name, ..macroware(d) }) - .map(|op| match op.enabled { - true => op, - false => OpDecl { - v8_fn_ptr: match op.is_async { - true => op_void_async::v8_fn_ptr as _, - false => op_void_sync::v8_fn_ptr as _, - }, - ..op - }, - }) .collect() } @@ -4223,11 +4211,12 @@ Deno.core.opAsync("op_async_serialize_object_with_numbers_as_keys", { extensions: vec![test_ext::init_ops()], ..Default::default() }); - let r = runtime + let err = runtime .execute_script_static("test.js", "Deno.core.ops.op_foo()") - .unwrap(); - let scope = &mut runtime.handle_scope(); - assert!(r.open(scope).is_undefined()); + .unwrap_err(); + assert!(err + .to_string() + .contains("TypeError: Deno.core.ops.op_foo is not a function")); } #[test] @@ -4327,7 +4316,7 @@ Deno.core.opAsync("op_async_serialize_object_with_numbers_as_keys", { if (Deno.core.ops.op_foo() !== 42) { throw new Error("Exptected op_foo() === 42"); } - if (Deno.core.ops.op_bar() !== undefined) { + if (typeof Deno.core.ops.op_bar !== "undefined") { throw new Error("Expected op_bar to be disabled") } "#, |