From ddbb7b83f2c483e354f425dfb70dbab494b05ea5 Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Mon, 16 Aug 2021 14:29:54 +0200 Subject: feat(runtime): support classic workers for internal testing (#11338) This commit implements classic workers, but only when the `--enable-testing-features-do-not-use` flag is provided. This change is not user facing. Classic workers are used extensively in WPT tests. The classic workers do not support loading from disk, and do not support TypeScript. Co-authored-by: Luca Casonato --- runtime/web_worker.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'runtime/web_worker.rs') diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index 495fedb81..240d79d1f 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -44,6 +44,13 @@ use std::sync::Arc; use std::task::Context; use std::task::Poll; +#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum WebWorkerType { + Classic, + Module, +} + #[derive( Debug, Default, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, )] @@ -110,6 +117,7 @@ pub struct WebWorkerInternalHandle { pub cancel: Rc, terminated: Arc, isolate_handle: v8::IsolateHandle, + pub worker_type: WebWorkerType, } impl WebWorkerInternalHandle { @@ -215,6 +223,7 @@ impl WebWorkerHandle { fn create_handles( isolate_handle: v8::IsolateHandle, + worker_type: WebWorkerType, ) -> (WebWorkerInternalHandle, SendableWebWorkerHandle) { let (parent_port, worker_port) = create_entangled_message_port(); let (ctrl_tx, ctrl_rx) = mpsc::channel::(1); @@ -225,6 +234,7 @@ fn create_handles( terminated: terminated.clone(), isolate_handle: isolate_handle.clone(), cancel: CancelHandle::new_rc(), + worker_type, }; let external_handle = SendableWebWorkerHandle { receiver: ctrl_rx, @@ -245,6 +255,7 @@ pub struct WebWorker { pub name: String, internal_handle: WebWorkerInternalHandle, pub use_deno_namespace: bool, + pub worker_type: WebWorkerType, pub main_module: ModuleSpecifier, } @@ -253,6 +264,7 @@ pub struct WebWorkerOptions { pub args: Vec, pub debug_flag: bool, pub unstable: bool, + pub enable_testing_features: bool, pub unsafely_ignore_certificate_errors: Option>, pub root_cert_store: Option, pub user_agent: String, @@ -261,6 +273,7 @@ pub struct WebWorkerOptions { pub create_web_worker_cb: Arc, pub js_error_create_fn: Option>, pub use_deno_namespace: bool, + pub worker_type: WebWorkerType, pub maybe_inspector_server: Option>, pub apply_source_maps: bool, /// Sets `Deno.version.deno` in JS runtime. @@ -286,10 +299,12 @@ impl WebWorker { ) -> (Self, SendableWebWorkerHandle) { // Permissions: many ops depend on this let unstable = options.unstable; + let enable_testing_features = options.enable_testing_features; let perm_ext = Extension::builder() .state(move |state| { state.put::(permissions.clone()); state.put(ops::UnstableChecker { unstable }); + state.put(ops::TestingFeaturesEnabled(enable_testing_features)); Ok(()) }) .build(); @@ -386,7 +401,8 @@ impl WebWorker { let (internal_handle, external_handle) = { let handle = js_runtime.v8_isolate().thread_safe_handle(); - let (internal_handle, external_handle) = create_handles(handle); + let (internal_handle, external_handle) = + create_handles(handle, options.worker_type); let op_state = js_runtime.op_state(); let mut op_state = op_state.borrow_mut(); op_state.put(internal_handle.clone()); @@ -400,6 +416,7 @@ impl WebWorker { name, internal_handle, use_deno_namespace: options.use_deno_namespace, + worker_type: options.worker_type, main_module, }, external_handle, @@ -418,6 +435,7 @@ impl WebWorker { "target": env!("TARGET"), "tsVersion": options.ts_version, "unstableFlag": options.unstable, + "enableTestingFeaturesFlag": options.enable_testing_features, "v8Version": deno_core::v8_version(), "location": self.main_module, "cpuCount": options.cpu_count, -- cgit v1.2.3