mirror of
https://github.com/servo/servo.git
synced 2025-06-15 03:44:30 +00:00
Merge pull request #2842 from Ms2ger/workers
Basic Web Workers; r=Manishearth,larsbergstrom
This commit is contained in:
commit
a3127593c2
13 changed files with 328 additions and 19 deletions
|
@ -15,6 +15,9 @@
|
||||||
|
|
||||||
DOMInterfaces = {
|
DOMInterfaces = {
|
||||||
|
|
||||||
|
'DedicatedWorkerGlobalScope': {
|
||||||
|
'createGlobal': True,
|
||||||
|
},
|
||||||
'EventListener': {
|
'EventListener': {
|
||||||
'nativeType': 'EventListenerBinding::EventListener',
|
'nativeType': 'EventListenerBinding::EventListener',
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
use dom::bindings::js::{JS, JSRef, Root};
|
use dom::bindings::js::{JS, JSRef, Root};
|
||||||
use dom::bindings::utils::{Reflectable, Reflector};
|
use dom::bindings::utils::{Reflectable, Reflector};
|
||||||
|
use dom::workerglobalscope::WorkerGlobalScope;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use page::Page;
|
use page::Page;
|
||||||
use script_task::ScriptChan;
|
use script_task::ScriptChan;
|
||||||
|
@ -16,27 +17,32 @@ use url::Url;
|
||||||
|
|
||||||
pub enum GlobalRef<'a> {
|
pub enum GlobalRef<'a> {
|
||||||
Window(JSRef<'a, Window>),
|
Window(JSRef<'a, Window>),
|
||||||
|
Worker(JSRef<'a, WorkerGlobalScope>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum GlobalRoot<'a, 'b> {
|
pub enum GlobalRoot<'a, 'b> {
|
||||||
WindowRoot(Root<'a, 'b, Window>),
|
WindowRoot(Root<'a, 'b, Window>),
|
||||||
|
WorkerRoot(Root<'a, 'b, WorkerGlobalScope>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Encodable)]
|
#[deriving(Encodable)]
|
||||||
pub enum GlobalField {
|
pub enum GlobalField {
|
||||||
WindowField(JS<Window>),
|
WindowField(JS<Window>),
|
||||||
|
WorkerField(JS<WorkerGlobalScope>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> GlobalRef<'a> {
|
impl<'a> GlobalRef<'a> {
|
||||||
pub fn get_cx(&self) -> *mut JSContext {
|
pub fn get_cx(&self) -> *mut JSContext {
|
||||||
match *self {
|
match *self {
|
||||||
Window(ref window) => window.get_cx(),
|
Window(ref window) => window.get_cx(),
|
||||||
|
Worker(ref worker) => worker.get_cx(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_window<'b>(&'b self) -> &'b JSRef<'b, Window> {
|
pub fn as_window<'b>(&'b self) -> &'b JSRef<'b, Window> {
|
||||||
match *self {
|
match *self {
|
||||||
Window(ref window) => window,
|
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 {
|
fn reflector<'b>(&'b self) -> &'b Reflector {
|
||||||
match *self {
|
match *self {
|
||||||
Window(ref window) => window.reflector(),
|
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> {
|
pub fn root_ref<'c>(&'c self) -> GlobalRef<'c> {
|
||||||
match *self {
|
match *self {
|
||||||
WindowRoot(ref window) => Window(window.root_ref()),
|
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 {
|
pub fn from_rooted(global: &GlobalRef) -> GlobalField {
|
||||||
match *global {
|
match *global {
|
||||||
Window(ref window) => WindowField(JS::from_rooted(window)),
|
Window(ref window) => WindowField(JS::from_rooted(window)),
|
||||||
|
Worker(ref worker) => WorkerField(JS::from_rooted(worker)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn root(&self) -> GlobalRoot {
|
pub fn root(&self) -> GlobalRoot {
|
||||||
match *self {
|
match *self {
|
||||||
WindowField(ref window) => WindowRoot(window.root()),
|
WindowField(ref window) => WindowRoot(window.root()),
|
||||||
|
WorkerField(ref worker) => WorkerRoot(worker.root()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use dom::bindings::codegen::PrototypeList;
|
use dom::bindings::codegen::PrototypeList;
|
||||||
use dom::bindings::codegen::PrototypeList::MAX_PROTO_CHAIN_LENGTH;
|
use dom::bindings::codegen::PrototypeList::MAX_PROTO_CHAIN_LENGTH;
|
||||||
use dom::bindings::conversions::{FromJSValConvertible, IDLInterface};
|
use dom::bindings::conversions::{FromJSValConvertible, IDLInterface};
|
||||||
use dom::bindings::global::{GlobalRef, GlobalField, WindowField};
|
use dom::bindings::global::{GlobalRef, GlobalField, WindowField, WorkerField};
|
||||||
use dom::bindings::js::{JS, Temporary, Root};
|
use dom::bindings::js::{JS, Temporary, Root};
|
||||||
use dom::bindings::trace::Untraceable;
|
use dom::bindings::trace::Untraceable;
|
||||||
use dom::browsercontext;
|
use dom::browsercontext;
|
||||||
|
@ -591,7 +591,12 @@ pub fn global_object_for_js_object(obj: *mut JSObject) -> GlobalField {
|
||||||
Err(_) => (),
|
Err(_) => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
fail!("found DOM global that doesn't unwrap to Window")
|
match FromJSValConvertible::from_jsval(ptr::mut_null(), ObjectOrNullValue(global), ()) {
|
||||||
|
Ok(worker) => return WorkerField(worker),
|
||||||
|
Err(_) => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
fail!("found DOM global that doesn't unwrap to Window or WorkerGlobalScope")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
62
src/components/script/dom/dedicatedworkerglobalscope.rs
Normal file
62
src/components/script/dom/dedicatedworkerglobalscope.rs
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use dom::bindings::codegen::Bindings::DedicatedWorkerGlobalScopeBinding;
|
||||||
|
use dom::bindings::codegen::InheritTypes::DedicatedWorkerGlobalScopeDerived;
|
||||||
|
use dom::bindings::js::Temporary;
|
||||||
|
use dom::bindings::utils::{Reflectable, Reflector};
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
|
use dom::eventtarget::WorkerGlobalScopeTypeId;
|
||||||
|
use dom::workerglobalscope::DedicatedGlobalScope;
|
||||||
|
use dom::workerglobalscope::WorkerGlobalScope;
|
||||||
|
use script_task::ScriptTask;
|
||||||
|
|
||||||
|
use js::rust::Cx;
|
||||||
|
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
#[deriving(Encodable)]
|
||||||
|
pub struct DedicatedWorkerGlobalScope {
|
||||||
|
workerglobalscope: WorkerGlobalScope,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DedicatedWorkerGlobalScope {
|
||||||
|
pub fn new_inherited(cx: Rc<Cx>) -> DedicatedWorkerGlobalScope {
|
||||||
|
DedicatedWorkerGlobalScope {
|
||||||
|
workerglobalscope: WorkerGlobalScope::new_inherited(DedicatedGlobalScope, cx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(cx: Rc<Cx>) -> Temporary<DedicatedWorkerGlobalScope> {
|
||||||
|
let scope = box DedicatedWorkerGlobalScope::new_inherited(cx.clone());
|
||||||
|
DedicatedWorkerGlobalScopeBinding::Wrap(cx.ptr, scope)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init() -> Temporary<DedicatedWorkerGlobalScope> {
|
||||||
|
let (_js_runtime, js_context) = ScriptTask::new_rt_and_cx();
|
||||||
|
DedicatedWorkerGlobalScope::new(js_context.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_rust_cx<'a>(&'a self) -> &'a Rc<Cx> {
|
||||||
|
self.workerglobalscope.get_rust_cx()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait DedicatedWorkerGlobalScopeMethods {
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Reflectable for DedicatedWorkerGlobalScope {
|
||||||
|
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||||
|
self.workerglobalscope.reflector()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DedicatedWorkerGlobalScopeDerived for EventTarget {
|
||||||
|
fn is_dedicatedworkerglobalscope(&self) -> bool {
|
||||||
|
match self.type_id {
|
||||||
|
WorkerGlobalScopeTypeId(DedicatedGlobalScope) => true,
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ use dom::bindings::utils::{Reflectable, Reflector};
|
||||||
use dom::event::Event;
|
use dom::event::Event;
|
||||||
use dom::eventdispatcher::dispatch_event;
|
use dom::eventdispatcher::dispatch_event;
|
||||||
use dom::node::NodeTypeId;
|
use dom::node::NodeTypeId;
|
||||||
|
use dom::workerglobalscope::WorkerGlobalScopeId;
|
||||||
use dom::xmlhttprequest::XMLHttpRequestId;
|
use dom::xmlhttprequest::XMLHttpRequestId;
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
use js::jsapi::{JS_CompileUCFunction, JS_GetFunctionObject, JS_CloneFunctionObject};
|
use js::jsapi::{JS_CompileUCFunction, JS_GetFunctionObject, JS_CloneFunctionObject};
|
||||||
|
@ -34,6 +35,8 @@ pub enum ListenerPhase {
|
||||||
pub enum EventTargetTypeId {
|
pub enum EventTargetTypeId {
|
||||||
NodeTargetTypeId(NodeTypeId),
|
NodeTargetTypeId(NodeTypeId),
|
||||||
WindowTypeId,
|
WindowTypeId,
|
||||||
|
WorkerTypeId,
|
||||||
|
WorkerGlobalScopeTypeId(WorkerGlobalScopeId),
|
||||||
XMLHttpRequestTargetTypeId(XMLHttpRequestId)
|
XMLHttpRequestTargetTypeId(XMLHttpRequestId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
// http://www.whatwg.org/html/#dedicatedworkerglobalscope
|
||||||
|
[Global/*=Worker,DedicatedWorker*/]
|
||||||
|
/*sealed*/ interface DedicatedWorkerGlobalScope : WorkerGlobalScope {
|
||||||
|
//void postMessage(any message, optional sequence<Transferable> transfer);
|
||||||
|
// attribute EventHandler onmessage;
|
||||||
|
};
|
20
src/components/script/dom/webidls/Worker.webidl
Normal file
20
src/components/script/dom/webidls/Worker.webidl
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
// http://www.whatwg.org/html/#abstractworker
|
||||||
|
[NoInterfaceObject/*, Exposed=Window,Worker*/]
|
||||||
|
interface AbstractWorker {
|
||||||
|
// attribute EventHandler onerror;
|
||||||
|
};
|
||||||
|
|
||||||
|
// http://www.whatwg.org/html/#worker
|
||||||
|
[Constructor(DOMString scriptURL)/*, Exposed=Window,Worker*/]
|
||||||
|
interface Worker : EventTarget {
|
||||||
|
//void terminate();
|
||||||
|
|
||||||
|
//void postMessage(any message/*, optional sequence<Transferable> transfer*/);
|
||||||
|
// attribute EventHandler onmessage;
|
||||||
|
};
|
||||||
|
Worker implements AbstractWorker;
|
33
src/components/script/dom/webidls/WorkerGlobalScope.webidl
Normal file
33
src/components/script/dom/webidls/WorkerGlobalScope.webidl
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
// http://www.whatwg.org/html/#workerglobalscope
|
||||||
|
//[Exposed=Worker]
|
||||||
|
interface WorkerGlobalScope : EventTarget {
|
||||||
|
readonly attribute WorkerGlobalScope self;
|
||||||
|
//readonly attribute WorkerLocation location;
|
||||||
|
|
||||||
|
//void close();
|
||||||
|
// attribute OnErrorEventHandler onerror;
|
||||||
|
// attribute EventHandler onlanguagechange;
|
||||||
|
// attribute EventHandler onoffline;
|
||||||
|
// attribute EventHandler ononline;
|
||||||
|
|
||||||
|
// also has obsolete members
|
||||||
|
};
|
||||||
|
|
||||||
|
// http://www.whatwg.org/html/#WorkerGlobalScope-partial
|
||||||
|
//[Exposed=Worker]
|
||||||
|
partial interface WorkerGlobalScope {
|
||||||
|
//void importScripts(DOMString... urls);
|
||||||
|
//readonly attribute WorkerNavigator navigator;
|
||||||
|
};
|
||||||
|
//WorkerGlobalScope implements WindowTimers;
|
||||||
|
//WorkerGlobalScope implements WindowBase64;
|
||||||
|
|
||||||
|
// Proprietary
|
||||||
|
partial interface WorkerGlobalScope {
|
||||||
|
[Replaceable]
|
||||||
|
readonly attribute Console console;
|
||||||
|
};
|
84
src/components/script/dom/worker.rs
Normal file
84
src/components/script/dom/worker.rs
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use dom::bindings::codegen::Bindings::WorkerBinding;
|
||||||
|
use dom::bindings::error::{Fallible, Syntax};
|
||||||
|
use dom::bindings::global::GlobalRef;
|
||||||
|
use dom::bindings::js::{Temporary, RootCollection};
|
||||||
|
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||||
|
use dom::dedicatedworkerglobalscope::DedicatedWorkerGlobalScope;
|
||||||
|
use dom::eventtarget::{EventTarget, WorkerTypeId};
|
||||||
|
use script_task::StackRootTLS;
|
||||||
|
|
||||||
|
use servo_net::resource_task::load_whole_resource;
|
||||||
|
use servo_util::str::DOMString;
|
||||||
|
use servo_util::url::try_parse_url;
|
||||||
|
|
||||||
|
use native;
|
||||||
|
use rustrt::task::TaskOpts;
|
||||||
|
|
||||||
|
#[deriving(Encodable)]
|
||||||
|
pub struct Worker {
|
||||||
|
eventtarget: EventTarget,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Worker {
|
||||||
|
pub fn new_inherited() -> Worker {
|
||||||
|
Worker {
|
||||||
|
eventtarget: EventTarget::new_inherited(WorkerTypeId),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(global: &GlobalRef) -> Temporary<Worker> {
|
||||||
|
reflect_dom_object(box Worker::new_inherited(),
|
||||||
|
global,
|
||||||
|
WorkerBinding::Wrap)
|
||||||
|
}
|
||||||
|
|
||||||
|
// http://www.whatwg.org/html/#dom-worker
|
||||||
|
pub fn Constructor(global: &GlobalRef, scriptURL: DOMString) -> Fallible<Temporary<Worker>> {
|
||||||
|
// Step 2-4.
|
||||||
|
let worker_url = match try_parse_url(scriptURL.as_slice(), Some(global.get_url())) {
|
||||||
|
Ok(url) => url,
|
||||||
|
Err(_) => return Err(Syntax),
|
||||||
|
};
|
||||||
|
|
||||||
|
let resource_task = global.page().resource_task.deref().clone();
|
||||||
|
|
||||||
|
let mut task_opts = TaskOpts::new();
|
||||||
|
task_opts.name = Some(format!("Web Worker at {}", worker_url).into_maybe_owned());
|
||||||
|
native::task::spawn_opts(task_opts, proc() {
|
||||||
|
let roots = RootCollection::new();
|
||||||
|
let _stack_roots_tls = StackRootTLS::new(&roots);
|
||||||
|
|
||||||
|
let (filename, source) = match load_whole_resource(&resource_task, worker_url.clone()) {
|
||||||
|
Err(_) => {
|
||||||
|
println!("error loading script {}", worker_url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Ok((metadata, bytes)) => {
|
||||||
|
(metadata.final_url, String::from_utf8(bytes).unwrap())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let global = DedicatedWorkerGlobalScope::init().root();
|
||||||
|
match global.get_rust_cx().evaluate_script(
|
||||||
|
global.reflector().get_jsobject(), source, filename.to_str(), 1) {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(_) => println!("evaluate_script failed")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(Worker::new(global))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait WorkerMethods {
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Reflectable for Worker {
|
||||||
|
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||||
|
self.eventtarget.reflector()
|
||||||
|
}
|
||||||
|
}
|
71
src/components/script/dom/workerglobalscope.rs
Normal file
71
src/components/script/dom/workerglobalscope.rs
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use dom::bindings::trace::Untraceable;
|
||||||
|
use dom::bindings::global;
|
||||||
|
use dom::bindings::js::{JS, JSRef, Temporary, OptionalSettable};
|
||||||
|
use dom::bindings::utils::{Reflectable, Reflector};
|
||||||
|
use dom::console::Console;
|
||||||
|
use dom::eventtarget::{EventTarget, WorkerGlobalScopeTypeId};
|
||||||
|
|
||||||
|
use js::jsapi::JSContext;
|
||||||
|
use js::rust::Cx;
|
||||||
|
|
||||||
|
use std::cell::Cell;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
#[deriving(PartialEq,Encodable)]
|
||||||
|
pub enum WorkerGlobalScopeId {
|
||||||
|
DedicatedGlobalScope,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[deriving(Encodable)]
|
||||||
|
pub struct WorkerGlobalScope {
|
||||||
|
pub eventtarget: EventTarget,
|
||||||
|
js_context: Untraceable<Rc<Cx>>,
|
||||||
|
console: Cell<Option<JS<Console>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WorkerGlobalScope {
|
||||||
|
pub fn new_inherited(type_id: WorkerGlobalScopeId,
|
||||||
|
cx: Rc<Cx>) -> WorkerGlobalScope {
|
||||||
|
WorkerGlobalScope {
|
||||||
|
eventtarget: EventTarget::new_inherited(WorkerGlobalScopeTypeId(type_id)),
|
||||||
|
js_context: Untraceable::new(cx),
|
||||||
|
console: Cell::new(None),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_rust_cx<'a>(&'a self) -> &'a Rc<Cx> {
|
||||||
|
&*self.js_context
|
||||||
|
}
|
||||||
|
pub fn get_cx(&self) -> *mut JSContext {
|
||||||
|
self.js_context.ptr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait WorkerGlobalScopeMethods {
|
||||||
|
fn Self(&self) -> Temporary<WorkerGlobalScope>;
|
||||||
|
fn Console(&self) -> Temporary<Console>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> WorkerGlobalScopeMethods for JSRef<'a, WorkerGlobalScope> {
|
||||||
|
fn Self(&self) -> Temporary<WorkerGlobalScope> {
|
||||||
|
Temporary::from_rooted(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn Console(&self) -> Temporary<Console> {
|
||||||
|
if self.console.get().is_none() {
|
||||||
|
let console = Console::new(&global::Worker(*self));
|
||||||
|
self.console.assign(Some(console));
|
||||||
|
}
|
||||||
|
Temporary::new(self.console.get().get_ref().clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Reflectable for WorkerGlobalScope {
|
||||||
|
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||||
|
self.eventtarget.reflector()
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,6 +30,7 @@ extern crate js;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate native;
|
extern crate native;
|
||||||
extern crate net;
|
extern crate net;
|
||||||
|
extern crate rustrt;
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
#[phase(plugin)]
|
#[phase(plugin)]
|
||||||
|
@ -75,6 +76,7 @@ pub mod dom {
|
||||||
pub mod comment;
|
pub mod comment;
|
||||||
pub mod console;
|
pub mod console;
|
||||||
pub mod customevent;
|
pub mod customevent;
|
||||||
|
pub mod dedicatedworkerglobalscope;
|
||||||
pub mod document;
|
pub mod document;
|
||||||
pub mod documentfragment;
|
pub mod documentfragment;
|
||||||
pub mod documenttype;
|
pub mod documenttype;
|
||||||
|
@ -174,6 +176,8 @@ pub mod dom {
|
||||||
pub mod validitystate;
|
pub mod validitystate;
|
||||||
pub mod virtualmethods;
|
pub mod virtualmethods;
|
||||||
pub mod window;
|
pub mod window;
|
||||||
|
pub mod worker;
|
||||||
|
pub mod workerglobalscope;
|
||||||
pub mod xmlhttprequest;
|
pub mod xmlhttprequest;
|
||||||
pub mod xmlhttprequesteventtarget;
|
pub mod xmlhttprequesteventtarget;
|
||||||
pub mod xmlhttprequestupload;
|
pub mod xmlhttprequestupload;
|
||||||
|
|
|
@ -115,10 +115,10 @@ impl ScriptChan {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct StackRootTLS;
|
pub struct StackRootTLS;
|
||||||
|
|
||||||
impl StackRootTLS {
|
impl StackRootTLS {
|
||||||
fn new(roots: &RootCollection) -> StackRootTLS {
|
pub fn new(roots: &RootCollection) -> StackRootTLS {
|
||||||
StackRoots.replace(Some(roots as *RootCollection));
|
StackRoots.replace(Some(roots as *RootCollection));
|
||||||
StackRootTLS
|
StackRootTLS
|
||||||
}
|
}
|
||||||
|
@ -210,6 +210,21 @@ impl ScriptTask {
|
||||||
window_size: WindowSizeData)
|
window_size: WindowSizeData)
|
||||||
-> Rc<ScriptTask> {
|
-> Rc<ScriptTask> {
|
||||||
let (js_runtime, js_context) = ScriptTask::new_rt_and_cx();
|
let (js_runtime, js_context) = ScriptTask::new_rt_and_cx();
|
||||||
|
unsafe {
|
||||||
|
// JS_SetWrapObjectCallbacks clobbers the existing wrap callback,
|
||||||
|
// and JSCompartment::wrap crashes if that happens. The only way
|
||||||
|
// to retrieve the default callback is as the result of
|
||||||
|
// JS_SetWrapObjectCallbacks, which is why we call it twice.
|
||||||
|
let callback = JS_SetWrapObjectCallbacks((*js_runtime).ptr,
|
||||||
|
None,
|
||||||
|
Some(wrap_for_same_compartment),
|
||||||
|
None);
|
||||||
|
JS_SetWrapObjectCallbacks((*js_runtime).ptr,
|
||||||
|
callback,
|
||||||
|
Some(wrap_for_same_compartment),
|
||||||
|
Some(pre_wrap));
|
||||||
|
}
|
||||||
|
|
||||||
let page = Page::new(id, None, layout_chan, window_size,
|
let page = Page::new(id, None, layout_chan, window_size,
|
||||||
resource_task.clone(),
|
resource_task.clone(),
|
||||||
constellation_chan.clone(),
|
constellation_chan.clone(),
|
||||||
|
@ -231,26 +246,12 @@ impl ScriptTask {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_rt_and_cx() -> (js::rust::rt, Rc<Cx>) {
|
pub fn new_rt_and_cx() -> (js::rust::rt, Rc<Cx>) {
|
||||||
let js_runtime = js::rust::rt();
|
let js_runtime = js::rust::rt();
|
||||||
assert!({
|
assert!({
|
||||||
let ptr: *mut JSRuntime = (*js_runtime).ptr;
|
let ptr: *mut JSRuntime = (*js_runtime).ptr;
|
||||||
ptr.is_not_null()
|
ptr.is_not_null()
|
||||||
});
|
});
|
||||||
unsafe {
|
|
||||||
// JS_SetWrapObjectCallbacks clobbers the existing wrap callback,
|
|
||||||
// and JSCompartment::wrap crashes if that happens. The only way
|
|
||||||
// to retrieve the default callback is as the result of
|
|
||||||
// JS_SetWrapObjectCallbacks, which is why we call it twice.
|
|
||||||
let callback = JS_SetWrapObjectCallbacks((*js_runtime).ptr,
|
|
||||||
None,
|
|
||||||
Some(wrap_for_same_compartment),
|
|
||||||
None);
|
|
||||||
JS_SetWrapObjectCallbacks((*js_runtime).ptr,
|
|
||||||
callback,
|
|
||||||
Some(wrap_for_same_compartment),
|
|
||||||
Some(pre_wrap));
|
|
||||||
}
|
|
||||||
|
|
||||||
let js_context = js_runtime.cx();
|
let js_context = js_runtime.cx();
|
||||||
assert!({
|
assert!({
|
||||||
|
|
|
@ -59,6 +59,7 @@ var interfaceNamesInGlobalScope = [
|
||||||
"Comment",
|
"Comment",
|
||||||
"Console",
|
"Console",
|
||||||
"CustomEvent",
|
"CustomEvent",
|
||||||
|
"DedicatedWorkerGlobalScope", // #2823
|
||||||
"Document",
|
"Document",
|
||||||
"DocumentFragment",
|
"DocumentFragment",
|
||||||
"DocumentType",
|
"DocumentType",
|
||||||
|
@ -156,6 +157,8 @@ var interfaceNamesInGlobalScope = [
|
||||||
"URLSearchParams",
|
"URLSearchParams",
|
||||||
"ValidityState",
|
"ValidityState",
|
||||||
"Window",
|
"Window",
|
||||||
|
"Worker",
|
||||||
|
"WorkerGlobalScope", // #2823
|
||||||
"XMLHttpRequest",
|
"XMLHttpRequest",
|
||||||
"XMLHttpRequestUpload",
|
"XMLHttpRequestUpload",
|
||||||
];
|
];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue