From 3ce61098363bd7be5a633d19ede38dcdab108502 Mon Sep 17 00:00:00 2001 From: Gregory Terzian Date: Mon, 30 Mar 2020 14:35:37 +0800 Subject: [PATCH] enable Atomics.wait in a dedicated worker agent --- components/script/script_runtime.rs | 19 +++++++++++++++---- .../requires-success.any.js.ini | 6 ------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 3cce6291d63..27459d65245 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -44,6 +44,7 @@ use js::glue::{ use js::jsapi::ContextOptionsRef; use js::jsapi::InitConsumeStreamCallback; use js::jsapi::InitDispatchToEventLoop; +use js::jsapi::JS_SetFutexCanWait; use js::jsapi::MimeType; use js::jsapi::StreamConsumer as JSStreamConsumer; use js::jsapi::{BuildIdCharVector, DisableIncrementalGC, GCDescription, GCProgress}; @@ -444,12 +445,22 @@ unsafe fn new_rt_and_cx_with_parent( networking_task_source: Option, ) -> Runtime { LiveDOMReferences::initialize(); - let runtime = if let Some(parent) = parent { - RustRuntime::create_with_parent(parent) + let (cx, runtime) = if let Some(parent) = parent { + let runtime = RustRuntime::create_with_parent(parent); + let cx = runtime.cx(); + + // Note: this enables blocking on an Atomics.wait, + // which should only be enabled for an agent whose [[CanBlock]] is true. + // Currently only a dedicated worker agent uses a parent, + // and this agent can block. + // See https://html.spec.whatwg.org/multipage/#integration-with-the-javascript-agent-cluster-formalism + JS_SetFutexCanWait(cx); + + (cx, runtime) } else { - RustRuntime::new(JS_ENGINE.lock().unwrap().as_ref().unwrap().clone()) + let runtime = RustRuntime::new(JS_ENGINE.lock().unwrap().as_ref().unwrap().clone()); + (runtime.cx(), runtime) }; - let cx = runtime.cx(); JS_AddExtraGCRootsTracer(cx, Some(trace_rust_roots), ptr::null_mut()); diff --git a/tests/wpt/metadata/html/webappapis/scripting/processing-model-2/integration-with-the-javascript-agent-formalism/requires-success.any.js.ini b/tests/wpt/metadata/html/webappapis/scripting/processing-model-2/integration-with-the-javascript-agent-formalism/requires-success.any.js.ini index f3eb22d76b4..346e45175cb 100644 --- a/tests/wpt/metadata/html/webappapis/scripting/processing-model-2/integration-with-the-javascript-agent-formalism/requires-success.any.js.ini +++ b/tests/wpt/metadata/html/webappapis/scripting/processing-model-2/integration-with-the-javascript-agent-formalism/requires-success.any.js.ini @@ -1,10 +1,4 @@ -[requires-success.any.worker.html] - [[[CanBlock\]\] in a DedicatedWorkerGlobalScope] - expected: FAIL - - [requires-success.any.sharedworker.html] expected: ERROR [requires-success] expected: FAIL -