mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
perf(core) Reduce copying and cloning in extension initialization (#18252)
Follow-up to #18210: * we are passing the generated `cfg` object into the state function rather than passing individual config fields * reduce cloning dramatically by making the state_fn `FnOnce` * `take` for `ExtensionBuilder` to avoid more unnecessary copies * renamed `config` to `options`
This commit is contained in:
parent
e55b448730
commit
3487fde236
27 changed files with 206 additions and 174 deletions
14
cli/build.rs
14
cli/build.rs
|
@ -1,9 +1,7 @@
|
|||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
|
||||
use deno_core::snapshot_util::*;
|
||||
use deno_core::Extension;
|
||||
|
@ -122,15 +120,15 @@ mod ts {
|
|||
"00_typescript.js",
|
||||
"99_main_compiler.js",
|
||||
],
|
||||
config = {
|
||||
options = {
|
||||
op_crate_libs: HashMap<&'static str, PathBuf>,
|
||||
build_libs: Vec<&'static str>,
|
||||
path_dts: PathBuf,
|
||||
},
|
||||
state = |state, op_crate_libs, build_libs, path_dts| {
|
||||
state.put(op_crate_libs);
|
||||
state.put(build_libs);
|
||||
state.put(path_dts);
|
||||
state = |state, options| {
|
||||
state.put(options.op_crate_libs);
|
||||
state.put(options.build_libs);
|
||||
state.put(options.path_dts);
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -362,7 +360,7 @@ fn create_cli_snapshot(snapshot_path: PathBuf) {
|
|||
deno_tls::deno_tls::init_ops(),
|
||||
deno_napi::deno_napi::init_ops::<PermissionsContainer>(),
|
||||
deno_http::deno_http::init_ops(),
|
||||
deno_io::deno_io::init_ops(Rc::new(RefCell::new(Some(Default::default())))),
|
||||
deno_io::deno_io::init_ops(Default::default()),
|
||||
deno_fs::deno_fs::init_ops::<PermissionsContainer>(false),
|
||||
deno_flash::deno_flash::init_ops::<PermissionsContainer>(false), // No --unstable
|
||||
deno_node::deno_node_loading::init_ops::<PermissionsContainer>(None), // No --unstable.
|
||||
|
|
|
@ -2834,13 +2834,13 @@ deno_core::extension!(deno_tsc,
|
|||
op_script_names,
|
||||
op_script_version,
|
||||
],
|
||||
config = {
|
||||
options = {
|
||||
performance: Arc<Performance>
|
||||
},
|
||||
state = |state, performance| {
|
||||
state = |state, options| {
|
||||
state.put(State::new(
|
||||
Arc::new(StateSnapshot::default()),
|
||||
performance,
|
||||
options.performance,
|
||||
));
|
||||
},
|
||||
);
|
||||
|
|
|
@ -30,13 +30,13 @@ deno_core::extension!(deno_bench,
|
|||
op_dispatch_bench_event,
|
||||
op_bench_now,
|
||||
],
|
||||
config = {
|
||||
options = {
|
||||
sender: UnboundedSender<BenchEvent>,
|
||||
filter: TestFilter,
|
||||
},
|
||||
state = |state, sender, filter| {
|
||||
state.put(sender);
|
||||
state.put(filter);
|
||||
state = |state, options| {
|
||||
state.put(options.sender);
|
||||
state.put(options.filter);
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
@ -15,11 +15,11 @@ pub fn cli_exts(ps: ProcState) -> Vec<Extension> {
|
|||
|
||||
deno_core::extension!(deno_cli,
|
||||
ops = [op_npm_process_state],
|
||||
config = {
|
||||
options = {
|
||||
ps: ProcState,
|
||||
},
|
||||
state = |state, ps| {
|
||||
state.put(ps);
|
||||
state = |state, options| {
|
||||
state.put(options.ps);
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
@ -34,15 +34,15 @@ deno_core::extension!(deno_test,
|
|||
op_dispatch_test_event,
|
||||
op_tests_should_stop,
|
||||
],
|
||||
config = {
|
||||
options = {
|
||||
sender: TestEventSender,
|
||||
fail_fast_tracker: FailFastTracker,
|
||||
filter: TestFilter,
|
||||
},
|
||||
state = |state, sender, fail_fast_tracker, filter| {
|
||||
state.put(sender);
|
||||
state.put(fail_fast_tracker);
|
||||
state.put(filter);
|
||||
state = |state, options| {
|
||||
state.put(options.sender);
|
||||
state.put(options.fail_fast_tracker);
|
||||
state.put(options.filter);
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
@ -41,7 +41,6 @@ use std::collections::HashMap;
|
|||
use std::fmt;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
mod diagnostics;
|
||||
|
@ -829,19 +828,19 @@ pub fn exec(request: Request) -> Result<Response, AnyError> {
|
|||
|
||||
deno_core::extension!(deno_cli_tsc,
|
||||
ops_fn = deno_ops,
|
||||
config = {
|
||||
request: Rc<Request>,
|
||||
options = {
|
||||
request: Request,
|
||||
root_map: HashMap<String, Url>,
|
||||
remapped_specifiers: HashMap<String, Url>,
|
||||
},
|
||||
state = |state, request, root_map, remapped_specifiers| {
|
||||
state = |state, options| {
|
||||
state.put(State::new(
|
||||
request.graph.clone(),
|
||||
request.hash_data.clone(),
|
||||
request.maybe_npm_resolver.clone(),
|
||||
request.maybe_tsbuildinfo.clone(),
|
||||
root_map,
|
||||
remapped_specifiers,
|
||||
options.request.graph,
|
||||
options.request.hash_data,
|
||||
options.request.maybe_npm_resolver,
|
||||
options.request.maybe_tsbuildinfo,
|
||||
options.root_map,
|
||||
options.remapped_specifiers,
|
||||
std::env::current_dir()
|
||||
.context("Unable to get CWD")
|
||||
.unwrap(),
|
||||
|
@ -861,7 +860,7 @@ pub fn exec(request: Request) -> Result<Response, AnyError> {
|
|||
let mut runtime = JsRuntime::new(RuntimeOptions {
|
||||
startup_snapshot: Some(compiler_snapshot()),
|
||||
extensions: vec![deno_cli_tsc::init_ops(
|
||||
Rc::new(request),
|
||||
request,
|
||||
root_map,
|
||||
remapped_specifiers,
|
||||
)],
|
||||
|
|
|
@ -42,7 +42,7 @@ pub struct ExtensionFileSource {
|
|||
}
|
||||
pub type OpFnRef = v8::FunctionCallback;
|
||||
pub type OpMiddlewareFn = dyn Fn(OpDecl) -> OpDecl;
|
||||
pub type OpStateFn = dyn Fn(&mut OpState);
|
||||
pub type OpStateFn = dyn FnOnce(&mut OpState);
|
||||
pub type OpEventLoopFn = dyn Fn(Rc<RefCell<OpState>>, &mut Context) -> bool;
|
||||
|
||||
pub struct OpDecl {
|
||||
|
@ -164,7 +164,7 @@ macro_rules! extension {
|
|||
$(, esm = [ $( dir $dir_esm:literal , )? $( $esm:literal ),* $(,)? ] )?
|
||||
$(, esm_setup_script = $esm_setup_script:expr )?
|
||||
$(, js = [ $( dir $dir_js:literal , )? $( $js:literal ),* $(,)? ] )?
|
||||
$(, config = { $( $config_id:ident : $config_type:ty ),* $(,)? } )?
|
||||
$(, options = { $( $options_id:ident : $options_type:ty ),* $(,)? } )?
|
||||
$(, middleware = $middleware_fn:expr )?
|
||||
$(, state = $state_fn:expr )?
|
||||
$(, event_loop_middleware = $event_loop_middleware_fn:ident )?
|
||||
|
@ -227,13 +227,13 @@ macro_rules! extension {
|
|||
// Includes the state and middleware functions, if defined.
|
||||
#[inline(always)]
|
||||
#[allow(unused_variables)]
|
||||
fn with_state_and_middleware$( < $( $param : $type + Clone + 'static ),+ > )?(ext: &mut $crate::ExtensionBuilder, $( $( $config_id : $config_type ),* )? ) {
|
||||
fn with_state_and_middleware$( < $( $param : $type + Clone + 'static ),+ > )?(ext: &mut $crate::ExtensionBuilder, $( $( $options_id : $options_type ),* )? ) {
|
||||
#[allow(unused_variables)]
|
||||
let config = $crate::extension!(! __config__ $( parameters = [ $( $param : $type ),* ] )? $( config = { $( $config_id : $config_type ),* } )? );
|
||||
let config = $crate::extension!(! __config__ $( parameters = [ $( $param : $type ),* ] )? $( config = { $( $options_id : $options_type ),* } )? );
|
||||
|
||||
$(
|
||||
ext.state(move |state: &mut $crate::OpState| {
|
||||
config.clone().call_callback(state, $state_fn)
|
||||
config.call_callback(state, $state_fn)
|
||||
});
|
||||
)?
|
||||
|
||||
|
@ -259,57 +259,78 @@ macro_rules! extension {
|
|||
Self::with_js(&mut ext);
|
||||
Self::with_ops $( ::<($( $param ),+)> )?(&mut ext);
|
||||
Self::with_customizer(&mut ext);
|
||||
ext.build()
|
||||
ext.take()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn init_ops_and_esm $( < $( $param : $type + Clone + 'static ),+ > )? ( $( $( $config_id : $config_type ),* )? ) -> $crate::Extension {
|
||||
pub fn init_ops_and_esm $( < $( $param : $type + Clone + 'static ),+ > )? ( $( $( $options_id : $options_type ),* )? ) -> $crate::Extension {
|
||||
let mut ext = Self::ext();
|
||||
// If esm or JS was specified, add JS files
|
||||
Self::with_js(&mut ext);
|
||||
Self::with_ops $( ::<($( $param ),+)> )?(&mut ext);
|
||||
Self::with_state_and_middleware $( ::<($( $param ),+)> )?(&mut ext, $( $( $config_id , )* )? );
|
||||
Self::with_state_and_middleware $( ::<($( $param ),+)> )?(&mut ext, $( $( $options_id , )* )? );
|
||||
Self::with_customizer(&mut ext);
|
||||
ext.build()
|
||||
ext.take()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn init_ops $( < $( $param : $type + Clone + 'static ),+ > )? ( $( $( $config_id : $config_type ),* )? ) -> $crate::Extension {
|
||||
pub fn init_ops $( < $( $param : $type + Clone + 'static ),+ > )? ( $( $( $options_id : $options_type ),* )? ) -> $crate::Extension {
|
||||
let mut ext = Self::ext();
|
||||
Self::with_ops $( ::<($( $param ),+)> )?(&mut ext);
|
||||
Self::with_state_and_middleware $( ::<($( $param ),+)> )?(&mut ext, $( $( $config_id , )* )? );
|
||||
Self::with_state_and_middleware $( ::<($( $param ),+)> )?(&mut ext, $( $( $options_id , )* )? );
|
||||
Self::with_customizer(&mut ext);
|
||||
ext.build()
|
||||
ext.take()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
(! __config__ $( parameters = [ $( $param:ident : $type:ident ),+ ] )? $( config = { $( $config_id:ident : $config_type:ty ),* } )? ) => {
|
||||
// This branch of the macro generates a config object that calls the state function with itself.
|
||||
(! __config__ $( parameters = [ $( $param:ident : $type:ident ),+ ] )? config = { $( $options_id:ident : $options_type:ty ),* } ) => {
|
||||
{
|
||||
#[doc(hidden)]
|
||||
#[derive(Clone)]
|
||||
struct Config $( < $( $param : $type + Clone + 'static ),+ > )? {
|
||||
$( $( pub $config_id : $config_type , )* )?
|
||||
$( pub $options_id : $options_type , )*
|
||||
$( __phantom_data: ::std::marker::PhantomData<($( $param ),+)>, )?
|
||||
}
|
||||
|
||||
impl $( < $( $param : $type + Clone + 'static ),+ > )? Config $( < $( $param ),+ > )? {
|
||||
/// Call a function of |state, ...| using the fields of this configuration structure.
|
||||
/// Call a function of |state, cfg| using this configuration structure.
|
||||
#[allow(dead_code)]
|
||||
#[doc(hidden)]
|
||||
#[inline(always)]
|
||||
fn call_callback<F: Fn(&mut $crate::OpState, $( $( $config_type ),* )?)>(self, state: &mut $crate::OpState, f: F) {
|
||||
f(state, $( $( self. $config_id ),* )? )
|
||||
fn call_callback<F: Fn(&mut $crate::OpState, Self)>(self, state: &mut $crate::OpState, f: F) {
|
||||
f(state, self)
|
||||
}
|
||||
}
|
||||
|
||||
Config {
|
||||
$( $( $config_id , )* )?
|
||||
$( $options_id , )*
|
||||
$( __phantom_data: ::std::marker::PhantomData::<($( $param ),+)>::default() )?
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// This branch of the macro generates an empty config object that doesn't actually make any callbacks on the state function.
|
||||
(! __config__ $( parameters = [ $( $param:ident : $type:ident ),+ ] )? ) => {
|
||||
{
|
||||
#[doc(hidden)]
|
||||
struct Config {
|
||||
}
|
||||
|
||||
impl Config {
|
||||
/// Call a function of |state| using the fields of this configuration structure.
|
||||
#[allow(dead_code)]
|
||||
#[doc(hidden)]
|
||||
#[inline(always)]
|
||||
fn call_callback<F: Fn(&mut $crate::OpState)>(self, state: &mut $crate::OpState, f: F) {
|
||||
f(state)
|
||||
}
|
||||
}
|
||||
|
||||
Config {}
|
||||
}
|
||||
};
|
||||
|
||||
(! __ops__ $ext:ident __eot__) => {
|
||||
};
|
||||
|
||||
|
@ -409,8 +430,8 @@ impl Extension {
|
|||
}
|
||||
|
||||
/// Allows setting up the initial op-state of an isolate at startup.
|
||||
pub fn init_state(&self, state: &mut OpState) {
|
||||
if let Some(op_fn) = &self.opstate_fn {
|
||||
pub fn init_state(&mut self, state: &mut OpState) {
|
||||
if let Some(op_fn) = self.opstate_fn.take() {
|
||||
op_fn(state);
|
||||
}
|
||||
}
|
||||
|
@ -499,7 +520,7 @@ impl ExtensionBuilder {
|
|||
|
||||
pub fn state<F>(&mut self, opstate_fn: F) -> &mut Self
|
||||
where
|
||||
F: Fn(&mut OpState) + 'static,
|
||||
F: FnOnce(&mut OpState) + 'static,
|
||||
{
|
||||
self.state = Some(Box::new(opstate_fn));
|
||||
self
|
||||
|
@ -521,6 +542,27 @@ impl ExtensionBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
/// Consume the [`ExtensionBuilder`] and return an [`Extension`].
|
||||
pub fn take(self) -> Extension {
|
||||
let js_files = Some(self.js);
|
||||
let esm_files = Some(self.esm);
|
||||
let ops = Some(self.ops);
|
||||
let deps = Some(self.deps);
|
||||
Extension {
|
||||
js_files,
|
||||
esm_files,
|
||||
esm_entry_point: self.esm_entry_point,
|
||||
ops,
|
||||
opstate_fn: self.state,
|
||||
middleware_fn: self.middleware,
|
||||
event_loop_middleware: self.event_loop_middleware,
|
||||
initialized: false,
|
||||
enabled: true,
|
||||
name: self.name,
|
||||
deps,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build(&mut self) -> Extension {
|
||||
let js_files = Some(std::mem::take(&mut self.js));
|
||||
let esm_files = Some(std::mem::take(&mut self.esm));
|
||||
|
|
|
@ -2731,14 +2731,14 @@ pub mod tests {
|
|||
deno_core::extension!(
|
||||
test_ext,
|
||||
ops = [op_test],
|
||||
config = {
|
||||
options = {
|
||||
mode: Mode,
|
||||
dispatch_count: Arc<AtomicUsize>,
|
||||
},
|
||||
state = |state, mode, dispatch_count| {
|
||||
state = |state, options| {
|
||||
state.put(TestState {
|
||||
mode,
|
||||
dispatch_count
|
||||
mode: options.mode,
|
||||
dispatch_count: options.dispatch_count
|
||||
})
|
||||
}
|
||||
);
|
||||
|
|
|
@ -114,13 +114,13 @@ deno_core::extension!(deno_broadcast_channel,
|
|||
op_broadcast_recv<BC>,
|
||||
],
|
||||
esm = [ "01_broadcast_channel.js" ],
|
||||
config = {
|
||||
options = {
|
||||
bc: BC,
|
||||
unstable: bool,
|
||||
},
|
||||
state = |state, bc, unstable| {
|
||||
state.put(bc);
|
||||
state.put(Unstable(unstable));
|
||||
state = |state, options| {
|
||||
state.put(options.bc);
|
||||
state.put(Unstable(options.unstable));
|
||||
},
|
||||
);
|
||||
|
||||
|
|
6
ext/cache/lib.rs
vendored
6
ext/cache/lib.rs
vendored
|
@ -32,11 +32,11 @@ deno_core::extension!(deno_cache,
|
|||
op_cache_delete<CA>,
|
||||
],
|
||||
esm = [ "01_cache.js" ],
|
||||
config = {
|
||||
options = {
|
||||
maybe_create_cache: Option<CreateCache<CA>>,
|
||||
},
|
||||
state = |state, maybe_create_cache| {
|
||||
if let Some(create_cache) = maybe_create_cache {
|
||||
state = |state, options| {
|
||||
if let Some(create_cache) = options.maybe_create_cache {
|
||||
state.put(create_cache);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -104,11 +104,11 @@ deno_core::extension!(deno_crypto,
|
|||
x25519::op_export_pkcs8_x25519,
|
||||
],
|
||||
esm = [ "00_crypto.js", "01_webidl.js" ],
|
||||
config = {
|
||||
options = {
|
||||
maybe_seed: Option<u64>,
|
||||
},
|
||||
state = |state, maybe_seed| {
|
||||
if let Some(seed) = maybe_seed {
|
||||
state = |state, options| {
|
||||
if let Some(seed) = options.maybe_seed {
|
||||
state.put(StdRng::seed_from_u64(seed));
|
||||
}
|
||||
},
|
||||
|
|
|
@ -107,19 +107,19 @@ deno_core::extension!(deno_fetch,
|
|||
"23_response.js",
|
||||
"26_fetch.js"
|
||||
],
|
||||
config = {
|
||||
options = {
|
||||
options: Options,
|
||||
},
|
||||
state = |state, options| {
|
||||
state.put::<Options>(options.clone());
|
||||
state.put::<Options>(options.options.clone());
|
||||
state.put::<reqwest::Client>({
|
||||
create_http_client(
|
||||
options.user_agent,
|
||||
options.root_cert_store,
|
||||
options.options.user_agent,
|
||||
options.options.root_cert_store,
|
||||
vec![],
|
||||
options.proxy,
|
||||
options.unsafely_ignore_certificate_errors,
|
||||
options.client_cert_chain_and_key
|
||||
options.options.proxy,
|
||||
options.options.unsafely_ignore_certificate_errors,
|
||||
options.options.client_cert_chain_and_key
|
||||
)
|
||||
.unwrap()
|
||||
});
|
||||
|
|
|
@ -112,12 +112,12 @@ deno_core::extension!(deno_ffi,
|
|||
op_ffi_unsafe_callback_ref,
|
||||
],
|
||||
esm = [ "00_ffi.js" ],
|
||||
config = {
|
||||
options = {
|
||||
unstable: bool,
|
||||
},
|
||||
state = |state, unstable| {
|
||||
state = |state, options| {
|
||||
// Stolen from deno_webgpu, is there a better option?
|
||||
state.put(Unstable(unstable));
|
||||
state.put(Unstable(options.unstable));
|
||||
|
||||
let (async_work_sender, async_work_receiver) =
|
||||
mpsc::unbounded::<PendingFfiAsyncWork>();
|
||||
|
|
|
@ -1559,11 +1559,11 @@ deno_core::extension!(deno_flash,
|
|||
op_try_flash_respond_chunked,
|
||||
],
|
||||
esm = [ "01_http.js" ],
|
||||
config = {
|
||||
options = {
|
||||
unstable: bool,
|
||||
},
|
||||
state = |state, unstable| {
|
||||
state.put(Unstable(unstable));
|
||||
state = |state, options| {
|
||||
state.put(Unstable(options.unstable));
|
||||
state.put(FlashContext {
|
||||
next_server_id: 0,
|
||||
join_handles: HashMap::default(),
|
||||
|
|
|
@ -180,11 +180,11 @@ deno_core::extension!(deno_fs,
|
|||
op_readfile_text_async<P>,
|
||||
],
|
||||
esm = [ "30_fs.js" ],
|
||||
config = {
|
||||
options = {
|
||||
unstable: bool
|
||||
},
|
||||
state = |state, unstable| {
|
||||
state.put(UnstableChecker { unstable });
|
||||
state = |state, options| {
|
||||
state.put(UnstableChecker { unstable: options.unstable });
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
@ -80,55 +80,53 @@ deno_core::extension!(deno_io,
|
|||
deps = [ deno_web ],
|
||||
ops = [op_read_sync, op_write_sync],
|
||||
esm = [ "12_io.js" ],
|
||||
config = {
|
||||
stdio: Rc<RefCell<Option<Stdio>>>,
|
||||
options = {
|
||||
stdio: Option<Stdio>,
|
||||
},
|
||||
middleware = |op| match op.name {
|
||||
"op_print" => op_print::decl(),
|
||||
_ => op,
|
||||
},
|
||||
state = |state, stdio| {
|
||||
let stdio = stdio
|
||||
.borrow_mut()
|
||||
.take()
|
||||
.expect("Extension only supports being used once.");
|
||||
let t = &mut state.resource_table;
|
||||
state = |state, options| {
|
||||
if let Some(stdio) = options.stdio {
|
||||
let t = &mut state.resource_table;
|
||||
|
||||
let rid = t.add(StdFileResource::stdio(
|
||||
match stdio.stdin {
|
||||
StdioPipe::Inherit => StdFileResourceInner {
|
||||
kind: StdFileResourceKind::Stdin,
|
||||
file: STDIN_HANDLE.try_clone().unwrap(),
|
||||
let rid = t.add(StdFileResource::stdio(
|
||||
match stdio.stdin {
|
||||
StdioPipe::Inherit => StdFileResourceInner {
|
||||
kind: StdFileResourceKind::Stdin,
|
||||
file: STDIN_HANDLE.try_clone().unwrap(),
|
||||
},
|
||||
StdioPipe::File(pipe) => StdFileResourceInner::file(pipe),
|
||||
},
|
||||
StdioPipe::File(pipe) => StdFileResourceInner::file(pipe),
|
||||
},
|
||||
"stdin",
|
||||
));
|
||||
assert_eq!(rid, 0, "stdin must have ResourceId 0");
|
||||
"stdin",
|
||||
));
|
||||
assert_eq!(rid, 0, "stdin must have ResourceId 0");
|
||||
|
||||
let rid = t.add(StdFileResource::stdio(
|
||||
match stdio.stdout {
|
||||
StdioPipe::Inherit => StdFileResourceInner {
|
||||
kind: StdFileResourceKind::Stdout,
|
||||
file: STDOUT_HANDLE.try_clone().unwrap(),
|
||||
let rid = t.add(StdFileResource::stdio(
|
||||
match stdio.stdout {
|
||||
StdioPipe::Inherit => StdFileResourceInner {
|
||||
kind: StdFileResourceKind::Stdout,
|
||||
file: STDOUT_HANDLE.try_clone().unwrap(),
|
||||
},
|
||||
StdioPipe::File(pipe) => StdFileResourceInner::file(pipe),
|
||||
},
|
||||
StdioPipe::File(pipe) => StdFileResourceInner::file(pipe),
|
||||
},
|
||||
"stdout",
|
||||
));
|
||||
assert_eq!(rid, 1, "stdout must have ResourceId 1");
|
||||
"stdout",
|
||||
));
|
||||
assert_eq!(rid, 1, "stdout must have ResourceId 1");
|
||||
|
||||
let rid = t.add(StdFileResource::stdio(
|
||||
match stdio.stderr {
|
||||
StdioPipe::Inherit => StdFileResourceInner {
|
||||
kind: StdFileResourceKind::Stderr,
|
||||
file: STDERR_HANDLE.try_clone().unwrap(),
|
||||
let rid = t.add(StdFileResource::stdio(
|
||||
match stdio.stderr {
|
||||
StdioPipe::Inherit => StdFileResourceInner {
|
||||
kind: StdFileResourceKind::Stderr,
|
||||
file: STDERR_HANDLE.try_clone().unwrap(),
|
||||
},
|
||||
StdioPipe::File(pipe) => StdFileResourceInner::file(pipe),
|
||||
},
|
||||
StdioPipe::File(pipe) => StdFileResourceInner::file(pipe),
|
||||
},
|
||||
"stderr",
|
||||
));
|
||||
assert_eq!(rid, 2, "stderr must have ResourceId 2");
|
||||
"stderr",
|
||||
));
|
||||
assert_eq!(rid, 2, "stderr must have ResourceId 2");
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
@ -105,18 +105,18 @@ deno_core::extension!(deno_net,
|
|||
#[cfg(unix)] ops_unix::op_net_send_unixpacket<P>,
|
||||
],
|
||||
esm = [ "01_net.js", "02_tls.js" ],
|
||||
config = {
|
||||
options = {
|
||||
root_cert_store: Option<RootCertStore>,
|
||||
unstable: bool,
|
||||
unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
||||
},
|
||||
state = |state, root_cert_store, unstable, unsafely_ignore_certificate_errors| {
|
||||
state = |state, options| {
|
||||
state.put(DefaultTlsOptions {
|
||||
root_cert_store,
|
||||
root_cert_store: options.root_cert_store,
|
||||
});
|
||||
state.put(UnstableChecker { unstable });
|
||||
state.put(UnstableChecker { unstable: options.unstable });
|
||||
state.put(UnsafelyIgnoreCertificateErrors(
|
||||
unsafely_ignore_certificate_errors,
|
||||
options.unsafely_ignore_certificate_errors,
|
||||
));
|
||||
},
|
||||
);
|
||||
|
|
|
@ -370,11 +370,11 @@ deno_core::extension!(deno_node_loading,
|
|||
ops::op_require_break_on_next_statement,
|
||||
],
|
||||
esm = ["01_node.js", "02_require.js", "module_es_shim.js"],
|
||||
config = {
|
||||
options = {
|
||||
maybe_npm_resolver: Option<Rc<dyn RequireNpmResolver>>,
|
||||
},
|
||||
state = |state, maybe_npm_resolver| {
|
||||
if let Some(npm_resolver) = maybe_npm_resolver.clone() {
|
||||
state = |state, options| {
|
||||
if let Some(npm_resolver) = options.maybe_npm_resolver {
|
||||
state.put(npm_resolver);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -109,13 +109,13 @@ deno_core::extension!(deno_web,
|
|||
"14_compression.js",
|
||||
"15_performance.js",
|
||||
],
|
||||
config = {
|
||||
options = {
|
||||
blob_store: BlobStore,
|
||||
maybe_location: Option<Url>,
|
||||
},
|
||||
state = |state, blob_store, maybe_location| {
|
||||
state.put(blob_store);
|
||||
if let Some(location) = maybe_location {
|
||||
state = |state, options| {
|
||||
state.put(options.blob_store);
|
||||
if let Some(location) = options.maybe_location {
|
||||
state.put(Location(location));
|
||||
}
|
||||
state.put(StartTime::now());
|
||||
|
|
|
@ -506,17 +506,17 @@ deno_core::extension!(deno_websocket,
|
|||
op_ws_next_event,
|
||||
],
|
||||
esm = [ "01_websocket.js", "02_websocketstream.js" ],
|
||||
config = {
|
||||
options = {
|
||||
user_agent: String,
|
||||
root_cert_store: Option<RootCertStore>,
|
||||
unsafely_ignore_certificate_errors: Option<Vec<String>>
|
||||
},
|
||||
state = |state, user_agent, root_cert_store, unsafely_ignore_certificate_errors| {
|
||||
state.put::<WsUserAgent>(WsUserAgent(user_agent));
|
||||
state = |state, options| {
|
||||
state.put::<WsUserAgent>(WsUserAgent(options.user_agent));
|
||||
state.put(UnsafelyIgnoreCertificateErrors(
|
||||
unsafely_ignore_certificate_errors,
|
||||
options.unsafely_ignore_certificate_errors,
|
||||
));
|
||||
state.put::<WsRootStore>(WsRootStore(root_cert_store));
|
||||
state.put::<WsRootStore>(WsRootStore(options.root_cert_store));
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
@ -31,11 +31,11 @@ deno_core::extension!(deno_webstorage,
|
|||
op_webstorage_iterate_keys,
|
||||
],
|
||||
esm = [ "01_webstorage.js" ],
|
||||
config = {
|
||||
options = {
|
||||
origin_storage_dir: Option<PathBuf>
|
||||
},
|
||||
state = |state, origin_storage_dir| {
|
||||
if let Some(origin_storage_dir) = origin_storage_dir {
|
||||
state = |state, options| {
|
||||
if let Some(origin_storage_dir) = options.origin_storage_dir {
|
||||
state.put(OriginStorageDir(origin_storage_dir));
|
||||
}
|
||||
},
|
||||
|
|
|
@ -17,9 +17,7 @@ mod startup_snapshot {
|
|||
use deno_core::snapshot_util::*;
|
||||
use deno_core::Extension;
|
||||
use deno_core::ExtensionFileSource;
|
||||
use std::cell::RefCell;
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
|
||||
fn transpile_ts_for_snapshotting(
|
||||
file_source: &ExtensionFileSource,
|
||||
|
@ -292,9 +290,7 @@ mod startup_snapshot {
|
|||
deno_tls::deno_tls::init_ops_and_esm(),
|
||||
deno_napi::deno_napi::init_ops_and_esm::<Permissions>(),
|
||||
deno_http::deno_http::init_ops_and_esm(),
|
||||
deno_io::deno_io::init_ops_and_esm(Rc::new(RefCell::new(Some(
|
||||
Default::default(),
|
||||
)))),
|
||||
deno_io::deno_io::init_ops_and_esm(Default::default()),
|
||||
deno_fs::deno_fs::init_ops_and_esm::<Permissions>(false),
|
||||
deno_flash::deno_flash::init_ops_and_esm::<Permissions>(false), // No --unstable
|
||||
runtime::init_ops_and_esm(),
|
||||
|
|
|
@ -42,11 +42,11 @@ deno_core::ops!(
|
|||
deno_core::extension!(
|
||||
deno_os,
|
||||
ops_fn = deno_ops,
|
||||
config = {
|
||||
options = {
|
||||
exit_code: ExitCode,
|
||||
},
|
||||
state = |state, exit_code| {
|
||||
state.put::<ExitCode>(exit_code);
|
||||
state = |state, options| {
|
||||
state.put::<ExitCode>(options.exit_code);
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@ use deno_core::OpState;
|
|||
deno_core::extension!(
|
||||
deno_runtime,
|
||||
ops = [op_main_module],
|
||||
config = { main_module: ModuleSpecifier },
|
||||
state = |state, main_module| {
|
||||
state.put::<ModuleSpecifier>(main_module);
|
||||
options = { main_module: ModuleSpecifier },
|
||||
state = |state, options| {
|
||||
state.put::<ModuleSpecifier>(options.main_module);
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -96,27 +96,27 @@ deno_core::extension!(
|
|||
op_host_recv_ctrl,
|
||||
op_host_recv_message,
|
||||
],
|
||||
config = {
|
||||
options = {
|
||||
create_web_worker_cb: Arc<CreateWebWorkerCb>,
|
||||
preload_module_cb: Arc<WorkerEventCb>,
|
||||
pre_execute_module_cb: Arc<WorkerEventCb>,
|
||||
format_js_error_fn: Option<Arc<FormatJsErrorFn>>,
|
||||
},
|
||||
state = |state, create_web_worker_cb, preload_module_cb, pre_execute_module_cb, format_js_error_fn| {
|
||||
state = |state, options| {
|
||||
state.put::<WorkersTable>(WorkersTable::default());
|
||||
state.put::<WorkerId>(WorkerId::default());
|
||||
|
||||
let create_web_worker_cb_holder =
|
||||
CreateWebWorkerCbHolder(create_web_worker_cb.clone());
|
||||
CreateWebWorkerCbHolder(options.create_web_worker_cb);
|
||||
state.put::<CreateWebWorkerCbHolder>(create_web_worker_cb_holder);
|
||||
let preload_module_cb_holder =
|
||||
PreloadModuleCbHolder(preload_module_cb.clone());
|
||||
PreloadModuleCbHolder(options.preload_module_cb);
|
||||
state.put::<PreloadModuleCbHolder>(preload_module_cb_holder);
|
||||
let pre_execute_module_cb_holder =
|
||||
PreExecuteModuleCbHolder(pre_execute_module_cb.clone());
|
||||
PreExecuteModuleCbHolder(options.pre_execute_module_cb);
|
||||
state.put::<PreExecuteModuleCbHolder>(pre_execute_module_cb_holder);
|
||||
let format_js_error_fn_holder =
|
||||
FormatJsErrorFnHolder(format_js_error_fn.clone());
|
||||
FormatJsErrorFnHolder(options.format_js_error_fn);
|
||||
state.put::<FormatJsErrorFnHolder>(format_js_error_fn_holder);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -369,15 +369,15 @@ impl WebWorker {
|
|||
mut options: WebWorkerOptions,
|
||||
) -> (Self, SendableWebWorkerHandle) {
|
||||
deno_core::extension!(deno_permissions_web_worker,
|
||||
config = {
|
||||
options = {
|
||||
permissions: PermissionsContainer,
|
||||
unstable: bool,
|
||||
enable_testing_features: bool,
|
||||
},
|
||||
state = |state, permissions, unstable, enable_testing_features| {
|
||||
state.put::<PermissionsContainer>(permissions);
|
||||
state.put(ops::UnstableChecker { unstable });
|
||||
state.put(ops::TestingFeaturesEnabled(enable_testing_features));
|
||||
state = |state, options| {
|
||||
state.put::<PermissionsContainer>(options.permissions);
|
||||
state.put(ops::UnstableChecker { unstable: options.unstable });
|
||||
state.put(ops::TestingFeaturesEnabled(options.enable_testing_features));
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -432,7 +432,7 @@ impl WebWorker {
|
|||
deno_tls::deno_tls::init_ops(),
|
||||
deno_napi::deno_napi::init_ops::<PermissionsContainer>(),
|
||||
deno_http::deno_http::init_ops(),
|
||||
deno_io::deno_io::init_ops(Rc::new(RefCell::new(Some(options.stdio)))),
|
||||
deno_io::deno_io::init_ops(Some(options.stdio)),
|
||||
deno_fs::deno_fs::init_ops::<PermissionsContainer>(unstable),
|
||||
deno_flash::deno_flash::init_ops::<PermissionsContainer>(unstable),
|
||||
deno_node::deno_node_loading::init_ops::<PermissionsContainer>(
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::pin::Pin;
|
||||
use std::rc::Rc;
|
||||
use std::sync::atomic::AtomicI32;
|
||||
|
@ -189,15 +188,15 @@ impl MainWorker {
|
|||
mut options: WorkerOptions,
|
||||
) -> Self {
|
||||
deno_core::extension!(deno_permissions_worker,
|
||||
config = {
|
||||
options = {
|
||||
permissions: PermissionsContainer,
|
||||
unstable: bool,
|
||||
enable_testing_features: bool,
|
||||
},
|
||||
state = |state, permissions, unstable, enable_testing_features| {
|
||||
state.put::<PermissionsContainer>(permissions);
|
||||
state.put(ops::UnstableChecker { unstable });
|
||||
state.put(ops::TestingFeaturesEnabled(enable_testing_features));
|
||||
state = |state, options| {
|
||||
state.put::<PermissionsContainer>(options.permissions);
|
||||
state.put(ops::UnstableChecker { unstable: options.unstable });
|
||||
state.put(ops::TestingFeaturesEnabled(options.enable_testing_features));
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -255,7 +254,7 @@ impl MainWorker {
|
|||
deno_tls::deno_tls::init_ops(),
|
||||
deno_napi::deno_napi::init_ops::<PermissionsContainer>(),
|
||||
deno_http::deno_http::init_ops(),
|
||||
deno_io::deno_io::init_ops(Rc::new(RefCell::new(Some(options.stdio)))),
|
||||
deno_io::deno_io::init_ops(Some(options.stdio)),
|
||||
deno_fs::deno_fs::init_ops::<PermissionsContainer>(unstable),
|
||||
deno_flash::deno_flash::init_ops::<PermissionsContainer>(unstable),
|
||||
deno_node::deno_node_loading::init_ops::<PermissionsContainer>(
|
||||
|
|
Loading…
Reference in a new issue