aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/worker.rs
diff options
context:
space:
mode:
authorMorris Tseng <mtseng@mozilla.com>2016-07-19 15:50:16 +0800
committerMorris Tseng <mtseng@mozilla.com>2016-07-25 11:59:32 +0800
commitd23ef776455ce7903150fd999ae2293842071f16 (patch)
tree851f90200507bc790260a82067e69c493402b2aa /components/script/dom/worker.rs
parent701e678d8eac3ebab7309759988832932f89af56 (diff)
downloadservo-d23ef776455ce7903150fd999ae2293842071f16.tar.gz
servo-d23ef776455ce7903150fd999ae2293842071f16.zip
Implementing Close function and mark success tests.
Diffstat (limited to 'components/script/dom/worker.rs')
-rw-r--r--components/script/dom/worker.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/components/script/dom/worker.rs b/components/script/dom/worker.rs
index c318672fb7a..c1ad7cf5a96 100644
--- a/components/script/dom/worker.rs
+++ b/components/script/dom/worker.rs
@@ -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();
}