Skip to content

Commit

Permalink
reuse vm snapshot context
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy committed May 24, 2024
1 parent 92a8d09 commit 22690cd
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions ext/node/ops/vm_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl ContextifyContext {
) {
let tmp = init_global_template(scope);

let context = create_v8_context(scope, tmp, None);
let context = create_v8_context(scope, tmp);
Self::from_context(scope, context, sandbox_obj);
}

Expand Down Expand Up @@ -175,17 +175,10 @@ pub const VM_CONTEXT_INDEX: usize = 0;

fn create_v8_context<'a>(
scope: &mut v8::HandleScope<'a>,
object_template: v8::Local<v8::ObjectTemplate>,
snapshot_data: Option<&'static [u8]>,
) -> v8::Local<'a, v8::Context> {
let scope = &mut v8::EscapableHandleScope::new(scope);

let context = if let Some(_snapshot_data) = snapshot_data {
v8::Context::from_snapshot(scope, VM_CONTEXT_INDEX).unwrap()
} else {
v8::Context::new_from_template(scope, object_template)
};

let context = v8::Context::from_snapshot(scope, VM_CONTEXT_INDEX)
.expect("Failed to create VM context from snapshot");
scope.escape(context)
}

Expand Down

0 comments on commit 22690cd

Please sign in to comment.