From 5bcb46cacf9320bfa5088fbbda4f5a241cf9da1b Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 13 Jun 2024 09:19:33 +0530 Subject: [PATCH] chore(ext/node): remove old vm ops (#24187) Unused; before the recent rewrite of node:vm --- ext/node/lib.rs | 2 +- ext/node/ops/v8.rs | 48 ---------------------------------------------- ext/node/ops/vm.rs | 1 + 3 files changed, 2 insertions(+), 49 deletions(-) diff --git a/ext/node/lib.rs b/ext/node/lib.rs index 8a20b3109b..1fc5198a02 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -34,11 +34,11 @@ mod resolution; pub use ops::ipc::ChildPipeFd; pub use ops::ipc::IpcJsonStreamResource; -pub use ops::v8::VM_CONTEXT_INDEX; use ops::vm; pub use ops::vm::create_v8_context; pub use ops::vm::init_global_template; pub use ops::vm::ContextInitMode; +pub use ops::vm::VM_CONTEXT_INDEX; pub use package_json::PackageJson; pub use path::PathClean; pub use polyfill::is_builtin_node_module; diff --git a/ext/node/ops/v8.rs b/ext/node/ops/v8.rs index 207ea10e90..5520784f35 100644 --- a/ext/node/ops/v8.rs +++ b/ext/node/ops/v8.rs @@ -1,5 +1,4 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use deno_core::error::AnyError; use deno_core::op2; use deno_core::v8; @@ -31,50 +30,3 @@ pub fn op_v8_get_heap_statistics( buffer[12] = stats.used_global_handles_size() as f64; buffer[13] = stats.external_memory() as f64; } - -pub const VM_CONTEXT_INDEX: usize = 0; - -fn make_context<'a>( - scope: &mut v8::HandleScope<'a>, -) -> v8::Local<'a, v8::Context> { - let scope = &mut v8::EscapableHandleScope::new(scope); - let context = v8::Context::from_snapshot(scope, VM_CONTEXT_INDEX).unwrap(); - scope.escape(context) -} - -#[op2] -pub fn op_vm_run_in_new_context<'a>( - scope: &mut v8::HandleScope<'a>, - script: v8::Local, - ctx_val: v8::Local, -) -> Result, AnyError> { - let _ctx_obj = if ctx_val.is_undefined() || ctx_val.is_null() { - v8::Object::new(scope) - } else { - ctx_val.try_into()? - }; - - let ctx = make_context(scope); - - let scope = &mut v8::ContextScope::new(scope, ctx); - - let tc_scope = &mut v8::TryCatch::new(scope); - let script = match v8::Script::compile(tc_scope, script, None) { - Some(s) => s, - None => { - assert!(tc_scope.has_caught()); - tc_scope.rethrow(); - return Ok(v8::undefined(tc_scope).into()); - } - }; - - Ok(match script.run(tc_scope) { - Some(result) => result, - None => { - assert!(tc_scope.has_caught()); - tc_scope.rethrow(); - - v8::undefined(tc_scope).into() - } - }) -} diff --git a/ext/node/ops/vm.rs b/ext/node/ops/vm.rs index a0a63cc6e5..7b12b72b7f 100644 --- a/ext/node/ops/vm.rs +++ b/ext/node/ops/vm.rs @@ -10,6 +10,7 @@ use super::vm_internal as i; pub use i::create_v8_context; pub use i::init_global_template; pub use i::ContextInitMode; +pub use i::VM_CONTEXT_INDEX; pub use i::DEFINER_MAP_FN; pub use i::DELETER_MAP_FN;