Implementing Close function and mark success tests.

This commit is contained in:
Morris Tseng 2016-07-19 15:50:16 +08:00
parent 701e678d8e
commit d23ef77645
7 changed files with 29 additions and 19 deletions

View file

@ -368,6 +368,12 @@ impl DedicatedWorkerGlobalScopeMethods for DedicatedWorkerGlobalScope {
Ok(())
}
// https://html.spec.whatwg.org/multipage/#dom-dedicatedworkerglobalscope-close
fn Close(&self) {
// Step 2
self.upcast::<WorkerGlobalScope>().close();
}
// https://html.spec.whatwg.org/multipage/#handler-dedicatedworkerglobalscope-onmessage
event_handler!(message, GetOnmessage, SetOnmessage);
}

View file

@ -8,4 +8,6 @@
[Throws]
void postMessage(any message/*, optional sequence<Transferable> transfer*/);
attribute EventHandler onmessage;
void close();
};

View file

@ -27,6 +27,7 @@ use js::jsapi::{HandleValue, JSContext, JSAutoCompartment};
use js::jsval::UndefinedValue;
use script_thread::Runnable;
use script_traits::WorkerScriptLoadOrigin;
use std::cell::Cell;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{Sender, channel};
use std::sync::{Arc, Mutex};
@ -43,7 +44,8 @@ pub struct Worker {
sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>,
closing: Arc<AtomicBool>,
#[ignore_heap_size_of = "Defined in rust-mozjs"]
runtime: Arc<Mutex<Option<SharedRt>>>
runtime: Arc<Mutex<Option<SharedRt>>>,
terminated: Cell<bool>,
}
impl Worker {
@ -53,7 +55,8 @@ impl Worker {
eventtarget: EventTarget::new_inherited(),
sender: sender,
closing: closing,
runtime: Arc::new(Mutex::new(None))
runtime: Arc::new(Mutex::new(None)),
terminated: Cell::new(false),
}
}
@ -112,11 +115,15 @@ impl Worker {
self.closing.load(Ordering::SeqCst)
}
pub fn is_terminated(&self) -> bool {
self.terminated.get()
}
pub fn handle_message(address: TrustedWorkerAddress,
data: StructuredCloneData) {
let worker = address.root();
if worker.is_closing() {
if worker.is_terminated() {
return;
}
@ -137,7 +144,7 @@ impl Worker {
filename: DOMString, lineno: u32, colno: u32) {
let worker = address.root();
if worker.is_closing() {
if worker.is_terminated() {
return;
}
@ -169,7 +176,10 @@ impl WorkerMethods for Worker {
return;
}
// Step 4
// Step 2
self.terminated.set(true);
// Step 3
if let Some(runtime) = *self.runtime.lock().unwrap() {
runtime.request_interrupt();
}

View file

@ -453,4 +453,10 @@ impl WorkerGlobalScope {
pub fn set_devtools_wants_updates(&self, value: bool) {
self.devtools_wants_updates.set(value);
}
pub fn close(&self) {
if let Some(ref closing) = self.closing {
closing.store(true, Ordering::SeqCst);
}
}
}

View file

@ -1,5 +0,0 @@
[WorkerGlobalScope_close.htm]
type: testharness
[ WorkerGlobalScope close(): clear events queue ]
expected: FAIL

View file

@ -21,9 +21,6 @@
[DedicatedWorkerGlobalScope interface: attribute onmessage]
expected: FAIL
[WorkerGlobalScope interface: self must inherit property "close" with the proper type (2)]
expected: FAIL
[WorkerGlobalScope interface: self must inherit property "onerror" with the proper type (3)]
expected: FAIL

View file

@ -1,6 +0,0 @@
[sending-messages.html]
type: testharness
expected: TIMEOUT
[close() and sending messages]
expected: TIMEOUT