mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
refactor: Split extension registration for runtime and snapshotting (#18095)
This commit splits "<ext_name>::init" functions into "init_ops" and "init_ops_and_esm". That way we don't have to construct list of ESM sources on each startup if we're running with a snapshot. In a follow up commit "deno_core" will be changed to not have a split between "extensions" and "extensions_with_js" - it will be embedders' responsibility to pass appropriately configured extensions. Prerequisite for https://github.com/denoland/deno/pull/18080
This commit is contained in:
parent
99da8a69e7
commit
8f207c0f3f
26 changed files with 1015 additions and 496 deletions
40
cli/build.rs
40
cli/build.rs
|
@ -322,36 +322,40 @@ 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(),
|
deno_webidl::init_esm(),
|
||||||
deno_console::init(),
|
deno_console::init_esm(),
|
||||||
deno_url::init(),
|
deno_url::init_ops_and_esm(),
|
||||||
deno_tls::init(),
|
deno_tls::init(),
|
||||||
deno_web::init::<PermissionsContainer>(
|
deno_web::init_ops_and_esm::<PermissionsContainer>(
|
||||||
deno_web::BlobStore::default(),
|
deno_web::BlobStore::default(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
),
|
),
|
||||||
deno_fetch::init::<PermissionsContainer>(Default::default()),
|
deno_fetch::init_ops_and_esm::<PermissionsContainer>(Default::default()),
|
||||||
deno_cache::init::<SqliteBackedCache>(None),
|
deno_cache::init_ops_and_esm::<SqliteBackedCache>(None),
|
||||||
deno_websocket::init::<PermissionsContainer>("".to_owned(), None, None),
|
deno_websocket::init_ops_and_esm::<PermissionsContainer>(
|
||||||
deno_webstorage::init(None),
|
"".to_owned(),
|
||||||
deno_crypto::init(None),
|
None,
|
||||||
deno_webgpu::init(false),
|
None,
|
||||||
deno_broadcast_channel::init(
|
),
|
||||||
|
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(Default::default()),
|
deno_io::init_ops_and_esm(Default::default()),
|
||||||
deno_fs::init::<PermissionsContainer>(false),
|
deno_fs::init_ops_and_esm::<PermissionsContainer>(false),
|
||||||
deno_node::init::<PermissionsContainer>(None), // No --unstable.
|
deno_node::init_ops_and_esm::<PermissionsContainer>(None), // No --unstable.
|
||||||
deno_node::init_polyfill_ops_and_esm(),
|
deno_node::init_polyfill_ops_and_esm(),
|
||||||
deno_ffi::init::<PermissionsContainer>(false),
|
deno_ffi::init_ops_and_esm::<PermissionsContainer>(false),
|
||||||
deno_net::init::<PermissionsContainer>(
|
deno_net::init_ops_and_esm::<PermissionsContainer>(
|
||||||
None, false, // No --unstable.
|
None, false, // No --unstable.
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
deno_napi::init::<PermissionsContainer>(),
|
deno_napi::init::<PermissionsContainer>(),
|
||||||
deno_http::init(),
|
deno_http::init_ops_and_esm(),
|
||||||
deno_flash::init::<PermissionsContainer>(false), // No --unstable
|
deno_flash::init_ops_and_esm::<PermissionsContainer>(false), // No --unstable
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut esm_files = include_js_files!(
|
let mut esm_files = include_js_files!(
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
mod in_memory_broadcast_channel;
|
mod in_memory_broadcast_channel;
|
||||||
|
|
||||||
|
use deno_core::ExtensionBuilder;
|
||||||
pub use in_memory_broadcast_channel::InMemoryBroadcastChannel;
|
pub use in_memory_broadcast_channel::InMemoryBroadcastChannel;
|
||||||
pub use in_memory_broadcast_channel::InMemoryBroadcastChannelResource;
|
pub use in_memory_broadcast_channel::InMemoryBroadcastChannelResource;
|
||||||
|
|
||||||
|
@ -106,26 +107,45 @@ where
|
||||||
bc.recv(&resource).await
|
bc.recv(&resource).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init<BC: BroadcastChannel + 'static>(
|
fn ext() -> ExtensionBuilder {
|
||||||
bc: BC,
|
|
||||||
unstable: bool,
|
|
||||||
) -> Extension {
|
|
||||||
Extension::builder_with_deps(
|
Extension::builder_with_deps(
|
||||||
env!("CARGO_PKG_NAME"),
|
env!("CARGO_PKG_NAME"),
|
||||||
&["deno_webidl", "deno_web"],
|
&["deno_webidl", "deno_web"],
|
||||||
)
|
)
|
||||||
.esm(include_js_files!("01_broadcast_channel.js",))
|
}
|
||||||
.ops(vec![
|
|
||||||
op_broadcast_subscribe::decl::<BC>(),
|
fn ops<BC: BroadcastChannel + 'static>(
|
||||||
op_broadcast_unsubscribe::decl::<BC>(),
|
ext: &mut ExtensionBuilder,
|
||||||
op_broadcast_send::decl::<BC>(),
|
bc: BC,
|
||||||
op_broadcast_recv::decl::<BC>(),
|
unstable: bool,
|
||||||
])
|
) -> &mut ExtensionBuilder {
|
||||||
.state(move |state| {
|
ext
|
||||||
state.put(bc.clone());
|
.ops(vec![
|
||||||
state.put(Unstable(unstable));
|
op_broadcast_subscribe::decl::<BC>(),
|
||||||
})
|
op_broadcast_unsubscribe::decl::<BC>(),
|
||||||
.build()
|
op_broadcast_send::decl::<BC>(),
|
||||||
|
op_broadcast_recv::decl::<BC>(),
|
||||||
|
])
|
||||||
|
.state(move |state| {
|
||||||
|
state.put(bc.clone());
|
||||||
|
state.put(Unstable(unstable));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops_and_esm<BC: BroadcastChannel + 'static>(
|
||||||
|
bc: BC,
|
||||||
|
unstable: bool,
|
||||||
|
) -> Extension {
|
||||||
|
ops::<BC>(&mut ext(), bc, unstable)
|
||||||
|
.esm(include_js_files!("01_broadcast_channel.js",))
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops<BC: BroadcastChannel + 'static>(
|
||||||
|
bc: BC,
|
||||||
|
unstable: bool,
|
||||||
|
) -> Extension {
|
||||||
|
ops::<BC>(&mut ext(), bc, unstable).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_declaration() -> PathBuf {
|
pub fn get_declaration() -> PathBuf {
|
||||||
|
|
54
ext/cache/lib.rs
vendored
54
ext/cache/lib.rs
vendored
|
@ -13,6 +13,7 @@ use deno_core::serde::Deserialize;
|
||||||
use deno_core::serde::Serialize;
|
use deno_core::serde::Serialize;
|
||||||
use deno_core::ByteString;
|
use deno_core::ByteString;
|
||||||
use deno_core::Extension;
|
use deno_core::Extension;
|
||||||
|
use deno_core::ExtensionBuilder;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
use deno_core::Resource;
|
use deno_core::Resource;
|
||||||
use deno_core::ResourceId;
|
use deno_core::ResourceId;
|
||||||
|
@ -22,28 +23,45 @@ pub use sqlite::SqliteBackedCache;
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CreateCache<C: Cache + 'static>(pub Arc<dyn Fn() -> C>);
|
pub struct CreateCache<C: Cache + 'static>(pub Arc<dyn Fn() -> C>);
|
||||||
|
|
||||||
pub fn init<CA: Cache + 'static>(
|
fn ext() -> ExtensionBuilder {
|
||||||
maybe_create_cache: Option<CreateCache<CA>>,
|
|
||||||
) -> Extension {
|
|
||||||
Extension::builder_with_deps(
|
Extension::builder_with_deps(
|
||||||
env!("CARGO_PKG_NAME"),
|
env!("CARGO_PKG_NAME"),
|
||||||
&["deno_webidl", "deno_web", "deno_url", "deno_fetch"],
|
&["deno_webidl", "deno_web", "deno_url", "deno_fetch"],
|
||||||
)
|
)
|
||||||
.esm(include_js_files!("01_cache.js",))
|
}
|
||||||
.ops(vec![
|
|
||||||
op_cache_storage_open::decl::<CA>(),
|
fn ops<CA: Cache + 'static>(
|
||||||
op_cache_storage_has::decl::<CA>(),
|
ext: &mut ExtensionBuilder,
|
||||||
op_cache_storage_delete::decl::<CA>(),
|
maybe_create_cache: Option<CreateCache<CA>>,
|
||||||
op_cache_put::decl::<CA>(),
|
) -> &mut ExtensionBuilder {
|
||||||
op_cache_match::decl::<CA>(),
|
ext
|
||||||
op_cache_delete::decl::<CA>(),
|
.ops(vec![
|
||||||
])
|
op_cache_storage_open::decl::<CA>(),
|
||||||
.state(move |state| {
|
op_cache_storage_has::decl::<CA>(),
|
||||||
if let Some(create_cache) = maybe_create_cache.clone() {
|
op_cache_storage_delete::decl::<CA>(),
|
||||||
state.put(create_cache);
|
op_cache_put::decl::<CA>(),
|
||||||
}
|
op_cache_match::decl::<CA>(),
|
||||||
})
|
op_cache_delete::decl::<CA>(),
|
||||||
.build()
|
])
|
||||||
|
.state(move |state| {
|
||||||
|
if let Some(create_cache) = maybe_create_cache.clone() {
|
||||||
|
state.put(create_cache);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops_and_esm<CA: Cache + 'static>(
|
||||||
|
maybe_create_cache: Option<CreateCache<CA>>,
|
||||||
|
) -> Extension {
|
||||||
|
ops::<CA>(&mut ext(), maybe_create_cache)
|
||||||
|
.esm(include_js_files!("01_cache.js",))
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops<CA: Cache + 'static>(
|
||||||
|
maybe_create_cache: Option<CreateCache<CA>>,
|
||||||
|
) -> Extension {
|
||||||
|
ops::<CA>(&mut ext(), maybe_create_cache).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_declaration() -> PathBuf {
|
pub fn get_declaration() -> PathBuf {
|
||||||
|
|
|
@ -2,10 +2,18 @@
|
||||||
|
|
||||||
use deno_core::include_js_files;
|
use deno_core::include_js_files;
|
||||||
use deno_core::Extension;
|
use deno_core::Extension;
|
||||||
|
use deno_core::ExtensionBuilder;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub fn init() -> Extension {
|
fn ext() -> ExtensionBuilder {
|
||||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||||
|
}
|
||||||
|
pub fn init() -> Extension {
|
||||||
|
ext().build()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_esm() -> Extension {
|
||||||
|
ext()
|
||||||
.esm(include_js_files!("01_colors.js", "02_console.js",))
|
.esm(include_js_files!("01_colors.js", "02_console.js",))
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ use deno_core::error::type_error;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::include_js_files;
|
use deno_core::include_js_files;
|
||||||
use deno_core::op;
|
use deno_core::op;
|
||||||
|
use deno_core::ExtensionBuilder;
|
||||||
|
|
||||||
use deno_core::Extension;
|
use deno_core::Extension;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
|
@ -72,49 +73,64 @@ use crate::key::CryptoNamedCurve;
|
||||||
use crate::key::HkdfOutput;
|
use crate::key::HkdfOutput;
|
||||||
use crate::shared::RawKeyData;
|
use crate::shared::RawKeyData;
|
||||||
|
|
||||||
pub fn init(maybe_seed: Option<u64>) -> Extension {
|
fn ext() -> ExtensionBuilder {
|
||||||
Extension::builder_with_deps(
|
Extension::builder_with_deps(
|
||||||
env!("CARGO_PKG_NAME"),
|
env!("CARGO_PKG_NAME"),
|
||||||
&["deno_webidl", "deno_web"],
|
&["deno_webidl", "deno_web"],
|
||||||
)
|
)
|
||||||
.esm(include_js_files!("00_crypto.js", "01_webidl.js",))
|
}
|
||||||
.ops(vec![
|
|
||||||
op_crypto_get_random_values::decl(),
|
fn ops(
|
||||||
op_crypto_generate_key::decl(),
|
ext: &mut ExtensionBuilder,
|
||||||
op_crypto_sign_key::decl(),
|
maybe_seed: Option<u64>,
|
||||||
op_crypto_verify_key::decl(),
|
) -> &mut ExtensionBuilder {
|
||||||
op_crypto_derive_bits::decl(),
|
ext
|
||||||
op_crypto_import_key::decl(),
|
.ops(vec![
|
||||||
op_crypto_export_key::decl(),
|
op_crypto_get_random_values::decl(),
|
||||||
op_crypto_encrypt::decl(),
|
op_crypto_generate_key::decl(),
|
||||||
op_crypto_decrypt::decl(),
|
op_crypto_sign_key::decl(),
|
||||||
op_crypto_subtle_digest::decl(),
|
op_crypto_verify_key::decl(),
|
||||||
op_crypto_random_uuid::decl(),
|
op_crypto_derive_bits::decl(),
|
||||||
op_crypto_wrap_key::decl(),
|
op_crypto_import_key::decl(),
|
||||||
op_crypto_unwrap_key::decl(),
|
op_crypto_export_key::decl(),
|
||||||
op_crypto_base64url_decode::decl(),
|
op_crypto_encrypt::decl(),
|
||||||
op_crypto_base64url_encode::decl(),
|
op_crypto_decrypt::decl(),
|
||||||
x25519::op_generate_x25519_keypair::decl(),
|
op_crypto_subtle_digest::decl(),
|
||||||
x25519::op_derive_bits_x25519::decl(),
|
op_crypto_random_uuid::decl(),
|
||||||
x25519::op_import_spki_x25519::decl(),
|
op_crypto_wrap_key::decl(),
|
||||||
x25519::op_import_pkcs8_x25519::decl(),
|
op_crypto_unwrap_key::decl(),
|
||||||
ed25519::op_generate_ed25519_keypair::decl(),
|
op_crypto_base64url_decode::decl(),
|
||||||
ed25519::op_import_spki_ed25519::decl(),
|
op_crypto_base64url_encode::decl(),
|
||||||
ed25519::op_import_pkcs8_ed25519::decl(),
|
x25519::op_generate_x25519_keypair::decl(),
|
||||||
ed25519::op_sign_ed25519::decl(),
|
x25519::op_derive_bits_x25519::decl(),
|
||||||
ed25519::op_verify_ed25519::decl(),
|
x25519::op_import_spki_x25519::decl(),
|
||||||
ed25519::op_export_spki_ed25519::decl(),
|
x25519::op_import_pkcs8_x25519::decl(),
|
||||||
ed25519::op_export_pkcs8_ed25519::decl(),
|
ed25519::op_generate_ed25519_keypair::decl(),
|
||||||
ed25519::op_jwk_x_ed25519::decl(),
|
ed25519::op_import_spki_ed25519::decl(),
|
||||||
x25519::op_export_spki_x25519::decl(),
|
ed25519::op_import_pkcs8_ed25519::decl(),
|
||||||
x25519::op_export_pkcs8_x25519::decl(),
|
ed25519::op_sign_ed25519::decl(),
|
||||||
])
|
ed25519::op_verify_ed25519::decl(),
|
||||||
.state(move |state| {
|
ed25519::op_export_spki_ed25519::decl(),
|
||||||
if let Some(seed) = maybe_seed {
|
ed25519::op_export_pkcs8_ed25519::decl(),
|
||||||
state.put(StdRng::seed_from_u64(seed));
|
ed25519::op_jwk_x_ed25519::decl(),
|
||||||
}
|
x25519::op_export_spki_x25519::decl(),
|
||||||
})
|
x25519::op_export_pkcs8_x25519::decl(),
|
||||||
.build()
|
])
|
||||||
|
.state(move |state| {
|
||||||
|
if let Some(seed) = maybe_seed {
|
||||||
|
state.put(StdRng::seed_from_u64(seed));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops_and_esm(maybe_seed: Option<u64>) -> Extension {
|
||||||
|
ops(&mut ext(), maybe_seed)
|
||||||
|
.esm(include_js_files!("00_crypto.js", "01_webidl.js",))
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops(maybe_seed: Option<u64>) -> Extension {
|
||||||
|
ops(&mut ext(), maybe_seed).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
|
|
|
@ -13,6 +13,7 @@ use deno_core::futures::StreamExt;
|
||||||
use deno_core::include_js_files;
|
use deno_core::include_js_files;
|
||||||
use deno_core::op;
|
use deno_core::op;
|
||||||
use deno_core::BufView;
|
use deno_core::BufView;
|
||||||
|
use deno_core::ExtensionBuilder;
|
||||||
use deno_core::WriteOutcome;
|
use deno_core::WriteOutcome;
|
||||||
|
|
||||||
use deno_core::url::Url;
|
use deno_core::url::Url;
|
||||||
|
@ -91,43 +92,74 @@ impl Default for Options {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init<FP>(options: Options) -> Extension
|
fn ext() -> ExtensionBuilder {
|
||||||
where
|
|
||||||
FP: FetchPermissions + 'static,
|
|
||||||
{
|
|
||||||
Extension::builder_with_deps(
|
Extension::builder_with_deps(
|
||||||
env!("CARGO_PKG_NAME"),
|
env!("CARGO_PKG_NAME"),
|
||||||
&["deno_webidl", "deno_web", "deno_url", "deno_console"],
|
&["deno_webidl", "deno_web", "deno_url", "deno_console"],
|
||||||
)
|
)
|
||||||
.esm(include_js_files!(
|
}
|
||||||
"20_headers.js",
|
|
||||||
"21_formdata.js",
|
fn ops<FP>(
|
||||||
"22_body.js",
|
ext: &mut ExtensionBuilder,
|
||||||
"22_http_client.js",
|
options: Options,
|
||||||
"23_request.js",
|
) -> &mut ExtensionBuilder
|
||||||
"23_response.js",
|
where
|
||||||
"26_fetch.js",
|
FP: FetchPermissions + 'static,
|
||||||
))
|
{
|
||||||
.ops(vec![
|
ext
|
||||||
op_fetch::decl::<FP>(),
|
.ops(vec![
|
||||||
op_fetch_send::decl(),
|
op_fetch::decl::<FP>(),
|
||||||
op_fetch_custom_client::decl::<FP>(),
|
op_fetch_send::decl(),
|
||||||
])
|
op_fetch_custom_client::decl::<FP>(),
|
||||||
.state(move |state| {
|
])
|
||||||
state.put::<Options>(options.clone());
|
.state(move |state| {
|
||||||
state.put::<reqwest::Client>({
|
state.put::<Options>(options.clone());
|
||||||
create_http_client(
|
state.put::<reqwest::Client>({
|
||||||
options.user_agent.clone(),
|
create_http_client(
|
||||||
options.root_cert_store.clone(),
|
options.user_agent.clone(),
|
||||||
vec![],
|
options.root_cert_store.clone(),
|
||||||
options.proxy.clone(),
|
vec![],
|
||||||
options.unsafely_ignore_certificate_errors.clone(),
|
options.proxy.clone(),
|
||||||
options.client_cert_chain_and_key.clone(),
|
options.unsafely_ignore_certificate_errors.clone(),
|
||||||
)
|
options.client_cert_chain_and_key.clone(),
|
||||||
.unwrap()
|
)
|
||||||
});
|
.unwrap()
|
||||||
})
|
});
|
||||||
.build()
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops_and_esm<FP>(options: Options) -> Extension
|
||||||
|
where
|
||||||
|
FP: FetchPermissions + 'static,
|
||||||
|
{
|
||||||
|
ops::<FP>(&mut ext(), options)
|
||||||
|
.esm(include_js_files!(
|
||||||
|
"20_headers.js",
|
||||||
|
"21_formdata.js",
|
||||||
|
"22_body.js",
|
||||||
|
"22_http_client.js",
|
||||||
|
"23_request.js",
|
||||||
|
"23_response.js",
|
||||||
|
"26_fetch.js",
|
||||||
|
))
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops<FP>(options: Options) -> Extension
|
||||||
|
where
|
||||||
|
FP: FetchPermissions + 'static,
|
||||||
|
{
|
||||||
|
ops::<FP>(&mut ext(), options)
|
||||||
|
.esm(include_js_files!(
|
||||||
|
"20_headers.js",
|
||||||
|
"21_formdata.js",
|
||||||
|
"22_body.js",
|
||||||
|
"22_http_client.js",
|
||||||
|
"23_request.js",
|
||||||
|
"23_response.js",
|
||||||
|
"26_fetch.js",
|
||||||
|
))
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type CancelableResponseFuture =
|
pub type CancelableResponseFuture =
|
||||||
|
|
|
@ -5,6 +5,7 @@ use deno_core::futures::channel::mpsc;
|
||||||
use deno_core::include_js_files;
|
use deno_core::include_js_files;
|
||||||
use deno_core::v8;
|
use deno_core::v8;
|
||||||
use deno_core::Extension;
|
use deno_core::Extension;
|
||||||
|
use deno_core::ExtensionBuilder;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
@ -81,9 +82,15 @@ pub(crate) struct FfiState {
|
||||||
pub(crate) async_work_receiver: mpsc::UnboundedReceiver<PendingFfiAsyncWork>,
|
pub(crate) async_work_receiver: mpsc::UnboundedReceiver<PendingFfiAsyncWork>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init<P: FfiPermissions + 'static>(unstable: bool) -> Extension {
|
fn ext() -> ExtensionBuilder {
|
||||||
Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_web"])
|
Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_web"])
|
||||||
.esm(include_js_files!("00_ffi.js",))
|
}
|
||||||
|
|
||||||
|
fn ops<P: FfiPermissions + 'static>(
|
||||||
|
ext: &mut ExtensionBuilder,
|
||||||
|
unstable: bool,
|
||||||
|
) -> &mut ExtensionBuilder {
|
||||||
|
ext
|
||||||
.ops(vec![
|
.ops(vec![
|
||||||
op_ffi_load::decl::<P>(),
|
op_ffi_load::decl::<P>(),
|
||||||
op_ffi_get_static::decl(),
|
op_ffi_get_static::decl(),
|
||||||
|
@ -151,5 +158,18 @@ pub fn init<P: FfiPermissions + 'static>(unstable: bool) -> Extension {
|
||||||
async_work_sender,
|
async_work_sender,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops_and_esm<P: FfiPermissions + 'static>(
|
||||||
|
unstable: bool,
|
||||||
|
) -> Extension {
|
||||||
|
ops::<P>(&mut ext(), unstable)
|
||||||
|
.esm(include_js_files!("00_ffi.js",))
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops<P: FfiPermissions + 'static>(unstable: bool) -> Extension {
|
||||||
|
ops::<P>(&mut ext(), unstable)
|
||||||
|
.esm(include_js_files!("00_ffi.js",))
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ use deno_core::ByteString;
|
||||||
use deno_core::CancelFuture;
|
use deno_core::CancelFuture;
|
||||||
use deno_core::CancelHandle;
|
use deno_core::CancelHandle;
|
||||||
use deno_core::Extension;
|
use deno_core::Extension;
|
||||||
|
use deno_core::ExtensionBuilder;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
use deno_core::StringOrBuffer;
|
use deno_core::StringOrBuffer;
|
||||||
use deno_core::ZeroCopyBuf;
|
use deno_core::ZeroCopyBuf;
|
||||||
|
@ -1526,7 +1527,7 @@ pub trait FlashPermissions {
|
||||||
) -> Result<(), AnyError>;
|
) -> Result<(), AnyError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init<P: FlashPermissions + 'static>(unstable: bool) -> Extension {
|
fn ext() -> ExtensionBuilder {
|
||||||
Extension::builder_with_deps(
|
Extension::builder_with_deps(
|
||||||
env!("CARGO_PKG_NAME"),
|
env!("CARGO_PKG_NAME"),
|
||||||
&[
|
&[
|
||||||
|
@ -1537,38 +1538,55 @@ pub fn init<P: FlashPermissions + 'static>(unstable: bool) -> Extension {
|
||||||
"deno_http",
|
"deno_http",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.esm(deno_core::include_js_files!("01_http.js",))
|
}
|
||||||
.ops(vec![
|
|
||||||
op_flash_serve::decl::<P>(),
|
fn ops<P: FlashPermissions + 'static>(
|
||||||
op_node_unstable_flash_serve::decl::<P>(),
|
ext: &mut ExtensionBuilder,
|
||||||
op_flash_respond::decl(),
|
unstable: bool,
|
||||||
op_flash_respond_async::decl(),
|
) -> &mut ExtensionBuilder {
|
||||||
op_flash_respond_chunked::decl(),
|
ext
|
||||||
op_flash_method::decl(),
|
.ops(vec![
|
||||||
op_flash_path::decl(),
|
op_flash_serve::decl::<P>(),
|
||||||
op_flash_headers::decl(),
|
op_node_unstable_flash_serve::decl::<P>(),
|
||||||
op_flash_addr::decl(),
|
op_flash_respond::decl(),
|
||||||
op_flash_next::decl(),
|
op_flash_respond_async::decl(),
|
||||||
op_flash_next_server::decl(),
|
op_flash_respond_chunked::decl(),
|
||||||
op_flash_next_async::decl(),
|
op_flash_method::decl(),
|
||||||
op_flash_read_body::decl(),
|
op_flash_path::decl(),
|
||||||
op_flash_upgrade_websocket::decl(),
|
op_flash_headers::decl(),
|
||||||
op_flash_drive_server::decl(),
|
op_flash_addr::decl(),
|
||||||
op_flash_wait_for_listening::decl(),
|
op_flash_next::decl(),
|
||||||
op_flash_first_packet::decl(),
|
op_flash_next_server::decl(),
|
||||||
op_flash_has_body_stream::decl(),
|
op_flash_next_async::decl(),
|
||||||
op_flash_close_server::decl(),
|
op_flash_read_body::decl(),
|
||||||
op_flash_make_request::decl(),
|
op_flash_upgrade_websocket::decl(),
|
||||||
op_flash_write_resource::decl(),
|
op_flash_drive_server::decl(),
|
||||||
op_try_flash_respond_chunked::decl(),
|
op_flash_wait_for_listening::decl(),
|
||||||
])
|
op_flash_first_packet::decl(),
|
||||||
.state(move |op_state| {
|
op_flash_has_body_stream::decl(),
|
||||||
op_state.put(Unstable(unstable));
|
op_flash_close_server::decl(),
|
||||||
op_state.put(FlashContext {
|
op_flash_make_request::decl(),
|
||||||
next_server_id: 0,
|
op_flash_write_resource::decl(),
|
||||||
join_handles: HashMap::default(),
|
op_try_flash_respond_chunked::decl(),
|
||||||
servers: HashMap::default(),
|
])
|
||||||
});
|
.state(move |op_state| {
|
||||||
})
|
op_state.put(Unstable(unstable));
|
||||||
.build()
|
op_state.put(FlashContext {
|
||||||
|
next_server_id: 0,
|
||||||
|
join_handles: HashMap::default(),
|
||||||
|
servers: HashMap::default(),
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops_and_esm<P: FlashPermissions + 'static>(
|
||||||
|
unstable: bool,
|
||||||
|
) -> Extension {
|
||||||
|
ops::<P>(&mut ext(), unstable)
|
||||||
|
.esm(deno_core::include_js_files!("01_http.js",))
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops<P: FlashPermissions + 'static>(unstable: bool) -> Extension {
|
||||||
|
ops::<P>(&mut ext(), unstable).build()
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ use deno_core::op;
|
||||||
use deno_core::CancelFuture;
|
use deno_core::CancelFuture;
|
||||||
use deno_core::CancelHandle;
|
use deno_core::CancelHandle;
|
||||||
use deno_core::Extension;
|
use deno_core::Extension;
|
||||||
|
use deno_core::ExtensionBuilder;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
use deno_core::ResourceId;
|
use deno_core::ResourceId;
|
||||||
use deno_core::ZeroCopyBuf;
|
use deno_core::ZeroCopyBuf;
|
||||||
|
@ -117,9 +118,15 @@ use deno_core::error::generic_error;
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
use deno_core::error::not_supported;
|
use deno_core::error::not_supported;
|
||||||
|
|
||||||
pub fn init<P: FsPermissions + 'static>(unstable: bool) -> Extension {
|
fn ext() -> ExtensionBuilder {
|
||||||
Extension::builder("deno_fs")
|
Extension::builder("deno_fs")
|
||||||
.esm(include_js_files!("30_fs.js",))
|
}
|
||||||
|
|
||||||
|
fn ops<P: FsPermissions + 'static>(
|
||||||
|
ext: &mut ExtensionBuilder,
|
||||||
|
unstable: bool,
|
||||||
|
) -> &mut ExtensionBuilder {
|
||||||
|
ext
|
||||||
.state(move |state| {
|
.state(move |state| {
|
||||||
state.put(UnstableChecker { unstable });
|
state.put(UnstableChecker { unstable });
|
||||||
})
|
})
|
||||||
|
@ -184,6 +191,19 @@ pub fn init<P: FsPermissions + 'static>(unstable: bool) -> Extension {
|
||||||
op_readfile_async::decl::<P>(),
|
op_readfile_async::decl::<P>(),
|
||||||
op_readfile_text_async::decl::<P>(),
|
op_readfile_text_async::decl::<P>(),
|
||||||
])
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops_and_esm<P: FsPermissions + 'static>(
|
||||||
|
unstable: bool,
|
||||||
|
) -> Extension {
|
||||||
|
ops::<P>(&mut ext(), unstable)
|
||||||
|
.esm(include_js_files!("30_fs.js",))
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops<P: FsPermissions + 'static>(unstable: bool) -> Extension {
|
||||||
|
ops::<P>(&mut ext(), unstable)
|
||||||
|
.esm(include_js_files!("30_fs.js",))
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ use deno_core::CancelFuture;
|
||||||
use deno_core::CancelHandle;
|
use deno_core::CancelHandle;
|
||||||
use deno_core::CancelTryFuture;
|
use deno_core::CancelTryFuture;
|
||||||
use deno_core::Extension;
|
use deno_core::Extension;
|
||||||
|
use deno_core::ExtensionBuilder;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
use deno_core::RcRef;
|
use deno_core::RcRef;
|
||||||
use deno_core::Resource;
|
use deno_core::Resource;
|
||||||
|
@ -77,13 +78,15 @@ use crate::reader_stream::ShutdownHandle;
|
||||||
pub mod compressible;
|
pub mod compressible;
|
||||||
mod reader_stream;
|
mod reader_stream;
|
||||||
|
|
||||||
pub fn init() -> Extension {
|
fn ext() -> ExtensionBuilder {
|
||||||
Extension::builder_with_deps(
|
Extension::builder_with_deps(
|
||||||
env!("CARGO_PKG_NAME"),
|
env!("CARGO_PKG_NAME"),
|
||||||
&["deno_web", "deno_net", "deno_fetch", "deno_websocket"],
|
&["deno_web", "deno_net", "deno_fetch", "deno_websocket"],
|
||||||
)
|
)
|
||||||
.esm(include_js_files!("01_http.js",))
|
}
|
||||||
.ops(vec![
|
|
||||||
|
fn ops(ext: &mut ExtensionBuilder) -> &mut ExtensionBuilder {
|
||||||
|
ext.ops(vec![
|
||||||
op_http_accept::decl(),
|
op_http_accept::decl(),
|
||||||
op_http_write_headers::decl(),
|
op_http_write_headers::decl(),
|
||||||
op_http_headers::decl(),
|
op_http_headers::decl(),
|
||||||
|
@ -93,7 +96,16 @@ pub fn init() -> Extension {
|
||||||
op_http_websocket_accept_header::decl(),
|
op_http_websocket_accept_header::decl(),
|
||||||
op_http_upgrade_websocket::decl(),
|
op_http_upgrade_websocket::decl(),
|
||||||
])
|
])
|
||||||
.build()
|
}
|
||||||
|
|
||||||
|
pub fn init_ops_and_esm() -> Extension {
|
||||||
|
ops(&mut ext())
|
||||||
|
.esm(include_js_files!("01_http.js",))
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops() -> Extension {
|
||||||
|
ops(&mut ext()).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum HttpSocketAddr {
|
pub enum HttpSocketAddr {
|
||||||
|
|
|
@ -13,6 +13,7 @@ use deno_core::BufView;
|
||||||
use deno_core::CancelHandle;
|
use deno_core::CancelHandle;
|
||||||
use deno_core::CancelTryFuture;
|
use deno_core::CancelTryFuture;
|
||||||
use deno_core::Extension;
|
use deno_core::Extension;
|
||||||
|
use deno_core::ExtensionBuilder;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
use deno_core::RcRef;
|
use deno_core::RcRef;
|
||||||
use deno_core::Resource;
|
use deno_core::Resource;
|
||||||
|
@ -78,13 +79,16 @@ pub static STDERR_HANDLE: Lazy<StdFile> = Lazy::new(|| {
|
||||||
unsafe { StdFile::from_raw_handle(GetStdHandle(winbase::STD_ERROR_HANDLE)) }
|
unsafe { StdFile::from_raw_handle(GetStdHandle(winbase::STD_ERROR_HANDLE)) }
|
||||||
});
|
});
|
||||||
|
|
||||||
pub fn init(stdio: Stdio) -> Extension {
|
fn ext() -> ExtensionBuilder {
|
||||||
// todo(dsheret): don't do this? Taking out the writers was necessary to prevent invalid handle panics
|
|
||||||
let stdio = Rc::new(RefCell::new(Some(stdio)));
|
|
||||||
|
|
||||||
Extension::builder_with_deps("deno_io", &["deno_web"])
|
Extension::builder_with_deps("deno_io", &["deno_web"])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ops(
|
||||||
|
ext: &mut ExtensionBuilder,
|
||||||
|
stdio: Rc<RefCell<Option<Stdio>>>,
|
||||||
|
) -> &mut ExtensionBuilder {
|
||||||
|
ext
|
||||||
.ops(vec![op_read_sync::decl(), op_write_sync::decl()])
|
.ops(vec![op_read_sync::decl(), op_write_sync::decl()])
|
||||||
.esm(include_js_files!("12_io.js",))
|
|
||||||
.middleware(|op| match op.name {
|
.middleware(|op| match op.name {
|
||||||
"op_print" => op_print::decl(),
|
"op_print" => op_print::decl(),
|
||||||
_ => op,
|
_ => op,
|
||||||
|
@ -132,9 +136,24 @@ pub fn init(stdio: Stdio) -> Extension {
|
||||||
));
|
));
|
||||||
assert_eq!(rid, 2, "stderr must have ResourceId 2");
|
assert_eq!(rid, 2, "stderr must have ResourceId 2");
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops_and_esm(stdio: Stdio) -> Extension {
|
||||||
|
// todo(dsheret): don't do this? Taking out the writers was necessary to prevent invalid handle panics
|
||||||
|
let stdio = Rc::new(RefCell::new(Some(stdio)));
|
||||||
|
|
||||||
|
ops(&mut ext(), stdio)
|
||||||
|
.esm(include_js_files!("12_io.js",))
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn init_ops(stdio: Stdio) -> Extension {
|
||||||
|
// todo(dsheret): don't do this? Taking out the writers was necessary to prevent invalid handle panics
|
||||||
|
let stdio = Rc::new(RefCell::new(Some(stdio)));
|
||||||
|
|
||||||
|
ops(&mut ext(), stdio).build()
|
||||||
|
}
|
||||||
|
|
||||||
pub enum StdioPipe {
|
pub enum StdioPipe {
|
||||||
Inherit,
|
Inherit,
|
||||||
File(StdFile),
|
File(StdFile),
|
||||||
|
|
|
@ -10,6 +10,7 @@ pub mod resolve_addr;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::include_js_files;
|
use deno_core::include_js_files;
|
||||||
use deno_core::Extension;
|
use deno_core::Extension;
|
||||||
|
use deno_core::ExtensionBuilder;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
use deno_tls::rustls::RootCertStore;
|
use deno_tls::rustls::RootCertStore;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
@ -77,24 +78,55 @@ pub struct DefaultTlsOptions {
|
||||||
/// would override previously used alias.
|
/// would override previously used alias.
|
||||||
pub struct UnsafelyIgnoreCertificateErrors(pub Option<Vec<String>>);
|
pub struct UnsafelyIgnoreCertificateErrors(pub Option<Vec<String>>);
|
||||||
|
|
||||||
pub fn init<P: NetPermissions + 'static>(
|
fn ext() -> ExtensionBuilder {
|
||||||
|
Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_web"])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ops<P: NetPermissions + 'static>(
|
||||||
|
ext: &mut ExtensionBuilder,
|
||||||
|
root_cert_store: Option<RootCertStore>,
|
||||||
|
unstable: bool,
|
||||||
|
unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
||||||
|
) -> &mut ExtensionBuilder {
|
||||||
|
let mut ops = ops::init::<P>();
|
||||||
|
ops.extend(ops_tls::init::<P>());
|
||||||
|
|
||||||
|
ext.ops(ops).state(move |state| {
|
||||||
|
state.put(DefaultTlsOptions {
|
||||||
|
root_cert_store: root_cert_store.clone(),
|
||||||
|
});
|
||||||
|
state.put(UnstableChecker { unstable });
|
||||||
|
state.put(UnsafelyIgnoreCertificateErrors(
|
||||||
|
unsafely_ignore_certificate_errors.clone(),
|
||||||
|
));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops_and_esm<P: NetPermissions + 'static>(
|
||||||
root_cert_store: Option<RootCertStore>,
|
root_cert_store: Option<RootCertStore>,
|
||||||
unstable: bool,
|
unstable: bool,
|
||||||
unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
||||||
) -> Extension {
|
) -> Extension {
|
||||||
let mut ops = ops::init::<P>();
|
ops::<P>(
|
||||||
ops.extend(ops_tls::init::<P>());
|
&mut ext(),
|
||||||
Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_web"])
|
root_cert_store,
|
||||||
.esm(include_js_files!("01_net.js", "02_tls.js",))
|
unstable,
|
||||||
.ops(ops)
|
unsafely_ignore_certificate_errors,
|
||||||
.state(move |state| {
|
)
|
||||||
state.put(DefaultTlsOptions {
|
.esm(include_js_files!("01_net.js", "02_tls.js",))
|
||||||
root_cert_store: root_cert_store.clone(),
|
.build()
|
||||||
});
|
}
|
||||||
state.put(UnstableChecker { unstable });
|
|
||||||
state.put(UnsafelyIgnoreCertificateErrors(
|
pub fn init_ops<P: NetPermissions + 'static>(
|
||||||
unsafely_ignore_certificate_errors.clone(),
|
root_cert_store: Option<RootCertStore>,
|
||||||
));
|
unstable: bool,
|
||||||
})
|
unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
||||||
.build()
|
) -> Extension {
|
||||||
|
ops::<P>(
|
||||||
|
&mut ext(),
|
||||||
|
root_cert_store,
|
||||||
|
unstable,
|
||||||
|
unsafely_ignore_certificate_errors,
|
||||||
|
)
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ use deno_core::include_js_files;
|
||||||
use deno_core::located_script_name;
|
use deno_core::located_script_name;
|
||||||
use deno_core::op;
|
use deno_core::op;
|
||||||
use deno_core::Extension;
|
use deno_core::Extension;
|
||||||
|
use deno_core::ExtensionBuilder;
|
||||||
use deno_core::JsRuntime;
|
use deno_core::JsRuntime;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
@ -95,16 +96,34 @@ fn op_node_build_os() -> String {
|
||||||
.to_string()
|
.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ext_polyfill() -> ExtensionBuilder {
|
||||||
|
Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_io", "deno_fs"])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ops_polyfill(ext: &mut ExtensionBuilder) -> &mut ExtensionBuilder {
|
||||||
|
ext.ops(vec![
|
||||||
|
crypto::op_node_create_hash::decl(),
|
||||||
|
crypto::op_node_hash_update::decl(),
|
||||||
|
crypto::op_node_hash_update_str::decl(),
|
||||||
|
crypto::op_node_hash_digest::decl(),
|
||||||
|
crypto::op_node_hash_digest_hex::decl(),
|
||||||
|
crypto::op_node_hash_clone::decl(),
|
||||||
|
crypto::op_node_private_encrypt::decl(),
|
||||||
|
crypto::op_node_private_decrypt::decl(),
|
||||||
|
crypto::op_node_public_encrypt::decl(),
|
||||||
|
winerror::op_node_sys_to_uv_error::decl(),
|
||||||
|
v8::op_v8_cached_data_version_tag::decl(),
|
||||||
|
v8::op_v8_get_heap_statistics::decl(),
|
||||||
|
idna::op_node_idna_domain_to_ascii::decl(),
|
||||||
|
idna::op_node_idna_domain_to_unicode::decl(),
|
||||||
|
idna::op_node_idna_punycode_decode::decl(),
|
||||||
|
idna::op_node_idna_punycode_encode::decl(),
|
||||||
|
op_node_build_os::decl(),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
pub fn init_polyfill_ops() -> Extension {
|
pub fn init_polyfill_ops() -> Extension {
|
||||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
ops_polyfill(&mut ext_polyfill()).build()
|
||||||
.ops(vec![
|
|
||||||
crypto::op_node_create_hash::decl(),
|
|
||||||
crypto::op_node_hash_update::decl(),
|
|
||||||
crypto::op_node_hash_digest::decl(),
|
|
||||||
crypto::op_node_hash_clone::decl(),
|
|
||||||
op_node_build_os::decl(),
|
|
||||||
])
|
|
||||||
.build()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_polyfill_ops_and_esm() -> Extension {
|
pub fn init_polyfill_ops_and_esm() -> Extension {
|
||||||
|
@ -332,40 +351,21 @@ pub fn init_polyfill_ops_and_esm() -> Extension {
|
||||||
"zlib.ts",
|
"zlib.ts",
|
||||||
);
|
);
|
||||||
|
|
||||||
Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_io", "deno_fs"])
|
ops_polyfill(&mut ext_polyfill())
|
||||||
.esm(esm_files)
|
.esm(esm_files)
|
||||||
.esm_entry_point("ext:deno_node/module_all.ts")
|
.esm_entry_point("ext:deno_node/module_all.ts")
|
||||||
.ops(vec![
|
|
||||||
crypto::op_node_create_hash::decl(),
|
|
||||||
crypto::op_node_hash_update::decl(),
|
|
||||||
crypto::op_node_hash_update_str::decl(),
|
|
||||||
crypto::op_node_hash_digest::decl(),
|
|
||||||
crypto::op_node_hash_digest_hex::decl(),
|
|
||||||
crypto::op_node_hash_clone::decl(),
|
|
||||||
crypto::op_node_private_encrypt::decl(),
|
|
||||||
crypto::op_node_private_decrypt::decl(),
|
|
||||||
crypto::op_node_public_encrypt::decl(),
|
|
||||||
winerror::op_node_sys_to_uv_error::decl(),
|
|
||||||
v8::op_v8_cached_data_version_tag::decl(),
|
|
||||||
v8::op_v8_get_heap_statistics::decl(),
|
|
||||||
idna::op_node_idna_domain_to_ascii::decl(),
|
|
||||||
idna::op_node_idna_domain_to_unicode::decl(),
|
|
||||||
idna::op_node_idna_punycode_decode::decl(),
|
|
||||||
idna::op_node_idna_punycode_encode::decl(),
|
|
||||||
op_node_build_os::decl(),
|
|
||||||
])
|
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init<P: NodePermissions + 'static>(
|
fn ext() -> ExtensionBuilder {
|
||||||
maybe_npm_resolver: Option<Rc<dyn RequireNpmResolver>>,
|
|
||||||
) -> Extension {
|
|
||||||
Extension::builder("deno_node_loading")
|
Extension::builder("deno_node_loading")
|
||||||
.esm(include_js_files!(
|
}
|
||||||
"01_node.js",
|
|
||||||
"02_require.js",
|
fn ops<P: NodePermissions + 'static>(
|
||||||
"module_es_shim.js",
|
ext: &mut ExtensionBuilder,
|
||||||
))
|
maybe_npm_resolver: Option<Rc<dyn RequireNpmResolver>>,
|
||||||
|
) -> &mut ExtensionBuilder {
|
||||||
|
ext
|
||||||
.ops(vec![
|
.ops(vec![
|
||||||
ops::op_require_init_paths::decl(),
|
ops::op_require_init_paths::decl(),
|
||||||
ops::op_require_node_module_paths::decl::<P>(),
|
ops::op_require_node_module_paths::decl::<P>(),
|
||||||
|
@ -395,9 +395,26 @@ pub fn init<P: NodePermissions + 'static>(
|
||||||
state.put(npm_resolver);
|
state.put(npm_resolver);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops_and_esm<P: NodePermissions + 'static>(
|
||||||
|
maybe_npm_resolver: Option<Rc<dyn RequireNpmResolver>>,
|
||||||
|
) -> Extension {
|
||||||
|
ops::<P>(&mut ext(), maybe_npm_resolver)
|
||||||
|
.esm(include_js_files!(
|
||||||
|
"01_node.js",
|
||||||
|
"02_require.js",
|
||||||
|
"module_es_shim.js",
|
||||||
|
))
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn init_ops<P: NodePermissions + 'static>(
|
||||||
|
maybe_npm_resolver: Option<Rc<dyn RequireNpmResolver>>,
|
||||||
|
) -> Extension {
|
||||||
|
ops::<P>(&mut ext(), maybe_npm_resolver).build()
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn initialize_runtime(
|
pub async fn initialize_runtime(
|
||||||
js_runtime: &mut JsRuntime,
|
js_runtime: &mut JsRuntime,
|
||||||
uses_local_node_modules_dir: bool,
|
uses_local_node_modules_dir: bool,
|
||||||
|
|
|
@ -11,8 +11,8 @@ use deno_core::ExtensionFileSourceCode;
|
||||||
|
|
||||||
fn setup() -> Vec<Extension> {
|
fn setup() -> Vec<Extension> {
|
||||||
vec![
|
vec![
|
||||||
deno_webidl::init(),
|
deno_webidl::init_esm(),
|
||||||
deno_url::init(),
|
deno_url::init_ops_and_esm(),
|
||||||
Extension::builder("bench_setup")
|
Extension::builder("bench_setup")
|
||||||
.esm(vec![ExtensionFileSource {
|
.esm(vec![ExtensionFileSource {
|
||||||
specifier: "ext:setup".to_string(),
|
specifier: "ext:setup".to_string(),
|
||||||
|
|
|
@ -10,6 +10,7 @@ use deno_core::url::form_urlencoded;
|
||||||
use deno_core::url::quirks;
|
use deno_core::url::quirks;
|
||||||
use deno_core::url::Url;
|
use deno_core::url::Url;
|
||||||
use deno_core::Extension;
|
use deno_core::Extension;
|
||||||
|
use deno_core::ExtensionBuilder;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
use deno_core::ZeroCopyBuf;
|
use deno_core::ZeroCopyBuf;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
@ -17,22 +18,33 @@ use std::path::PathBuf;
|
||||||
use crate::urlpattern::op_urlpattern_parse;
|
use crate::urlpattern::op_urlpattern_parse;
|
||||||
use crate::urlpattern::op_urlpattern_process_match_input;
|
use crate::urlpattern::op_urlpattern_process_match_input;
|
||||||
|
|
||||||
pub fn init() -> Extension {
|
fn ext() -> ExtensionBuilder {
|
||||||
Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_webidl"])
|
Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_webidl"])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ops(ext: &mut ExtensionBuilder) -> &mut ExtensionBuilder {
|
||||||
|
ext.ops(vec![
|
||||||
|
op_url_reparse::decl(),
|
||||||
|
op_url_parse::decl(),
|
||||||
|
op_url_get_serialization::decl(),
|
||||||
|
op_url_parse_with_base::decl(),
|
||||||
|
op_url_parse_search_params::decl(),
|
||||||
|
op_url_stringify_search_params::decl(),
|
||||||
|
op_urlpattern_parse::decl(),
|
||||||
|
op_urlpattern_process_match_input::decl(),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops_and_esm() -> Extension {
|
||||||
|
ops(&mut ext())
|
||||||
.esm(include_js_files!("00_url.js", "01_urlpattern.js",))
|
.esm(include_js_files!("00_url.js", "01_urlpattern.js",))
|
||||||
.ops(vec![
|
|
||||||
op_url_reparse::decl(),
|
|
||||||
op_url_parse::decl(),
|
|
||||||
op_url_get_serialization::decl(),
|
|
||||||
op_url_parse_with_base::decl(),
|
|
||||||
op_url_parse_search_params::decl(),
|
|
||||||
op_url_stringify_search_params::decl(),
|
|
||||||
op_urlpattern_parse::decl(),
|
|
||||||
op_urlpattern_process_match_input::decl(),
|
|
||||||
])
|
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn init_ops() -> Extension {
|
||||||
|
ops(&mut ext()).build()
|
||||||
|
}
|
||||||
|
|
||||||
/// Parse `href` with a `base_href`. Fills the out `buf` with URL components.
|
/// Parse `href` with a `base_href`. Fills the out `buf` with URL components.
|
||||||
#[op]
|
#[op]
|
||||||
pub fn op_url_parse_with_base(
|
pub fn op_url_parse_with_base(
|
||||||
|
|
|
@ -23,10 +23,10 @@ impl deno_web::TimersPermission for Permissions {
|
||||||
|
|
||||||
fn setup() -> Vec<Extension> {
|
fn setup() -> Vec<Extension> {
|
||||||
vec![
|
vec![
|
||||||
deno_webidl::init(),
|
deno_webidl::init_esm(),
|
||||||
deno_url::init(),
|
deno_url::init_ops_and_esm(),
|
||||||
deno_console::init(),
|
deno_console::init_esm(),
|
||||||
deno_web::init::<Permissions>(BlobStore::default(), None),
|
deno_web::init_ops_and_esm::<Permissions>(BlobStore::default(), None),
|
||||||
Extension::builder("bench_setup")
|
Extension::builder("bench_setup")
|
||||||
.esm(vec![ExtensionFileSource {
|
.esm(vec![ExtensionFileSource {
|
||||||
specifier: "ext:setup".to_string(),
|
specifier: "ext:setup".to_string(),
|
||||||
|
|
|
@ -21,10 +21,10 @@ impl deno_web::TimersPermission for Permissions {
|
||||||
|
|
||||||
fn setup() -> Vec<Extension> {
|
fn setup() -> Vec<Extension> {
|
||||||
vec![
|
vec![
|
||||||
deno_webidl::init(),
|
deno_webidl::init_esm(),
|
||||||
deno_url::init(),
|
deno_url::init_ops_and_esm(),
|
||||||
deno_console::init(),
|
deno_console::init_esm(),
|
||||||
deno_web::init::<Permissions>(BlobStore::default(), None),
|
deno_web::init_ops_and_esm::<Permissions>(BlobStore::default(), None),
|
||||||
Extension::builder("bench_setup")
|
Extension::builder("bench_setup")
|
||||||
.esm(vec![
|
.esm(vec![
|
||||||
ExtensionFileSource {
|
ExtensionFileSource {
|
||||||
|
|
147
ext/web/lib.rs
147
ext/web/lib.rs
|
@ -16,6 +16,7 @@ use deno_core::v8;
|
||||||
use deno_core::ByteString;
|
use deno_core::ByteString;
|
||||||
use deno_core::CancelHandle;
|
use deno_core::CancelHandle;
|
||||||
use deno_core::Extension;
|
use deno_core::Extension;
|
||||||
|
use deno_core::ExtensionBuilder;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
use deno_core::Resource;
|
use deno_core::Resource;
|
||||||
use deno_core::ResourceId;
|
use deno_core::ResourceId;
|
||||||
|
@ -57,74 +58,92 @@ use crate::timers::op_timer_handle;
|
||||||
use crate::timers::StartTime;
|
use crate::timers::StartTime;
|
||||||
pub use crate::timers::TimersPermission;
|
pub use crate::timers::TimersPermission;
|
||||||
|
|
||||||
/// Load and execute the javascript code.
|
fn ext() -> ExtensionBuilder {
|
||||||
pub fn init<P: TimersPermission + 'static>(
|
|
||||||
blob_store: BlobStore,
|
|
||||||
maybe_location: Option<Url>,
|
|
||||||
) -> Extension {
|
|
||||||
Extension::builder_with_deps(
|
Extension::builder_with_deps(
|
||||||
env!("CARGO_PKG_NAME"),
|
env!("CARGO_PKG_NAME"),
|
||||||
&["deno_webidl", "deno_console", "deno_url"],
|
&["deno_webidl", "deno_console", "deno_url"],
|
||||||
)
|
)
|
||||||
.esm(include_js_files!(
|
}
|
||||||
"00_infra.js",
|
|
||||||
"01_dom_exception.js",
|
fn ops<P: TimersPermission + 'static>(
|
||||||
"01_mimesniff.js",
|
ext: &mut ExtensionBuilder,
|
||||||
"02_event.js",
|
blob_store: BlobStore,
|
||||||
"02_structured_clone.js",
|
maybe_location: Option<Url>,
|
||||||
"02_timers.js",
|
) -> &mut ExtensionBuilder {
|
||||||
"03_abort_signal.js",
|
ext
|
||||||
"04_global_interfaces.js",
|
.ops(vec![
|
||||||
"05_base64.js",
|
op_base64_decode::decl(),
|
||||||
"06_streams.js",
|
op_base64_encode::decl(),
|
||||||
"08_text_encoding.js",
|
op_base64_atob::decl(),
|
||||||
"09_file.js",
|
op_base64_btoa::decl(),
|
||||||
"10_filereader.js",
|
op_encoding_normalize_label::decl(),
|
||||||
"11_blob_url.js",
|
op_encoding_decode_single::decl(),
|
||||||
"12_location.js",
|
op_encoding_decode_utf8::decl(),
|
||||||
"13_message_port.js",
|
op_encoding_new_decoder::decl(),
|
||||||
"14_compression.js",
|
op_encoding_decode::decl(),
|
||||||
"15_performance.js",
|
op_encoding_encode_into::decl(),
|
||||||
))
|
op_encode_binary_string::decl(),
|
||||||
.ops(vec![
|
op_blob_create_part::decl(),
|
||||||
op_base64_decode::decl(),
|
op_blob_slice_part::decl(),
|
||||||
op_base64_encode::decl(),
|
op_blob_read_part::decl(),
|
||||||
op_base64_atob::decl(),
|
op_blob_remove_part::decl(),
|
||||||
op_base64_btoa::decl(),
|
op_blob_create_object_url::decl(),
|
||||||
op_encoding_normalize_label::decl(),
|
op_blob_revoke_object_url::decl(),
|
||||||
op_encoding_decode_single::decl(),
|
op_blob_from_object_url::decl(),
|
||||||
op_encoding_decode_utf8::decl(),
|
op_message_port_create_entangled::decl(),
|
||||||
op_encoding_new_decoder::decl(),
|
op_message_port_post_message::decl(),
|
||||||
op_encoding_decode::decl(),
|
op_message_port_recv_message::decl(),
|
||||||
op_encoding_encode_into::decl(),
|
compression::op_compression_new::decl(),
|
||||||
op_encode_binary_string::decl(),
|
compression::op_compression_write::decl(),
|
||||||
op_blob_create_part::decl(),
|
compression::op_compression_finish::decl(),
|
||||||
op_blob_slice_part::decl(),
|
op_now::decl::<P>(),
|
||||||
op_blob_read_part::decl(),
|
op_timer_handle::decl(),
|
||||||
op_blob_remove_part::decl(),
|
op_cancel_handle::decl(),
|
||||||
op_blob_create_object_url::decl(),
|
op_sleep::decl(),
|
||||||
op_blob_revoke_object_url::decl(),
|
op_transfer_arraybuffer::decl(),
|
||||||
op_blob_from_object_url::decl(),
|
])
|
||||||
op_message_port_create_entangled::decl(),
|
.state(move |state| {
|
||||||
op_message_port_post_message::decl(),
|
state.put(blob_store.clone());
|
||||||
op_message_port_recv_message::decl(),
|
if let Some(location) = maybe_location.clone() {
|
||||||
compression::op_compression_new::decl(),
|
state.put(Location(location));
|
||||||
compression::op_compression_write::decl(),
|
}
|
||||||
compression::op_compression_finish::decl(),
|
state.put(StartTime::now());
|
||||||
op_now::decl::<P>(),
|
})
|
||||||
op_timer_handle::decl(),
|
}
|
||||||
op_cancel_handle::decl(),
|
|
||||||
op_sleep::decl(),
|
pub fn init_ops_and_esm<P: TimersPermission + 'static>(
|
||||||
op_transfer_arraybuffer::decl(),
|
blob_store: BlobStore,
|
||||||
])
|
maybe_location: Option<Url>,
|
||||||
.state(move |state| {
|
) -> Extension {
|
||||||
state.put(blob_store.clone());
|
ops::<P>(&mut ext(), blob_store, maybe_location)
|
||||||
if let Some(location) = maybe_location.clone() {
|
.esm(include_js_files!(
|
||||||
state.put(Location(location));
|
"00_infra.js",
|
||||||
}
|
"01_dom_exception.js",
|
||||||
state.put(StartTime::now());
|
"01_mimesniff.js",
|
||||||
})
|
"02_event.js",
|
||||||
.build()
|
"02_structured_clone.js",
|
||||||
|
"02_timers.js",
|
||||||
|
"03_abort_signal.js",
|
||||||
|
"04_global_interfaces.js",
|
||||||
|
"05_base64.js",
|
||||||
|
"06_streams.js",
|
||||||
|
"08_text_encoding.js",
|
||||||
|
"09_file.js",
|
||||||
|
"10_filereader.js",
|
||||||
|
"11_blob_url.js",
|
||||||
|
"12_location.js",
|
||||||
|
"13_message_port.js",
|
||||||
|
"14_compression.js",
|
||||||
|
"15_performance.js",
|
||||||
|
))
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops<P: TimersPermission + 'static>(
|
||||||
|
blob_store: BlobStore,
|
||||||
|
maybe_location: Option<Url>,
|
||||||
|
) -> Extension {
|
||||||
|
ops::<P>(&mut ext(), blob_store, maybe_location).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
|
|
|
@ -6,6 +6,7 @@ use deno_core::error::AnyError;
|
||||||
use deno_core::include_js_files;
|
use deno_core::include_js_files;
|
||||||
use deno_core::op;
|
use deno_core::op;
|
||||||
use deno_core::Extension;
|
use deno_core::Extension;
|
||||||
|
use deno_core::ExtensionBuilder;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
use deno_core::Resource;
|
use deno_core::Resource;
|
||||||
use deno_core::ResourceId;
|
use deno_core::ResourceId;
|
||||||
|
@ -116,21 +117,31 @@ impl Resource for WebGpuQuerySet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(unstable: bool) -> Extension {
|
fn ext() -> ExtensionBuilder {
|
||||||
Extension::builder_with_deps(
|
Extension::builder_with_deps(
|
||||||
env!("CARGO_PKG_NAME"),
|
env!("CARGO_PKG_NAME"),
|
||||||
&["deno_webidl", "deno_web"],
|
&["deno_webidl", "deno_web"],
|
||||||
)
|
)
|
||||||
.esm(include_js_files!("01_webgpu.js", "02_idl_types.js",))
|
}
|
||||||
.ops(declare_webgpu_ops())
|
|
||||||
.state(move |state| {
|
fn ops(ext: &mut ExtensionBuilder, unstable: bool) -> &mut ExtensionBuilder {
|
||||||
|
ext.ops(declare_webgpu_ops()).state(move |state| {
|
||||||
// TODO: check & possibly streamline this
|
// TODO: check & possibly streamline this
|
||||||
// Unstable might be able to be OpMiddleware
|
// Unstable might be able to be OpMiddleware
|
||||||
// let unstable_checker = state.borrow::<super::UnstableChecker>();
|
// let unstable_checker = state.borrow::<super::UnstableChecker>();
|
||||||
// let unstable = unstable_checker.unstable;
|
// let unstable = unstable_checker.unstable;
|
||||||
state.put(Unstable(unstable));
|
state.put(Unstable(unstable));
|
||||||
})
|
})
|
||||||
.build()
|
}
|
||||||
|
|
||||||
|
pub fn init_ops_and_esm(unstable: bool) -> Extension {
|
||||||
|
ops(&mut ext(), unstable)
|
||||||
|
.esm(include_js_files!("01_webgpu.js", "02_idl_types.js",))
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops(unstable: bool) -> Extension {
|
||||||
|
ops(&mut ext(), unstable).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_features(features: &wgpu_types::Features) -> Vec<&'static str> {
|
fn deserialize_features(features: &wgpu_types::Features) -> Vec<&'static str> {
|
||||||
|
|
|
@ -11,7 +11,7 @@ use deno_core::ExtensionFileSourceCode;
|
||||||
|
|
||||||
fn setup() -> Vec<Extension> {
|
fn setup() -> Vec<Extension> {
|
||||||
vec![
|
vec![
|
||||||
deno_webidl::init(),
|
deno_webidl::init_esm(),
|
||||||
Extension::builder("deno_webidl_bench")
|
Extension::builder("deno_webidl_bench")
|
||||||
.esm(vec![ExtensionFileSource {
|
.esm(vec![ExtensionFileSource {
|
||||||
specifier: "ext:setup".to_string(),
|
specifier: "ext:setup".to_string(),
|
||||||
|
|
|
@ -3,8 +3,11 @@
|
||||||
use deno_core::include_js_files;
|
use deno_core::include_js_files;
|
||||||
use deno_core::Extension;
|
use deno_core::Extension;
|
||||||
|
|
||||||
/// Load and execute the javascript code.
|
|
||||||
pub fn init() -> Extension {
|
pub fn init() -> Extension {
|
||||||
|
Extension::builder(env!("CARGO_PKG_NAME")).build()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_esm() -> Extension {
|
||||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||||
.esm(include_js_files!("00_webidl.js",))
|
.esm(include_js_files!("00_webidl.js",))
|
||||||
.build()
|
.build()
|
||||||
|
|
|
@ -9,6 +9,7 @@ use deno_core::futures::SinkExt;
|
||||||
use deno_core::futures::StreamExt;
|
use deno_core::futures::StreamExt;
|
||||||
use deno_core::include_js_files;
|
use deno_core::include_js_files;
|
||||||
use deno_core::op;
|
use deno_core::op;
|
||||||
|
use deno_core::ExtensionBuilder;
|
||||||
|
|
||||||
use deno_core::url;
|
use deno_core::url;
|
||||||
use deno_core::AsyncRefCell;
|
use deno_core::AsyncRefCell;
|
||||||
|
@ -497,33 +498,65 @@ pub async fn op_ws_next_event(
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init<P: WebSocketPermissions + 'static>(
|
fn ext() -> ExtensionBuilder {
|
||||||
|
Extension::builder_with_deps(
|
||||||
|
env!("CARGO_PKG_NAME"),
|
||||||
|
&["deno_url", "deno_webidl"],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ops<P: WebSocketPermissions + 'static>(
|
||||||
|
ext: &mut ExtensionBuilder,
|
||||||
|
user_agent: String,
|
||||||
|
root_cert_store: Option<RootCertStore>,
|
||||||
|
unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
||||||
|
) -> &mut ExtensionBuilder {
|
||||||
|
ext
|
||||||
|
.ops(vec![
|
||||||
|
op_ws_check_permission_and_cancel_handle::decl::<P>(),
|
||||||
|
op_ws_create::decl::<P>(),
|
||||||
|
op_ws_send::decl(),
|
||||||
|
op_ws_close::decl(),
|
||||||
|
op_ws_next_event::decl(),
|
||||||
|
])
|
||||||
|
.state(move |state| {
|
||||||
|
state.put::<WsUserAgent>(WsUserAgent(user_agent.clone()));
|
||||||
|
state.put(UnsafelyIgnoreCertificateErrors(
|
||||||
|
unsafely_ignore_certificate_errors.clone(),
|
||||||
|
));
|
||||||
|
state.put::<WsRootStore>(WsRootStore(root_cert_store.clone()));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops_and_esm<P: WebSocketPermissions + 'static>(
|
||||||
user_agent: String,
|
user_agent: String,
|
||||||
root_cert_store: Option<RootCertStore>,
|
root_cert_store: Option<RootCertStore>,
|
||||||
unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
||||||
) -> Extension {
|
) -> Extension {
|
||||||
Extension::builder_with_deps(
|
ops::<P>(
|
||||||
env!("CARGO_PKG_NAME"),
|
&mut ext(),
|
||||||
&["deno_url", "deno_webidl"],
|
user_agent,
|
||||||
|
root_cert_store,
|
||||||
|
unsafely_ignore_certificate_errors,
|
||||||
)
|
)
|
||||||
.esm(include_js_files!(
|
.esm(include_js_files!(
|
||||||
"01_websocket.js",
|
"01_websocket.js",
|
||||||
"02_websocketstream.js",
|
"02_websocketstream.js",
|
||||||
))
|
))
|
||||||
.ops(vec![
|
.build()
|
||||||
op_ws_check_permission_and_cancel_handle::decl::<P>(),
|
}
|
||||||
op_ws_create::decl::<P>(),
|
|
||||||
op_ws_send::decl(),
|
pub fn init_ops<P: WebSocketPermissions + 'static>(
|
||||||
op_ws_close::decl(),
|
user_agent: String,
|
||||||
op_ws_next_event::decl(),
|
root_cert_store: Option<RootCertStore>,
|
||||||
])
|
unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
||||||
.state(move |state| {
|
) -> Extension {
|
||||||
state.put::<WsUserAgent>(WsUserAgent(user_agent.clone()));
|
ops::<P>(
|
||||||
state.put(UnsafelyIgnoreCertificateErrors(
|
&mut ext(),
|
||||||
unsafely_ignore_certificate_errors.clone(),
|
user_agent,
|
||||||
));
|
root_cert_store,
|
||||||
state.put::<WsRootStore>(WsRootStore(root_cert_store.clone()));
|
unsafely_ignore_certificate_errors,
|
||||||
})
|
)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ use deno_core::error::AnyError;
|
||||||
use deno_core::include_js_files;
|
use deno_core::include_js_files;
|
||||||
use deno_core::op;
|
use deno_core::op;
|
||||||
use deno_core::Extension;
|
use deno_core::Extension;
|
||||||
|
use deno_core::ExtensionBuilder;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
use rusqlite::params;
|
use rusqlite::params;
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
|
@ -21,9 +22,15 @@ struct OriginStorageDir(PathBuf);
|
||||||
|
|
||||||
const MAX_STORAGE_BYTES: usize = 10 * 1024 * 1024;
|
const MAX_STORAGE_BYTES: usize = 10 * 1024 * 1024;
|
||||||
|
|
||||||
pub fn init(origin_storage_dir: Option<PathBuf>) -> Extension {
|
fn ext() -> ExtensionBuilder {
|
||||||
Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_webidl"])
|
Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_webidl"])
|
||||||
.esm(include_js_files!("01_webstorage.js",))
|
}
|
||||||
|
|
||||||
|
fn ops(
|
||||||
|
ext: &mut ExtensionBuilder,
|
||||||
|
origin_storage_dir: Option<PathBuf>,
|
||||||
|
) -> &mut ExtensionBuilder {
|
||||||
|
ext
|
||||||
.ops(vec![
|
.ops(vec![
|
||||||
op_webstorage_length::decl(),
|
op_webstorage_length::decl(),
|
||||||
op_webstorage_key::decl(),
|
op_webstorage_key::decl(),
|
||||||
|
@ -38,9 +45,18 @@ pub fn init(origin_storage_dir: Option<PathBuf>) -> Extension {
|
||||||
state.put(OriginStorageDir(origin_storage_dir.clone()));
|
state.put(OriginStorageDir(origin_storage_dir.clone()));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_ops_and_esm(origin_storage_dir: Option<PathBuf>) -> Extension {
|
||||||
|
ops(&mut ext(), origin_storage_dir)
|
||||||
|
.esm(include_js_files!("01_webstorage.js",))
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn init_ops(origin_storage_dir: Option<PathBuf>) -> Extension {
|
||||||
|
ops(&mut ext(), origin_storage_dir).build()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_declaration() -> PathBuf {
|
pub fn get_declaration() -> PathBuf {
|
||||||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("lib.deno_webstorage.d.ts")
|
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("lib.deno_webstorage.d.ts")
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,38 +251,42 @@ mod startup_snapshot {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut extensions_with_js: Vec<Extension> = vec![
|
let mut extensions_with_js: Vec<Extension> = vec![
|
||||||
deno_webidl::init(),
|
deno_webidl::init_esm(),
|
||||||
deno_console::init(),
|
deno_console::init_esm(),
|
||||||
deno_url::init(),
|
deno_url::init_ops_and_esm(),
|
||||||
deno_tls::init(),
|
deno_tls::init(),
|
||||||
deno_web::init::<Permissions>(
|
deno_web::init_ops_and_esm::<Permissions>(
|
||||||
deno_web::BlobStore::default(),
|
deno_web::BlobStore::default(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
),
|
),
|
||||||
deno_fetch::init::<Permissions>(Default::default()),
|
deno_fetch::init_ops_and_esm::<Permissions>(Default::default()),
|
||||||
deno_cache::init::<SqliteBackedCache>(None),
|
deno_cache::init_ops_and_esm::<SqliteBackedCache>(None),
|
||||||
deno_websocket::init::<Permissions>("".to_owned(), None, None),
|
deno_websocket::init_ops_and_esm::<Permissions>(
|
||||||
deno_webstorage::init(None),
|
"".to_owned(),
|
||||||
deno_crypto::init(None),
|
None,
|
||||||
deno_webgpu::init(false),
|
None,
|
||||||
deno_broadcast_channel::init(
|
),
|
||||||
|
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_ffi::init::<Permissions>(false),
|
deno_ffi::init_ops_and_esm::<Permissions>(false),
|
||||||
deno_net::init::<Permissions>(
|
deno_net::init_ops_and_esm::<Permissions>(
|
||||||
None, false, // No --unstable.
|
None, false, // No --unstable.
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
deno_napi::init::<Permissions>(),
|
deno_napi::init::<Permissions>(),
|
||||||
deno_http::init(),
|
deno_http::init_ops_and_esm(),
|
||||||
deno_io::init(Default::default()),
|
deno_io::init_ops_and_esm(Default::default()),
|
||||||
deno_fs::init::<Permissions>(false),
|
deno_fs::init_ops_and_esm::<Permissions>(false),
|
||||||
deno_flash::init::<Permissions>(false), // No --unstable
|
deno_flash::init_ops_and_esm::<Permissions>(false), // No --unstable
|
||||||
runtime_extension,
|
runtime_extension,
|
||||||
// FIXME(bartlomieju): these extensions are specified last, because they
|
// FIXME(bartlomieju): these extensions are specified last, because they
|
||||||
// depend on `runtime`, even though it should be other way around
|
// depend on `runtime`, even though it should be other way around
|
||||||
deno_node::init::<Permissions>(None),
|
deno_node::init_ops_and_esm::<Permissions>(None),
|
||||||
deno_node::init_polyfill_ops_and_esm(),
|
deno_node::init_polyfill_ops_and_esm(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -346,6 +346,168 @@ pub struct WebWorkerOptions {
|
||||||
pub stdio: Stdio,
|
pub stdio: Stdio,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(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(),
|
||||||
|
deno_console::init(),
|
||||||
|
deno_url::init_ops(),
|
||||||
|
deno_web::init_ops::<PermissionsContainer>(
|
||||||
|
options.blob_store.clone(),
|
||||||
|
Some(main_module.clone()),
|
||||||
|
),
|
||||||
|
deno_fetch::init_ops::<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::<SqliteBackedCache>(create_cache),
|
||||||
|
deno_websocket::init_ops::<PermissionsContainer>(
|
||||||
|
options.bootstrap.user_agent.clone(),
|
||||||
|
options.root_cert_store.clone(),
|
||||||
|
options.unsafely_ignore_certificate_errors.clone(),
|
||||||
|
),
|
||||||
|
deno_webstorage::init_ops(None).disable(),
|
||||||
|
deno_broadcast_channel::init_ops(
|
||||||
|
options.broadcast_channel.clone(),
|
||||||
|
unstable,
|
||||||
|
),
|
||||||
|
deno_crypto::init_ops(options.seed),
|
||||||
|
deno_webgpu::init_ops(unstable),
|
||||||
|
// ffi
|
||||||
|
deno_ffi::init_ops::<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::<PermissionsContainer>(unstable),
|
||||||
|
deno_io::init_ops(std::mem::take(&mut options.stdio)),
|
||||||
|
deno_tls::init(),
|
||||||
|
deno_net::init_ops::<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(),
|
||||||
|
deno_node::init_ops::<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(),
|
||||||
|
deno_flash::init_ops::<PermissionsContainer>(unstable),
|
||||||
|
ops::http::init(),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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 {
|
impl WebWorker {
|
||||||
pub fn bootstrap_from_options(
|
pub fn bootstrap_from_options(
|
||||||
name: String,
|
name: String,
|
||||||
|
@ -378,77 +540,10 @@ impl WebWorker {
|
||||||
state.put(ops::TestingFeaturesEnabled(enable_testing_features));
|
state.put(ops::TestingFeaturesEnabled(enable_testing_features));
|
||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
let create_cache = options.cache_storage_dir.map(|storage_dir| {
|
|
||||||
let create_cache_fn = move || SqliteBackedCache::new(storage_dir.clone());
|
|
||||||
CreateCache(Arc::new(create_cache_fn))
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut extensions: Vec<Extension> = vec![
|
let mut extensions =
|
||||||
// Web APIs
|
get_extensions(&mut options, unstable, main_module.clone());
|
||||||
deno_webidl::init(),
|
extensions.push(perm_ext);
|
||||||
deno_console::init(),
|
|
||||||
deno_url::init(),
|
|
||||||
deno_web::init::<PermissionsContainer>(
|
|
||||||
options.blob_store.clone(),
|
|
||||||
Some(main_module.clone()),
|
|
||||||
),
|
|
||||||
deno_fetch::init::<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::<SqliteBackedCache>(create_cache),
|
|
||||||
deno_websocket::init::<PermissionsContainer>(
|
|
||||||
options.bootstrap.user_agent.clone(),
|
|
||||||
options.root_cert_store.clone(),
|
|
||||||
options.unsafely_ignore_certificate_errors.clone(),
|
|
||||||
),
|
|
||||||
deno_webstorage::init(None).disable(),
|
|
||||||
deno_broadcast_channel::init(options.broadcast_channel.clone(), unstable),
|
|
||||||
deno_crypto::init(options.seed),
|
|
||||||
deno_webgpu::init(unstable),
|
|
||||||
// ffi
|
|
||||||
deno_ffi::init::<PermissionsContainer>(unstable),
|
|
||||||
// Runtime ops that are always initialized for WebWorkers
|
|
||||||
ops::web_worker::init(),
|
|
||||||
ops::runtime::init(main_module.clone()),
|
|
||||||
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::<PermissionsContainer>(unstable),
|
|
||||||
deno_io::init(options.stdio),
|
|
||||||
deno_tls::init(),
|
|
||||||
deno_net::init::<PermissionsContainer>(
|
|
||||||
options.root_cert_store.clone(),
|
|
||||||
unstable,
|
|
||||||
options.unsafely_ignore_certificate_errors.clone(),
|
|
||||||
),
|
|
||||||
deno_napi::init::<PermissionsContainer>(),
|
|
||||||
// TODO(bartlomieju): this 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::<PermissionsContainer>(options.npm_resolver),
|
|
||||||
ops::os::init_for_worker(),
|
|
||||||
ops::permissions::init(),
|
|
||||||
ops::process::init_ops(),
|
|
||||||
ops::signal::init(),
|
|
||||||
ops::tty::init(),
|
|
||||||
deno_http::init(),
|
|
||||||
deno_flash::init::<PermissionsContainer>(unstable),
|
|
||||||
ops::http::init(),
|
|
||||||
// Permissions ext (worker specific state)
|
|
||||||
perm_ext,
|
|
||||||
];
|
|
||||||
|
|
||||||
// Append exts
|
// Append exts
|
||||||
extensions.extend(std::mem::take(&mut options.extensions));
|
extensions.extend(std::mem::take(&mut options.extensions));
|
||||||
|
|
|
@ -183,6 +183,160 @@ impl Default for WorkerOptions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(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(),
|
||||||
|
deno_console::init(),
|
||||||
|
deno_url::init_ops(),
|
||||||
|
deno_web::init_ops::<PermissionsContainer>(
|
||||||
|
options.blob_store.clone(),
|
||||||
|
options.bootstrap.location.clone(),
|
||||||
|
),
|
||||||
|
deno_fetch::init_ops::<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::<SqliteBackedCache>(create_cache),
|
||||||
|
deno_websocket::init_ops::<PermissionsContainer>(
|
||||||
|
options.bootstrap.user_agent.clone(),
|
||||||
|
options.root_cert_store.clone(),
|
||||||
|
options.unsafely_ignore_certificate_errors.clone(),
|
||||||
|
),
|
||||||
|
deno_webstorage::init_ops(options.origin_storage_dir.clone()),
|
||||||
|
deno_broadcast_channel::init_ops(
|
||||||
|
options.broadcast_channel.clone(),
|
||||||
|
unstable,
|
||||||
|
),
|
||||||
|
deno_crypto::init_ops(options.seed),
|
||||||
|
deno_webgpu::init_ops(unstable),
|
||||||
|
// ffi
|
||||||
|
deno_ffi::init_ops::<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::<PermissionsContainer>(unstable),
|
||||||
|
deno_io::init_ops(std::mem::take(&mut options.stdio)),
|
||||||
|
deno_tls::init(),
|
||||||
|
deno_net::init_ops::<PermissionsContainer>(
|
||||||
|
options.root_cert_store.clone(),
|
||||||
|
unstable,
|
||||||
|
options.unsafely_ignore_certificate_errors.clone(),
|
||||||
|
),
|
||||||
|
deno_napi::init::<PermissionsContainer>(),
|
||||||
|
deno_node::init_ops::<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(),
|
||||||
|
deno_flash::init_ops::<PermissionsContainer>(unstable),
|
||||||
|
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 {
|
impl MainWorker {
|
||||||
pub fn bootstrap_from_options(
|
pub fn bootstrap_from_options(
|
||||||
main_module: ModuleSpecifier,
|
main_module: ModuleSpecifier,
|
||||||
|
@ -211,77 +365,13 @@ impl MainWorker {
|
||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
let exit_code = ExitCode(Arc::new(AtomicI32::new(0)));
|
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());
|
|
||||||
CreateCache(Arc::new(create_cache_fn))
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut extensions = vec![
|
let mut extensions = get_extensions(
|
||||||
// Web APIs
|
&mut options,
|
||||||
deno_webidl::init(),
|
unstable,
|
||||||
deno_console::init(),
|
exit_code.clone(),
|
||||||
deno_url::init(),
|
main_module.clone(),
|
||||||
deno_web::init::<PermissionsContainer>(
|
);
|
||||||
options.blob_store.clone(),
|
|
||||||
options.bootstrap.location.clone(),
|
|
||||||
),
|
|
||||||
deno_fetch::init::<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::<SqliteBackedCache>(create_cache),
|
|
||||||
deno_websocket::init::<PermissionsContainer>(
|
|
||||||
options.bootstrap.user_agent.clone(),
|
|
||||||
options.root_cert_store.clone(),
|
|
||||||
options.unsafely_ignore_certificate_errors.clone(),
|
|
||||||
),
|
|
||||||
deno_webstorage::init(options.origin_storage_dir.clone()),
|
|
||||||
deno_broadcast_channel::init(options.broadcast_channel.clone(), unstable),
|
|
||||||
deno_crypto::init(options.seed),
|
|
||||||
deno_webgpu::init(unstable),
|
|
||||||
// ffi
|
|
||||||
deno_ffi::init::<PermissionsContainer>(unstable),
|
|
||||||
// Runtime ops
|
|
||||||
ops::runtime::init(main_module.clone()),
|
|
||||||
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::<PermissionsContainer>(unstable),
|
|
||||||
deno_io::init(options.stdio),
|
|
||||||
deno_tls::init(),
|
|
||||||
deno_net::init::<PermissionsContainer>(
|
|
||||||
options.root_cert_store.clone(),
|
|
||||||
unstable,
|
|
||||||
options.unsafely_ignore_certificate_errors.clone(),
|
|
||||||
),
|
|
||||||
deno_napi::init::<PermissionsContainer>(),
|
|
||||||
deno_node::init::<PermissionsContainer>(options.npm_resolver),
|
|
||||||
ops::os::init(exit_code.clone()),
|
|
||||||
ops::permissions::init(),
|
|
||||||
ops::process::init_ops(),
|
|
||||||
ops::signal::init(),
|
|
||||||
ops::tty::init(),
|
|
||||||
deno_http::init(),
|
|
||||||
deno_flash::init::<PermissionsContainer>(unstable),
|
|
||||||
ops::http::init(),
|
|
||||||
];
|
|
||||||
|
|
||||||
// TODO(bartlomieju): finish this work, currently only `deno_node` is different
|
|
||||||
// as it has the most files
|
|
||||||
#[cfg(feature = "dont_create_runtime_snapshot")]
|
|
||||||
extensions.push(deno_node::init_polyfill_ops_and_esm());
|
|
||||||
|
|
||||||
#[cfg(not(feature = "dont_create_runtime_snapshot"))]
|
|
||||||
extensions.push(deno_node::init_polyfill_ops());
|
|
||||||
|
|
||||||
extensions.push(perm_ext);
|
extensions.push(perm_ext);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue