mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
feat(core): allow specifying name and dependencies of an Extension (#17301)
This commit is contained in:
parent
2be1282be4
commit
c41d4ff90e
57 changed files with 158 additions and 80 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1258,6 +1258,7 @@ dependencies = [
|
|||
"async-trait",
|
||||
"base64-simd",
|
||||
"deno_bench_util",
|
||||
"deno_console",
|
||||
"deno_core",
|
||||
"deno_url",
|
||||
"deno_webidl",
|
||||
|
|
|
@ -6,7 +6,7 @@ use deno_core::op;
|
|||
use deno_core::Extension;
|
||||
|
||||
fn setup() -> Vec<Extension> {
|
||||
vec![Extension::builder()
|
||||
vec![Extension::builder("bench_setup")
|
||||
.ops(vec![
|
||||
op_pi_json::decl(),
|
||||
op_pi_async::decl(),
|
||||
|
|
|
@ -6,7 +6,7 @@ use deno_bench_util::BenchOptions;
|
|||
use deno_core::Extension;
|
||||
|
||||
fn setup() -> Vec<Extension> {
|
||||
vec![Extension::builder()
|
||||
vec![Extension::builder("bench_setup")
|
||||
.js(vec![(
|
||||
"setup.js",
|
||||
r#"
|
||||
|
|
|
@ -238,7 +238,7 @@ mod ts {
|
|||
cargo_manifest_dir: env!("CARGO_MANIFEST_DIR"),
|
||||
snapshot_path,
|
||||
startup_snapshot: None,
|
||||
extensions: vec![Extension::builder()
|
||||
extensions: vec![Extension::builder("deno_tsc")
|
||||
.ops(vec![
|
||||
op_build_info::decl(),
|
||||
op_cwd::decl(),
|
||||
|
|
|
@ -2805,7 +2805,7 @@ fn js_runtime(performance: Arc<Performance>) -> JsRuntime {
|
|||
}
|
||||
|
||||
fn init_extension(performance: Arc<Performance>) -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder("deno_tsc")
|
||||
.ops(vec![
|
||||
op_exists::decl(),
|
||||
op_is_cancelled::decl(),
|
||||
|
|
|
@ -22,7 +22,7 @@ pub fn init(
|
|||
sender: UnboundedSender<BenchEvent>,
|
||||
filter: TestFilter,
|
||||
) -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder("deno_bench")
|
||||
.ops(vec![
|
||||
op_pledge_test_permissions::decl(),
|
||||
op_restore_test_permissions::decl(),
|
||||
|
|
|
@ -14,7 +14,7 @@ pub fn cli_exts(ps: ProcState) -> Vec<Extension> {
|
|||
}
|
||||
|
||||
fn init_proc_state(ps: ProcState) -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder("deno_cli")
|
||||
.ops(vec![op_npm_process_state::decl()])
|
||||
.state(move |state| {
|
||||
state.put(ps.clone());
|
||||
|
|
|
@ -30,7 +30,7 @@ pub fn init(
|
|||
fail_fast_tracker: FailFastTracker,
|
||||
filter: TestFilter,
|
||||
) -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder("deno_test")
|
||||
.ops(vec![
|
||||
op_pledge_test_permissions::decl(),
|
||||
op_restore_test_permissions::decl(),
|
||||
|
|
|
@ -770,7 +770,7 @@ pub fn exec(request: Request) -> Result<Response, AnyError> {
|
|||
.collect();
|
||||
let mut runtime = JsRuntime::new(RuntimeOptions {
|
||||
startup_snapshot: Some(compiler_snapshot()),
|
||||
extensions: vec![Extension::builder()
|
||||
extensions: vec![Extension::builder("deno_cli_tsc")
|
||||
.ops(vec![
|
||||
op_cwd::decl(),
|
||||
op_create_hash::decl(),
|
||||
|
|
|
@ -7,7 +7,7 @@ use deno_core::JsRuntime;
|
|||
use deno_core::RuntimeOptions;
|
||||
|
||||
fn main() {
|
||||
let my_ext = Extension::builder()
|
||||
let my_ext = Extension::builder("my_ext")
|
||||
.middleware(|op| match op.name {
|
||||
"op_print" => op.disable(),
|
||||
_ => op,
|
||||
|
|
|
@ -22,7 +22,7 @@ fn op_sum(nums: Vec<f64>) -> Result<f64, deno_core::error::AnyError> {
|
|||
|
||||
fn main() {
|
||||
// Build a deno_core::Extension providing custom ops
|
||||
let ext = Extension::builder()
|
||||
let ext = Extension::builder("my_ext")
|
||||
.ops(vec![
|
||||
// An op for summing an array of numbers
|
||||
// The op-layer automatically deserializes inputs
|
||||
|
|
|
@ -117,7 +117,7 @@ impl From<tokio::net::TcpStream> for TcpStream {
|
|||
}
|
||||
|
||||
fn create_js_runtime() -> JsRuntime {
|
||||
let ext = deno_core::Extension::builder()
|
||||
let ext = deno_core::Extension::builder("my_ext")
|
||||
.ops(vec![op_listen::decl(), op_accept::decl()])
|
||||
.build();
|
||||
|
||||
|
|
|
@ -24,8 +24,9 @@ fn main() {
|
|||
panic!("panik !!!")
|
||||
}
|
||||
|
||||
let extensions =
|
||||
vec![Extension::builder().ops(vec![op_panik::decl()]).build()];
|
||||
let extensions = vec![Extension::builder("my_ext")
|
||||
.ops(vec![op_panik::decl()])
|
||||
.build()];
|
||||
let mut rt = JsRuntime::new(RuntimeOptions {
|
||||
extensions,
|
||||
..Default::default()
|
||||
|
|
|
@ -18,7 +18,7 @@ use deno_core::*;
|
|||
type Task = Box<dyn FnOnce()>;
|
||||
|
||||
fn main() {
|
||||
let my_ext = Extension::builder()
|
||||
let my_ext = Extension::builder("my_ext")
|
||||
.ops(vec![op_schedule_task::decl()])
|
||||
.event_loop_middleware(|state_rc, cx| {
|
||||
let mut state = state_rc.borrow_mut();
|
||||
|
|
|
@ -51,7 +51,7 @@ fn op_set_wasm_mem(
|
|||
|
||||
fn main() {
|
||||
// Build a deno_core::Extension providing custom ops
|
||||
let ext = Extension::builder()
|
||||
let ext = Extension::builder("my_ext")
|
||||
.ops(vec![op_wasm::decl(), op_set_wasm_mem::decl()])
|
||||
.build();
|
||||
|
||||
|
|
|
@ -42,13 +42,39 @@ pub struct Extension {
|
|||
event_loop_middleware: Option<Box<OpEventLoopFn>>,
|
||||
initialized: bool,
|
||||
enabled: bool,
|
||||
name: &'static str,
|
||||
deps: Option<Vec<&'static str>>,
|
||||
}
|
||||
|
||||
// Note: this used to be a trait, but we "downgraded" it to a single concrete type
|
||||
// for the initial iteration, it will likely become a trait in the future
|
||||
impl Extension {
|
||||
pub fn builder() -> ExtensionBuilder {
|
||||
Default::default()
|
||||
pub fn builder(name: &'static str) -> ExtensionBuilder {
|
||||
ExtensionBuilder {
|
||||
name,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if dependencies have been loaded, and errors if either:
|
||||
/// - The extension is depending on itself or an extension with the same name.
|
||||
/// - A dependency hasn't been loaded yet.
|
||||
pub fn check_dependencies(&self, previous_exts: &[&mut Extension]) {
|
||||
if let Some(deps) = &self.deps {
|
||||
'dep_loop: for dep in deps {
|
||||
if dep == &self.name {
|
||||
panic!("Extension '{}' is either depending on itself or there is another extension with the same name", self.name);
|
||||
}
|
||||
|
||||
for ext in previous_exts {
|
||||
if dep == &ext.name {
|
||||
continue 'dep_loop;
|
||||
}
|
||||
}
|
||||
|
||||
panic!("Extension '{}' is missing dependency '{dep}'", self.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// returns JS source code to be loaded into the isolate (either at snapshotting,
|
||||
|
@ -121,9 +147,16 @@ pub struct ExtensionBuilder {
|
|||
state: Option<Box<OpStateFn>>,
|
||||
middleware: Option<Box<OpMiddlewareFn>>,
|
||||
event_loop_middleware: Option<Box<OpEventLoopFn>>,
|
||||
name: &'static str,
|
||||
deps: Vec<&'static str>,
|
||||
}
|
||||
|
||||
impl ExtensionBuilder {
|
||||
pub fn dependencies(&mut self, dependencies: Vec<&'static str>) -> &mut Self {
|
||||
self.deps.extend(dependencies);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn js(&mut self, js_files: Vec<SourcePair>) -> &mut Self {
|
||||
self.js.extend(js_files);
|
||||
self
|
||||
|
@ -161,6 +194,7 @@ impl ExtensionBuilder {
|
|||
pub fn build(&mut self) -> Extension {
|
||||
let js_files = Some(std::mem::take(&mut self.js));
|
||||
let ops = Some(std::mem::take(&mut self.ops));
|
||||
let deps = Some(std::mem::take(&mut self.deps));
|
||||
Extension {
|
||||
js_files,
|
||||
ops,
|
||||
|
@ -169,6 +203,8 @@ impl ExtensionBuilder {
|
|||
event_loop_middleware: self.event_loop_middleware.take(),
|
||||
initialized: false,
|
||||
enabled: true,
|
||||
name: self.name,
|
||||
deps,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1479,7 +1479,9 @@ import "/a.js";
|
|||
43
|
||||
}
|
||||
|
||||
let ext = Extension::builder().ops(vec![op_test::decl()]).build();
|
||||
let ext = Extension::builder("test_ext")
|
||||
.ops(vec![op_test::decl()])
|
||||
.build();
|
||||
|
||||
let mut runtime = JsRuntime::new(RuntimeOptions {
|
||||
extensions: vec![ext],
|
||||
|
|
|
@ -17,7 +17,7 @@ use std::io::{stderr, stdout, Write};
|
|||
use std::rc::Rc;
|
||||
|
||||
pub(crate) fn init_builtins() -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder("deno_builtins")
|
||||
.js(include_js_files!(
|
||||
prefix "deno:core",
|
||||
"00_primordials.js",
|
||||
|
|
|
@ -728,10 +728,9 @@ impl JsRuntime {
|
|||
/// Initializes JS of provided Extensions in the given realm
|
||||
fn init_extension_js(&mut self, realm: &JsRealm) -> Result<(), Error> {
|
||||
// Take extensions to avoid double-borrow
|
||||
let mut extensions: Vec<Extension> =
|
||||
std::mem::take(&mut self.extensions_with_js);
|
||||
for m in extensions.iter_mut() {
|
||||
let js_files = m.init_js();
|
||||
let extensions = std::mem::take(&mut self.extensions_with_js);
|
||||
for ext in &extensions {
|
||||
let js_files = ext.init_js();
|
||||
for (filename, source) in js_files {
|
||||
// TODO(@AaronO): use JsRuntime::execute_static() here to move src off heap
|
||||
realm.execute_script(self.v8_isolate(), filename, source)?;
|
||||
|
@ -752,6 +751,12 @@ impl JsRuntime {
|
|||
exts.extend(extensions);
|
||||
exts.extend(extensions_with_js);
|
||||
|
||||
for (ext, previous_exts) in
|
||||
exts.iter().enumerate().map(|(i, ext)| (ext, &exts[..i]))
|
||||
{
|
||||
ext.check_dependencies(previous_exts);
|
||||
}
|
||||
|
||||
// Middleware
|
||||
let middleware: Vec<Box<OpMiddlewareFn>> = exts
|
||||
.iter_mut()
|
||||
|
@ -2554,7 +2559,7 @@ pub mod tests {
|
|||
fn setup(mode: Mode) -> (JsRuntime, Arc<AtomicUsize>) {
|
||||
let dispatch_count = Arc::new(AtomicUsize::new(0));
|
||||
let dispatch_count2 = dispatch_count.clone();
|
||||
let ext = Extension::builder()
|
||||
let ext = Extension::builder("test_ext")
|
||||
.ops(vec![op_test::decl()])
|
||||
.state(move |state| {
|
||||
state.put(TestState {
|
||||
|
@ -2976,7 +2981,9 @@ pub mod tests {
|
|||
}
|
||||
|
||||
run_in_task(|cx| {
|
||||
let ext = Extension::builder().ops(vec![op_err::decl()]).build();
|
||||
let ext = Extension::builder("test_ext")
|
||||
.ops(vec![op_err::decl()])
|
||||
.build();
|
||||
let mut runtime = JsRuntime::new(RuntimeOptions {
|
||||
extensions: vec![ext],
|
||||
get_error_class_fn: Some(&get_error_class_name),
|
||||
|
@ -3428,7 +3435,7 @@ main();
|
|||
}
|
||||
|
||||
run_in_task(|cx| {
|
||||
let ext = Extension::builder()
|
||||
let ext = Extension::builder("test_ext")
|
||||
.ops(vec![op_err_sync::decl(), op_err_async::decl()])
|
||||
.build();
|
||||
let mut runtime = JsRuntime::new(RuntimeOptions {
|
||||
|
@ -3596,7 +3603,7 @@ assertEquals(1, notify_return_value);
|
|||
Ok(())
|
||||
}
|
||||
|
||||
let extension = Extension::builder()
|
||||
let extension = Extension::builder("test_ext")
|
||||
.ops(vec![op_async_borrow::decl()])
|
||||
.state(|state| {
|
||||
state.put(InnerState(42));
|
||||
|
@ -3631,7 +3638,7 @@ assertEquals(1, notify_return_value);
|
|||
Ok(())
|
||||
}
|
||||
|
||||
let extension = Extension::builder()
|
||||
let extension = Extension::builder("test_ext")
|
||||
.ops(vec![op_sync_serialize_object_with_numbers_as_keys::decl()])
|
||||
.build();
|
||||
|
||||
|
@ -3673,7 +3680,7 @@ Deno.core.ops.op_sync_serialize_object_with_numbers_as_keys({
|
|||
Ok(())
|
||||
}
|
||||
|
||||
let extension = Extension::builder()
|
||||
let extension = Extension::builder("test_ext")
|
||||
.ops(vec![op_async_serialize_object_with_numbers_as_keys::decl()])
|
||||
.build();
|
||||
|
||||
|
@ -3712,7 +3719,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
|
|||
Ok(())
|
||||
}
|
||||
|
||||
let extension = Extension::builder()
|
||||
let extension = Extension::builder("test_ext")
|
||||
.ops(vec![op_async_sleep::decl()])
|
||||
.build();
|
||||
|
||||
|
@ -3792,7 +3799,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
|
|||
Ok(())
|
||||
}
|
||||
|
||||
let extension = Extension::builder()
|
||||
let extension = Extension::builder("test_ext")
|
||||
.ops(vec![op_macrotask::decl(), op_next_tick::decl()])
|
||||
.build();
|
||||
|
||||
|
@ -3922,7 +3929,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
|
|||
Ok(())
|
||||
}
|
||||
|
||||
let extension = Extension::builder()
|
||||
let extension = Extension::builder("test_ext")
|
||||
.ops(vec![op_promise_reject::decl()])
|
||||
.build();
|
||||
|
||||
|
@ -3982,7 +3989,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
|
|||
Ok(())
|
||||
}
|
||||
|
||||
let extension = Extension::builder()
|
||||
let extension = Extension::builder("test_ext")
|
||||
.ops(vec![op_promise_reject::decl()])
|
||||
.build();
|
||||
|
||||
|
@ -4051,7 +4058,9 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
|
|||
Ok([(1, 2), (3, 4)].into_iter().collect()) // Maps can't have non-string keys in serde_v8
|
||||
}
|
||||
|
||||
let ext = Extension::builder().ops(vec![op_err::decl()]).build();
|
||||
let ext = Extension::builder("test_ext")
|
||||
.ops(vec![op_err::decl()])
|
||||
.build();
|
||||
let mut runtime = JsRuntime::new(RuntimeOptions {
|
||||
extensions: vec![ext],
|
||||
..Default::default()
|
||||
|
@ -4076,7 +4085,9 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
|
|||
Ok(x1 + x2 + x3 + x4)
|
||||
}
|
||||
|
||||
let ext = Extension::builder().ops(vec![op_add_4::decl()]).build();
|
||||
let ext = Extension::builder("test_ext")
|
||||
.ops(vec![op_add_4::decl()])
|
||||
.build();
|
||||
let mut runtime = JsRuntime::new(RuntimeOptions {
|
||||
extensions: vec![ext],
|
||||
..Default::default()
|
||||
|
@ -4095,7 +4106,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
|
|||
Ok(42)
|
||||
}
|
||||
|
||||
let ext = Extension::builder()
|
||||
let ext = Extension::builder("test_ext")
|
||||
.ops(vec![op_foo::decl().disable()])
|
||||
.build();
|
||||
let mut runtime = JsRuntime::new(RuntimeOptions {
|
||||
|
@ -4125,7 +4136,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
|
|||
Ok(b)
|
||||
}
|
||||
|
||||
let ext = Extension::builder()
|
||||
let ext = Extension::builder("test_ext")
|
||||
.ops(vec![op_sum_take::decl(), op_boomerang::decl()])
|
||||
.build();
|
||||
|
||||
|
@ -4193,7 +4204,7 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
|
|||
Ok(42)
|
||||
}
|
||||
|
||||
let ext = Extension::builder()
|
||||
let ext = Extension::builder("test_ext")
|
||||
.ops(vec![op_foo::decl(), op_bar::decl()])
|
||||
.middleware(|op| if op.is_unstable { op.disable() } else { op })
|
||||
.build();
|
||||
|
@ -4245,7 +4256,9 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
|
|||
}
|
||||
|
||||
let mut runtime = JsRuntime::new(RuntimeOptions {
|
||||
extensions: vec![Extension::builder().ops(vec![op_test::decl()]).build()],
|
||||
extensions: vec![Extension::builder("test_ext")
|
||||
.ops(vec![op_test::decl()])
|
||||
.build()],
|
||||
..Default::default()
|
||||
});
|
||||
let realm = runtime.create_realm().unwrap();
|
||||
|
@ -4275,7 +4288,9 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
|
|||
|
||||
let mut runtime = JsRuntime::new(RuntimeOptions {
|
||||
startup_snapshot: Some(Snapshot::Boxed(snapshot)),
|
||||
extensions: vec![Extension::builder().ops(vec![op_test::decl()]).build()],
|
||||
extensions: vec![Extension::builder("test_ext")
|
||||
.ops(vec![op_test::decl()])
|
||||
.build()],
|
||||
..Default::default()
|
||||
});
|
||||
let realm = runtime.create_realm().unwrap();
|
||||
|
@ -4304,7 +4319,9 @@ Deno.core.ops.op_async_serialize_object_with_numbers_as_keys({
|
|||
}
|
||||
|
||||
let mut runtime = JsRuntime::new(RuntimeOptions {
|
||||
extensions: vec![Extension::builder().ops(vec![op_test::decl()]).build()],
|
||||
extensions: vec![Extension::builder("test_ext")
|
||||
.ops(vec![op_test::decl()])
|
||||
.build()],
|
||||
get_error_class_fn: Some(&|error| {
|
||||
crate::error::get_custom_error_class(error).unwrap()
|
||||
}),
|
||||
|
|
|
@ -109,7 +109,8 @@ pub fn init<BC: BroadcastChannel + 'static>(
|
|||
bc: BC,
|
||||
unstable: bool,
|
||||
) -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_webidl", "deno_web"])
|
||||
.js(include_js_files!(
|
||||
prefix "deno:ext/broadcast_channel",
|
||||
"01_broadcast_channel.js",
|
||||
|
|
3
ext/cache/lib.rs
vendored
3
ext/cache/lib.rs
vendored
|
@ -26,7 +26,8 @@ pub struct CreateCache<C: Cache + 'static>(pub Arc<dyn Fn() -> C>);
|
|||
pub fn init<CA: Cache + 'static>(
|
||||
maybe_create_cache: Option<CreateCache<CA>>,
|
||||
) -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_webidl", "deno_web", "deno_url", "deno_fetch"])
|
||||
.js(include_js_files!(
|
||||
prefix "deno:ext/cache",
|
||||
"01_cache.js",
|
||||
|
|
|
@ -5,7 +5,7 @@ use deno_core::Extension;
|
|||
use std::path::PathBuf;
|
||||
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.js(include_js_files!(
|
||||
prefix "deno:ext/console",
|
||||
"01_colors.js",
|
||||
|
|
|
@ -73,7 +73,8 @@ use crate::key::HkdfOutput;
|
|||
use crate::shared::RawKeyData;
|
||||
|
||||
pub fn init(maybe_seed: Option<u64>) -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_webidl", "deno_web"])
|
||||
.js(include_js_files!(
|
||||
prefix "deno:ext/crypto",
|
||||
"00_crypto.js",
|
||||
|
|
|
@ -94,7 +94,8 @@ pub fn init<FP>(options: Options) -> Extension
|
|||
where
|
||||
FP: FetchPermissions + 'static,
|
||||
{
|
||||
Extension::builder()
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_webidl", "deno_web", "deno_url", "deno_console"])
|
||||
.js(include_js_files!(
|
||||
prefix "deno:ext/fetch",
|
||||
"01_fetch_util.js",
|
||||
|
|
|
@ -84,7 +84,7 @@ pub(crate) struct FfiState {
|
|||
}
|
||||
|
||||
pub fn init<P: FfiPermissions + 'static>(unstable: bool) -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.js(include_js_files!(
|
||||
prefix "deno:ext/ffi",
|
||||
"00_ffi.js",
|
||||
|
|
|
@ -1505,7 +1505,14 @@ pub trait FlashPermissions {
|
|||
}
|
||||
|
||||
pub fn init<P: FlashPermissions + 'static>(unstable: bool) -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec![
|
||||
"deno_web",
|
||||
"deno_net",
|
||||
"deno_fetch",
|
||||
"deno_websocket",
|
||||
"deno_http",
|
||||
])
|
||||
.js(deno_core::include_js_files!(
|
||||
prefix "deno:ext/flash",
|
||||
"01_http.js",
|
||||
|
|
|
@ -78,7 +78,8 @@ pub mod compressible;
|
|||
mod reader_stream;
|
||||
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_web", "deno_net", "deno_fetch", "deno_websocket"])
|
||||
.js(include_js_files!(
|
||||
prefix "deno:ext/http",
|
||||
"01_http.js",
|
||||
|
|
|
@ -410,7 +410,7 @@ impl Env {
|
|||
}
|
||||
|
||||
pub fn init<P: NapiPermissions + 'static>(unstable: bool) -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.ops(vec![op_napi_open::decl::<P>()])
|
||||
.event_loop_middleware(|op_state_rc, cx| {
|
||||
// `work` can call back into the runtime. It can also schedule an async task
|
||||
|
|
|
@ -85,7 +85,8 @@ pub fn init<P: NetPermissions + 'static>(
|
|||
) -> Extension {
|
||||
let mut ops = ops::init::<P>();
|
||||
ops.extend(ops_tls::init::<P>());
|
||||
Extension::builder()
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_web"])
|
||||
.js(include_js_files!(
|
||||
prefix "deno:ext/net",
|
||||
"01_net.js",
|
||||
|
|
|
@ -865,7 +865,7 @@ mod tests {
|
|||
let listener = TcpListener::bind(addr).await.unwrap();
|
||||
let _ = listener.accept().await;
|
||||
});
|
||||
let my_ext = Extension::builder()
|
||||
let my_ext = Extension::builder("test_ext")
|
||||
.state(move |state| {
|
||||
state.put(TestPermission {});
|
||||
state.put(UnstableChecker { unstable: true });
|
||||
|
|
|
@ -80,7 +80,7 @@ pub static NODE_ENV_VAR_ALLOWLIST: Lazy<HashSet<String>> = Lazy::new(|| {
|
|||
pub fn init<P: NodePermissions + 'static>(
|
||||
maybe_npm_resolver: Option<Rc<dyn RequireNpmResolver>>,
|
||||
) -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.js(include_js_files!(
|
||||
prefix "deno:ext/node",
|
||||
"01_node.js",
|
||||
|
|
|
@ -37,7 +37,7 @@ use std::time::SystemTime;
|
|||
|
||||
/// This extension has no runtime apis, it only exports some shared native functions.
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder().build()
|
||||
Extension::builder(env!("CARGO_PKG_NAME")).build()
|
||||
}
|
||||
|
||||
struct DefaultSignatureVerification;
|
||||
|
|
|
@ -8,7 +8,7 @@ fn setup() -> Vec<Extension> {
|
|||
vec![
|
||||
deno_webidl::init(),
|
||||
deno_url::init(),
|
||||
Extension::builder()
|
||||
Extension::builder("bench_setup")
|
||||
.js(vec![(
|
||||
"setup",
|
||||
"const { URL } = globalThis.__bootstrap.url;",
|
||||
|
|
|
@ -18,7 +18,8 @@ use crate::urlpattern::op_urlpattern_parse;
|
|||
use crate::urlpattern::op_urlpattern_process_match_input;
|
||||
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_webidl"])
|
||||
.js(include_js_files!(
|
||||
prefix "deno:ext/url",
|
||||
"00_url.js",
|
||||
|
|
|
@ -25,6 +25,7 @@ uuid = { workspace = true, features = ["serde"] }
|
|||
|
||||
[dev-dependencies]
|
||||
deno_bench_util.workspace = true
|
||||
deno_console.workspace = true
|
||||
deno_url.workspace = true
|
||||
deno_webidl.workspace = true
|
||||
|
||||
|
|
|
@ -24,8 +24,9 @@ fn setup() -> Vec<Extension> {
|
|||
vec![
|
||||
deno_webidl::init(),
|
||||
deno_url::init(),
|
||||
deno_console::init(),
|
||||
deno_web::init::<Permissions>(BlobStore::default(), None),
|
||||
Extension::builder()
|
||||
Extension::builder("bench_setup")
|
||||
.js(vec![(
|
||||
"setup",
|
||||
r#"
|
||||
|
|
|
@ -23,8 +23,9 @@ fn setup() -> Vec<Extension> {
|
|||
vec![
|
||||
deno_webidl::init(),
|
||||
deno_url::init(),
|
||||
deno_console::init(),
|
||||
deno_web::init::<Permissions>(BlobStore::default(), None),
|
||||
Extension::builder()
|
||||
Extension::builder("bench_setup")
|
||||
.js(vec![
|
||||
("setup", r#"
|
||||
const { setTimeout, handleTimerMacrotask } = globalThis.__bootstrap.timers;
|
||||
|
|
|
@ -62,7 +62,8 @@ pub fn init<P: TimersPermission + 'static>(
|
|||
blob_store: BlobStore,
|
||||
maybe_location: Option<Url>,
|
||||
) -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_webidl", "deno_console", "deno_url"])
|
||||
.js(include_js_files!(
|
||||
prefix "deno:ext/web",
|
||||
"00_infra.js",
|
||||
|
|
|
@ -104,7 +104,8 @@ impl Resource for WebGpuQuerySet {
|
|||
}
|
||||
|
||||
pub fn init(unstable: bool) -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_webidl", "deno_web"])
|
||||
.js(include_js_files!(
|
||||
prefix "deno:ext/webgpu",
|
||||
"01_webgpu.js",
|
||||
|
|
|
@ -5,7 +5,7 @@ use deno_core::Extension;
|
|||
|
||||
/// Load and execute the javascript code.
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.js(include_js_files!(
|
||||
prefix "deno:ext/webidl",
|
||||
"00_webidl.js",
|
||||
|
|
|
@ -602,7 +602,8 @@ pub fn init<P: WebSocketPermissions + 'static>(
|
|||
root_cert_store: Option<RootCertStore>,
|
||||
unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
||||
) -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_url", "deno_webidl"])
|
||||
.js(include_js_files!(
|
||||
prefix "deno:ext/websocket",
|
||||
"01_websocket.js",
|
||||
|
|
|
@ -22,7 +22,8 @@ struct OriginStorageDir(PathBuf);
|
|||
const MAX_STORAGE_BYTES: u32 = 10 * 1024 * 1024;
|
||||
|
||||
pub fn init(origin_storage_dir: Option<PathBuf>) -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_webidl"])
|
||||
.js(include_js_files!(
|
||||
prefix "deno:ext/webstorage",
|
||||
"01_webstorage.js",
|
||||
|
|
|
@ -42,7 +42,7 @@ use deno_core::error::generic_error;
|
|||
use deno_core::error::not_supported;
|
||||
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder("deno_fs")
|
||||
.ops(vec![
|
||||
op_open_sync::decl(),
|
||||
op_open_async::decl(),
|
||||
|
|
|
@ -30,7 +30,7 @@ use std::rc::Rc;
|
|||
use tokio::sync::mpsc;
|
||||
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder("deno_fs_events")
|
||||
.ops(vec![op_fs_events_open::decl(), op_fs_events_poll::decl()])
|
||||
.build()
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ use deno_net::io::UnixStreamResource;
|
|||
use tokio::net::UnixStream;
|
||||
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder("deno_http_runtime")
|
||||
.ops(vec![
|
||||
op_http_start::decl(),
|
||||
op_http_upgrade::decl(),
|
||||
|
|
|
@ -76,7 +76,7 @@ pub static STDERR_HANDLE: Lazy<StdFile> = Lazy::new(|| {
|
|||
});
|
||||
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder("deno_io")
|
||||
.ops(vec![op_read_sync::decl(), op_write_sync::decl()])
|
||||
.build()
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ pub fn init_stdio(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)));
|
||||
|
||||
Extension::builder()
|
||||
Extension::builder("deno_stdio")
|
||||
.middleware(|op| match op.name {
|
||||
"op_print" => op_print::decl(),
|
||||
_ => op,
|
||||
|
|
|
@ -40,7 +40,7 @@ fn init_ops(builder: &mut ExtensionBuilder) -> &mut ExtensionBuilder {
|
|||
}
|
||||
|
||||
pub fn init(exit_code: ExitCode) -> Extension {
|
||||
let mut builder = Extension::builder();
|
||||
let mut builder = Extension::builder("deno_os");
|
||||
init_ops(&mut builder)
|
||||
.state(move |state| {
|
||||
state.put::<ExitCode>(exit_code.clone());
|
||||
|
@ -50,7 +50,7 @@ pub fn init(exit_code: ExitCode) -> Extension {
|
|||
}
|
||||
|
||||
pub fn init_for_worker() -> Extension {
|
||||
let mut builder = Extension::builder();
|
||||
let mut builder = Extension::builder("deno_os_worker");
|
||||
init_ops(&mut builder)
|
||||
.middleware(|op| match op.name {
|
||||
"op_exit" => noop_op::decl(),
|
||||
|
|
|
@ -13,7 +13,7 @@ use serde::Deserialize;
|
|||
use std::path::Path;
|
||||
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder("deno_permissions")
|
||||
.ops(vec![
|
||||
op_query_permission::decl(),
|
||||
op_revoke_permission::decl(),
|
||||
|
|
|
@ -27,7 +27,7 @@ use tokio::process::Command;
|
|||
use std::os::unix::process::ExitStatusExt;
|
||||
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder("deno_process")
|
||||
.ops(vec![op_run::decl(), op_run_status::decl(), op_kill::decl()])
|
||||
.build()
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ use deno_core::ModuleSpecifier;
|
|||
use deno_core::OpState;
|
||||
|
||||
pub fn init(main_module: ModuleSpecifier) -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder("deno_runtime")
|
||||
.ops(vec![op_main_module::decl()])
|
||||
.state(move |state| {
|
||||
state.put::<ModuleSpecifier>(main_module.clone());
|
||||
|
|
|
@ -21,7 +21,7 @@ use tokio::signal::unix::{signal, Signal, SignalKind};
|
|||
use tokio::signal::windows::{ctrl_break, ctrl_c, CtrlBreak, CtrlC};
|
||||
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder("deno_signal")
|
||||
.ops(vec![
|
||||
op_signal_bind::decl(),
|
||||
op_signal_unbind::decl(),
|
||||
|
|
|
@ -28,7 +28,7 @@ use std::os::unix::prelude::ExitStatusExt;
|
|||
use std::os::unix::process::CommandExt;
|
||||
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder("deno_spawn")
|
||||
.ops(vec![
|
||||
op_spawn_child::decl(),
|
||||
op_node_unstable_spawn_child::decl(),
|
||||
|
|
|
@ -34,7 +34,7 @@ fn get_windows_handle(
|
|||
}
|
||||
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder("deno_tty")
|
||||
.ops(vec![
|
||||
op_stdin_set_raw::decl(),
|
||||
op_isatty::decl(),
|
||||
|
|
|
@ -17,7 +17,7 @@ use std::rc::Rc;
|
|||
use self::sync_fetch::op_worker_sync_fetch;
|
||||
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder("deno_web_worker")
|
||||
.ops(vec![
|
||||
op_worker_post_message::decl(),
|
||||
op_worker_recv_message::decl(),
|
||||
|
|
|
@ -94,7 +94,7 @@ pub fn init(
|
|||
pre_execute_module_cb: Arc<WorkerEventCb>,
|
||||
format_js_error_fn: Option<Arc<FormatJsErrorFn>>,
|
||||
) -> Extension {
|
||||
Extension::builder()
|
||||
Extension::builder("deno_worker_host")
|
||||
.state(move |state| {
|
||||
state.put::<WorkersTable>(WorkersTable::default());
|
||||
state.put::<WorkerId>(WorkerId::default());
|
||||
|
|
|
@ -370,7 +370,7 @@ impl WebWorker {
|
|||
// 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()
|
||||
let perm_ext = Extension::builder("deno_permissions_web_worker")
|
||||
.state(move |state| {
|
||||
state.put::<PermissionsContainer>(permissions.clone());
|
||||
state.put(ops::UnstableChecker { unstable });
|
||||
|
|
|
@ -202,7 +202,7 @@ impl MainWorker {
|
|||
// 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()
|
||||
let perm_ext = Extension::builder("deno_permissions_worker")
|
||||
.state(move |state| {
|
||||
state.put::<PermissionsContainer>(permissions.clone());
|
||||
state.put(ops::UnstableChecker { unstable });
|
||||
|
|
Loading…
Reference in a new issue