Merge pull request #2839 from Ms2ger/globals

Introduce abstractions for global scopes; r=Manishearth,larsberg
This commit is contained in:
Ms2ger 2014-07-15 22:28:43 +02:00
commit d97ec69957
41 changed files with 296 additions and 183 deletions

View file

@ -4,6 +4,7 @@
use dom::bindings::codegen::Bindings::AttrBinding; use dom::bindings::codegen::Bindings::AttrBinding;
use dom::bindings::codegen::InheritTypes::NodeCast; use dom::bindings::codegen::InheritTypes::NodeCast;
use dom::bindings::global::Window;
use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::trace::Traceable; use dom::bindings::trace::Traceable;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
@ -94,7 +95,7 @@ impl Attr {
name: DOMString, namespace: Namespace, name: DOMString, namespace: Namespace,
prefix: Option<DOMString>, owner: &JSRef<Element>) -> Temporary<Attr> { prefix: Option<DOMString>, owner: &JSRef<Element>) -> Temporary<Attr> {
let attr = Attr::new_inherited(local_name, value, name, namespace, prefix, owner); let attr = Attr::new_inherited(local_name, value, name, namespace, prefix, owner);
reflect_dom_object(box attr, window, AttrBinding::Wrap) reflect_dom_object(box attr, &Window(*window), AttrBinding::Wrap)
} }
pub fn set_value(&self, set_type: AttrSettingType, value: AttrValue) { pub fn set_value(&self, set_type: AttrSettingType, value: AttrValue) {

View file

@ -4,6 +4,7 @@
use dom::attr::Attr; use dom::attr::Attr;
use dom::bindings::codegen::Bindings::AttrListBinding; use dom::bindings::codegen::Bindings::AttrListBinding;
use dom::bindings::global::Window;
use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::element::Element; use dom::element::Element;
@ -25,7 +26,7 @@ impl AttrList {
pub fn new(window: &JSRef<Window>, elem: &JSRef<Element>) -> Temporary<AttrList> { pub fn new(window: &JSRef<Window>, elem: &JSRef<Element>) -> Temporary<AttrList> {
reflect_dom_object(box AttrList::new_inherited(elem), reflect_dom_object(box AttrList::new_inherited(elem),
window, AttrListBinding::Wrap) &Window(*window), AttrListBinding::Wrap)
} }
} }

View file

@ -114,8 +114,8 @@ pub struct CallSetup {
impl CallSetup { impl CallSetup {
pub fn new<T: CallbackContainer>(callback: &T, handling: ExceptionHandling) -> CallSetup { pub fn new<T: CallbackContainer>(callback: &T, handling: ExceptionHandling) -> CallSetup {
let win = global_object_for_js_object(callback.callback()).root(); let global = global_object_for_js_object(callback.callback()).root();
let cx = win.deref().get_cx(); let cx = global.root_ref().get_cx();
CallSetup { CallSetup {
cx: cx, cx: cx,
_handling: handling _handling: handling

View file

@ -1792,7 +1792,7 @@ class CGWrapMethod(CGAbstractMethod):
def __init__(self, descriptor): def __init__(self, descriptor):
assert descriptor.interface.hasInterfacePrototypeObject() assert descriptor.interface.hasInterfacePrototypeObject()
if not descriptor.createGlobal: if not descriptor.createGlobal:
args = [Argument('*mut JSContext', 'aCx'), Argument('&JSRef<Window>', 'aScope'), args = [Argument('*mut JSContext', 'aCx'), Argument('&GlobalRef', 'aScope'),
Argument("Box<%s>" % descriptor.concreteType, 'aObject', mutable=True)] Argument("Box<%s>" % descriptor.concreteType, 'aObject', mutable=True)]
else: else:
args = [Argument('*mut JSContext', 'aCx'), args = [Argument('*mut JSContext', 'aCx'),
@ -2185,7 +2185,7 @@ class CGCallGenerator(CGThing):
" Ok(result) => result,\n" " Ok(result) => result,\n"
" Err(e) => {\n" " Err(e) => {\n"
"%s" "%s"
" throw_dom_exception(cx, &*global, e);\n" " throw_dom_exception(cx, &global.root_ref(), e);\n"
" return%s;\n" " return%s;\n"
" },\n" " },\n"
"};\n" % (glob, errorResult))) "};\n" % (glob, errorResult)))
@ -4405,6 +4405,7 @@ class CGBindingRoot(CGThing):
'js::rust::with_compartment', 'js::rust::with_compartment',
'dom::types::*', 'dom::types::*',
'dom::bindings', 'dom::bindings',
'dom::bindings::global::GlobalRef',
'dom::bindings::js::{JS, JSRef, Root, RootedReference, Temporary}', 'dom::bindings::js::{JS, JSRef, Root, RootedReference, Temporary}',
'dom::bindings::js::{OptionalRootable, OptionalRootedRootable, ResultRootable}', 'dom::bindings::js::{OptionalRootable, OptionalRootedRootable, ResultRootable}',
'dom::bindings::js::{OptionalRootedReference, OptionalOptionalRootedRootable}', 'dom::bindings::js::{OptionalRootedReference, OptionalOptionalRootedRootable}',

View file

@ -3,9 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::conversions::ToJSValConvertible; use dom::bindings::conversions::ToJSValConvertible;
use dom::bindings::js::JSRef; use dom::bindings::global::GlobalRef;
use dom::domexception::DOMException; use dom::domexception::DOMException;
use dom::window::Window;
use js::jsapi::{JSContext, JSBool}; use js::jsapi::{JSContext, JSBool};
use js::jsapi::{JS_IsExceptionPending, JS_SetPendingException}; use js::jsapi::{JS_IsExceptionPending, JS_SetPendingException};
@ -37,7 +36,7 @@ pub type Fallible<T> = Result<T, Error>;
pub type ErrorResult = Fallible<()>; pub type ErrorResult = Fallible<()>;
pub fn throw_dom_exception(cx: *mut JSContext, global: &JSRef<Window>, pub fn throw_dom_exception(cx: *mut JSContext, global: &GlobalRef,
result: Error) { result: Error) {
assert!(unsafe { JS_IsExceptionPending(cx) } == 0); assert!(unsafe { JS_IsExceptionPending(cx) } == 0);
let exception = DOMException::new_from_error(global, result).root(); let exception = DOMException::new_from_error(global, result).root();

View 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/. */
//! Abstractions for global scopes.
use dom::bindings::js::{JS, JSRef, Root};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::window::Window;
use page::Page;
use script_task::ScriptChan;
use js::jsapi::JSContext;
use url::Url;
pub enum GlobalRef<'a> {
Window(JSRef<'a, Window>),
}
pub enum GlobalRoot<'a, 'b> {
WindowRoot(Root<'a, 'b, Window>),
}
#[deriving(Encodable)]
pub enum GlobalField {
WindowField(JS<Window>),
}
impl<'a> GlobalRef<'a> {
pub fn get_cx(&self) -> *mut JSContext {
match *self {
Window(ref window) => window.get_cx(),
}
}
pub fn as_window<'b>(&'b self) -> &'b JSRef<'b, Window> {
match *self {
Window(ref window) => window,
}
}
pub fn page<'b>(&'b self) -> &'b Page {
self.as_window().page()
}
pub fn get_url(&self) -> Url {
self.as_window().get_url()
}
pub fn script_chan<'b>(&'b self) -> &'b ScriptChan {
&self.as_window().script_chan
}
}
impl<'a> Reflectable for GlobalRef<'a> {
fn reflector<'b>(&'b self) -> &'b Reflector {
match *self {
Window(ref window) => window.reflector(),
}
}
}
impl<'a, 'b> GlobalRoot<'a, 'b> {
pub fn root_ref<'c>(&'c self) -> GlobalRef<'c> {
match *self {
WindowRoot(ref window) => Window(window.root_ref()),
}
}
}
impl GlobalField {
pub fn from_rooted(global: &GlobalRef) -> GlobalField {
match *global {
Window(ref window) => WindowField(JS::from_rooted(window)),
}
}
pub fn root(&self) -> GlobalRoot {
match *self {
WindowField(ref window) => WindowRoot(window.root()),
}
}
}

View file

@ -5,7 +5,8 @@
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::js::{JS, JSRef, Temporary, Root}; use dom::bindings::global::{GlobalRef, GlobalField, WindowField};
use dom::bindings::js::{JS, Temporary, Root};
use dom::bindings::trace::Untraceable; use dom::bindings::trace::Untraceable;
use dom::browsercontext; use dom::browsercontext;
use dom::window; use dom::window;
@ -373,10 +374,10 @@ pub trait Reflectable {
pub fn reflect_dom_object<T: Reflectable> pub fn reflect_dom_object<T: Reflectable>
(obj: Box<T>, (obj: Box<T>,
window: &JSRef<window::Window>, global: &GlobalRef,
wrap_fn: extern "Rust" fn(*mut JSContext, &JSRef<window::Window>, Box<T>) -> Temporary<T>) wrap_fn: extern "Rust" fn(*mut JSContext, &GlobalRef, Box<T>) -> Temporary<T>)
-> Temporary<T> { -> Temporary<T> {
wrap_fn(window.get_cx(), window, obj) wrap_fn(global.get_cx(), global, obj)
} }
#[allow(raw_pointer_deriving)] #[allow(raw_pointer_deriving)]
@ -580,23 +581,23 @@ pub extern fn outerize_global(_cx: *mut JSContext, obj: JSHandleObject) -> *mut
} }
/// Returns the global object of the realm that the given JS object was created in. /// Returns the global object of the realm that the given JS object was created in.
pub fn global_object_for_js_object(obj: *mut JSObject) -> JS<window::Window> { pub fn global_object_for_js_object(obj: *mut JSObject) -> GlobalField {
unsafe { unsafe {
let global = GetGlobalForObjectCrossCompartment(obj); let global = GetGlobalForObjectCrossCompartment(obj);
let clasp = JS_GetClass(global); let clasp = JS_GetClass(global);
assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0); assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0);
FromJSValConvertible::from_jsval(ptr::mut_null(), ObjectOrNullValue(global), ()) match FromJSValConvertible::from_jsval(ptr::mut_null(), ObjectOrNullValue(global), ()) {
.ok().expect("found DOM global that doesn't unwrap to Window") Ok(window) => return WindowField(window),
Err(_) => (),
}
fail!("found DOM global that doesn't unwrap to Window")
} }
} }
fn cx_for_dom_reflector(obj: *mut JSObject) -> *mut JSContext { fn cx_for_dom_reflector(obj: *mut JSObject) -> *mut JSContext {
let win = global_object_for_js_object(obj).root(); let global = global_object_for_js_object(obj).root();
let js_info = win.deref().page().js_info(); global.root_ref().get_cx()
match *js_info {
Some(ref info) => info.js_context.deref().deref().ptr,
None => fail!("no JS context for DOM global")
}
} }
pub fn cx_for_dom_object<T: Reflectable>(obj: &T) -> *mut JSContext { pub fn cx_for_dom_object<T: Reflectable>(obj: &T) -> *mut JSContext {

View file

@ -3,11 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::InheritTypes::FileDerived; use dom::bindings::codegen::InheritTypes::FileDerived;
use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::global::{GlobalRef, GlobalField};
use dom::bindings::js::Temporary;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::codegen::Bindings::BlobBinding; use dom::bindings::codegen::Bindings::BlobBinding;
use dom::window::Window;
#[deriving(Encodable)] #[deriving(Encodable)]
pub enum BlobType { pub enum BlobType {
@ -18,27 +18,27 @@ pub enum BlobType {
#[deriving(Encodable)] #[deriving(Encodable)]
pub struct Blob { pub struct Blob {
reflector_: Reflector, reflector_: Reflector,
window: JS<Window>, global: GlobalField,
type_: BlobType type_: BlobType
} }
impl Blob { impl Blob {
pub fn new_inherited(window: &JSRef<Window>) -> Blob { pub fn new_inherited(global: &GlobalRef) -> Blob {
Blob { Blob {
reflector_: Reflector::new(), reflector_: Reflector::new(),
window: JS::from_rooted(window), global: GlobalField::from_rooted(global),
type_: BlobTypeId type_: BlobTypeId
} }
} }
pub fn new(window: &JSRef<Window>) -> Temporary<Blob> { pub fn new(global: &GlobalRef) -> Temporary<Blob> {
reflect_dom_object(box Blob::new_inherited(window), reflect_dom_object(box Blob::new_inherited(global),
window, global,
BlobBinding::Wrap) BlobBinding::Wrap)
} }
pub fn Constructor(window: &JSRef<Window>) -> Fallible<Temporary<Blob>> { pub fn Constructor(global: &GlobalRef) -> Fallible<Temporary<Blob>> {
Ok(Blob::new(window)) Ok(Blob::new(global))
} }
} }

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::ClientRectBinding; use dom::bindings::codegen::Bindings::ClientRectBinding;
use dom::bindings::global::Window;
use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::window::Window; use dom::window::Window;
@ -36,7 +37,7 @@ impl ClientRect {
top: Au, bottom: Au, top: Au, bottom: Au,
left: Au, right: Au) -> Temporary<ClientRect> { left: Au, right: Au) -> Temporary<ClientRect> {
let rect = ClientRect::new_inherited(window, top, bottom, left, right); let rect = ClientRect::new_inherited(window, top, bottom, left, right);
reflect_dom_object(box rect, window, ClientRectBinding::Wrap) reflect_dom_object(box rect, &Window(*window), ClientRectBinding::Wrap)
} }
} }

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::ClientRectListBinding; use dom::bindings::codegen::Bindings::ClientRectListBinding;
use dom::bindings::global::Window;
use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::clientrect::ClientRect; use dom::clientrect::ClientRect;
@ -29,7 +30,7 @@ impl ClientRectList {
pub fn new(window: &JSRef<Window>, pub fn new(window: &JSRef<Window>,
rects: Vec<JSRef<ClientRect>>) -> Temporary<ClientRectList> { rects: Vec<JSRef<ClientRect>>) -> Temporary<ClientRectList> {
reflect_dom_object(box ClientRectList::new_inherited(window, rects), reflect_dom_object(box ClientRectList::new_inherited(window, rects),
window, ClientRectListBinding::Wrap) &Window(*window), ClientRectListBinding::Wrap)
} }
} }

View file

@ -4,14 +4,15 @@
use dom::bindings::codegen::InheritTypes::CommentDerived; use dom::bindings::codegen::InheritTypes::CommentDerived;
use dom::bindings::codegen::Bindings::CommentBinding; use dom::bindings::codegen::Bindings::CommentBinding;
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector}; use dom::bindings::utils::{Reflectable, Reflector};
use dom::characterdata::CharacterData; use dom::characterdata::CharacterData;
use dom::document::Document; use dom::document::Document;
use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::node::{CommentNodeTypeId, Node}; use dom::node::{CommentNodeTypeId, Node};
use dom::window::{Window, WindowMethods}; use dom::window::WindowMethods;
use servo_util::str::DOMString; use servo_util::str::DOMString;
/// An HTML comment. /// An HTML comment.
@ -38,8 +39,8 @@ impl Comment {
Node::reflect_node(box node, document, CommentBinding::Wrap) Node::reflect_node(box node, document, CommentBinding::Wrap)
} }
pub fn Constructor(owner: &JSRef<Window>, data: DOMString) -> Fallible<Temporary<Comment>> { pub fn Constructor(global: &GlobalRef, data: DOMString) -> Fallible<Temporary<Comment>> {
let document = owner.Document().root(); let document = global.as_window().Document().root();
Ok(Comment::new(data, &*document)) Ok(Comment::new(data, &*document))
} }
} }

View file

@ -3,9 +3,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::ConsoleBinding; use dom::bindings::codegen::Bindings::ConsoleBinding;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::window::Window;
use servo_util::str::DOMString; use servo_util::str::DOMString;
#[deriving(Encodable)] #[deriving(Encodable)]
@ -20,8 +20,8 @@ impl Console {
} }
} }
pub fn new(window: &JSRef<Window>) -> Temporary<Console> { pub fn new(global: &GlobalRef) -> Temporary<Console> {
reflect_dom_object(box Console::new_inherited(), window, ConsoleBinding::Wrap) reflect_dom_object(box Console::new_inherited(), global, ConsoleBinding::Wrap)
} }
} }

View file

@ -4,12 +4,12 @@
use dom::bindings::codegen::Bindings::CustomEventBinding; use dom::bindings::codegen::Bindings::CustomEventBinding;
use dom::bindings::codegen::InheritTypes::{EventCast, CustomEventDerived}; use dom::bindings::codegen::InheritTypes::{EventCast, CustomEventDerived};
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::trace::Traceable; use dom::bindings::trace::Traceable;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::event::{Event, EventMethods, EventTypeId, CustomEventTypeId}; use dom::event::{Event, EventMethods, EventTypeId, CustomEventTypeId};
use dom::window::Window;
use js::jsapi::JSContext; use js::jsapi::JSContext;
use js::jsval::{JSVal, NullValue}; use js::jsval::{JSVal, NullValue};
use servo_util::str::DOMString; use servo_util::str::DOMString;
@ -43,20 +43,20 @@ impl CustomEvent {
} }
} }
pub fn new_uninitialized(window: &JSRef<Window>) -> Temporary<CustomEvent> { pub fn new_uninitialized(global: &GlobalRef) -> Temporary<CustomEvent> {
reflect_dom_object(box CustomEvent::new_inherited(CustomEventTypeId), reflect_dom_object(box CustomEvent::new_inherited(CustomEventTypeId),
window, global,
CustomEventBinding::Wrap) CustomEventBinding::Wrap)
} }
pub fn new(window: &JSRef<Window>, type_: DOMString, bubbles: bool, cancelable: bool, detail: JSVal) -> Temporary<CustomEvent> { pub fn new(global: &GlobalRef, type_: DOMString, bubbles: bool, cancelable: bool, detail: JSVal) -> Temporary<CustomEvent> {
let ev = CustomEvent::new_uninitialized(window).root(); let ev = CustomEvent::new_uninitialized(global).root();
ev.deref().InitCustomEvent(window.deref().get_cx(), type_, bubbles, cancelable, detail); ev.deref().InitCustomEvent(global.get_cx(), type_, bubbles, cancelable, detail);
Temporary::from_rooted(&*ev) Temporary::from_rooted(&*ev)
} }
pub fn Constructor(owner: &JSRef<Window>, pub fn Constructor(global: &GlobalRef,
type_: DOMString, type_: DOMString,
init: &CustomEventBinding::CustomEventInit) -> Fallible<Temporary<CustomEvent>>{ init: &CustomEventBinding::CustomEventInit) -> Fallible<Temporary<CustomEvent>>{
Ok(CustomEvent::new(owner, type_, init.parent.bubbles, init.parent.cancelable, init.detail)) Ok(CustomEvent::new(global, type_, init.parent.bubbles, init.parent.cancelable, init.detail))
} }
} }

View file

@ -2,18 +2,19 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::DocumentBinding;
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
use dom::bindings::codegen::InheritTypes::{DocumentDerived, EventCast, HTMLElementCast}; use dom::bindings::codegen::InheritTypes::{DocumentDerived, EventCast, HTMLElementCast};
use dom::bindings::codegen::InheritTypes::{HTMLHeadElementCast, TextCast, ElementCast}; use dom::bindings::codegen::InheritTypes::{HTMLHeadElementCast, TextCast, ElementCast};
use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, HTMLHtmlElementCast, NodeCast}; use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, HTMLHtmlElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::EventTargetCast; use dom::bindings::codegen::InheritTypes::EventTargetCast;
use dom::bindings::codegen::Bindings::DocumentBinding; use dom::bindings::error::{ErrorResult, Fallible, NotSupported, InvalidCharacter};
use dom::bindings::error::{HierarchyRequest, NamespaceError};
use dom::bindings::global::{GlobalRef, Window};
use dom::bindings::js::{JS, JSRef, Temporary, OptionalSettable, TemporaryPushable}; use dom::bindings::js::{JS, JSRef, Temporary, OptionalSettable, TemporaryPushable};
use dom::bindings::js::OptionalRootable; use dom::bindings::js::OptionalRootable;
use dom::bindings::trace::{Traceable, Untraceable}; use dom::bindings::trace::{Traceable, Untraceable};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::error::{ErrorResult, Fallible, NotSupported, InvalidCharacter};
use dom::bindings::error::{HierarchyRequest, NamespaceError};
use dom::bindings::utils::{xml_name_type, InvalidXMLName, Name, QName}; use dom::bindings::utils::{xml_name_type, InvalidXMLName, Name, QName};
use dom::comment::Comment; use dom::comment::Comment;
use dom::customevent::CustomEvent; use dom::customevent::CustomEvent;
@ -222,13 +223,13 @@ impl Document {
} }
// http://dom.spec.whatwg.org/#dom-document // http://dom.spec.whatwg.org/#dom-document
pub fn Constructor(owner: &JSRef<Window>) -> Fallible<Temporary<Document>> { pub fn Constructor(global: &GlobalRef) -> Fallible<Temporary<Document>> {
Ok(Document::new(owner, None, NonHTMLDocument, None)) Ok(Document::new(global.as_window(), None, NonHTMLDocument, None))
} }
pub fn new(window: &JSRef<Window>, url: Option<Url>, doctype: IsHTMLDocument, content_type: Option<DOMString>) -> Temporary<Document> { pub fn new(window: &JSRef<Window>, url: Option<Url>, doctype: IsHTMLDocument, content_type: Option<DOMString>) -> Temporary<Document> {
let document = Document::new_inherited(window, url, doctype, content_type); let document = Document::new_inherited(window, url, doctype, content_type);
let document = reflect_dom_object(box document, window, let document = reflect_dom_object(box document, &Window(*window),
DocumentBinding::Wrap).root(); DocumentBinding::Wrap).root();
let node: &JSRef<Node> = NodeCast::from_ref(&*document); let node: &JSRef<Node> = NodeCast::from_ref(&*document);
@ -540,8 +541,8 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
// FIXME: Implement CustomEvent (http://dom.spec.whatwg.org/#customevent) // FIXME: Implement CustomEvent (http://dom.spec.whatwg.org/#customevent)
"uievents" | "uievent" => Ok(EventCast::from_temporary(UIEvent::new_uninitialized(&*window))), "uievents" | "uievent" => Ok(EventCast::from_temporary(UIEvent::new_uninitialized(&*window))),
"mouseevents" | "mouseevent" => Ok(EventCast::from_temporary(MouseEvent::new_uninitialized(&*window))), "mouseevents" | "mouseevent" => Ok(EventCast::from_temporary(MouseEvent::new_uninitialized(&*window))),
"customevent" => Ok(EventCast::from_temporary(CustomEvent::new_uninitialized(&*window))), "customevent" => Ok(EventCast::from_temporary(CustomEvent::new_uninitialized(&Window(*window)))),
"htmlevents" | "events" | "event" => Ok(Event::new_uninitialized(&*window)), "htmlevents" | "events" | "event" => Ok(Event::new_uninitialized(&Window(*window))),
_ => Err(NotSupported) _ => Err(NotSupported)
} }
} }

View file

@ -6,6 +6,7 @@ use dom::bindings::codegen::InheritTypes::{DocumentFragmentDerived, NodeCast};
use dom::bindings::codegen::Bindings::DocumentFragmentBinding; use dom::bindings::codegen::Bindings::DocumentFragmentBinding;
use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef;
use dom::bindings::utils::{Reflectable, Reflector}; use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::Document; use dom::document::Document;
use dom::element::Element; use dom::element::Element;
@ -13,7 +14,7 @@ use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlcollection::HTMLCollection; use dom::htmlcollection::HTMLCollection;
use dom::node::{DocumentFragmentNodeTypeId, Node, NodeHelpers, window_from_node}; use dom::node::{DocumentFragmentNodeTypeId, Node, NodeHelpers, window_from_node};
use dom::nodelist::NodeList; use dom::nodelist::NodeList;
use dom::window::{Window, WindowMethods}; use dom::window::WindowMethods;
use servo_util::str::DOMString; use servo_util::str::DOMString;
#[deriving(Encodable)] #[deriving(Encodable)]
@ -40,8 +41,8 @@ impl DocumentFragment {
Node::reflect_node(box node, document, DocumentFragmentBinding::Wrap) Node::reflect_node(box node, document, DocumentFragmentBinding::Wrap)
} }
pub fn Constructor(owner: &JSRef<Window>) -> Fallible<Temporary<DocumentFragment>> { pub fn Constructor(global: &GlobalRef) -> Fallible<Temporary<DocumentFragment>> {
let document = owner.Document(); let document = global.as_window().Document();
let document = document.root(); let document = document.root();
Ok(DocumentFragment::new(&document.root_ref())) Ok(DocumentFragment::new(&document.root_ref()))

View file

@ -6,9 +6,9 @@ use dom::bindings::codegen::Bindings::DOMExceptionBinding;
use dom::bindings::codegen::Bindings::DOMExceptionBinding::DOMExceptionConstants; use dom::bindings::codegen::Bindings::DOMExceptionBinding::DOMExceptionConstants;
use dom::bindings::error; use dom::bindings::error;
use dom::bindings::error::Error; use dom::bindings::error::Error;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::window::Window;
use servo_util::str::DOMString; use servo_util::str::DOMString;
#[repr(uint)] #[repr(uint)]
@ -72,12 +72,12 @@ impl DOMException {
} }
} }
pub fn new(window: &JSRef<Window>, code: DOMErrorName) -> Temporary<DOMException> { pub fn new(global: &GlobalRef, code: DOMErrorName) -> Temporary<DOMException> {
reflect_dom_object(box DOMException::new_inherited(code), window, DOMExceptionBinding::Wrap) reflect_dom_object(box DOMException::new_inherited(code), global, DOMExceptionBinding::Wrap)
} }
pub fn new_from_error(window: &JSRef<Window>, code: Error) -> Temporary<DOMException> { pub fn new_from_error(global: &GlobalRef, code: Error) -> Temporary<DOMException> {
DOMException::new(window, DOMErrorName::from_error(code)) DOMException::new(global, DOMErrorName::from_error(code))
} }
} }

View file

@ -4,9 +4,10 @@
use dom::bindings::codegen::Bindings::DOMImplementationBinding; use dom::bindings::codegen::Bindings::DOMImplementationBinding;
use dom::bindings::codegen::InheritTypes::NodeCast; use dom::bindings::codegen::InheritTypes::NodeCast;
use dom::bindings::error::{Fallible, InvalidCharacter, NamespaceError};
use dom::bindings::global::Window;
use dom::bindings::js::{JS, JSRef, Root, Temporary, OptionalRootable}; use dom::bindings::js::{JS, JSRef, Root, Temporary, OptionalRootable};
use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object}; use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object};
use dom::bindings::error::{Fallible, InvalidCharacter, NamespaceError};
use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type}; use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type};
use dom::document::{Document, HTMLDocument, NonHTMLDocument, DocumentMethods}; use dom::document::{Document, HTMLDocument, NonHTMLDocument, DocumentMethods};
use dom::documenttype::DocumentType; use dom::documenttype::DocumentType;
@ -35,7 +36,7 @@ impl DOMImplementation {
pub fn new(document: &JSRef<Document>) -> Temporary<DOMImplementation> { pub fn new(document: &JSRef<Document>) -> Temporary<DOMImplementation> {
let window = document.window.root(); let window = document.window.root();
reflect_dom_object(box DOMImplementation::new_inherited(document), reflect_dom_object(box DOMImplementation::new_inherited(document),
&*window, &Window(*window),
DOMImplementationBinding::Wrap) DOMImplementationBinding::Wrap)
} }
} }

View file

@ -4,34 +4,35 @@
use dom::bindings::codegen::Bindings::DOMParserBinding; use dom::bindings::codegen::Bindings::DOMParserBinding;
use dom::bindings::codegen::Bindings::DOMParserBinding::SupportedTypeValues::{Text_html, Text_xml}; use dom::bindings::codegen::Bindings::DOMParserBinding::SupportedTypeValues::{Text_html, Text_xml};
use dom::bindings::error::{Fallible, FailureUnknown};
use dom::bindings::global::{GlobalRef, Window};
use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object}; use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object};
use dom::bindings::error::{Fallible, FailureUnknown};
use dom::document::{Document, HTMLDocument, NonHTMLDocument}; use dom::document::{Document, HTMLDocument, NonHTMLDocument};
use dom::window::Window; use dom::window::Window;
use servo_util::str::DOMString; use servo_util::str::DOMString;
#[deriving(Encodable)] #[deriving(Encodable)]
pub struct DOMParser { pub struct DOMParser {
pub owner: JS<Window>, //XXXjdm Document instead? window: JS<Window>, //XXXjdm Document instead?
pub reflector_: Reflector reflector_: Reflector
} }
impl DOMParser { impl DOMParser {
pub fn new_inherited(owner: &JSRef<Window>) -> DOMParser { pub fn new_inherited(window: &JSRef<Window>) -> DOMParser {
DOMParser { DOMParser {
owner: JS::from_rooted(owner), window: JS::from_rooted(window),
reflector_: Reflector::new() reflector_: Reflector::new()
} }
} }
pub fn new(owner: &JSRef<Window>) -> Temporary<DOMParser> { pub fn new(window: &JSRef<Window>) -> Temporary<DOMParser> {
reflect_dom_object(box DOMParser::new_inherited(owner), owner, reflect_dom_object(box DOMParser::new_inherited(window), &Window(*window),
DOMParserBinding::Wrap) DOMParserBinding::Wrap)
} }
pub fn Constructor(owner: &JSRef<Window>) -> Fallible<Temporary<DOMParser>> { pub fn Constructor(global: &GlobalRef) -> Fallible<Temporary<DOMParser>> {
Ok(DOMParser::new(owner)) Ok(DOMParser::new(global.as_window()))
} }
} }
@ -45,13 +46,13 @@ impl<'a> DOMParserMethods for JSRef<'a, DOMParser> {
_s: DOMString, _s: DOMString,
ty: DOMParserBinding::SupportedType) ty: DOMParserBinding::SupportedType)
-> Fallible<Temporary<Document>> { -> Fallible<Temporary<Document>> {
let owner = self.owner.root(); let window = self.window.root();
match ty { match ty {
Text_html => { Text_html => {
Ok(Document::new(&owner.root_ref(), None, HTMLDocument, Some("text/html".to_string()))) Ok(Document::new(&window.root_ref(), None, HTMLDocument, Some("text/html".to_string())))
} }
Text_xml => { Text_xml => {
Ok(Document::new(&owner.root_ref(), None, NonHTMLDocument, Some("text/xml".to_string()))) Ok(Document::new(&window.root_ref(), None, NonHTMLDocument, Some("text/xml".to_string())))
} }
_ => { _ => {
Err(FailureUnknown) Err(FailureUnknown)

View file

@ -4,6 +4,7 @@
use dom::attr::{Attr, TokenListAttrValue}; use dom::attr::{Attr, TokenListAttrValue};
use dom::bindings::codegen::Bindings::DOMTokenListBinding; use dom::bindings::codegen::Bindings::DOMTokenListBinding;
use dom::bindings::global::Window;
use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootable}; use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootable};
use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object}; use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object};
use dom::element::{Element, AttributeHandlers}; use dom::element::{Element, AttributeHandlers};
@ -33,7 +34,7 @@ impl DOMTokenList {
local_name: &'static str) -> Temporary<DOMTokenList> { local_name: &'static str) -> Temporary<DOMTokenList> {
let window = window_from_node(element).root(); let window = window_from_node(element).root();
reflect_dom_object(box DOMTokenList::new_inherited(element, local_name), reflect_dom_object(box DOMTokenList::new_inherited(element, local_name),
&*window, DOMTokenListBinding::Wrap) &Window(*window), DOMTokenListBinding::Wrap)
} }
} }

View file

@ -5,11 +5,11 @@
use dom::bindings::codegen::Bindings::EventBinding; use dom::bindings::codegen::Bindings::EventBinding;
use dom::bindings::codegen::Bindings::EventBinding::EventConstants; use dom::bindings::codegen::Bindings::EventBinding::EventConstants;
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::trace::Traceable; use dom::bindings::trace::Traceable;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::eventtarget::EventTarget; use dom::eventtarget::EventTarget;
use dom::window::Window;
use servo_msg::constellation_msg::WindowSizeData; use servo_msg::constellation_msg::WindowSizeData;
use servo_util::str::DOMString; use servo_util::str::DOMString;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
@ -85,22 +85,22 @@ impl Event {
} }
} }
pub fn new_uninitialized(window: &JSRef<Window>) -> Temporary<Event> { pub fn new_uninitialized(global: &GlobalRef) -> Temporary<Event> {
reflect_dom_object(box Event::new_inherited(HTMLEventTypeId), reflect_dom_object(box Event::new_inherited(HTMLEventTypeId),
window, global,
EventBinding::Wrap) EventBinding::Wrap)
} }
pub fn new(window: &JSRef<Window>, pub fn new(global: &GlobalRef,
type_: DOMString, type_: DOMString,
can_bubble: bool, can_bubble: bool,
cancelable: bool) -> Temporary<Event> { cancelable: bool) -> Temporary<Event> {
let event = Event::new_uninitialized(window).root(); let event = Event::new_uninitialized(global).root();
event.deref().InitEvent(type_, can_bubble, cancelable); event.deref().InitEvent(type_, can_bubble, cancelable);
Temporary::from_rooted(&*event) Temporary::from_rooted(&*event)
} }
pub fn Constructor(global: &JSRef<Window>, pub fn Constructor(global: &GlobalRef,
type_: DOMString, type_: DOMString,
init: &EventBinding::EventInit) -> Fallible<Temporary<Event>> { init: &EventBinding::EventInit) -> Fallible<Temporary<Event>> {
Ok(Event::new(global, type_, init.bubbles, init.cancelable)) Ok(Event::new(global, type_, init.bubbles, init.cancelable))

View file

@ -2,11 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::FileBinding;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::codegen::Bindings::FileBinding;
use dom::blob::{Blob, BlobType, FileTypeId}; use dom::blob::{Blob, BlobType, FileTypeId};
use dom::window::Window;
use servo_util::str::DOMString; use servo_util::str::DOMString;
#[deriving(Encodable)] #[deriving(Encodable)]
@ -17,9 +17,9 @@ pub struct File {
} }
impl File { impl File {
pub fn new_inherited(window: &JSRef<Window>, _file_bits: &JSRef<Blob>, name: DOMString) -> File { pub fn new_inherited(global: &GlobalRef, _file_bits: &JSRef<Blob>, name: DOMString) -> File {
File { File {
blob: Blob::new_inherited(window), blob: Blob::new_inherited(global),
name: name, name: name,
type_: FileTypeId type_: FileTypeId
} }
@ -27,9 +27,9 @@ impl File {
// the relevant subfields of file_bits should be copied over // the relevant subfields of file_bits should be copied over
} }
pub fn new(window: &JSRef<Window>, file_bits: &JSRef<Blob>, name: DOMString) -> Temporary<File> { pub fn new(global: &GlobalRef, file_bits: &JSRef<Blob>, name: DOMString) -> Temporary<File> {
reflect_dom_object(box File::new_inherited(window, file_bits, name), reflect_dom_object(box File::new_inherited(global, file_bits, name),
window, global,
FileBinding::Wrap) FileBinding::Wrap)
} }
} }

View file

@ -6,13 +6,13 @@ use dom::bindings::codegen::Bindings::FormDataBinding;
use dom::bindings::codegen::InheritTypes::FileCast; use dom::bindings::codegen::InheritTypes::FileCast;
use dom::bindings::codegen::UnionTypes::FileOrString::{FileOrString, eFile, eString}; use dom::bindings::codegen::UnionTypes::FileOrString::{FileOrString, eFile, eString};
use dom::bindings::error::{Fallible}; use dom::bindings::error::{Fallible};
use dom::bindings::global::{GlobalRef, GlobalField};
use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::trace::Traceable; use dom::bindings::trace::Traceable;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::blob::Blob; use dom::blob::Blob;
use dom::file::File; use dom::file::File;
use dom::htmlformelement::HTMLFormElement; use dom::htmlformelement::HTMLFormElement;
use dom::window::Window;
use servo_util::str::DOMString; use servo_util::str::DOMString;
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::hashmap::HashMap; use std::collections::hashmap::HashMap;
@ -27,26 +27,27 @@ pub enum FormDatum {
pub struct FormData { pub struct FormData {
data: Traceable<RefCell<HashMap<DOMString, Vec<FormDatum>>>>, data: Traceable<RefCell<HashMap<DOMString, Vec<FormDatum>>>>,
reflector_: Reflector, reflector_: Reflector,
window: JS<Window>, global: GlobalField,
form: Option<JS<HTMLFormElement>> form: Option<JS<HTMLFormElement>>
} }
impl FormData { impl FormData {
pub fn new_inherited(form: Option<JSRef<HTMLFormElement>>, window: &JSRef<Window>) -> FormData { pub fn new_inherited(form: Option<JSRef<HTMLFormElement>>, global: &GlobalRef) -> FormData {
FormData { FormData {
data: Traceable::new(RefCell::new(HashMap::new())), data: Traceable::new(RefCell::new(HashMap::new())),
reflector_: Reflector::new(), reflector_: Reflector::new(),
window: JS::from_rooted(window), global: GlobalField::from_rooted(global),
form: form.map(|f| JS::from_rooted(&f)), form: form.map(|f| JS::from_rooted(&f)),
} }
} }
pub fn new(form: Option<JSRef<HTMLFormElement>>, window: &JSRef<Window>) -> Temporary<FormData> { pub fn new(form: Option<JSRef<HTMLFormElement>>, global: &GlobalRef) -> Temporary<FormData> {
reflect_dom_object(box FormData::new_inherited(form, window), window, FormDataBinding::Wrap) reflect_dom_object(box FormData::new_inherited(form, global),
global, FormDataBinding::Wrap)
} }
pub fn Constructor(window: &JSRef<Window>, form: Option<JSRef<HTMLFormElement>>) -> Fallible<Temporary<FormData>> { pub fn Constructor(global: &GlobalRef, form: Option<JSRef<HTMLFormElement>>) -> Fallible<Temporary<FormData>> {
Ok(FormData::new(form, window)) Ok(FormData::new(form, global))
} }
} }
@ -115,9 +116,9 @@ trait PrivateFormDataHelpers{
impl PrivateFormDataHelpers for FormData { impl PrivateFormDataHelpers for FormData {
fn get_file_from_blob(&self, value: &JSRef<Blob>, filename: Option<DOMString>) -> Temporary<File> { fn get_file_from_blob(&self, value: &JSRef<Blob>, filename: Option<DOMString>) -> Temporary<File> {
let global = self.window.root(); let global = self.global.root();
let f: Option<&JSRef<File>> = FileCast::to_ref(value); let f: Option<&JSRef<File>> = FileCast::to_ref(value);
let name = filename.unwrap_or(f.map(|inner| inner.name.clone()).unwrap_or("blob".to_string())); let name = filename.unwrap_or(f.map(|inner| inner.name.clone()).unwrap_or("blob".to_string()));
File::new(&*global, value, name) File::new(&global.root_ref(), value, name)
} }
} }

View file

@ -4,6 +4,7 @@
use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast}; use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast};
use dom::bindings::codegen::Bindings::HTMLCollectionBinding; use dom::bindings::codegen::Bindings::HTMLCollectionBinding;
use dom::bindings::global::Window;
use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::element::{Element, AttributeHandlers}; use dom::element::{Element, AttributeHandlers};
@ -46,7 +47,7 @@ impl HTMLCollection {
pub fn new(window: &JSRef<Window>, collection: CollectionTypeId) -> Temporary<HTMLCollection> { pub fn new(window: &JSRef<Window>, collection: CollectionTypeId) -> Temporary<HTMLCollection> {
reflect_dom_object(box HTMLCollection::new_inherited(collection), reflect_dom_object(box HTMLCollection::new_inherited(collection),
window, HTMLCollectionBinding::Wrap) &Window(*window), HTMLCollectionBinding::Wrap)
} }
} }

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::LocationBinding; use dom::bindings::codegen::Bindings::LocationBinding;
use dom::bindings::global::Window;
use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::window::Window; use dom::window::Window;
@ -30,7 +31,7 @@ impl Location {
pub fn new(window: &JSRef<Window>, page: Rc<Page>) -> Temporary<Location> { pub fn new(window: &JSRef<Window>, page: Rc<Page>) -> Temporary<Location> {
reflect_dom_object(box Location::new_inherited(page), reflect_dom_object(box Location::new_inherited(page),
window, &Window(*window),
LocationBinding::Wrap) LocationBinding::Wrap)
} }
} }

View file

@ -5,6 +5,7 @@
use dom::bindings::codegen::Bindings::MouseEventBinding; use dom::bindings::codegen::Bindings::MouseEventBinding;
use dom::bindings::codegen::InheritTypes::{UIEventCast, MouseEventDerived}; use dom::bindings::codegen::InheritTypes::{UIEventCast, MouseEventDerived};
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::global::{GlobalRef, Window};
use dom::bindings::js::{JS, JSRef, RootedReference, Temporary, OptionalSettable}; use dom::bindings::js::{JS, JSRef, RootedReference, Temporary, OptionalSettable};
use dom::bindings::trace::Traceable; use dom::bindings::trace::Traceable;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
@ -55,7 +56,7 @@ impl MouseEvent {
pub fn new_uninitialized(window: &JSRef<Window>) -> Temporary<MouseEvent> { pub fn new_uninitialized(window: &JSRef<Window>) -> Temporary<MouseEvent> {
reflect_dom_object(box MouseEvent::new_inherited(), reflect_dom_object(box MouseEvent::new_inherited(),
window, &Window(*window),
MouseEventBinding::Wrap) MouseEventBinding::Wrap)
} }
@ -83,10 +84,11 @@ impl MouseEvent {
Temporary::from_rooted(&*ev) Temporary::from_rooted(&*ev)
} }
pub fn Constructor(owner: &JSRef<Window>, pub fn Constructor(global: &GlobalRef,
type_: DOMString, type_: DOMString,
init: &MouseEventBinding::MouseEventInit) -> Fallible<Temporary<MouseEvent>> { init: &MouseEventBinding::MouseEventInit) -> Fallible<Temporary<MouseEvent>> {
let event = MouseEvent::new(owner, type_, init.parent.parent.bubbles, let event = MouseEvent::new(global.as_window(), type_,
init.parent.parent.bubbles,
init.parent.parent.cancelable, init.parent.parent.cancelable,
init.parent.view.root_ref(), init.parent.view.root_ref(),
init.parent.detail, init.parent.detail,

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::NavigatorBinding; use dom::bindings::codegen::Bindings::NavigatorBinding;
use dom::bindings::global::Window;
use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::window::Window; use dom::window::Window;
@ -22,7 +23,7 @@ impl Navigator {
pub fn new(window: &JSRef<Window>) -> Temporary<Navigator> { pub fn new(window: &JSRef<Window>) -> Temporary<Navigator> {
reflect_dom_object(box Navigator::new_inherited(), reflect_dom_object(box Navigator::new_inherited(),
window, &Window(*window),
NavigatorBinding::Wrap) NavigatorBinding::Wrap)
} }
} }

View file

@ -12,6 +12,7 @@ use dom::bindings::codegen::InheritTypes::{CharacterDataCast, NodeBase, NodeDeri
use dom::bindings::codegen::InheritTypes::{ProcessingInstructionCast, EventTargetCast}; use dom::bindings::codegen::InheritTypes::{ProcessingInstructionCast, EventTargetCast};
use dom::bindings::codegen::Bindings::NodeBinding::NodeConstants; use dom::bindings::codegen::Bindings::NodeBinding::NodeConstants;
use dom::bindings::error::{ErrorResult, Fallible, NotFound, HierarchyRequest, Syntax}; use dom::bindings::error::{ErrorResult, Fallible, NotFound, HierarchyRequest, Syntax};
use dom::bindings::global::{GlobalRef, Window};
use dom::bindings::js::{JS, JSRef, RootedReference, Temporary, Root, OptionalUnrootable}; use dom::bindings::js::{JS, JSRef, RootedReference, Temporary, Root, OptionalUnrootable};
use dom::bindings::js::{OptionalSettable, TemporaryPushable, OptionalRootedRootable}; use dom::bindings::js::{OptionalSettable, TemporaryPushable, OptionalRootedRootable};
use dom::bindings::js::{ResultRootable, OptionalRootable}; use dom::bindings::js::{ResultRootable, OptionalRootable};
@ -907,10 +908,10 @@ impl Node {
pub fn reflect_node<N: Reflectable+NodeBase> pub fn reflect_node<N: Reflectable+NodeBase>
(node: Box<N>, (node: Box<N>,
document: &JSRef<Document>, document: &JSRef<Document>,
wrap_fn: extern "Rust" fn(*mut JSContext, &JSRef<Window>, Box<N>) -> Temporary<N>) wrap_fn: extern "Rust" fn(*mut JSContext, &GlobalRef, Box<N>) -> Temporary<N>)
-> Temporary<N> { -> Temporary<N> {
let window = document.window.root(); let window = document.window.root();
reflect_dom_object(node, &*window, wrap_fn) reflect_dom_object(node, &Window(*window), wrap_fn)
} }
pub fn new_inherited(type_id: NodeTypeId, doc: &JSRef<Document>) -> Node { pub fn new_inherited(type_id: NodeTypeId, doc: &JSRef<Document>) -> Node {

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::NodeListBinding; use dom::bindings::codegen::Bindings::NodeListBinding;
use dom::bindings::global::Window;
use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::node::{Node, NodeHelpers}; use dom::node::{Node, NodeHelpers};
@ -31,7 +32,7 @@ impl NodeList {
pub fn new(window: &JSRef<Window>, pub fn new(window: &JSRef<Window>,
list_type: NodeListType) -> Temporary<NodeList> { list_type: NodeListType) -> Temporary<NodeList> {
reflect_dom_object(box NodeList::new_inherited(list_type), reflect_dom_object(box NodeList::new_inherited(list_type),
window, NodeListBinding::Wrap) &Window(*window), NodeListBinding::Wrap)
} }
pub fn new_simple_list(window: &JSRef<Window>, elements: Vec<JSRef<Node>>) -> Temporary<NodeList> { pub fn new_simple_list(window: &JSRef<Window>, elements: Vec<JSRef<Node>>) -> Temporary<NodeList> {

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::PerformanceBinding; use dom::bindings::codegen::Bindings::PerformanceBinding;
use dom::bindings::global::Window;
use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::performancetiming::{PerformanceTiming, PerformanceTimingMethods}; use dom::performancetiming::{PerformanceTiming, PerformanceTimingMethods};
@ -27,7 +28,8 @@ impl Performance {
pub fn new(window: &JSRef<Window>) -> Temporary<Performance> { pub fn new(window: &JSRef<Window>) -> Temporary<Performance> {
let performance = Performance::new_inherited(window); let performance = Performance::new_inherited(window);
reflect_dom_object(box performance, window, PerformanceBinding::Wrap) reflect_dom_object(box performance, &Window(*window),
PerformanceBinding::Wrap)
} }
} }

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::PerformanceTimingBinding; use dom::bindings::codegen::Bindings::PerformanceTimingBinding;
use dom::bindings::global::Window;
use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::window::Window; use dom::window::Window;
@ -27,7 +28,8 @@ impl PerformanceTiming {
pub fn new(window: &JSRef<Window>) -> Temporary<PerformanceTiming> { pub fn new(window: &JSRef<Window>) -> Temporary<PerformanceTiming> {
let timing = PerformanceTiming::new_inherited(window.navigationStart, let timing = PerformanceTiming::new_inherited(window.navigationStart,
window.navigationStartPrecise); window.navigationStartPrecise);
reflect_dom_object(box timing, window, PerformanceTimingBinding::Wrap) reflect_dom_object(box timing, &Window(*window),
PerformanceTimingBinding::Wrap)
} }
} }

View file

@ -5,10 +5,10 @@
use dom::bindings::codegen::Bindings::ProgressEventBinding; use dom::bindings::codegen::Bindings::ProgressEventBinding;
use dom::bindings::codegen::InheritTypes::{EventCast, ProgressEventDerived}; use dom::bindings::codegen::InheritTypes::{EventCast, ProgressEventDerived};
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::event::{Event, EventMethods, ProgressEventTypeId}; use dom::event::{Event, EventMethods, ProgressEventTypeId};
use dom::window::Window;
use servo_util::str::DOMString; use servo_util::str::DOMString;
#[deriving(Encodable)] #[deriving(Encodable)]
@ -34,21 +34,21 @@ impl ProgressEvent {
total: total total: total
} }
} }
pub fn new(window: &JSRef<Window>, type_: DOMString, pub fn new(global: &GlobalRef, type_: DOMString,
can_bubble: bool, cancelable: bool, can_bubble: bool, cancelable: bool,
length_computable: bool, loaded: u64, total: u64) -> Temporary<ProgressEvent> { length_computable: bool, loaded: u64, total: u64) -> Temporary<ProgressEvent> {
let ev = reflect_dom_object(box ProgressEvent::new_inherited(length_computable, loaded, total), let ev = reflect_dom_object(box ProgressEvent::new_inherited(length_computable, loaded, total),
window, global,
ProgressEventBinding::Wrap).root(); ProgressEventBinding::Wrap).root();
let event: &JSRef<Event> = EventCast::from_ref(&*ev); let event: &JSRef<Event> = EventCast::from_ref(&*ev);
event.InitEvent(type_, can_bubble, cancelable); event.InitEvent(type_, can_bubble, cancelable);
Temporary::from_rooted(&*ev) Temporary::from_rooted(&*ev)
} }
pub fn Constructor(owner: &JSRef<Window>, pub fn Constructor(global: &GlobalRef,
type_: DOMString, type_: DOMString,
init: &ProgressEventBinding::ProgressEventInit) init: &ProgressEventBinding::ProgressEventInit)
-> Fallible<Temporary<ProgressEvent>> { -> Fallible<Temporary<ProgressEvent>> {
let ev = ProgressEvent::new(owner, type_, init.parent.bubbles, init.parent.cancelable, let ev = ProgressEvent::new(global, type_, init.parent.bubbles, init.parent.cancelable,
init.lengthComputable, init.loaded, init.total); init.lengthComputable, init.loaded, init.total);
Ok(ev) Ok(ev)
} }

View file

@ -2,27 +2,25 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::codegen::Bindings::TestBindingBinding::TestEnum; use dom::bindings::codegen::Bindings::TestBindingBinding::TestEnum;
use dom::bindings::codegen::Bindings::TestBindingBinding::TestEnumValues::_empty; use dom::bindings::codegen::Bindings::TestBindingBinding::TestEnumValues::_empty;
use dom::bindings::codegen::UnionTypes::BlobOrString::BlobOrString; use dom::bindings::codegen::UnionTypes::BlobOrString::BlobOrString;
use dom::bindings::codegen::UnionTypes::EventOrString::{EventOrString, eString}; use dom::bindings::codegen::UnionTypes::EventOrString::{EventOrString, eString};
use dom::bindings::codegen::UnionTypes::HTMLElementOrLong::{HTMLElementOrLong, eLong}; use dom::bindings::codegen::UnionTypes::HTMLElementOrLong::{HTMLElementOrLong, eLong};
use dom::bindings::global::GlobalField;
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::str::ByteString; use dom::bindings::str::ByteString;
use dom::bindings::utils::{Reflector, Reflectable}; use dom::bindings::utils::{Reflector, Reflectable};
use dom::blob::Blob; use dom::blob::Blob;
use dom::window::Window;
use servo_util::str::DOMString; use servo_util::str::DOMString;
use js::jsapi::JSContext; use js::jsapi::JSContext;
use js::jsval::{JSVal, NullValue}; use js::jsval::{JSVal, NullValue};
use std::cell::Cell;
#[deriving(Encodable)] #[deriving(Encodable)]
pub struct TestBinding { pub struct TestBinding {
pub reflector: Reflector, reflector: Reflector,
pub window: Cell<JS<Window>>, global: GlobalField,
} }
pub trait TestBindingMethods { pub trait TestBindingMethods {
@ -279,20 +277,20 @@ pub trait TestBindingMethods {
impl<'a> TestBindingMethods for JSRef<'a, TestBinding> { impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
fn InterfaceAttribute(&self) -> Temporary<Blob> { fn InterfaceAttribute(&self) -> Temporary<Blob> {
let window = self.window.get().root(); let global = self.global.root();
Blob::new(&*window) Blob::new(&global.root_ref())
} }
fn GetInterfaceAttributeNullable(&self) -> Option<Temporary<Blob>> { fn GetInterfaceAttributeNullable(&self) -> Option<Temporary<Blob>> {
let window = self.window.get().root(); let global = self.global.root();
Some(Blob::new(&*window)) Some(Blob::new(&global.root_ref()))
} }
fn ReceiveInterface(&self) -> Temporary<Blob> { fn ReceiveInterface(&self) -> Temporary<Blob> {
let window = self.window.get().root(); let global = self.global.root();
Blob::new(&*window) Blob::new(&global.root_ref())
} }
fn ReceiveNullableInterface(&self) -> Option<Temporary<Blob>> { fn ReceiveNullableInterface(&self) -> Option<Temporary<Blob>> {
let window = self.window.get().root(); let global = self.global.root();
Some(Blob::new(&*window)) Some(Blob::new(&global.root_ref()))
} }
} }

View file

@ -4,14 +4,15 @@
use dom::bindings::codegen::Bindings::TextBinding; use dom::bindings::codegen::Bindings::TextBinding;
use dom::bindings::codegen::InheritTypes::TextDerived; use dom::bindings::codegen::InheritTypes::TextDerived;
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector}; use dom::bindings::utils::{Reflectable, Reflector};
use dom::characterdata::CharacterData; use dom::characterdata::CharacterData;
use dom::document::Document; use dom::document::Document;
use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::node::{Node, TextNodeTypeId}; use dom::node::{Node, TextNodeTypeId};
use dom::window::{Window, WindowMethods}; use dom::window::WindowMethods;
use servo_util::str::DOMString; use servo_util::str::DOMString;
/// An HTML text node. /// An HTML text node.
@ -38,8 +39,8 @@ impl Text {
Node::reflect_node(box node, document, TextBinding::Wrap) Node::reflect_node(box node, document, TextBinding::Wrap)
} }
pub fn Constructor(owner: &JSRef<Window>, text: DOMString) -> Fallible<Temporary<Text>> { pub fn Constructor(global: &GlobalRef, text: DOMString) -> Fallible<Temporary<Text>> {
let document = owner.Document().root(); let document = global.as_window().Document().root();
Ok(Text::new(text, &*document)) Ok(Text::new(text, &*document))
} }
} }

View file

@ -5,6 +5,7 @@
use dom::bindings::codegen::Bindings::UIEventBinding; use dom::bindings::codegen::Bindings::UIEventBinding;
use dom::bindings::codegen::InheritTypes::{EventCast, UIEventDerived}; use dom::bindings::codegen::InheritTypes::{EventCast, UIEventDerived};
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::global::{GlobalRef, Window};
use dom::bindings::js::{JS, JSRef, RootedReference, Temporary, OptionalSettable}; use dom::bindings::js::{JS, JSRef, RootedReference, Temporary, OptionalSettable};
use dom::bindings::trace::Traceable; use dom::bindings::trace::Traceable;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
@ -39,7 +40,7 @@ impl UIEvent {
pub fn new_uninitialized(window: &JSRef<Window>) -> Temporary<UIEvent> { pub fn new_uninitialized(window: &JSRef<Window>) -> Temporary<UIEvent> {
reflect_dom_object(box UIEvent::new_inherited(UIEventTypeId), reflect_dom_object(box UIEvent::new_inherited(UIEventTypeId),
window, &Window(*window),
UIEventBinding::Wrap) UIEventBinding::Wrap)
} }
@ -54,10 +55,10 @@ impl UIEvent {
Temporary::from_rooted(&*ev) Temporary::from_rooted(&*ev)
} }
pub fn Constructor(owner: &JSRef<Window>, pub fn Constructor(global: &GlobalRef,
type_: DOMString, type_: DOMString,
init: &UIEventBinding::UIEventInit) -> Fallible<Temporary<UIEvent>> { init: &UIEventBinding::UIEventInit) -> Fallible<Temporary<UIEvent>> {
let event = UIEvent::new(owner, type_, let event = UIEvent::new(global.as_window(), type_,
init.parent.bubbles, init.parent.cancelable, init.parent.bubbles, init.parent.cancelable,
init.view.root_ref(), init.detail); init.view.root_ref(), init.detail);
Ok(event) Ok(event)

View file

@ -6,10 +6,10 @@ use std::collections::hashmap::HashMap;
use dom::bindings::codegen::Bindings::URLSearchParamsBinding; use dom::bindings::codegen::Bindings::URLSearchParamsBinding;
use dom::bindings::codegen::UnionTypes::StringOrURLSearchParams::{StringOrURLSearchParams, eURLSearchParams, eString}; use dom::bindings::codegen::UnionTypes::StringOrURLSearchParams::{StringOrURLSearchParams, eURLSearchParams, eString};
use dom::bindings::error::{Fallible}; use dom::bindings::error::{Fallible};
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::trace::Traceable; use dom::bindings::trace::Traceable;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::window::Window;
use encoding::all::UTF_8; use encoding::all::UTF_8;
use encoding::types::{Encoding, EncodeReplace}; use encoding::types::{Encoding, EncodeReplace};
use servo_util::str::DOMString; use servo_util::str::DOMString;
@ -18,9 +18,9 @@ use std::num::ToStrRadix;
use std::ascii::OwnedStrAsciiExt; use std::ascii::OwnedStrAsciiExt;
#[deriving(Encodable)] #[deriving(Encodable)]
pub struct URLSearchParams{ pub struct URLSearchParams {
pub data: Traceable<RefCell<HashMap<DOMString, Vec<DOMString>>>>, data: Traceable<RefCell<HashMap<DOMString, Vec<DOMString>>>>,
pub reflector_: Reflector, reflector_: Reflector,
} }
impl URLSearchParams { impl URLSearchParams {
@ -31,12 +31,12 @@ impl URLSearchParams {
} }
} }
pub fn new(window: &JSRef<Window>) -> Temporary<URLSearchParams> { pub fn new(global: &GlobalRef) -> Temporary<URLSearchParams> {
reflect_dom_object(box URLSearchParams::new_inherited(), window, URLSearchParamsBinding::Wrap) reflect_dom_object(box URLSearchParams::new_inherited(), global, URLSearchParamsBinding::Wrap)
} }
pub fn Constructor(window: &JSRef<Window>, init: Option<StringOrURLSearchParams>) -> Fallible<Temporary<URLSearchParams>> { pub fn Constructor(global: &GlobalRef, init: Option<StringOrURLSearchParams>) -> Fallible<Temporary<URLSearchParams>> {
let usp = URLSearchParams::new(window).root(); let usp = URLSearchParams::new(global).root();
match init { match init {
Some(eString(_s)) => { Some(eString(_s)) => {
// XXXManishearth we need to parse the input here // XXXManishearth we need to parse the input here

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::ValidityStateBinding; use dom::bindings::codegen::Bindings::ValidityStateBinding;
use dom::bindings::global::Window;
use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::window::Window; use dom::window::Window;
@ -23,7 +24,7 @@ impl ValidityState {
pub fn new(window: &JSRef<Window>) -> Temporary<ValidityState> { pub fn new(window: &JSRef<Window>) -> Temporary<ValidityState> {
reflect_dom_object(box ValidityState::new_inherited(), reflect_dom_object(box ValidityState::new_inherited(),
window, &Window(*window),
ValidityStateBinding::Wrap) ValidityStateBinding::Wrap)
} }
} }

View file

@ -5,6 +5,7 @@
use dom::bindings::codegen::Bindings::EventHandlerBinding::{OnErrorEventHandlerNonNull, EventHandlerNonNull}; use dom::bindings::codegen::Bindings::EventHandlerBinding::{OnErrorEventHandlerNonNull, EventHandlerNonNull};
use dom::bindings::codegen::Bindings::WindowBinding; use dom::bindings::codegen::Bindings::WindowBinding;
use dom::bindings::codegen::InheritTypes::EventTargetCast; use dom::bindings::codegen::InheritTypes::EventTargetCast;
use dom::bindings::global;
use dom::bindings::js::{JS, JSRef, Temporary, OptionalSettable}; use dom::bindings::js::{JS, JSRef, Temporary, OptionalSettable};
use dom::bindings::trace::{Traceable, Untraceable}; use dom::bindings::trace::{Traceable, Untraceable};
use dom::bindings::utils::{Reflectable, Reflector}; use dom::bindings::utils::{Reflectable, Reflector};
@ -169,7 +170,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
fn Console(&self) -> Temporary<Console> { fn Console(&self) -> Temporary<Console> {
if self.console.get().is_none() { if self.console.get().is_none() {
let console = Console::new(self); let console = Console::new(&global::Window(*self));
self.console.assign(Some(console)); self.console.assign(Some(console));
} }
Temporary::new(self.console.get().get_ref().clone()) Temporary::new(self.console.get().get_ref().clone())

View file

@ -10,6 +10,7 @@ use dom::bindings::codegen::InheritTypes::{EventCast, EventTargetCast, XMLHttpRe
use dom::bindings::conversions::ToJSValConvertible; use dom::bindings::conversions::ToJSValConvertible;
use dom::bindings::error::{Error, ErrorResult, Fallible, InvalidState, InvalidAccess}; use dom::bindings::error::{Error, ErrorResult, Fallible, InvalidState, InvalidAccess};
use dom::bindings::error::{Network, Syntax, Security, Abort, Timeout}; use dom::bindings::error::{Network, Syntax, Security, Abort, Timeout};
use dom::bindings::global::{GlobalField, GlobalRef};
use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootedRootable}; use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootedRootable};
use dom::bindings::str::ByteString; use dom::bindings::str::ByteString;
use dom::bindings::trace::{Traceable, Untraceable}; use dom::bindings::trace::{Traceable, Untraceable};
@ -19,7 +20,6 @@ use dom::event::Event;
use dom::eventtarget::{EventTarget, EventTargetHelpers, XMLHttpRequestTargetTypeId}; use dom::eventtarget::{EventTarget, EventTargetHelpers, XMLHttpRequestTargetTypeId};
use dom::progressevent::ProgressEvent; use dom::progressevent::ProgressEvent;
use dom::urlsearchparams::URLSearchParamsHelpers; use dom::urlsearchparams::URLSearchParamsHelpers;
use dom::window::Window;
use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTarget; use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTarget;
use dom::xmlhttprequestupload::XMLHttpRequestUpload; use dom::xmlhttprequestupload::XMLHttpRequestUpload;
@ -102,7 +102,7 @@ pub struct XMLHttpRequest {
ready_state: Traceable<Cell<XMLHttpRequestState>>, ready_state: Traceable<Cell<XMLHttpRequestState>>,
timeout: Traceable<Cell<u32>>, timeout: Traceable<Cell<u32>>,
with_credentials: Traceable<Cell<bool>>, with_credentials: Traceable<Cell<bool>>,
upload: Cell<JS<XMLHttpRequestUpload>>, upload: JS<XMLHttpRequestUpload>,
response_url: DOMString, response_url: DOMString,
status: Traceable<Cell<u16>>, status: Traceable<Cell<u16>>,
status_text: Traceable<RefCell<ByteString>>, status_text: Traceable<RefCell<ByteString>>,
@ -121,7 +121,7 @@ pub struct XMLHttpRequest {
upload_events: Traceable<Cell<bool>>, upload_events: Traceable<Cell<bool>>,
send_flag: Traceable<Cell<bool>>, send_flag: Traceable<Cell<bool>>,
global: JS<Window>, global: GlobalField,
pinned_count: Traceable<Cell<uint>>, pinned_count: Traceable<Cell<uint>>,
timer: Untraceable<RefCell<Timer>>, timer: Untraceable<RefCell<Timer>>,
fetch_time: Traceable<Cell<i64>>, fetch_time: Traceable<Cell<i64>>,
@ -130,13 +130,13 @@ pub struct XMLHttpRequest {
} }
impl XMLHttpRequest { impl XMLHttpRequest {
pub fn new_inherited(owner: &JSRef<Window>) -> XMLHttpRequest { pub fn new_inherited(global: &GlobalRef) -> XMLHttpRequest {
let xhr = XMLHttpRequest { let xhr = XMLHttpRequest {
eventtarget: XMLHttpRequestEventTarget::new_inherited(XMLHttpRequestTypeId), eventtarget: XMLHttpRequestEventTarget::new_inherited(XMLHttpRequestTypeId),
ready_state: Traceable::new(Cell::new(Unsent)), ready_state: Traceable::new(Cell::new(Unsent)),
timeout: Traceable::new(Cell::new(0u32)), timeout: Traceable::new(Cell::new(0u32)),
with_credentials: Traceable::new(Cell::new(false)), with_credentials: Traceable::new(Cell::new(false)),
upload: Cell::new(JS::from_rooted(&XMLHttpRequestUpload::new(owner))), upload: JS::from_rooted(&XMLHttpRequestUpload::new(global)),
response_url: "".to_string(), response_url: "".to_string(),
status: Traceable::new(Cell::new(0)), status: Traceable::new(Cell::new(0)),
status_text: Traceable::new(RefCell::new(ByteString::new(vec!()))), status_text: Traceable::new(RefCell::new(ByteString::new(vec!()))),
@ -155,7 +155,7 @@ impl XMLHttpRequest {
upload_complete: Traceable::new(Cell::new(false)), upload_complete: Traceable::new(Cell::new(false)),
upload_events: Traceable::new(Cell::new(false)), upload_events: Traceable::new(Cell::new(false)),
global: JS::from_rooted(owner), global: GlobalField::from_rooted(global),
pinned_count: Traceable::new(Cell::new(0)), pinned_count: Traceable::new(Cell::new(0)),
timer: Untraceable::new(RefCell::new(Timer::new().unwrap())), timer: Untraceable::new(RefCell::new(Timer::new().unwrap())),
fetch_time: Traceable::new(Cell::new(0)), fetch_time: Traceable::new(Cell::new(0)),
@ -164,13 +164,13 @@ impl XMLHttpRequest {
}; };
xhr xhr
} }
pub fn new(window: &JSRef<Window>) -> Temporary<XMLHttpRequest> { pub fn new(global: &GlobalRef) -> Temporary<XMLHttpRequest> {
reflect_dom_object(box XMLHttpRequest::new_inherited(window), reflect_dom_object(box XMLHttpRequest::new_inherited(global),
window, global,
XMLHttpRequestBinding::Wrap) XMLHttpRequestBinding::Wrap)
} }
pub fn Constructor(owner: &JSRef<Window>) -> Fallible<Temporary<XMLHttpRequest>> { pub fn Constructor(global: &GlobalRef) -> Fallible<Temporary<XMLHttpRequest>> {
Ok(XMLHttpRequest::new(owner)) Ok(XMLHttpRequest::new(global))
} }
pub fn handle_xhr_progress(addr: TrustedXHRAddress, progress: XHRProgress) { pub fn handle_xhr_progress(addr: TrustedXHRAddress, progress: XHRProgress) {
@ -293,7 +293,7 @@ impl<'a> XMLHttpRequestMethods<'a> for JSRef<'a, XMLHttpRequest> {
Method::from_str_or_new(s.as_slice()) Method::from_str_or_new(s.as_slice())
}); });
// Step 2 // Step 2
let base: Option<Url> = Some(self.global.root().get_url()); let base: Option<Url> = Some(self.global.root().root_ref().get_url());
match maybe_method { match maybe_method {
// Step 4 // Step 4
Some(Connect) | Some(Trace) => Err(Security), Some(Connect) | Some(Trace) => Err(Security),
@ -434,7 +434,7 @@ impl<'a> XMLHttpRequestMethods<'a> for JSRef<'a, XMLHttpRequest> {
self.with_credentials.deref().set(with_credentials); self.with_credentials.deref().set(with_credentials);
} }
fn Upload(&self) -> Temporary<XMLHttpRequestUpload> { fn Upload(&self) -> Temporary<XMLHttpRequestUpload> {
Temporary::new(self.upload.get()) Temporary::new(self.upload)
} }
fn Send(&self, data: Option<SendParam>) -> ErrorResult { fn Send(&self, data: Option<SendParam>) -> ErrorResult {
if self.ready_state.deref().get() != Opened || self.send_flag.deref().get() { if self.ready_state.deref().get() != Opened || self.send_flag.deref().get() {
@ -466,7 +466,7 @@ impl<'a> XMLHttpRequestMethods<'a> for JSRef<'a, XMLHttpRequest> {
} }
// Step 8 // Step 8
let upload_target = &*self.upload.get().root(); let upload_target = &*self.upload.root();
let event_target: &JSRef<EventTarget> = EventTargetCast::from_ref(upload_target); let event_target: &JSRef<EventTarget> = EventTargetCast::from_ref(upload_target);
if event_target.has_handlers() { if event_target.has_handlers() {
self.upload_events.deref().set(true); self.upload_events.deref().set(true);
@ -486,7 +486,7 @@ impl<'a> XMLHttpRequestMethods<'a> for JSRef<'a, XMLHttpRequest> {
} }
let global = self.global.root(); let global = self.global.root();
let resource_task = global.deref().page().resource_task.deref().clone(); let resource_task = global.root_ref().page().resource_task.deref().clone();
let mut load_data = LoadData::new(self.request_url.deref().borrow().clone()); let mut load_data = LoadData::new(self.request_url.deref().borrow().clone());
load_data.data = extracted; load_data.data = extracted;
@ -516,7 +516,7 @@ impl<'a> XMLHttpRequestMethods<'a> for JSRef<'a, XMLHttpRequest> {
} }
// XXXManishearth this is to be replaced with Origin for CORS (with no path) // XXXManishearth this is to be replaced with Origin for CORS (with no path)
let referer_url = self.global.root().get_url(); let referer_url = self.global.root().root_ref().get_url();
let mut buf = String::new(); let mut buf = String::new();
buf.push_str(referer_url.scheme.as_slice()); buf.push_str(referer_url.scheme.as_slice());
buf.push_str("://".as_slice()); buf.push_str("://".as_slice());
@ -537,7 +537,7 @@ impl<'a> XMLHttpRequestMethods<'a> for JSRef<'a, XMLHttpRequest> {
} else { } else {
let builder = TaskBuilder::new().named("XHRTask"); let builder = TaskBuilder::new().named("XHRTask");
self.fetch_time.deref().set(time::now().to_timespec().sec); self.fetch_time.deref().set(time::now().to_timespec().sec);
let script_chan = global.deref().script_chan.clone(); let script_chan = global.root_ref().script_chan().clone();
builder.spawn(proc() { builder.spawn(proc() {
let _ = XMLHttpRequest::fetch(&mut Async(addr.unwrap(), script_chan), resource_task, load_data, terminate_receiver); let _ = XMLHttpRequest::fetch(&mut Async(addr.unwrap(), script_chan), resource_task, load_data, terminate_receiver);
}); });
@ -692,7 +692,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> {
// Creates a trusted address to the object, and roots it. Always pair this with a release() // Creates a trusted address to the object, and roots it. Always pair this with a release()
unsafe fn to_trusted(&self) -> TrustedXHRAddress { unsafe fn to_trusted(&self) -> TrustedXHRAddress {
if self.pinned_count.deref().get() == 0 { if self.pinned_count.deref().get() == 0 {
JS_AddObjectRoot(self.global.root().get_cx(), self.reflector().rootable()); JS_AddObjectRoot(self.global.root().root_ref().get_cx(), self.reflector().rootable());
} }
let pinned_count = self.pinned_count.deref().get(); let pinned_count = self.pinned_count.deref().get();
self.pinned_count.deref().set(pinned_count + 1); self.pinned_count.deref().set(pinned_count + 1);
@ -711,7 +711,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> {
self.pinned_count.deref().set(pinned_count - 1); self.pinned_count.deref().set(pinned_count - 1);
if self.pinned_count.deref().get() == 0 { if self.pinned_count.deref().get() == 0 {
unsafe { unsafe {
JS_RemoveObjectRoot(self.global.root().get_cx(), self.reflector().rootable()); JS_RemoveObjectRoot(self.global.root().root_ref().get_cx(), self.reflector().rootable());
} }
} }
} }
@ -719,9 +719,10 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> {
fn change_ready_state(&self, rs: XMLHttpRequestState) { fn change_ready_state(&self, rs: XMLHttpRequestState) {
assert!(self.ready_state.deref().get() != rs) assert!(self.ready_state.deref().get() != rs)
self.ready_state.deref().set(rs); self.ready_state.deref().set(rs);
let win = &*self.global.root(); let global = self.global.root();
let event = let event = Event::new(&global.root_ref(),
Event::new(win, "readystatechange".to_string(), false, true).root(); "readystatechange".to_string(),
false, true).root();
let target: &JSRef<EventTarget> = EventTargetCast::from_ref(self); let target: &JSRef<EventTarget> = EventTargetCast::from_ref(self);
target.dispatch_event_with_target(None, &*event).ok(); target.dispatch_event_with_target(None, &*event).ok();
} }
@ -839,9 +840,10 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> {
} }
fn dispatch_progress_event(&self, upload: bool, type_: DOMString, loaded: u64, total: Option<u64>) { fn dispatch_progress_event(&self, upload: bool, type_: DOMString, loaded: u64, total: Option<u64>) {
let win = &*self.global.root(); let global = self.global.root();
let upload_target = &*self.upload.get().root(); let upload_target = &*self.upload.root();
let progressevent = ProgressEvent::new(win, type_, false, false, let progressevent = ProgressEvent::new(&global.root_ref(),
type_, false, false,
total.is_some(), loaded, total.is_some(), loaded,
total.unwrap_or(0)).root(); total.unwrap_or(0)).root();
let target: &JSRef<EventTarget> = if upload { let target: &JSRef<EventTarget> = if upload {
@ -878,7 +880,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> {
} }
self.timeout_pinned.deref().set(true); self.timeout_pinned.deref().set(true);
let global = self.global.root(); let global = self.global.root();
let script_chan = global.deref().script_chan.clone(); let script_chan = global.root_ref().script_chan().clone();
let terminate_sender = (*self.terminate_sender.deref().borrow()).clone(); let terminate_sender = (*self.terminate_sender.deref().borrow()).clone();
spawn_named("XHR:Timer", proc () { spawn_named("XHR:Timer", proc () {
match oneshot.recv_opt() { match oneshot.recv_opt() {

View file

@ -4,10 +4,10 @@
use dom::bindings::codegen::InheritTypes::XMLHttpRequestUploadDerived; use dom::bindings::codegen::InheritTypes::XMLHttpRequestUploadDerived;
use dom::bindings::codegen::Bindings::XMLHttpRequestUploadBinding; use dom::bindings::codegen::Bindings::XMLHttpRequestUploadBinding;
use dom::bindings::js::{Temporary, JSRef}; use dom::bindings::global::GlobalRef;
use dom::bindings::js::Temporary;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::eventtarget::{EventTarget, XMLHttpRequestTargetTypeId}; use dom::eventtarget::{EventTarget, XMLHttpRequestTargetTypeId};
use dom::window::Window;
use dom::xmlhttprequest::{XMLHttpRequestUploadTypeId}; use dom::xmlhttprequest::{XMLHttpRequestUploadTypeId};
use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTarget; use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTarget;
@ -22,9 +22,9 @@ impl XMLHttpRequestUpload {
eventtarget:XMLHttpRequestEventTarget::new_inherited(XMLHttpRequestUploadTypeId) eventtarget:XMLHttpRequestEventTarget::new_inherited(XMLHttpRequestUploadTypeId)
} }
} }
pub fn new(window: &JSRef<Window>) -> Temporary<XMLHttpRequestUpload> { pub fn new(global: &GlobalRef) -> Temporary<XMLHttpRequestUpload> {
reflect_dom_object(box XMLHttpRequestUpload::new_inherited(), reflect_dom_object(box XMLHttpRequestUpload::new_inherited(),
window, global,
XMLHttpRequestUploadBinding::Wrap) XMLHttpRequestUploadBinding::Wrap)
} }
} }

View file

@ -43,6 +43,7 @@ extern crate url;
pub mod dom { pub mod dom {
pub mod bindings { pub mod bindings {
pub mod global;
pub mod js; pub mod js;
pub mod utils; pub mod utils;
pub mod callback; pub mod callback;

View file

@ -6,6 +6,7 @@
//! and layout tasks. //! and layout tasks.
use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, EventCast}; use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, EventCast};
use dom::bindings::global::Window;
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalSettable}; use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalSettable};
use dom::bindings::js::OptionalRootable; use dom::bindings::js::OptionalRootable;
use dom::bindings::utils::Reflectable; use dom::bindings::utils::Reflectable;
@ -621,7 +622,7 @@ impl ScriptTask {
// We have no concept of a document loader right now, so just dispatch the // We have no concept of a document loader right now, so just dispatch the
// "load" event as soon as we've finished executing all scripts parsed during // "load" event as soon as we've finished executing all scripts parsed during
// the initial load. // the initial load.
let event = Event::new(&*window, "load".to_string(), false, false).root(); let event = Event::new(&Window(*window), "load".to_string(), false, false).root();
let doctarget: &JSRef<EventTarget> = EventTargetCast::from_ref(&*document); let doctarget: &JSRef<EventTarget> = EventTargetCast::from_ref(&*document);
let wintarget: &JSRef<EventTarget> = EventTargetCast::from_ref(&*window); let wintarget: &JSRef<EventTarget> = EventTargetCast::from_ref(&*window);
let _ = wintarget.dispatch_event_with_target(Some((*doctarget).clone()), let _ = wintarget.dispatch_event_with_target(Some((*doctarget).clone()),
@ -719,7 +720,7 @@ impl ScriptTask {
Some(ref frame) => { Some(ref frame) => {
let window = frame.window.root(); let window = frame.window.root();
let event = let event =
Event::new(&*window, Event::new(&Window(*window),
"click".to_string(), "click".to_string(),
true, true).root(); true, true).root();
let eventtarget: &JSRef<EventTarget> = EventTargetCast::from_ref(&node); let eventtarget: &JSRef<EventTarget> = EventTargetCast::from_ref(&node);