mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Store the JSContext in a field on the worker global scope.
This commit is contained in:
parent
b11440750b
commit
3074b4747a
4 changed files with 32 additions and 14 deletions
|
@ -35,7 +35,7 @@ impl<'a> GlobalRef<'a> {
|
|||
pub fn get_cx(&self) -> *mut JSContext {
|
||||
match *self {
|
||||
Window(ref window) => window.get_cx(),
|
||||
Worker(_) => fail!("NYI"),
|
||||
Worker(ref worker) => worker.get_cx(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ use dom::workerglobalscope::DedicatedGlobalScope;
|
|||
use dom::workerglobalscope::WorkerGlobalScope;
|
||||
use script_task::ScriptTask;
|
||||
|
||||
use js::jsapi::JSContext;
|
||||
use js::rust::Cx;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
@ -23,21 +22,24 @@ pub struct DedicatedWorkerGlobalScope {
|
|||
}
|
||||
|
||||
impl DedicatedWorkerGlobalScope {
|
||||
pub fn new_inherited() -> DedicatedWorkerGlobalScope {
|
||||
pub fn new_inherited(cx: Rc<Cx>) -> DedicatedWorkerGlobalScope {
|
||||
DedicatedWorkerGlobalScope {
|
||||
workerglobalscope: WorkerGlobalScope::new_inherited(DedicatedGlobalScope),
|
||||
workerglobalscope: WorkerGlobalScope::new_inherited(DedicatedGlobalScope, cx),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(cx: *mut JSContext) -> Temporary<DedicatedWorkerGlobalScope> {
|
||||
let scope = box DedicatedWorkerGlobalScope::new_inherited();
|
||||
DedicatedWorkerGlobalScopeBinding::Wrap(cx, scope)
|
||||
pub fn new(cx: Rc<Cx>) -> Temporary<DedicatedWorkerGlobalScope> {
|
||||
let scope = box DedicatedWorkerGlobalScope::new_inherited(cx.clone());
|
||||
DedicatedWorkerGlobalScopeBinding::Wrap(cx.ptr, scope)
|
||||
}
|
||||
|
||||
pub fn init() -> (Rc<Cx>, Temporary<DedicatedWorkerGlobalScope>) {
|
||||
pub fn init() -> Temporary<DedicatedWorkerGlobalScope> {
|
||||
let (_js_runtime, js_context) = ScriptTask::new_rt_and_cx();
|
||||
let global = DedicatedWorkerGlobalScope::new(js_context.ptr);
|
||||
(js_context, global)
|
||||
DedicatedWorkerGlobalScope::new(js_context.clone())
|
||||
}
|
||||
|
||||
pub fn get_rust_cx<'a>(&'a self) -> &'a Rc<Cx> {
|
||||
self.workerglobalscope.get_rust_cx()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,9 +45,9 @@ impl Worker {
|
|||
}
|
||||
};
|
||||
|
||||
let (cx, global) = DedicatedWorkerGlobalScope::init();
|
||||
let global = global.root();
|
||||
match cx.evaluate_script(global.reflector().get_jsobject(), source, filename.to_str(), 1) {
|
||||
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")
|
||||
}
|
||||
|
|
|
@ -2,9 +2,15 @@
|
|||
* 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::utils::{Reflectable, Reflector};
|
||||
use dom::eventtarget::{EventTarget, WorkerGlobalScopeTypeId};
|
||||
|
||||
use js::jsapi::JSContext;
|
||||
use js::rust::Cx;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
#[deriving(PartialEq,Encodable)]
|
||||
pub enum WorkerGlobalScopeId {
|
||||
DedicatedGlobalScope,
|
||||
|
@ -13,14 +19,24 @@ pub enum WorkerGlobalScopeId {
|
|||
#[deriving(Encodable)]
|
||||
pub struct WorkerGlobalScope {
|
||||
pub eventtarget: EventTarget,
|
||||
js_context: Untraceable<Rc<Cx>>,
|
||||
}
|
||||
|
||||
impl WorkerGlobalScope {
|
||||
pub fn new_inherited(type_id: WorkerGlobalScopeId) -> 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),
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue