From afafde5191e5de9934103d4ecad5c51559146dc9 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 27 Apr 2015 01:51:28 +0200 Subject: [PATCH] Change MutNullableJS to MutNullableHeap> --- components/script/dom/attr.rs | 10 +-- components/script/dom/bindings/js.rs | 89 ++++++++++------------ components/script/dom/document.rs | 42 +++++----- components/script/dom/element.rs | 9 ++- components/script/dom/event.rs | 18 ++--- components/script/dom/htmlanchorelement.rs | 5 +- components/script/dom/htmlareaelement.rs | 4 +- components/script/dom/htmlcanvaselement.rs | 12 +-- components/script/dom/htmlelement.rs | 6 +- components/script/dom/htmlinputelement.rs | 9 ++- components/script/dom/htmllinkelement.rs | 5 +- components/script/dom/mouseevent.rs | 9 ++- components/script/dom/node.rs | 83 ++++++++++---------- components/script/dom/storageevent.rs | 9 ++- components/script/dom/uievent.rs | 9 ++- components/script/dom/window.rs | 15 ++-- components/script/dom/workerglobalscope.rs | 8 +- components/script/dom/xmlhttprequest.rs | 7 +- 18 files changed, 176 insertions(+), 173 deletions(-) diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 1387131e0f8..c25c9d4d611 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -6,7 +6,7 @@ use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::{self, AttrMethods}; use dom::bindings::codegen::InheritTypes::NodeCast; use dom::bindings::global::GlobalRef; -use dom::bindings::js::{JSRef, MutNullableJS, Temporary}; +use dom::bindings::js::{JS, JSRef, MutNullableHeap, Temporary}; use dom::bindings::js::{OptionalRootable, OptionalRootedRootable}; use dom::bindings::js::RootedReference; use dom::bindings::utils::{Reflector, reflect_dom_object}; @@ -104,7 +104,7 @@ pub struct Attr { prefix: Option, /// the element that owns this attribute. - owner: MutNullableJS, + owner: MutNullableHeap>, } impl Attr { @@ -117,7 +117,7 @@ impl Attr { name: name, namespace: namespace, prefix: prefix, - owner: MutNullableJS::new(owner), + owner: MutNullableHeap::new(owner.map(JS::from_rooted)), } } @@ -271,11 +271,11 @@ impl<'a> AttrHelpers<'a> for JSRef<'a, Attr> { } (old, new) => assert!(old == new) } - self.owner.assign(owner) + self.owner.set(owner.map(JS::from_rooted)) } fn owner(self) -> Option> { - self.owner.get() + self.owner.get().map(Temporary::new) } fn summarize(self) -> AttrInfo { diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index cb8aaf04160..80eb1317f32 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -339,54 +339,50 @@ impl MutHeap { } } -/// A mutable `JS` value, with nullability represented by an enclosing -/// Option wrapper. Must be used in place of traditional internal mutability -/// to ensure that the proper GC barriers are enforced. +/// A mutable holder for GC-managed values such as `JSval` and `JS`, with +/// nullability represented by an enclosing Option wrapper. Must be used in +/// place of traditional internal mutability to ensure that the proper GC +/// barriers are enforced. #[must_root] #[jstraceable] -pub struct MutNullableJS { - ptr: Cell>> +pub struct MutNullableHeap { + ptr: Cell> } -impl MutNullableJS { - /// Create a new `MutNullableJS` - pub fn new>(initial: Option) -> MutNullableJS { - MutNullableJS { - ptr: Cell::new(initial.map(|initial| { - unsafe { initial.get_js() } - })) +impl MutNullableHeap { + /// Create a new `MutNullableHeap`. + pub fn new(initial: Option) -> MutNullableHeap { + MutNullableHeap { + ptr: Cell::new(initial) } } -} -impl Default for MutNullableJS { - fn default() -> MutNullableJS { - MutNullableJS { - ptr: Cell::new(None) - } - } -} - -impl MutNullableJS { - /// Store an unrooted value in this field. This is safe under the - /// assumption that `MutNullableJS` values are only used as fields in - /// DOM types that are reachable in the GC graph, so this unrooted value - /// becomes transitively rooted for the lifetime of its new owner. - pub fn assign>(&self, val: Option) { - self.ptr.set(val.map(|val| { - unsafe { val.get_js() } - })); - } - - /// Set the inner value to null, without making API users jump through - /// useless type-ascription hoops. - pub fn clear(&self) { - self.assign(None::>); + /// Set this `MutNullableHeap` to the given value, calling write barriers + /// as appropriate. + pub fn set(&self, val: Option) { + self.ptr.set(val); } /// Retrieve a copy of the current optional inner value. - pub fn get(&self) -> Option> { - self.ptr.get().map(Temporary::new) + pub fn get(&self) -> Option { + self.ptr.get() + } +} + +impl MutNullableHeap> { + /// Retrieve a copy of the current inner value. If it is `None`, it is + /// initialized with the result of `cb` first. + pub fn or_init(&self, cb: F) -> Temporary + where F: FnOnce() -> Temporary + { + match self.get() { + Some(inner) => Temporary::new(inner), + None => { + let inner = cb(); + self.set(Some(JS::from_rooted(inner.clone()))); + inner + }, + } } /// Retrieve a copy of the inner optional `JS` as `LayoutJS`. @@ -394,19 +390,12 @@ impl MutNullableJS { pub unsafe fn get_inner_as_layout(&self) -> Option> { self.ptr.get().map(|js| js.to_layout()) } +} - /// Retrieve a copy of the current inner value. If it is `None`, it is - /// initialized with the result of `cb` first. - pub fn or_init(&self, cb: F) -> Temporary - where F: FnOnce() -> Temporary - { - match self.get() { - Some(inner) => inner, - None => { - let inner = cb(); - self.assign(Some(inner.clone())); - inner - }, +impl Default for MutNullableHeap { + fn default() -> MutNullableHeap { + MutNullableHeap { + ptr: Cell::new(None) } } } diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index e83f9c51bbb..8cd3655d7c5 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -24,8 +24,10 @@ use dom::bindings::error::{ErrorResult, Fallible}; use dom::bindings::error::Error::{NotSupported, InvalidCharacter, Security}; use dom::bindings::error::Error::HierarchyRequest; use dom::bindings::global::GlobalRef; -use dom::bindings::js::{MutNullableJS, JS, JSRef, LayoutJS, Temporary, TemporaryPushable}; -use dom::bindings::js::{OptionalRootable, RootedReference}; +use dom::bindings::js::{JS, JSRef, LayoutJS, MutNullableHeap}; +use dom::bindings::js::{OptionalRootable, OptionalRootedRootable}; +use dom::bindings::js::{RootedReference, Temporary}; +use dom::bindings::js::TemporaryPushable; use dom::bindings::refcounted::Trusted; use dom::bindings::trace::RootedVec; use dom::bindings::utils::reflect_dom_object; @@ -102,28 +104,28 @@ pub struct Document { node: Node, window: JS, idmap: DOMRefCell>>>, - implementation: MutNullableJS, - location: MutNullableJS, + implementation: MutNullableHeap>, + location: MutNullableHeap>, content_type: DOMString, last_modified: Option, encoding_name: DOMRefCell, is_html_document: bool, url: Url, quirks_mode: Cell, - images: MutNullableJS, - embeds: MutNullableJS, - links: MutNullableJS, - forms: MutNullableJS, - scripts: MutNullableJS, - anchors: MutNullableJS, - applets: MutNullableJS, + images: MutNullableHeap>, + embeds: MutNullableHeap>, + links: MutNullableHeap>, + forms: MutNullableHeap>, + scripts: MutNullableHeap>, + anchors: MutNullableHeap>, + applets: MutNullableHeap>, ready_state: Cell, /// The element that has most recently requested focus for itself. - possibly_focused: MutNullableJS, + possibly_focused: MutNullableHeap>, /// The element that currently has the document focus context. - focused: MutNullableJS, + focused: MutNullableHeap>, /// The script element that is currently executing. - current_script: MutNullableJS, + current_script: MutNullableHeap>, /// https://html.spec.whatwg.org/multipage/#concept-n-noscript /// True if scripting is enabled for all scripts in this document scripting_enabled: Cell, @@ -440,19 +442,19 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { /// Return the element that currently has focus. // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#events-focusevent-doc-focus fn get_focused_element(self) -> Option> { - self.focused.get() + self.focused.get().map(Temporary::new) } /// Initiate a new round of checking for elements requesting focus. The last element to call /// `request_focus` before `commit_focus_transaction` is called will receive focus. fn begin_focus_transaction(self) { - self.possibly_focused.clear(); + self.possibly_focused.set(None); } /// Request that the given element receive focus once the current transaction is complete. fn request_focus(self, elem: JSRef) { if elem.is_focusable_area() { - self.possibly_focused.assign(Some(elem)) + self.possibly_focused.set(Some(JS::from_rooted(elem))) } } @@ -466,7 +468,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { node.set_focus_state(false); } - self.focused.assign(self.possibly_focused.get()); + self.focused.set(self.possibly_focused.get()); if let Some(ref elem) = self.focused.get().root() { let node: JSRef = NodeCast::from_ref(elem.r()); @@ -741,7 +743,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { } fn set_current_script(self, script: Option>) { - self.current_script.assign(script); + self.current_script.set(script.map(JS::from_rooted)); } fn trigger_mozbrowser_event(self, event: MozBrowserEvent) { @@ -1250,7 +1252,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // https://html.spec.whatwg.org/#dom-document-currentscript fn GetCurrentScript(self) -> Option> { - self.current_script.get() + self.current_script.get().map(Temporary::new) } // https://html.spec.whatwg.org/#dom-document-body diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 3f0ba0e8ca1..c17d4dce43f 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -27,8 +27,9 @@ use dom::bindings::codegen::UnionTypes::NodeOrString; use dom::bindings::error::{ErrorResult, Fallible}; use dom::bindings::error::Error::{InvalidCharacter, Syntax}; use dom::bindings::error::Error::NoModificationAllowed; -use dom::bindings::js::{MutNullableJS, JS, JSRef, LayoutJS, Temporary, TemporaryPushable}; -use dom::bindings::js::{OptionalRootable, RootedReference}; +use dom::bindings::js::{JS, JSRef, LayoutJS, MutNullableHeap}; +use dom::bindings::js::{OptionalRootable, RootedReference, Temporary}; +use dom::bindings::js::TemporaryPushable; use dom::bindings::trace::RootedVec; use dom::bindings::utils::{xml_name_type, validate_and_extract}; use dom::bindings::utils::XMLName::InvalidXMLName; @@ -88,8 +89,8 @@ pub struct Element { prefix: Option, attrs: DOMRefCell>>, style_attribute: DOMRefCell>, - attr_list: MutNullableJS, - class_list: MutNullableJS, + attr_list: MutNullableHeap>, + class_list: MutNullableHeap>, } impl ElementDerived for EventTarget { diff --git a/components/script/dom/event.rs b/components/script/dom/event.rs index b44fef145a1..8a969fb3e9b 100644 --- a/components/script/dom/event.rs +++ b/components/script/dom/event.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::EventBinding; use dom::bindings::codegen::Bindings::EventBinding::{EventConstants, EventMethods}; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; -use dom::bindings::js::{MutNullableJS, JSRef, Temporary}; +use dom::bindings::js::{JS, JSRef, MutNullableHeap, Temporary}; use dom::bindings::utils::{Reflector, reflect_dom_object}; use dom::eventtarget::{EventTarget, EventTargetHelpers}; use util::str::DOMString; @@ -58,8 +58,8 @@ pub enum EventCancelable { pub struct Event { reflector_: Reflector, type_id: EventTypeId, - current_target: MutNullableJS, - target: MutNullableJS, + current_target: MutNullableHeap>, + target: MutNullableHeap>, type_: DOMRefCell, phase: Cell, canceled: Cell, @@ -124,17 +124,17 @@ impl Event { #[inline] pub fn clear_current_target(&self) { - self.current_target.clear(); + self.current_target.set(None); } #[inline] pub fn set_current_target(&self, val: JSRef) { - self.current_target.assign(Some(val)); + self.current_target.set(Some(JS::from_rooted(val))); } #[inline] pub fn set_target(&self, val: JSRef) { - self.target.assign(Some(val)); + self.target.set(Some(JS::from_rooted(val))); } #[inline] @@ -188,12 +188,12 @@ impl<'a> EventMethods for JSRef<'a, Event> { // https://dom.spec.whatwg.org/#dom-event-target fn GetTarget(self) -> Option> { - self.target.get() + self.target.get().map(Temporary::new) } // https://dom.spec.whatwg.org/#dom-event-currenttarget fn GetCurrentTarget(self) -> Option> { - self.current_target.get() + self.current_target.get().map(Temporary::new) } // https://dom.spec.whatwg.org/#dom-event-defaultprevented @@ -248,7 +248,7 @@ impl<'a> EventMethods for JSRef<'a, Event> { self.stop_immediate.set(false); self.canceled.set(false); self.trusted.set(false); - self.target.clear(); + self.target.set(None); *self.type_.borrow_mut() = type_; self.bubbles.set(bubbles); self.cancelable.set(cancelable); diff --git a/components/script/dom/htmlanchorelement.rs b/components/script/dom/htmlanchorelement.rs index 80e5d476837..74c8e8b2d85 100644 --- a/components/script/dom/htmlanchorelement.rs +++ b/components/script/dom/htmlanchorelement.rs @@ -13,7 +13,8 @@ use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::InheritTypes::{HTMLAnchorElementDerived, HTMLImageElementDerived}; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast}; use dom::bindings::codegen::InheritTypes::{MouseEventCast, NodeCast}; -use dom::bindings::js::{MutNullableJS, JSRef, Temporary, OptionalRootable}; +use dom::bindings::js::{JS, JSRef, MutNullableHeap, Temporary}; +use dom::bindings::js::OptionalRootable; use dom::document::{Document, DocumentHelpers}; use dom::domtokenlist::DOMTokenList; use dom::element::{Element, AttributeHandlers, ElementTypeId}; @@ -32,7 +33,7 @@ use util::str::DOMString; #[dom_struct] pub struct HTMLAnchorElement { htmlelement: HTMLElement, - rel_list: MutNullableJS, + rel_list: MutNullableHeap>, } impl HTMLAnchorElementDerived for EventTarget { diff --git a/components/script/dom/htmlareaelement.rs b/components/script/dom/htmlareaelement.rs index 0a88f6153a8..9c7d255a5b4 100644 --- a/components/script/dom/htmlareaelement.rs +++ b/components/script/dom/htmlareaelement.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::HTMLAreaElementBinding; use dom::bindings::codegen::Bindings::HTMLAreaElementBinding::HTMLAreaElementMethods; use dom::bindings::codegen::InheritTypes::{HTMLAreaElementDerived, HTMLElementCast}; use dom::bindings::codegen::InheritTypes::ElementCast; -use dom::bindings::js::{MutNullableJS, JSRef, Temporary}; +use dom::bindings::js::{JS, JSRef, MutNullableHeap, Temporary}; use dom::bindings::utils::Reflectable; use dom::document::Document; use dom::domtokenlist::DOMTokenList; @@ -24,7 +24,7 @@ use util::str::DOMString; #[dom_struct] pub struct HTMLAreaElement { htmlelement: HTMLElement, - rel_list: MutNullableJS, + rel_list: MutNullableHeap>, } impl HTMLAreaElementDerived for EventTarget { diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index efeb61386e0..5beb415f3e1 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -11,7 +11,8 @@ use dom::bindings::codegen::InheritTypes::HTMLCanvasElementDerived; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast}; use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; use dom::bindings::global::GlobalRef; -use dom::bindings::js::{MutNullableJS, JSRef, LayoutJS, Temporary, Unrooted}; +use dom::bindings::js::{JS, JSRef, LayoutJS, MutNullableHeap, Temporary}; +use dom::bindings::js::Unrooted; use dom::bindings::utils::{Reflectable}; use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; use dom::document::Document; @@ -37,8 +38,8 @@ const DEFAULT_HEIGHT: u32 = 150; #[dom_struct] pub struct HTMLCanvasElement { htmlelement: HTMLElement, - context_2d: MutNullableJS, - context_webgl: MutNullableJS, + context_2d: MutNullableHeap>, + context_webgl: MutNullableHeap>, width: Cell, height: Cell, } @@ -192,11 +193,12 @@ impl<'a> HTMLCanvasElementMethods for JSRef<'a, HTMLCanvasElement> { let window = window_from_node(self).root(); let size = self.get_size(); - self.context_webgl.assign(WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size)) + self.context_webgl.set( + WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size).map(JS::from_rooted)) } self.context_webgl.get().map( |ctx| - CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext(Unrooted::from_temporary(ctx))) + CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext(Unrooted::from_js(ctx))) } _ => None } diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 8c0445b8ea2..c0431b3856a 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -12,7 +12,7 @@ use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLFrameSetElementDerived}; use dom::bindings::codegen::InheritTypes::{EventTargetCast, HTMLInputElementCast, NodeCast}; use dom::bindings::codegen::InheritTypes::{HTMLElementDerived, HTMLBodyElementDerived}; -use dom::bindings::js::{JSRef, Temporary, MutNullableJS}; +use dom::bindings::js::{JS, JSRef, MutNullableHeap, Temporary}; use dom::bindings::error::ErrorResult; use dom::bindings::error::Error::Syntax; use dom::bindings::utils::Reflectable; @@ -39,8 +39,8 @@ use std::default::Default; #[dom_struct] pub struct HTMLElement { element: Element, - style_decl: MutNullableJS, - dataset: MutNullableJS, + style_decl: MutNullableHeap>, + dataset: MutNullableHeap>, } impl HTMLElementDerived for EventTarget { diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index d8f5407a9d1..56596a181e9 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -14,8 +14,9 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLInp use dom::bindings::codegen::InheritTypes::{HTMLInputElementDerived, HTMLFieldSetElementDerived, EventTargetCast}; use dom::bindings::codegen::InheritTypes::KeyboardEventCast; use dom::bindings::global::GlobalRef; -use dom::bindings::js::{Comparable, JSRef, LayoutJS, Root, Temporary, OptionalRootable}; -use dom::bindings::js::{ResultRootable, RootedReference, MutNullableJS}; +use dom::bindings::js::{Comparable, JS, JSRef, LayoutJS, MutNullableHeap}; +use dom::bindings::js::{OptionalRootable, OptionalRootedRootable}; +use dom::bindings::js::{ResultRootable, Root, RootedReference, Temporary}; use dom::document::{Document, DocumentHelpers}; use dom::element::{AttributeHandlers, Element}; use dom::element::{RawLayoutElementHelpers, ActivationElementHelpers}; @@ -80,7 +81,7 @@ struct InputActivationState { indeterminate: bool, checked: bool, checked_changed: bool, - checked_radio: MutNullableJS, + checked_radio: MutNullableHeap>, // In case mutability changed was_mutable: bool, // In case the type changed @@ -694,7 +695,7 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { r.r().Checked() }) }; - cache.checked_radio.assign(checked_member.r()); + cache.checked_radio.set(checked_member.r().map(JS::from_rooted)); cache.checked_changed = self.checked_changed.get(); self.SetChecked(true); } diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index c1b455ccf49..0a415c8d0be 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -8,7 +8,8 @@ use dom::bindings::codegen::Bindings::HTMLLinkElementBinding; use dom::bindings::codegen::Bindings::HTMLLinkElementBinding::HTMLLinkElementMethods; use dom::bindings::codegen::InheritTypes::HTMLLinkElementDerived; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCast}; -use dom::bindings::js::{MutNullableJS, JSRef, Temporary, OptionalRootable}; +use dom::bindings::js::{JS, JSRef, MutNullableHeap, Temporary}; +use dom::bindings::js::OptionalRootable; use dom::document::Document; use dom::domtokenlist::DOMTokenList; use dom::element::{AttributeHandlers, Element}; @@ -33,7 +34,7 @@ use string_cache::Atom; #[dom_struct] pub struct HTMLLinkElement { htmlelement: HTMLElement, - rel_list: MutNullableJS, + rel_list: MutNullableHeap>, } impl HTMLLinkElementDerived for EventTarget { diff --git a/components/script/dom/mouseevent.rs b/components/script/dom/mouseevent.rs index 1af4adf79c4..71e95fb4b02 100644 --- a/components/script/dom/mouseevent.rs +++ b/components/script/dom/mouseevent.rs @@ -8,7 +8,8 @@ use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods; use dom::bindings::codegen::InheritTypes::{EventCast, UIEventCast, MouseEventDerived}; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; -use dom::bindings::js::{MutNullableJS, JSRef, RootedReference, Temporary}; +use dom::bindings::js::{JS, JSRef, MutNullableHeap, RootedReference}; +use dom::bindings::js::Temporary; use dom::bindings::utils::reflect_dom_object; use dom::event::{Event, EventTypeId, EventBubbles, EventCancelable}; use dom::eventtarget::EventTarget; @@ -30,7 +31,7 @@ pub struct MouseEvent { alt_key: Cell, meta_key: Cell, button: Cell, - related_target: MutNullableJS + related_target: MutNullableHeap>, } impl MouseEventDerived for Event { @@ -142,7 +143,7 @@ impl<'a> MouseEventMethods for JSRef<'a, MouseEvent> { } fn GetRelatedTarget(self) -> Option> { - self.related_target.get() + self.related_target.get().map(Temporary::new) } fn InitMouseEvent(self, @@ -177,7 +178,7 @@ impl<'a> MouseEventMethods for JSRef<'a, MouseEvent> { self.shift_key.set(shiftKeyArg); self.meta_key.set(metaKeyArg); self.button.set(buttonArg); - self.related_target.assign(relatedTargetArg); + self.related_target.set(relatedTargetArg.map(JS::from_rooted)); } } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 8037454d5dc..525130af9fc 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -24,9 +24,10 @@ use dom::bindings::conversions; use dom::bindings::error::{ErrorResult, Fallible}; use dom::bindings::error::Error::{NotFound, HierarchyRequest, Syntax}; use dom::bindings::global::GlobalRef; -use dom::bindings::js::{JS, JSRef, LayoutJS, RootedReference, Temporary, Root, Unrooted}; -use dom::bindings::js::{TemporaryPushable, OptionalRootedRootable}; -use dom::bindings::js::{ResultRootable, OptionalRootable, MutNullableJS}; +use dom::bindings::js::{JS, JSRef, LayoutJS, OptionalRootable}; +use dom::bindings::js::{OptionalRootedRootable, MutNullableHeap}; +use dom::bindings::js::{ResultRootable, Root, RootedReference, Temporary}; +use dom::bindings::js::{TemporaryPushable, Unrooted}; use dom::bindings::trace::JSTraceable; use dom::bindings::trace::RootedVec; use dom::bindings::utils::{Reflectable, reflect_dom_object}; @@ -85,25 +86,25 @@ pub struct Node { type_id: NodeTypeId, /// The parent of this node. - parent_node: MutNullableJS, + parent_node: MutNullableHeap>, /// The first child of this node. - first_child: MutNullableJS, + first_child: MutNullableHeap>, /// The last child of this node. - last_child: MutNullableJS, + last_child: MutNullableHeap>, /// The next sibling of this node. - next_sibling: MutNullableJS, + next_sibling: MutNullableHeap>, /// The previous sibling of this node. - prev_sibling: MutNullableJS, + prev_sibling: MutNullableHeap>, /// The document that this node belongs to. - owner_doc: MutNullableJS, + owner_doc: MutNullableHeap>, /// The live list of children return by .childNodes. - child_list: MutNullableJS, + child_list: MutNullableHeap>, /// A bitfield of flags for node items. flags: Cell, @@ -328,31 +329,31 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> { match before.prev_sibling().root() { None => { assert!(Some(*before) == self.first_child().root().r()); - self.first_child.assign(Some(new_child)); + self.first_child.set(Some(JS::from_rooted(new_child))); }, Some(prev_sibling) => { - prev_sibling.r().next_sibling.assign(Some(new_child)); - new_child.prev_sibling.assign(Some(prev_sibling.r())); + prev_sibling.r().next_sibling.set(Some(JS::from_rooted(new_child))); + new_child.prev_sibling.set(Some(JS::from_rooted(prev_sibling.r()))); }, } - before.prev_sibling.assign(Some(new_child)); - new_child.next_sibling.assign(Some(*before)); + before.prev_sibling.set(Some(JS::from_rooted(new_child))); + new_child.next_sibling.set(Some(JS::from_rooted(*before))); }, None => { match self.last_child().root() { - None => self.first_child.assign(Some(new_child)), + None => self.first_child.set(Some(JS::from_rooted(new_child))), Some(last_child) => { assert!(last_child.r().next_sibling().is_none()); - last_child.r().next_sibling.assign(Some(new_child)); - new_child.prev_sibling.assign(Some(last_child.r())); + last_child.r().next_sibling.set(Some(JS::from_rooted(new_child))); + new_child.prev_sibling.set(Some(JS::from_rooted(last_child.r()))); } } - self.last_child.assign(Some(new_child)); + self.last_child.set(Some(JS::from_rooted(new_child))); }, } - new_child.parent_node.assign(Some(self)); + new_child.parent_node.set(Some(JS::from_rooted(self))); } /// Removes the given child from this node's list of children. @@ -363,25 +364,25 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> { match child.prev_sibling.get().root() { None => { - self.first_child.assign(child.next_sibling.get()); + self.first_child.set(child.next_sibling.get()); } Some(prev_sibling) => { - prev_sibling.r().next_sibling.assign(child.next_sibling.get()); + prev_sibling.r().next_sibling.set(child.next_sibling.get()); } } match child.next_sibling.get().root() { None => { - self.last_child.assign(child.prev_sibling.get()); + self.last_child.set(child.prev_sibling.get()); } Some(next_sibling) => { - next_sibling.r().prev_sibling.assign(child.prev_sibling.get()); + next_sibling.r().prev_sibling.set(child.prev_sibling.get()); } } - child.prev_sibling.clear(); - child.next_sibling.clear(); - child.parent_node.clear(); + child.prev_sibling.set(None); + child.next_sibling.set(None); + child.parent_node.set(None); } } @@ -569,25 +570,25 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { } fn parent_node(self) -> Option> { - self.parent_node.get() + self.parent_node.get().map(Temporary::new) } fn first_child(self) -> Option> { - self.first_child.get() + self.first_child.get().map(Temporary::new) } fn last_child(self) -> Option> { - self.last_child.get() + self.last_child.get().map(Temporary::new) } /// Returns the previous sibling of this node. Fails if this node is borrowed mutably. fn prev_sibling(self) -> Option> { - self.prev_sibling.get() + self.prev_sibling.get().map(Temporary::new) } /// Returns the next sibling of this node. Fails if this node is borrowed mutably. fn next_sibling(self) -> Option> { - self.next_sibling.get() + self.next_sibling.get().map(Temporary::new) } #[inline] @@ -946,11 +947,11 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { } fn owner_doc(self) -> Temporary { - self.owner_doc.get().unwrap() + Temporary::new(self.owner_doc.get().unwrap()) } fn set_owner_doc(self, document: JSRef) { - self.owner_doc.assign(Some(document.clone())); + self.owner_doc.set(Some(JS::from_rooted(document))); } fn is_in_html_doc(self) -> bool { @@ -959,7 +960,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { fn children(self) -> NodeSiblingIterator { NodeSiblingIterator { - current: self.first_child.get(), + current: self.first_child(), } } @@ -1346,7 +1347,7 @@ impl Node { last_child: Default::default(), next_sibling: Default::default(), prev_sibling: Default::default(), - owner_doc: MutNullableJS::new(doc), + owner_doc: MutNullableHeap::new(doc.map(JS::from_rooted)), child_list: Default::default(), flags: Cell::new(NodeFlags::new(type_id)), @@ -1872,7 +1873,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { // https://dom.spec.whatwg.org/#dom-node-parentnode fn GetParentNode(self) -> Option> { - self.parent_node.get() + self.parent_node.get().map(Temporary::new) } // https://dom.spec.whatwg.org/#dom-node-parentelement @@ -1902,22 +1903,22 @@ impl<'a> NodeMethods for JSRef<'a, Node> { // https://dom.spec.whatwg.org/#dom-node-firstchild fn GetFirstChild(self) -> Option> { - self.first_child.get() + self.first_child.get().map(Temporary::new) } // https://dom.spec.whatwg.org/#dom-node-lastchild fn GetLastChild(self) -> Option> { - self.last_child.get() + self.last_child.get().map(Temporary::new) } // https://dom.spec.whatwg.org/#dom-node-previoussibling fn GetPreviousSibling(self) -> Option> { - self.prev_sibling.get() + self.prev_sibling.get().map(Temporary::new) } // https://dom.spec.whatwg.org/#dom-node-nextsibling fn GetNextSibling(self) -> Option> { - self.next_sibling.get() + self.next_sibling.get().map(Temporary::new) } // https://dom.spec.whatwg.org/#dom-node-nodevalue diff --git a/components/script/dom/storageevent.rs b/components/script/dom/storageevent.rs index 18de6ae88f0..ba394df0ee8 100644 --- a/components/script/dom/storageevent.rs +++ b/components/script/dom/storageevent.rs @@ -10,7 +10,8 @@ use dom::bindings::codegen::Bindings::StorageEventBinding::{StorageEventMethods} use dom::bindings::codegen::InheritTypes::{EventCast}; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; -use dom::bindings::js::{MutNullableJS, JSRef, RootedReference, Temporary}; +use dom::bindings::js::{JS, JSRef, MutNullableHeap, RootedReference}; +use dom::bindings::js::Temporary; use dom::bindings::utils::{reflect_dom_object}; use dom::event::{Event, EventTypeId, EventBubbles, EventCancelable}; use dom::storage::Storage; @@ -23,7 +24,7 @@ pub struct StorageEvent { oldValue: DOMRefCell>, newValue: DOMRefCell>, url: DOMRefCell, - storageArea: MutNullableJS + storageArea: MutNullableHeap> } @@ -40,7 +41,7 @@ impl StorageEvent { oldValue: DOMRefCell::new(oldValue), newValue: DOMRefCell::new(newValue), url: DOMRefCell::new(url), - storageArea: MutNullableJS::new(storageArea) + storageArea: MutNullableHeap::new(storageArea.map(JS::from_rooted)) } } @@ -107,7 +108,7 @@ impl<'a> StorageEventMethods for JSRef<'a, StorageEvent> { } fn GetStorageArea(self) -> Option> { - self.storageArea.get() + self.storageArea.get().map(Temporary::new) } } diff --git a/components/script/dom/uievent.rs b/components/script/dom/uievent.rs index 24d029cbce7..eec08a0193b 100644 --- a/components/script/dom/uievent.rs +++ b/components/script/dom/uievent.rs @@ -8,7 +8,8 @@ use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods; use dom::bindings::codegen::InheritTypes::{EventCast, UIEventDerived}; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; -use dom::bindings::js::{MutNullableJS, JSRef, RootedReference, Temporary}; +use dom::bindings::js::{JS, JSRef, MutNullableHeap, RootedReference}; +use dom::bindings::js::Temporary; use dom::bindings::utils::reflect_dom_object; use dom::event::{Event, EventTypeId, EventBubbles, EventCancelable}; @@ -22,7 +23,7 @@ use std::default::Default; #[dom_struct] pub struct UIEvent { event: Event, - view: MutNullableJS, + view: MutNullableHeap>, detail: Cell } @@ -73,7 +74,7 @@ impl UIEvent { impl<'a> UIEventMethods for JSRef<'a, UIEvent> { // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#widl-UIEvent-view fn GetView(self) -> Option> { - self.view.get() + self.view.get().map(Temporary::new) } // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#widl-UIEvent-detail @@ -93,7 +94,7 @@ impl<'a> UIEventMethods for JSRef<'a, UIEvent> { } event.InitEvent(type_, can_bubble, cancelable); - self.view.assign(view); + self.view.set(view.map(JS::from_rooted)); self.detail.set(detail); } } diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index ec98dfff19f..f8c468e14fc 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -13,7 +13,8 @@ use dom::bindings::global::global_object_for_js_object; use dom::bindings::error::{report_pending_exception, Fallible}; use dom::bindings::error::Error::InvalidCharacter; use dom::bindings::global::GlobalRef; -use dom::bindings::js::{MutNullableJS, JSRef, Temporary, OptionalRootable, RootedReference}; +use dom::bindings::js::{JS, JSRef, MutNullableHeap, OptionalRootable}; +use dom::bindings::js::{RootedReference, Temporary}; use dom::bindings::utils::{GlobalStaticData, Reflectable, WindowProxyHandler}; use dom::browsercontext::BrowserContext; use dom::console::Console; @@ -87,19 +88,19 @@ pub struct Window { eventtarget: EventTarget, script_chan: Box, control_chan: ScriptControlChan, - console: MutNullableJS, - navigator: MutNullableJS, + console: MutNullableHeap>, + navigator: MutNullableHeap>, image_cache_task: ImageCacheTask, image_cache_chan: ImageCacheChan, compositor: DOMRefCell>, browser_context: DOMRefCell>, page: Rc, - performance: MutNullableJS, + performance: MutNullableHeap>, navigation_start: u64, navigation_start_precise: f64, - screen: MutNullableJS, - session_storage: MutNullableJS, - local_storage: MutNullableJS, + screen: MutNullableHeap>, + session_storage: MutNullableHeap>, + local_storage: MutNullableHeap>, timers: TimerManager, next_worker_id: Cell, diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index 170dd317c7b..ec58f3e4221 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -8,7 +8,7 @@ use dom::bindings::codegen::InheritTypes::DedicatedWorkerGlobalScopeCast; use dom::bindings::error::{ErrorResult, Fallible}; use dom::bindings::error::Error::{Syntax, Network, JSFailed}; use dom::bindings::global::GlobalRef; -use dom::bindings::js::{MutNullableJS, JSRef, Temporary}; +use dom::bindings::js::{JS, JSRef, MutNullableHeap, Temporary}; use dom::bindings::utils::Reflectable; use dom::console::Console; use dom::dedicatedworkerglobalscope::{DedicatedWorkerGlobalScope, DedicatedWorkerGlobalScopeHelpers}; @@ -48,9 +48,9 @@ pub struct WorkerGlobalScope { js_context: Rc, next_worker_id: Cell, resource_task: ResourceTask, - location: MutNullableJS, - navigator: MutNullableJS, - console: MutNullableJS, + location: MutNullableHeap>, + navigator: MutNullableHeap>, + console: MutNullableHeap>, timers: TimerManager, devtools_chan: Option, } diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index ffb0b2e17f5..69295ea3f30 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -14,7 +14,8 @@ use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::error::Error::{InvalidState, InvalidAccess}; use dom::bindings::error::Error::{Network, Syntax, Security, Abort, Timeout}; use dom::bindings::global::{GlobalField, GlobalRef, GlobalRoot}; -use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary, OptionalRootedRootable}; +use dom::bindings::js::{JS, JSRef, MutNullableHeap, Temporary}; +use dom::bindings::js::OptionalRootedRootable; use dom::bindings::refcounted::Trusted; use dom::bindings::str::ByteString; use dom::bindings::utils::{Reflectable, reflect_dom_object}; @@ -125,7 +126,7 @@ pub struct XMLHttpRequest { status_text: DOMRefCell, response: DOMRefCell, response_type: Cell, - response_xml: MutNullableJS, + response_xml: MutNullableHeap>, response_headers: DOMRefCell, // Associated concepts @@ -710,7 +711,7 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { // https://xhr.spec.whatwg.org/#the-responsexml-attribute fn GetResponseXML(self) -> Option> { - self.response_xml.get() + self.response_xml.get().map(Temporary::new) } }