chore(ext/timers): move ext/timers to ext/web (#13665)

This commit is contained in:
Andreu Botella 2022-02-15 12:17:30 +01:00 committed by GitHub
parent 5e845442fa
commit 760f4c9e24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 46 additions and 88 deletions

16
Cargo.lock generated
View file

@ -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",

View file

@ -17,7 +17,6 @@ members = [
"ext/ffi",
"ext/http",
"ext/net",
"ext/timers",
"ext/url",
"ext/web",
"ext/webgpu",

View file

@ -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])

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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<Extension> {
vec![
deno_webidl::init(),
deno_url::init(),
deno_web::init(BlobStore::default(), None),
deno_timers::init::<Permissions>(),
deno_web::init::<Permissions>(BlobStore::default(), None),
Extension::builder()
.js(vec![
("setup",

View file

@ -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<Url>) -> Extension {
pub fn init<P: TimersPermission + 'static>(
blob_store: BlobStore,
maybe_location: Option<Url>,
) -> Extension {
Extension::builder()
.js(include_js_files!(
prefix "deno:ext/web",
@ -57,6 +68,7 @@ pub fn init(blob_store: BlobStore, maybe_location: Option<Url>) -> 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<Url>) -> 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<Url>) -> Extension {
"op_compression_finish",
op_sync(compression::op_compression_finish),
),
("op_now", op_sync(op_now::<P>)),
("op_timer_handle", op_sync(op_timer_handle)),
("op_sleep", op_async(op_sleep)),
("op_sleep_sync", op_sync(op_sleep_sync::<P>)),
])
.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()

View file

@ -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<P: TimersPermission + 'static>() -> 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::<P>)),
("op_timer_handle", op_sync(op_timer_handle)),
("op_sleep", op_async(op_sleep)),
("op_sleep_sync", op_sync(op_sleep_sync::<P>)),
])
.state(|state| {
state.put(StartTime::now());
Ok(())
})
.build()
}
pub type StartTime = Instant;
// Returns a milliseconds and nanoseconds subsec

View file

@ -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" }

View file

@ -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::<Permissions>(
deno_web::BlobStore::default(),
Default::default(),
),
deno_fetch::init::<Permissions>(Default::default()),
deno_websocket::init::<Permissions>("".to_owned(), None, None),
deno_webstorage::init(None),
deno_crypto::init(None),
deno_webgpu::init(false),
deno_timers::init::<Permissions>(),
deno_broadcast_channel::init(
deno_broadcast_channel::InMemoryBroadcastChannel::default(),
false, // No --unstable.

View file

@ -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;

View file

@ -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()
}

View file

@ -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::<Permissions>(
options.blob_store.clone(),
Some(main_module.clone()),
),
deno_fetch::init::<Permissions>(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::<Permissions>(),
// ffi
deno_ffi::init::<Permissions>(unstable),
// Permissions ext (worker specific state)

View file

@ -100,7 +100,7 @@ impl MainWorker {
deno_webidl::init(),
deno_console::init(),
deno_url::init(),
deno_web::init(
deno_web::init::<Permissions>(
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::<Permissions>(),
// ffi
deno_ffi::init::<Permissions>(unstable),
// Runtime ops