From 760f4c9e2427e87815a8e59b0807693c8dcb623a Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Tue, 15 Feb 2022 12:17:30 +0100 Subject: [PATCH] chore(ext/timers): move ext/timers to ext/web (#13665) --- Cargo.lock | 16 ++--------- Cargo.toml | 1 - .../testdata/worker_drop_handle_race.js.out | 4 +-- ext/timers/Cargo.toml | 28 ------------------- ext/timers/README.md | 5 ---- ext/{timers/01_timers.js => web/02_timers.js} | 0 .../15_performance.js} | 0 ext/web/Cargo.toml | 9 ++++++ ext/{timers => web}/benches/timers_ops.rs | 5 ++-- ext/web/lib.rs | 20 ++++++++++++- ext/{timers/lib.rs => web/timers.rs} | 24 ---------------- runtime/Cargo.toml | 2 -- runtime/build.rs | 8 ++++-- runtime/lib.rs | 1 - runtime/permissions.rs | 2 +- runtime/web_worker.rs | 6 ++-- runtime/worker.rs | 3 +- 17 files changed, 46 insertions(+), 88 deletions(-) delete mode 100644 ext/timers/Cargo.toml delete mode 100644 ext/timers/README.md rename ext/{timers/01_timers.js => web/02_timers.js} (100%) rename ext/{timers/02_performance.js => web/15_performance.js} (100%) rename ext/{timers => web}/benches/timers_ops.rs (88%) rename ext/{timers/lib.rs => web/timers.rs} (81%) diff --git a/Cargo.lock b/Cargo.lock index 49d478a00b..170272e9fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1006,7 +1006,6 @@ dependencies = [ "deno_ffi", "deno_http", "deno_net", - "deno_timers", "deno_tls", "deno_url", "deno_web", @@ -1041,18 +1040,6 @@ dependencies = [ "winres", ] -[[package]] -name = "deno_timers" -version = "0.34.0" -dependencies = [ - "deno_bench_util", - "deno_core", - "deno_url", - "deno_web", - "deno_webidl", - "tokio", -] - [[package]] name = "deno_tls" version = "0.23.0" @@ -1085,7 +1072,10 @@ version = "0.67.0" dependencies = [ "async-trait", "base64 0.13.0", + "deno_bench_util", "deno_core", + "deno_url", + "deno_webidl", "encoding_rs", "flate2", "serde", diff --git a/Cargo.toml b/Cargo.toml index 3f206b2232..781b88cb5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,6 @@ members = [ "ext/ffi", "ext/http", "ext/net", - "ext/timers", "ext/url", "ext/web", "ext/webgpu", diff --git a/cli/tests/testdata/worker_drop_handle_race.js.out b/cli/tests/testdata/worker_drop_handle_race.js.out index b7218e8f61..34c2d5be26 100644 --- a/cli/tests/testdata/worker_drop_handle_race.js.out +++ b/cli/tests/testdata/worker_drop_handle_race.js.out @@ -2,7 +2,7 @@ error: Uncaught (in worker "") Error throw new Error(); ^ at [WILDCARD]/workers/drop_handle_race.js:2:9 - at Object.action (deno:ext/timers/[WILDCARD]) - at handleTimerMacrotask (deno:ext/timers/[WILDCARD]) + at Object.action (deno:ext/web/02_timers.js:[WILDCARD]) + at handleTimerMacrotask (deno:ext/web/02_timers.js:[WILDCARD]) error: Uncaught (in promise) Error: Unhandled error event in child worker. at Worker.#pollControl (deno:runtime/js/11_workers.js:[WILDCARD]) diff --git a/ext/timers/Cargo.toml b/ext/timers/Cargo.toml deleted file mode 100644 index 15979388ed..0000000000 --- a/ext/timers/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. - -[package] -name = "deno_timers" -version = "0.34.0" -authors = ["the Deno authors"] -edition = "2021" -license = "MIT" -readme = "README.md" -repository = "https://github.com/denoland/deno" -description = "Timers API implementation for Deno" - -[lib] -path = "lib.rs" - -[dependencies] -deno_core = { version = "0.118.0", path = "../../core" } -tokio = { version = "1.10.1", features = ["full"] } - -[dev-dependencies] -deno_bench_util = { version = "0.30.0", path = "../../bench_util" } -deno_url = { version = "0.36.0", path = "../url" } -deno_web = { version = "0.67.0", path = "../web" } -deno_webidl = { version = "0.36.0", path = "../webidl" } - -[[bench]] -name = "timers_ops" -harness = false diff --git a/ext/timers/README.md b/ext/timers/README.md deleted file mode 100644 index 5a2a8e5162..0000000000 --- a/ext/timers/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# deno_timers - -This crate implements the timers API. - -Spec: https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timers diff --git a/ext/timers/01_timers.js b/ext/web/02_timers.js similarity index 100% rename from ext/timers/01_timers.js rename to ext/web/02_timers.js diff --git a/ext/timers/02_performance.js b/ext/web/15_performance.js similarity index 100% rename from ext/timers/02_performance.js rename to ext/web/15_performance.js diff --git a/ext/web/Cargo.toml b/ext/web/Cargo.toml index 0e1c1433b4..f32a05999b 100644 --- a/ext/web/Cargo.toml +++ b/ext/web/Cargo.toml @@ -22,3 +22,12 @@ flate2 = "1" serde = "1.0.129" tokio = { version = "1.10.1", features = ["full"] } uuid = { version = "0.8.2", features = ["v4", "serde"] } + +[dev-dependencies] +deno_bench_util = { version = "0.30.0", path = "../../bench_util" } +deno_url = { version = "0.36.0", path = "../url" } +deno_webidl = { version = "0.36.0", path = "../webidl" } + +[[bench]] +name = "timers_ops" +harness = false diff --git a/ext/timers/benches/timers_ops.rs b/ext/web/benches/timers_ops.rs similarity index 88% rename from ext/timers/benches/timers_ops.rs rename to ext/web/benches/timers_ops.rs index 8d13d5807f..30f50b7d91 100644 --- a/ext/timers/benches/timers_ops.rs +++ b/ext/web/benches/timers_ops.rs @@ -7,7 +7,7 @@ use deno_web::BlobStore; struct Permissions; -impl deno_timers::TimersPermission for Permissions { +impl deno_web::TimersPermission for Permissions { fn allow_hrtime(&mut self) -> bool { true } @@ -23,8 +23,7 @@ fn setup() -> Vec { vec![ deno_webidl::init(), deno_url::init(), - deno_web::init(BlobStore::default(), None), - deno_timers::init::(), + deno_web::init::(BlobStore::default(), None), Extension::builder() .js(vec![ ("setup", diff --git a/ext/web/lib.rs b/ext/web/lib.rs index b32deeb972..b10cb972d1 100644 --- a/ext/web/lib.rs +++ b/ext/web/lib.rs @@ -3,6 +3,7 @@ mod blob; mod compression; mod message_port; +mod timers; use deno_core::error::range_error; use deno_core::error::type_error; @@ -47,8 +48,18 @@ use crate::message_port::op_message_port_recv_message; pub use crate::message_port::JsMessageData; pub use crate::message_port::MessagePort; +use crate::timers::op_now; +use crate::timers::op_sleep; +use crate::timers::op_sleep_sync; +use crate::timers::op_timer_handle; +use crate::timers::StartTime; +pub use crate::timers::TimersPermission; + /// Load and execute the javascript code. -pub fn init(blob_store: BlobStore, maybe_location: Option) -> Extension { +pub fn init( + blob_store: BlobStore, + maybe_location: Option, +) -> Extension { Extension::builder() .js(include_js_files!( prefix "deno:ext/web", @@ -57,6 +68,7 @@ pub fn init(blob_store: BlobStore, maybe_location: Option) -> Extension { "01_mimesniff.js", "02_event.js", "02_structured_clone.js", + "02_timers.js", "03_abort_signal.js", "04_global_interfaces.js", "05_base64.js", @@ -68,6 +80,7 @@ pub fn init(blob_store: BlobStore, maybe_location: Option) -> Extension { "12_location.js", "13_message_port.js", "14_compression.js", + "15_performance.js", )) .ops(vec![ ("op_base64_decode", op_sync(op_base64_decode)), @@ -116,12 +129,17 @@ pub fn init(blob_store: BlobStore, maybe_location: Option) -> Extension { "op_compression_finish", op_sync(compression::op_compression_finish), ), + ("op_now", op_sync(op_now::

)), + ("op_timer_handle", op_sync(op_timer_handle)), + ("op_sleep", op_async(op_sleep)), + ("op_sleep_sync", op_sync(op_sleep_sync::

)), ]) .state(move |state| { state.put(blob_store.clone()); if let Some(location) = maybe_location.clone() { state.put(Location(location)); } + state.put(StartTime::now()); Ok(()) }) .build() diff --git a/ext/timers/lib.rs b/ext/web/timers.rs similarity index 81% rename from ext/timers/lib.rs rename to ext/web/timers.rs index 63aabe9d4e..7f17aa9691 100644 --- a/ext/timers/lib.rs +++ b/ext/web/timers.rs @@ -3,12 +3,8 @@ //! This module helps deno implement timers and performance APIs. use deno_core::error::AnyError; -use deno_core::include_js_files; -use deno_core::op_async; -use deno_core::op_sync; use deno_core::CancelFuture; use deno_core::CancelHandle; -use deno_core::Extension; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; @@ -23,26 +19,6 @@ pub trait TimersPermission { fn check_unstable(&self, state: &OpState, api_name: &'static str); } -pub fn init() -> Extension { - Extension::builder() - .js(include_js_files!( - prefix "deno:ext/timers", - "01_timers.js", - "02_performance.js", - )) - .ops(vec![ - ("op_now", op_sync(op_now::

)), - ("op_timer_handle", op_sync(op_timer_handle)), - ("op_sleep", op_async(op_sleep)), - ("op_sleep_sync", op_sync(op_sleep_sync::

)), - ]) - .state(|state| { - state.put(StartTime::now()); - Ok(()) - }) - .build() -} - pub type StartTime = Instant; // Returns a milliseconds and nanoseconds subsec diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 6333d3387f..1763d6feb7 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -30,7 +30,6 @@ deno_fetch = { version = "0.59.0", path = "../ext/fetch" } deno_ffi = { version = "0.23.0", path = "../ext/ffi" } deno_http = { version = "0.28.0", path = "../ext/http" } deno_net = { version = "0.28.0", path = "../ext/net" } -deno_timers = { version = "0.34.0", path = "../ext/timers" } deno_tls = { version = "0.23.0", path = "../ext/tls" } deno_url = { version = "0.36.0", path = "../ext/url" } deno_web = { version = "0.67.0", path = "../ext/web" } @@ -54,7 +53,6 @@ deno_fetch = { version = "0.59.0", path = "../ext/fetch" } deno_ffi = { version = "0.23.0", path = "../ext/ffi" } deno_http = { version = "0.28.0", path = "../ext/http" } deno_net = { version = "0.28.0", path = "../ext/net" } -deno_timers = { version = "0.34.0", path = "../ext/timers" } deno_tls = { version = "0.23.0", path = "../ext/tls" } deno_url = { version = "0.36.0", path = "../ext/url" } deno_web = { version = "0.67.0", path = "../ext/web" } diff --git a/runtime/build.rs b/runtime/build.rs index e2fe21b9e7..eea7a3602c 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -93,7 +93,7 @@ mod not_docs { } } - impl deno_timers::TimersPermission for Permissions { + impl deno_web::TimersPermission for Permissions { fn allow_hrtime(&mut self) -> bool { unreachable!("snapshotting!") } @@ -145,13 +145,15 @@ mod not_docs { deno_console::init(), deno_url::init(), deno_tls::init(), - deno_web::init(deno_web::BlobStore::default(), Default::default()), + deno_web::init::( + deno_web::BlobStore::default(), + Default::default(), + ), deno_fetch::init::(Default::default()), deno_websocket::init::("".to_owned(), None, None), deno_webstorage::init(None), deno_crypto::init(None), deno_webgpu::init(false), - deno_timers::init::(), deno_broadcast_channel::init( deno_broadcast_channel::InMemoryBroadcastChannel::default(), false, // No --unstable. diff --git a/runtime/lib.rs b/runtime/lib.rs index fef3956eac..543d3a0a21 100644 --- a/runtime/lib.rs +++ b/runtime/lib.rs @@ -8,7 +8,6 @@ pub use deno_fetch; pub use deno_ffi; pub use deno_http; pub use deno_net; -pub use deno_timers; pub use deno_tls; pub use deno_url; pub use deno_web; diff --git a/runtime/permissions.rs b/runtime/permissions.rs index c404436d65..77ad8496f9 100644 --- a/runtime/permissions.rs +++ b/runtime/permissions.rs @@ -1314,7 +1314,7 @@ impl deno_fetch::FetchPermissions for Permissions { } } -impl deno_timers::TimersPermission for Permissions { +impl deno_web::TimersPermission for Permissions { fn allow_hrtime(&mut self) -> bool { self.hrtime.check().is_ok() } diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index 8cbbb5d4fc..c90e91b929 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -368,7 +368,10 @@ impl WebWorker { deno_webidl::init(), deno_console::init(), deno_url::init(), - deno_web::init(options.blob_store.clone(), Some(main_module.clone())), + deno_web::init::( + options.blob_store.clone(), + Some(main_module.clone()), + ), deno_fetch::init::(deno_fetch::Options { user_agent: options.user_agent.clone(), root_cert_store: options.root_cert_store.clone(), @@ -386,7 +389,6 @@ impl WebWorker { deno_broadcast_channel::init(options.broadcast_channel.clone(), unstable), deno_crypto::init(options.seed), deno_webgpu::init(unstable), - deno_timers::init::(), // ffi deno_ffi::init::(unstable), // Permissions ext (worker specific state) diff --git a/runtime/worker.rs b/runtime/worker.rs index 1dc9504d65..1e31b84dc5 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -100,7 +100,7 @@ impl MainWorker { deno_webidl::init(), deno_console::init(), deno_url::init(), - deno_web::init( + deno_web::init::( options.blob_store.clone(), options.bootstrap.location.clone(), ), @@ -122,7 +122,6 @@ impl MainWorker { deno_crypto::init(options.seed), deno_broadcast_channel::init(options.broadcast_channel.clone(), unstable), deno_webgpu::init(unstable), - deno_timers::init::(), // ffi deno_ffi::init::(unstable), // Runtime ops