mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix: Split extension registration and snapshotting (#18098)
This commit partially reverts changes from https://github.com/denoland/deno/pull/18095. Turns out I made a mistake that became apparent when working on removing "RuntimeOptions::extensions_with_js" in a follow up.
This commit is contained in:
parent
47012bd931
commit
44e67df1cd
6 changed files with 161 additions and 354 deletions
46
cli/build.rs
46
cli/build.rs
|
@ -322,40 +322,36 @@ mod ts {
|
||||||
|
|
||||||
fn create_cli_snapshot(snapshot_path: PathBuf) {
|
fn create_cli_snapshot(snapshot_path: PathBuf) {
|
||||||
let extensions: Vec<Extension> = vec![
|
let extensions: Vec<Extension> = vec![
|
||||||
deno_webidl::init_esm(),
|
deno_webidl::init(),
|
||||||
deno_console::init_esm(),
|
deno_console::init(),
|
||||||
deno_url::init_ops_and_esm(),
|
deno_url::init_ops(),
|
||||||
deno_tls::init(),
|
deno_tls::init_ops(),
|
||||||
deno_web::init_ops_and_esm::<PermissionsContainer>(
|
deno_web::init_ops::<PermissionsContainer>(
|
||||||
deno_web::BlobStore::default(),
|
deno_web::BlobStore::default(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
),
|
),
|
||||||
deno_fetch::init_ops_and_esm::<PermissionsContainer>(Default::default()),
|
deno_fetch::init_ops::<PermissionsContainer>(Default::default()),
|
||||||
deno_cache::init_ops_and_esm::<SqliteBackedCache>(None),
|
deno_cache::init_ops::<SqliteBackedCache>(None),
|
||||||
deno_websocket::init_ops_and_esm::<PermissionsContainer>(
|
deno_websocket::init_ops::<PermissionsContainer>("".to_owned(), None, None),
|
||||||
"".to_owned(),
|
deno_webstorage::init_ops(None),
|
||||||
None,
|
deno_crypto::init_ops(None),
|
||||||
None,
|
deno_webgpu::init_ops(false),
|
||||||
),
|
deno_broadcast_channel::init_ops(
|
||||||
deno_webstorage::init_ops_and_esm(None),
|
|
||||||
deno_crypto::init_ops_and_esm(None),
|
|
||||||
deno_webgpu::init_ops_and_esm(false),
|
|
||||||
deno_broadcast_channel::init_ops_and_esm(
|
|
||||||
deno_broadcast_channel::InMemoryBroadcastChannel::default(),
|
deno_broadcast_channel::InMemoryBroadcastChannel::default(),
|
||||||
false, // No --unstable.
|
false, // No --unstable.
|
||||||
),
|
),
|
||||||
deno_io::init_ops_and_esm(Default::default()),
|
deno_io::init_ops(Default::default()),
|
||||||
deno_fs::init_ops_and_esm::<PermissionsContainer>(false),
|
deno_fs::init_ops::<PermissionsContainer>(false),
|
||||||
deno_node::init_ops_and_esm::<PermissionsContainer>(None), // No --unstable.
|
deno_node::init_ops::<PermissionsContainer>(None), // No --unstable.
|
||||||
deno_node::init_polyfill_ops_and_esm(),
|
deno_node::init_polyfill_ops(),
|
||||||
deno_ffi::init_ops_and_esm::<PermissionsContainer>(false),
|
deno_ffi::init_ops::<PermissionsContainer>(false),
|
||||||
deno_net::init_ops_and_esm::<PermissionsContainer>(
|
deno_net::init_ops::<PermissionsContainer>(
|
||||||
None, false, // No --unstable.
|
None, false, // No --unstable.
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
deno_napi::init::<PermissionsContainer>(),
|
deno_napi::init_ops::<PermissionsContainer>(),
|
||||||
deno_http::init_ops_and_esm(),
|
deno_http::init_ops(),
|
||||||
deno_flash::init_ops_and_esm::<PermissionsContainer>(false), // No --unstable
|
deno_flash::init_ops::<PermissionsContainer>(false), // No --unstable
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut esm_files = include_js_files!(
|
let mut esm_files = include_js_files!(
|
||||||
|
|
|
@ -514,7 +514,7 @@ impl Env {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init<P: NapiPermissions + 'static>() -> Extension {
|
pub fn init_ops<P: NapiPermissions + 'static>() -> Extension {
|
||||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||||
.ops(vec![op_napi_open::decl::<P>()])
|
.ops(vec![op_napi_open::decl::<P>()])
|
||||||
.event_loop_middleware(|op_state_rc, cx| {
|
.event_loop_middleware(|op_state_rc, cx| {
|
||||||
|
|
|
@ -36,7 +36,7 @@ use std::sync::Arc;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
/// This extension has no runtime apis, it only exports some shared native functions.
|
/// This extension has no runtime apis, it only exports some shared native functions.
|
||||||
pub fn init() -> Extension {
|
pub fn init_ops() -> Extension {
|
||||||
Extension::builder(env!("CARGO_PKG_NAME")).build()
|
Extension::builder(env!("CARGO_PKG_NAME")).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -254,7 +254,7 @@ mod startup_snapshot {
|
||||||
deno_webidl::init_esm(),
|
deno_webidl::init_esm(),
|
||||||
deno_console::init_esm(),
|
deno_console::init_esm(),
|
||||||
deno_url::init_ops_and_esm(),
|
deno_url::init_ops_and_esm(),
|
||||||
deno_tls::init(),
|
deno_tls::init_ops(),
|
||||||
deno_web::init_ops_and_esm::<Permissions>(
|
deno_web::init_ops_and_esm::<Permissions>(
|
||||||
deno_web::BlobStore::default(),
|
deno_web::BlobStore::default(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
|
@ -278,7 +278,7 @@ mod startup_snapshot {
|
||||||
None, false, // No --unstable.
|
None, false, // No --unstable.
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
deno_napi::init::<Permissions>(),
|
deno_napi::init_ops::<Permissions>(),
|
||||||
deno_http::init_ops_and_esm(),
|
deno_http::init_ops_and_esm(),
|
||||||
deno_io::init_ops_and_esm(Default::default()),
|
deno_io::init_ops_and_esm(Default::default()),
|
||||||
deno_fs::init_ops_and_esm::<Permissions>(false),
|
deno_fs::init_ops_and_esm::<Permissions>(false),
|
||||||
|
|
|
@ -346,18 +346,44 @@ pub struct WebWorkerOptions {
|
||||||
pub stdio: Stdio,
|
pub stdio: Stdio,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "dont_create_runtime_snapshot")]
|
impl WebWorker {
|
||||||
fn get_extensions(
|
pub fn bootstrap_from_options(
|
||||||
options: &mut WebWorkerOptions,
|
name: String,
|
||||||
unstable: bool,
|
permissions: PermissionsContainer,
|
||||||
main_module: ModuleSpecifier,
|
main_module: ModuleSpecifier,
|
||||||
) -> Vec<Extension> {
|
worker_id: WorkerId,
|
||||||
let create_cache = options.cache_storage_dir.take().map(|storage_dir| {
|
options: WebWorkerOptions,
|
||||||
|
) -> (Self, SendableWebWorkerHandle) {
|
||||||
|
let bootstrap_options = options.bootstrap.clone();
|
||||||
|
let (mut worker, handle) =
|
||||||
|
Self::from_options(name, permissions, main_module, worker_id, options);
|
||||||
|
worker.bootstrap(&bootstrap_options);
|
||||||
|
(worker, handle)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_options(
|
||||||
|
name: String,
|
||||||
|
permissions: PermissionsContainer,
|
||||||
|
main_module: ModuleSpecifier,
|
||||||
|
worker_id: WorkerId,
|
||||||
|
mut options: WebWorkerOptions,
|
||||||
|
) -> (Self, SendableWebWorkerHandle) {
|
||||||
|
// Permissions: many ops depend on this
|
||||||
|
let unstable = options.bootstrap.unstable;
|
||||||
|
let enable_testing_features = options.bootstrap.enable_testing_features;
|
||||||
|
let perm_ext = Extension::builder("deno_permissions_web_worker")
|
||||||
|
.state(move |state| {
|
||||||
|
state.put::<PermissionsContainer>(permissions.clone());
|
||||||
|
state.put(ops::UnstableChecker { unstable });
|
||||||
|
state.put(ops::TestingFeaturesEnabled(enable_testing_features));
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
let create_cache = options.cache_storage_dir.map(|storage_dir| {
|
||||||
let create_cache_fn = move || SqliteBackedCache::new(storage_dir.clone());
|
let create_cache_fn = move || SqliteBackedCache::new(storage_dir.clone());
|
||||||
CreateCache(Arc::new(create_cache_fn))
|
CreateCache(Arc::new(create_cache_fn))
|
||||||
});
|
});
|
||||||
|
|
||||||
vec![
|
let mut extensions: Vec<Extension> = vec![
|
||||||
// Web APIs
|
// Web APIs
|
||||||
deno_webidl::init(),
|
deno_webidl::init(),
|
||||||
deno_console::init(),
|
deno_console::init(),
|
||||||
|
@ -392,7 +418,7 @@ fn get_extensions(
|
||||||
deno_ffi::init_ops::<PermissionsContainer>(unstable),
|
deno_ffi::init_ops::<PermissionsContainer>(unstable),
|
||||||
// Runtime ops that are always initialized for WebWorkers
|
// Runtime ops that are always initialized for WebWorkers
|
||||||
ops::web_worker::init(),
|
ops::web_worker::init(),
|
||||||
ops::runtime::init(main_module),
|
ops::runtime::init(main_module.clone()),
|
||||||
ops::worker_host::init(
|
ops::worker_host::init(
|
||||||
options.create_web_worker_cb.clone(),
|
options.create_web_worker_cb.clone(),
|
||||||
options.preload_module_cb.clone(),
|
options.preload_module_cb.clone(),
|
||||||
|
@ -402,19 +428,16 @@ fn get_extensions(
|
||||||
// Extensions providing Deno.* features
|
// Extensions providing Deno.* features
|
||||||
ops::fs_events::init(),
|
ops::fs_events::init(),
|
||||||
deno_fs::init_ops::<PermissionsContainer>(unstable),
|
deno_fs::init_ops::<PermissionsContainer>(unstable),
|
||||||
deno_io::init_ops(std::mem::take(&mut options.stdio)),
|
deno_io::init_ops(options.stdio),
|
||||||
deno_tls::init(),
|
deno_tls::init_ops(),
|
||||||
deno_net::init_ops::<PermissionsContainer>(
|
deno_net::init_ops::<PermissionsContainer>(
|
||||||
options.root_cert_store.clone(),
|
options.root_cert_store.clone(),
|
||||||
unstable,
|
unstable,
|
||||||
options.unsafely_ignore_certificate_errors.clone(),
|
options.unsafely_ignore_certificate_errors.clone(),
|
||||||
),
|
),
|
||||||
deno_napi::init::<PermissionsContainer>(),
|
deno_napi::init_ops::<PermissionsContainer>(),
|
||||||
// TODO(bartlomieju): thes two should be conditional on `dont_create_runtime_snapshot`
|
|
||||||
// cargo feature and should use `init_polyfill_ops` or `init_polyfill_ops_and_esm`
|
|
||||||
// if the feature is enabled
|
|
||||||
deno_node::init_polyfill_ops(),
|
deno_node::init_polyfill_ops(),
|
||||||
deno_node::init_ops::<PermissionsContainer>(options.npm_resolver.take()),
|
deno_node::init_ops::<PermissionsContainer>(options.npm_resolver),
|
||||||
ops::os::init_for_worker(),
|
ops::os::init_for_worker(),
|
||||||
ops::permissions::init(),
|
ops::permissions::init(),
|
||||||
ops::process::init_ops(),
|
ops::process::init_ops(),
|
||||||
|
@ -423,127 +446,9 @@ fn get_extensions(
|
||||||
deno_http::init_ops(),
|
deno_http::init_ops(),
|
||||||
deno_flash::init_ops::<PermissionsContainer>(unstable),
|
deno_flash::init_ops::<PermissionsContainer>(unstable),
|
||||||
ops::http::init(),
|
ops::http::init(),
|
||||||
]
|
// Permissions ext (worker specific state)
|
||||||
}
|
perm_ext,
|
||||||
|
];
|
||||||
#[cfg(not(feature = "dont_create_runtime_snapshot"))]
|
|
||||||
fn get_extensions(
|
|
||||||
options: &mut WebWorkerOptions,
|
|
||||||
unstable: bool,
|
|
||||||
main_module: ModuleSpecifier,
|
|
||||||
) -> Vec<Extension> {
|
|
||||||
let create_cache = options.cache_storage_dir.take().map(|storage_dir| {
|
|
||||||
let create_cache_fn = move || SqliteBackedCache::new(storage_dir.clone());
|
|
||||||
CreateCache(Arc::new(create_cache_fn))
|
|
||||||
});
|
|
||||||
|
|
||||||
vec![
|
|
||||||
// Web APIs
|
|
||||||
deno_webidl::init_esm(),
|
|
||||||
deno_console::init_esm(),
|
|
||||||
deno_url::init_ops_and_esm(),
|
|
||||||
deno_web::init_ops_and_esm::<PermissionsContainer>(
|
|
||||||
options.blob_store.clone(),
|
|
||||||
Some(main_module.clone()),
|
|
||||||
),
|
|
||||||
deno_fetch::init_ops_and_esm::<PermissionsContainer>(deno_fetch::Options {
|
|
||||||
user_agent: options.bootstrap.user_agent.clone(),
|
|
||||||
root_cert_store: options.root_cert_store.clone(),
|
|
||||||
unsafely_ignore_certificate_errors: options
|
|
||||||
.unsafely_ignore_certificate_errors
|
|
||||||
.clone(),
|
|
||||||
file_fetch_handler: Rc::new(deno_fetch::FsFetchHandler),
|
|
||||||
..Default::default()
|
|
||||||
}),
|
|
||||||
deno_cache::init_ops_and_esm::<SqliteBackedCache>(create_cache),
|
|
||||||
deno_websocket::init_ops_and_esm::<PermissionsContainer>(
|
|
||||||
options.bootstrap.user_agent.clone(),
|
|
||||||
options.root_cert_store.clone(),
|
|
||||||
options.unsafely_ignore_certificate_errors.clone(),
|
|
||||||
),
|
|
||||||
deno_webstorage::init_ops_and_esm(None).disable(),
|
|
||||||
deno_broadcast_channel::init_ops_and_esm(
|
|
||||||
options.broadcast_channel.clone(),
|
|
||||||
unstable,
|
|
||||||
),
|
|
||||||
deno_crypto::init_ops_and_esm(options.seed),
|
|
||||||
deno_webgpu::init_ops_and_esm(unstable),
|
|
||||||
// ffi
|
|
||||||
deno_ffi::init_ops_and_esm::<PermissionsContainer>(unstable),
|
|
||||||
// Runtime ops that are always initialized for WebWorkers
|
|
||||||
ops::web_worker::init(),
|
|
||||||
ops::runtime::init(main_module),
|
|
||||||
ops::worker_host::init(
|
|
||||||
options.create_web_worker_cb.clone(),
|
|
||||||
options.preload_module_cb.clone(),
|
|
||||||
options.pre_execute_module_cb.clone(),
|
|
||||||
options.format_js_error_fn.clone(),
|
|
||||||
),
|
|
||||||
// Extensions providing Deno.* features
|
|
||||||
ops::fs_events::init(),
|
|
||||||
deno_fs::init_ops_and_esm::<PermissionsContainer>(unstable),
|
|
||||||
deno_io::init_ops_and_esm(std::mem::take(&mut options.stdio)),
|
|
||||||
deno_tls::init(),
|
|
||||||
deno_net::init_ops_and_esm::<PermissionsContainer>(
|
|
||||||
options.root_cert_store.clone(),
|
|
||||||
unstable,
|
|
||||||
options.unsafely_ignore_certificate_errors.clone(),
|
|
||||||
),
|
|
||||||
deno_napi::init::<PermissionsContainer>(),
|
|
||||||
// TODO(bartlomieju): thes two should be conditional on `dont_create_runtime_snapshot`
|
|
||||||
// cargo feature and should use `init_polyfill_ops` or `init_polyfill_ops_and_esm`
|
|
||||||
// if the feature is enabled
|
|
||||||
deno_node::init_polyfill_ops_and_esm(),
|
|
||||||
deno_node::init_ops_and_esm::<PermissionsContainer>(
|
|
||||||
options.npm_resolver.take(),
|
|
||||||
),
|
|
||||||
ops::os::init_for_worker(),
|
|
||||||
ops::permissions::init(),
|
|
||||||
ops::process::init_ops(),
|
|
||||||
ops::signal::init(),
|
|
||||||
ops::tty::init(),
|
|
||||||
deno_http::init_ops_and_esm(),
|
|
||||||
deno_flash::init_ops_and_esm::<PermissionsContainer>(unstable),
|
|
||||||
ops::http::init(),
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WebWorker {
|
|
||||||
pub fn bootstrap_from_options(
|
|
||||||
name: String,
|
|
||||||
permissions: PermissionsContainer,
|
|
||||||
main_module: ModuleSpecifier,
|
|
||||||
worker_id: WorkerId,
|
|
||||||
options: WebWorkerOptions,
|
|
||||||
) -> (Self, SendableWebWorkerHandle) {
|
|
||||||
let bootstrap_options = options.bootstrap.clone();
|
|
||||||
let (mut worker, handle) =
|
|
||||||
Self::from_options(name, permissions, main_module, worker_id, options);
|
|
||||||
worker.bootstrap(&bootstrap_options);
|
|
||||||
(worker, handle)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_options(
|
|
||||||
name: String,
|
|
||||||
permissions: PermissionsContainer,
|
|
||||||
main_module: ModuleSpecifier,
|
|
||||||
worker_id: WorkerId,
|
|
||||||
mut options: WebWorkerOptions,
|
|
||||||
) -> (Self, SendableWebWorkerHandle) {
|
|
||||||
// Permissions: many ops depend on this
|
|
||||||
let unstable = options.bootstrap.unstable;
|
|
||||||
let enable_testing_features = options.bootstrap.enable_testing_features;
|
|
||||||
let perm_ext = Extension::builder("deno_permissions_web_worker")
|
|
||||||
.state(move |state| {
|
|
||||||
state.put::<PermissionsContainer>(permissions.clone());
|
|
||||||
state.put(ops::UnstableChecker { unstable });
|
|
||||||
state.put(ops::TestingFeaturesEnabled(enable_testing_features));
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
|
|
||||||
let mut extensions =
|
|
||||||
get_extensions(&mut options, unstable, main_module.clone());
|
|
||||||
extensions.push(perm_ext);
|
|
||||||
|
|
||||||
// Append exts
|
// Append exts
|
||||||
extensions.extend(std::mem::take(&mut options.extensions));
|
extensions.extend(std::mem::take(&mut options.extensions));
|
||||||
|
|
|
@ -183,19 +183,40 @@ impl Default for WorkerOptions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "dont_create_runtime_snapshot"))]
|
impl MainWorker {
|
||||||
fn get_extensions(
|
pub fn bootstrap_from_options(
|
||||||
options: &mut WorkerOptions,
|
|
||||||
unstable: bool,
|
|
||||||
exit_code: ExitCode,
|
|
||||||
main_module: ModuleSpecifier,
|
main_module: ModuleSpecifier,
|
||||||
) -> Vec<Extension> {
|
permissions: PermissionsContainer,
|
||||||
let create_cache = options.cache_storage_dir.take().map(|storage_dir| {
|
options: WorkerOptions,
|
||||||
|
) -> Self {
|
||||||
|
let bootstrap_options = options.bootstrap.clone();
|
||||||
|
let mut worker = Self::from_options(main_module, permissions, options);
|
||||||
|
worker.bootstrap(&bootstrap_options);
|
||||||
|
worker
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_options(
|
||||||
|
main_module: ModuleSpecifier,
|
||||||
|
permissions: PermissionsContainer,
|
||||||
|
mut options: WorkerOptions,
|
||||||
|
) -> Self {
|
||||||
|
// Permissions: many ops depend on this
|
||||||
|
let unstable = options.bootstrap.unstable;
|
||||||
|
let enable_testing_features = options.bootstrap.enable_testing_features;
|
||||||
|
let perm_ext = Extension::builder("deno_permissions_worker")
|
||||||
|
.state(move |state| {
|
||||||
|
state.put::<PermissionsContainer>(permissions.clone());
|
||||||
|
state.put(ops::UnstableChecker { unstable });
|
||||||
|
state.put(ops::TestingFeaturesEnabled(enable_testing_features));
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
let exit_code = ExitCode(Arc::new(AtomicI32::new(0)));
|
||||||
|
let create_cache = options.cache_storage_dir.map(|storage_dir| {
|
||||||
let create_cache_fn = move || SqliteBackedCache::new(storage_dir.clone());
|
let create_cache_fn = move || SqliteBackedCache::new(storage_dir.clone());
|
||||||
CreateCache(Arc::new(create_cache_fn))
|
CreateCache(Arc::new(create_cache_fn))
|
||||||
});
|
});
|
||||||
|
|
||||||
vec![
|
let mut extensions = vec![
|
||||||
// Web APIs
|
// Web APIs
|
||||||
deno_webidl::init(),
|
deno_webidl::init(),
|
||||||
deno_console::init(),
|
deno_console::init(),
|
||||||
|
@ -229,7 +250,7 @@ fn get_extensions(
|
||||||
// ffi
|
// ffi
|
||||||
deno_ffi::init_ops::<PermissionsContainer>(unstable),
|
deno_ffi::init_ops::<PermissionsContainer>(unstable),
|
||||||
// Runtime ops
|
// Runtime ops
|
||||||
ops::runtime::init(main_module),
|
ops::runtime::init(main_module.clone()),
|
||||||
ops::worker_host::init(
|
ops::worker_host::init(
|
||||||
options.create_web_worker_cb.clone(),
|
options.create_web_worker_cb.clone(),
|
||||||
options.web_worker_preload_module_cb.clone(),
|
options.web_worker_preload_module_cb.clone(),
|
||||||
|
@ -238,16 +259,17 @@ fn get_extensions(
|
||||||
),
|
),
|
||||||
ops::fs_events::init(),
|
ops::fs_events::init(),
|
||||||
deno_fs::init_ops::<PermissionsContainer>(unstable),
|
deno_fs::init_ops::<PermissionsContainer>(unstable),
|
||||||
deno_io::init_ops(std::mem::take(&mut options.stdio)),
|
deno_io::init_ops(options.stdio),
|
||||||
deno_tls::init(),
|
deno_tls::init_ops(),
|
||||||
deno_net::init_ops::<PermissionsContainer>(
|
deno_net::init_ops::<PermissionsContainer>(
|
||||||
options.root_cert_store.clone(),
|
options.root_cert_store.clone(),
|
||||||
unstable,
|
unstable,
|
||||||
options.unsafely_ignore_certificate_errors.clone(),
|
options.unsafely_ignore_certificate_errors.clone(),
|
||||||
),
|
),
|
||||||
deno_napi::init::<PermissionsContainer>(),
|
deno_napi::init_ops::<PermissionsContainer>(),
|
||||||
deno_node::init_ops::<PermissionsContainer>(options.npm_resolver.take()),
|
deno_node::init_ops::<PermissionsContainer>(options.npm_resolver),
|
||||||
ops::os::init(exit_code),
|
deno_node::init_polyfill_ops(),
|
||||||
|
ops::os::init(exit_code.clone()),
|
||||||
ops::permissions::init(),
|
ops::permissions::init(),
|
||||||
ops::process::init_ops(),
|
ops::process::init_ops(),
|
||||||
ops::signal::init(),
|
ops::signal::init(),
|
||||||
|
@ -255,123 +277,7 @@ fn get_extensions(
|
||||||
deno_http::init_ops(),
|
deno_http::init_ops(),
|
||||||
deno_flash::init_ops::<PermissionsContainer>(unstable),
|
deno_flash::init_ops::<PermissionsContainer>(unstable),
|
||||||
ops::http::init(),
|
ops::http::init(),
|
||||||
deno_node::init_polyfill_ops(),
|
];
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "dont_create_runtime_snapshot")]
|
|
||||||
fn get_extensions(
|
|
||||||
options: &mut WorkerOptions,
|
|
||||||
unstable: bool,
|
|
||||||
exit_code: ExitCode,
|
|
||||||
main_module: ModuleSpecifier,
|
|
||||||
) -> Vec<Extension> {
|
|
||||||
let create_cache = options.cache_storage_dir.take().map(|storage_dir| {
|
|
||||||
let create_cache_fn = move || SqliteBackedCache::new(storage_dir.clone());
|
|
||||||
CreateCache(Arc::new(create_cache_fn))
|
|
||||||
});
|
|
||||||
|
|
||||||
vec![
|
|
||||||
// Web APIs
|
|
||||||
deno_webidl::init_esm(),
|
|
||||||
deno_console::init_esm(),
|
|
||||||
deno_url::init_ops_and_esm(),
|
|
||||||
deno_web::init_ops_and_esm::<PermissionsContainer>(
|
|
||||||
options.blob_store.clone(),
|
|
||||||
options.bootstrap.location.clone(),
|
|
||||||
),
|
|
||||||
deno_fetch::init_ops_and_esm::<PermissionsContainer>(deno_fetch::Options {
|
|
||||||
user_agent: options.bootstrap.user_agent.clone(),
|
|
||||||
root_cert_store: options.root_cert_store.clone(),
|
|
||||||
unsafely_ignore_certificate_errors: options
|
|
||||||
.unsafely_ignore_certificate_errors
|
|
||||||
.clone(),
|
|
||||||
file_fetch_handler: Rc::new(deno_fetch::FsFetchHandler),
|
|
||||||
..Default::default()
|
|
||||||
}),
|
|
||||||
deno_cache::init_ops_and_esm::<SqliteBackedCache>(create_cache),
|
|
||||||
deno_websocket::init_ops_and_esm::<PermissionsContainer>(
|
|
||||||
options.bootstrap.user_agent.clone(),
|
|
||||||
options.root_cert_store.clone(),
|
|
||||||
options.unsafely_ignore_certificate_errors.clone(),
|
|
||||||
),
|
|
||||||
deno_webstorage::init_ops_and_esm(options.origin_storage_dir.clone()),
|
|
||||||
deno_broadcast_channel::init_ops_and_esm(
|
|
||||||
options.broadcast_channel.clone(),
|
|
||||||
unstable,
|
|
||||||
),
|
|
||||||
deno_crypto::init_ops_and_esm(options.seed),
|
|
||||||
deno_webgpu::init_ops_and_esm(unstable),
|
|
||||||
// ffi
|
|
||||||
deno_ffi::init_ops_and_esm::<PermissionsContainer>(unstable),
|
|
||||||
// Runtime ops
|
|
||||||
ops::runtime::init(main_module),
|
|
||||||
ops::worker_host::init(
|
|
||||||
options.create_web_worker_cb.clone(),
|
|
||||||
options.web_worker_preload_module_cb.clone(),
|
|
||||||
options.web_worker_pre_execute_module_cb.clone(),
|
|
||||||
options.format_js_error_fn.clone(),
|
|
||||||
),
|
|
||||||
ops::fs_events::init(),
|
|
||||||
deno_fs::init_ops_and_esm::<PermissionsContainer>(unstable),
|
|
||||||
deno_io::init_ops_and_esm(std::mem::take(&mut options.stdio)),
|
|
||||||
deno_tls::init(),
|
|
||||||
deno_net::init_ops_and_esm::<PermissionsContainer>(
|
|
||||||
options.root_cert_store.clone(),
|
|
||||||
unstable,
|
|
||||||
options.unsafely_ignore_certificate_errors.clone(),
|
|
||||||
),
|
|
||||||
deno_napi::init::<PermissionsContainer>(),
|
|
||||||
deno_node::init_ops_and_esm::<PermissionsContainer>(
|
|
||||||
options.npm_resolver.take(),
|
|
||||||
),
|
|
||||||
ops::os::init(exit_code),
|
|
||||||
ops::permissions::init(),
|
|
||||||
ops::process::init_ops(),
|
|
||||||
ops::signal::init(),
|
|
||||||
ops::tty::init(),
|
|
||||||
deno_http::init_ops_and_esm(),
|
|
||||||
deno_flash::init_ops_and_esm::<PermissionsContainer>(unstable),
|
|
||||||
ops::http::init(),
|
|
||||||
deno_node::init_polyfill_ops_and_esm(),
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MainWorker {
|
|
||||||
pub fn bootstrap_from_options(
|
|
||||||
main_module: ModuleSpecifier,
|
|
||||||
permissions: PermissionsContainer,
|
|
||||||
options: WorkerOptions,
|
|
||||||
) -> Self {
|
|
||||||
let bootstrap_options = options.bootstrap.clone();
|
|
||||||
let mut worker = Self::from_options(main_module, permissions, options);
|
|
||||||
worker.bootstrap(&bootstrap_options);
|
|
||||||
worker
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_options(
|
|
||||||
main_module: ModuleSpecifier,
|
|
||||||
permissions: PermissionsContainer,
|
|
||||||
mut options: WorkerOptions,
|
|
||||||
) -> Self {
|
|
||||||
// Permissions: many ops depend on this
|
|
||||||
let unstable = options.bootstrap.unstable;
|
|
||||||
let enable_testing_features = options.bootstrap.enable_testing_features;
|
|
||||||
let perm_ext = Extension::builder("deno_permissions_worker")
|
|
||||||
.state(move |state| {
|
|
||||||
state.put::<PermissionsContainer>(permissions.clone());
|
|
||||||
state.put(ops::UnstableChecker { unstable });
|
|
||||||
state.put(ops::TestingFeaturesEnabled(enable_testing_features));
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
let exit_code = ExitCode(Arc::new(AtomicI32::new(0)));
|
|
||||||
|
|
||||||
let mut extensions = get_extensions(
|
|
||||||
&mut options,
|
|
||||||
unstable,
|
|
||||||
exit_code.clone(),
|
|
||||||
main_module.clone(),
|
|
||||||
);
|
|
||||||
|
|
||||||
extensions.push(perm_ext);
|
extensions.push(perm_ext);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue