diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-12-11 12:38:45 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-11 07:08:45 +0000 |
commit | 02e138dca9c9fd79f47d352114b45b21dbb2b2ba (patch) | |
tree | 396fce46b544635ecec93a0c7592d570e48474cb /runtime/snapshot.rs | |
parent | 0bee37a5e24048cbf92c1b56efd0c65deaea1418 (diff) |
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
Diffstat (limited to 'runtime/snapshot.rs')
-rw-r--r-- | runtime/snapshot.rs | 9 |
1 files changed, 8 insertions, 1 deletions
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 { |