1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

refactor(core): remove force_op_registration and cleanup JsRuntimeForSnapshot (#19353)

Addresses
https://github.com/denoland/deno/pull/19308#discussion_r1212248194. 

Removes force_op_registration as it is no longer necessary.
This commit is contained in:
Nayeem Rahman 2023-06-03 21:22:32 +01:00 committed by GitHub
parent 7d0853d158
commit 34dac6c6ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
52 changed files with 161 additions and 402 deletions

View file

@ -3261,9 +3261,6 @@ deno_core::extension!(deno_tsc,
options.performance, options.performance,
)); ));
}, },
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
},
); );
/// Instruct a language server runtime to start the language server and provide /// Instruct a language server runtime to start the language server and provide

View file

@ -42,9 +42,6 @@ deno_core::extension!(deno_bench,
state.put(options.sender); state.put(options.sender);
state.put(BenchContainer::default()); state.put(BenchContainer::default());
}, },
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
},
); );
#[derive(Clone)] #[derive(Clone)]

View file

@ -23,9 +23,6 @@ deno_core::extension!(deno_cli,
state = |state, options| { state = |state, options| {
state.put(options.npm_resolver); state.put(options.npm_resolver);
}, },
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
},
); );
#[op] #[op]

View file

@ -43,9 +43,6 @@ deno_core::extension!(deno_test,
state.put(options.sender); state.put(options.sender);
state.put(TestContainer::default()); state.put(TestContainer::default());
}, },
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
},
); );
#[derive(Clone)] #[derive(Clone)]

View file

@ -117,13 +117,7 @@ pub fn get_types_declaration_file_text(unstable: bool) -> String {
} }
fn get_asset_texts_from_new_runtime() -> Result<Vec<AssetText>, AnyError> { fn get_asset_texts_from_new_runtime() -> Result<Vec<AssetText>, AnyError> {
deno_core::extension!( deno_core::extension!(deno_cli_tsc, ops_fn = deno_ops);
deno_cli_tsc,
ops_fn = deno_ops,
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
},
);
// the assets are stored within the typescript isolate, so take them out of there // the assets are stored within the typescript isolate, so take them out of there
let mut runtime = JsRuntime::new(RuntimeOptions { let mut runtime = JsRuntime::new(RuntimeOptions {
@ -780,9 +774,6 @@ pub fn exec(request: Request) -> Result<Response, AnyError> {
.unwrap(), .unwrap(),
)); ));
}, },
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
},
); );
let startup_source = ascii_str!("globalThis.startup({ legacyFlag: false })"); let startup_source = ascii_str!("globalThis.startup({ legacyFlag: false })");

View file

@ -15,19 +15,10 @@ use crate::modules::ImportAssertionsKind;
use crate::modules::ModuleMap; use crate::modules::ModuleMap;
use crate::modules::ResolutionKind; use crate::modules::ResolutionKind;
use crate::ops::OpCtx; use crate::ops::OpCtx;
use crate::runtime::InitMode;
use crate::JsRealm; use crate::JsRealm;
use crate::JsRuntime; 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 { pub(crate) fn external_references(ops: &[OpCtx]) -> v8::ExternalReferences {
// Overallocate a bit, it's better than having to resize the vector. // Overallocate a bit, it's better than having to resize the vector.
let mut references = Vec::with_capacity(4 + ops.len() * 4); let mut references = Vec::with_capacity(4 + ops.len() * 4);
@ -127,7 +118,7 @@ pub(crate) fn initialize_context<'s>(
scope: &mut v8::HandleScope<'s>, scope: &mut v8::HandleScope<'s>,
context: v8::Local<'s, v8::Context>, context: v8::Local<'s, v8::Context>,
op_ctxs: &[OpCtx], op_ctxs: &[OpCtx],
bindings_mode: BindingsMode, init_mode: InitMode,
) -> v8::Local<'s, v8::Context> { ) -> v8::Local<'s, v8::Context> {
let global = context.global(scope); let global = context.global(scope);
@ -137,17 +128,11 @@ pub(crate) fn initialize_context<'s>(
codegen, codegen,
"Deno.__op__ = function(opFns, callConsole, console) {{" "Deno.__op__ = function(opFns, callConsole, console) {{"
); );
if bindings_mode == BindingsMode::New { if init_mode == InitMode::New {
_ = writeln!(codegen, "Deno.__op__console(callConsole, console);"); _ = writeln!(codegen, "Deno.__op__console(callConsole, console);");
} }
for op_ctx in op_ctxs { for op_ctx in op_ctxs {
if op_ctx.decl.enabled { if op_ctx.decl.enabled {
// If we're loading from a snapshot, we can skip registration for most ops
if bindings_mode == BindingsMode::LoadedFinal
&& !op_ctx.decl.force_registration
{
continue;
}
_ = writeln!( _ = writeln!(
codegen, codegen,
"Deno.__op__registerOp({}, opFns[{}], \"{}\");", "Deno.__op__registerOp({}, opFns[{}], \"{}\");",
@ -182,7 +167,7 @@ pub(crate) fn initialize_context<'s>(
let op_fn = op_ctx_function(scope, op_ctx); let op_fn = op_ctx_function(scope, op_ctx);
op_fns.set_index(scope, op_ctx.id as u32, op_fn.into()); op_fns.set_index(scope, op_ctx.id as u32, op_fn.into());
} }
if bindings_mode != BindingsMode::New { if init_mode == InitMode::FromSnapshot {
op_fn.call(scope, recv.into(), &[op_fns.into()]); op_fn.call(scope, recv.into(), &[op_fns.into()]);
} else { } else {
// Bind functions to Deno.core.* // Bind functions to Deno.core.*

View file

@ -72,7 +72,6 @@ pub struct OpDecl {
pub is_async: bool, pub is_async: bool,
pub is_unstable: bool, pub is_unstable: bool,
pub is_v8: bool, pub is_v8: bool,
pub force_registration: bool,
pub arg_count: u8, pub arg_count: u8,
pub fast_fn: Option<FastFunction>, pub fast_fn: Option<FastFunction>,
} }
@ -360,7 +359,6 @@ pub struct Extension {
initialized: bool, initialized: bool,
enabled: bool, enabled: bool,
deps: Option<&'static [&'static str]>, deps: Option<&'static [&'static str]>,
force_op_registration: bool,
pub(crate) is_core: bool, pub(crate) is_core: bool,
} }
@ -431,7 +429,6 @@ impl Extension {
let mut ops = self.ops.take()?; let mut ops = self.ops.take()?;
for op in ops.iter_mut() { for op in ops.iter_mut() {
op.enabled = self.enabled && op.enabled; op.enabled = self.enabled && op.enabled;
op.force_registration = self.force_op_registration;
} }
Some(ops) Some(ops)
} }
@ -485,7 +482,6 @@ pub struct ExtensionBuilder {
event_loop_middleware: Option<Box<OpEventLoopFn>>, event_loop_middleware: Option<Box<OpEventLoopFn>>,
name: &'static str, name: &'static str,
deps: &'static [&'static str], deps: &'static [&'static str],
force_op_registration: bool,
is_core: bool, is_core: bool,
} }
@ -534,15 +530,6 @@ impl ExtensionBuilder {
self self
} }
/// Mark that ops from this extension should be added to `Deno.core.ops`
/// unconditionally. This is useful is some ops are not available
/// during snapshotting, as ops are not registered by default when a
/// `JsRuntime` is created with an existing snapshot.
pub fn force_op_registration(&mut self) -> &mut Self {
self.force_op_registration = true;
self
}
/// Consume the [`ExtensionBuilder`] and return an [`Extension`]. /// Consume the [`ExtensionBuilder`] and return an [`Extension`].
pub fn take(self) -> Extension { pub fn take(self) -> Extension {
let js_files = Some(self.js); let js_files = Some(self.js);
@ -560,7 +547,6 @@ impl ExtensionBuilder {
initialized: false, initialized: false,
enabled: true, enabled: true,
name: self.name, name: self.name,
force_op_registration: self.force_op_registration,
deps, deps,
is_core: self.is_core, is_core: self.is_core,
} }
@ -583,7 +569,6 @@ impl ExtensionBuilder {
enabled: true, enabled: true,
name: self.name, name: self.name,
deps, deps,
force_op_registration: self.force_op_registration,
is_core: self.is_core, is_core: self.is_core,
} }
} }

View file

@ -1,7 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use crate::bindings; use crate::bindings;
use crate::bindings::BindingsMode;
use crate::error::generic_error; use crate::error::generic_error;
use crate::error::to_v8_type_error; use crate::error::to_v8_type_error;
use crate::error::JsError; use crate::error::JsError;
@ -24,8 +23,6 @@ use crate::realm::ContextState;
use crate::realm::JsRealm; use crate::realm::JsRealm;
use crate::realm::JsRealmInner; use crate::realm::JsRealmInner;
use crate::snapshot_util; use crate::snapshot_util;
use crate::snapshot_util::SnapshotOptions;
use crate::snapshot_util::SnapshottedData;
use crate::source_map::SourceMapCache; use crate::source_map::SourceMapCache;
use crate::source_map::SourceMapGetter; use crate::source_map::SourceMapGetter;
use crate::Extension; use crate::Extension;
@ -63,7 +60,6 @@ use std::sync::Mutex;
use std::sync::Once; use std::sync::Once;
use std::task::Context; use std::task::Context;
use std::task::Poll; use std::task::Poll;
use v8::CreateParams;
const STATE_DATA_OFFSET: u32 = 0; const STATE_DATA_OFFSET: u32 = 0;
const MODULE_MAP_DATA_OFFSET: u32 = 1; const MODULE_MAP_DATA_OFFSET: u32 = 1;
@ -121,7 +117,7 @@ impl<T> DerefMut for ManuallyDropRc<T> {
/// This inner struct allows us to let the outer JsRuntime drop normally without a Drop impl, while we /// This inner struct allows us to let the outer JsRuntime drop normally without a Drop impl, while we
/// control dropping more closely here using ManuallyDrop. /// control dropping more closely here using ManuallyDrop.
struct InnerIsolateState { struct InnerIsolateState {
snapshotting: bool, will_snapshot: bool,
state: ManuallyDropRc<RefCell<JsRuntimeState>>, state: ManuallyDropRc<RefCell<JsRuntimeState>>,
v8_isolate: ManuallyDrop<v8::OwnedIsolate>, v8_isolate: ManuallyDrop<v8::OwnedIsolate>,
} }
@ -182,7 +178,7 @@ impl Drop for InnerIsolateState {
// SAFETY: We gotta drop these // SAFETY: We gotta drop these
unsafe { unsafe {
ManuallyDrop::drop(&mut self.state.0); ManuallyDrop::drop(&mut self.state.0);
if self.snapshotting { if self.will_snapshot {
// Create the snapshot and just drop it. // Create the snapshot and just drop it.
eprintln!("WARNING: v8::OwnedIsolate for snapshot was leaked"); eprintln!("WARNING: v8::OwnedIsolate for snapshot was leaked");
} else { } else {
@ -192,47 +188,46 @@ impl Drop for InnerIsolateState {
} }
} }
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub(crate) enum InitMode {
/// We have no snapshot -- this is a pristine context.
New,
/// We are using a snapshot, thus certain initialization steps are skipped.
FromSnapshot,
}
impl InitMode {
fn from_options(options: &RuntimeOptions) -> Self {
match options.startup_snapshot {
None => Self::New,
Some(_) => Self::FromSnapshot,
}
}
}
/// A single execution context of JavaScript. Corresponds roughly to the "Web /// A single execution context of JavaScript. Corresponds roughly to the "Web
/// Worker" concept in the DOM. /// Worker" concept in the DOM.
//// ////
/// The JsRuntimeImpl future completes when there is an error or when all /// The JsRuntime future completes when there is an error or when all
/// pending ops have completed. /// pending ops have completed.
/// ///
/// API consumers will want to use either the [`JsRuntime`] or [`JsRuntimeForSnapshot`] /// Use [`JsRuntimeForSnapshot`] to be able to create a snapshot.
/// type aliases. pub struct JsRuntime {
pub struct JsRuntimeImpl<const FOR_SNAPSHOT: bool = false> {
inner: InnerIsolateState, inner: InnerIsolateState,
module_map: Rc<RefCell<ModuleMap>>, module_map: Rc<RefCell<ModuleMap>>,
allocations: IsolateAllocations, allocations: IsolateAllocations,
extensions: Vec<Extension>, extensions: Vec<Extension>,
event_loop_middlewares: Vec<Box<OpEventLoopFn>>, event_loop_middlewares: Vec<Box<OpEventLoopFn>>,
bindings_mode: BindingsMode, init_mode: InitMode,
// Marks if this is considered the top-level runtime. Used only be inspector. // Marks if this is considered the top-level runtime. Used only be inspector.
is_main: bool, is_main: bool,
} }
/// The runtime type that most users will use when not creating a snapshot.
pub struct JsRuntime(JsRuntimeImpl<false>);
impl Deref for JsRuntime {
type Target = JsRuntimeImpl<false>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for JsRuntime {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
/// The runtime type used for snapshot creation. /// The runtime type used for snapshot creation.
pub struct JsRuntimeForSnapshot(JsRuntimeImpl<true>); pub struct JsRuntimeForSnapshot(JsRuntime);
impl Deref for JsRuntimeForSnapshot { impl Deref for JsRuntimeForSnapshot {
type Target = JsRuntimeImpl<true>; type Target = JsRuntime;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
&self.0 &self.0
@ -301,7 +296,7 @@ pub type SharedArrayBufferStore =
pub type CompiledWasmModuleStore = CrossIsolateStore<v8::CompiledWasmModule>; pub type CompiledWasmModuleStore = CrossIsolateStore<v8::CompiledWasmModule>;
/// Internal state for JsRuntimeImpl which is stored in one of v8::Isolate's /// Internal state for JsRuntime which is stored in one of v8::Isolate's
/// embedder slots. /// embedder slots.
pub struct JsRuntimeState { pub struct JsRuntimeState {
global_realm: Option<JsRealm>, global_realm: Option<JsRealm>,
@ -398,7 +393,7 @@ pub struct RuntimeOptions {
/// executed tries to load modules. /// executed tries to load modules.
pub module_loader: Option<Rc<dyn ModuleLoader>>, pub module_loader: Option<Rc<dyn ModuleLoader>>,
/// JsRuntimeImpl extensions, not to be confused with ES modules. /// JsRuntime extensions, not to be confused with ES modules.
/// Only ops registered by extensions will be initialized. If you need /// Only ops registered by extensions will be initialized. If you need
/// to execute JS code from extensions, pass source files in `js` or `esm` /// to execute JS code from extensions, pass source files in `js` or `esm`
/// option on `ExtensionBuilder`. /// option on `ExtensionBuilder`.
@ -448,21 +443,60 @@ pub struct RuntimeSnapshotOptions {
pub snapshot_module_load_cb: Option<ExtModuleLoaderCb>, pub snapshot_module_load_cb: Option<ExtModuleLoaderCb>,
} }
trait JsRuntimeInternalTrait { impl JsRuntime {
fn create_raw_isolate( /// Only constructor, configuration is done through `options`.
refs: &'static v8::ExternalReferences, pub fn new(mut options: RuntimeOptions) -> JsRuntime {
params: Option<CreateParams>, JsRuntime::init_v8(options.v8_platform.take(), cfg!(test));
snapshot: SnapshotOptions, JsRuntime::new_inner(options, false, None)
) -> v8::OwnedIsolate; }
}
impl<const FOR_SNAPSHOT: bool> JsRuntimeImpl<FOR_SNAPSHOT> { pub(crate) fn state_from(
fn init_v8(v8_platform: Option<v8::SharedRef<v8::Platform>>) { isolate: &v8::Isolate,
) -> Rc<RefCell<JsRuntimeState>> {
let state_ptr = isolate.get_data(STATE_DATA_OFFSET);
let state_rc =
// SAFETY: We are sure that it's a valid pointer for whole lifetime of
// the runtime.
unsafe { Rc::from_raw(state_ptr as *const RefCell<JsRuntimeState>) };
let state = state_rc.clone();
std::mem::forget(state_rc);
state
}
pub(crate) fn module_map_from(
isolate: &v8::Isolate,
) -> Rc<RefCell<ModuleMap>> {
let module_map_ptr = isolate.get_data(MODULE_MAP_DATA_OFFSET);
let module_map_rc =
// SAFETY: We are sure that it's a valid pointer for whole lifetime of
// the runtime.
unsafe { Rc::from_raw(module_map_ptr as *const RefCell<ModuleMap>) };
let module_map = module_map_rc.clone();
std::mem::forget(module_map_rc);
module_map
}
pub(crate) fn event_loop_pending_state_from_scope(
scope: &mut v8::HandleScope,
) -> EventLoopPendingState {
let state = JsRuntime::state_from(scope);
let module_map = JsRuntime::module_map_from(scope);
let state = EventLoopPendingState::new(
scope,
&mut state.borrow_mut(),
&module_map.borrow(),
);
state
}
fn init_v8(
v8_platform: Option<v8::SharedRef<v8::Platform>>,
predictable: bool,
) {
static DENO_INIT: Once = Once::new(); static DENO_INIT: Once = Once::new();
static DENO_PREDICTABLE: AtomicBool = AtomicBool::new(false); static DENO_PREDICTABLE: AtomicBool = AtomicBool::new(false);
static DENO_PREDICTABLE_SET: AtomicBool = AtomicBool::new(false); static DENO_PREDICTABLE_SET: AtomicBool = AtomicBool::new(false);
let predictable = FOR_SNAPSHOT || cfg!(test);
if DENO_PREDICTABLE_SET.load(Ordering::SeqCst) { if DENO_PREDICTABLE_SET.load(Ordering::SeqCst) {
let current = DENO_PREDICTABLE.load(Ordering::SeqCst); let current = DENO_PREDICTABLE.load(Ordering::SeqCst);
assert_eq!(current, predictable, "V8 may only be initialized once in either snapshotting or non-snapshotting mode. Either snapshotting or non-snapshotting mode may be used in a single process, not both."); assert_eq!(current, predictable, "V8 may only be initialized once in either snapshotting or non-snapshotting mode. Either snapshotting or non-snapshotting mode may be used in a single process, not both.");
@ -473,15 +507,13 @@ impl<const FOR_SNAPSHOT: bool> JsRuntimeImpl<FOR_SNAPSHOT> {
DENO_INIT.call_once(move || v8_init(v8_platform, predictable)); DENO_INIT.call_once(move || v8_init(v8_platform, predictable));
} }
fn new_runtime( fn new_inner(
mut options: RuntimeOptions, mut options: RuntimeOptions,
snapshot_options: SnapshotOptions, will_snapshot: bool,
maybe_load_callback: Option<ExtModuleLoaderCb>, maybe_load_callback: Option<ExtModuleLoaderCb>,
) -> JsRuntimeImpl<FOR_SNAPSHOT> ) -> JsRuntime {
where let init_mode = InitMode::from_options(&options);
JsRuntimeImpl<FOR_SNAPSHOT>: JsRuntimeInternalTrait, let (op_state, ops) = Self::create_opstate(&mut options, init_mode);
{
let (op_state, ops) = Self::create_opstate(&mut options, &snapshot_options);
let op_state = Rc::new(RefCell::new(op_state)); let op_state = Rc::new(RefCell::new(op_state));
// Collect event-loop middleware // Collect event-loop middleware
@ -546,19 +578,56 @@ impl<const FOR_SNAPSHOT: bool> JsRuntimeImpl<FOR_SNAPSHOT> {
// V8 takes ownership of external_references. // V8 takes ownership of external_references.
let refs: &'static v8::ExternalReferences = Box::leak(Box::new(refs)); let refs: &'static v8::ExternalReferences = Box::leak(Box::new(refs));
let bindings_mode = match snapshot_options { let mut isolate = if will_snapshot {
SnapshotOptions::None => bindings::BindingsMode::New, snapshot_util::create_snapshot_creator(
SnapshotOptions::Create => bindings::BindingsMode::New, refs,
SnapshotOptions::Load(_) => bindings::BindingsMode::LoadedFinal, options.startup_snapshot.take(),
SnapshotOptions::CreateFromExisting(_) => bindings::BindingsMode::Loaded, )
} else {
let mut params = options
.create_params
.take()
.unwrap_or_default()
.embedder_wrapper_type_info_offsets(
V8_WRAPPER_TYPE_INDEX,
V8_WRAPPER_OBJECT_INDEX,
)
.external_references(&**refs);
if let Some(snapshot) = options.startup_snapshot.take() {
params = match snapshot {
Snapshot::Static(data) => params.snapshot_blob(data),
Snapshot::JustCreated(data) => params.snapshot_blob(data),
Snapshot::Boxed(data) => params.snapshot_blob(data),
};
}
v8::Isolate::new(params)
}; };
let snapshotting = snapshot_options.will_snapshot(); isolate.set_capture_stack_trace_for_uncaught_exceptions(true, 10);
isolate.set_promise_reject_callback(bindings::promise_reject_callback);
let (mut isolate, global_context, snapshotted_data) = Self::create_isolate( isolate.set_host_initialize_import_meta_object_callback(
refs, bindings::host_initialize_import_meta_object_callback,
options.create_params.take(),
snapshot_options,
); );
isolate.set_host_import_module_dynamically_callback(
bindings::host_import_module_dynamically_callback,
);
isolate.set_wasm_async_resolve_promise_callback(
bindings::wasm_async_resolve_promise_callback,
);
let (global_context, snapshotted_data) = {
let scope = &mut v8::HandleScope::new(&mut isolate);
let context = v8::Context::new(scope);
// Get module map data from the snapshot
let snapshotted_data = if init_mode == InitMode::FromSnapshot {
Some(snapshot_util::get_snapshotted_data(scope, context))
} else {
None
};
(v8::Global::new(scope, context), snapshotted_data)
};
// SAFETY: this is first use of `isolate_ptr` so we are sure we're // SAFETY: this is first use of `isolate_ptr` so we are sure we're
// not overwriting an existing pointer. // not overwriting an existing pointer.
isolate = unsafe { isolate = unsafe {
@ -575,7 +644,7 @@ impl<const FOR_SNAPSHOT: bool> JsRuntimeImpl<FOR_SNAPSHOT> {
scope, scope,
context, context,
&context_state.borrow().op_ctxs, &context_state.borrow().op_ctxs,
bindings_mode, init_mode,
); );
context.set_slot(scope, context_state.clone()); context.set_slot(scope, context_state.clone());
@ -619,13 +688,13 @@ impl<const FOR_SNAPSHOT: bool> JsRuntimeImpl<FOR_SNAPSHOT> {
drop(context_scope); drop(context_scope);
let mut js_runtime = JsRuntimeImpl { let mut js_runtime = JsRuntime {
inner: InnerIsolateState { inner: InnerIsolateState {
snapshotting, will_snapshot,
state: ManuallyDropRc(ManuallyDrop::new(state_rc)), state: ManuallyDropRc(ManuallyDrop::new(state_rc)),
v8_isolate: ManuallyDrop::new(isolate), v8_isolate: ManuallyDrop::new(isolate),
}, },
bindings_mode, init_mode,
allocations: IsolateAllocations::default(), allocations: IsolateAllocations::default(),
event_loop_middlewares, event_loop_middlewares,
extensions: options.extensions, extensions: options.extensions,
@ -641,51 +710,6 @@ impl<const FOR_SNAPSHOT: bool> JsRuntimeImpl<FOR_SNAPSHOT> {
js_runtime js_runtime
} }
/// Create a new [`v8::OwnedIsolate`] and its global [`v8::Context`] from optional parameters and snapshot.
fn create_isolate(
refs: &'static v8::ExternalReferences,
params: Option<CreateParams>,
snapshot: SnapshotOptions,
) -> (
v8::OwnedIsolate,
v8::Global<v8::Context>,
Option<SnapshottedData>,
)
where
JsRuntimeImpl<FOR_SNAPSHOT>: JsRuntimeInternalTrait,
{
let has_snapshot = snapshot.loaded();
let mut isolate = Self::create_raw_isolate(refs, params, snapshot);
isolate.set_capture_stack_trace_for_uncaught_exceptions(true, 10);
isolate.set_promise_reject_callback(bindings::promise_reject_callback);
isolate.set_host_initialize_import_meta_object_callback(
bindings::host_initialize_import_meta_object_callback,
);
isolate.set_host_import_module_dynamically_callback(
bindings::host_import_module_dynamically_callback,
);
isolate.set_wasm_async_resolve_promise_callback(
bindings::wasm_async_resolve_promise_callback,
);
let (context, snapshotted_data) = {
let scope = &mut v8::HandleScope::new(&mut isolate);
let context = v8::Context::new(scope);
// Get module map data from the snapshot
let snapshotted_data = if has_snapshot {
Some(snapshot_util::get_snapshotted_data(scope, context))
} else {
None
};
(v8::Global::new(scope, context), snapshotted_data)
};
(isolate, context, snapshotted_data)
}
#[cfg(test)] #[cfg(test)]
#[inline] #[inline]
pub(crate) fn module_map(&self) -> &Rc<RefCell<ModuleMap>> { pub(crate) fn module_map(&self) -> &Rc<RefCell<ModuleMap>> {
@ -728,7 +752,7 @@ impl<const FOR_SNAPSHOT: bool> JsRuntimeImpl<FOR_SNAPSHOT> {
/// Creates a new realm (V8 context) in this JS execution context, /// Creates a new realm (V8 context) in this JS execution context,
/// pre-initialized with all of the extensions that were passed in /// pre-initialized with all of the extensions that were passed in
/// [`RuntimeOptions::extensions`] when the [`JsRuntimeImpl`] was /// [`RuntimeOptions::extensions`] when the [`JsRuntime`] was
/// constructed. /// constructed.
pub fn create_realm(&mut self) -> Result<JsRealm, Error> { pub fn create_realm(&mut self) -> Result<JsRealm, Error> {
let realm = { let realm = {
@ -768,7 +792,7 @@ impl<const FOR_SNAPSHOT: bool> JsRuntimeImpl<FOR_SNAPSHOT> {
scope, scope,
context, context,
&context_state.borrow().op_ctxs, &context_state.borrow().op_ctxs,
self.bindings_mode, self.init_mode,
); );
context.set_slot(scope, context_state.clone()); context.set_slot(scope, context_state.clone());
let realm = JsRealmInner::new( let realm = JsRealmInner::new(
@ -946,10 +970,10 @@ impl<const FOR_SNAPSHOT: bool> JsRuntimeImpl<FOR_SNAPSHOT> {
/// Initializes ops of provided Extensions /// Initializes ops of provided Extensions
fn create_opstate( fn create_opstate(
options: &mut RuntimeOptions, options: &mut RuntimeOptions,
snapshot_options: &SnapshotOptions, init_mode: InitMode,
) -> (OpState, Vec<OpDecl>) { ) -> (OpState, Vec<OpDecl>) {
// Add built-in extension // Add built-in extension
if snapshot_options.loaded() { if init_mode == InitMode::FromSnapshot {
options options
.extensions .extensions
.insert(0, crate::ops_builtin::core::init_ops()); .insert(0, crate::ops_builtin::core::init_ops());
@ -1470,78 +1494,15 @@ impl<const FOR_SNAPSHOT: bool> JsRuntimeImpl<FOR_SNAPSHOT> {
} }
} }
impl JsRuntime {
/// Only constructor, configuration is done through `options`.
pub fn new(mut options: RuntimeOptions) -> JsRuntime {
JsRuntimeImpl::<false>::init_v8(options.v8_platform.take());
let snapshot_options = snapshot_util::SnapshotOptions::new_from(
options.startup_snapshot.take(),
false,
);
JsRuntime(JsRuntimeImpl::<false>::new_runtime(
options,
snapshot_options,
None,
))
}
pub(crate) fn state_from(
isolate: &v8::Isolate,
) -> Rc<RefCell<JsRuntimeState>> {
let state_ptr = isolate.get_data(STATE_DATA_OFFSET);
let state_rc =
// SAFETY: We are sure that it's a valid pointer for whole lifetime of
// the runtime.
unsafe { Rc::from_raw(state_ptr as *const RefCell<JsRuntimeState>) };
let state = state_rc.clone();
std::mem::forget(state_rc);
state
}
pub(crate) fn module_map_from(
isolate: &v8::Isolate,
) -> Rc<RefCell<ModuleMap>> {
let module_map_ptr = isolate.get_data(MODULE_MAP_DATA_OFFSET);
let module_map_rc =
// SAFETY: We are sure that it's a valid pointer for whole lifetime of
// the runtime.
unsafe { Rc::from_raw(module_map_ptr as *const RefCell<ModuleMap>) };
let module_map = module_map_rc.clone();
std::mem::forget(module_map_rc);
module_map
}
pub(crate) fn event_loop_pending_state_from_scope(
scope: &mut v8::HandleScope,
) -> EventLoopPendingState {
let state = JsRuntime::state_from(scope);
let module_map = JsRuntime::module_map_from(scope);
let state = EventLoopPendingState::new(
scope,
&mut state.borrow_mut(),
&module_map.borrow(),
);
state
}
}
impl JsRuntimeForSnapshot { impl JsRuntimeForSnapshot {
pub fn new( pub fn new(
mut options: RuntimeOptions, mut options: RuntimeOptions,
runtime_snapshot_options: RuntimeSnapshotOptions, runtime_snapshot_options: RuntimeSnapshotOptions,
) -> JsRuntimeForSnapshot { ) -> JsRuntimeForSnapshot {
JsRuntimeImpl::<true>::init_v8(options.v8_platform.take()); JsRuntime::init_v8(options.v8_platform.take(), true);
JsRuntimeForSnapshot(JsRuntime::new_inner(
let snapshot_options = snapshot_util::SnapshotOptions::new_from(
options.startup_snapshot.take(),
true,
);
JsRuntimeForSnapshot(JsRuntimeImpl::<true>::new_runtime(
options, options,
snapshot_options, true,
runtime_snapshot_options.snapshot_module_load_cb, runtime_snapshot_options.snapshot_module_load_cb,
)) ))
} }
@ -1590,42 +1551,6 @@ impl JsRuntimeForSnapshot {
} }
} }
impl JsRuntimeInternalTrait for JsRuntimeImpl<true> {
fn create_raw_isolate(
refs: &'static v8::ExternalReferences,
_params: Option<CreateParams>,
snapshot: SnapshotOptions,
) -> v8::OwnedIsolate {
snapshot_util::create_snapshot_creator(refs, snapshot)
}
}
impl JsRuntimeInternalTrait for JsRuntimeImpl<false> {
fn create_raw_isolate(
refs: &'static v8::ExternalReferences,
params: Option<CreateParams>,
snapshot: SnapshotOptions,
) -> v8::OwnedIsolate {
let mut params = params
.unwrap_or_default()
.embedder_wrapper_type_info_offsets(
V8_WRAPPER_TYPE_INDEX,
V8_WRAPPER_OBJECT_INDEX,
)
.external_references(&**refs);
if let Some(snapshot) = snapshot.snapshot() {
params = match snapshot {
Snapshot::Static(data) => params.snapshot_blob(data),
Snapshot::JustCreated(data) => params.snapshot_blob(data),
Snapshot::Boxed(data) => params.snapshot_blob(data),
};
}
v8::Isolate::new(params)
}
}
fn get_stalled_top_level_await_message_for_module( fn get_stalled_top_level_await_message_for_module(
scope: &mut v8::HandleScope, scope: &mut v8::HandleScope,
module_id: ModuleId, module_id: ModuleId,
@ -1731,7 +1656,7 @@ where
F: FnMut(usize, usize) -> usize, F: FnMut(usize, usize) -> usize,
{ {
// SAFETY: The data is a pointer to the Rust callback function. It is stored // SAFETY: The data is a pointer to the Rust callback function. It is stored
// in `JsRuntimeImpl::allocations` and thus is guaranteed to outlive the isolate. // in `JsRuntime::allocations` and thus is guaranteed to outlive the isolate.
let callback = unsafe { &mut *(data as *mut F) }; let callback = unsafe { &mut *(data as *mut F) };
callback(current_heap_limit, initial_heap_limit) callback(current_heap_limit, initial_heap_limit)
} }
@ -1800,7 +1725,7 @@ pub(crate) fn exception_to_err_result<T>(
} }
// Related to module loading // Related to module loading
impl<const FOR_SNAPSHOT: bool> JsRuntimeImpl<FOR_SNAPSHOT> { impl JsRuntime {
pub(crate) fn instantiate_module( pub(crate) fn instantiate_module(
&mut self, &mut self,
id: ModuleId, id: ModuleId,
@ -1916,11 +1841,11 @@ impl<const FOR_SNAPSHOT: bool> JsRuntimeImpl<FOR_SNAPSHOT> {
/// Evaluates an already instantiated ES module. /// Evaluates an already instantiated ES module.
/// ///
/// Returns a receiver handle that resolves when module promise resolves. /// Returns a receiver handle that resolves when module promise resolves.
/// Implementors must manually call [`JsRuntimeImpl::run_event_loop`] to drive /// Implementors must manually call [`JsRuntime::run_event_loop`] to drive
/// module evaluation future. /// module evaluation future.
/// ///
/// `Error` can usually be downcast to `JsError` and should be awaited and /// `Error` can usually be downcast to `JsError` and should be awaited and
/// checked after [`JsRuntimeImpl::run_event_loop`] completion. /// checked after [`JsRuntime::run_event_loop`] completion.
/// ///
/// This function panics if module has not been instantiated. /// This function panics if module has not been instantiated.
pub fn mod_evaluate( pub fn mod_evaluate(
@ -1953,7 +1878,7 @@ impl<const FOR_SNAPSHOT: bool> JsRuntimeImpl<FOR_SNAPSHOT> {
// Because that promise is created internally by V8, when error occurs during // Because that promise is created internally by V8, when error occurs during
// module evaluation the promise is rejected, and since the promise has no rejection // module evaluation the promise is rejected, and since the promise has no rejection
// handler it will result in call to `bindings::promise_reject_callback` adding // handler it will result in call to `bindings::promise_reject_callback` adding
// the promise to pending promise rejection table - meaning JsRuntimeImpl will return // the promise to pending promise rejection table - meaning JsRuntime will return
// error on next poll(). // error on next poll().
// //
// This situation is not desirable as we want to manually return error at the // This situation is not desirable as we want to manually return error at the
@ -2362,7 +2287,7 @@ impl<const FOR_SNAPSHOT: bool> JsRuntimeImpl<FOR_SNAPSHOT> {
/// The module will be marked as "main", and because of that /// The module will be marked as "main", and because of that
/// "import.meta.main" will return true when checked inside that module. /// "import.meta.main" will return true when checked inside that module.
/// ///
/// User must call [`JsRuntimeImpl::mod_evaluate`] with returned `ModuleId` /// User must call [`JsRuntime::mod_evaluate`] with returned `ModuleId`
/// manually after load is finished. /// manually after load is finished.
pub async fn load_main_module( pub async fn load_main_module(
&mut self, &mut self,
@ -2417,7 +2342,7 @@ impl<const FOR_SNAPSHOT: bool> JsRuntimeImpl<FOR_SNAPSHOT> {
/// This method is meant to be used when loading some utility code that /// This method is meant to be used when loading some utility code that
/// might be later imported by the main module (ie. an entry point module). /// might be later imported by the main module (ie. an entry point module).
/// ///
/// User must call [`JsRuntimeImpl::mod_evaluate`] with returned `ModuleId` /// User must call [`JsRuntime::mod_evaluate`] with returned `ModuleId`
/// manually after load is finished. /// manually after load is finished.
pub async fn load_side_module( pub async fn load_side_module(
&mut self, &mut self,
@ -2563,7 +2488,7 @@ pub fn queue_fast_async_op<R: serde::Serialize + 'static>(
) { ) {
let runtime_state = match ctx.runtime_state.upgrade() { let runtime_state = match ctx.runtime_state.upgrade() {
Some(rc_state) => rc_state, Some(rc_state) => rc_state,
// at least 1 Rc is held by the JsRuntimeImpl. // at least 1 Rc is held by the JsRuntime.
None => unreachable!(), None => unreachable!(),
}; };
let get_class = { let get_class = {
@ -2661,7 +2586,7 @@ pub fn queue_async_op<'s>(
) -> Option<v8::Local<'s, v8::Value>> { ) -> Option<v8::Local<'s, v8::Value>> {
let runtime_state = match ctx.runtime_state.upgrade() { let runtime_state = match ctx.runtime_state.upgrade() {
Some(rc_state) => rc_state, Some(rc_state) => rc_state,
// at least 1 Rc is held by the JsRuntimeImpl. // at least 1 Rc is held by the JsRuntime.
None => unreachable!(), None => unreachable!(),
}; };
@ -3559,8 +3484,8 @@ pub mod tests {
} }
} }
fn create_module<const FOR_SNAPSHOT: bool>( fn create_module(
runtime: &mut JsRuntimeImpl<FOR_SNAPSHOT>, runtime: &mut JsRuntime,
i: usize, i: usize,
main: bool, main: bool,
) -> ModuleInfo { ) -> ModuleInfo {
@ -3603,10 +3528,7 @@ pub mod tests {
} }
} }
fn assert_module_map<const FOR_SNAPSHOT: bool>( fn assert_module_map(runtime: &mut JsRuntime, modules: &Vec<ModuleInfo>) {
runtime: &mut JsRuntimeImpl<FOR_SNAPSHOT>,
modules: &Vec<ModuleInfo>,
) {
let module_map = runtime.module_map.borrow(); let module_map = runtime.module_map.borrow();
assert_eq!(module_map.handles.len(), modules.len()); assert_eq!(module_map.handles.len(), modules.len());
assert_eq!(module_map.info.len(), modules.len()); assert_eq!(module_map.info.len(), modules.len());
@ -4679,13 +4601,7 @@ Deno.core.opAsync("op_async_serialize_object_with_numbers_as_keys", {
Ok(String::from("Test")) Ok(String::from("Test"))
} }
deno_core::extension!( deno_core::extension!(test_ext, ops = [op_test]);
test_ext,
ops = [op_test],
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
},
);
let mut runtime = JsRuntime::new(RuntimeOptions { let mut runtime = JsRuntime::new(RuntimeOptions {
startup_snapshot: Some(Snapshot::Boxed(snapshot)), startup_snapshot: Some(Snapshot::Boxed(snapshot)),
extensions: vec![test_ext::init_ops()], extensions: vec![test_ext::init_ops()],

View file

@ -153,40 +153,6 @@ fn data_error_to_panic(err: v8::DataError) -> ! {
} }
} }
pub(crate) enum SnapshotOptions {
Load(Snapshot),
CreateFromExisting(Snapshot),
Create,
None,
}
impl SnapshotOptions {
pub fn new_from(snapshot: Option<Snapshot>, will_snapshot: bool) -> Self {
match (snapshot, will_snapshot) {
(Some(snapshot), true) => Self::CreateFromExisting(snapshot),
(None, true) => Self::Create,
(Some(snapshot), false) => Self::Load(snapshot),
(None, false) => Self::None,
}
}
pub fn loaded(&self) -> bool {
matches!(self, Self::Load(_) | Self::CreateFromExisting(_))
}
pub fn will_snapshot(&self) -> bool {
matches!(self, Self::Create | Self::CreateFromExisting(_))
}
pub fn snapshot(self) -> Option<Snapshot> {
match self {
Self::CreateFromExisting(snapshot) => Some(snapshot),
Self::Load(snapshot) => Some(snapshot),
_ => None,
}
}
}
pub(crate) struct SnapshottedData { pub(crate) struct SnapshottedData {
pub module_map_data: v8::Global<v8::Array>, pub module_map_data: v8::Global<v8::Array>,
pub module_handles: Vec<v8::Global<v8::Module>>, pub module_handles: Vec<v8::Global<v8::Module>>,
@ -257,9 +223,9 @@ pub(crate) fn set_snapshotted_data(
/// Returns an isolate set up for snapshotting. /// Returns an isolate set up for snapshotting.
pub(crate) fn create_snapshot_creator( pub(crate) fn create_snapshot_creator(
external_refs: &'static v8::ExternalReferences, external_refs: &'static v8::ExternalReferences,
maybe_startup_snapshot: SnapshotOptions, maybe_startup_snapshot: Option<Snapshot>,
) -> v8::OwnedIsolate { ) -> v8::OwnedIsolate {
if let Some(snapshot) = maybe_startup_snapshot.snapshot() { if let Some(snapshot) = maybe_startup_snapshot {
match snapshot { match snapshot {
Snapshot::Static(data) => { Snapshot::Static(data) => {
v8::Isolate::snapshot_creator_from_existing_snapshot( v8::Isolate::snapshot_creator_from_existing_snapshot(

View file

@ -143,7 +143,6 @@ impl Op {
is_async: #is_async, is_async: #is_async,
is_unstable: #is_unstable, is_unstable: #is_unstable,
is_v8: #is_v8, is_v8: #is_v8,
force_registration: false,
// TODO(mmastrac) // TODO(mmastrac)
arg_count: 0, arg_count: 0,
} }
@ -206,7 +205,6 @@ impl Op {
is_async: #is_async, is_async: #is_async,
is_unstable: #is_unstable, is_unstable: #is_unstable,
is_v8: #is_v8, is_v8: #is_v8,
force_registration: false,
arg_count: #arg_count as u8, arg_count: #arg_count as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl op_void_async {
is_async: true, is_async: true,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 1usize as u8, arg_count: 1usize as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl op_async_result {
is_async: true, is_async: true,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 2usize as u8, arg_count: 2usize as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl op_fallback {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 1usize as u8, arg_count: 1usize as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl op_cow_str {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 1usize as u8, arg_count: 1usize as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl op_f64_buf {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 1usize as u8, arg_count: 1usize as u8,
} }
} }

View file

@ -30,7 +30,6 @@ impl op_sync_serialize_object_with_numbers_as_keys {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 1usize as u8, arg_count: 1usize as u8,
} }
} }

View file

@ -30,7 +30,6 @@ impl send_stdin {
is_async: true, is_async: true,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 2usize as u8, arg_count: 2usize as u8,
} }
} }

View file

@ -30,7 +30,6 @@ impl send_stdin {
is_async: true, is_async: true,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 2usize as u8, arg_count: 2usize as u8,
} }
} }

View file

@ -30,7 +30,6 @@ impl op_blob_revoke_object_url {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 1usize as u8, arg_count: 1usize as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl op_ffi_ptr_value {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 2usize as u8, arg_count: 2usize as u8,
} }
} }

View file

@ -30,7 +30,6 @@ impl op_print {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 2usize as u8, arg_count: 2usize as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl op_set_exit_code {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 1usize as u8, arg_count: 1usize as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl foo {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 2usize as u8, arg_count: 2usize as u8,
} }
} }

View file

@ -46,7 +46,6 @@ impl op_foo {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 0usize as u8, arg_count: 0usize as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl foo {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 2usize as u8, arg_count: 2usize as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl op_listen {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 0usize as u8, arg_count: 0usize as u8,
} }
} }

View file

@ -46,7 +46,6 @@ impl op_now {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 1usize as u8, arg_count: 1usize as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl op_add_4 {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 4usize as u8, arg_count: 4usize as u8,
} }
} }

View file

@ -30,7 +30,6 @@ impl op_try_close {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 1usize as u8, arg_count: 1usize as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl op_string_length {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 1usize as u8, arg_count: 1usize as u8,
} }
} }

View file

@ -30,7 +30,6 @@ impl op_read_sync {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 2usize as u8, arg_count: 2usize as u8,
} }
} }

View file

@ -51,7 +51,6 @@ impl op_ffi_ptr_of {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 2usize as u8, arg_count: 2usize as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl op_is_proxy {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 1usize as u8, arg_count: 1usize as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl op_string_length {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 1usize as u8, arg_count: 1usize as u8,
} }
} }

View file

@ -30,7 +30,6 @@ impl op_string_length {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 1usize as u8, arg_count: 1usize as u8,
} }
} }

View file

@ -30,7 +30,6 @@ impl op_bench_now {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 0usize as u8, arg_count: 0usize as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl op_import_spki_x25519 {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 2usize as u8, arg_count: 2usize as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl op_unit_result {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 0usize as u8, arg_count: 0usize as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl op_set_nodelay {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 2usize as u8, arg_count: 2usize as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl op_unit {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 0usize as u8, arg_count: 0usize as u8,
} }
} }

View file

@ -40,7 +40,6 @@ impl op_wasm {
is_async: false, is_async: false,
is_unstable: false, is_unstable: false,
is_v8: false, is_v8: false,
force_registration: false,
arg_count: 1usize as u8, arg_count: 1usize as u8,
} }
} }

View file

@ -11,13 +11,7 @@ use deno_runtime::permissions::PermissionsContainer;
use deno_runtime::worker::MainWorker; use deno_runtime::worker::MainWorker;
use deno_runtime::worker::WorkerOptions; use deno_runtime::worker::WorkerOptions;
deno_core::extension!( deno_core::extension!(hello_runtime, ops = [op_hello]);
hello_runtime,
ops = [op_hello],
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
},
);
#[op] #[op]
fn op_hello(text: &str) { fn op_hello(text: &str) {

View file

@ -31,9 +31,6 @@ use tokio::sync::mpsc;
deno_core::extension!( deno_core::extension!(
deno_fs_events, deno_fs_events,
ops = [op_fs_events_open, op_fs_events_poll], ops = [op_fs_events_open, op_fs_events_poll],
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
},
); );
struct FsEventsResource { struct FsEventsResource {

View file

@ -30,9 +30,6 @@ use tokio::net::UnixStream;
deno_core::extension!( deno_core::extension!(
deno_http_runtime, deno_http_runtime,
ops = [op_http_start, op_http_upgrade], ops = [op_http_start, op_http_upgrade],
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
},
); );
#[op] #[op]

View file

@ -48,9 +48,6 @@ deno_core::extension!(
state = |state, options| { state = |state, options| {
state.put::<ExitCode>(options.exit_code); state.put::<ExitCode>(options.exit_code);
}, },
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
}
); );
deno_core::extension!( deno_core::extension!(
@ -63,9 +60,6 @@ deno_core::extension!(
}, },
_ => op, _ => op,
}, },
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
}
); );
#[op] #[op]

View file

@ -18,9 +18,6 @@ deno_core::extension!(
op_revoke_permission, op_revoke_permission,
op_request_permission, op_request_permission,
], ],
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
},
); );
#[derive(Deserialize)] #[derive(Deserialize)]

View file

@ -112,9 +112,6 @@ deno_core::extension!(
deprecated::op_run_status, deprecated::op_run_status,
deprecated::op_kill, deprecated::op_kill,
], ],
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
},
); );
/// Second member stores the pid separately from the RefCell. It's needed for /// Second member stores the pid separately from the RefCell. It's needed for

View file

@ -13,9 +13,6 @@ deno_core::extension!(
state = |state, options| { state = |state, options| {
state.put::<ModuleSpecifier>(options.main_module); state.put::<ModuleSpecifier>(options.main_module);
}, },
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
},
); );
#[op] #[op]

View file

@ -32,9 +32,6 @@ use tokio::signal::windows::CtrlC;
deno_core::extension!( deno_core::extension!(
deno_signal, deno_signal,
ops = [op_signal_bind, op_signal_unbind, op_signal_poll], ops = [op_signal_bind, op_signal_unbind, op_signal_poll],
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
},
); );
#[cfg(unix)] #[cfg(unix)]

View file

@ -79,9 +79,6 @@ deno_core::extension!(
#[cfg(unix)] #[cfg(unix)]
state.put(TtyModeStore::default()); state.put(TtyModeStore::default());
}, },
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
},
); );
// ref: <https://learn.microsoft.com/en-us/windows/console/setconsolemode> // ref: <https://learn.microsoft.com/en-us/windows/console/setconsolemode>

View file

@ -25,9 +25,6 @@ deno_core::extension!(
op_worker_get_type, op_worker_get_type,
op_worker_sync_fetch, op_worker_sync_fetch,
], ],
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
},
); );
#[op] #[op]

View file

@ -119,9 +119,6 @@ deno_core::extension!(
FormatJsErrorFnHolder(options.format_js_error_fn); FormatJsErrorFnHolder(options.format_js_error_fn);
state.put::<FormatJsErrorFnHolder>(format_js_error_fn_holder); state.put::<FormatJsErrorFnHolder>(format_js_error_fn_holder);
}, },
customizer = |ext: &mut deno_core::ExtensionBuilder| {
ext.force_op_registration();
},
); );
#[derive(Deserialize)] #[derive(Deserialize)]