From 02e138dca9c9fd79f47d352114b45b21dbb2b2ba Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Mon, 11 Dec 2023 12:38:45 +0530 Subject: fix(ext/node): basic vm.runInNewContext implementation (#21527) Simple implementation to support webpack (& Next.js): https://github.com/webpack/webpack/blob/87660921808566ef3b8796f8df61bd79fc026108/lib/javascript/JavascriptParser.js#L4329 --- runtime/snapshot.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'runtime') diff --git a/runtime/snapshot.rs b/runtime/snapshot.rs index c2e8b0df2..6a9fb4a2b 100644 --- a/runtime/snapshot.rs +++ b/runtime/snapshot.rs @@ -7,6 +7,7 @@ use crate::shared::runtime; use deno_cache::SqliteBackedCache; use deno_core::error::AnyError; use deno_core::snapshot_util::*; +use deno_core::v8; use deno_core::Extension; use deno_http::DefaultHttpPropertyExtractor; use std::path::Path; @@ -261,7 +262,13 @@ pub fn create_runtime_snapshot( startup_snapshot: None, extensions, compression_cb: None, - with_runtime_cb: None, + with_runtime_cb: Some(Box::new(|rt| { + let isolate = rt.v8_isolate(); + let scope = &mut v8::HandleScope::new(isolate); + + let ctx = v8::Context::new(scope); + assert_eq!(scope.add_context(ctx), deno_node::VM_CONTEXT_INDEX); + })), skip_op_registration: false, }); for path in output.files_loaded_during_snapshot { -- cgit v1.2.3