aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/bindings/DESIGN.md3
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py15
-rw-r--r--components/script/dom/bindings/conversions.rs51
-rw-r--r--components/script/dom/bindings/js.rs80
-rw-r--r--components/script/dom/bindings/mod.rs34
-rw-r--r--components/script/dom/canvasrenderingcontext2d.rs4
-rw-r--r--components/script/dom/document.rs4
-rw-r--r--components/script/dom/element.rs6
-rw-r--r--components/script/dom/htmlareaelement.rs12
-rw-r--r--components/script/dom/htmlcanvaselement.rs6
-rw-r--r--components/script/dom/htmlimageelement.rs4
-rw-r--r--components/script/dom/htmlinputelement.rs10
-rw-r--r--components/script/dom/htmltextareaelement.rs4
-rw-r--r--components/script/dom/keyboardevent.rs11
-rw-r--r--components/script/dom/mod.rs149
-rw-r--r--components/script/dom/node.rs40
16 files changed, 346 insertions, 87 deletions
diff --git a/components/script/dom/bindings/DESIGN.md b/components/script/dom/bindings/DESIGN.md
index e47d7467609..b97bac77e68 100644
--- a/components/script/dom/bindings/DESIGN.md
+++ b/components/script/dom/bindings/DESIGN.md
@@ -33,8 +33,9 @@ In the `_finalize()` function the pointer of the Rusty DOM object that is contai
For supporting SpiderMonkey’s exact GC rooting, we introduce [some types](https://github.com/mozilla/servo/wiki/Using-DOM-types):
- `JS<T>` is used for the DOM typed field in a DOM type structure. The GC can trace them recursively while the enclosing DOM object (maybe root) is alive.
+ - `LayoutJS<T>` is specialized `JS<T>` to use in layout. `Layout*Helper` must be implemented on this type to prevent calling methods from non layout code.
- `Temporary<T>` is used as a return value for functions returning a DOM type. They are rooted for the duration of their lifetime. But a retun value gets moved around which can break the LIFO ordering constraint. Thus we need to introduce `Root<T>`.
- `Root<T>` contains the pointer to `JSObject` which the represented DOM type has. SpiderMonkey's conservative stack scanner scans it's pointers and marks a pointed `JSObject` as GC root.
- `JSRef` is just a reference to the value rooted by `Root<T>`.
- `RootCollection` is used to dynamically check if rooting satisfies LIFO ordering, because SpiderMonkey's GC requires LIFO order (See also: [Exact Stack Rooting - Storing a GCPointer on the CStack](https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Internals/GC/Exact_Stack_Rooting)).
- - `MutHeap<T>` is a version of `Cell<T>` that is safe to use for internal mutability of Spidermonkey heap objects like `JSVal` and `JS<T>` \ No newline at end of file
+ - `MutHeap<T>` is a version of `Cell<T>` that is safe to use for internal mutability of Spidermonkey heap objects like `JSVal` and `JS<T>`
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 795204466df..a7f73e67494 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -3016,7 +3016,7 @@ class CGUnionConversionStruct(CGThing):
post="\n}")
return CGWrapper(
CGIndenter(method),
- pre="impl FromJSValConvertible<()> for %s {\n" % self.type,
+ pre="impl FromJSValConvertible for %s {\ntype Config = ();\n" % self.type,
post="\n}")
def try_method(self, t):
@@ -5220,7 +5220,7 @@ class GlobalGenRoots():
descriptors = config.getDescriptors(register=True, isCallback=False)
allprotos = [CGGeneric("#![allow(unused_imports)]\n"),
CGGeneric("use dom::types::*;\n"),
- CGGeneric("use dom::bindings::js::{JS, JSRef, Temporary};\n"),
+ CGGeneric("use dom::bindings::js::{JS, JSRef, LayoutJS, Temporary};\n"),
CGGeneric("use dom::bindings::trace::JSTraceable;\n"),
CGGeneric("use dom::bindings::utils::Reflectable;\n"),
CGGeneric("use js::jsapi::JSTracer;\n\n"),
@@ -5280,6 +5280,17 @@ pub trait ${castTraitName} : Sized {
}
#[inline(always)]
+ #[allow(unrooted_must_root)]
+ fn to_layout_js<T: ${toBound}+Reflectable>(base: &LayoutJS<T>) -> Option<LayoutJS<Self>> {
+ unsafe {
+ match (*base.unsafe_get()).${checkFn}() {
+ true => Some(base.transmute_copy()),
+ false => None
+ }
+ }
+ }
+
+ #[inline(always)]
fn from_ref<'a, T: ${fromBound}+Reflectable>(derived: JSRef<'a, T>) -> JSRef<'a, Self> {
unsafe { derived.transmute() }
}
diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs
index bf805a35fbf..d7182f8993f 100644
--- a/components/script/dom/bindings/conversions.rs
+++ b/components/script/dom/bindings/conversions.rs
@@ -49,12 +49,13 @@ pub trait ToJSValConvertible {
}
/// A trait to convert `JSVal`s to Rust types.
-pub trait FromJSValConvertible<T> {
+pub trait FromJSValConvertible {
+ type Config;
/// Convert `val` to type `Self`.
/// Optional configuration of type `T` can be passed as the `option`
/// argument.
/// If it returns `Err(())`, a JSAPI exception is pending.
- fn from_jsval(cx: *mut JSContext, val: JSVal, option: T) -> Result<Self, ()>;
+ fn from_jsval(cx: *mut JSContext, val: JSVal, option: Self::Config) -> Result<Self, ()>;
}
@@ -92,7 +93,8 @@ impl ToJSValConvertible for bool {
}
}
-impl FromJSValConvertible<()> for bool {
+impl FromJSValConvertible for bool {
+ type Config = ();
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<bool, ()> {
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToBoolean) };
result.map(|b| b != 0)
@@ -105,7 +107,8 @@ impl ToJSValConvertible for i8 {
}
}
-impl FromJSValConvertible<()> for i8 {
+impl FromJSValConvertible for i8 {
+ type Config = ();
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<i8, ()> {
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) };
result.map(|v| v as i8)
@@ -118,7 +121,8 @@ impl ToJSValConvertible for u8 {
}
}
-impl FromJSValConvertible<()> for u8 {
+impl FromJSValConvertible for u8 {
+ type Config = ();
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<u8, ()> {
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) };
result.map(|v| v as u8)
@@ -131,7 +135,8 @@ impl ToJSValConvertible for i16 {
}
}
-impl FromJSValConvertible<()> for i16 {
+impl FromJSValConvertible for i16 {
+ type Config = ();
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<i16, ()> {
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) };
result.map(|v| v as i16)
@@ -144,7 +149,8 @@ impl ToJSValConvertible for u16 {
}
}
-impl FromJSValConvertible<()> for u16 {
+impl FromJSValConvertible for u16 {
+ type Config = ();
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<u16, ()> {
unsafe { convert_from_jsval(cx, val, JS_ValueToUint16) }
}
@@ -156,7 +162,8 @@ impl ToJSValConvertible for i32 {
}
}
-impl FromJSValConvertible<()> for i32 {
+impl FromJSValConvertible for i32 {
+ type Config = ();
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<i32, ()> {
unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) }
}
@@ -168,7 +175,8 @@ impl ToJSValConvertible for u32 {
}
}
-impl FromJSValConvertible<()> for u32 {
+impl FromJSValConvertible for u32 {
+ type Config = ();
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<u32, ()> {
unsafe { convert_from_jsval(cx, val, JS_ValueToECMAUint32) }
}
@@ -182,7 +190,8 @@ impl ToJSValConvertible for i64 {
}
}
-impl FromJSValConvertible<()> for i64 {
+impl FromJSValConvertible for i64 {
+ type Config = ();
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<i64, ()> {
unsafe { convert_from_jsval(cx, val, JS_ValueToInt64) }
}
@@ -196,7 +205,8 @@ impl ToJSValConvertible for u64 {
}
}
-impl FromJSValConvertible<()> for u64 {
+impl FromJSValConvertible for u64 {
+ type Config = ();
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<u64, ()> {
unsafe { convert_from_jsval(cx, val, JS_ValueToUint64) }
}
@@ -210,7 +220,8 @@ impl ToJSValConvertible for f32 {
}
}
-impl FromJSValConvertible<()> for f32 {
+impl FromJSValConvertible for f32 {
+ type Config = ();
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<f32, ()> {
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToNumber) };
result.map(|f| f as f32)
@@ -225,7 +236,8 @@ impl ToJSValConvertible for f64 {
}
}
-impl FromJSValConvertible<()> for f64 {
+impl FromJSValConvertible for f64 {
+ type Config = ();
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<f64, ()> {
unsafe { convert_from_jsval(cx, val, JS_ValueToNumber) }
}
@@ -285,7 +297,8 @@ pub fn jsid_to_str(cx: *mut JSContext, id: jsid) -> DOMString {
}
}
-impl FromJSValConvertible<StringificationBehavior> for DOMString {
+impl FromJSValConvertible for DOMString {
+ type Config = StringificationBehavior;
fn from_jsval(cx: *mut JSContext, value: JSVal,
null_behavior: StringificationBehavior)
-> Result<DOMString, ()> {
@@ -317,7 +330,8 @@ impl ToJSValConvertible for ByteString {
}
}
-impl FromJSValConvertible<()> for ByteString {
+impl FromJSValConvertible for ByteString {
+ type Config = ();
fn from_jsval(cx: *mut JSContext, value: JSVal, _option: ()) -> Result<ByteString, ()> {
unsafe {
let string = JS_ValueToString(cx, value);
@@ -462,7 +476,8 @@ pub fn unwrap_jsmanaged<T>(mut obj: *mut JSObject) -> Result<JS<T>, ()>
}
}
-impl<T: Reflectable+IDLInterface> FromJSValConvertible<()> for JS<T> {
+impl<T: Reflectable+IDLInterface> FromJSValConvertible for JS<T> {
+ type Config = ();
fn from_jsval(_cx: *mut JSContext, value: JSVal, _option: ()) -> Result<JS<T>, ()> {
if !value.is_object() {
return Err(());
@@ -498,8 +513,8 @@ impl<T: ToJSValConvertible> ToJSValConvertible for Option<T> {
}
}
-#[old_impl_check]
-impl<X: default::Default, T: FromJSValConvertible<X>> FromJSValConvertible<()> for Option<T> {
+impl<X: default::Default, T: FromJSValConvertible<Config=X>> FromJSValConvertible for Option<T> {
+ type Config = ();
fn from_jsval(cx: *mut JSContext, value: JSVal, _: ()) -> Result<Option<T>, ()> {
if value.is_null_or_undefined() {
Ok(None)
diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs
index 3c9eba38911..f062eb8cf64 100644
--- a/components/script/dom/bindings/js.rs
+++ b/components/script/dom/bindings/js.rs
@@ -129,8 +129,32 @@ pub struct JS<T> {
ptr: NonZero<*const T>
}
+impl<T> JS<T> {
+ /// Returns `LayoutJS<T>` containing the same pointer.
+ fn to_layout(self) -> LayoutJS<T> {
+ LayoutJS {
+ ptr: self.ptr.clone()
+ }
+ }
+}
+
+/// This is specialized `JS<T>` to use in under `layout` crate.
+/// `Layout*Helpers` traits must be implemented on this.
+pub struct LayoutJS<T> {
+ ptr: NonZero<*const T>
+}
+
+impl<T: Reflectable> LayoutJS<T> {
+ /// Get the reflector.
+ pub unsafe fn get_jsobject(&self) -> *mut JSObject {
+ (**self.ptr).reflector().get_jsobject()
+ }
+}
+
impl<T> Copy for JS<T> {}
+impl<T> Copy for LayoutJS<T> {}
+
impl<T> PartialEq for JS<T> {
#[allow(unrooted_must_root)]
fn eq(&self, other: &JS<T>) -> bool {
@@ -138,6 +162,13 @@ impl<T> PartialEq for JS<T> {
}
}
+impl<T> PartialEq for LayoutJS<T> {
+ #[allow(unrooted_must_root)]
+ fn eq(&self, other: &LayoutJS<T>) -> bool {
+ self.ptr == other.ptr
+ }
+}
+
impl <T> Clone for JS<T> {
#[inline]
fn clone(&self) -> JS<T> {
@@ -147,6 +178,15 @@ impl <T> Clone for JS<T> {
}
}
+impl <T> Clone for LayoutJS<T> {
+ #[inline]
+ fn clone(&self) -> LayoutJS<T> {
+ LayoutJS {
+ ptr: self.ptr.clone()
+ }
+ }
+}
+
impl JS<Node> {
/// Create a new JS-owned value wrapped from an address known to be a `Node` pointer.
pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> JS<Node> {
@@ -158,6 +198,16 @@ impl JS<Node> {
}
}
+impl LayoutJS<Node> {
+ /// Create a new JS-owned value wrapped from an address known to be a `Node` pointer.
+ pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> LayoutJS<Node> {
+ let TrustedNodeAddress(addr) = inner;
+ LayoutJS {
+ ptr: NonZero::new(addr as *const Node)
+ }
+ }
+}
+
impl<T: Reflectable> JS<T> {
/// Create a new JS-owned value wrapped from a raw Rust pointer.
pub unsafe fn from_raw(raw: *const T) -> JS<T> {
@@ -296,6 +346,12 @@ impl<T: Reflectable> MutNullableJS<T> {
self.ptr.get()
}
+ /// Retrieve a copy of the inner optional `JS<T>` as `LayoutJS<T>`.
+ /// For use by layout, which can't use safe types like Temporary.
+ pub unsafe fn get_inner_as_layout(&self) -> Option<LayoutJS<T>> {
+ self.get_inner().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<F>(&self, cb: F) -> Temporary<T>
@@ -313,9 +369,8 @@ impl<T: Reflectable> MutNullableJS<T> {
}
impl<T: Reflectable> JS<T> {
- /// Returns an unsafe pointer to the interior of this object. This is the
- /// only method that be safely accessed from layout. (The fact that this is
- /// unsafe is what necessitates the layout wrappers.)
+ /// Returns an unsafe pointer to the interior of this object.
+ /// This should only be used by the DOM bindings.
pub unsafe fn unsafe_get(&self) -> *const T {
*self.ptr
}
@@ -328,19 +383,28 @@ impl<T: Reflectable> JS<T> {
}
}
-impl<From> JS<From> {
- /// Return `self` as a `JS` of another type.
- //XXXjdm It would be lovely if this could be private.
- pub unsafe fn transmute<To>(self) -> JS<To> {
- mem::transmute(self)
+impl<T: Reflectable> LayoutJS<T> {
+ /// Returns an unsafe pointer to the interior of this JS object without touching the borrow
+ /// flags. This is the only method that be safely accessed from layout. (The fact that this
+ /// is unsafe is what necessitates the layout wrappers.)
+ pub unsafe fn unsafe_get(&self) -> *const T {
+ *self.ptr
}
+}
+impl<From> JS<From> {
/// Return `self` as a `JS` of another type.
pub unsafe fn transmute_copy<To>(&self) -> JS<To> {
mem::transmute_copy(self)
}
}
+impl<From> LayoutJS<From> {
+ /// Return `self` as a `LayoutJS` of another type.
+ pub unsafe fn transmute_copy<To>(&self) -> LayoutJS<To> {
+ mem::transmute_copy(self)
+ }
+}
/// Get an `Option<JSRef<T>>` out of an `Option<Root<T>>`
pub trait RootedReference<T> {
diff --git a/components/script/dom/bindings/mod.rs b/components/script/dom/bindings/mod.rs
new file mode 100644
index 00000000000..54d564965e2
--- /dev/null
+++ b/components/script/dom/bindings/mod.rs
@@ -0,0 +1,34 @@
+/* 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/. */
+
+//! The code to expose the DOM to JavaScript through IDL bindings.
+
+#![allow(unsafe_blocks)]
+#![deny(missing_docs, non_snake_case)]
+
+pub mod cell;
+pub mod global;
+pub mod js;
+pub mod refcounted;
+pub mod utils;
+pub mod callback;
+pub mod error;
+pub mod conversions;
+pub mod proxyhandler;
+pub mod str;
+pub mod structuredclone;
+pub mod trace;
+
+/// Generated JS-Rust bindings.
+#[allow(missing_docs, non_snake_case)]
+pub mod codegen {
+ #[allow(unrooted_must_root)]
+ pub mod Bindings;
+ pub mod InterfaceTypes;
+ pub mod InheritTypes;
+ pub mod PrototypeList;
+ pub mod RegisterBindings;
+ pub mod UnionTypes;
+}
+
diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs
index a1eb1af9997..c157714b742 100644
--- a/components/script/dom/canvasrenderingcontext2d.rs
+++ b/components/script/dom/canvasrenderingcontext2d.rs
@@ -5,7 +5,7 @@
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding;
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRenderingContext2DMethods;
use dom::bindings::global::{GlobalRef, GlobalField};
-use dom::bindings::js::{JS, JSRef, Temporary};
+use dom::bindings::js::{JS, JSRef, LayoutJS, Temporary};
use dom::bindings::utils::{Reflector, reflect_dom_object};
use dom::htmlcanvaselement::HTMLCanvasElement;
@@ -50,7 +50,7 @@ pub trait LayoutCanvasRenderingContext2DHelpers {
unsafe fn get_renderer(&self) -> Sender<CanvasMsg>;
}
-impl LayoutCanvasRenderingContext2DHelpers for JS<CanvasRenderingContext2D> {
+impl LayoutCanvasRenderingContext2DHelpers for LayoutJS<CanvasRenderingContext2D> {
unsafe fn get_renderer(&self) -> Sender<CanvasMsg> {
(*self.unsafe_get()).renderer.clone()
}
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index d2775d3e5aa..859720a28fc 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -23,7 +23,7 @@ use dom::bindings::error::{ErrorResult, Fallible};
use dom::bindings::error::Error::{NotSupported, InvalidCharacter};
use dom::bindings::error::Error::{HierarchyRequest, NamespaceError};
use dom::bindings::global::GlobalRef;
-use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary, TemporaryPushable};
+use dom::bindings::js::{MutNullableJS, JS, JSRef, LayoutJS, Temporary, TemporaryPushable};
use dom::bindings::js::{OptionalRootable, RootedReference};
use dom::bindings::utils::reflect_dom_object;
use dom::bindings::utils::xml_name_type;
@@ -395,7 +395,7 @@ pub trait LayoutDocumentHelpers {
unsafe fn is_html_document_for_layout(&self) -> bool;
}
-impl LayoutDocumentHelpers for JS<Document> {
+impl LayoutDocumentHelpers for LayoutJS<Document> {
#[allow(unrooted_must_root)]
#[inline]
unsafe fn is_html_document_for_layout(&self) -> bool {
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index 9b74c0cb5c9..943e4139dde 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -23,7 +23,7 @@ use dom::bindings::codegen::InheritTypes::{HTMLTableRowElementDerived, HTMLTextA
use dom::bindings::codegen::InheritTypes::{HTMLTableSectionElementDerived, NodeCast};
use dom::bindings::error::{ErrorResult, Fallible};
use dom::bindings::error::Error::{NamespaceError, InvalidCharacter, Syntax};
-use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary, TemporaryPushable};
+use dom::bindings::js::{MutNullableJS, JS, JSRef, LayoutJS, Temporary, TemporaryPushable};
use dom::bindings::js::{OptionalRootable, Root};
use dom::bindings::utils::xml_name_type;
use dom::bindings::utils::XMLName::{QName, Name, InvalidXMLName};
@@ -376,13 +376,13 @@ pub trait LayoutElementHelpers {
unsafe fn has_attr_for_layout(&self, namespace: &Namespace, name: &Atom) -> bool;
}
-impl LayoutElementHelpers for JS<Element> {
+impl LayoutElementHelpers for LayoutJS<Element> {
#[inline]
unsafe fn html_element_in_html_document_for_layout(&self) -> bool {
if (*self.unsafe_get()).namespace != ns!(HTML) {
return false
}
- let node: JS<Node> = self.transmute_copy();
+ let node: LayoutJS<Node> = self.transmute_copy();
node.owner_doc_for_layout().is_html_document_for_layout()
}
diff --git a/components/script/dom/htmlareaelement.rs b/components/script/dom/htmlareaelement.rs
index 85ccb270cca..0a88f6153a8 100644
--- a/components/script/dom/htmlareaelement.rs
+++ b/components/script/dom/htmlareaelement.rs
@@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::HTMLAreaElementBinding::HTMLAreaElementMet
use dom::bindings::codegen::InheritTypes::{HTMLAreaElementDerived, HTMLElementCast};
use dom::bindings::codegen::InheritTypes::ElementCast;
use dom::bindings::js::{MutNullableJS, JSRef, Temporary};
-use dom::bindings::utils::{Reflectable, Reflector};
+use dom::bindings::utils::Reflectable;
use dom::document::Document;
use dom::domtokenlist::DOMTokenList;
use dom::element::ElementTypeId;
@@ -21,9 +21,7 @@ use std::default::Default;
use string_cache::Atom;
use util::str::DOMString;
-#[jstraceable]
-#[must_root]
-#[privatize]
+#[dom_struct]
pub struct HTMLAreaElement {
htmlelement: HTMLElement,
rel_list: MutNullableJS<DOMTokenList>,
@@ -64,12 +62,6 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLAreaElement> {
}
}
-impl Reflectable for HTMLAreaElement {
- fn reflector<'a>(&'a self) -> &'a Reflector {
- self.htmlelement.reflector()
- }
-}
-
impl<'a> HTMLAreaElementMethods for JSRef<'a, HTMLAreaElement> {
fn RelList(self) -> Temporary<DOMTokenList> {
self.rel_list.or_init(|| {
diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs
index a9606caf923..60ff0f88f82 100644
--- a/components/script/dom/htmlcanvaselement.rs
+++ b/components/script/dom/htmlcanvaselement.rs
@@ -10,7 +10,7 @@ use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElemen
use dom::bindings::codegen::InheritTypes::HTMLCanvasElementDerived;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast};
use dom::bindings::global::GlobalRef;
-use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary};
+use dom::bindings::js::{MutNullableJS, JSRef, LayoutJS, Temporary};
use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers};
use dom::document::Document;
use dom::element::{Element, AttributeHandlers};
@@ -68,9 +68,9 @@ pub trait LayoutHTMLCanvasElementHelpers {
unsafe fn get_canvas_height(&self) -> u32;
}
-impl LayoutHTMLCanvasElementHelpers for JS<HTMLCanvasElement> {
+impl LayoutHTMLCanvasElementHelpers for LayoutJS<HTMLCanvasElement> {
unsafe fn get_renderer(&self) -> Option<Sender<CanvasMsg>> {
- let context = (*self.unsafe_get()).context.get_inner();
+ let context = (*self.unsafe_get()).context.get_inner_as_layout();
context.map(|cx| cx.get_renderer())
}
diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs
index c555e5c50e4..913f69c0553 100644
--- a/components/script/dom/htmlimageelement.rs
+++ b/components/script/dom/htmlimageelement.rs
@@ -8,7 +8,7 @@ use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::HTMLImageElementBinding;
use dom::bindings::codegen::Bindings::HTMLImageElementBinding::HTMLImageElementMethods;
use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast, HTMLElementCast, HTMLImageElementDerived};
-use dom::bindings::js::{JS, JSRef, Temporary};
+use dom::bindings::js::{JSRef, LayoutJS, Temporary};
use dom::document::{Document, DocumentHelpers};
use dom::element::Element;
use dom::element::AttributeHandlers;
@@ -88,7 +88,7 @@ pub trait LayoutHTMLImageElementHelpers {
unsafe fn image(&self) -> Option<Url>;
}
-impl LayoutHTMLImageElementHelpers for JS<HTMLImageElement> {
+impl LayoutHTMLImageElementHelpers for LayoutJS<HTMLImageElement> {
unsafe fn image(&self) -> Option<Url> {
(*self.unsafe_get()).image.borrow_for_layout().clone()
}
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index e99bdaf3fcf..ede6ee71fb0 100644
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -15,7 +15,7 @@ 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, JS, JSRef, Root, Temporary, OptionalRootable};
+use dom::bindings::js::{Comparable, JSRef, LayoutJS, Root, Temporary, OptionalRootable};
use dom::bindings::js::{ResultRootable, RootedReference, MutNullableJS};
use dom::document::{Document, DocumentHelpers};
use dom::element::{AttributeHandlers, Element};
@@ -140,15 +140,15 @@ pub trait RawLayoutHTMLInputElementHelpers {
unsafe fn get_size_for_layout(&self) -> u32;
}
-impl LayoutHTMLInputElementHelpers for JS<HTMLInputElement> {
+impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> {
#[allow(unrooted_must_root)]
unsafe fn get_value_for_layout(self) -> String {
- unsafe fn get_raw_textinput_value(input: JS<HTMLInputElement>) -> String {
+ unsafe fn get_raw_textinput_value(input: LayoutJS<HTMLInputElement>) -> String {
(*input.unsafe_get()).textinput.borrow_for_layout().get_content()
}
- unsafe fn get_raw_attr_value(input: JS<HTMLInputElement>) -> Option<String> {
- let elem: JS<Element> = input.transmute_copy();
+ unsafe fn get_raw_attr_value(input: LayoutJS<HTMLInputElement>) -> Option<String> {
+ let elem: LayoutJS<Element> = input.transmute_copy();
(*elem.unsafe_get()).get_attr_val_for_layout(&ns!(""), &atom!("value"))
.map(|s| s.to_owned())
}
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs
index ed6a8c8f06a..7196b4ff891 100644
--- a/components/script/dom/htmltextareaelement.rs
+++ b/components/script/dom/htmltextareaelement.rs
@@ -12,7 +12,7 @@ use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{HTMLTextAreaElementDerived, HTMLFieldSetElementDerived};
use dom::bindings::codegen::InheritTypes::{KeyboardEventCast, TextDerived};
-use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootable};
+use dom::bindings::js::{JSRef, LayoutJS, Temporary, OptionalRootable};
use dom::document::{Document, DocumentHelpers};
use dom::element::{Element, AttributeHandlers};
use dom::event::Event;
@@ -58,7 +58,7 @@ pub trait RawLayoutHTMLTextAreaElementHelpers {
unsafe fn get_rows_for_layout(&self) -> u32;
}
-impl LayoutHTMLTextAreaElementHelpers for JS<HTMLTextAreaElement> {
+impl LayoutHTMLTextAreaElementHelpers for LayoutJS<HTMLTextAreaElement> {
#[allow(unrooted_must_root)]
unsafe fn get_value_for_layout(self) -> String {
(*self.unsafe_get()).textinput.borrow_for_layout().get_content()
diff --git a/components/script/dom/keyboardevent.rs b/components/script/dom/keyboardevent.rs
index 7cd1c4b9e98..f220f90a36a 100644
--- a/components/script/dom/keyboardevent.rs
+++ b/components/script/dom/keyboardevent.rs
@@ -9,7 +9,7 @@ use dom::bindings::codegen::InheritTypes::{EventCast, UIEventCast, KeyboardEvent
use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JSRef, Temporary, RootedReference};
-use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
+use dom::bindings::utils::{Reflectable, reflect_dom_object};
use dom::event::{Event, EventTypeId};
use dom::uievent::UIEvent;
use dom::window::Window;
@@ -19,8 +19,7 @@ use util::str::DOMString;
use std::borrow::ToOwned;
use std::cell::{RefCell, Cell};
-#[jstraceable]
-#[must_root]
+#[dom_struct]
pub struct KeyboardEvent {
uievent: UIEvent,
key: RefCell<DOMString>,
@@ -632,9 +631,3 @@ impl<'a> KeyboardEventMethods for JSRef<'a, KeyboardEvent> {
self.char_code.get().unwrap_or(self.KeyCode())
}
}
-
-impl Reflectable for KeyboardEvent {
- fn reflector<'a>(&'a self) -> &'a Reflector {
- self.uievent.reflector()
- }
-}
diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs
new file mode 100644
index 00000000000..4e58f87942e
--- /dev/null
+++ b/components/script/dom/mod.rs
@@ -0,0 +1,149 @@
+/* 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/. */
+
+//! The implementation of the DOM.
+
+#[macro_use]
+pub mod macros;
+
+pub mod bindings;
+
+#[path="bindings/codegen/InterfaceTypes.rs"]
+pub mod types;
+
+pub mod activation;
+pub mod attr;
+pub mod blob;
+pub mod browsercontext;
+pub mod canvasrenderingcontext2d;
+pub mod characterdata;
+pub mod cssstyledeclaration;
+pub mod domrect;
+pub mod domrectlist;
+pub mod domstringmap;
+pub mod comment;
+pub mod console;
+mod create;
+pub mod customevent;
+pub mod dedicatedworkerglobalscope;
+pub mod document;
+pub mod documentfragment;
+pub mod documenttype;
+pub mod domexception;
+pub mod domimplementation;
+pub mod domparser;
+pub mod domtokenlist;
+pub mod element;
+pub mod errorevent;
+pub mod event;
+pub mod eventdispatcher;
+pub mod eventtarget;
+pub mod file;
+pub mod formdata;
+pub mod htmlanchorelement;
+pub mod htmlappletelement;
+pub mod htmlareaelement;
+pub mod htmlaudioelement;
+pub mod htmlbaseelement;
+pub mod htmlbodyelement;
+pub mod htmlbrelement;
+pub mod htmlbuttonelement;
+pub mod htmlcanvaselement;
+pub mod htmlcollection;
+pub mod htmldataelement;
+pub mod htmldatalistelement;
+pub mod htmldirectoryelement;
+pub mod htmldivelement;
+pub mod htmldlistelement;
+pub mod htmlelement;
+pub mod htmlembedelement;
+pub mod htmlfieldsetelement;
+pub mod htmlfontelement;
+pub mod htmlformelement;
+pub mod htmlframeelement;
+pub mod htmlframesetelement;
+pub mod htmlheadelement;
+pub mod htmlheadingelement;
+pub mod htmlhrelement;
+pub mod htmlhtmlelement;
+pub mod htmliframeelement;
+pub mod htmlimageelement;
+pub mod htmlinputelement;
+pub mod htmllabelelement;
+pub mod htmllegendelement;
+pub mod htmllielement;
+pub mod htmllinkelement;
+pub mod htmlmapelement;
+pub mod htmlmediaelement;
+pub mod htmlmetaelement;
+pub mod htmlmeterelement;
+pub mod htmlmodelement;
+pub mod htmlobjectelement;
+pub mod htmlolistelement;
+pub mod htmloptgroupelement;
+pub mod htmloptionelement;
+pub mod htmloutputelement;
+pub mod htmlparagraphelement;
+pub mod htmlparamelement;
+pub mod htmlpreelement;
+pub mod htmlprogresselement;
+pub mod htmlquoteelement;
+pub mod htmlscriptelement;
+pub mod htmlselectelement;
+pub mod htmlserializer;
+pub mod htmlspanelement;
+pub mod htmlsourceelement;
+pub mod htmlstyleelement;
+pub mod htmltableelement;
+pub mod htmltablecaptionelement;
+pub mod htmltablecellelement;
+pub mod htmltabledatacellelement;
+pub mod htmltableheadercellelement;
+pub mod htmltablecolelement;
+pub mod htmltablerowelement;
+pub mod htmltablesectionelement;
+pub mod htmltemplateelement;
+pub mod htmltextareaelement;
+pub mod htmltimeelement;
+pub mod htmltitleelement;
+pub mod htmltrackelement;
+pub mod htmlulistelement;
+pub mod htmlvideoelement;
+pub mod htmlunknownelement;
+pub mod keyboardevent;
+pub mod location;
+pub mod messageevent;
+pub mod mouseevent;
+pub mod namednodemap;
+pub mod navigator;
+pub mod navigatorinfo;
+pub mod node;
+pub mod nodeiterator;
+pub mod nodelist;
+pub mod processinginstruction;
+pub mod performance;
+pub mod performancetiming;
+pub mod progressevent;
+pub mod range;
+pub mod screen;
+pub mod servohtmlparser;
+pub mod storage;
+pub mod text;
+pub mod treewalker;
+pub mod uievent;
+pub mod urlhelper;
+pub mod urlsearchparams;
+pub mod validitystate;
+pub mod virtualmethods;
+pub mod websocket;
+pub mod window;
+pub mod worker;
+pub mod workerglobalscope;
+pub mod workerlocation;
+pub mod workernavigator;
+pub mod xmlhttprequest;
+pub mod xmlhttprequesteventtarget;
+pub mod xmlhttprequestupload;
+
+pub mod testbinding;
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index 38b6846193c..745c5a3a135 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -23,7 +23,7 @@ use dom::bindings::conversions;
use dom::bindings::error::Fallible;
use dom::bindings::error::Error::{NotFound, HierarchyRequest, Syntax};
use dom::bindings::global::GlobalRef;
-use dom::bindings::js::{JS, JSRef, RootedReference, Temporary, Root};
+use dom::bindings::js::{JS, JSRef, LayoutJS, RootedReference, Temporary, Root};
use dom::bindings::js::{TemporaryPushable, OptionalRootedRootable};
use dom::bindings::js::{ResultRootable, OptionalRootable, MutNullableJS};
use dom::bindings::trace::JSTraceable;
@@ -914,20 +914,20 @@ pub fn from_untrusted_node_address(runtime: *mut JSRuntime, candidate: Untrusted
pub trait LayoutNodeHelpers {
unsafe fn type_id_for_layout(&self) -> NodeTypeId;
- unsafe fn parent_node_ref(&self) -> Option<JS<Node>>;
- unsafe fn first_child_ref(&self) -> Option<JS<Node>>;
- unsafe fn last_child_ref(&self) -> Option<JS<Node>>;
- unsafe fn prev_sibling_ref(&self) -> Option<JS<Node>>;
- unsafe fn next_sibling_ref(&self) -> Option<JS<Node>>;
+ unsafe fn parent_node_ref(&self) -> Option<LayoutJS<Node>>;
+ unsafe fn first_child_ref(&self) -> Option<LayoutJS<Node>>;
+ unsafe fn last_child_ref(&self) -> Option<LayoutJS<Node>>;
+ unsafe fn prev_sibling_ref(&self) -> Option<LayoutJS<Node>>;
+ unsafe fn next_sibling_ref(&self) -> Option<LayoutJS<Node>>;
- unsafe fn owner_doc_for_layout(&self) -> JS<Document>;
+ unsafe fn owner_doc_for_layout(&self) -> LayoutJS<Document>;
unsafe fn is_element_for_layout(&self) -> bool;
unsafe fn get_flag(self, flag: NodeFlags) -> bool;
unsafe fn set_flag(self, flag: NodeFlags, value: bool);
}
-impl LayoutNodeHelpers for JS<Node> {
+impl LayoutNodeHelpers for LayoutJS<Node> {
#[inline]
unsafe fn type_id_for_layout(&self) -> NodeTypeId {
(*self.unsafe_get()).type_id
@@ -939,33 +939,33 @@ impl LayoutNodeHelpers for JS<Node> {
}
#[inline]
- unsafe fn parent_node_ref(&self) -> Option<JS<Node>> {
- (*self.unsafe_get()).parent_node.get_inner()
+ unsafe fn parent_node_ref(&self) -> Option<LayoutJS<Node>> {
+ (*self.unsafe_get()).parent_node.get_inner_as_layout()
}
#[inline]
- unsafe fn first_child_ref(&self) -> Option<JS<Node>> {
- (*self.unsafe_get()).first_child.get_inner()
+ unsafe fn first_child_ref(&self) -> Option<LayoutJS<Node>> {
+ (*self.unsafe_get()).first_child.get_inner_as_layout()
}
#[inline]
- unsafe fn last_child_ref(&self) -> Option<JS<Node>> {
- (*self.unsafe_get()).last_child.get_inner()
+ unsafe fn last_child_ref(&self) -> Option<LayoutJS<Node>> {
+ (*self.unsafe_get()).last_child.get_inner_as_layout()
}
#[inline]
- unsafe fn prev_sibling_ref(&self) -> Option<JS<Node>> {
- (*self.unsafe_get()).prev_sibling.get_inner()
+ unsafe fn prev_sibling_ref(&self) -> Option<LayoutJS<Node>> {
+ (*self.unsafe_get()).prev_sibling.get_inner_as_layout()
}
#[inline]
- unsafe fn next_sibling_ref(&self) -> Option<JS<Node>> {
- (*self.unsafe_get()).next_sibling.get_inner()
+ unsafe fn next_sibling_ref(&self) -> Option<LayoutJS<Node>> {
+ (*self.unsafe_get()).next_sibling.get_inner_as_layout()
}
#[inline]
- unsafe fn owner_doc_for_layout(&self) -> JS<Document> {
- (*self.unsafe_get()).owner_doc.get_inner().unwrap()
+ unsafe fn owner_doc_for_layout(&self) -> LayoutJS<Document> {
+ (*self.unsafe_get()).owner_doc.get_inner_as_layout().unwrap()
}
#[inline]