diff options
Diffstat (limited to 'op_crates')
-rw-r--r-- | op_crates/console/lib.rs | 12 | ||||
-rw-r--r-- | op_crates/crypto/lib.rs | 16 | ||||
-rw-r--r-- | op_crates/fetch/lib.rs | 16 | ||||
-rw-r--r-- | op_crates/file/lib.rs | 16 | ||||
-rw-r--r-- | op_crates/timers/lib.rs | 21 | ||||
-rw-r--r-- | op_crates/url/lib.rs | 13 | ||||
-rw-r--r-- | op_crates/web/lib.rs | 24 | ||||
-rw-r--r-- | op_crates/webgpu/lib.rs | 14 | ||||
-rw-r--r-- | op_crates/webidl/lib.rs | 11 | ||||
-rw-r--r-- | op_crates/websocket/lib.rs | 16 |
10 files changed, 83 insertions, 76 deletions
diff --git a/op_crates/console/lib.rs b/op_crates/console/lib.rs index 4d6a213f2..4f64bb108 100644 --- a/op_crates/console/lib.rs +++ b/op_crates/console/lib.rs @@ -5,11 +5,13 @@ use deno_core::Extension; use std::path::PathBuf; pub fn init() -> Extension { - Extension::pure_js(include_js_files!( - prefix "deno:op_crates/console", - "01_colors.js", - "02_console.js", - )) + Extension::builder() + .js(include_js_files!( + prefix "deno:op_crates/console", + "01_colors.js", + "02_console.js", + )) + .build() } pub fn get_declaration() -> PathBuf { diff --git a/op_crates/crypto/lib.rs b/op_crates/crypto/lib.rs index d5b0a30bc..543220548 100644 --- a/op_crates/crypto/lib.rs +++ b/op_crates/crypto/lib.rs @@ -16,22 +16,22 @@ use std::path::PathBuf; pub use rand; // Re-export rand pub fn init(maybe_seed: Option<u64>) -> Extension { - Extension::with_ops( - include_js_files!( + Extension::builder() + .js(include_js_files!( prefix "deno:op_crates/crypto", "01_crypto.js", - ), - vec![( + )) + .ops(vec![( "op_crypto_get_random_values", op_sync(op_crypto_get_random_values), - )], - Some(Box::new(move |state| { + )]) + .state(move |state| { if let Some(seed) = maybe_seed { state.put(StdRng::seed_from_u64(seed)); } Ok(()) - })), - ) + }) + .build() } pub fn op_crypto_get_random_values( diff --git a/op_crates/fetch/lib.rs b/op_crates/fetch/lib.rs index 7033a416c..861fc6e54 100644 --- a/op_crates/fetch/lib.rs +++ b/op_crates/fetch/lib.rs @@ -56,8 +56,8 @@ pub fn init<P: FetchPermissions + 'static>( user_agent: String, ca_data: Option<Vec<u8>>, ) -> Extension { - Extension::with_ops( - include_js_files!( + Extension::builder() + .js(include_js_files!( prefix "deno:op_crates/fetch", "01_fetch_util.js", "11_streams.js", @@ -68,15 +68,15 @@ pub fn init<P: FetchPermissions + 'static>( "23_request.js", "23_response.js", "26_fetch.js", - ), - vec![ + )) + .ops(vec![ ("op_fetch", op_sync(op_fetch::<P>)), ("op_fetch_send", op_async(op_fetch_send)), ("op_fetch_request_write", op_async(op_fetch_request_write)), ("op_fetch_response_read", op_async(op_fetch_response_read)), ("op_create_http_client", op_sync(op_create_http_client::<P>)), - ], - Some(Box::new(move |state| { + ]) + .state(move |state| { state.put::<reqwest::Client>({ create_http_client(user_agent.clone(), ca_data.clone()).unwrap() }); @@ -85,8 +85,8 @@ pub fn init<P: FetchPermissions + 'static>( user_agent: user_agent.clone(), }); Ok(()) - })), - ) + }) + .build() } pub struct HttpClientDefaults { diff --git a/op_crates/file/lib.rs b/op_crates/file/lib.rs index 19bb8b19b..ccde34ada 100644 --- a/op_crates/file/lib.rs +++ b/op_crates/file/lib.rs @@ -88,14 +88,14 @@ pub fn init( blob_url_store: BlobUrlStore, maybe_location: Option<Url>, ) -> Extension { - Extension::with_ops( - include_js_files!( + Extension::builder() + .js(include_js_files!( prefix "deno:op_crates/file", "01_file.js", "02_filereader.js", "03_blob_url.js", - ), - vec![ + )) + .ops(vec![ ( "op_file_create_object_url", op_sync(op_file_create_object_url), @@ -104,15 +104,15 @@ pub fn init( "op_file_revoke_object_url", op_sync(op_file_revoke_object_url), ), - ], - Some(Box::new(move |state| { + ]) + .state(move |state| { state.put(blob_url_store.clone()); if let Some(location) = maybe_location.clone() { state.put(Location(location)); } Ok(()) - })), - ) + }) + .build() } pub fn get_declaration() -> PathBuf { diff --git a/op_crates/timers/lib.rs b/op_crates/timers/lib.rs index 6359b20f0..62f5953fa 100644 --- a/op_crates/timers/lib.rs +++ b/op_crates/timers/lib.rs @@ -13,6 +13,7 @@ use deno_core::futures; use deno_core::futures::channel::oneshot; use deno_core::futures::FutureExt; use deno_core::futures::TryFutureExt; +use deno_core::include_js_files; use deno_core::op_async; use deno_core::op_sync; use deno_core::Extension; @@ -41,24 +42,24 @@ impl TimersPermission for NoTimersPermission { } pub fn init<P: TimersPermission + 'static>() -> Extension { - Extension::with_ops( - vec![( - "deno:op_crates/timers/01_timers.js", - include_str!("01_timers.js"), - )], - vec![ + Extension::builder() + .js(include_js_files!( + prefix "deno:op_crates/timers", + "01_timers.js", + )) + .ops(vec![ ("op_global_timer_stop", op_sync(op_global_timer_stop)), ("op_global_timer_start", op_sync(op_global_timer_start)), ("op_global_timer", op_async(op_global_timer)), ("op_now", op_sync(op_now::<P>)), ("op_sleep_sync", op_sync(op_sleep_sync::<P>)), - ], - Some(Box::new(|state| { + ]) + .state(|state| { state.put(GlobalTimer::default()); state.put(StartTime::now()); Ok(()) - })), - ) + }) + .build() } pub type StartTime = Instant; diff --git a/op_crates/url/lib.rs b/op_crates/url/lib.rs index 49e34c47d..1d7a9b08b 100644 --- a/op_crates/url/lib.rs +++ b/op_crates/url/lib.rs @@ -17,12 +17,12 @@ use std::panic::catch_unwind; use std::path::PathBuf; pub fn init() -> Extension { - Extension::with_ops( - include_js_files!( + Extension::builder() + .js(include_js_files!( prefix "deno:op_crates/url", "00_url.js", - ), - vec![ + )) + .ops(vec![ ("op_url_parse", op_sync(op_url_parse)), ( "op_url_parse_search_params", @@ -32,9 +32,8 @@ pub fn init() -> Extension { "op_url_stringify_search_params", op_sync(op_url_stringify_search_params), ), - ], - None, - ) + ]) + .build() } #[derive(Deserialize)] diff --git a/op_crates/web/lib.rs b/op_crates/web/lib.rs index 7fd8221eb..a2612743e 100644 --- a/op_crates/web/lib.rs +++ b/op_crates/web/lib.rs @@ -6,17 +6,19 @@ use std::path::PathBuf; /// Load and execute the javascript code. pub fn init() -> Extension { - Extension::pure_js(include_js_files!( - prefix "deno:op_crates/web", - "00_infra.js", - "01_dom_exception.js", - "01_mimesniff.js", - "02_event.js", - "03_abort_signal.js", - "04_global_interfaces.js", - "08_text_encoding.js", - "12_location.js", - )) + Extension::builder() + .js(include_js_files!( + prefix "deno:op_crates/web", + "00_infra.js", + "01_dom_exception.js", + "01_mimesniff.js", + "02_event.js", + "03_abort_signal.js", + "04_global_interfaces.js", + "08_text_encoding.js", + "12_location.js", + )) + .build() } pub fn get_declaration() -> PathBuf { diff --git a/op_crates/webgpu/lib.rs b/op_crates/webgpu/lib.rs index a9cbbb882..b5b2905b2 100644 --- a/op_crates/webgpu/lib.rs +++ b/op_crates/webgpu/lib.rs @@ -95,22 +95,22 @@ impl Resource for WebGpuQuerySet { } pub fn init(unstable: bool) -> Extension { - Extension::with_ops( - include_js_files!( + Extension::builder() + .js(include_js_files!( prefix "deno:op_crates/webgpu", "01_webgpu.js", "02_idl_types.js", - ), - declare_webgpu_ops(), - Some(Box::new(move |state| { + )) + .ops(declare_webgpu_ops()) + .state(move |state| { // TODO: check & possibly streamline this // Unstable might be able to be OpMiddleware // let unstable_checker = state.borrow::<super::UnstableChecker>(); // let unstable = unstable_checker.unstable; state.put(Unstable(unstable)); Ok(()) - })), - ) + }) + .build() } pub fn get_declaration() -> PathBuf { diff --git a/op_crates/webidl/lib.rs b/op_crates/webidl/lib.rs index a1a404dbd..c73c60bab 100644 --- a/op_crates/webidl/lib.rs +++ b/op_crates/webidl/lib.rs @@ -1,11 +1,14 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +use deno_core::include_js_files; use deno_core::Extension; /// Load and execute the javascript code. pub fn init() -> Extension { - Extension::pure_js(vec![( - "deno:op_crates/webidl/00_webidl.js", - include_str!("00_webidl.js"), - )]) + Extension::builder() + .js(include_js_files!( + prefix "deno:op_crates/webidl", + "00_webidl.js", + )) + .build() } diff --git a/op_crates/websocket/lib.rs b/op_crates/websocket/lib.rs index c682c6b2f..b81b1701d 100644 --- a/op_crates/websocket/lib.rs +++ b/op_crates/websocket/lib.rs @@ -340,12 +340,12 @@ pub fn init<P: WebSocketPermissions + 'static>( user_agent: String, ca_data: Option<Vec<u8>>, ) -> Extension { - Extension::with_ops( - include_js_files!( + Extension::builder() + .js(include_js_files!( prefix "deno:op_crates/websocket", "01_websocket.js", - ), - vec![ + )) + .ops(vec![ ( "op_ws_check_permission", op_sync(op_ws_check_permission::<P>), @@ -354,15 +354,15 @@ pub fn init<P: WebSocketPermissions + 'static>( ("op_ws_send", op_async(op_ws_send)), ("op_ws_close", op_async(op_ws_close)), ("op_ws_next_event", op_async(op_ws_next_event)), - ], - Some(Box::new(move |state| { + ]) + .state(move |state| { state.put::<WsUserAgent>(WsUserAgent(user_agent.clone())); if let Some(ca_data) = ca_data.clone() { state.put::<WsCaData>(WsCaData(ca_data)); } Ok(()) - })), - ) + }) + .build() } pub fn get_declaration() -> PathBuf { |