diff options
Diffstat (limited to 'core/bindings.rs')
-rw-r--r-- | core/bindings.rs | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/core/bindings.rs b/core/bindings.rs index 1f35d1246..d91e4c309 100644 --- a/core/bindings.rs +++ b/core/bindings.rs @@ -15,10 +15,19 @@ use crate::modules::ImportAssertionsKind; use crate::modules::ModuleMap; use crate::modules::ResolutionKind; use crate::ops::OpCtx; -use crate::snapshot_util::SnapshotOptions; use crate::JsRealm; use crate::JsRuntime; +#[derive(Copy, Clone, Eq, PartialEq)] +pub(crate) enum BindingsMode { + /// We have no snapshot -- this is a pristine context. + New, + /// We have initialized before, are reloading a snapshot, and will snapshot. + Loaded, + /// We have initialized before, are reloading a snapshot, and will not snapshot again. + LoadedFinal, +} + pub(crate) fn external_references(ops: &[OpCtx]) -> v8::ExternalReferences { // Overallocate a bit, it's better than having to resize the vector. let mut references = Vec::with_capacity(4 + ops.len() * 4); @@ -118,7 +127,7 @@ pub(crate) fn initialize_context<'s>( scope: &mut v8::HandleScope<'s>, context: v8::Local<'s, v8::Context>, op_ctxs: &[OpCtx], - snapshot_options: SnapshotOptions, + bindings_mode: BindingsMode, ) -> v8::Local<'s, v8::Context> { let global = context.global(scope); @@ -128,13 +137,13 @@ pub(crate) fn initialize_context<'s>( codegen, "Deno.__op__ = function(opFns, callConsole, console) {{" ); - if !snapshot_options.loaded() { + if bindings_mode == BindingsMode::New { _ = writeln!(codegen, "Deno.__op__console(callConsole, console);"); } for op_ctx in op_ctxs { if op_ctx.decl.enabled { // If we're loading from a snapshot, we can skip registration for most ops - if matches!(snapshot_options, SnapshotOptions::Load) + if bindings_mode == BindingsMode::LoadedFinal && !op_ctx.decl.force_registration { continue; @@ -173,7 +182,7 @@ pub(crate) fn initialize_context<'s>( let op_fn = op_ctx_function(scope, op_ctx); op_fns.set_index(scope, op_ctx.id as u32, op_fn.into()); } - if snapshot_options.loaded() { + if bindings_mode != BindingsMode::New { op_fn.call(scope, recv.into(), &[op_fns.into()]); } else { // Bind functions to Deno.core.* @@ -284,7 +293,7 @@ pub fn host_import_module_dynamically_callback<'s>( let resolver_handle = v8::Global::new(scope, resolver); { - let state_rc = JsRuntime::state(scope); + let state_rc = JsRuntime::state_from(scope); let module_map_rc = JsRuntime::module_map_from(scope); debug!( @@ -484,7 +493,7 @@ pub extern "C" fn promise_reject_callback(message: v8::PromiseRejectMessage) { }; if has_unhandled_rejection_handler { - let state_rc = JsRuntime::state(tc_scope); + let state_rc = JsRuntime::state_from(tc_scope); let mut state = state_rc.borrow_mut(); if let Some(pending_mod_evaluate) = state.pending_mod_evaluate.as_mut() { if !pending_mod_evaluate.has_evaluated { |