summaryrefslogtreecommitdiff
path: root/core/bindings.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-04-21 15:22:45 +0200
committerGitHub <noreply@github.com>2023-04-21 15:22:45 +0200
commit1d447cb7c3295941be85a05b455f45d89e119667 (patch)
tree118635a7bcb8e75fbe067a16e351711f946ebd75 /core/bindings.rs
parent4e944dea1d6ad6cc819cbef278b59923eeaa2287 (diff)
refactor(core): remove ops from Deno.core.ops that are disabled (#18793)
This commit changes how "disabled" ops behave. Instead of using "void" functions under the hood, they now explicitly throw errors saying that a given op doesn't exist.
Diffstat (limited to 'core/bindings.rs')
-rw-r--r--core/bindings.rs46
1 files changed, 34 insertions, 12 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>,