Skip to content
Permalink
Browse files

Update Worker webidl to support WorkerOptions

  • Loading branch information...
CYBAI committed May 2, 2019
1 parent 81f750a commit dececad3905ccf8834abc37e71c7c1a8ac7542c7
@@ -9,6 +9,7 @@ use crate::dom::abstractworkerglobalscope::{SendableWorkerScriptChan, WorkerThre
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::DedicatedWorkerGlobalScopeBinding;
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::inheritance::Castable;
use crate::dom::bindings::reflector::DomObject;
@@ -212,6 +213,8 @@ impl WorkerEventLoopMethods for DedicatedWorkerGlobalScope {
impl DedicatedWorkerGlobalScope {
fn new_inherited(
init: WorkerGlobalScopeInit,
worker_name: DOMString,
worker_type: WorkerType,
worker_url: ServoUrl,
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
runtime: Runtime,
@@ -225,6 +228,8 @@ impl DedicatedWorkerGlobalScope {
DedicatedWorkerGlobalScope {
workerglobalscope: WorkerGlobalScope::new_inherited(
init,
worker_name,
worker_type,
worker_url,
runtime,
from_devtools_receiver,
@@ -242,6 +247,8 @@ impl DedicatedWorkerGlobalScope {
#[allow(unsafe_code)]
pub fn new(
init: WorkerGlobalScopeInit,
worker_name: DOMString,
worker_type: WorkerType,
worker_url: ServoUrl,
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
runtime: Runtime,
@@ -255,6 +262,8 @@ impl DedicatedWorkerGlobalScope {
let cx = runtime.cx();
let scope = Box::new(DedicatedWorkerGlobalScope::new_inherited(
init,
worker_name,
worker_type,
worker_url,
from_devtools_receiver,
runtime,
@@ -279,6 +288,8 @@ impl DedicatedWorkerGlobalScope {
own_sender: Sender<DedicatedWorkerScriptMsg>,
receiver: Receiver<DedicatedWorkerScriptMsg>,
worker_load_origin: WorkerScriptLoadOrigin,
worker_name: String,
worker_type: WorkerType,
closing: Arc<AtomicBool>,
) {
let serialized_worker_url = worker_url.to_string();
@@ -338,6 +349,8 @@ impl DedicatedWorkerGlobalScope {

let global = DedicatedWorkerGlobalScope::new(
init,
DOMString::from_string(worker_name),
worker_type,
worker_url,
devtools_mpsc_port,
runtime,
@@ -53,7 +53,7 @@ impl ServiceWorkerContainerMethods for ServiceWorkerContainer {
}

#[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
fn Register(&self, script_url: USVString, options: &RegistrationOptions) -> Rc<Promise> {
// A: Step 1
@@ -127,6 +127,7 @@ impl ServiceWorkerContainerMethods for ServiceWorkerContainer {
scope,
script_url,
promise.clone(),
options.type_,
&*self.client,
);
// 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::bindings::codegen::Bindings::ServiceWorkerGlobalScopeBinding;
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::reflector::DomObject;
use crate::dom::bindings::root::{DomRoot, RootCollection, ThreadLocalStackRoots};
@@ -203,6 +204,8 @@ impl ServiceWorkerGlobalScope {
ServiceWorkerGlobalScope {
workerglobalscope: WorkerGlobalScope::new_inherited(
init,
DOMString::new(),
WorkerType::Classic, // FIXME(cybai): Should be provided from `Run Service Worker`
worker_url,
runtime,
from_devtools_receiver,
@@ -24,6 +24,6 @@ interface ServiceWorkerContainer : EventTarget {

dictionary RegistrationOptions {
USVString scope;
//WorkerType type = "classic";
WorkerType type = "classic";
ServiceWorkerUpdateViaCache updateViaCache = "imports";
};
@@ -9,12 +9,22 @@ interface AbstractWorker {
};

// 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 {
void terminate();

[Throws]
void postMessage(any message/*, optional sequence<Transferable> transfer*/);
attribute EventHandler onmessage;
[Throws] void postMessage(any message/*, sequence<object> transfer*/);
// void postMessage(any message, optional PostMessageOptions options);
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;
@@ -5,13 +5,13 @@
use crate::dom::abstractworker::SimpleWorkerErrorHandler;
use crate::dom::abstractworker::WorkerScriptMsg;
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::inheritance::Castable;
use crate::dom::bindings::refcounted::Trusted;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
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::dedicatedworkerglobalscope::{
DedicatedWorkerGlobalScope, DedicatedWorkerScriptMsg,
@@ -72,7 +72,11 @@ impl Worker {

// https://html.spec.whatwg.org/multipage/#dom-worker
#[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.
let worker_url = match global.api_base_url().join(&script_url) {
Ok(url) => url,
@@ -118,6 +122,8 @@ impl Worker {
sender,
receiver,
worker_load_origin,
String::from(&*worker_options.name),
worker_options.type_,
closing,
);

@@ -184,6 +190,9 @@ impl WorkerMethods for Worker {
// https://html.spec.whatwg.org/multipage/#handler-worker-onmessage
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
event_handler!(error, GetOnerror, SetOnerror);
}
@@ -5,6 +5,7 @@
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::FunctionBinding::Function;
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::UnionTypes::RequestOrUSVString;
use crate::dom::bindings::error::{report_pending_exception, Error, ErrorResult, Fallible};
@@ -79,6 +80,9 @@ pub fn prepare_workerscope_init(
pub struct WorkerGlobalScope {
globalscope: GlobalScope,

worker_name: DOMString,
worker_type: WorkerType,

worker_id: WorkerId,
worker_url: DomRefCell<ServoUrl>,
#[ignore_malloc_size_of = "Arc"]
@@ -105,6 +109,8 @@ pub struct WorkerGlobalScope {
impl WorkerGlobalScope {
pub fn new_inherited(
init: WorkerGlobalScopeInit,
worker_name: DOMString,
worker_type: WorkerType,
worker_url: ServoUrl,
runtime: Runtime,
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
@@ -125,6 +131,8 @@ impl WorkerGlobalScope {
Default::default(),
),
worker_id: init.worker_id,
worker_name,
worker_type,
worker_url: DomRefCell::new(worker_url),
closing,
runtime,
@@ -8,6 +8,7 @@
//! by multiple service worker clients in a Vec.

use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WorkerBinding::WorkerType;
use crate::dom::bindings::error::Error;
use crate::dom::bindings::refcounted::{Trusted, TrustedPromise};
use crate::dom::bindings::reflector::DomObject;
@@ -45,6 +46,7 @@ pub struct Job {
pub script_url: ServoUrl,
pub promise: Rc<Promise>,
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
pub client: Dom<Client>,
pub referrer: ServoUrl,
@@ -58,6 +60,7 @@ impl Job {
scope_url: ServoUrl,
script_url: ServoUrl,
promise: Rc<Promise>,
worker_type: WorkerType,
client: &Client,
) -> Job {
Job {
@@ -66,6 +69,7 @@ impl Job {
script_url: script_url,
promise: promise,
equivalent_jobs: vec![],
worker_type,
client: Dom::from_ref(client),
referrer: client.creation_url(),
}
@@ -10511,9 +10511,6 @@
[BroadcastChannel interface: attribute onmessageerror]
expected: FAIL

[Worker interface: attribute onmessageerror]
expected: FAIL

[SharedWorker interface: existence and properties of interface object]
expected: FAIL

@@ -558,9 +558,6 @@
[WorkerGlobalScope interface: attribute onrejectionhandled]
expected: FAIL

[Worker interface: attribute onmessageerror]
expected: FAIL

[OffscreenCanvasRenderingContext2D interface: operation createImageData(ImageData)]
expected: FAIL

This file was deleted.

Oops, something went wrong.

0 comments on commit dececad

Please sign in to comment.
You can’t perform that action at this time.