servo: Merge #2839 - Introduce abstractions for global scopes; r=Manishearth,larsberg (from Ms2ger:globals)

Source-Repo: https://github.com/servo/servo
Source-Revision: d97ec6995773ee79fbde053520bc580e7b33d15d
This commit is contained in:
Ms2ger 2014-07-15 22:28:43 +02:00
Родитель 10322bcfca
Коммит 51c3f1388d
41 изменённых файлов: 296 добавлений и 183 удалений

Просмотреть файл

@ -4,6 +4,7 @@
use dom::bindings::codegen::Bindings::AttrBinding;
use dom::bindings::codegen::InheritTypes::NodeCast;
use dom::bindings::global::Window;
use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::trace::Traceable;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
@ -94,7 +95,7 @@ impl Attr {
name: DOMString, namespace: Namespace,
prefix: Option<DOMString>, owner: &JSRef<Element>) -> Temporary<Attr> {
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) {

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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()),
}
}
}

Просмотреть файл

@ -5,7 +5,8 @@
use dom::bindings::codegen::PrototypeList;
use dom::bindings::codegen::PrototypeList::MAX_PROTO_CHAIN_LENGTH;
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::browsercontext;
use dom::window;
@ -373,10 +374,10 @@ pub trait Reflectable {
pub fn reflect_dom_object<T: Reflectable>
(obj: Box<T>,
window: &JSRef<window::Window>,
wrap_fn: extern "Rust" fn(*mut JSContext, &JSRef<window::Window>, Box<T>) -> Temporary<T>)
global: &GlobalRef,
wrap_fn: extern "Rust" fn(*mut JSContext, &GlobalRef, Box<T>) -> Temporary<T>)
-> Temporary<T> {
wrap_fn(window.get_cx(), window, obj)
wrap_fn(global.get_cx(), global, obj)
}
#[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.
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 {
let global = GetGlobalForObjectCrossCompartment(obj);
let clasp = JS_GetClass(global);
assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0);
FromJSValConvertible::from_jsval(ptr::mut_null(), ObjectOrNullValue(global), ())
.ok().expect("found DOM global that doesn't unwrap to Window")
match FromJSValConvertible::from_jsval(ptr::mut_null(), ObjectOrNullValue(global), ()) {
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 {
let win = global_object_for_js_object(obj).root();
let js_info = win.deref().page().js_info();
match *js_info {
Some(ref info) => info.js_context.deref().deref().ptr,
None => fail!("no JS context for DOM global")
}
let global = global_object_for_js_object(obj).root();
global.root_ref().get_cx()
}
pub fn cx_for_dom_object<T: Reflectable>(obj: &T) -> *mut JSContext {

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -2,18 +2,19 @@
* 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::DocumentBinding;
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
use dom::bindings::codegen::InheritTypes::{DocumentDerived, EventCast, HTMLElementCast};
use dom::bindings::codegen::InheritTypes::{HTMLHeadElementCast, TextCast, ElementCast};
use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, HTMLHtmlElementCast, NodeCast};
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::OptionalRootable;
use dom::bindings::trace::{Traceable, Untraceable};
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::comment::Comment;
use dom::customevent::CustomEvent;
@ -222,13 +223,13 @@ impl Document {
}
// http://dom.spec.whatwg.org/#dom-document
pub fn Constructor(owner: &JSRef<Window>) -> Fallible<Temporary<Document>> {
Ok(Document::new(owner, None, NonHTMLDocument, None))
pub fn Constructor(global: &GlobalRef) -> Fallible<Temporary<Document>> {
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> {
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();
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)
"uievents" | "uievent" => Ok(EventCast::from_temporary(UIEvent::new_uninitialized(&*window))),
"mouseevents" | "mouseevent" => Ok(EventCast::from_temporary(MouseEvent::new_uninitialized(&*window))),
"customevent" => Ok(EventCast::from_temporary(CustomEvent::new_uninitialized(&*window))),
"htmlevents" | "events" | "event" => Ok(Event::new_uninitialized(&*window)),
"customevent" => Ok(EventCast::from_temporary(CustomEvent::new_uninitialized(&Window(*window)))),
"htmlevents" | "events" | "event" => Ok(Event::new_uninitialized(&Window(*window))),
_ => Err(NotSupported)
}
}

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -4,9 +4,10 @@
use dom::bindings::codegen::Bindings::DOMImplementationBinding;
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::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::document::{Document, HTMLDocument, NonHTMLDocument, DocumentMethods};
use dom::documenttype::DocumentType;
@ -35,7 +36,7 @@ impl DOMImplementation {
pub fn new(document: &JSRef<Document>) -> Temporary<DOMImplementation> {
let window = document.window.root();
reflect_dom_object(box DOMImplementation::new_inherited(document),
&*window,
&Window(*window),
DOMImplementationBinding::Wrap)
}
}

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -5,11 +5,11 @@
use dom::bindings::codegen::Bindings::EventBinding;
use dom::bindings::codegen::Bindings::EventBinding::EventConstants;
use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::trace::Traceable;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::eventtarget::EventTarget;
use dom::window::Window;
use servo_msg::constellation_msg::WindowSizeData;
use servo_util::str::DOMString;
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),
window,
global,
EventBinding::Wrap)
}
pub fn new(window: &JSRef<Window>,
pub fn new(global: &GlobalRef,
type_: DOMString,
can_bubble: bool,
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);
Temporary::from_rooted(&*event)
}
pub fn Constructor(global: &JSRef<Window>,
pub fn Constructor(global: &GlobalRef,
type_: DOMString,
init: &EventBinding::EventInit) -> Fallible<Temporary<Event>> {
Ok(Event::new(global, type_, init.bubbles, init.cancelable))

Просмотреть файл

@ -2,11 +2,11 @@
* 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::FileBinding;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::codegen::Bindings::FileBinding;
use dom::blob::{Blob, BlobType, FileTypeId};
use dom::window::Window;
use servo_util::str::DOMString;
#[deriving(Encodable)]
@ -17,9 +17,9 @@ pub struct 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 {
blob: Blob::new_inherited(window),
blob: Blob::new_inherited(global),
name: name,
type_: FileTypeId
}
@ -27,9 +27,9 @@ impl File {
// the relevant subfields of file_bits should be copied over
}
pub fn new(window: &JSRef<Window>, file_bits: &JSRef<Blob>, name: DOMString) -> Temporary<File> {
reflect_dom_object(box File::new_inherited(window, file_bits, name),
window,
pub fn new(global: &GlobalRef, file_bits: &JSRef<Blob>, name: DOMString) -> Temporary<File> {
reflect_dom_object(box File::new_inherited(global, file_bits, name),
global,
FileBinding::Wrap)
}
}

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -12,6 +12,7 @@ use dom::bindings::codegen::InheritTypes::{CharacterDataCast, NodeBase, NodeDeri
use dom::bindings::codegen::InheritTypes::{ProcessingInstructionCast, EventTargetCast};
use dom::bindings::codegen::Bindings::NodeBinding::NodeConstants;
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::{OptionalSettable, TemporaryPushable, OptionalRootedRootable};
use dom::bindings::js::{ResultRootable, OptionalRootable};
@ -907,10 +908,10 @@ impl Node {
pub fn reflect_node<N: Reflectable+NodeBase>
(node: Box<N>,
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> {
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 {

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -2,27 +2,25 @@
* 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::js::{JS, JSRef, Temporary};
use dom::bindings::codegen::Bindings::TestBindingBinding::TestEnum;
use dom::bindings::codegen::Bindings::TestBindingBinding::TestEnumValues::_empty;
use dom::bindings::codegen::UnionTypes::BlobOrString::BlobOrString;
use dom::bindings::codegen::UnionTypes::EventOrString::{EventOrString, eString};
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::utils::{Reflector, Reflectable};
use dom::blob::Blob;
use dom::window::Window;
use servo_util::str::DOMString;
use js::jsapi::JSContext;
use js::jsval::{JSVal, NullValue};
use std::cell::Cell;
#[deriving(Encodable)]
pub struct TestBinding {
pub reflector: Reflector,
pub window: Cell<JS<Window>>,
reflector: Reflector,
global: GlobalField,
}
pub trait TestBindingMethods {
@ -279,20 +277,20 @@ pub trait TestBindingMethods {
impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
fn InterfaceAttribute(&self) -> Temporary<Blob> {
let window = self.window.get().root();
Blob::new(&*window)
let global = self.global.root();
Blob::new(&global.root_ref())
}
fn GetInterfaceAttributeNullable(&self) -> Option<Temporary<Blob>> {
let window = self.window.get().root();
Some(Blob::new(&*window))
let global = self.global.root();
Some(Blob::new(&global.root_ref()))
}
fn ReceiveInterface(&self) -> Temporary<Blob> {
let window = self.window.get().root();
Blob::new(&*window)
let global = self.global.root();
Blob::new(&global.root_ref())
}
fn ReceiveNullableInterface(&self) -> Option<Temporary<Blob>> {
let window = self.window.get().root();
Some(Blob::new(&*window))
let global = self.global.root();
Some(Blob::new(&global.root_ref()))
}
}

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -10,6 +10,7 @@ use dom::bindings::codegen::InheritTypes::{EventCast, EventTargetCast, XMLHttpRe
use dom::bindings::conversions::ToJSValConvertible;
use dom::bindings::error::{Error, ErrorResult, Fallible, InvalidState, InvalidAccess};
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::str::ByteString;
use dom::bindings::trace::{Traceable, Untraceable};
@ -19,7 +20,6 @@ use dom::event::Event;
use dom::eventtarget::{EventTarget, EventTargetHelpers, XMLHttpRequestTargetTypeId};
use dom::progressevent::ProgressEvent;
use dom::urlsearchparams::URLSearchParamsHelpers;
use dom::window::Window;
use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTarget;
use dom::xmlhttprequestupload::XMLHttpRequestUpload;
@ -102,7 +102,7 @@ pub struct XMLHttpRequest {
ready_state: Traceable<Cell<XMLHttpRequestState>>,
timeout: Traceable<Cell<u32>>,
with_credentials: Traceable<Cell<bool>>,
upload: Cell<JS<XMLHttpRequestUpload>>,
upload: JS<XMLHttpRequestUpload>,
response_url: DOMString,
status: Traceable<Cell<u16>>,
status_text: Traceable<RefCell<ByteString>>,
@ -121,7 +121,7 @@ pub struct XMLHttpRequest {
upload_events: Traceable<Cell<bool>>,
send_flag: Traceable<Cell<bool>>,
global: JS<Window>,
global: GlobalField,
pinned_count: Traceable<Cell<uint>>,
timer: Untraceable<RefCell<Timer>>,
fetch_time: Traceable<Cell<i64>>,
@ -130,13 +130,13 @@ pub struct XMLHttpRequest {
}
impl XMLHttpRequest {
pub fn new_inherited(owner: &JSRef<Window>) -> XMLHttpRequest {
pub fn new_inherited(global: &GlobalRef) -> XMLHttpRequest {
let xhr = XMLHttpRequest {
eventtarget: XMLHttpRequestEventTarget::new_inherited(XMLHttpRequestTypeId),
ready_state: Traceable::new(Cell::new(Unsent)),
timeout: Traceable::new(Cell::new(0u32)),
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(),
status: Traceable::new(Cell::new(0)),
status_text: Traceable::new(RefCell::new(ByteString::new(vec!()))),
@ -155,7 +155,7 @@ impl XMLHttpRequest {
upload_complete: 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)),
timer: Untraceable::new(RefCell::new(Timer::new().unwrap())),
fetch_time: Traceable::new(Cell::new(0)),
@ -164,13 +164,13 @@ impl XMLHttpRequest {
};
xhr
}
pub fn new(window: &JSRef<Window>) -> Temporary<XMLHttpRequest> {
reflect_dom_object(box XMLHttpRequest::new_inherited(window),
window,
pub fn new(global: &GlobalRef) -> Temporary<XMLHttpRequest> {
reflect_dom_object(box XMLHttpRequest::new_inherited(global),
global,
XMLHttpRequestBinding::Wrap)
}
pub fn Constructor(owner: &JSRef<Window>) -> Fallible<Temporary<XMLHttpRequest>> {
Ok(XMLHttpRequest::new(owner))
pub fn Constructor(global: &GlobalRef) -> Fallible<Temporary<XMLHttpRequest>> {
Ok(XMLHttpRequest::new(global))
}
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())
});
// 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 {
// Step 4
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);
}
fn Upload(&self) -> Temporary<XMLHttpRequestUpload> {
Temporary::new(self.upload.get())
Temporary::new(self.upload)
}
fn Send(&self, data: Option<SendParam>) -> ErrorResult {
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
let upload_target = &*self.upload.get().root();
let upload_target = &*self.upload.root();
let event_target: &JSRef<EventTarget> = EventTargetCast::from_ref(upload_target);
if event_target.has_handlers() {
self.upload_events.deref().set(true);
@ -486,7 +486,7 @@ impl<'a> XMLHttpRequestMethods<'a> for JSRef<'a, XMLHttpRequest> {
}
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());
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)
let referer_url = self.global.root().get_url();
let referer_url = self.global.root().root_ref().get_url();
let mut buf = String::new();
buf.push_str(referer_url.scheme.as_slice());
buf.push_str("://".as_slice());
@ -537,7 +537,7 @@ impl<'a> XMLHttpRequestMethods<'a> for JSRef<'a, XMLHttpRequest> {
} else {
let builder = TaskBuilder::new().named("XHRTask");
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() {
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()
unsafe fn to_trusted(&self) -> TrustedXHRAddress {
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();
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);
if self.pinned_count.deref().get() == 0 {
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) {
assert!(self.ready_state.deref().get() != rs)
self.ready_state.deref().set(rs);
let win = &*self.global.root();
let event =
Event::new(win, "readystatechange".to_string(), false, true).root();
let global = self.global.root();
let event = Event::new(&global.root_ref(),
"readystatechange".to_string(),
false, true).root();
let target: &JSRef<EventTarget> = EventTargetCast::from_ref(self);
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>) {
let win = &*self.global.root();
let upload_target = &*self.upload.get().root();
let progressevent = ProgressEvent::new(win, type_, false, false,
let global = self.global.root();
let upload_target = &*self.upload.root();
let progressevent = ProgressEvent::new(&global.root_ref(),
type_, false, false,
total.is_some(), loaded,
total.unwrap_or(0)).root();
let target: &JSRef<EventTarget> = if upload {
@ -878,7 +880,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> {
}
self.timeout_pinned.deref().set(true);
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();
spawn_named("XHR:Timer", proc () {
match oneshot.recv_opt() {

Просмотреть файл

@ -4,10 +4,10 @@
use dom::bindings::codegen::InheritTypes::XMLHttpRequestUploadDerived;
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::eventtarget::{EventTarget, XMLHttpRequestTargetTypeId};
use dom::window::Window;
use dom::xmlhttprequest::{XMLHttpRequestUploadTypeId};
use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTarget;
@ -22,9 +22,9 @@ impl XMLHttpRequestUpload {
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(),
window,
global,
XMLHttpRequestUploadBinding::Wrap)
}
}

Просмотреть файл

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

Просмотреть файл

@ -6,6 +6,7 @@
//! and layout tasks.
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::OptionalRootable;
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
// "load" event as soon as we've finished executing all scripts parsed during
// 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 wintarget: &JSRef<EventTarget> = EventTargetCast::from_ref(&*window);
let _ = wintarget.dispatch_event_with_target(Some((*doctarget).clone()),
@ -719,7 +720,7 @@ impl ScriptTask {
Some(ref frame) => {
let window = frame.window.root();
let event =
Event::new(&*window,
Event::new(&Window(*window),
"click".to_string(),
true, true).root();
let eventtarget: &JSRef<EventTarget> = EventTargetCast::from_ref(&node);