mirror of
https://github.com/servo/servo.git
synced 2025-07-25 08:10:21 +01:00
Update Worker webidl to support WorkerOptions
This commit is contained in:
parent
81f750afa7
commit
dececad390
11 changed files with 57 additions and 22 deletions
|
@ -9,6 +9,7 @@ use crate::dom::abstractworkerglobalscope::{SendableWorkerScriptChan, WorkerThre
|
||||||
use crate::dom::bindings::cell::DomRefCell;
|
use crate::dom::bindings::cell::DomRefCell;
|
||||||
use crate::dom::bindings::codegen::Bindings::DedicatedWorkerGlobalScopeBinding;
|
use crate::dom::bindings::codegen::Bindings::DedicatedWorkerGlobalScopeBinding;
|
||||||
use crate::dom::bindings::codegen::Bindings::DedicatedWorkerGlobalScopeBinding::DedicatedWorkerGlobalScopeMethods;
|
use crate::dom::bindings::codegen::Bindings::DedicatedWorkerGlobalScopeBinding::DedicatedWorkerGlobalScopeMethods;
|
||||||
|
use crate::dom::bindings::codegen::Bindings::WorkerBinding::WorkerType;
|
||||||
use crate::dom::bindings::error::{ErrorInfo, ErrorResult};
|
use crate::dom::bindings::error::{ErrorInfo, ErrorResult};
|
||||||
use crate::dom::bindings::inheritance::Castable;
|
use crate::dom::bindings::inheritance::Castable;
|
||||||
use crate::dom::bindings::reflector::DomObject;
|
use crate::dom::bindings::reflector::DomObject;
|
||||||
|
@ -212,6 +213,8 @@ impl WorkerEventLoopMethods for DedicatedWorkerGlobalScope {
|
||||||
impl DedicatedWorkerGlobalScope {
|
impl DedicatedWorkerGlobalScope {
|
||||||
fn new_inherited(
|
fn new_inherited(
|
||||||
init: WorkerGlobalScopeInit,
|
init: WorkerGlobalScopeInit,
|
||||||
|
worker_name: DOMString,
|
||||||
|
worker_type: WorkerType,
|
||||||
worker_url: ServoUrl,
|
worker_url: ServoUrl,
|
||||||
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
|
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
|
||||||
runtime: Runtime,
|
runtime: Runtime,
|
||||||
|
@ -225,6 +228,8 @@ impl DedicatedWorkerGlobalScope {
|
||||||
DedicatedWorkerGlobalScope {
|
DedicatedWorkerGlobalScope {
|
||||||
workerglobalscope: WorkerGlobalScope::new_inherited(
|
workerglobalscope: WorkerGlobalScope::new_inherited(
|
||||||
init,
|
init,
|
||||||
|
worker_name,
|
||||||
|
worker_type,
|
||||||
worker_url,
|
worker_url,
|
||||||
runtime,
|
runtime,
|
||||||
from_devtools_receiver,
|
from_devtools_receiver,
|
||||||
|
@ -242,6 +247,8 @@ impl DedicatedWorkerGlobalScope {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
init: WorkerGlobalScopeInit,
|
init: WorkerGlobalScopeInit,
|
||||||
|
worker_name: DOMString,
|
||||||
|
worker_type: WorkerType,
|
||||||
worker_url: ServoUrl,
|
worker_url: ServoUrl,
|
||||||
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
|
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
|
||||||
runtime: Runtime,
|
runtime: Runtime,
|
||||||
|
@ -255,6 +262,8 @@ impl DedicatedWorkerGlobalScope {
|
||||||
let cx = runtime.cx();
|
let cx = runtime.cx();
|
||||||
let scope = Box::new(DedicatedWorkerGlobalScope::new_inherited(
|
let scope = Box::new(DedicatedWorkerGlobalScope::new_inherited(
|
||||||
init,
|
init,
|
||||||
|
worker_name,
|
||||||
|
worker_type,
|
||||||
worker_url,
|
worker_url,
|
||||||
from_devtools_receiver,
|
from_devtools_receiver,
|
||||||
runtime,
|
runtime,
|
||||||
|
@ -279,6 +288,8 @@ impl DedicatedWorkerGlobalScope {
|
||||||
own_sender: Sender<DedicatedWorkerScriptMsg>,
|
own_sender: Sender<DedicatedWorkerScriptMsg>,
|
||||||
receiver: Receiver<DedicatedWorkerScriptMsg>,
|
receiver: Receiver<DedicatedWorkerScriptMsg>,
|
||||||
worker_load_origin: WorkerScriptLoadOrigin,
|
worker_load_origin: WorkerScriptLoadOrigin,
|
||||||
|
worker_name: String,
|
||||||
|
worker_type: WorkerType,
|
||||||
closing: Arc<AtomicBool>,
|
closing: Arc<AtomicBool>,
|
||||||
) {
|
) {
|
||||||
let serialized_worker_url = worker_url.to_string();
|
let serialized_worker_url = worker_url.to_string();
|
||||||
|
@ -338,6 +349,8 @@ impl DedicatedWorkerGlobalScope {
|
||||||
|
|
||||||
let global = DedicatedWorkerGlobalScope::new(
|
let global = DedicatedWorkerGlobalScope::new(
|
||||||
init,
|
init,
|
||||||
|
DOMString::from_string(worker_name),
|
||||||
|
worker_type,
|
||||||
worker_url,
|
worker_url,
|
||||||
devtools_mpsc_port,
|
devtools_mpsc_port,
|
||||||
runtime,
|
runtime,
|
||||||
|
|
|
@ -53,7 +53,7 @@ impl ServiceWorkerContainerMethods for ServiceWorkerContainer {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unrooted_must_root)] // Job is unrooted
|
#[allow(unrooted_must_root)] // Job is unrooted
|
||||||
/// https://w3c.github.io/ServiceWorker/#service-worker-container-register-method and - A
|
/// https://w3c.github.io/ServiceWorker/#navigator-service-worker-register and - A
|
||||||
/// https://w3c.github.io/ServiceWorker/#start-register-algorithm - B
|
/// https://w3c.github.io/ServiceWorker/#start-register-algorithm - B
|
||||||
fn Register(&self, script_url: USVString, options: &RegistrationOptions) -> Rc<Promise> {
|
fn Register(&self, script_url: USVString, options: &RegistrationOptions) -> Rc<Promise> {
|
||||||
// A: Step 1
|
// A: Step 1
|
||||||
|
@ -127,6 +127,7 @@ impl ServiceWorkerContainerMethods for ServiceWorkerContainer {
|
||||||
scope,
|
scope,
|
||||||
script_url,
|
script_url,
|
||||||
promise.clone(),
|
promise.clone(),
|
||||||
|
options.type_,
|
||||||
&*self.client,
|
&*self.client,
|
||||||
);
|
);
|
||||||
// Job is unrooted here, do not do anything other than immediately scheduling
|
// Job is unrooted here, do not do anything other than immediately scheduling
|
||||||
|
|
|
@ -7,6 +7,7 @@ use crate::dom::abstractworker::WorkerScriptMsg;
|
||||||
use crate::dom::abstractworkerglobalscope::{run_worker_event_loop, WorkerEventLoopMethods};
|
use crate::dom::abstractworkerglobalscope::{run_worker_event_loop, WorkerEventLoopMethods};
|
||||||
use crate::dom::bindings::codegen::Bindings::ServiceWorkerGlobalScopeBinding;
|
use crate::dom::bindings::codegen::Bindings::ServiceWorkerGlobalScopeBinding;
|
||||||
use crate::dom::bindings::codegen::Bindings::ServiceWorkerGlobalScopeBinding::ServiceWorkerGlobalScopeMethods;
|
use crate::dom::bindings::codegen::Bindings::ServiceWorkerGlobalScopeBinding::ServiceWorkerGlobalScopeMethods;
|
||||||
|
use crate::dom::bindings::codegen::Bindings::WorkerBinding::WorkerType;
|
||||||
use crate::dom::bindings::inheritance::Castable;
|
use crate::dom::bindings::inheritance::Castable;
|
||||||
use crate::dom::bindings::reflector::DomObject;
|
use crate::dom::bindings::reflector::DomObject;
|
||||||
use crate::dom::bindings::root::{DomRoot, RootCollection, ThreadLocalStackRoots};
|
use crate::dom::bindings::root::{DomRoot, RootCollection, ThreadLocalStackRoots};
|
||||||
|
@ -203,6 +204,8 @@ impl ServiceWorkerGlobalScope {
|
||||||
ServiceWorkerGlobalScope {
|
ServiceWorkerGlobalScope {
|
||||||
workerglobalscope: WorkerGlobalScope::new_inherited(
|
workerglobalscope: WorkerGlobalScope::new_inherited(
|
||||||
init,
|
init,
|
||||||
|
DOMString::new(),
|
||||||
|
WorkerType::Classic, // FIXME(cybai): Should be provided from `Run Service Worker`
|
||||||
worker_url,
|
worker_url,
|
||||||
runtime,
|
runtime,
|
||||||
from_devtools_receiver,
|
from_devtools_receiver,
|
||||||
|
|
|
@ -24,6 +24,6 @@ interface ServiceWorkerContainer : EventTarget {
|
||||||
|
|
||||||
dictionary RegistrationOptions {
|
dictionary RegistrationOptions {
|
||||||
USVString scope;
|
USVString scope;
|
||||||
//WorkerType type = "classic";
|
WorkerType type = "classic";
|
||||||
ServiceWorkerUpdateViaCache updateViaCache = "imports";
|
ServiceWorkerUpdateViaCache updateViaCache = "imports";
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,12 +9,22 @@ interface AbstractWorker {
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#worker
|
// https://html.spec.whatwg.org/multipage/#worker
|
||||||
[Constructor(DOMString scriptURL), Exposed=(Window,Worker)]
|
[Constructor(USVString scriptURL, optional WorkerOptions options), Exposed=(Window,Worker)]
|
||||||
interface Worker : EventTarget {
|
interface Worker : EventTarget {
|
||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
[Throws]
|
[Throws] void postMessage(any message/*, sequence<object> transfer*/);
|
||||||
void postMessage(any message/*, optional sequence<Transferable> transfer*/);
|
// void postMessage(any message, optional PostMessageOptions options);
|
||||||
attribute EventHandler onmessage;
|
attribute EventHandler onmessage;
|
||||||
|
attribute EventHandler onmessageerror;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dictionary WorkerOptions {
|
||||||
|
WorkerType type = "classic";
|
||||||
|
RequestCredentials credentials = "same-origin"; // credentials is only used if type is "module"
|
||||||
|
DOMString name = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
enum WorkerType { "classic", "module" };
|
||||||
|
|
||||||
Worker implements AbstractWorker;
|
Worker implements AbstractWorker;
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
use crate::dom::abstractworker::SimpleWorkerErrorHandler;
|
use crate::dom::abstractworker::SimpleWorkerErrorHandler;
|
||||||
use crate::dom::abstractworker::WorkerScriptMsg;
|
use crate::dom::abstractworker::WorkerScriptMsg;
|
||||||
use crate::dom::bindings::codegen::Bindings::WorkerBinding;
|
use crate::dom::bindings::codegen::Bindings::WorkerBinding;
|
||||||
use crate::dom::bindings::codegen::Bindings::WorkerBinding::WorkerMethods;
|
use crate::dom::bindings::codegen::Bindings::WorkerBinding::{WorkerMethods, WorkerOptions};
|
||||||
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
|
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||||
use crate::dom::bindings::inheritance::Castable;
|
use crate::dom::bindings::inheritance::Castable;
|
||||||
use crate::dom::bindings::refcounted::Trusted;
|
use crate::dom::bindings::refcounted::Trusted;
|
||||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
|
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
|
||||||
use crate::dom::bindings::root::DomRoot;
|
use crate::dom::bindings::root::DomRoot;
|
||||||
use crate::dom::bindings::str::DOMString;
|
use crate::dom::bindings::str::USVString;
|
||||||
use crate::dom::bindings::structuredclone::StructuredCloneData;
|
use crate::dom::bindings::structuredclone::StructuredCloneData;
|
||||||
use crate::dom::dedicatedworkerglobalscope::{
|
use crate::dom::dedicatedworkerglobalscope::{
|
||||||
DedicatedWorkerGlobalScope, DedicatedWorkerScriptMsg,
|
DedicatedWorkerGlobalScope, DedicatedWorkerScriptMsg,
|
||||||
|
@ -72,7 +72,11 @@ impl Worker {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-worker
|
// https://html.spec.whatwg.org/multipage/#dom-worker
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub fn Constructor(global: &GlobalScope, script_url: DOMString) -> Fallible<DomRoot<Worker>> {
|
pub fn Constructor(
|
||||||
|
global: &GlobalScope,
|
||||||
|
script_url: USVString,
|
||||||
|
worker_options: &WorkerOptions,
|
||||||
|
) -> Fallible<DomRoot<Worker>> {
|
||||||
// Step 2-4.
|
// Step 2-4.
|
||||||
let worker_url = match global.api_base_url().join(&script_url) {
|
let worker_url = match global.api_base_url().join(&script_url) {
|
||||||
Ok(url) => url,
|
Ok(url) => url,
|
||||||
|
@ -118,6 +122,8 @@ impl Worker {
|
||||||
sender,
|
sender,
|
||||||
receiver,
|
receiver,
|
||||||
worker_load_origin,
|
worker_load_origin,
|
||||||
|
String::from(&*worker_options.name),
|
||||||
|
worker_options.type_,
|
||||||
closing,
|
closing,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -184,6 +190,9 @@ impl WorkerMethods for Worker {
|
||||||
// https://html.spec.whatwg.org/multipage/#handler-worker-onmessage
|
// https://html.spec.whatwg.org/multipage/#handler-worker-onmessage
|
||||||
event_handler!(message, GetOnmessage, SetOnmessage);
|
event_handler!(message, GetOnmessage, SetOnmessage);
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#handler-worker-onmessageerror
|
||||||
|
event_handler!(messageerror, GetOnmessageerror, SetOnmessageerror);
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#handler-workerglobalscope-onerror
|
// https://html.spec.whatwg.org/multipage/#handler-workerglobalscope-onerror
|
||||||
event_handler!(error, GetOnerror, SetOnerror);
|
event_handler!(error, GetOnerror, SetOnerror);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
use crate::dom::bindings::cell::DomRefCell;
|
use crate::dom::bindings::cell::DomRefCell;
|
||||||
use crate::dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
use crate::dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
||||||
use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestInit;
|
use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestInit;
|
||||||
|
use crate::dom::bindings::codegen::Bindings::WorkerBinding::WorkerType;
|
||||||
use crate::dom::bindings::codegen::Bindings::WorkerGlobalScopeBinding::WorkerGlobalScopeMethods;
|
use crate::dom::bindings::codegen::Bindings::WorkerGlobalScopeBinding::WorkerGlobalScopeMethods;
|
||||||
use crate::dom::bindings::codegen::UnionTypes::RequestOrUSVString;
|
use crate::dom::bindings::codegen::UnionTypes::RequestOrUSVString;
|
||||||
use crate::dom::bindings::error::{report_pending_exception, Error, ErrorResult, Fallible};
|
use crate::dom::bindings::error::{report_pending_exception, Error, ErrorResult, Fallible};
|
||||||
|
@ -79,6 +80,9 @@ pub fn prepare_workerscope_init(
|
||||||
pub struct WorkerGlobalScope {
|
pub struct WorkerGlobalScope {
|
||||||
globalscope: GlobalScope,
|
globalscope: GlobalScope,
|
||||||
|
|
||||||
|
worker_name: DOMString,
|
||||||
|
worker_type: WorkerType,
|
||||||
|
|
||||||
worker_id: WorkerId,
|
worker_id: WorkerId,
|
||||||
worker_url: DomRefCell<ServoUrl>,
|
worker_url: DomRefCell<ServoUrl>,
|
||||||
#[ignore_malloc_size_of = "Arc"]
|
#[ignore_malloc_size_of = "Arc"]
|
||||||
|
@ -105,6 +109,8 @@ pub struct WorkerGlobalScope {
|
||||||
impl WorkerGlobalScope {
|
impl WorkerGlobalScope {
|
||||||
pub fn new_inherited(
|
pub fn new_inherited(
|
||||||
init: WorkerGlobalScopeInit,
|
init: WorkerGlobalScopeInit,
|
||||||
|
worker_name: DOMString,
|
||||||
|
worker_type: WorkerType,
|
||||||
worker_url: ServoUrl,
|
worker_url: ServoUrl,
|
||||||
runtime: Runtime,
|
runtime: Runtime,
|
||||||
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
|
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
|
||||||
|
@ -125,6 +131,8 @@ impl WorkerGlobalScope {
|
||||||
Default::default(),
|
Default::default(),
|
||||||
),
|
),
|
||||||
worker_id: init.worker_id,
|
worker_id: init.worker_id,
|
||||||
|
worker_name,
|
||||||
|
worker_type,
|
||||||
worker_url: DomRefCell::new(worker_url),
|
worker_url: DomRefCell::new(worker_url),
|
||||||
closing,
|
closing,
|
||||||
runtime,
|
runtime,
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
//! by multiple service worker clients in a Vec.
|
//! by multiple service worker clients in a Vec.
|
||||||
|
|
||||||
use crate::dom::bindings::cell::DomRefCell;
|
use crate::dom::bindings::cell::DomRefCell;
|
||||||
|
use crate::dom::bindings::codegen::Bindings::WorkerBinding::WorkerType;
|
||||||
use crate::dom::bindings::error::Error;
|
use crate::dom::bindings::error::Error;
|
||||||
use crate::dom::bindings::refcounted::{Trusted, TrustedPromise};
|
use crate::dom::bindings::refcounted::{Trusted, TrustedPromise};
|
||||||
use crate::dom::bindings::reflector::DomObject;
|
use crate::dom::bindings::reflector::DomObject;
|
||||||
|
@ -45,6 +46,7 @@ pub struct Job {
|
||||||
pub script_url: ServoUrl,
|
pub script_url: ServoUrl,
|
||||||
pub promise: Rc<Promise>,
|
pub promise: Rc<Promise>,
|
||||||
pub equivalent_jobs: Vec<Job>,
|
pub equivalent_jobs: Vec<Job>,
|
||||||
|
pub worker_type: WorkerType,
|
||||||
// client can be a window client, worker client so `Client` will be an enum in future
|
// client can be a window client, worker client so `Client` will be an enum in future
|
||||||
pub client: Dom<Client>,
|
pub client: Dom<Client>,
|
||||||
pub referrer: ServoUrl,
|
pub referrer: ServoUrl,
|
||||||
|
@ -58,6 +60,7 @@ impl Job {
|
||||||
scope_url: ServoUrl,
|
scope_url: ServoUrl,
|
||||||
script_url: ServoUrl,
|
script_url: ServoUrl,
|
||||||
promise: Rc<Promise>,
|
promise: Rc<Promise>,
|
||||||
|
worker_type: WorkerType,
|
||||||
client: &Client,
|
client: &Client,
|
||||||
) -> Job {
|
) -> Job {
|
||||||
Job {
|
Job {
|
||||||
|
@ -66,6 +69,7 @@ impl Job {
|
||||||
script_url: script_url,
|
script_url: script_url,
|
||||||
promise: promise,
|
promise: promise,
|
||||||
equivalent_jobs: vec![],
|
equivalent_jobs: vec![],
|
||||||
|
worker_type,
|
||||||
client: Dom::from_ref(client),
|
client: Dom::from_ref(client),
|
||||||
referrer: client.creation_url(),
|
referrer: client.creation_url(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -10511,9 +10511,6 @@
|
||||||
[BroadcastChannel interface: attribute onmessageerror]
|
[BroadcastChannel interface: attribute onmessageerror]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Worker interface: attribute onmessageerror]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[SharedWorker interface: existence and properties of interface object]
|
[SharedWorker interface: existence and properties of interface object]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -558,9 +558,6 @@
|
||||||
[WorkerGlobalScope interface: attribute onrejectionhandled]
|
[WorkerGlobalScope interface: attribute onrejectionhandled]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Worker interface: attribute onmessageerror]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[OffscreenCanvasRenderingContext2D interface: operation createImageData(ImageData)]
|
[OffscreenCanvasRenderingContext2D interface: operation createImageData(ImageData)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
[dedicated-worker-options-type.html]
|
|
||||||
[Test worker construction with an empty worker type.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Test worker construction with an unknown worker type.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue