Add worker scope variants to the Global enums.

This commit is contained in:
Ms2ger 2014-07-15 19:40:55 +02:00
parent a345f413cb
commit d8152646f3

View file

@ -6,6 +6,7 @@
use dom::bindings::js::{JS, JSRef, Root};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::workerglobalscope::WorkerGlobalScope;
use dom::window::Window;
use page::Page;
use script_task::ScriptChan;
@ -16,27 +17,32 @@ use url::Url;
pub enum GlobalRef<'a> {
Window(JSRef<'a, Window>),
Worker(JSRef<'a, WorkerGlobalScope>),
}
pub enum GlobalRoot<'a, 'b> {
WindowRoot(Root<'a, 'b, Window>),
WorkerRoot(Root<'a, 'b, WorkerGlobalScope>),
}
#[deriving(Encodable)]
pub enum GlobalField {
WindowField(JS<Window>),
WorkerField(JS<WorkerGlobalScope>),
}
impl<'a> GlobalRef<'a> {
pub fn get_cx(&self) -> *mut JSContext {
match *self {
Window(ref window) => window.get_cx(),
Worker(_) => fail!("NYI"),
}
}
pub fn as_window<'b>(&'b self) -> &'b JSRef<'b, Window> {
match *self {
Window(ref window) => window,
Worker(_) => fail!("expected a Window scope"),
}
}
@ -57,6 +63,7 @@ impl<'a> Reflectable for GlobalRef<'a> {
fn reflector<'b>(&'b self) -> &'b Reflector {
match *self {
Window(ref window) => window.reflector(),
Worker(ref worker) => worker.reflector(),
}
}
}
@ -65,6 +72,7 @@ impl<'a, 'b> GlobalRoot<'a, 'b> {
pub fn root_ref<'c>(&'c self) -> GlobalRef<'c> {
match *self {
WindowRoot(ref window) => Window(window.root_ref()),
WorkerRoot(ref worker) => Worker(worker.root_ref()),
}
}
}
@ -73,12 +81,14 @@ impl GlobalField {
pub fn from_rooted(global: &GlobalRef) -> GlobalField {
match *global {
Window(ref window) => WindowField(JS::from_rooted(window)),
Worker(ref worker) => WorkerField(JS::from_rooted(worker)),
}
}
pub fn root(&self) -> GlobalRoot {
match *self {
WindowField(ref window) => WindowRoot(window.root()),
WorkerField(ref worker) => WorkerRoot(worker.root()),
}
}
}