From ffdc3f5b32a345b88eed774848924e862d47c093 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Fri, 28 Mar 2014 10:17:56 -0400 Subject: [PATCH 01/16] Turn on GC all the time. Fix rooting errors during parsing and storing timers. Fix borrow errors during tracing. --- configure | 1 + src/components/script/dom/attr.rs | 4 +- src/components/script/dom/attrlist.rs | 6 +- .../dom/bindings/codegen/CodegenRust.py | 104 ++-- .../script/dom/bindings/conversions.rs | 20 +- src/components/script/dom/bindings/js.rs | 224 +++++++- src/components/script/dom/bindings/trace.rs | 24 + src/components/script/dom/bindings/utils.rs | 27 +- src/components/script/dom/blob.rs | 12 +- src/components/script/dom/clientrect.rs | 6 +- src/components/script/dom/clientrectlist.rs | 6 +- src/components/script/dom/comment.rs | 14 +- src/components/script/dom/console.rs | 4 +- src/components/script/dom/document.rs | 229 +++++---- src/components/script/dom/documentfragment.rs | 24 +- src/components/script/dom/documenttype.rs | 6 +- src/components/script/dom/domexception.rs | 4 +- .../script/dom/domimplementation.rs | 68 ++- src/components/script/dom/domparser.rs | 14 +- src/components/script/dom/element.rs | 134 +++-- src/components/script/dom/event.rs | 6 +- src/components/script/dom/eventdispatcher.rs | 18 +- src/components/script/dom/eventtarget.rs | 12 +- src/components/script/dom/formdata.rs | 16 +- .../script/dom/htmlanchorelement.rs | 6 +- .../script/dom/htmlappletelement.rs | 6 +- src/components/script/dom/htmlareaelement.rs | 6 +- src/components/script/dom/htmlaudioelement.rs | 6 +- src/components/script/dom/htmlbaseelement.rs | 6 +- src/components/script/dom/htmlbodyelement.rs | 6 +- src/components/script/dom/htmlbrelement.rs | 6 +- .../script/dom/htmlbuttonelement.rs | 9 +- .../script/dom/htmlcanvaselement.rs | 6 +- src/components/script/dom/htmlcollection.rs | 85 ++-- src/components/script/dom/htmldataelement.rs | 6 +- .../script/dom/htmldatalistelement.rs | 16 +- .../script/dom/htmldirectoryelement.rs | 6 +- src/components/script/dom/htmldivelement.rs | 6 +- src/components/script/dom/htmldlistelement.rs | 6 +- src/components/script/dom/htmlelement.rs | 6 +- src/components/script/dom/htmlembedelement.rs | 6 +- .../script/dom/htmlfieldsetelement.rs | 24 +- src/components/script/dom/htmlfontelement.rs | 6 +- src/components/script/dom/htmlformelement.rs | 10 +- src/components/script/dom/htmlframeelement.rs | 6 +- .../script/dom/htmlframesetelement.rs | 6 +- src/components/script/dom/htmlheadelement.rs | 6 +- .../script/dom/htmlheadingelement.rs | 6 +- src/components/script/dom/htmlhrelement.rs | 6 +- src/components/script/dom/htmlhtmlelement.rs | 6 +- .../script/dom/htmliframeelement.rs | 14 +- src/components/script/dom/htmlimageelement.rs | 102 ++-- src/components/script/dom/htmlinputelement.rs | 6 +- src/components/script/dom/htmllabelelement.rs | 6 +- .../script/dom/htmllegendelement.rs | 6 +- src/components/script/dom/htmllielement.rs | 6 +- src/components/script/dom/htmllinkelement.rs | 6 +- src/components/script/dom/htmlmainelement.rs | 6 +- src/components/script/dom/htmlmapelement.rs | 10 +- src/components/script/dom/htmlmetaelement.rs | 6 +- src/components/script/dom/htmlmeterelement.rs | 6 +- src/components/script/dom/htmlmodelement.rs | 6 +- .../script/dom/htmlobjectelement.rs | 10 +- src/components/script/dom/htmlolistelement.rs | 6 +- .../script/dom/htmloptgroupelement.rs | 6 +- .../script/dom/htmloptionelement.rs | 6 +- .../script/dom/htmloutputelement.rs | 10 +- .../script/dom/htmlparagraphelement.rs | 6 +- src/components/script/dom/htmlparamelement.rs | 6 +- src/components/script/dom/htmlpreelement.rs | 6 +- .../script/dom/htmlprogresselement.rs | 6 +- src/components/script/dom/htmlquoteelement.rs | 6 +- .../script/dom/htmlscriptelement.rs | 12 +- .../script/dom/htmlselectelement.rs | 12 +- src/components/script/dom/htmlserializer.rs | 34 +- .../script/dom/htmlsourceelement.rs | 6 +- src/components/script/dom/htmlspanelement.rs | 6 +- src/components/script/dom/htmlstyleelement.rs | 10 +- .../script/dom/htmltablecaptionelement.rs | 6 +- .../script/dom/htmltablecolelement.rs | 6 +- .../script/dom/htmltabledatacellelement.rs | 6 +- src/components/script/dom/htmltableelement.rs | 6 +- .../script/dom/htmltableheadercellelement.rs | 6 +- .../script/dom/htmltablerowelement.rs | 6 +- .../script/dom/htmltablesectionelement.rs | 6 +- .../script/dom/htmltemplateelement.rs | 6 +- .../script/dom/htmltextareaelement.rs | 6 +- src/components/script/dom/htmltimeelement.rs | 6 +- src/components/script/dom/htmltitleelement.rs | 6 +- src/components/script/dom/htmltrackelement.rs | 6 +- src/components/script/dom/htmlulistelement.rs | 6 +- .../script/dom/htmlunknownelement.rs | 6 +- src/components/script/dom/htmlvideoelement.rs | 6 +- src/components/script/dom/location.rs | 4 +- src/components/script/dom/mouseevent.rs | 19 +- src/components/script/dom/navigator.rs | 4 +- src/components/script/dom/node.rs | 481 +++++++++++------- src/components/script/dom/nodelist.rs | 12 +- .../script/dom/processinginstruction.rs | 6 +- src/components/script/dom/testbinding.rs | 26 +- src/components/script/dom/text.rs | 13 +- src/components/script/dom/uievent.rs | 14 +- src/components/script/dom/validitystate.rs | 6 +- .../script/dom/webidls/TestBinding.webidl | 2 +- src/components/script/dom/window.rs | 77 ++- src/components/script/dom/xmlhttprequest.rs | 8 +- .../script/dom/xmlhttprequestupload.rs | 4 +- .../script/html/hubbub_html_parser.rs | 43 +- src/components/script/script_task.rs | 173 ++++--- 109 files changed, 1567 insertions(+), 996 deletions(-) diff --git a/configure b/configure index d0a8d806d5a..bf3c739c6ea 100755 --- a/configure +++ b/configure @@ -697,6 +697,7 @@ do CONFIGURE_ARGS="${CONFIGURE_ARGS} --with-android-ndk=${CFG_ANDROID_NDK_PATH}" CONFIGURE_ARGS="${CONFIGURE_ARGS} --with-android-toolchain=${CFG_ANDROID_CROSS_PATH}" fi + CONFIGURE_ARGS="${CONFIGURE_ARGS} --enable-gczeal" ;; support/skia/skia) # Right now the skia configure script actually ignores --enable-debug and the diff --git a/src/components/script/dom/attr.rs b/src/components/script/dom/attr.rs index 0ca2fb2889e..5b5fc39d1c9 100644 --- a/src/components/script/dom/attr.rs +++ b/src/components/script/dom/attr.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::AttrBinding; use dom::bindings::codegen::InheritTypes::NodeCast; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::element::Element; use dom::node::Node; @@ -57,7 +57,7 @@ impl Attr { } } - pub fn new(window: &JS, local_name: DOMString, value: DOMString, + pub fn new(window: &JSRef, local_name: DOMString, value: DOMString, name: DOMString, namespace: Namespace, prefix: Option, owner: JS) -> JS { let attr = Attr::new_inherited(local_name, value, name, namespace, prefix, owner); diff --git a/src/components/script/dom/attrlist.rs b/src/components/script/dom/attrlist.rs index cfa6c2c083f..ed476897c82 100644 --- a/src/components/script/dom/attrlist.rs +++ b/src/components/script/dom/attrlist.rs @@ -4,7 +4,7 @@ use dom::attr::Attr; use dom::bindings::codegen::BindingDeclarations::AttrListBinding; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::element::Element; use dom::window::Window; @@ -25,8 +25,8 @@ impl AttrList { } } - pub fn new(window: &JS, elem: &JS) -> JS { - reflect_dom_object(~AttrList::new_inherited(window.clone(), elem.clone()), + pub fn new(window: &JSRef, elem: &JSRef) -> JS { + reflect_dom_object(~AttrList::new_inherited(window.unrooted(), elem.unrooted()), window, AttrListBinding::Wrap) } diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index cb3fc862c64..5d4f6cc9bf4 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -281,6 +281,7 @@ class CGMethodCall(CGThing): isDefinitelyObject=True), { "declName" : "arg%d" % distinguishingIndex, + "simpleDeclName" : "arg%d" % distinguishingIndex, "holderName" : ("arg%d" % distinguishingIndex) + "_holder", "val" : distinguishingArg }) @@ -551,12 +552,21 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, templateBody += ( "} else {\n" + CGIndenter(onFailureNotAnObject(failureCode)).define() + - "}") + "}\n") if type.nullable(): templateBody = handleDefaultNull(templateBody, "None") else: assert(defaultValue is None) + #if type.isGeckoInterface() and not type.unroll().inner.isCallback(): + # if type.nullable() or isOptional: + # + # else: + # + # templateBody = CGList([CGGeneric(templateBody), + # CGGeneric("\n"), + # CGGeneric(rootBody)]).define() + return templateBody assert not (isEnforceRange and isClamp) # These are mutually exclusive @@ -888,6 +898,18 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements, # Add an empty CGGeneric to get an extra newline after the argument # conversion. result.append(CGGeneric("")) + + type = declType.define() if declType else None + if type and 'JS<' in type: + if dealWithOptional or 'Option<' in type: + rootBody = """let ${simpleDeclName} = ${declName}.as_ref().map(|inner| { + inner.root(&roots) //second root code +});""" + else: + rootBody = "let ${simpleDeclName} = ${declName}.root(&roots); //third root code" + result.append(CGGeneric(string.Template(rootBody).substitute(replacements))) + result.append(CGGeneric("")) + return result; def convertConstIDLValueToJSVal(value): @@ -929,6 +951,7 @@ class CGArgumentConverter(CGThing): } self.replacementVariables = { "declName" : "arg%d" % index, + "simpleDeclName" : "arg%d" % index, "holderName" : ("arg%d" % index) + "_holder" } self.replacementVariables["val"] = string.Template( @@ -1691,6 +1714,8 @@ class Argument(): A class for outputting the type and name of an argument """ def __init__(self, argType, name, default=None, mutable=False): + if argType and 'JS<' in argType: + argType = argType.replace('JS<', 'JSRef<') self.argType = argType self.name = name self.default = default @@ -1763,7 +1788,7 @@ class CGAbstractMethod(CGThing): def _returnType(self): return (" -> %s" % self.returnType) if self.returnType != "void" else "" def _unsafe_open(self): - return "\n unsafe {" if self.unsafe else "" + return "\n unsafe {\n let roots = RootCollection::new();\n" if self.unsafe else "" def _unsafe_close(self): return "\n }\n" if self.unsafe else "" @@ -1809,7 +1834,7 @@ class CGWrapMethod(CGAbstractMethod): def __init__(self, descriptor): assert descriptor.interface.hasInterfacePrototypeObject() if not descriptor.createGlobal: - args = [Argument('*JSContext', 'aCx'), Argument('&JS', 'aScope'), + args = [Argument('*JSContext', 'aCx'), Argument('&JSRef', 'aScope'), Argument("~" + descriptor.concreteType, 'aObject', mutable=True)] else: args = [Argument('*JSContext', 'aCx'), @@ -2277,7 +2302,12 @@ class CGPerSignatureCall(CGThing): def getArgc(self): return "argc" def getArguments(self): - return [(a, "arg" + str(i)) for (i, a) in enumerate(self.arguments)] + def process(arg, i): + argVal = "arg" + str(i) + if arg.type.isGeckoInterface() and not arg.type.unroll().inner.isCallback(): + argVal += ".root_ref()" + return argVal + return [(a, process(a, i)) for (i, a) in enumerate(self.arguments)] def isFallible(self): return not 'infallible' in self.extendedAttributes @@ -2452,8 +2482,10 @@ class CGSpecializedMethod(CGAbstractExternMethod): argsPre = [] if name in self.descriptor.needsAbstract: abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType) - extraPre = ' let mut abstract_this = %s::from_raw(this);\n' % abstractName - argsPre = ['&mut abstract_this'] + extraPre = """ let mut abstract_this = %s::from_raw(this); + let abstract_this = abstract_this.root(&roots); +""" % abstractName + argsPre = ['&mut abstract_this.root_ref()'] return CGWrapper(CGMethodCall(argsPre, nativeName, self.method.isStatic(), self.descriptor, self.method), pre=extraPre + @@ -2480,10 +2512,8 @@ class CGGenericGetter(CGAbstractBindingMethod): def generate_code(self): return CGIndenter(CGGeneric( - "return with_gc_disabled(cx, || {\n" - " let info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, &*vp));\n" - " CallJitPropertyOp(info, cx, obj, this.unsafe_get() as *libc::c_void, &*vp)\n" - "});\n")) + "let info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, &*vp));\n" + "return CallJitPropertyOp(info, cx, obj, this.unsafe_get() as *libc::c_void, &*vp);\n")) class CGSpecializedGetter(CGAbstractExternMethod): """ @@ -2509,8 +2539,10 @@ class CGSpecializedGetter(CGAbstractExternMethod): getter=True)) if name in self.descriptor.needsAbstract: abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType) - extraPre = ' let mut abstract_this = %s::from_raw(this);\n' % abstractName - argsPre = ['&mut abstract_this'] + extraPre = """ let mut abstract_this = %s::from_raw(this); + let abstract_this = abstract_this.root(&roots); +""" % abstractName + argsPre = ['&mut abstract_this.root_ref()'] if self.attr.type.nullable() or not infallible: nativeName = "Get" + nativeName return CGWrapper(CGIndenter(CGGetterCall(argsPre, self.attr.type, nativeName, @@ -2541,10 +2573,7 @@ class CGGenericSetter(CGAbstractBindingMethod): "let undef = UndefinedValue();\n" "let argv: *JSVal = if argc != 0 { JS_ARGV(cx, vp as *JSVal) } else { &undef as *JSVal };\n" "let info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp as *JSVal));\n" - "let ok = with_gc_disabled(cx, || {\n" - " CallJitPropertyOp(info, cx, obj, this.unsafe_get() as *libc::c_void, argv)\n" - "});\n" - "if ok == 0 {\n" + "if CallJitPropertyOp(info, cx, obj, this.unsafe_get() as *libc::c_void, argv) == 0 {\n" " return 0;\n" "}\n" "*vp = UndefinedValue();\n" @@ -2571,8 +2600,10 @@ class CGSpecializedSetter(CGAbstractExternMethod): extraPre = '' if name in self.descriptor.needsAbstract: abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType) - extraPre = ' let mut abstract_this = %s::from_raw(this);\n' % abstractName - argsPre = ['&mut abstract_this'] + extraPre = """ let mut abstract_this = %s::from_raw(this); + let abstract_this = abstract_this.root(&roots); +""" % abstractName + argsPre = ['&mut abstract_this.root_ref()'] return CGWrapper(CGIndenter(CGSetterCall(argsPre, self.attr.type, nativeName, self.descriptor, self.attr)), pre=extraPre + @@ -3402,6 +3433,7 @@ class CGProxySpecialOperation(CGPerSignatureCall): treatNullAs=argument.treatNullAs) templateValues = { "declName": argument.identifier.name, + "simpleDeclName": argument.identifier.name, "holderName": argument.identifier.name + "_holder", "val": "(*desc).value", "valPtr": "&(*desc).value" @@ -3411,7 +3443,12 @@ class CGProxySpecialOperation(CGPerSignatureCall): self.cgRoot.prepend(CGGeneric("let mut found = false;")) def getArguments(self): - args = [(a, a.identifier.name) for a in self.arguments] + def process(arg): + argVal = arg.identifier.name + if arg.type.isGeckoInterface() and not arg.type.unroll().inner.isCallback(): + argVal += ".root_ref()" + return argVal + args = [(a, process(a)) for a in self.arguments] if self.idlNode.isGetter(): args.append((FakeArgument(BuiltinTypes[IDLBuiltinType.Types.boolean], self.idlNode), @@ -3825,11 +3862,13 @@ class CGClassConstructHook(CGAbstractExternMethod): def generate_code(self): preamble = """ + let roots = RootCollection::new(); let global = global_object_for_js_object(JS_CALLEE(cx, &*vp).to_object()); + let global = global.root(&roots); let obj = global.reflector().get_jsobject(); """ nativeName = MakeNativeName(self._ctor.identifier.name) - callGenerator = CGMethodCall(["&global"], nativeName, True, + callGenerator = CGMethodCall(["&global.root_ref()"], nativeName, True, self.descriptor, self._ctor) return preamble + callGenerator.define(); @@ -4067,6 +4106,7 @@ class CGDictionary(CGThing): return string.Template( "impl ${selfName} {\n" " pub fn new(cx: *JSContext, val: JSVal) -> Result<${selfName}, ()> {\n" + " let roots = RootCollection::new();\n" # XXXjdm need to root dict members outside of Init " let object = if val.is_null_or_undefined() {\n" " ptr::null()\n" " } else if val.is_object() {\n" @@ -4266,7 +4306,7 @@ class CGBindingRoot(CGThing): 'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}', 'dom::types::*', 'dom::bindings', - 'dom::bindings::js::JS', + 'dom::bindings::js::{JS, JSRef, RootCollection, RootedReference}', 'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}', 'dom::bindings::utils::{ConstantSpec, cx_for_dom_object, Default}', 'dom::bindings::utils::{dom_object_slot, DOM_OBJECT_SLOT, DOMClass}', @@ -4279,8 +4319,7 @@ class CGBindingRoot(CGThing): 'dom::bindings::utils::{Reflectable}', 'dom::bindings::utils::{squirrel_away_unique}', 'dom::bindings::utils::{ThrowingConstructor, unwrap, unwrap_jsmanaged}', - 'dom::bindings::utils::{VoidVal, with_gc_disabled}', - 'dom::bindings::utils::{with_gc_enabled}', + 'dom::bindings::utils::VoidVal', 'dom::bindings::utils::get_dictionary_property', 'dom::bindings::trace::JSTraceable', 'dom::bindings::callback::{CallbackContainer,CallbackInterface}', @@ -5057,11 +5096,8 @@ class CallbackMethod(CallbackMember): replacements["argc"] = "0" return string.Template("${getCallable}" "let ok = unsafe {\n" - " //JS_AllowGC(cx); // It's unsafe to enable GC at arbitrary points during Rust execution; leave it disabled\n" - " let ok = JS_CallFunctionValue(cx, ${thisObj}, callable,\n" - " ${argc}, ${argv}, &rval);\n" - " //JS_InhibitGC(cx);\n" - " ok\n" + " JS_CallFunctionValue(cx, ${thisObj}, callable,\n" + " ${argc}, ${argv}, &rval)\n" "};\n" "if ok == 0 {\n" " return${errorReturn};\n" @@ -5209,7 +5245,7 @@ class GlobalGenRoots(): # TODO - Generate the methods we want return CGImports(CGRegisterProtos(config), [ 'dom::bindings::codegen', - 'dom::bindings::js::JS', + 'dom::bindings::js::{JS, JSRef}', 'dom::window::Window', 'script_task::JSPageInfo', ]) @@ -5241,7 +5277,7 @@ class GlobalGenRoots(): descriptors = config.getDescriptors(register=True, hasInterfaceObject=True) allprotos = [CGGeneric("#![allow(unused_imports)]\n"), CGGeneric("use dom::types::*;\n"), - CGGeneric("use dom::bindings::js::JS;\n"), + CGGeneric("use dom::bindings::js::{JS, JSRef};\n"), CGGeneric("use dom::bindings::trace::JSTraceable;\n"), CGGeneric("use serialize::{Encodable, Encoder};\n"), CGGeneric("use js::jsapi::JSTracer;\n\n")] @@ -5286,6 +5322,14 @@ class GlobalGenRoots(): assert!(base.get().${checkFn}()); base.clone().transmute() } + + fn from_ref<'a, 'b, T: ${fromBound}>(derived: &'a JSRef<'b, T>) -> &'a JSRef<'b, Self> { + unsafe { derived.transmute() } + } + + fn from_mut_ref<'a, 'b, T: ${fromBound}>(derived: &'a mut JSRef<'b, T>) -> &'a mut JSRef<'b, Self> { + unsafe { derived.transmute_mut() } + } } ''').substitute({'checkFn': 'is_' + name.lower(), 'castTraitName': name + 'Cast', diff --git a/src/components/script/dom/bindings/conversions.rs b/src/components/script/dom/bindings/conversions.rs index 6721f3f5dde..90c0251ba2f 100644 --- a/src/components/script/dom/bindings/conversions.rs +++ b/src/components/script/dom/bindings/conversions.rs @@ -2,9 +2,9 @@ * 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; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::str::ByteString; -use dom::bindings::utils::Reflectable; +use dom::bindings::utils::{Reflectable, Reflector}; use dom::bindings::utils::jsstring_to_str; use dom::bindings::utils::unwrap_jsmanaged; use servo_util::str::DOMString; @@ -293,9 +293,9 @@ impl FromJSValConvertible<()> for ByteString { } } -impl ToJSValConvertible for JS { +impl ToJSValConvertible for Reflector { fn to_jsval(&self, cx: *JSContext) -> JSVal { - let obj = self.reflector().get_jsobject(); + let obj = self.get_jsobject(); assert!(obj.is_not_null()); let mut value = ObjectValue(unsafe { &*obj }); if unsafe { JS_WrapValue(cx, &mut value as *mut JSVal as *JSVal) } == 0 { @@ -316,6 +316,18 @@ impl FromJSValConvertible<()> for JS { } } +impl ToJSValConvertible for JS { + fn to_jsval(&self, cx: *JSContext) -> JSVal { + self.reflector().to_jsval(cx) + } +} + +impl<'a, T: Reflectable> ToJSValConvertible for JSRef<'a, T> { + fn to_jsval(&self, cx: *JSContext) -> JSVal { + self.reflector().to_jsval(cx) + } +} + impl ToJSValConvertible for Option { fn to_jsval(&self, cx: *JSContext) -> JSVal { match self { diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs index 10aec5424bc..dac459f9c03 100644 --- a/src/components/script/dom/bindings/js.rs +++ b/src/components/script/dom/bindings/js.rs @@ -4,11 +4,13 @@ use dom::bindings::utils::{Reflector, Reflectable}; use dom::window::Window; -use js::jsapi::JSContext; +use js::jsapi::{JSObject, JSContext}; use layout_interface::TrustedNodeAddress; use std::cast; -use std::cell::RefCell; +use std::cell::{Cell, RefCell}; +use std::ptr; +//use std::ops::{Deref, DerefMut}; pub struct JS { ptr: RefCell<*mut T> @@ -31,8 +33,8 @@ impl Clone for JS { impl JS { pub fn new(obj: ~T, - window: &JS, - wrap_fn: extern "Rust" fn(*JSContext, &JS, ~T) -> JS) -> JS { + window: &JSRef, + wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~T) -> JS) -> JS { wrap_fn(window.get().get_cx(), window, obj) } @@ -49,6 +51,10 @@ impl JS { ptr: RefCell::new(addr as *mut T) } } + + pub fn root<'a>(&self, collection: &'a RootCollection) -> Root<'a, T> { + collection.new_root(self) + } } impl Reflectable for JS { @@ -94,3 +100,213 @@ impl JS { cast::transmute_copy(self) } } + +pub trait RootedReference { + fn root_ref<'a>(&'a self) -> Option>; +} + +impl<'a, T: Reflectable> RootedReference for Option> { + fn root_ref<'a>(&'a self) -> Option> { + self.as_ref().map(|root| root.root_ref()) + } +} + +#[deriving(Eq, Clone)] +struct RootReference(*JSObject); + +impl RootReference { + fn new<'a, T: Reflectable>(unrooted: &Root<'a, T>) -> RootReference { + RootReference(unrooted.rooted()) + } + + fn null() -> RootReference { + RootReference(ptr::null()) + } +} + +static MAX_STACK_ROOTS: uint = 10; + +pub struct RootCollection { + roots: [Cell, ..MAX_STACK_ROOTS], + current: Cell, +} + +impl RootCollection { + pub fn new() -> RootCollection { + RootCollection { + roots: [Cell::new(RootReference::null()), ..MAX_STACK_ROOTS], + current: Cell::new(0), + } + } + + fn new_root<'a, T: Reflectable>(&'a self, unrooted: &JS) -> Root<'a, T> { + Root::new(self, unrooted) + } + + fn root_impl(&self, unrooted: RootReference) { + let current = self.current.get(); + assert!(current < MAX_STACK_ROOTS); + self.roots[current].set(unrooted); + self.current.set(current + 1); + } + + fn root<'a, T: Reflectable>(&self, unrooted: &Root<'a, T>) { + self.root_impl(RootReference::new(unrooted)); + } + + pub fn root_raw(&self, unrooted: *JSObject) { + self.root_impl(RootReference(unrooted)); + } + + fn unroot_impl(&self, rooted: RootReference) { + let mut current = self.current.get(); + assert!(current != 0); + current -= 1; + assert!(self.roots[current].get() == rooted); + self.roots[current].set(RootReference::null()); + self.current.set(current); + } + + fn unroot<'a, T: Reflectable>(&self, rooted: &Root<'a, T>) { + self.unroot_impl(RootReference::new(rooted)); + } + + pub fn unroot_raw(&self, rooted: *JSObject) { + self.unroot_impl(RootReference(rooted)); + } +} + +pub struct Root<'a, T> { + root_list: &'a RootCollection, + ptr: RefCell<*mut T>, +} + +impl<'a, T: Reflectable> Root<'a, T> { + fn new(roots: &'a RootCollection, unrooted: &JS) -> Root<'a, T> { + let root = Root { + root_list: roots, + ptr: unrooted.ptr.clone() + }; + roots.root(&root); + root + } + + pub fn get<'a>(&'a self) -> &'a T { + unsafe { + let borrow = self.ptr.borrow(); + &**borrow + } + } + + pub fn get_mut<'a>(&'a mut self) -> &'a mut T { + unsafe { + let mut borrow = self.ptr.borrow_mut(); + &mut **borrow + } + } + + fn rooted(&self) -> *JSObject { + self.reflector().get_jsobject() + } + + pub fn root_ref<'b>(&'b self) -> JSRef<'b,T> { + unsafe { + JSRef { + ptr: self.ptr.clone(), + chain: ::std::cast::transmute_region(&()), + } + } + } +} + +#[unsafe_destructor] +impl<'a, T: Reflectable> Drop for Root<'a, T> { + fn drop(&mut self) { + self.root_list.unroot(self); + } +} + +impl<'a, T: Reflectable> Reflectable for Root<'a, T> { + fn reflector<'a>(&'a self) -> &'a Reflector { + self.get().reflector() + } + + fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector { + self.get_mut().mut_reflector() + } +} + +/*impl<'a, T> Deref for Root<'a, T> { + fn deref<'a>(&'a self) -> &'a T { + self.get() + } +} + +impl<'a, T> DerefMut for Root<'a, T> { + fn deref_mut<'a>(&'a mut self) -> &'a mut T { + self.get_mut() + } +}*/ + +/// Encapsulates a reference to something that is guaranteed to be alive. This is freely copyable. +pub struct JSRef<'a, T> { + ptr: RefCell<*mut T>, + chain: &'a (), +} + +impl<'a, T> Clone for JSRef<'a, T> { + fn clone(&self) -> JSRef<'a, T> { + JSRef { + ptr: self.ptr.clone(), + chain: self.chain + } + } +} + +impl<'a, T> Eq for JSRef<'a, T> { + fn eq(&self, other: &JSRef) -> bool { + self.ptr == other.ptr + } +} + +impl<'a,T> JSRef<'a,T> { + pub fn get<'a>(&'a self) -> &'a T { + unsafe { + let borrow = self.ptr.borrow(); + &**borrow + } + } + + pub fn get_mut<'a>(&'a mut self) -> &'a mut T { + let mut borrowed = self.ptr.borrow_mut(); + unsafe { + &mut **borrowed + } + } + + //XXXjdm It would be lovely if this could be private. + pub unsafe fn transmute<'b, To>(&'b self) -> &'b JSRef<'a, To> { + cast::transmute(self) + } + + //XXXjdm It would be lovely if this could be private. + pub unsafe fn transmute_mut<'b, To>(&'b mut self) -> &'b mut JSRef<'a, To> { + cast::transmute(self) + } + + pub fn unrooted(&self) -> JS { + JS { + ptr: self.ptr.clone() + } + } +} + +impl<'a, T: Reflectable> Reflectable for JSRef<'a, T> { + fn reflector<'a>(&'a self) -> &'a Reflector { + self.get().reflector() + } + + fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector { + self.get_mut().mut_reflector() + } +} diff --git a/src/components/script/dom/bindings/trace.rs b/src/components/script/dom/bindings/trace.rs index 554c67e8dc6..cbbeddb8594 100644 --- a/src/components/script/dom/bindings/trace.rs +++ b/src/components/script/dom/bindings/trace.rs @@ -6,6 +6,7 @@ use dom::bindings::js::JS; use dom::bindings::utils::{Reflectable, Reflector}; use js::jsapi::{JSObject, JSTracer, JS_CallTracer, JSTRACE_OBJECT}; +use js::jsval::JSVal; use libc; use std::cast; @@ -42,6 +43,22 @@ pub trait JSTraceable { fn trace(&self, trc: *mut JSTracer); } +pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: JSVal) { + if !val.is_gcthing() { + return; + } + + unsafe { + description.to_c_str().with_ref(|name| { + (*tracer).debugPrinter = ptr::null(); + (*tracer).debugPrintIndex = -1; + (*tracer).debugPrintArg = name as *libc::c_void; + debug!("tracing value {:s}", description); + JS_CallTracer(tracer as *JSTracer, val.to_gcthing(), val.trace_kind()); + }); + } +} + pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Reflector) { trace_object(tracer, description, reflector.get_jsobject()) } @@ -132,3 +149,10 @@ impl, E> Encodable for Traceable<*JSObject> { Ok(()) } } + +impl, E> Encodable for Traceable { + fn encode(&self, s: &mut S) -> Result<(), E> { + trace_jsval(get_jstracer(s), "val", **self); + Ok(()) + } +} diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index 417d4c434c2..7f240070ea1 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -5,7 +5,7 @@ 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; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::trace::Untraceable; use dom::browsercontext; use dom::window; @@ -37,7 +37,6 @@ use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass, JSNative}; use js::jsapi::{JSFunctionSpec, JSPropertySpec}; use js::jsapi::{JS_NewGlobalObject, JS_InitStandardClasses}; use js::jsapi::{JSString}; -use js::jsapi::{JS_AllowGC, JS_InhibitGC}; use js::jsfriendapi::bindgen::JS_NewObjectWithUniqueType; use js::jsval::JSVal; use js::jsval::{PrivateValue, ObjectValue, NullValue, ObjectOrNullValue}; @@ -390,8 +389,8 @@ pub trait Reflectable { pub fn reflect_dom_object (obj: ~T, - window: &JS, - wrap_fn: extern "Rust" fn(*JSContext, &JS, ~T) -> JS) + window: &JSRef, + wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~T) -> JS) -> JS { JS::new(obj, window, wrap_fn) } @@ -637,26 +636,6 @@ pub fn cx_for_dom_object(obj: &T) -> *JSContext { cx_for_dom_reflector(obj.reflector().get_jsobject()) } -/// Execute arbitrary code with the JS GC enabled, then disable it afterwards. -pub fn with_gc_enabled(cx: *JSContext, f: || -> R) -> R { - unsafe { - JS_AllowGC(cx); - let rv = f(); - JS_InhibitGC(cx); - rv - } -} - -/// Execute arbitrary code with the JS GC disabled, then enable it afterwards. -pub fn with_gc_disabled(cx: *JSContext, f: || -> R) -> R { - unsafe { - JS_InhibitGC(cx); - let rv = f(); - JS_AllowGC(cx); - rv - } -} - /// Check if an element name is valid. See http://www.w3.org/TR/xml/#NT-Name /// for details. #[deriving(Eq)] diff --git a/src/components/script/dom/blob.rs b/src/components/script/dom/blob.rs index 04964af092e..8dba1775ff6 100644 --- a/src/components/script/dom/blob.rs +++ b/src/components/script/dom/blob.rs @@ -2,7 +2,7 @@ * 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; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::Fallible; use dom::bindings::codegen::BindingDeclarations::BlobBinding; @@ -23,15 +23,15 @@ impl Blob { } } - pub fn new(window: &JS) -> JS { - reflect_dom_object(~Blob::new_inherited(window.clone()), + pub fn new(window: &JSRef) -> JS { + reflect_dom_object(~Blob::new_inherited(window.unrooted()), window, BlobBinding::Wrap) } } impl Blob { - pub fn Constructor(window: &JS) -> Fallible> { + pub fn Constructor(window: &JSRef) -> Fallible> { Ok(Blob::new(window)) } @@ -44,7 +44,9 @@ impl Blob { } pub fn Slice(&self, _start: Option, _end: Option, _contentType: Option) -> JS { - Blob::new(&self.window) + let roots = RootCollection::new(); + let window = self.window.root(&roots); + Blob::new(&window.root_ref()) } pub fn Close(&self) {} diff --git a/src/components/script/dom/clientrect.rs b/src/components/script/dom/clientrect.rs index 3d84944dfaa..977c4569bf5 100644 --- a/src/components/script/dom/clientrect.rs +++ b/src/components/script/dom/clientrect.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::ClientRectBinding; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::window::Window; use servo_util::geometry::Au; @@ -32,10 +32,10 @@ impl ClientRect { } } - pub fn new(window: &JS, + pub fn new(window: &JSRef, top: Au, bottom: Au, left: Au, right: Au) -> JS { - let rect = ClientRect::new_inherited(window.clone(), top, bottom, left, right); + let rect = ClientRect::new_inherited(window.unrooted(), top, bottom, left, right); reflect_dom_object(~rect, window, ClientRectBinding::Wrap) } diff --git a/src/components/script/dom/clientrectlist.rs b/src/components/script/dom/clientrectlist.rs index 906cfaa65e9..abd87c47455 100644 --- a/src/components/script/dom/clientrectlist.rs +++ b/src/components/script/dom/clientrectlist.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::ClientRectListBinding; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::clientrect::ClientRect; use dom::window::Window; @@ -25,9 +25,9 @@ impl ClientRectList { } } - pub fn new(window: &JS, + pub fn new(window: &JSRef, rects: Vec>) -> JS { - reflect_dom_object(~ClientRectList::new_inherited(window.clone(), rects), + reflect_dom_object(~ClientRectList::new_inherited(window.unrooted(), rects), window, ClientRectListBinding::Wrap) } diff --git a/src/components/script/dom/comment.rs b/src/components/script/dom/comment.rs index d6681c6ba2a..a0786441fe6 100644 --- a/src/components/script/dom/comment.rs +++ b/src/components/script/dom/comment.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::CommentDerived; use dom::bindings::codegen::BindingDeclarations::CommentBinding; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::error::Fallible; use dom::characterdata::CharacterData; use dom::document::Document; @@ -35,12 +35,16 @@ impl Comment { } } - pub fn new(text: DOMString, document: &JS) -> JS { - let node = Comment::new_inherited(text, document.clone()); + pub fn new(text: DOMString, document: &JSRef) -> JS { + let node = Comment::new_inherited(text, document.unrooted()); Node::reflect_node(~node, document, CommentBinding::Wrap) } - pub fn Constructor(owner: &JS, data: DOMString) -> Fallible> { - Ok(Comment::new(data, &owner.get().Document())) + pub fn Constructor(owner: &JSRef, data: DOMString) -> Fallible> { + let roots = RootCollection::new(); + let document = owner.get().Document(); + let document = document.root(&roots); + + Ok(Comment::new(data, &document.root_ref())) } } diff --git a/src/components/script/dom/console.rs b/src/components/script/dom/console.rs index 8e8081dcd83..a7908c6bc4f 100644 --- a/src/components/script/dom/console.rs +++ b/src/components/script/dom/console.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::ConsoleBinding; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::window::Window; use servo_util::str::DOMString; @@ -20,7 +20,7 @@ impl Console { } } - pub fn new(window: &JS) -> JS { + pub fn new(window: &JSRef) -> JS { reflect_dom_object(~Console::new_inherited(), window, ConsoleBinding::Wrap) } diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index fdf47a5467d..44b141dcea5 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::InheritTypes::{DocumentBase, NodeCast, DocumentCast} use dom::bindings::codegen::InheritTypes::{HTMLHeadElementCast, TextCast, ElementCast}; use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, HTMLHtmlElementCast}; use dom::bindings::codegen::BindingDeclarations::DocumentBinding; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::trace::Untraceable; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::{ErrorResult, Fallible, NotSupported, InvalidCharacter, HierarchyRequest, NamespaceError}; @@ -79,16 +79,18 @@ impl DocumentDerived for EventTarget { impl Document { pub fn reflect_document (document: ~D, - window: &JS, - wrap_fn: extern "Rust" fn(*JSContext, &JS, ~D) -> JS) + window: &JSRef, + wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~D) -> JS) -> JS { + let roots = RootCollection::new(); assert!(document.reflector().get_jsobject().is_null()); let raw_doc = reflect_dom_object(document, window, wrap_fn); assert!(raw_doc.reflector().get_jsobject().is_not_null()); let document = DocumentCast::from(&raw_doc); + let document_root = document.root(&roots); let mut node: JS = NodeCast::from(&document); - node.get_mut().set_owner_doc(&document); + node.get_mut().set_owner_doc(&document_root.root_ref()); raw_doc } @@ -122,8 +124,8 @@ impl Document { } } - pub fn new(window: &JS, url: Option, doctype: IsHTMLDocument, content_type: Option) -> JS { - let document = Document::new_inherited(window.clone(), url, doctype, content_type); + pub fn new(window: &JSRef, url: Option, doctype: IsHTMLDocument, content_type: Option) -> JS { + let document = Document::new_inherited(window.unrooted(), url, doctype, content_type); Document::reflect_document(~document, window, DocumentBinding::Wrap) } } @@ -136,7 +138,7 @@ impl Document { impl Document { // http://dom.spec.whatwg.org/#dom-document - pub fn Constructor(owner: &JS) -> Fallible> { + pub fn Constructor(owner: &JSRef) -> Fallible> { Ok(Document::new(owner, None, NonHTMLDocument, None)) } } @@ -155,7 +157,9 @@ impl Document { // http://dom.spec.whatwg.org/#dom-document-implementation pub fn Implementation(&mut self) -> JS { if self.implementation.is_none() { - self.implementation = Some(DOMImplementation::new(&self.window)); + let roots = RootCollection::new(); + let window = self.window.root(&roots); + self.implementation = Some(DOMImplementation::new(&window.root_ref())); } self.implementation.get_ref().clone() } @@ -212,22 +216,30 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-getelementsbytagname - pub fn GetElementsByTagName(&self, abstract_self: &JS, tag_name: DOMString) -> JS { - HTMLCollection::by_tag_name(&self.window, &NodeCast::from(abstract_self), tag_name) + pub fn GetElementsByTagName(&self, abstract_self: &JSRef, tag_name: DOMString) -> JS { + let roots = RootCollection::new(); + let window = self.window.root(&roots); + HTMLCollection::by_tag_name(&window.root_ref(), NodeCast::from_ref(abstract_self), tag_name) } // http://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens - pub fn GetElementsByTagNameNS(&self, abstract_self: &JS, maybe_ns: Option, tag_name: DOMString) -> JS { + pub fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, tag_name: DOMString) -> JS { + let roots = RootCollection::new(); + let window = self.window.root(&roots); + let namespace = match maybe_ns { Some(namespace) => Namespace::from_str(namespace), None => Null }; - HTMLCollection::by_tag_name_ns(&self.window, &NodeCast::from(abstract_self), tag_name, namespace) + HTMLCollection::by_tag_name_ns(&window.root_ref(), NodeCast::from_ref(abstract_self), tag_name, namespace) } // http://dom.spec.whatwg.org/#dom-document-getelementsbyclassname - pub fn GetElementsByClassName(&self, abstract_self: &JS, classes: DOMString) -> JS { - HTMLCollection::by_class_name(&self.window, &NodeCast::from(abstract_self), classes) + pub fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> JS { + let roots = RootCollection::new(); + let window = self.window.root(&roots); + + HTMLCollection::by_class_name(&window.root_ref(), NodeCast::from_ref(abstract_self), classes) } // http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid @@ -239,7 +251,7 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-createelement - pub fn CreateElement(&self, abstract_self: &JS, local_name: DOMString) + pub fn CreateElement(&self, abstract_self: &JSRef, local_name: DOMString) -> Fallible> { if xml_name_type(local_name) == InvalidXMLName { debug!("Not a valid element name"); @@ -250,7 +262,7 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-createelementns - pub fn CreateElementNS(&self, abstract_self: &JS, + pub fn CreateElementNS(&self, abstract_self: &JSRef, namespace: Option, qualified_name: DOMString) -> Fallible> { let ns = Namespace::from_str(null_str_as_empty_ref(&namespace)); @@ -296,23 +308,23 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-createdocumentfragment - pub fn CreateDocumentFragment(&self, abstract_self: &JS) -> JS { + pub fn CreateDocumentFragment(&self, abstract_self: &JSRef) -> JS { DocumentFragment::new(abstract_self) } // http://dom.spec.whatwg.org/#dom-document-createtextnode - pub fn CreateTextNode(&self, abstract_self: &JS, data: DOMString) + pub fn CreateTextNode(&self, abstract_self: &JSRef, data: DOMString) -> JS { Text::new(data, abstract_self) } // http://dom.spec.whatwg.org/#dom-document-createcomment - pub fn CreateComment(&self, abstract_self: &JS, data: DOMString) -> JS { + pub fn CreateComment(&self, abstract_self: &JSRef, data: DOMString) -> JS { Comment::new(data, abstract_self) } // http://dom.spec.whatwg.org/#dom-document-createprocessinginstruction - pub fn CreateProcessingInstruction(&self, abstract_self: &JS, target: DOMString, + pub fn CreateProcessingInstruction(&self, abstract_self: &JSRef, target: DOMString, data: DOMString) -> Fallible> { // Step 1. if xml_name_type(target) == InvalidXMLName { @@ -329,9 +341,9 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-importnode - pub fn ImportNode(&self, abstract_self: &JS, node: &JS, deep: bool) -> Fallible> { + pub fn ImportNode(&self, abstract_self: &JSRef, node: &JSRef, deep: bool) -> Fallible> { // Step 1. - if node.is_document() { + if node.unrooted().is_document() { return Err(NotSupported); } @@ -345,9 +357,9 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-adoptnode - pub fn AdoptNode(&self, abstract_self: &JS, node: &JS) -> Fallible> { + pub fn AdoptNode(&self, abstract_self: &JSRef, node: &JSRef) -> Fallible> { // Step 1. - if node.is_document() { + if node.unrooted().is_document() { return Err(NotSupported); } @@ -356,22 +368,25 @@ impl Document { Node::adopt(&mut adoptee, abstract_self); // Step 3. - Ok(adoptee) + Ok(adoptee.unrooted()) } // http://dom.spec.whatwg.org/#dom-document-createevent pub fn CreateEvent(&self, interface: DOMString) -> Fallible> { + let roots = RootCollection::new(); + let window = self.window.root(&roots); + match interface.to_ascii_lower().as_slice() { // FIXME: Implement CustomEvent (http://dom.spec.whatwg.org/#customevent) - "uievents" | "uievent" => Ok(EventCast::from(&UIEvent::new(&self.window))), - "mouseevents" | "mouseevent" => Ok(EventCast::from(&MouseEvent::new(&self.window))), - "htmlevents" | "events" | "event" => Ok(Event::new(&self.window)), + "uievents" | "uievent" => Ok(EventCast::from(&UIEvent::new(&window.root_ref()))), + "mouseevents" | "mouseevent" => Ok(EventCast::from(&MouseEvent::new(&window.root_ref()))), + "htmlevents" | "events" | "event" => Ok(Event::new(&window.root_ref())), _ => Err(NotSupported) } } // http://www.whatwg.org/specs/web-apps/current-work/#document.title - pub fn Title(&self, _: &JS) -> DOMString { + pub fn Title(&self, _: &JSRef) -> DOMString { let mut title = ~""; self.GetDocumentElement().map(|root| { let root: JS = NodeCast::from(&root); @@ -392,7 +407,9 @@ impl Document { } // http://www.whatwg.org/specs/web-apps/current-work/#document.title - pub fn SetTitle(&self, abstract_self: &JS, title: DOMString) -> ErrorResult { + pub fn SetTitle(&self, abstract_self: &JSRef, title: DOMString) -> ErrorResult { + let roots = RootCollection::new(); + self.GetDocumentElement().map(|root| { let root: JS = NodeCast::from(&root); let mut head_node = root.traverse_preorder().find(|child| { @@ -405,18 +422,25 @@ impl Document { match title_node { Some(ref mut title_node) => { - for mut title_child in title_node.children() { - assert!(title_node.RemoveChild(&mut title_child).is_ok()); + for title_child in title_node.children() { + let title_child = title_child.root(&roots); + assert!(title_node.RemoveChild(&mut title_child.root_ref()).is_ok()); } let new_text = self.CreateTextNode(abstract_self, title.clone()); - assert!(title_node.AppendChild(&mut NodeCast::from(&new_text)).is_ok()); + let new_text = new_text.root(&roots); + + assert!(title_node.AppendChild(NodeCast::from_mut_ref(&mut new_text.root_ref())).is_ok()); }, None => { let mut new_title: JS = NodeCast::from(&HTMLTitleElement::new(~"title", abstract_self)); + let new_title_root = new_title.root(&roots); + let new_text = self.CreateTextNode(abstract_self, title.clone()); - assert!(new_title.AppendChild(&mut NodeCast::from(&new_text)).is_ok()); - assert!(head.AppendChild(&mut new_title).is_ok()); + let new_text = new_text.root(&roots); + + assert!(new_title.AppendChild(NodeCast::from_mut_ref(&mut new_text.root_ref())).is_ok()); + assert!(head.AppendChild(&mut new_title_root.root_ref()).is_ok()); }, } }); @@ -441,7 +465,7 @@ impl Document { } // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body - pub fn GetBody(&self, _: &JS) -> Option> { + pub fn GetBody(&self, _: &JSRef) -> Option> { self.get_html_element().and_then(|root| { let node: JS = NodeCast::from(&root); node.children().find(|child| { @@ -455,7 +479,9 @@ impl Document { } // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body - pub fn SetBody(&self, abstract_self: &JS, new_body: Option>) -> ErrorResult { + pub fn SetBody(&self, abstract_self: &JSRef, new_body: Option>) -> ErrorResult { + let roots = RootCollection::new(); + // Step 1. match new_body { Some(ref node) => { @@ -469,7 +495,7 @@ impl Document { // Step 2. let old_body: Option> = self.GetBody(abstract_self); - if old_body == new_body { + if old_body == new_body.as_ref().map(|new_body| new_body.unrooted()) { return Ok(()); } @@ -478,14 +504,18 @@ impl Document { // Step 4. None => return Err(HierarchyRequest), Some(root) => { - let mut new_body: JS = NodeCast::from(&new_body.unwrap()); + let mut new_body_unwrapped = new_body.unwrap(); + let new_body: &mut JSRef = NodeCast::from_mut_ref(&mut new_body_unwrapped); + let mut root: JS = NodeCast::from(&root); match old_body { Some(child) => { - let mut child: JS = NodeCast::from(&child); - assert!(root.ReplaceChild(&mut new_body, &mut child).is_ok()) + let child: JS = NodeCast::from(&child); + let child = child.root(&roots); + + assert!(root.ReplaceChild(new_body, &mut child.root_ref()).is_ok()) } - None => assert!(root.AppendChild(&mut new_body).is_ok()) + None => assert!(root.AppendChild(new_body).is_ok()) }; } } @@ -495,132 +525,159 @@ impl Document { // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-getelementsbyname pub fn GetElementsByName(&self, name: DOMString) -> JS { self.createNodeList(|node| { - if !node.is_element() { + if !node.get().is_element() { return false; } - let element: JS = ElementCast::to(node).unwrap(); + let element: JS = ElementCast::to(&node.unrooted()).unwrap(); element.get_attribute(Null, "name").map_or(false, |attr| { attr.get().value_ref() == name }) }) } - pub fn Images(&self, abstract_self: &JS) -> JS { + pub fn Images(&self, abstract_self: &JSRef) -> JS { + let roots = RootCollection::new(); + let window = self.window.root(&roots); + // FIXME: https://github.com/mozilla/servo/issues/1847 struct ImagesFilter; impl CollectionFilter for ImagesFilter { - fn filter(&self, elem: &JS, _root: &JS) -> bool { + fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { elem.get().local_name == ~"img" } } let filter = ~ImagesFilter; - HTMLCollection::create(&self.window, &NodeCast::from(abstract_self), filter) + HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter) } - pub fn Embeds(&self, abstract_self: &JS) -> JS { + pub fn Embeds(&self, abstract_self: &JSRef) -> JS { + let roots = RootCollection::new(); + let window = self.window.root(&roots); + // FIXME: https://github.com/mozilla/servo/issues/1847 struct EmbedsFilter; impl CollectionFilter for EmbedsFilter { - fn filter(&self, elem: &JS, _root: &JS) -> bool { + fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { elem.get().local_name == ~"embed" } } let filter = ~EmbedsFilter; - HTMLCollection::create(&self.window, &NodeCast::from(abstract_self), filter) + HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter) } - pub fn Plugins(&self, abstract_self: &JS) -> JS { + pub fn Plugins(&self, abstract_self: &JSRef) -> JS { // FIXME: https://github.com/mozilla/servo/issues/1847 self.Embeds(abstract_self) } - pub fn Links(&self, abstract_self: &JS) -> JS { + pub fn Links(&self, abstract_self: &JSRef) -> JS { + let roots = RootCollection::new(); + let window = self.window.root(&roots); + // FIXME: https://github.com/mozilla/servo/issues/1847 struct LinksFilter; impl CollectionFilter for LinksFilter { - fn filter(&self, elem: &JS, _root: &JS) -> bool { + fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { (elem.get().local_name == ~"a" || elem.get().local_name == ~"area") && - elem.get_attribute(Null, "href").is_some() + elem.unrooted().get_attribute(Null, "href").is_some() } } let filter = ~LinksFilter; - HTMLCollection::create(&self.window, &NodeCast::from(abstract_self), filter) + HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter) } - pub fn Forms(&self, abstract_self: &JS) -> JS { + pub fn Forms(&self, abstract_self: &JSRef) -> JS { + let roots = RootCollection::new(); + let window = self.window.root(&roots); + // FIXME: https://github.com/mozilla/servo/issues/1847 struct FormsFilter; impl CollectionFilter for FormsFilter { - fn filter(&self, elem: &JS, _root: &JS) -> bool { + fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { elem.get().local_name == ~"form" } } let filter = ~FormsFilter; - HTMLCollection::create(&self.window, &NodeCast::from(abstract_self), filter) + HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter) } - pub fn Scripts(&self, abstract_self: &JS) -> JS { + pub fn Scripts(&self, abstract_self: &JSRef) -> JS { + let roots = RootCollection::new(); + let window = self.window.root(&roots); + // FIXME: https://github.com/mozilla/servo/issues/1847 struct ScriptsFilter; impl CollectionFilter for ScriptsFilter { - fn filter(&self, elem: &JS, _root: &JS) -> bool { + fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { elem.get().local_name == ~"script" } } let filter = ~ScriptsFilter; - HTMLCollection::create(&self.window, &NodeCast::from(abstract_self), filter) + HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter) } - pub fn Anchors(&self, abstract_self: &JS) -> JS { + pub fn Anchors(&self, abstract_self: &JSRef) -> JS { + let roots = RootCollection::new(); + let window = self.window.root(&roots); + // FIXME: https://github.com/mozilla/servo/issues/1847 struct AnchorsFilter; impl CollectionFilter for AnchorsFilter { - fn filter(&self, elem: &JS, _root: &JS) -> bool { - elem.get().local_name == ~"a" && elem.get_attribute(Null, "name").is_some() + fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { + elem.get().local_name == ~"a" && elem.unrooted().get_attribute(Null, "name").is_some() } } let filter = ~AnchorsFilter; - HTMLCollection::create(&self.window, &NodeCast::from(abstract_self), filter) + HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter) } - pub fn Applets(&self, abstract_self: &JS) -> JS { + pub fn Applets(&self, abstract_self: &JSRef) -> JS { + let roots = RootCollection::new(); + let window = self.window.root(&roots); + // FIXME: This should be return OBJECT elements containing applets. struct AppletsFilter; impl CollectionFilter for AppletsFilter { - fn filter(&self, elem: &JS, _root: &JS) -> bool { + fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { elem.get().local_name == ~"applet" } } let filter = ~AppletsFilter; - HTMLCollection::create(&self.window, &NodeCast::from(abstract_self), filter) + HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter) } - pub fn Location(&mut self, abstract_self: &JS) -> JS { - self.window.get_mut().Location(&abstract_self.get().window) + pub fn Location(&mut self, _abstract_self: &JSRef) -> JS { + let roots = RootCollection::new(); + let window = self.window.root(&roots); + self.window.get_mut().Location(&window.root_ref()) } - pub fn Children(&self, abstract_self: &JS) -> JS { - let doc = self.node.owner_doc(); - let doc = doc.get(); - HTMLCollection::children(&doc.window, &NodeCast::from(abstract_self)) + pub fn Children(&self, abstract_self: &JSRef) -> JS { + let roots = RootCollection::new(); + let window = self.window.root(&roots); + HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self)) } - pub fn createNodeList(&self, callback: |node: &JS| -> bool) -> JS { + pub fn createNodeList(&self, callback: |node: &JSRef| -> bool) -> JS { + let roots = RootCollection::new(); + let window = self.window.root(&roots); + let mut nodes = vec!(); match self.GetDocumentElement() { None => {}, Some(root) => { let root: JS = NodeCast::from(&root); for child in root.traverse_preorder() { - if callback(&child) { - nodes.push(child.clone()); + let child = child.root(&roots); + if callback(&child.root_ref()) { + nodes.push(child.root_ref().unrooted()); } } } } - NodeList::new_simple_list(&self.window, nodes) + NodeList::new_simple_list(&window.root_ref(), nodes) } pub fn content_changed(&self) { @@ -638,14 +695,14 @@ impl Document { /// Remove any existing association between the provided id and any elements in this document. pub fn unregister_named_element(&mut self, - abstract_self: &JS, + abstract_self: &JSRef, id: DOMString) { let mut is_empty = false; match self.idmap.find_mut(&id) { None => {}, Some(elements) => { let position = elements.iter() - .position(|element| element == abstract_self) + .position(|element| element == &abstract_self.unrooted()) .expect("This element should be in registered."); elements.remove(position); is_empty = elements.is_empty(); @@ -658,10 +715,10 @@ impl Document { /// Associate an element present in this document with the provided id. pub fn register_named_element(&mut self, - element: &JS, + element: &JSRef, id: DOMString) { assert!({ - let node: JS = NodeCast::from(element); + let node: JS = NodeCast::from(&element.unrooted()); node.is_in_doc() }); @@ -670,7 +727,7 @@ impl Document { let root = self.GetDocumentElement().expect("The element is in the document, so there must be a document element."); match self.idmap.find_mut(&id) { Some(elements) => { - let new_node = NodeCast::from(element); + let new_node = NodeCast::from_ref(element); let mut head : uint = 0u; let root: JS = NodeCast::from(&root); for node in root.traverse_preorder() { @@ -679,18 +736,18 @@ impl Document { if elements.get(head) == &elem { head = head + 1; } - if new_node == node || head == elements.len() { + if new_node.unrooted() == node || head == elements.len() { break; } } None => {} } } - elements.insert(head, element.clone()); + elements.insert(head, element.unrooted()); return; }, None => (), } - self.idmap.insert(id, vec!(element.clone())); + self.idmap.insert(id, vec!(element.unrooted())); } } diff --git a/src/components/script/dom/documentfragment.rs b/src/components/script/dom/documentfragment.rs index 7346a5a98ef..e10e9e1204c 100644 --- a/src/components/script/dom/documentfragment.rs +++ b/src/components/script/dom/documentfragment.rs @@ -4,12 +4,12 @@ use dom::bindings::codegen::InheritTypes::{DocumentFragmentDerived, NodeCast}; use dom::bindings::codegen::BindingDeclarations::DocumentFragmentBinding; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::error::Fallible; use dom::document::Document; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlcollection::HTMLCollection; -use dom::node::{DocumentFragmentNodeTypeId, Node}; +use dom::node::{DocumentFragmentNodeTypeId, Node, window_from_node}; use dom::window::Window; #[deriving(Encodable)] @@ -34,22 +34,26 @@ impl DocumentFragment { } } - pub fn new(document: &JS) -> JS { - let node = DocumentFragment::new_inherited(document.clone()); + pub fn new(document: &JSRef) -> JS { + let node = DocumentFragment::new_inherited(document.unrooted()); Node::reflect_node(~node, document, DocumentFragmentBinding::Wrap) } } impl DocumentFragment { - pub fn Constructor(owner: &JS) -> Fallible> { - Ok(DocumentFragment::new(&owner.get().Document())) + pub fn Constructor(owner: &JSRef) -> Fallible> { + let roots = RootCollection::new(); + let document = owner.get().Document(); + let document = document.root(&roots); + + Ok(DocumentFragment::new(&document.root_ref())) } } impl DocumentFragment { - pub fn Children(&self, abstract_self: &JS) -> JS { - let doc = self.node.owner_doc(); - let doc = doc.get(); - HTMLCollection::children(&doc.window, &NodeCast::from(abstract_self)) + pub fn Children(&self, abstract_self: &JSRef) -> JS { + let roots = RootCollection::new(); + let window = window_from_node(&abstract_self.unrooted()).root(&roots); + HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self)) } } diff --git a/src/components/script/dom/documenttype.rs b/src/components/script/dom/documenttype.rs index 856dde0e98e..dacce041f5c 100644 --- a/src/components/script/dom/documenttype.rs +++ b/src/components/script/dom/documenttype.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::DocumentTypeDerived; use dom::bindings::codegen::BindingDeclarations::DocumentTypeBinding; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::document::Document; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::node::{Node, DoctypeNodeTypeId}; @@ -45,12 +45,12 @@ impl DocumentType { pub fn new(name: DOMString, public_id: Option, system_id: Option, - document: &JS) + document: &JSRef) -> JS { let documenttype = DocumentType::new_inherited(name, public_id, system_id, - document.clone()); + document.unrooted()); Node::reflect_node(~documenttype, document, DocumentTypeBinding::Wrap) } } diff --git a/src/components/script/dom/domexception.rs b/src/components/script/dom/domexception.rs index 6bb946e4bed..db562d08c71 100644 --- a/src/components/script/dom/domexception.rs +++ b/src/components/script/dom/domexception.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::DOMExceptionBinding; use dom::bindings::codegen::BindingDeclarations::DOMExceptionBinding::DOMExceptionConstants; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::window::Window; use servo_util::str::DOMString; @@ -49,7 +49,7 @@ impl DOMException { } } - pub fn new(window: &JS, code: DOMErrorName) -> JS { + pub fn new(window: &JSRef, code: DOMErrorName) -> JS { reflect_dom_object(~DOMException::new_inherited(code), window, DOMExceptionBinding::Wrap) } } diff --git a/src/components/script/dom/domimplementation.rs b/src/components/script/dom/domimplementation.rs index 28d226ba406..e002cf9d28c 100644 --- a/src/components/script/dom/domimplementation.rs +++ b/src/components/script/dom/domimplementation.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::DOMImplementationBinding; use dom::bindings::codegen::InheritTypes::NodeCast; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; 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}; @@ -33,8 +33,8 @@ impl DOMImplementation { } } - pub fn new(owner: &JS) -> JS { - reflect_dom_object(~DOMImplementation::new_inherited(owner.clone()), owner, + pub fn new(owner: &JSRef) -> JS { + reflect_dom_object(~DOMImplementation::new_inherited(owner.unrooted()), owner, DOMImplementationBinding::Wrap) } } @@ -53,28 +53,37 @@ impl Reflectable for DOMImplementation { impl DOMImplementation { // http://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype pub fn CreateDocumentType(&self, qname: DOMString, pubid: DOMString, sysid: DOMString) -> Fallible> { + let roots = RootCollection::new(); match xml_name_type(qname) { // Step 1. InvalidXMLName => Err(InvalidCharacter), // Step 2. Name => Err(NamespaceError), // Step 3. - QName => Ok(DocumentType::new(qname, Some(pubid), Some(sysid), &self.owner.get().Document())) + QName => { + let document = self.owner.get().Document(); + let document = document.root(&roots); + Ok(DocumentType::new(qname, Some(pubid), Some(sysid), &document.root_ref())) + } } } // http://dom.spec.whatwg.org/#dom-domimplementation-createdocument pub fn CreateDocument(&self, namespace: Option, qname: DOMString, - maybe_doctype: Option>) -> Fallible> { + mut maybe_doctype: Option>) -> Fallible> { + let roots = RootCollection::new(); + let win = self.owner.root(&roots); + // Step 1. - let doc = Document::new(&self.owner, None, NonHTMLDocument, None); + let doc = Document::new(&win.root_ref(), None, NonHTMLDocument, None); + let doc_root = doc.root(&roots); let mut doc_node: JS = NodeCast::from(&doc); // Step 2-3. - let maybe_elem = if qname.is_empty() { + let mut maybe_elem = if qname.is_empty() { None } else { - match doc.get().CreateElementNS(&doc, namespace, qname) { + match doc.get().CreateElementNS(&doc_root.root_ref(), namespace, qname) { Err(error) => return Err(error), Ok(elem) => Some(elem) } @@ -83,13 +92,16 @@ impl DOMImplementation { // Step 4. match maybe_doctype { None => (), - Some(ref doctype) => assert!(doc_node.AppendChild(&mut NodeCast::from(doctype)).is_ok()) + Some(ref mut doctype) => assert!(doc_node.AppendChild(NodeCast::from_mut_ref(doctype)).is_ok()) } // Step 5. match maybe_elem { None => (), - Some(ref elem) => assert!(doc_node.AppendChild(&mut NodeCast::from(elem)).is_ok()) + Some(ref elem) => { + let elem = elem.root(&roots); + assert!(doc_node.AppendChild(NodeCast::from_mut_ref(&mut elem.root_ref())).is_ok()) + } } // Step 6. @@ -101,44 +113,54 @@ impl DOMImplementation { // http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument pub fn CreateHTMLDocument(&self, title: Option) -> JS { + let roots = RootCollection::new(); + let owner = self.owner.root(&roots); + // Step 1-2. - let doc = Document::new(&self.owner, None, HTMLDocument, None); + let doc = Document::new(&owner.root_ref(), None, HTMLDocument, None); + let doc_root = doc.root(&roots); let mut doc_node: JS = NodeCast::from(&doc); { // Step 3. - let doc_type = DocumentType::new(~"html", None, None, &doc); - assert!(doc_node.AppendChild(&mut NodeCast::from(&doc_type)).is_ok()); + let doc_type = DocumentType::new(~"html", None, None, &doc_root.root_ref()); + let doc_type = doc_type.root(&roots); + assert!(doc_node.AppendChild(NodeCast::from_mut_ref(&mut doc_type.root_ref())).is_ok()); } { // Step 4. - let mut doc_html = NodeCast::from(&HTMLHtmlElement::new(~"html", &doc)); - assert!(doc_node.AppendChild(&mut doc_html).is_ok()); + let mut doc_html = NodeCast::from(&HTMLHtmlElement::new(~"html", &doc_root.root_ref())); + let doc_html_root = {doc_html.root(&roots)}; + assert!(doc_node.AppendChild(&mut doc_html_root.root_ref()).is_ok()); { // Step 5. - let mut doc_head = NodeCast::from(&HTMLHeadElement::new(~"head", &doc)); - assert!(doc_html.AppendChild(&mut doc_head).is_ok()); + let mut doc_head = NodeCast::from(&HTMLHeadElement::new(~"head", &doc_root.root_ref())); + let doc_head_root = doc_head.root(&roots); + assert!(doc_html.AppendChild(&mut doc_head_root.root_ref()).is_ok()); // Step 6. match title { None => (), Some(title_str) => { // Step 6.1. - let mut doc_title = NodeCast::from(&HTMLTitleElement::new(~"title", &doc)); - assert!(doc_head.AppendChild(&mut doc_title).is_ok()); + let mut doc_title = NodeCast::from(&HTMLTitleElement::new(~"title", &doc_root.root_ref())); + let doc_title_root = doc_title.root(&roots); + assert!(doc_head.AppendChild(&mut doc_title_root.root_ref()).is_ok()); // Step 6.2. - let title_text = Text::new(title_str, &doc); - assert!(doc_title.AppendChild(&mut NodeCast::from(&title_text)).is_ok()); + let title_text = Text::new(title_str, &doc_root.root_ref()); + let title_text = title_text.root(&roots); + assert!(doc_title.AppendChild(NodeCast::from_mut_ref(&mut title_text.root_ref())).is_ok()); } } } // Step 7. - let doc_body = HTMLBodyElement::new(~"body", &doc); - assert!(doc_html.AppendChild(&mut NodeCast::from(&doc_body)).is_ok()); + let doc_body = HTMLBodyElement::new(~"body", &doc_root.root_ref()); + let doc_body = doc_body.root(&roots); + assert!(doc_html.AppendChild(NodeCast::from_mut_ref(&mut doc_body.root_ref())).is_ok()); } // Step 8. diff --git a/src/components/script/dom/domparser.rs b/src/components/script/dom/domparser.rs index 1961c8d4661..d11c7270057 100644 --- a/src/components/script/dom/domparser.rs +++ b/src/components/script/dom/domparser.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::DOMParserBinding; use dom::bindings::codegen::BindingDeclarations::DOMParserBinding::SupportedTypeValues::{Text_html, Text_xml}; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object}; use dom::bindings::error::{Fallible, FailureUnknown}; use dom::document::{Document, HTMLDocument, NonHTMLDocument}; @@ -25,12 +25,12 @@ impl DOMParser { } } - pub fn new(owner: &JS) -> JS { - reflect_dom_object(~DOMParser::new_inherited(owner.clone()), owner, + pub fn new(owner: &JSRef) -> JS { + reflect_dom_object(~DOMParser::new_inherited(owner.unrooted()), owner, DOMParserBinding::Wrap) } - pub fn Constructor(owner: &JS) -> Fallible> { + pub fn Constructor(owner: &JSRef) -> Fallible> { Ok(DOMParser::new(owner)) } @@ -38,12 +38,14 @@ impl DOMParser { _s: DOMString, ty: DOMParserBinding::SupportedType) -> Fallible> { + let roots = RootCollection::new(); + let owner = self.owner.root(&roots); match ty { Text_html => { - Ok(Document::new(&self.owner, None, HTMLDocument, Some(~"text/html"))) + Ok(Document::new(&owner.root_ref(), None, HTMLDocument, Some(~"text/html"))) } Text_xml => { - Ok(Document::new(&self.owner, None, NonHTMLDocument, Some(~"text/xml"))) + Ok(Document::new(&owner.root_ref(), None, NonHTMLDocument, Some(~"text/xml"))) } _ => { Err(FailureUnknown) diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index 4f1e265e8f9..179f2c7571d 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -8,7 +8,7 @@ use dom::attr::{Attr, AttrSettingType, ReplacedAttr, FirstSetAttr}; use dom::attrlist::AttrList; use dom::bindings::codegen::BindingDeclarations::ElementBinding; use dom::bindings::codegen::InheritTypes::{ElementDerived, NodeCast}; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::utils::{Reflectable, Reflector}; use dom::bindings::error::{ErrorResult, Fallible, NamespaceError, InvalidCharacter}; use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type}; @@ -19,6 +19,7 @@ use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlcollection::HTMLCollection; use dom::htmlserializer::serialize; use dom::node::{ElementNodeTypeId, Node, NodeHelpers, NodeIterator, document_from_node}; +use dom::node::window_from_node; use dom::virtualmethods::{VirtualMethods, vtable_for}; use layout_interface::ContentChangedDocumentDamage; use layout_interface::MatchSelectorsDocumentDamage; @@ -151,8 +152,8 @@ impl Element { } } - pub fn new(local_name: DOMString, namespace: Namespace, prefix: Option, document: &JS) -> JS { - let element = Element::new_inherited(ElementTypeId, local_name, namespace, prefix, document.clone()); + pub fn new(local_name: DOMString, namespace: Namespace, prefix: Option, document: &JSRef) -> JS { + let element = Element::new_inherited(ElementTypeId, local_name, namespace, prefix, document.unrooted()); Node::reflect_node(~element, document, ElementBinding::Wrap) } @@ -260,6 +261,7 @@ impl AttributeHandlers for JS { fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString, name: DOMString, namespace: Namespace, prefix: Option, cb: |&JS| -> bool) { + let roots = RootCollection::new(); let node: JS = NodeCast::from(self); let idx = self.get().attrs.iter().position(cb); let (mut attr, set_type): (JS, AttrSettingType) = match idx { @@ -270,8 +272,9 @@ impl AttributeHandlers for JS { None => { let doc = node.get().owner_doc().get(); - let attr = Attr::new(&doc.window, local_name.clone(), value.clone(), - name, namespace.clone(), prefix, self.clone()); + let window = doc.window.root(&roots); + let attr = Attr::new(&window.root_ref(), local_name.clone(), value.clone(), + name, namespace.clone(), prefix, self.clone()); self.get_mut().attrs.push(attr.clone()); (attr, FirstSetAttr) } @@ -474,32 +477,34 @@ impl Element { } // http://dom.spec.whatwg.org/#dom-element-id - pub fn Id(&self, abstract_self: &JS) -> DOMString { - abstract_self.get_string_attribute("id") + pub fn Id(&self, abstract_self: &JSRef) -> DOMString { + abstract_self.unrooted().get_string_attribute("id") } // http://dom.spec.whatwg.org/#dom-element-id - pub fn SetId(&mut self, abstract_self: &mut JS, id: DOMString) { - abstract_self.set_string_attribute("id", id); + pub fn SetId(&mut self, abstract_self: &mut JSRef, id: DOMString) { + abstract_self.unrooted().set_string_attribute("id", id); } // http://dom.spec.whatwg.org/#dom-element-classname - pub fn ClassName(&self, abstract_self: &JS) -> DOMString { - abstract_self.get_string_attribute("class") + pub fn ClassName(&self, abstract_self: &JSRef) -> DOMString { + abstract_self.unrooted().get_string_attribute("class") } // http://dom.spec.whatwg.org/#dom-element-classname - pub fn SetClassName(&self, abstract_self: &mut JS, class: DOMString) { - abstract_self.set_string_attribute("class", class); + pub fn SetClassName(&self, abstract_self: &mut JSRef, class: DOMString) { + abstract_self.unrooted().set_string_attribute("class", class); } // http://dom.spec.whatwg.org/#dom-element-attributes - pub fn Attributes(&mut self, abstract_self: &JS) -> JS { + pub fn Attributes(&mut self, abstract_self: &JSRef) -> JS { + let roots = RootCollection::new(); match self.attr_list { None => { let doc = self.node.owner_doc(); let doc = doc.get(); - let list = AttrList::new(&doc.window, abstract_self); + let window = doc.window.root(&roots); + let list = AttrList::new(&window.root_ref(), abstract_self); self.attr_list = Some(list.clone()); list } @@ -508,142 +513,151 @@ impl Element { } // http://dom.spec.whatwg.org/#dom-element-getattribute - pub fn GetAttribute(&self, abstract_self: &JS, name: DOMString) -> Option { + pub fn GetAttribute(&self, abstract_self: &JSRef, name: DOMString) -> Option { let name = if abstract_self.get().html_element_in_html_document() { name.to_ascii_lower() } else { name }; - abstract_self.get_attribute(Null, name).map(|s| s.get().Value()) + abstract_self.unrooted().get_attribute(Null, name).map(|s| s.get().Value()) } // http://dom.spec.whatwg.org/#dom-element-getattributens - pub fn GetAttributeNS(&self, abstract_self: &JS, + pub fn GetAttributeNS(&self, abstract_self: &JSRef, namespace: Option, local_name: DOMString) -> Option { let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace)); - abstract_self.get_attribute(namespace, local_name) + abstract_self.unrooted() + .get_attribute(namespace, local_name) .map(|attr| attr.get().value.clone()) } // http://dom.spec.whatwg.org/#dom-element-setattribute - pub fn SetAttribute(&self, abstract_self: &mut JS, + pub fn SetAttribute(&self, abstract_self: &mut JSRef, name: DOMString, value: DOMString) -> ErrorResult { - abstract_self.SetAttribute(name, value) + abstract_self.unrooted().SetAttribute(name, value) } // http://dom.spec.whatwg.org/#dom-element-setattributens pub fn SetAttributeNS(&self, - abstract_self: &mut JS, + abstract_self: &mut JSRef, namespace_url: Option, name: DOMString, value: DOMString) -> ErrorResult { - abstract_self.SetAttributeNS(namespace_url, name, value) + abstract_self.unrooted().SetAttributeNS(namespace_url, name, value) } // http://dom.spec.whatwg.org/#dom-element-removeattribute pub fn RemoveAttribute(&mut self, - abstract_self: &mut JS, + abstract_self: &mut JSRef, name: DOMString) -> ErrorResult { let name = if self.html_element_in_html_document() { name.to_ascii_lower() } else { name }; - abstract_self.remove_attribute(namespace::Null, name) + abstract_self.unrooted().remove_attribute(namespace::Null, name) } // http://dom.spec.whatwg.org/#dom-element-removeattributens pub fn RemoveAttributeNS(&mut self, - abstract_self: &mut JS, + abstract_self: &mut JSRef, namespace: Option, localname: DOMString) -> ErrorResult { let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace)); - abstract_self.remove_attribute(namespace, localname) + abstract_self.unrooted().remove_attribute(namespace, localname) } // http://dom.spec.whatwg.org/#dom-element-hasattribute - pub fn HasAttribute(&self, abstract_self: &JS, + pub fn HasAttribute(&self, abstract_self: &JSRef, name: DOMString) -> bool { self.GetAttribute(abstract_self, name).is_some() } // http://dom.spec.whatwg.org/#dom-element-hasattributens - pub fn HasAttributeNS(&self, abstract_self: &JS, + pub fn HasAttributeNS(&self, abstract_self: &JSRef, namespace: Option, local_name: DOMString) -> bool { self.GetAttributeNS(abstract_self, namespace, local_name).is_some() } - pub fn GetElementsByTagName(&self, abstract_self: &JS, localname: DOMString) -> JS { + pub fn GetElementsByTagName(&self, abstract_self: &JSRef, localname: DOMString) -> JS { + let roots = RootCollection::new(); let doc = self.node.owner_doc(); let doc = doc.get(); - HTMLCollection::by_tag_name(&doc.window, &NodeCast::from(abstract_self), localname) + let window = doc.window.root(&roots); + HTMLCollection::by_tag_name(&window.root_ref(), NodeCast::from_ref(abstract_self), localname) } - pub fn GetElementsByTagNameNS(&self, abstract_self: &JS, maybe_ns: Option, + pub fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, localname: DOMString) -> JS { + let roots = RootCollection::new(); let doc = self.node.owner_doc(); let doc = doc.get(); let namespace = match maybe_ns { Some(namespace) => Namespace::from_str(namespace), None => Null }; - HTMLCollection::by_tag_name_ns(&doc.window, &NodeCast::from(abstract_self), localname, namespace) + let window = doc.window.root(&roots); + HTMLCollection::by_tag_name_ns(&window.root_ref(), NodeCast::from_ref(abstract_self), localname, namespace) } - pub fn GetElementsByClassName(&self, abstract_self: &JS, classes: DOMString) -> JS { + pub fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> JS { + let roots = RootCollection::new(); let doc = self.node.owner_doc(); let doc = doc.get(); - HTMLCollection::by_class_name(&doc.window, &NodeCast::from(abstract_self), classes) + let window = doc.window.root(&roots); + HTMLCollection::by_class_name(&window.root_ref(), NodeCast::from_ref(abstract_self), classes) } // http://dev.w3.org/csswg/cssom-view/#dom-element-getclientrects - pub fn GetClientRects(&self, abstract_self: &JS) -> JS { + pub fn GetClientRects(&self, abstract_self: &JSRef) -> JS { + let roots = RootCollection::new(); let doc = self.node.owner_doc(); - let win = &doc.get().window; - let node: JS = NodeCast::from(abstract_self); + let win = doc.get().window.root(&roots); + let node: JS = NodeCast::from(&abstract_self.unrooted()); let rects = node.get_content_boxes(); let rects = rects.iter().map(|r| { ClientRect::new( - win, + &win.root_ref(), r.origin.y, r.origin.y + r.size.height, r.origin.x, r.origin.x + r.size.width) }).collect(); - ClientRectList::new(win, rects) + ClientRectList::new(&win.root_ref(), rects) } // http://dev.w3.org/csswg/cssom-view/#dom-element-getboundingclientrect - pub fn GetBoundingClientRect(&self, abstract_self: &JS) -> JS { + pub fn GetBoundingClientRect(&self, abstract_self: &JSRef) -> JS { + let roots = RootCollection::new(); let doc = self.node.owner_doc(); - let win = &doc.get().window; - let node: JS = NodeCast::from(abstract_self); + let win = doc.get().window.root(&roots); + let node: JS = NodeCast::from(&abstract_self.unrooted()); let rect = node.get_bounding_content_box(); ClientRect::new( - win, + &win.root_ref(), rect.origin.y, rect.origin.y + rect.size.height, rect.origin.x, rect.origin.x + rect.size.width) } - pub fn GetInnerHTML(&self, abstract_self: &JS) -> Fallible { + pub fn GetInnerHTML(&self, abstract_self: &JSRef) -> Fallible { //XXX TODO: XML case - Ok(serialize(&mut NodeIterator::new(NodeCast::from(abstract_self), false, false))) + Ok(serialize(&mut NodeIterator::new(NodeCast::from(&abstract_self.unrooted()), false, false))) } - pub fn GetOuterHTML(&self, abstract_self: &JS) -> Fallible { - Ok(serialize(&mut NodeIterator::new(NodeCast::from(abstract_self), true, false))) + pub fn GetOuterHTML(&self, abstract_self: &JSRef) -> Fallible { + Ok(serialize(&mut NodeIterator::new(NodeCast::from(&abstract_self.unrooted()), true, false))) } - pub fn Children(&self, abstract_self: &JS) -> JS { - let doc = self.node.owner_doc(); - let doc = doc.get(); - HTMLCollection::children(&doc.window, &NodeCast::from(abstract_self)) + pub fn Children(&self, abstract_self: &JSRef) -> JS { + let roots = RootCollection::new(); + let window = window_from_node(&abstract_self.unrooted()).root(&roots); + HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self)) } } @@ -667,6 +681,7 @@ impl VirtualMethods for JS { } fn after_set_attr(&mut self, name: DOMString, value: DOMString) { + let roots = RootCollection::new(); match self.super_type() { Some(ref mut s) => s.after_set_attr(name.clone(), value.clone()), _ => (), @@ -684,7 +699,8 @@ impl VirtualMethods for JS { // "borrowed value does not live long enough" let mut doc = node.get().owner_doc().clone(); let doc = doc.get_mut(); - doc.register_named_element(self, value.clone()); + let elem = self.root(&roots); + doc.register_named_element(&elem.root_ref(), value.clone()); } _ => () } @@ -693,6 +709,7 @@ impl VirtualMethods for JS { } fn before_remove_attr(&mut self, name: DOMString, value: DOMString) { + let roots = RootCollection::new(); match self.super_type() { Some(ref mut s) => s.before_remove_attr(name.clone(), value.clone()), _ => (), @@ -708,7 +725,8 @@ impl VirtualMethods for JS { // "borrowed value does not live long enough" let mut doc = node.get().owner_doc().clone(); let doc = doc.get_mut(); - doc.unregister_named_element(self, value); + let elem = self.root(&roots); + doc.unregister_named_element(&elem.root_ref(), value); } _ => () } @@ -717,6 +735,7 @@ impl VirtualMethods for JS { } fn bind_to_tree(&mut self) { + let roots = RootCollection::new(); match self.super_type() { Some(ref mut s) => s.bind_to_tree(), _ => (), @@ -725,13 +744,15 @@ impl VirtualMethods for JS { match self.get_attribute(Null, "id") { Some(attr) => { let mut doc = document_from_node(self); - doc.get_mut().register_named_element(self, attr.get().Value()); + let elem = self.root(&roots); + doc.get_mut().register_named_element(&elem.root_ref(), attr.get().Value()); } _ => () } } fn unbind_from_tree(&mut self) { + let roots = RootCollection::new(); match self.super_type() { Some(ref mut s) => s.unbind_from_tree(), _ => (), @@ -740,7 +761,8 @@ impl VirtualMethods for JS { match self.get_attribute(Null, "id") { Some(attr) => { let mut doc = document_from_node(self); - doc.get_mut().unregister_named_element(self, attr.get().Value()); + let elem = self.root(&roots); + doc.get_mut().unregister_named_element(&elem.root_ref(), attr.get().Value()); } _ => () } diff --git a/src/components/script/dom/event.rs b/src/components/script/dom/event.rs index 22be9c3def0..89c250dbc95 100644 --- a/src/components/script/dom/event.rs +++ b/src/components/script/dom/event.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::EventBinding; use dom::bindings::codegen::BindingDeclarations::EventBinding::EventConstants; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::Fallible; use dom::eventtarget::EventTarget; @@ -80,7 +80,7 @@ impl Event { } } - pub fn new(window: &JS) -> JS { + pub fn new(window: &JSRef) -> JS { reflect_dom_object(~Event::new_inherited(HTMLEventTypeId), window, EventBinding::Wrap) @@ -155,7 +155,7 @@ impl Event { self.trusted } - pub fn Constructor(global: &JS, + pub fn Constructor(global: &JSRef, type_: DOMString, init: &EventBinding::EventInit) -> Fallible> { let mut ev = Event::new(global); diff --git a/src/components/script/dom/eventdispatcher.rs b/src/components/script/dom/eventdispatcher.rs index d298ab38492..b8fbce59974 100644 --- a/src/components/script/dom/eventdispatcher.rs +++ b/src/components/script/dom/eventdispatcher.rs @@ -4,21 +4,23 @@ use dom::bindings::callback::ReportExceptions; use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, NodeDerived}; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::eventtarget::{Capturing, Bubbling, EventTarget}; use dom::event::{Event, PhaseAtTarget, PhaseNone, PhaseBubbling, PhaseCapturing}; use dom::node::{Node, NodeHelpers}; // See http://dom.spec.whatwg.org/#concept-event-dispatch for the full dispatch algorithm -pub fn dispatch_event(target: &JS, - pseudo_target: Option>, - event: &mut JS) -> bool { +pub fn dispatch_event(target: &JSRef, + pseudo_target: Option>, + event: &mut JSRef) -> bool { assert!(!event.get().dispatching); { let event = event.get_mut(); - event.target = pseudo_target.or_else(|| { - Some(target.clone()) + event.target = pseudo_target.map(|pseudo_target| { + pseudo_target.unrooted() + }).or_else(|| { + Some(target.unrooted()) }); event.dispatching = true; } @@ -27,7 +29,7 @@ pub fn dispatch_event(target: &JS, //TODO: no chain if not participating in a tree let chain: Vec> = if target.get().is_node() { - let target_node: JS = NodeCast::to(target).unwrap(); + let target_node: JS = NodeCast::to(&target.unrooted()).unwrap(); target_node.ancestors().map(|ancestor| { let ancestor_target: JS = EventTargetCast::from(&ancestor); ancestor_target @@ -70,7 +72,7 @@ pub fn dispatch_event(target: &JS, { let event = event.get_mut(); event.phase = PhaseAtTarget; - event.current_target = Some(target.clone()); + event.current_target = Some(target.unrooted()); } let opt_listeners = target.get().get_listeners(type_); diff --git a/src/components/script/dom/eventtarget.rs b/src/components/script/dom/eventtarget.rs index 5214aa0aa69..b77834e7cc4 100644 --- a/src/components/script/dom/eventtarget.rs +++ b/src/components/script/dom/eventtarget.rs @@ -2,7 +2,7 @@ * 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; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::utils::{Reflectable, Reflector}; use dom::bindings::error::{Fallible, InvalidState}; use dom::bindings::codegen::BindingDeclarations::EventListenerBinding; @@ -102,15 +102,15 @@ impl EventTarget { } } - pub fn DispatchEvent(&self, abstract_self: &JS, - event: &mut JS) -> Fallible { + pub fn DispatchEvent(&self, abstract_self: &JSRef, + event: &mut JSRef) -> Fallible { self.dispatch_event_with_target(abstract_self, None, event) } pub fn dispatch_event_with_target(&self, - abstract_self: &JS, - abstract_target: Option>, - event: &mut JS) -> Fallible { + abstract_self: &JSRef, + abstract_target: Option>, + event: &mut JSRef) -> Fallible { if event.get().dispatching || !event.get().initialized { return Err(InvalidState); } diff --git a/src/components/script/dom/formdata.rs b/src/components/script/dom/formdata.rs index 140c70a12d2..4b6d61c1d82 100644 --- a/src/components/script/dom/formdata.rs +++ b/src/components/script/dom/formdata.rs @@ -5,7 +5,7 @@ use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::{Fallible}; use dom::bindings::codegen::BindingDeclarations::FormDataBinding; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::blob::Blob; use dom::htmlformelement::HTMLFormElement; use dom::window::Window; @@ -28,27 +28,27 @@ pub struct FormData { } impl FormData { - pub fn new_inherited(form: Option>, window: JS) -> FormData { + pub fn new_inherited(form: Option>, window: JS) -> FormData { FormData { data: HashMap::new(), reflector_: Reflector::new(), window: window, - form: form + form: form.map(|form| form.unrooted()) } } - pub fn new(form: Option>, window: &JS) -> JS { - reflect_dom_object(~FormData::new_inherited(form, window.clone()), window, FormDataBinding::Wrap) + pub fn new(form: Option>, window: &JSRef) -> JS { + reflect_dom_object(~FormData::new_inherited(form, window.unrooted()), window, FormDataBinding::Wrap) } - pub fn Constructor(window: &JS, form: Option>) + pub fn Constructor(window: &JSRef, form: Option>) -> Fallible> { Ok(FormData::new(form, window)) } - pub fn Append(&mut self, name: DOMString, value: &JS, filename: Option) { + pub fn Append(&mut self, name: DOMString, value: &JSRef, filename: Option) { let blob = BlobData { - blob: value.clone(), + blob: value.unrooted(), name: filename.unwrap_or(~"default") }; self.data.insert(name.clone(), blob); diff --git a/src/components/script/dom/htmlanchorelement.rs b/src/components/script/dom/htmlanchorelement.rs index c773e8b55b1..7edd9116dea 100644 --- a/src/components/script/dom/htmlanchorelement.rs +++ b/src/components/script/dom/htmlanchorelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLAnchorElementBinding; use dom::bindings::codegen::InheritTypes::HTMLAnchorElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLAnchorElementTypeId; @@ -34,8 +34,8 @@ impl HTMLAnchorElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLAnchorElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLAnchorElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLAnchorElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlappletelement.rs b/src/components/script/dom/htmlappletelement.rs index a6b4de0e21f..d2b9fcf2e80 100644 --- a/src/components/script/dom/htmlappletelement.rs +++ b/src/components/script/dom/htmlappletelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLAppletElementBinding; use dom::bindings::codegen::InheritTypes::HTMLAppletElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLAppletElementTypeId; @@ -34,8 +34,8 @@ impl HTMLAppletElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLAppletElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLAppletElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLAppletElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlareaelement.rs b/src/components/script/dom/htmlareaelement.rs index e50ad671023..f4950d46ad7 100644 --- a/src/components/script/dom/htmlareaelement.rs +++ b/src/components/script/dom/htmlareaelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLAreaElementBinding; use dom::bindings::codegen::InheritTypes::HTMLAreaElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLAreaElementTypeId; @@ -34,8 +34,8 @@ impl HTMLAreaElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLAreaElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLAreaElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLAreaElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlaudioelement.rs b/src/components/script/dom/htmlaudioelement.rs index 20a36b60749..2b0b86a36f1 100644 --- a/src/components/script/dom/htmlaudioelement.rs +++ b/src/components/script/dom/htmlaudioelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLAudioElementBinding; use dom::bindings::codegen::InheritTypes::HTMLAudioElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::document::Document; use dom::element::HTMLAudioElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,8 +33,8 @@ impl HTMLAudioElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLAudioElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLAudioElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLAudioElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlbaseelement.rs b/src/components/script/dom/htmlbaseelement.rs index bedfd156284..c7d206f3c65 100644 --- a/src/components/script/dom/htmlbaseelement.rs +++ b/src/components/script/dom/htmlbaseelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLBaseElementBinding; use dom::bindings::codegen::InheritTypes::HTMLBaseElementDerived; use dom::bindings::error::ErrorResult; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::document::Document; use dom::element::HTMLBaseElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -34,8 +34,8 @@ impl HTMLBaseElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLBaseElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLBaseElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLBaseElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlbodyelement.rs b/src/components/script/dom/htmlbodyelement.rs index 6e7e0349e40..466c60c6430 100644 --- a/src/components/script/dom/htmlbodyelement.rs +++ b/src/components/script/dom/htmlbodyelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLBodyElementBinding; use dom::bindings::codegen::InheritTypes::HTMLBodyElementDerived; use dom::bindings::error::ErrorResult; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::document::Document; use dom::element::HTMLBodyElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -34,8 +34,8 @@ impl HTMLBodyElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLBodyElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLBodyElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLBodyElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlbrelement.rs b/src/components/script/dom/htmlbrelement.rs index 1cf175468ae..e537b1b2c2a 100644 --- a/src/components/script/dom/htmlbrelement.rs +++ b/src/components/script/dom/htmlbrelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLBRElementBinding; use dom::bindings::codegen::InheritTypes::HTMLBRElementDerived; use dom::bindings::error::ErrorResult; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::document::Document; use dom::element::HTMLBRElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -34,8 +34,8 @@ impl HTMLBRElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLBRElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLBRElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLBRElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlbuttonelement.rs b/src/components/script/dom/htmlbuttonelement.rs index d40fdbe94be..cee5e13946c 100644 --- a/src/components/script/dom/htmlbuttonelement.rs +++ b/src/components/script/dom/htmlbuttonelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLButtonElementBinding; use dom::bindings::codegen::InheritTypes::HTMLButtonElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLButtonElementTypeId; @@ -36,8 +36,8 @@ impl HTMLButtonElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLButtonElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLButtonElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLButtonElementBinding::Wrap) } } @@ -135,9 +135,10 @@ impl HTMLButtonElement { } pub fn Validity(&self) -> JS { + let roots = RootCollection::new(); let doc = self.htmlelement.element.node.owner_doc(); let doc = doc.get(); - ValidityState::new(&doc.window) + ValidityState::new(&doc.window.root(&roots).root_ref()) } pub fn SetValidity(&mut self, _validity: JS) { diff --git a/src/components/script/dom/htmlcanvaselement.rs b/src/components/script/dom/htmlcanvaselement.rs index 6bf26adc593..4c825780216 100644 --- a/src/components/script/dom/htmlcanvaselement.rs +++ b/src/components/script/dom/htmlcanvaselement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLCanvasElementBinding; use dom::bindings::codegen::InheritTypes::HTMLCanvasElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::{ErrorResult}; use dom::document::Document; use dom::element::HTMLCanvasElementTypeId; @@ -34,8 +34,8 @@ impl HTMLCanvasElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLCanvasElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLCanvasElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLCanvasElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlcollection.rs b/src/components/script/dom/htmlcollection.rs index 79b35487634..8529d4daf64 100644 --- a/src/components/script/dom/htmlcollection.rs +++ b/src/components/script/dom/htmlcollection.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast}; use dom::bindings::codegen::BindingDeclarations::HTMLCollectionBinding; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::element::{Element, AttributeHandlers}; use dom::node::{Node, NodeHelpers}; @@ -15,7 +15,7 @@ use servo_util::str::{DOMString, split_html_space_chars}; use serialize::{Encoder, Encodable}; pub trait CollectionFilter { - fn filter(&self, elem: &JS, root: &JS) -> bool; + fn filter(&self, elem: &JSRef, root: &JSRef) -> bool; } impl, E> Encodable for ~CollectionFilter { @@ -46,24 +46,24 @@ impl HTMLCollection { } } - pub fn new(window: &JS, collection: CollectionTypeId) -> JS { - reflect_dom_object(~HTMLCollection::new_inherited(window.clone(), collection), + pub fn new(window: &JSRef, collection: CollectionTypeId) -> JS { + reflect_dom_object(~HTMLCollection::new_inherited(window.unrooted(), collection), window, HTMLCollectionBinding::Wrap) } } impl HTMLCollection { - pub fn create(window: &JS, root: &JS, filter: ~CollectionFilter) -> JS { - HTMLCollection::new(window, Live(root.clone(), filter)) + pub fn create(window: &JSRef, root: &JSRef, filter: ~CollectionFilter) -> JS { + HTMLCollection::new(window, Live(root.unrooted(), filter)) } - pub fn by_tag_name(window: &JS, root: &JS, tag: DOMString) + pub fn by_tag_name(window: &JSRef, root: &JSRef, tag: DOMString) -> JS { struct TagNameFilter { tag: DOMString } impl CollectionFilter for TagNameFilter { - fn filter(&self, elem: &JS, _root: &JS) -> bool { + fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { elem.get().local_name == self.tag } } @@ -73,14 +73,14 @@ impl HTMLCollection { HTMLCollection::create(window, root, ~filter) } - pub fn by_tag_name_ns(window: &JS, root: &JS, tag: DOMString, + pub fn by_tag_name_ns(window: &JSRef, root: &JSRef, tag: DOMString, namespace: Namespace) -> JS { struct TagNameNSFilter { tag: DOMString, namespace: Namespace } impl CollectionFilter for TagNameNSFilter { - fn filter(&self, elem: &JS, _root: &JS) -> bool { + fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { elem.get().namespace == self.namespace && elem.get().local_name == self.tag } } @@ -91,14 +91,14 @@ impl HTMLCollection { HTMLCollection::create(window, root, ~filter) } - pub fn by_class_name(window: &JS, root: &JS, classes: DOMString) + pub fn by_class_name(window: &JSRef, root: &JSRef, classes: DOMString) -> JS { struct ClassNameFilter { classes: Vec } impl CollectionFilter for ClassNameFilter { - fn filter(&self, elem: &JS, _root: &JS) -> bool { - self.classes.iter().all(|class| elem.has_class(*class)) + fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { + self.classes.iter().all(|class| elem.unrooted().has_class(*class)) } } let filter = ClassNameFilter { @@ -107,11 +107,11 @@ impl HTMLCollection { HTMLCollection::create(window, root, ~filter) } - pub fn children(window: &JS, root: &JS) -> JS { + pub fn children(window: &JSRef, root: &JSRef) -> JS { struct ElementChildFilter; impl CollectionFilter for ElementChildFilter { - fn filter(&self, elem: &JS, root: &JS) -> bool { - root.is_parent_of(&NodeCast::from(elem)) + fn filter(&self, elem: &JSRef, root: &JSRef) -> bool { + root.unrooted().is_parent_of(NodeCast::from_ref(elem)) } } HTMLCollection::create(window, root, ~ElementChildFilter) @@ -121,32 +121,47 @@ impl HTMLCollection { impl HTMLCollection { // http://dom.spec.whatwg.org/#dom-htmlcollection-length pub fn Length(&self) -> u32 { + let roots = RootCollection::new(); match self.collection { Static(ref elems) => elems.len() as u32, - Live(ref root, ref filter) => root.traverse_preorder() - .count(|child| { - let elem: Option> = ElementCast::to(&child); - elem.map_or(false, |elem| filter.filter(&elem, root)) - }) as u32 + Live(ref root, ref filter) => { + let root_root = root.root(&roots); + root.traverse_preorder() + .count(|child| { + let elem: Option> = ElementCast::to(&child); + elem.map_or(false, |elem| { + let elem = elem.root(&roots); + filter.filter(&elem.root_ref(), &root_root.root_ref()) + }) + }) as u32 + } } } // http://dom.spec.whatwg.org/#dom-htmlcollection-item pub fn Item(&self, index: u32) -> Option> { + let roots = RootCollection::new(); match self.collection { Static(ref elems) => elems .as_slice() .get(index as uint) .map(|elem| elem.clone()), - Live(ref root, ref filter) => root.traverse_preorder() - .filter_map(|node| ElementCast::to(&node)) - .filter(|elem| filter.filter(elem, root)) - .nth(index as uint).clone() + Live(ref root, ref filter) => { + let root_root = root.root(&roots); + root.traverse_preorder() + .filter_map(|node| ElementCast::to(&node)) + .filter(|elem| { + let elem = elem.root(&roots); + filter.filter(&elem.root_ref(), &root_root.root_ref()) + }) + .nth(index as uint).clone() + } } } // http://dom.spec.whatwg.org/#dom-htmlcollection-nameditem pub fn NamedItem(&self, key: DOMString) -> Option> { + let roots = RootCollection::new(); // Step 1. if key.is_empty() { return None; @@ -159,13 +174,19 @@ impl HTMLCollection { elem.get_string_attribute("name") == key || elem.get_string_attribute("id") == key }) .map(|maybe_elem| maybe_elem.clone()), - Live(ref root, ref filter) => root.traverse_preorder() - .filter_map(|node| ElementCast::to(&node)) - .filter(|elem| filter.filter(elem, root)) - .find(|elem| { - elem.get_string_attribute("name") == key || - elem.get_string_attribute("id") == key }) - .map(|maybe_elem| maybe_elem.clone()) + Live(ref root, ref filter) => { + let root_root = root.root(&roots); + root.traverse_preorder() + .filter_map(|node| ElementCast::to(&node)) + .filter(|elem| { + let elem = elem.root(&roots); + filter.filter(&elem.root_ref(), &root_root.root_ref()) + }) + .find(|elem| { + elem.get_string_attribute("name") == key || + elem.get_string_attribute("id") == key }) + .map(|maybe_elem| maybe_elem.clone()) + } } } } diff --git a/src/components/script/dom/htmldataelement.rs b/src/components/script/dom/htmldataelement.rs index e242be54d9d..b95c77acc07 100644 --- a/src/components/script/dom/htmldataelement.rs +++ b/src/components/script/dom/htmldataelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDataElementBinding; use dom::bindings::codegen::InheritTypes::HTMLDataElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLDataElementTypeId; @@ -34,8 +34,8 @@ impl HTMLDataElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLDataElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLDataElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLDataElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmldatalistelement.rs b/src/components/script/dom/htmldatalistelement.rs index 7a5d5329b18..b341a34dcb0 100644 --- a/src/components/script/dom/htmldatalistelement.rs +++ b/src/components/script/dom/htmldatalistelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDataListElementBinding; use dom::bindings::codegen::InheritTypes::{HTMLDataListElementDerived, NodeCast}; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::document::Document; use dom::element::{Element, HTMLDataListElementTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -34,22 +34,24 @@ impl HTMLDataListElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLDataListElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLDataListElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLDataListElementBinding::Wrap) } } impl HTMLDataListElement { - pub fn Options(&self, abstract_self: &JS) -> JS { + pub fn Options(&self, abstract_self: &JSRef) -> JS { struct HTMLDataListOptionsFilter; impl CollectionFilter for HTMLDataListOptionsFilter { - fn filter(&self, elem: &JS, _root: &JS) -> bool { + fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { elem.get().local_name == ~"option" } } - let node: JS = NodeCast::from(abstract_self); + let roots = RootCollection::new(); + let node: &JSRef = NodeCast::from_ref(abstract_self); let filter = ~HTMLDataListOptionsFilter; - HTMLCollection::create(&window_from_node(&node), &node, filter) + let window = window_from_node(&node.unrooted()).root(&roots); + HTMLCollection::create(&window.root_ref(), node, filter) } } diff --git a/src/components/script/dom/htmldirectoryelement.rs b/src/components/script/dom/htmldirectoryelement.rs index d356fb0bb51..84ee0b539b6 100644 --- a/src/components/script/dom/htmldirectoryelement.rs +++ b/src/components/script/dom/htmldirectoryelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDirectoryElementBinding; use dom::bindings::codegen::InheritTypes::HTMLDirectoryElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLDirectoryElementTypeId; @@ -34,8 +34,8 @@ impl HTMLDirectoryElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLDirectoryElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLDirectoryElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLDirectoryElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmldivelement.rs b/src/components/script/dom/htmldivelement.rs index e018a1a0c3c..723a2088307 100644 --- a/src/components/script/dom/htmldivelement.rs +++ b/src/components/script/dom/htmldivelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDivElementBinding; use dom::bindings::codegen::InheritTypes::HTMLDivElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLDivElementTypeId; @@ -34,8 +34,8 @@ impl HTMLDivElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLDivElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLDivElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLDivElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmldlistelement.rs b/src/components/script/dom/htmldlistelement.rs index f2f9784764e..8f3523189b7 100644 --- a/src/components/script/dom/htmldlistelement.rs +++ b/src/components/script/dom/htmldlistelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDListElementBinding; use dom::bindings::codegen::InheritTypes::HTMLDListElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLDListElementTypeId; @@ -34,8 +34,8 @@ impl HTMLDListElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLDListElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLDListElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLDListElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlelement.rs b/src/components/script/dom/htmlelement.rs index 61ebf7d1301..a7852aec276 100644 --- a/src/components/script/dom/htmlelement.rs +++ b/src/components/script/dom/htmlelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLElementBinding; use dom::bindings::codegen::InheritTypes::ElementCast; use dom::bindings::codegen::InheritTypes::HTMLElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::{ErrorResult, Fallible}; use dom::document::Document; use dom::element::{Element, ElementTypeId, HTMLElementTypeId}; @@ -39,8 +39,8 @@ impl HTMLElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLElement::new_inherited(HTMLElementTypeId, localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLElement::new_inherited(HTMLElementTypeId, localName, document.unrooted()); Node::reflect_node(~element, document, HTMLElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlembedelement.rs b/src/components/script/dom/htmlembedelement.rs index d0a2e436043..73a915c4cc7 100644 --- a/src/components/script/dom/htmlembedelement.rs +++ b/src/components/script/dom/htmlembedelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLEmbedElementBinding; use dom::bindings::codegen::InheritTypes::HTMLEmbedElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLEmbedElementTypeId; @@ -34,8 +34,8 @@ impl HTMLEmbedElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLEmbedElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLEmbedElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLEmbedElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlfieldsetelement.rs b/src/components/script/dom/htmlfieldsetelement.rs index 21116ee41fb..3b1141f403e 100644 --- a/src/components/script/dom/htmlfieldsetelement.rs +++ b/src/components/script/dom/htmlfieldsetelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFieldSetElementBinding; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLFieldSetElementDerived, NodeCast}; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLFieldSetElementTypeId}; @@ -37,8 +37,8 @@ impl HTMLFieldSetElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLFieldSetElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLFieldSetElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLFieldSetElementBinding::Wrap) } } @@ -69,19 +69,21 @@ impl HTMLFieldSetElement { } // http://www.whatwg.org/html/#dom-fieldset-elements - pub fn Elements(&self, abstract_self: &JS) -> JS { + pub fn Elements(&self, abstract_self: &JSRef) -> JS { struct ElementsFilter; impl CollectionFilter for ElementsFilter { - fn filter(&self, elem: &JS, root: &JS) -> bool { + fn filter(&self, elem: &JSRef, root: &JSRef) -> bool { static tag_names: StaticStringVec = &["button", "fieldset", "input", "keygen", "object", "output", "select", "textarea"]; - let root: &JS = &ElementCast::to(root).unwrap(); - elem != root && tag_names.iter().any(|&tag_name| tag_name == elem.get().local_name) + let root: &JS = &ElementCast::to(&root.unrooted()).unwrap(); + &elem.unrooted() != root && tag_names.iter().any(|&tag_name| tag_name == elem.get().local_name) } } - let node: JS = NodeCast::from(abstract_self); + let roots = RootCollection::new(); + let node: &JSRef = NodeCast::from_ref(abstract_self); let filter = ~ElementsFilter; - HTMLCollection::create(&window_from_node(&node), &node, filter) + let window = window_from_node(&node.unrooted()).root(&roots); + HTMLCollection::create(&window.root_ref(), node, filter) } pub fn WillValidate(&self) -> bool { @@ -89,9 +91,11 @@ impl HTMLFieldSetElement { } pub fn Validity(&self) -> JS { + let roots = RootCollection::new(); let doc = self.htmlelement.element.node.owner_doc(); let doc = doc.get(); - ValidityState::new(&doc.window) + let window = doc.window.root(&roots); + ValidityState::new(&window.root_ref()) } pub fn ValidationMessage(&self) -> DOMString { diff --git a/src/components/script/dom/htmlfontelement.rs b/src/components/script/dom/htmlfontelement.rs index 6eae087cdcd..f28971e7c43 100644 --- a/src/components/script/dom/htmlfontelement.rs +++ b/src/components/script/dom/htmlfontelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFontElementBinding; use dom::bindings::codegen::InheritTypes::HTMLFontElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLFontElementTypeId; @@ -34,8 +34,8 @@ impl HTMLFontElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLFontElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLFontElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLFontElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlformelement.rs b/src/components/script/dom/htmlformelement.rs index 3fdf2a4ba7f..0e7159c61b9 100644 --- a/src/components/script/dom/htmlformelement.rs +++ b/src/components/script/dom/htmlformelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFormElementBinding; use dom::bindings::codegen::InheritTypes::HTMLFormElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLFormElementTypeId}; @@ -35,8 +35,8 @@ impl HTMLFormElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLFormElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLFormElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLFormElementBinding::Wrap) } } @@ -116,9 +116,11 @@ impl HTMLFormElement { pub fn Elements(&self) -> JS { // FIXME: https://github.com/mozilla/servo/issues/1844 + let roots = RootCollection::new(); let doc = self.htmlelement.element.node.owner_doc(); let doc = doc.get(); - HTMLCollection::new(&doc.window, Static(vec!())) + let window = doc.window.root(&roots); + HTMLCollection::new(&window.root_ref(), Static(vec!())) } pub fn Length(&self) -> i32 { diff --git a/src/components/script/dom/htmlframeelement.rs b/src/components/script/dom/htmlframeelement.rs index a0ac8293ff7..535c0398690 100644 --- a/src/components/script/dom/htmlframeelement.rs +++ b/src/components/script/dom/htmlframeelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFrameElementBinding; use dom::bindings::codegen::InheritTypes::HTMLFrameElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLFrameElementTypeId; @@ -35,8 +35,8 @@ impl HTMLFrameElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLFrameElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLFrameElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLFrameElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlframesetelement.rs b/src/components/script/dom/htmlframesetelement.rs index 3d7297ca6ec..29691e01397 100644 --- a/src/components/script/dom/htmlframesetelement.rs +++ b/src/components/script/dom/htmlframesetelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFrameSetElementBinding; use dom::bindings::codegen::InheritTypes::HTMLFrameSetElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLFrameSetElementTypeId; @@ -34,8 +34,8 @@ impl HTMLFrameSetElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLFrameSetElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLFrameSetElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLFrameSetElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlheadelement.rs b/src/components/script/dom/htmlheadelement.rs index bf0b3f3d9b8..3f2037d7188 100644 --- a/src/components/script/dom/htmlheadelement.rs +++ b/src/components/script/dom/htmlheadelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLHeadElementBinding; use dom::bindings::codegen::InheritTypes::HTMLHeadElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::document::Document; use dom::element::HTMLHeadElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,8 +33,8 @@ impl HTMLHeadElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLHeadElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLHeadElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLHeadElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlheadingelement.rs b/src/components/script/dom/htmlheadingelement.rs index 5bf9ac39f55..40844eb36e5 100644 --- a/src/components/script/dom/htmlheadingelement.rs +++ b/src/components/script/dom/htmlheadingelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLHeadingElementBinding; use dom::bindings::codegen::InheritTypes::HTMLHeadingElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::document::Document; use dom::element::HTMLHeadingElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -45,8 +45,8 @@ impl HTMLHeadingElement { } } - pub fn new(localName: DOMString, document: &JS, level: HeadingLevel) -> JS { - let element = HTMLHeadingElement::new_inherited(localName, document.clone(), level); + pub fn new(localName: DOMString, document: &JSRef, level: HeadingLevel) -> JS { + let element = HTMLHeadingElement::new_inherited(localName, document.unrooted(), level); Node::reflect_node(~element, document, HTMLHeadingElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlhrelement.rs b/src/components/script/dom/htmlhrelement.rs index 25315450c5a..28bdd2ed3de 100644 --- a/src/components/script/dom/htmlhrelement.rs +++ b/src/components/script/dom/htmlhrelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLHRElementBinding; use dom::bindings::codegen::InheritTypes::HTMLHRElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLHRElementTypeId; @@ -34,8 +34,8 @@ impl HTMLHRElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLHRElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLHRElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLHRElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlhtmlelement.rs b/src/components/script/dom/htmlhtmlelement.rs index b88639b3c59..391bf7b2465 100644 --- a/src/components/script/dom/htmlhtmlelement.rs +++ b/src/components/script/dom/htmlhtmlelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLHtmlElementBinding; use dom::bindings::codegen::InheritTypes::HTMLHtmlElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLHtmlElementTypeId; @@ -34,8 +34,8 @@ impl HTMLHtmlElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLHtmlElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLHtmlElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLHtmlElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmliframeelement.rs b/src/components/script/dom/htmliframeelement.rs index 99ddf3d30f2..c037f17f9a5 100644 --- a/src/components/script/dom/htmliframeelement.rs +++ b/src/components/script/dom/htmliframeelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLIFrameElementBinding; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLIFrameElementDerived, HTMLElementCast}; use dom::bindings::error::ErrorResult; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::trace::Untraceable; use dom::document::Document; use dom::element::{HTMLIFrameElementTypeId, Element}; @@ -74,8 +74,8 @@ impl HTMLIFrameElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLIFrameElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLIFrameElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLIFrameElementBinding::Wrap) } } @@ -105,13 +105,13 @@ impl HTMLIFrameElement { Ok(()) } - pub fn Sandbox(&self, abstract_self: &JS) -> DOMString { - let element: JS = ElementCast::from(abstract_self); + pub fn Sandbox(&self, abstract_self: &JSRef) -> DOMString { + let element: JS = ElementCast::from(&abstract_self.unrooted()); element.get_string_attribute("sandbox") } - pub fn SetSandbox(&mut self, abstract_self: &mut JS, sandbox: DOMString) { - let mut element: JS = ElementCast::from(abstract_self); + pub fn SetSandbox(&mut self, abstract_self: &mut JSRef, sandbox: DOMString) { + let mut element: JS = ElementCast::from(&abstract_self.unrooted()); element.set_string_attribute("sandbox", sandbox); } diff --git a/src/components/script/dom/htmlimageelement.rs b/src/components/script/dom/htmlimageelement.rs index 6bb7096fcde..d986f5d07e8 100644 --- a/src/components/script/dom/htmlimageelement.rs +++ b/src/components/script/dom/htmlimageelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLImageElementBinding; use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast, HTMLElementCast, HTMLImageElementDerived}; use dom::bindings::error::ErrorResult; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::trace::Untraceable; use dom::document::Document; use dom::element::{Element, HTMLImageElementTypeId}; @@ -43,8 +43,8 @@ impl HTMLImageElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLImageElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLImageElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLImageElementBinding::Wrap) } } @@ -79,23 +79,23 @@ impl HTMLImageElement { } } - pub fn Alt(&self, abstract_self: &JS) -> DOMString { - let element: JS = ElementCast::from(abstract_self); + pub fn Alt(&self, abstract_self: &JSRef) -> DOMString { + let element: JS = ElementCast::from(&abstract_self.unrooted()); element.get_string_attribute("alt") } - pub fn SetAlt(&mut self, abstract_self: &JS, alt: DOMString) { - let mut element: JS = ElementCast::from(abstract_self); + pub fn SetAlt(&mut self, abstract_self: &JSRef, alt: DOMString) { + let mut element: JS = ElementCast::from(&abstract_self.unrooted()); element.set_string_attribute("alt", alt) } - pub fn Src(&self, abstract_self: &JS) -> DOMString { - let element: JS = ElementCast::from(abstract_self); + pub fn Src(&self, abstract_self: &JSRef) -> DOMString { + let element: JS = ElementCast::from(&abstract_self.unrooted()); element.get_string_attribute("src") } - pub fn SetSrc(&mut self, abstract_self: &mut JS, src: DOMString) { - let mut element: JS = ElementCast::from(abstract_self); + pub fn SetSrc(&mut self, abstract_self: &mut JSRef, src: DOMString) { + let mut element: JS = ElementCast::from(&abstract_self.unrooted()); element.set_url_attribute("src", src) } @@ -107,45 +107,45 @@ impl HTMLImageElement { Ok(()) } - pub fn UseMap(&self, abstract_self: &JS) -> DOMString { - let element: JS = ElementCast::from(abstract_self); + pub fn UseMap(&self, abstract_self: &JSRef) -> DOMString { + let element: JS = ElementCast::from(&abstract_self.unrooted()); element.get_string_attribute("useMap") } - pub fn SetUseMap(&mut self, abstract_self: &mut JS, use_map: DOMString) { - let mut element: JS = ElementCast::from(abstract_self); + pub fn SetUseMap(&mut self, abstract_self: &mut JSRef, use_map: DOMString) { + let mut element: JS = ElementCast::from(&abstract_self.unrooted()); element.set_string_attribute("useMap", use_map) } - pub fn IsMap(&self, abstract_self: &JS) -> bool { - let element: JS = ElementCast::from(abstract_self); + pub fn IsMap(&self, abstract_self: &JSRef) -> bool { + let element: JS = ElementCast::from(&abstract_self.unrooted()); from_str::(element.get_string_attribute("hspace")).unwrap() } - pub fn SetIsMap(&self, abstract_self: &mut JS, is_map: bool) { - let mut element: JS = ElementCast::from(abstract_self); + pub fn SetIsMap(&self, abstract_self: &mut JSRef, is_map: bool) { + let mut element: JS = ElementCast::from(&abstract_self.unrooted()); element.set_string_attribute("isMap", is_map.to_str()) } - pub fn Width(&self, abstract_self: &JS) -> u32 { - let node: JS = NodeCast::from(abstract_self); + pub fn Width(&self, abstract_self: &JSRef) -> u32 { + let node: JS = NodeCast::from(&abstract_self.unrooted()); let rect = node.get_bounding_content_box(); to_px(rect.size.width) as u32 } - pub fn SetWidth(&mut self, abstract_self: &JS, width: u32) { - let mut elem: JS = ElementCast::from(abstract_self); + pub fn SetWidth(&mut self, abstract_self: &JSRef, width: u32) { + let mut elem: JS = ElementCast::from(&abstract_self.unrooted()); elem.set_uint_attribute("width", width) } - pub fn Height(&self, abstract_self: &JS) -> u32 { - let node: JS = NodeCast::from(abstract_self); + pub fn Height(&self, abstract_self: &JSRef) -> u32 { + let node: JS = NodeCast::from(&abstract_self.unrooted()); let rect = node.get_bounding_content_box(); to_px(rect.size.height) as u32 } - pub fn SetHeight(&mut self, abstract_self: &JS, height: u32) { - let mut elem: JS = ElementCast::from(abstract_self); + pub fn SetHeight(&mut self, abstract_self: &JSRef, height: u32) { + let mut elem: JS = ElementCast::from(&abstract_self.unrooted()); elem.set_uint_attribute("height", height) } @@ -161,63 +161,63 @@ impl HTMLImageElement { false } - pub fn Name(&self, abstract_self: &JS) -> DOMString { - let element: JS = ElementCast::from(abstract_self); + pub fn Name(&self, abstract_self: &JSRef) -> DOMString { + let element: JS = ElementCast::from(&abstract_self.unrooted()); element.get_string_attribute("name") } - pub fn SetName(&mut self, abstract_self: &mut JS, name: DOMString) { - let mut element: JS = ElementCast::from(abstract_self); + pub fn SetName(&mut self, abstract_self: &mut JSRef, name: DOMString) { + let mut element: JS = ElementCast::from(&abstract_self.unrooted()); element.set_string_attribute("name", name) } - pub fn Align(&self, abstract_self: &JS) -> DOMString { - let element: JS = ElementCast::from(abstract_self); + pub fn Align(&self, abstract_self: &JSRef) -> DOMString { + let element: JS = ElementCast::from(&abstract_self.unrooted()); element.get_string_attribute("longdesc") } - pub fn SetAlign(&mut self, abstract_self: &mut JS, align: DOMString) { - let mut element: JS = ElementCast::from(abstract_self); + pub fn SetAlign(&mut self, abstract_self: &mut JSRef, align: DOMString) { + let mut element: JS = ElementCast::from(&abstract_self.unrooted()); element.set_string_attribute("align", align) } - pub fn Hspace(&self, abstract_self: &JS) -> u32 { - let element: JS = ElementCast::from(abstract_self); + pub fn Hspace(&self, abstract_self: &JSRef) -> u32 { + let element: JS = ElementCast::from(&abstract_self.unrooted()); from_str::(element.get_string_attribute("hspace")).unwrap() } - pub fn SetHspace(&mut self, abstract_self: &mut JS, hspace: u32) { - let mut element: JS = ElementCast::from(abstract_self); + pub fn SetHspace(&mut self, abstract_self: &mut JSRef, hspace: u32) { + let mut element: JS = ElementCast::from(&abstract_self.unrooted()); element.set_uint_attribute("hspace", hspace) } - pub fn Vspace(&self, abstract_self: &JS) -> u32 { - let element: JS = ElementCast::from(abstract_self); + pub fn Vspace(&self, abstract_self: &JSRef) -> u32 { + let element: JS = ElementCast::from(&abstract_self.unrooted()); from_str::(element.get_string_attribute("vspace")).unwrap() } - pub fn SetVspace(&mut self, abstract_self: &mut JS, vspace: u32) { - let mut element: JS = ElementCast::from(abstract_self); + pub fn SetVspace(&mut self, abstract_self: &mut JSRef, vspace: u32) { + let mut element: JS = ElementCast::from(&abstract_self.unrooted()); element.set_uint_attribute("vspace", vspace) } - pub fn LongDesc(&self, abstract_self: &JS) -> DOMString { - let element: JS = ElementCast::from(abstract_self); + pub fn LongDesc(&self, abstract_self: &JSRef) -> DOMString { + let element: JS = ElementCast::from(&abstract_self.unrooted()); element.get_string_attribute("longdesc") } - pub fn SetLongDesc(&mut self, abstract_self: &mut JS, longdesc: DOMString) { - let mut element: JS = ElementCast::from(abstract_self); + pub fn SetLongDesc(&mut self, abstract_self: &mut JSRef, longdesc: DOMString) { + let mut element: JS = ElementCast::from(&abstract_self.unrooted()); element.set_string_attribute("longdesc", longdesc) } - pub fn Border(&self, abstract_self: &JS) -> DOMString { - let element: JS = ElementCast::from(abstract_self); + pub fn Border(&self, abstract_self: &JSRef) -> DOMString { + let element: JS = ElementCast::from(&abstract_self.unrooted()); element.get_string_attribute("border") } - pub fn SetBorder(&mut self, abstract_self: &mut JS, border: DOMString) { - let mut element: JS = ElementCast::from(abstract_self); + pub fn SetBorder(&mut self, abstract_self: &mut JSRef, border: DOMString) { + let mut element: JS = ElementCast::from(&abstract_self.unrooted()); element.set_string_attribute("border", border) } } diff --git a/src/components/script/dom/htmlinputelement.rs b/src/components/script/dom/htmlinputelement.rs index 978ce8a0d63..90914fbc7bb 100644 --- a/src/components/script/dom/htmlinputelement.rs +++ b/src/components/script/dom/htmlinputelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLInputElementBinding; use dom::bindings::codegen::InheritTypes::HTMLInputElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::{ErrorResult, Fallible}; use dom::document::Document; use dom::element::HTMLInputElementTypeId; @@ -34,8 +34,8 @@ impl HTMLInputElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLInputElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLInputElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLInputElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmllabelelement.rs b/src/components/script/dom/htmllabelelement.rs index 70c811c949e..5c920fd75eb 100644 --- a/src/components/script/dom/htmllabelelement.rs +++ b/src/components/script/dom/htmllabelelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLLabelElementBinding; use dom::bindings::codegen::InheritTypes::HTMLLabelElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::document::Document; use dom::element::HTMLLabelElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,8 +33,8 @@ impl HTMLLabelElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLLabelElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLLabelElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLLabelElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmllegendelement.rs b/src/components/script/dom/htmllegendelement.rs index a8fdf6a1405..ee6199808eb 100644 --- a/src/components/script/dom/htmllegendelement.rs +++ b/src/components/script/dom/htmllegendelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLLegendElementBinding; use dom::bindings::codegen::InheritTypes::HTMLLegendElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLLegendElementTypeId; @@ -34,8 +34,8 @@ impl HTMLLegendElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLLegendElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLLegendElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLLegendElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmllielement.rs b/src/components/script/dom/htmllielement.rs index 052557545ea..2a7501b08e9 100644 --- a/src/components/script/dom/htmllielement.rs +++ b/src/components/script/dom/htmllielement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLLIElementBinding; use dom::bindings::codegen::InheritTypes::HTMLLIElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLLIElementTypeId; @@ -34,8 +34,8 @@ impl HTMLLIElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLLIElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLLIElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLLIElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmllinkelement.rs b/src/components/script/dom/htmllinkelement.rs index ae47e5168a2..528ea303a2c 100644 --- a/src/components/script/dom/htmllinkelement.rs +++ b/src/components/script/dom/htmllinkelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLLinkElementBinding; use dom::bindings::codegen::InheritTypes::HTMLLinkElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLLinkElementTypeId; @@ -34,8 +34,8 @@ impl HTMLLinkElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLLinkElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLLinkElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLLinkElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlmainelement.rs b/src/components/script/dom/htmlmainelement.rs index 182a3194019..74bc99c0149 100644 --- a/src/components/script/dom/htmlmainelement.rs +++ b/src/components/script/dom/htmlmainelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLMainElementBinding; use dom::bindings::codegen::InheritTypes::HTMLMainElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::document::Document; use dom::element::HTMLMainElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,8 +33,8 @@ impl HTMLMainElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLMainElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLMainElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLMainElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlmapelement.rs b/src/components/script/dom/htmlmapelement.rs index 72214f0ff1d..aff393505af 100644 --- a/src/components/script/dom/htmlmapelement.rs +++ b/src/components/script/dom/htmlmapelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLMapElementBinding; use dom::bindings::codegen::InheritTypes::HTMLMapElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLMapElementTypeId; @@ -35,8 +35,8 @@ impl HTMLMapElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLMapElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLMapElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLMapElementBinding::Wrap) } } @@ -51,9 +51,11 @@ impl HTMLMapElement { } pub fn Areas(&self) -> JS { + let roots = RootCollection::new(); // FIXME: https://github.com/mozilla/servo/issues/1845 let doc = self.htmlelement.element.node.owner_doc(); let doc = doc.get(); - HTMLCollection::new(&doc.window, Static(vec!())) + let window = doc.window.root(&roots); + HTMLCollection::new(&window.root_ref(), Static(vec!())) } } diff --git a/src/components/script/dom/htmlmetaelement.rs b/src/components/script/dom/htmlmetaelement.rs index 3ecba0013d2..191a49f2444 100644 --- a/src/components/script/dom/htmlmetaelement.rs +++ b/src/components/script/dom/htmlmetaelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLMetaElementBinding; use dom::bindings::codegen::InheritTypes::HTMLMetaElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLMetaElementTypeId; @@ -34,8 +34,8 @@ impl HTMLMetaElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLMetaElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLMetaElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLMetaElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlmeterelement.rs b/src/components/script/dom/htmlmeterelement.rs index 044c4785cb8..19bac1c9797 100644 --- a/src/components/script/dom/htmlmeterelement.rs +++ b/src/components/script/dom/htmlmeterelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLMeterElementBinding; use dom::bindings::codegen::InheritTypes::HTMLMeterElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLMeterElementTypeId; @@ -34,8 +34,8 @@ impl HTMLMeterElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLMeterElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLMeterElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLMeterElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlmodelement.rs b/src/components/script/dom/htmlmodelement.rs index a656b891b1b..b934ef74b86 100644 --- a/src/components/script/dom/htmlmodelement.rs +++ b/src/components/script/dom/htmlmodelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLModElementBinding; use dom::bindings::codegen::InheritTypes::HTMLModElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLModElementTypeId; @@ -34,8 +34,8 @@ impl HTMLModElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLModElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLModElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLModElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlobjectelement.rs b/src/components/script/dom/htmlobjectelement.rs index e2c7d16c03d..f3f48cba313 100644 --- a/src/components/script/dom/htmlobjectelement.rs +++ b/src/components/script/dom/htmlobjectelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLObjectElementBinding; use dom::bindings::codegen::InheritTypes::HTMLObjectElementDerived; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast}; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLObjectElementTypeId}; @@ -47,8 +47,8 @@ impl HTMLObjectElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLObjectElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLObjectElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLObjectElementBinding::Wrap) } } @@ -144,9 +144,11 @@ impl HTMLObjectElement { } pub fn Validity(&self) -> JS { + let roots = RootCollection::new(); let doc = self.htmlelement.element.node.owner_doc(); let doc = doc.get(); - ValidityState::new(&doc.window) + let window = doc.window.root(&roots); + ValidityState::new(&window.root_ref()) } pub fn ValidationMessage(&self) -> DOMString { diff --git a/src/components/script/dom/htmlolistelement.rs b/src/components/script/dom/htmlolistelement.rs index ced7b98edb4..a62acc013c6 100644 --- a/src/components/script/dom/htmlolistelement.rs +++ b/src/components/script/dom/htmlolistelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLOListElementBinding; use dom::bindings::codegen::InheritTypes::HTMLOListElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLOListElementTypeId; @@ -34,8 +34,8 @@ impl HTMLOListElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLOListElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLOListElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLOListElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmloptgroupelement.rs b/src/components/script/dom/htmloptgroupelement.rs index dfddb3e2546..3ef4df88ab9 100644 --- a/src/components/script/dom/htmloptgroupelement.rs +++ b/src/components/script/dom/htmloptgroupelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLOptGroupElementBinding; use dom::bindings::codegen::InheritTypes::HTMLOptGroupElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLOptGroupElementTypeId; @@ -34,8 +34,8 @@ impl HTMLOptGroupElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLOptGroupElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLOptGroupElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLOptGroupElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmloptionelement.rs b/src/components/script/dom/htmloptionelement.rs index e6a030df48c..5119ce17b73 100644 --- a/src/components/script/dom/htmloptionelement.rs +++ b/src/components/script/dom/htmloptionelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLOptionElementBinding; use dom::bindings::codegen::InheritTypes::HTMLOptionElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLOptionElementTypeId; @@ -35,8 +35,8 @@ impl HTMLOptionElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLOptionElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLOptionElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLOptionElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmloutputelement.rs b/src/components/script/dom/htmloutputelement.rs index 1a1ec088489..4f5dae6d8c0 100644 --- a/src/components/script/dom/htmloutputelement.rs +++ b/src/components/script/dom/htmloutputelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLOutputElementBinding; use dom::bindings::codegen::InheritTypes::HTMLOutputElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLOutputElementTypeId; @@ -36,8 +36,8 @@ impl HTMLOutputElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLOutputElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLOutputElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLOutputElementBinding::Wrap) } } @@ -83,9 +83,11 @@ impl HTMLOutputElement { } pub fn Validity(&self) -> JS { + let roots = RootCollection::new(); let doc = self.htmlelement.element.node.owner_doc(); let doc = doc.get(); - ValidityState::new(&doc.window) + let window = doc.window.root(&roots); + ValidityState::new(&window.root_ref()) } pub fn SetValidity(&mut self, _validity: JS) { diff --git a/src/components/script/dom/htmlparagraphelement.rs b/src/components/script/dom/htmlparagraphelement.rs index e6e6473e816..b473a81613e 100644 --- a/src/components/script/dom/htmlparagraphelement.rs +++ b/src/components/script/dom/htmlparagraphelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLParagraphElementBinding; use dom::bindings::codegen::InheritTypes::HTMLParagraphElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLParagraphElementTypeId; @@ -34,8 +34,8 @@ impl HTMLParagraphElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLParagraphElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLParagraphElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLParagraphElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlparamelement.rs b/src/components/script/dom/htmlparamelement.rs index 781221bfad0..c33b68fc932 100644 --- a/src/components/script/dom/htmlparamelement.rs +++ b/src/components/script/dom/htmlparamelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLParamElementBinding; use dom::bindings::codegen::InheritTypes::HTMLParamElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLParamElementTypeId; @@ -34,8 +34,8 @@ impl HTMLParamElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLParamElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLParamElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLParamElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlpreelement.rs b/src/components/script/dom/htmlpreelement.rs index 9b3e2c73953..cfbc2ddc3fe 100644 --- a/src/components/script/dom/htmlpreelement.rs +++ b/src/components/script/dom/htmlpreelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLPreElementBinding; use dom::bindings::codegen::InheritTypes::HTMLPreElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLPreElementTypeId; @@ -34,8 +34,8 @@ impl HTMLPreElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLPreElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLPreElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLPreElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlprogresselement.rs b/src/components/script/dom/htmlprogresselement.rs index ccd0463539f..ec76ab7d41d 100644 --- a/src/components/script/dom/htmlprogresselement.rs +++ b/src/components/script/dom/htmlprogresselement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLProgressElementBinding; use dom::bindings::codegen::InheritTypes::HTMLProgressElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::{ErrorResult, Fallible}; use dom::document::Document; use dom::element::HTMLProgressElementTypeId; @@ -34,8 +34,8 @@ impl HTMLProgressElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLProgressElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLProgressElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLProgressElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlquoteelement.rs b/src/components/script/dom/htmlquoteelement.rs index 87e313cc857..0ec36d39711 100644 --- a/src/components/script/dom/htmlquoteelement.rs +++ b/src/components/script/dom/htmlquoteelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLQuoteElementBinding; use dom::bindings::codegen::InheritTypes::HTMLQuoteElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLQuoteElementTypeId; @@ -34,8 +34,8 @@ impl HTMLQuoteElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLQuoteElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLQuoteElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLQuoteElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlscriptelement.rs b/src/components/script/dom/htmlscriptelement.rs index bccaa740906..3be3739542a 100644 --- a/src/components/script/dom/htmlscriptelement.rs +++ b/src/components/script/dom/htmlscriptelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLScriptElementBinding; use dom::bindings::codegen::InheritTypes::HTMLScriptElementDerived; use dom::bindings::codegen::InheritTypes::ElementCast; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{HTMLScriptElementTypeId, Element, AttributeHandlers}; @@ -35,19 +35,19 @@ impl HTMLScriptElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLScriptElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLScriptElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLScriptElementBinding::Wrap) } } impl HTMLScriptElement { - pub fn Src(&self, abstract_self: &JS) -> DOMString { - let element: JS = ElementCast::from(abstract_self); + pub fn Src(&self, abstract_self: &JSRef) -> DOMString { + let element: JS = ElementCast::from(&abstract_self.unrooted()); element.get_url_attribute("src") } - pub fn SetSrc(&mut self, _abstract_self: &JS, _src: DOMString) -> ErrorResult { + pub fn SetSrc(&mut self, _abstract_self: &JSRef, _src: DOMString) -> ErrorResult { Ok(()) } diff --git a/src/components/script/dom/htmlselectelement.rs b/src/components/script/dom/htmlselectelement.rs index 47353bd8eb5..53a738e1a97 100644 --- a/src/components/script/dom/htmlselectelement.rs +++ b/src/components/script/dom/htmlselectelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLSelectElementBinding; use dom::bindings::codegen::InheritTypes::HTMLSelectElementDerived; use dom::bindings::codegen::UnionTypes::{HTMLElementOrLong, HTMLOptionElementOrHTMLOptGroupElement}; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLSelectElementTypeId}; @@ -38,8 +38,8 @@ impl HTMLSelectElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLSelectElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLSelectElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLSelectElementBinding::Wrap) } } @@ -121,7 +121,7 @@ impl HTMLSelectElement { None } - pub fn IndexedSetter(&mut self, _index: u32, _option: Option>) -> ErrorResult { + pub fn IndexedSetter(&mut self, _index: u32, _option: Option>) -> ErrorResult { Ok(()) } @@ -154,9 +154,11 @@ impl HTMLSelectElement { } pub fn Validity(&self) -> JS { + let roots = RootCollection::new(); let doc = self.htmlelement.element.node.owner_doc(); let doc = doc.get(); - ValidityState::new(&doc.window) + let window = doc.window.root(&roots); + ValidityState::new(&window.root_ref()) } pub fn SetValidity(&mut self, _validity: JS) { diff --git a/src/components/script/dom/htmlserializer.rs b/src/components/script/dom/htmlserializer.rs index 8bd5beb6cf8..e99982822ed 100644 --- a/src/components/script/dom/htmlserializer.rs +++ b/src/components/script/dom/htmlserializer.rs @@ -7,7 +7,7 @@ use dom::attr::Attr; use dom::bindings::codegen::InheritTypes::{ElementCast, TextCast, CommentCast}; use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, CharacterDataCast}; use dom::bindings::codegen::InheritTypes::ProcessingInstructionCast; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::characterdata::CharacterData; use dom::comment::Comment; use dom::documenttype::DocumentType; @@ -20,6 +20,7 @@ use dom::processinginstruction::ProcessingInstruction; use dom::text::Text; pub fn serialize(iterator: &mut NodeIterator) -> ~str { + let roots = RootCollection::new(); let mut html = ~""; let mut open_elements: Vec<~str> = vec!(); @@ -31,23 +32,28 @@ pub fn serialize(iterator: &mut NodeIterator) -> ~str { match node.type_id() { ElementNodeTypeId(..) => { let elem: JS = ElementCast::to(&node).unwrap(); - serialize_elem(&elem, &mut open_elements) + let elem = elem.root(&roots); + serialize_elem(&elem.root_ref(), &mut open_elements) } CommentNodeTypeId => { let comment: JS = CommentCast::to(&node).unwrap(); - serialize_comment(&comment) + let comment = comment.root(&roots); + serialize_comment(&comment.root_ref()) } TextNodeTypeId => { let text: JS = TextCast::to(&node).unwrap(); - serialize_text(&text) + let text = text.root(&roots); + serialize_text(&text.root_ref()) } DoctypeNodeTypeId => { let doctype: JS = DocumentTypeCast::to(&node).unwrap(); - serialize_doctype(&doctype) + let doctype = doctype.root(&roots); + serialize_doctype(&doctype.root_ref()) } ProcessingInstructionNodeTypeId => { let processing_instruction: JS = ProcessingInstructionCast::to(&node).unwrap(); - serialize_processing_instruction(&processing_instruction) + let processing_instruction = processing_instruction.root(&roots); + serialize_processing_instruction(&processing_instruction.root_ref()) } DocumentFragmentNodeTypeId => { ~"" @@ -64,11 +70,11 @@ pub fn serialize(iterator: &mut NodeIterator) -> ~str { html } -fn serialize_comment(comment: &JS) -> ~str { +fn serialize_comment(comment: &JSRef) -> ~str { ~"" } -fn serialize_text(text: &JS) -> ~str { +fn serialize_text(text: &JSRef) -> ~str { match text.get().characterdata.node.parent_node { Some(ref parent) if parent.is_element() => { let elem: JS = ElementCast::to(parent).unwrap(); @@ -85,18 +91,20 @@ fn serialize_text(text: &JS) -> ~str { } } -fn serialize_processing_instruction(processing_instruction: &JS) -> ~str { +fn serialize_processing_instruction(processing_instruction: &JSRef) -> ~str { ~"" } -fn serialize_doctype(doctype: &JS) -> ~str { +fn serialize_doctype(doctype: &JSRef) -> ~str { ~"" } -fn serialize_elem(elem: &JS, open_elements: &mut Vec<~str>) -> ~str { +fn serialize_elem(elem: &JSRef, open_elements: &mut Vec<~str>) -> ~str { + let roots = RootCollection::new(); let mut rv = ~"<" + elem.get().local_name; for attr in elem.get().attrs.iter() { - rv.push_str(serialize_attr(attr)); + let attr = attr.root(&roots); + rv.push_str(serialize_attr(&attr.root_ref())); }; rv.push_str(">"); match elem.get().local_name.as_slice() { @@ -119,7 +127,7 @@ fn serialize_elem(elem: &JS, open_elements: &mut Vec<~str>) -> ~str { rv } -fn serialize_attr(attr: &JS) -> ~str { +fn serialize_attr(attr: &JSRef) -> ~str { let attr_name = if attr.get().namespace == namespace::XML { ~"xml:" + attr.get().local_name.clone() } else if attr.get().namespace == namespace::XMLNS && diff --git a/src/components/script/dom/htmlsourceelement.rs b/src/components/script/dom/htmlsourceelement.rs index 86f45c131ee..8db513bfbd2 100644 --- a/src/components/script/dom/htmlsourceelement.rs +++ b/src/components/script/dom/htmlsourceelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLSourceElementBinding; use dom::bindings::codegen::InheritTypes::HTMLSourceElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLSourceElementTypeId; @@ -34,8 +34,8 @@ impl HTMLSourceElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLSourceElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLSourceElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLSourceElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlspanelement.rs b/src/components/script/dom/htmlspanelement.rs index 14151f655a1..20e95ae4b8d 100644 --- a/src/components/script/dom/htmlspanelement.rs +++ b/src/components/script/dom/htmlspanelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLSpanElementBinding; use dom::bindings::codegen::InheritTypes::HTMLSpanElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::document::Document; use dom::element::HTMLSpanElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,8 +33,8 @@ impl HTMLSpanElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLSpanElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLSpanElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLSpanElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlstyleelement.rs b/src/components/script/dom/htmlstyleelement.rs index 29caa80da1d..be43a40f27d 100644 --- a/src/components/script/dom/htmlstyleelement.rs +++ b/src/components/script/dom/htmlstyleelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLStyleElementBinding; use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLStyleElementDerived, NodeCast}; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLStyleElementTypeId; @@ -37,8 +37,8 @@ impl HTMLStyleElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLStyleElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLStyleElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLStyleElementBinding::Wrap) } } @@ -82,11 +82,13 @@ pub trait StyleElementHelpers { impl StyleElementHelpers for JS { fn parse_own_css(&self) { + let roots = RootCollection::new(); let node: JS = NodeCast::from(self); + let node_root = node.root(&roots); let win = window_from_node(&node); let url = win.get().page().get_url(); - let data = node.get().GetTextContent(&node).expect("Element.textContent must be a string"); + let data = node.get().GetTextContent(&node_root.root_ref()).expect("Element.textContent must be a string"); let sheet = parse_inline_css(url, data); let LayoutChan(ref layout_chan) = *win.get().page().layout_chan; layout_chan.send(AddStylesheetMsg(sheet)); diff --git a/src/components/script/dom/htmltablecaptionelement.rs b/src/components/script/dom/htmltablecaptionelement.rs index 0366c458f27..6aa88d6c05a 100644 --- a/src/components/script/dom/htmltablecaptionelement.rs +++ b/src/components/script/dom/htmltablecaptionelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableCaptionElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableCaptionElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableCaptionElementTypeId; @@ -34,8 +34,8 @@ impl HTMLTableCaptionElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLTableCaptionElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLTableCaptionElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableCaptionElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltablecolelement.rs b/src/components/script/dom/htmltablecolelement.rs index cb7da24bc26..cc967f14c49 100644 --- a/src/components/script/dom/htmltablecolelement.rs +++ b/src/components/script/dom/htmltablecolelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableColElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableColElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableColElementTypeId; @@ -34,8 +34,8 @@ impl HTMLTableColElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLTableColElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLTableColElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableColElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltabledatacellelement.rs b/src/components/script/dom/htmltabledatacellelement.rs index 84d55945a29..7a6185d6ec2 100644 --- a/src/components/script/dom/htmltabledatacellelement.rs +++ b/src/components/script/dom/htmltabledatacellelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableDataCellElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableDataCellElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::document::Document; use dom::element::HTMLTableDataCellElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,8 +33,8 @@ impl HTMLTableDataCellElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLTableDataCellElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLTableDataCellElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableDataCellElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltableelement.rs b/src/components/script/dom/htmltableelement.rs index e4dbddd65ab..20948ff1d67 100644 --- a/src/components/script/dom/htmltableelement.rs +++ b/src/components/script/dom/htmltableelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableElementTypeId; @@ -34,8 +34,8 @@ impl HTMLTableElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLTableElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLTableElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltableheadercellelement.rs b/src/components/script/dom/htmltableheadercellelement.rs index af3421a1309..47057fd0fa2 100644 --- a/src/components/script/dom/htmltableheadercellelement.rs +++ b/src/components/script/dom/htmltableheadercellelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableHeaderCellElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableHeaderCellElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::document::Document; use dom::element::HTMLTableHeaderCellElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,8 +33,8 @@ impl HTMLTableHeaderCellElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLTableHeaderCellElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLTableHeaderCellElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableHeaderCellElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltablerowelement.rs b/src/components/script/dom/htmltablerowelement.rs index aa46e96524f..1256dbfdabc 100644 --- a/src/components/script/dom/htmltablerowelement.rs +++ b/src/components/script/dom/htmltablerowelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableRowElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableRowElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableRowElementTypeId; @@ -34,8 +34,8 @@ impl HTMLTableRowElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLTableRowElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLTableRowElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableRowElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltablesectionelement.rs b/src/components/script/dom/htmltablesectionelement.rs index 2e7cbda0f71..3689bba1f48 100644 --- a/src/components/script/dom/htmltablesectionelement.rs +++ b/src/components/script/dom/htmltablesectionelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableSectionElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableSectionElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableSectionElementTypeId; @@ -34,8 +34,8 @@ impl HTMLTableSectionElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLTableSectionElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLTableSectionElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableSectionElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltemplateelement.rs b/src/components/script/dom/htmltemplateelement.rs index cc431bc117e..9880dc0b34d 100644 --- a/src/components/script/dom/htmltemplateelement.rs +++ b/src/components/script/dom/htmltemplateelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTemplateElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTemplateElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::document::Document; use dom::element::HTMLTemplateElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,8 +33,8 @@ impl HTMLTemplateElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLTemplateElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLTemplateElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTemplateElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltextareaelement.rs b/src/components/script/dom/htmltextareaelement.rs index d41b32070c1..4f4c7b55c9d 100644 --- a/src/components/script/dom/htmltextareaelement.rs +++ b/src/components/script/dom/htmltextareaelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTextAreaElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTextAreaElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::{ErrorResult, Fallible}; use dom::document::Document; use dom::element::HTMLTextAreaElementTypeId; @@ -34,8 +34,8 @@ impl HTMLTextAreaElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLTextAreaElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLTextAreaElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTextAreaElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltimeelement.rs b/src/components/script/dom/htmltimeelement.rs index 527267d30a4..938a1013876 100644 --- a/src/components/script/dom/htmltimeelement.rs +++ b/src/components/script/dom/htmltimeelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTimeElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTimeElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTimeElementTypeId; @@ -34,8 +34,8 @@ impl HTMLTimeElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLTimeElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLTimeElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTimeElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltitleelement.rs b/src/components/script/dom/htmltitleelement.rs index 6b4b8f118bd..3fe46fe1b81 100644 --- a/src/components/script/dom/htmltitleelement.rs +++ b/src/components/script/dom/htmltitleelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTitleElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTitleElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTitleElementTypeId; @@ -34,8 +34,8 @@ impl HTMLTitleElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLTitleElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLTitleElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTitleElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltrackelement.rs b/src/components/script/dom/htmltrackelement.rs index c427c799ef1..19a58090dcf 100644 --- a/src/components/script/dom/htmltrackelement.rs +++ b/src/components/script/dom/htmltrackelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTrackElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTrackElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTrackElementTypeId; @@ -34,8 +34,8 @@ impl HTMLTrackElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLTrackElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLTrackElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTrackElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlulistelement.rs b/src/components/script/dom/htmlulistelement.rs index 8c9958fd8ff..1fe1be79af1 100644 --- a/src/components/script/dom/htmlulistelement.rs +++ b/src/components/script/dom/htmlulistelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLUListElementBinding; use dom::bindings::codegen::InheritTypes::HTMLUListElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLUListElementTypeId; @@ -34,8 +34,8 @@ impl HTMLUListElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLUListElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLUListElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLUListElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlunknownelement.rs b/src/components/script/dom/htmlunknownelement.rs index a8a0b3cb41d..aa472bb04fc 100644 --- a/src/components/script/dom/htmlunknownelement.rs +++ b/src/components/script/dom/htmlunknownelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLUnknownElementBinding; use dom::bindings::codegen::InheritTypes::HTMLUnknownElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::document::Document; use dom::element::HTMLUnknownElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,8 +33,8 @@ impl HTMLUnknownElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLUnknownElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLUnknownElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLUnknownElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlvideoelement.rs b/src/components/script/dom/htmlvideoelement.rs index 4ef1d9c57a3..3587ab4931a 100644 --- a/src/components/script/dom/htmlvideoelement.rs +++ b/src/components/script/dom/htmlvideoelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLVideoElementBinding; use dom::bindings::codegen::InheritTypes::HTMLVideoElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLVideoElementTypeId; @@ -34,8 +34,8 @@ impl HTMLVideoElement { } } - pub fn new(localName: DOMString, document: &JS) -> JS { - let element = HTMLVideoElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef) -> JS { + let element = HTMLVideoElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLVideoElementBinding::Wrap) } } diff --git a/src/components/script/dom/location.rs b/src/components/script/dom/location.rs index 0933d324c8b..fa0aaf103d7 100644 --- a/src/components/script/dom/location.rs +++ b/src/components/script/dom/location.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::LocationBinding; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::Fallible; use dom::window::Window; @@ -29,7 +29,7 @@ impl Location { } } - pub fn new(window: &JS, page: Rc) -> JS { + pub fn new(window: &JSRef, page: Rc) -> JS { reflect_dom_object(~Location::new_inherited(page), window, LocationBinding::Wrap) diff --git a/src/components/script/dom/mouseevent.rs b/src/components/script/dom/mouseevent.rs index 9db7963c2c9..a1f08aa72e0 100644 --- a/src/components/script/dom/mouseevent.rs +++ b/src/components/script/dom/mouseevent.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::MouseEventBinding; use dom::bindings::codegen::InheritTypes::MouseEventDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference}; use dom::bindings::error::Fallible; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::event::{Event, MouseEventTypeId}; @@ -51,21 +51,24 @@ impl MouseEvent { } } - pub fn new(window: &JS) -> JS { + pub fn new(window: &JSRef) -> JS { reflect_dom_object(~MouseEvent::new_inherited(), window, MouseEventBinding::Wrap) } - pub fn Constructor(owner: &JS, + pub fn Constructor(owner: &JSRef, type_: DOMString, init: &MouseEventBinding::MouseEventInit) -> Fallible> { + let roots = RootCollection::new(); let mut ev = MouseEvent::new(owner); - ev.get_mut().InitMouseEvent(type_, init.bubbles, init.cancelable, init.view.clone(), + let view = init.view.as_ref().map(|view| view.root(&roots)); + let related_target = init.relatedTarget.as_ref().map(|relatedTarget| relatedTarget.root(&roots)); + ev.get_mut().InitMouseEvent(type_, init.bubbles, init.cancelable, view.root_ref(), init.detail, init.screenX, init.screenY, init.clientX, init.clientY, init.ctrlKey, init.altKey, init.shiftKey, init.metaKey, - init.button, init.relatedTarget.clone()); + init.button, related_target.root_ref()); Ok(ev) } @@ -123,7 +126,7 @@ impl MouseEvent { typeArg: DOMString, canBubbleArg: bool, cancelableArg: bool, - viewArg: Option>, + viewArg: Option>, detailArg: i32, screenXArg: i32, screenYArg: i32, @@ -134,7 +137,7 @@ impl MouseEvent { shiftKeyArg: bool, metaKeyArg: bool, buttonArg: u16, - relatedTargetArg: Option>) { + relatedTargetArg: Option>) { self.mouseevent.InitUIEvent(typeArg, canBubbleArg, cancelableArg, viewArg, detailArg); self.screen_x = screenXArg; self.screen_y = screenYArg; @@ -145,7 +148,7 @@ impl MouseEvent { self.shift_key = shiftKeyArg; self.meta_key = metaKeyArg; self.button = buttonArg; - self.related_target = relatedTargetArg; + self.related_target = relatedTargetArg.map(|target| target.unrooted()); } } diff --git a/src/components/script/dom/navigator.rs b/src/components/script/dom/navigator.rs index 39788fa7013..63779428d94 100644 --- a/src/components/script/dom/navigator.rs +++ b/src/components/script/dom/navigator.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::NavigatorBinding; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::Fallible; use dom::window::Window; @@ -21,7 +21,7 @@ impl Navigator { } } - pub fn new(window: &JS) -> JS { + pub fn new(window: &JSRef) -> JS { reflect_dom_object(~Navigator::new_inherited(), window, NavigatorBinding::Wrap) diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index d5b43a6257f..4d40d8daeb7 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -10,7 +10,7 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, TextCast, NodeCast}; use dom::bindings::codegen::InheritTypes::{CharacterDataCast, NodeBase, NodeDerived}; use dom::bindings::codegen::InheritTypes::{ProcessingInstructionCast, EventTargetCast}; use dom::bindings::codegen::BindingDeclarations::NodeBinding::NodeConstants; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::{ErrorResult, Fallible, NotFound, HierarchyRequest}; use dom::bindings::utils; @@ -223,25 +223,28 @@ pub enum NodeTypeId { } pub trait INode { - fn AppendChild(&mut self, node: &mut JS) -> Fallible>; - fn ReplaceChild(&mut self, node: &mut JS, child: &mut JS) -> Fallible>; - fn RemoveChild(&mut self, node: &mut JS) -> Fallible>; + fn AppendChild(&mut self, node: &mut JSRef) -> Fallible>; + fn ReplaceChild(&mut self, node: &mut JSRef, child: &mut JSRef) -> Fallible>; + fn RemoveChild(&mut self, node: &mut JSRef) -> Fallible>; } impl INode for JS { - fn AppendChild(&mut self, node: &mut JS) -> Fallible> { - let mut self_node = self.clone(); - self.get_mut().AppendChild(&mut self_node, node) + fn AppendChild(&mut self, node: &mut JSRef) -> Fallible> { + let roots = RootCollection::new(); + let self_node = self.root(&roots); + self.get_mut().AppendChild(&mut self_node.root_ref(), node) } - fn ReplaceChild(&mut self, node: &mut JS, child: &mut JS) -> Fallible> { - let mut self_node = self.clone(); - self.get_mut().ReplaceChild(&mut self_node, node, child) + fn ReplaceChild(&mut self, node: &mut JSRef, child: &mut JSRef) -> Fallible> { + let roots = RootCollection::new(); + let self_node = self.root(&roots); + self.get_mut().ReplaceChild(&mut self_node.root_ref(), node, child) } - fn RemoveChild(&mut self, node: &mut JS) -> Fallible> { - let mut self_node = self.clone(); - self.get_mut().RemoveChild(&mut self_node, node) + fn RemoveChild(&mut self, node: &mut JSRef) -> Fallible> { + let roots = RootCollection::new(); + let self_node = self.root(&roots); + self.get_mut().RemoveChild(&mut self_node.root_ref(), node) } } @@ -251,8 +254,8 @@ pub trait NodeHelpers { fn child_elements(&self) -> ChildElementIterator; fn following_siblings(&self) -> AbstractNodeChildrenIterator; fn is_in_doc(&self) -> bool; - fn is_inclusive_ancestor_of(&self, parent: &JS) -> bool; - fn is_parent_of(&self, child: &JS) -> bool; + fn is_inclusive_ancestor_of(&self, parent: &JSRef) -> bool; + fn is_parent_of(&self, child: &JSRef) -> bool; fn type_id(&self) -> NodeTypeId; @@ -270,8 +273,8 @@ pub trait NodeHelpers { fn node_inserted(&self); fn node_removed(&self); - fn add_child(&mut self, new_child: &mut JS, before: Option>); - fn remove_child(&mut self, child: &mut JS); + fn add_child(&mut self, new_child: &mut JSRef, before: Option>); + fn remove_child(&mut self, child: &mut JSRef); fn get_hover_state(&self) -> bool; fn set_hover_state(&mut self, state: bool); @@ -364,10 +367,7 @@ impl NodeHelpers for JS { #[inline] fn is_element(&self) -> bool { - match self.type_id() { - ElementNodeTypeId(..) => true, - _ => false - } + self.get().is_element() } #[inline] @@ -439,66 +439,81 @@ impl NodeHelpers for JS { /// Adds a new child to the end of this node's list of children. /// /// Fails unless `new_child` is disconnected from the tree. - fn add_child(&mut self, new_child: &mut JS, before: Option>) { + fn add_child(&mut self, new_child_root: &mut JSRef, before: Option>) { + let roots = RootCollection::new(); + let mut new_child = new_child_root.unrooted(); assert!(new_child.parent_node().is_none()); assert!(new_child.prev_sibling().is_none()); assert!(new_child.next_sibling().is_none()); match before { - Some(mut before) => { + Some(before_root) => { + let mut before = before_root.unrooted(); // XXX Should assert that parent is self. assert!(before.parent_node().is_some()); match before.prev_sibling() { None => { // XXX Should assert that before is the first child of // self. - self.get_mut().set_first_child(Some(new_child.clone())); + self.get_mut().set_first_child(Some(new_child_root.clone())); }, Some(mut prev_sibling) => { - prev_sibling.get_mut().set_next_sibling(Some(new_child.clone())); - new_child.get_mut().set_prev_sibling(Some(prev_sibling.clone())); + let prev_sibling_root = prev_sibling.root(&roots); + prev_sibling.get_mut().set_next_sibling(Some(new_child_root.clone())); + new_child.get_mut().set_prev_sibling(Some(prev_sibling_root.root_ref())); }, } - before.get_mut().set_prev_sibling(Some(new_child.clone())); - new_child.get_mut().set_next_sibling(Some(before.clone())); + before.get_mut().set_prev_sibling(Some(new_child_root.clone())); + new_child.get_mut().set_next_sibling(Some(before_root.clone())); }, None => { match self.last_child() { - None => self.get_mut().set_first_child(Some(new_child.clone())), + None => self.get_mut().set_first_child(Some(new_child_root.clone())), Some(mut last_child) => { + let last_child_root = last_child.root(&roots); assert!(last_child.next_sibling().is_none()); - last_child.get_mut().set_next_sibling(Some(new_child.clone())); - new_child.get_mut().set_prev_sibling(Some(last_child.clone())); + last_child.get_mut().set_next_sibling(Some(new_child_root.clone())); + new_child.get_mut().set_prev_sibling(Some(last_child_root.root_ref())); } } - self.get_mut().set_last_child(Some(new_child.clone())); + self.get_mut().set_last_child(Some(new_child_root.clone())); }, } - new_child.get_mut().set_parent_node(Some(self.clone())); + let self_root = self.root(&roots); + new_child.get_mut().set_parent_node(Some(self_root.root_ref())); } /// Removes the given child from this node's list of children. /// /// Fails unless `child` is a child of this node. (FIXME: This is not yet checked.) - fn remove_child(&mut self, child: &mut JS) { + fn remove_child(&mut self, child: &mut JSRef) { + let roots = RootCollection::new(); let this_node = self.get_mut(); let child_node = child.get_mut(); assert!(child_node.parent_node.is_some()); match child_node.prev_sibling { - None => this_node.set_first_child(child_node.next_sibling.clone()), + None => { + let next_sibling = child_node.next_sibling.as_ref().map(|next| next.root(&roots)); + this_node.set_first_child(next_sibling.root_ref()); + } Some(ref mut prev_sibling) => { let prev_sibling_node = prev_sibling.get_mut(); - prev_sibling_node.set_next_sibling(child_node.next_sibling.clone()); + let next_sibling = child_node.next_sibling.as_ref().map(|next| next.root(&roots)); + prev_sibling_node.set_next_sibling(next_sibling.root_ref()); } } match child_node.next_sibling { - None => this_node.set_last_child(child_node.prev_sibling.clone()), + None => { + let prev_sibling = child_node.prev_sibling.as_ref().map(|prev| prev.root(&roots)); + this_node.set_last_child(prev_sibling.root_ref()); + } Some(ref mut next_sibling) => { let next_sibling_node = next_sibling.get_mut(); - next_sibling_node.set_prev_sibling(child_node.prev_sibling.clone()); + let prev_sibling = child_node.prev_sibling.as_ref().map(|prev| prev.root(&roots)); + next_sibling_node.set_prev_sibling(prev_sibling.root_ref()); } } @@ -517,15 +532,19 @@ impl NodeHelpers for JS { /// Iterates over this node and all its descendants, in preorder. fn traverse_preorder(&self) -> TreeIterator { + let roots = RootCollection::new(); let mut nodes = vec!(); - gather_abstract_nodes(self, &mut nodes, false); + let self_root = self.root(&roots); + gather_abstract_nodes(&self_root.root_ref(), &mut nodes, false); TreeIterator::new(nodes) } /// Iterates over this node and all its descendants, in postorder. fn sequential_traverse_postorder(&self) -> TreeIterator { + let roots = RootCollection::new(); let mut nodes = vec!(); - gather_abstract_nodes(self, &mut nodes, true); + let self_root = self.root(&roots); + gather_abstract_nodes(&self_root.root_ref(), &mut nodes, true); TreeIterator::new(nodes) } @@ -535,7 +554,8 @@ impl NodeHelpers for JS { } } - fn is_inclusive_ancestor_of(&self, parent: &JS) -> bool { + fn is_inclusive_ancestor_of(&self, parent: &JSRef) -> bool { + let parent = &parent.unrooted(); self == parent || parent.ancestors().any(|ancestor| ancestor == *self) } @@ -545,8 +565,8 @@ impl NodeHelpers for JS { } } - fn is_parent_of(&self, child: &JS) -> bool { - match child.parent_node() { + fn is_parent_of(&self, child: &JSRef) -> bool { + match child.unrooted().parent_node() { Some(ref parent) if parent == self => true, _ => false } @@ -677,32 +697,35 @@ impl NodeIterator { } } - fn next_child(&self, node: &JS) -> Option> { - if !self.include_descendants_of_void && node.is_element() { - let elem: JS = ElementCast::to(node).unwrap(); + fn next_child(&self, node: &JSRef) -> Option> { + if !self.include_descendants_of_void && node.get().is_element() { + let elem: JS = ElementCast::to(&node.unrooted()).unwrap(); if elem.get().is_void() { None } else { - node.first_child() + node.get().first_child.clone() } } else { - node.first_child() + node.get().first_child.clone() } } } impl Iterator> for NodeIterator { fn next(&mut self) -> Option> { + let roots = RootCollection::new(); self.current_node = match self.current_node { None => { if self.include_start { Some(self.start_node.clone()) } else { - self.next_child(&self.start_node) + let start_node = self.start_node.root(&roots); + self.next_child(&start_node.root_ref()) } }, Some(ref node) => { - match self.next_child(node) { + let node_root = node.root(&roots); + match self.next_child(&node_root.root_ref()) { Some(child) => { self.depth += 1; Some(child.clone()) @@ -735,15 +758,17 @@ impl Iterator> for NodeIterator { } } -fn gather_abstract_nodes(cur: &JS, refs: &mut Vec>, postorder: bool) { +fn gather_abstract_nodes(cur: &JSRef, refs: &mut Vec>, postorder: bool) { + let roots = RootCollection::new(); if !postorder { - refs.push(cur.clone()); + refs.push(cur.unrooted()); } - for kid in cur.children() { - gather_abstract_nodes(&kid, refs, postorder) + for kid in cur.unrooted().children() { + let kid = kid.root(&roots); + gather_abstract_nodes(&kid.root_ref(), refs, postorder) } if postorder { - refs.push(cur.clone()); + refs.push(cur.unrooted()); } } @@ -763,12 +788,19 @@ impl Node { } } + pub fn is_element(&self) -> bool { + match self.type_id { + ElementNodeTypeId(..) => true, + _ => false + } + } + pub fn owner_doc<'a>(&'a self) -> &'a JS { self.owner_doc.get_ref() } - pub fn set_owner_doc(&mut self, document: &JS) { - self.owner_doc = Some(document.clone()); + pub fn set_owner_doc(&mut self, document: &JSRef) { + self.owner_doc = Some(document.unrooted()); } pub fn children(&self) -> AbstractNodeChildrenIterator { @@ -788,24 +820,28 @@ impl Node { pub fn reflect_node (node: ~N, - document: &JS, - wrap_fn: extern "Rust" fn(*JSContext, &JS, ~N) -> JS) + document: &JSRef, + wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~N) -> JS) -> JS { + let roots = RootCollection::new(); assert!(node.reflector().get_jsobject().is_null()); - let node = reflect_dom_object(node, &document.get().window, wrap_fn); + let window = document.get().window.root(&roots); + let node = reflect_dom_object(node, &window.root_ref(), wrap_fn); assert!(node.reflector().get_jsobject().is_not_null()); node } pub fn new_inherited(type_id: NodeTypeId, doc: JS) -> Node { - Node::new_(type_id, Some(doc)) + let roots = RootCollection::new(); + let doc = doc.root(&roots); + Node::new_(type_id, Some(doc.root_ref())) } pub fn new_without_doc(type_id: NodeTypeId) -> Node { Node::new_(type_id, None) } - fn new_(type_id: NodeTypeId, doc: Option>) -> Node { + fn new_(type_id: NodeTypeId, doc: Option>) -> Node { Node { eventtarget: EventTarget::new_inherited(NodeTargetTypeId(type_id)), type_id: type_id, @@ -816,7 +852,7 @@ impl Node { next_sibling: None, prev_sibling: None, - owner_doc: doc, + owner_doc: doc.map(|doc| doc.unrooted()), child_list: None, flags: NodeFlags::new(type_id), @@ -854,21 +890,21 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-nodename - pub fn NodeName(&self, abstract_self: &JS) -> DOMString { + pub fn NodeName(&self, abstract_self: &JSRef) -> DOMString { match self.type_id { ElementNodeTypeId(..) => { - let elem: JS = ElementCast::to(abstract_self).unwrap(); + let elem: JS = ElementCast::to(&abstract_self.unrooted()).unwrap(); elem.get().TagName() } TextNodeTypeId => ~"#text", ProcessingInstructionNodeTypeId => { let processing_instruction: JS = - ProcessingInstructionCast::to(abstract_self).unwrap(); + ProcessingInstructionCast::to(&abstract_self.unrooted()).unwrap(); processing_instruction.get().Target() } CommentNodeTypeId => ~"#comment", DoctypeNodeTypeId => { - let doctype: JS = DocumentTypeCast::to(abstract_self).unwrap(); + let doctype: JS = DocumentTypeCast::to(&abstract_self.unrooted()).unwrap(); doctype.get().name.clone() }, DocumentFragmentNodeTypeId => ~"#document-fragment", @@ -911,12 +947,14 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-childnodes - pub fn ChildNodes(&mut self, abstract_self: &JS) -> JS { + pub fn ChildNodes(&mut self, abstract_self: &JSRef) -> JS { + let roots = RootCollection::new(); match self.child_list { None => { let doc = self.owner_doc().clone(); let doc = doc.get(); - let list = NodeList::new_child_list(&doc.window, abstract_self); + let window = doc.window.root(&roots); + let list = NodeList::new_child_list(&window.root_ref(), abstract_self); self.child_list = Some(list.clone()); list } @@ -945,12 +983,12 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-nodevalue - pub fn GetNodeValue(&self, abstract_self: &JS) -> Option { + pub fn GetNodeValue(&self, abstract_self: &JSRef) -> Option { match self.type_id { CommentNodeTypeId | TextNodeTypeId | ProcessingInstructionNodeTypeId => { - let chardata: JS = CharacterDataCast::to(abstract_self).unwrap(); + let chardata: JS = CharacterDataCast::to(&abstract_self.unrooted()).unwrap(); Some(chardata.get().Data()) } _ => { @@ -960,7 +998,7 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-nodevalue - pub fn SetNodeValue(&mut self, abstract_self: &mut JS, val: Option) + pub fn SetNodeValue(&mut self, abstract_self: &mut JSRef, val: Option) -> ErrorResult { match self.type_id { CommentNodeTypeId | @@ -973,12 +1011,12 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-textcontent - pub fn GetTextContent(&self, abstract_self: &JS) -> Option { + pub fn GetTextContent(&self, abstract_self: &JSRef) -> Option { match self.type_id { DocumentFragmentNodeTypeId | ElementNodeTypeId(..) => { let mut content = ~""; - for node in abstract_self.traverse_preorder() { + for node in abstract_self.unrooted().traverse_preorder() { if node.is_text() { let text: JS = TextCast::to(&node).unwrap(); content.push_str(text.get().characterdata.data.as_slice()); @@ -989,7 +1027,7 @@ impl Node { CommentNodeTypeId | TextNodeTypeId | ProcessingInstructionNodeTypeId => { - let characterdata: JS = CharacterDataCast::to(abstract_self).unwrap(); + let characterdata: JS = CharacterDataCast::to(&abstract_self.unrooted()).unwrap(); Some(characterdata.get().Data()) } DoctypeNodeTypeId | @@ -1000,8 +1038,9 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-textcontent - pub fn SetTextContent(&mut self, abstract_self: &mut JS, value: Option) + pub fn SetTextContent(&mut self, abstract_self: &mut JSRef, value: Option) -> ErrorResult { + let roots = RootCollection::new(); let value = null_str_as_empty(&value); match self.type_id { DocumentFragmentNodeTypeId | @@ -1011,17 +1050,20 @@ impl Node { None } else { let document = self.owner_doc(); - Some(NodeCast::from(&document.get().CreateTextNode(document, value))) + let document = document.root(&roots); + Some(NodeCast::from(&document.get().CreateTextNode(&document.root_ref(), value))) }; + let node = node.map(|node| node.root(&roots)); + // Step 3. - Node::replace_all(node, abstract_self); + Node::replace_all(node.root_ref(), abstract_self); } CommentNodeTypeId | TextNodeTypeId | ProcessingInstructionNodeTypeId => { self.wait_until_safe_to_modify_dom(); - let mut characterdata: JS = CharacterDataCast::to(abstract_self).unwrap(); + let mut characterdata: JS = CharacterDataCast::to(&abstract_self.unrooted()).unwrap(); characterdata.get_mut().data = value.clone(); // Notify the document that the content of this node is different @@ -1035,15 +1077,20 @@ impl Node { } // http://dom.spec.whatwg.org/#concept-node-adopt - pub fn adopt(node: &mut JS, document: &JS) { + pub fn adopt(node_root: &mut JSRef, document: &JSRef) { + let roots = RootCollection::new(); + let node = node_root.unrooted(); // Step 1. match node.parent_node() { - Some(ref mut parent) => Node::remove(node, parent, Unsuppressed), + Some(ref mut parent) => { + let parent = parent.root(&roots); + Node::remove(node_root, &mut parent.root_ref(), Unsuppressed); + } None => (), } // Step 2. - if document_from_node(node) != *document { + if document_from_node(&node) != document.unrooted() { for mut descendant in node.traverse_preorder() { descendant.get_mut().set_owner_doc(document); } @@ -1054,8 +1101,11 @@ impl Node { } // http://dom.spec.whatwg.org/#concept-node-pre-insert - fn pre_insert(node: &mut JS, parent: &mut JS, child: Option>) + fn pre_insert(node_root: &mut JSRef, parent_root: &mut JSRef, child: Option>) -> Fallible> { + let roots = RootCollection::new(); + let node = node_root.unrooted(); + let parent = parent_root.unrooted(); // Step 1. match parent.type_id() { DocumentNodeTypeId | @@ -1065,7 +1115,7 @@ impl Node { } // Step 2. - if node.is_inclusive_ancestor_of(parent) { + if node.is_inclusive_ancestor_of(parent_root) { return Err(HierarchyRequest); } @@ -1097,6 +1147,7 @@ impl Node { } // Step 6. + let child = child.map(|child| child.unrooted()); match parent.type_id() { DocumentNodeTypeId => { match node.type_id() { @@ -1175,25 +1226,31 @@ impl Node { // Step 7-8. let referenceChild = match child { - Some(ref child) if child == node => node.next_sibling(), + Some(ref child) if child == &node => node.next_sibling(), _ => child }; + let referenceChild = referenceChild.map(|child| child.root(&roots)); // Step 9. - Node::adopt(node, &document_from_node(parent)); + let document = document_from_node(&parent); + let document = document.root(&roots); + Node::adopt(node_root, &document.root_ref()); // Step 10. - Node::insert(node, parent, referenceChild, Unsuppressed); + Node::insert(node_root, parent_root, referenceChild.root_ref(), Unsuppressed); // Step 11. - return Ok(node.clone()) + return Ok(node) } // http://dom.spec.whatwg.org/#concept-node-insert - fn insert(node: &mut JS, - parent: &mut JS, - child: Option>, + fn insert(node_root: &mut JSRef, + parent_root: &mut JSRef, + child: Option>, suppress_observers: SuppressObserver) { + let roots = RootCollection::new(); + let node = node_root.unrooted(); + let mut parent = parent_root.unrooted(); // XXX assert owner_doc // Step 1-3: ranges. // Step 4. @@ -1206,8 +1263,9 @@ impl Node { // Step 6: DocumentFragment. match node.type_id() { DocumentFragmentNodeTypeId => { - for mut c in node.children() { - Node::remove(&mut c, node, Suppressed); + for c in node.children() { + let c = c.root(&roots); + Node::remove(&mut c.root_ref(), node_root, Suppressed); } }, _ => (), @@ -1216,7 +1274,7 @@ impl Node { // Step 7: mutation records. // Step 8. for node in nodes.mut_iter() { - parent.add_child(node, child.clone()); + parent.add_child(node_root, child.clone()); node.get_mut().flags.set_is_in_doc(parent.is_in_doc()); } @@ -1232,10 +1290,18 @@ impl Node { } // http://dom.spec.whatwg.org/#concept-node-replace-all - pub fn replace_all(mut node: Option>, parent: &mut JS) { + pub fn replace_all(mut node_root: Option>, parent_root: &mut JSRef) { + let roots = RootCollection::new(); + let node = node_root.as_ref().map(|node| node.unrooted()); + let parent = parent_root.unrooted(); + // Step 1. - match node { - Some(ref mut node) => Node::adopt(node, &document_from_node(parent)), + match node_root { + Some(ref mut node) => { + let document = document_from_node(&parent); + let document = document.root(&roots); + Node::adopt(node, &document.root_ref()); + } None => (), } @@ -1252,13 +1318,14 @@ impl Node { }; // Step 4. - for mut child in parent.children() { - Node::remove(&mut child, parent, Suppressed); + for child in parent.children() { + let child = child.root(&roots); + Node::remove(&mut child.root_ref(), parent_root, Suppressed); } // Step 5. - match node { - Some(ref mut node) => Node::insert(node, parent, None, Suppressed), + match node_root { + Some(ref mut node) => Node::insert(node, parent_root, None, Suppressed), None => (), } @@ -1274,10 +1341,10 @@ impl Node { } // http://dom.spec.whatwg.org/#concept-node-pre-remove - fn pre_remove(child: &mut JS, parent: &mut JS) -> Fallible> { + fn pre_remove(child: &mut JSRef, parent: &mut JSRef) -> Fallible> { // Step 1. - match child.parent_node() { - Some(ref node) if node != parent => return Err(NotFound), + match child.unrooted().parent_node() { + Some(ref node) if node != &parent.unrooted() => return Err(NotFound), _ => () } @@ -1285,17 +1352,19 @@ impl Node { Node::remove(child, parent, Unsuppressed); // Step 3. - Ok(child.clone()) + Ok(child.unrooted()) } // http://dom.spec.whatwg.org/#concept-node-remove - fn remove(node: &mut JS, parent: &mut JS, suppress_observers: SuppressObserver) { - assert!(node.parent_node().map_or(false, |ref node_parent| node_parent == parent)); + fn remove(node_root: &mut JSRef, parent: &mut JSRef, suppress_observers: SuppressObserver) { + let mut parent = parent.unrooted(); + let mut node = node_root.unrooted(); + assert!(node.parent_node().map_or(false, |ref node_parent| node_parent == &parent)); // Step 1-5: ranges. // Step 6-7: mutation observers. // Step 8. - parent.remove_child(node); + parent.remove_child(node_root); node.get_mut().flags.set_is_in_doc(false); // Step 9. @@ -1306,63 +1375,67 @@ impl Node { } // http://dom.spec.whatwg.org/#concept-node-clone - pub fn clone(node: &JS, maybe_doc: Option<&JS>, + pub fn clone(node: &JSRef, maybe_doc: Option<&JSRef>, clone_children: CloneChildrenFlag) -> JS { + let roots = RootCollection::new(); + // Step 1. let mut document = match maybe_doc { - Some(doc) => doc.clone(), + Some(doc) => doc.unrooted(), None => node.get().owner_doc().clone() }; + let document_root = document.root(&roots); // Step 2. // XXXabinader: clone() for each node as trait? - let mut copy: JS = match node.type_id() { + let copy: JS = match node.get().type_id { DoctypeNodeTypeId => { - let doctype: JS = DocumentTypeCast::to(node).unwrap(); + let doctype: JS = DocumentTypeCast::to(&node.unrooted()).unwrap(); let doctype = doctype.get(); let doctype = DocumentType::new(doctype.name.clone(), Some(doctype.public_id.clone()), - Some(doctype.system_id.clone()), &document); + Some(doctype.system_id.clone()), &document_root.root_ref()); NodeCast::from(&doctype) }, DocumentFragmentNodeTypeId => { - let doc_fragment = DocumentFragment::new(&document); + let doc_fragment = DocumentFragment::new(&document_root.root_ref()); NodeCast::from(&doc_fragment) }, CommentNodeTypeId => { - let comment: JS = CommentCast::to(node).unwrap(); + let comment: JS = CommentCast::to(&node.unrooted()).unwrap(); let comment = comment.get(); - let comment = Comment::new(comment.characterdata.data.clone(), &document); + let comment = Comment::new(comment.characterdata.data.clone(), &document_root.root_ref()); NodeCast::from(&comment) }, DocumentNodeTypeId => { - let document: JS = DocumentCast::to(node).unwrap(); + let document: JS = DocumentCast::to(&node.unrooted()).unwrap(); let document = document.get(); let is_html_doc = match document.is_html_document { true => HTMLDocument, false => NonHTMLDocument }; - let document = Document::new(&document.window, Some(document.url().clone()), + let window = document.window.root(&roots); + let document = Document::new(&window.root_ref(), Some(document.url().clone()), is_html_doc, None); NodeCast::from(&document) }, ElementNodeTypeId(..) => { - let element: JS = ElementCast::to(node).unwrap(); + let element: JS = ElementCast::to(&node.unrooted()).unwrap(); let element = element.get(); - let element = build_element_from_tag(element.local_name.clone(), &document); + let element = build_element_from_tag(element.local_name.clone(), &document_root.root_ref()); NodeCast::from(&element) }, TextNodeTypeId => { - let text: JS = TextCast::to(node).unwrap(); + let text: JS = TextCast::to(&node.unrooted()).unwrap(); let text = text.get(); - let text = Text::new(text.characterdata.data.clone(), &document); + let text = Text::new(text.characterdata.data.clone(), &document_root.root_ref()); NodeCast::from(&text) }, ProcessingInstructionNodeTypeId => { - let pi: JS = ProcessingInstructionCast::to(node).unwrap(); + let pi: JS = ProcessingInstructionCast::to(&node.unrooted()).unwrap(); let pi = pi.get(); let pi = ProcessingInstruction::new(pi.target.clone(), - pi.characterdata.data.clone(), &document); + pi.characterdata.data.clone(), &document_root.root_ref()); NodeCast::from(&pi) }, }; @@ -1371,12 +1444,13 @@ impl Node { if copy.is_document() { document = DocumentCast::to(©).unwrap(); } + let document_root = document.root(&roots); assert!(copy.get().owner_doc() == &document); // Step 4 (some data already copied in step 2). - match node.type_id() { + match node.get().type_id { DocumentNodeTypeId => { - let node_doc: JS = DocumentCast::to(node).unwrap(); + let node_doc: JS = DocumentCast::to(&node.unrooted()).unwrap(); let node_doc = node_doc.get(); let mut copy_doc: JS = DocumentCast::to(©).unwrap(); let copy_doc = copy_doc.get_mut(); @@ -1384,7 +1458,7 @@ impl Node { copy_doc.set_quirks_mode(node_doc.quirks_mode()); }, ElementNodeTypeId(..) => { - let node_elem: JS = ElementCast::to(node).unwrap(); + let node_elem: JS = ElementCast::to(&node.unrooted()).unwrap(); let node_elem = node_elem.get(); let mut copy_elem: JS = ElementCast::to(©).unwrap(); @@ -1394,9 +1468,10 @@ impl Node { let copy_elem = copy_elem.get_mut(); // FIXME: https://github.com/mozilla/servo/issues/1737 copy_elem.namespace = node_elem.namespace.clone(); + let window = document.get().window.root(&roots); for attr in node_elem.attrs.iter() { let attr = attr.get(); - copy_elem.attrs.push(Attr::new(&document.get().window, + copy_elem.attrs.push(Attr::new(&window.root_ref(), attr.local_name.clone(), attr.value.clone(), attr.name.clone(), attr.namespace.clone(), attr.prefix.clone(), copy_elem_alias.clone())); @@ -1410,8 +1485,10 @@ impl Node { // Step 6. if clone_children == CloneChildren { for ref child in node.get().children() { - let mut child_copy = Node::clone(child, Some(&document), clone_children); - let _inserted_node = Node::pre_insert(&mut child_copy, &mut copy, None); + let child = child.root(&roots); + let child_copy = Node::clone(&child.root_ref(), Some(&document_root.root_ref()), clone_children).root(&roots); + let copy = copy.root(&roots); + let _inserted_node = Node::pre_insert(&mut child_copy.root_ref(), &mut copy.root_ref(), None); } } @@ -1420,7 +1497,7 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-insertbefore - pub fn InsertBefore(&self, abstract_self: &mut JS, node: &mut JS, child: Option>) + pub fn InsertBefore(&self, abstract_self: &mut JSRef, node: &mut JSRef, child: Option>) -> Fallible> { Node::pre_insert(node, abstract_self, child) } @@ -1431,14 +1508,19 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-appendchild - pub fn AppendChild(&self, abstract_self: &mut JS, node: &mut JS) + pub fn AppendChild(&self, abstract_self: &mut JSRef, node: &mut JSRef) -> Fallible> { Node::pre_insert(node, abstract_self, None) } // http://dom.spec.whatwg.org/#concept-node-replace - pub fn ReplaceChild(&self, parent: &mut JS, node: &mut JS, child: &mut JS) + pub fn ReplaceChild(&self, parent_root: &mut JSRef, node_root: &mut JSRef, child_root: &mut JSRef) -> Fallible> { + let roots = RootCollection::new(); + let parent = parent_root.unrooted(); + let node = node_root.unrooted(); + let child = child_root.unrooted(); + // Step 1. match parent.type_id() { DocumentNodeTypeId | @@ -1448,12 +1530,12 @@ impl Node { } // Step 2. - if node.is_inclusive_ancestor_of(parent) { + if node.is_inclusive_ancestor_of(parent_root) { return Err(HierarchyRequest); } // Step 3. - if !parent.is_parent_of(child) { + if !parent.is_parent_of(child_root) { return Err(NotFound); } @@ -1484,7 +1566,7 @@ impl Node { 0 => (), // Step 6.1.2 1 => { - if parent.child_elements().any(|c| &NodeCast::from(&c) != child) { + if parent.child_elements().any(|c| NodeCast::from(&c) != child) { return Err(HierarchyRequest); } if child.following_siblings() @@ -1498,7 +1580,7 @@ impl Node { }, // Step 6.2 ElementNodeTypeId(..) => { - if parent.child_elements().any(|c| &NodeCast::from(&c) != child) { + if parent.child_elements().any(|c| NodeCast::from(&c) != child) { return Err(HierarchyRequest); } if child.following_siblings() @@ -1508,11 +1590,11 @@ impl Node { }, // Step 6.3 DoctypeNodeTypeId => { - if parent.children().any(|c| c.is_doctype() && &c != child) { + if parent.children().any(|c| c.is_doctype() && c != child) { return Err(HierarchyRequest); } if parent.children() - .take_while(|c| c != child) + .take_while(|c| c != &child) .any(|c| c.is_element()) { return Err(HierarchyRequest); } @@ -1527,26 +1609,29 @@ impl Node { } // Ok if not caught by previous error checks. - if *node == *child { - return Ok(child.clone()); + if node == child { + return Ok(child); } // Step 7-8. let next_sibling = child.next_sibling(); let reference_child = match next_sibling { - Some(ref sibling) if sibling == node => node.next_sibling(), + Some(ref sibling) if sibling == &node => node.next_sibling(), _ => next_sibling }; + let reference_child = reference_child.map(|child| child.root(&roots)); // Step 9. - Node::adopt(node, &document_from_node(parent)); + let document = document_from_node(&parent); + let document = document.root(&roots); + Node::adopt(node_root, &document.root_ref()); { // Step 10. - Node::remove(child, parent, Suppressed); + Node::remove(child_root, parent_root, Suppressed); // Step 11. - Node::insert(node, parent, reference_child, Suppressed); + Node::insert(node_root, parent_root, reference_child.root_ref(), Suppressed); } // Step 12-14. @@ -1561,36 +1646,40 @@ impl Node { } // Step 15. - Ok(child.clone()) + Ok(child) } // http://dom.spec.whatwg.org/#dom-node-removechild - pub fn RemoveChild(&self, abstract_self: &mut JS, node: &mut JS) + pub fn RemoveChild(&self, abstract_self: &mut JSRef, node: &mut JSRef) -> Fallible> { Node::pre_remove(node, abstract_self) } // http://dom.spec.whatwg.org/#dom-node-normalize - pub fn Normalize(&mut self, abstract_self: &mut JS) { + pub fn Normalize(&mut self, abstract_self: &mut JSRef) { + let roots = RootCollection::new(); + let mut abstract_self = abstract_self.unrooted(); let mut prev_text = None; for mut child in self.children() { if child.is_text() { let characterdata: JS = CharacterDataCast::to(&child).unwrap(); if characterdata.get().Length() == 0 { - abstract_self.remove_child(&mut child); + let child = child.root(&roots); + abstract_self.remove_child(&mut child.root_ref()); } else { match prev_text { Some(ref text_node) => { let mut prev_characterdata: JS = CharacterDataCast::to(text_node).unwrap(); let _ = prev_characterdata.get_mut().AppendData(characterdata.get().Data()); - abstract_self.remove_child(&mut child); + let child = child.root(&roots); + abstract_self.remove_child(&mut child.root_ref()); }, None => prev_text = Some(child) } } } else { - let c = &mut child.clone(); - child.get_mut().Normalize(c); + let c = child.root(&roots); + child.get_mut().Normalize(&mut c.root_ref()); prev_text = None; } @@ -1598,7 +1687,7 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-clonenode - pub fn CloneNode(&self, abstract_self: &mut JS, deep: bool) -> JS { + pub fn CloneNode(&self, abstract_self: &mut JSRef, deep: bool) -> JS { match deep { true => Node::clone(abstract_self, None, CloneChildren), false => Node::clone(abstract_self, None, DoNotCloneChildren) @@ -1606,36 +1695,36 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-isequalnode - pub fn IsEqualNode(&self, abstract_self: &JS, maybe_node: Option>) -> bool { - fn is_equal_doctype(node: &JS, other: &JS) -> bool { - let doctype: JS = DocumentTypeCast::to(node).unwrap(); - let other_doctype: JS = DocumentTypeCast::to(other).unwrap(); + pub fn IsEqualNode(&self, abstract_self: &JSRef, maybe_node: Option>) -> bool { + fn is_equal_doctype(node: &JSRef, other: &JSRef) -> bool { + let doctype: JS = DocumentTypeCast::to(&node.unrooted()).unwrap(); + let other_doctype: JS = DocumentTypeCast::to(&other.unrooted()).unwrap(); (doctype.get().name == other_doctype.get().name) && (doctype.get().public_id == other_doctype.get().public_id) && (doctype.get().system_id == other_doctype.get().system_id) } - fn is_equal_element(node: &JS, other: &JS) -> bool { - let element: JS = ElementCast::to(node).unwrap(); - let other_element: JS = ElementCast::to(other).unwrap(); + fn is_equal_element(node: &JSRef, other: &JSRef) -> bool { + let element: JS = ElementCast::to(&node.unrooted()).unwrap(); + let other_element: JS = ElementCast::to(&other.unrooted()).unwrap(); // FIXME: namespace prefix (element.get().namespace == other_element.get().namespace) && (element.get().local_name == other_element.get().local_name) && (element.get().attrs.len() == other_element.get().attrs.len()) } - fn is_equal_processinginstruction(node: &JS, other: &JS) -> bool { - let pi: JS = ProcessingInstructionCast::to(node).unwrap(); - let other_pi: JS = ProcessingInstructionCast::to(other).unwrap(); + fn is_equal_processinginstruction(node: &JSRef, other: &JSRef) -> bool { + let pi: JS = ProcessingInstructionCast::to(&node.unrooted()).unwrap(); + let other_pi: JS = ProcessingInstructionCast::to(&other.unrooted()).unwrap(); (pi.get().target == other_pi.get().target) && (pi.get().characterdata.data == other_pi.get().characterdata.data) } - fn is_equal_characterdata(node: &JS, other: &JS) -> bool { - let characterdata: JS = CharacterDataCast::to(node).unwrap(); - let other_characterdata: JS = CharacterDataCast::to(other).unwrap(); + fn is_equal_characterdata(node: &JSRef, other: &JSRef) -> bool { + let characterdata: JS = CharacterDataCast::to(&node.unrooted()).unwrap(); + let other_characterdata: JS = CharacterDataCast::to(&other.unrooted()).unwrap(); characterdata.get().data == other_characterdata.get().data } - fn is_equal_element_attrs(node: &JS, other: &JS) -> bool { - let element: JS = ElementCast::to(node).unwrap(); - let other_element: JS = ElementCast::to(other).unwrap(); + fn is_equal_element_attrs(node: &JSRef, other: &JSRef) -> bool { + let element: JS = ElementCast::to(&node.unrooted()).unwrap(); + let other_element: JS = ElementCast::to(&other.unrooted()).unwrap(); assert!(element.get().attrs.len() == other_element.get().attrs.len()); element.get().attrs.iter().all(|attr| { other_element.get().attrs.iter().any(|other_attr| { @@ -1645,13 +1734,17 @@ impl Node { }) }) } - fn is_equal_node(this: &JS, node: &JS) -> bool { + fn is_equal_node(this: &JSRef, node: &JSRef) -> bool { + let roots = RootCollection::new(); + let this_node = this.unrooted(); + let other = node.unrooted(); + // Step 2. - if this.type_id() != node.type_id() { + if this_node.type_id() != other.type_id() { return false; } - match node.type_id() { + match other.type_id() { // Step 3. DoctypeNodeTypeId if !is_equal_doctype(this, node) => return false, ElementNodeTypeId(..) if !is_equal_element(this, node) => return false, @@ -1664,12 +1757,16 @@ impl Node { } // Step 5. - if this.children().len() != node.children().len() { + if this_node.children().len() != other.children().len() { return false; } // Step 6. - this.children().zip(node.children()).all(|(ref child, ref other_child)| is_equal_node(child, other_child)) + this_node.children().zip(other.children()).all(|(ref child, ref other_child)| { + let child = child.root(&roots); + let other_child = other_child.root(&roots); + is_equal_node(&child.root_ref(), &other_child.root_ref()) + }) } match maybe_node { // Step 1. @@ -1680,7 +1777,9 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-comparedocumentposition - pub fn CompareDocumentPosition(&self, abstract_self: &JS, other: &JS) -> u16 { + pub fn CompareDocumentPosition(&self, abstract_self_root: &JSRef, other_root: &JSRef) -> u16 { + let other = other_root.unrooted(); + let abstract_self = abstract_self_root.unrooted(); if abstract_self == other { // step 2. 0 @@ -1688,7 +1787,7 @@ impl Node { let mut lastself = abstract_self.clone(); let mut lastother = other.clone(); for ancestor in abstract_self.ancestors() { - if &ancestor == other { + if ancestor == other { // step 4. return NodeConstants::DOCUMENT_POSITION_CONTAINS + NodeConstants::DOCUMENT_POSITION_PRECEDING; @@ -1696,7 +1795,7 @@ impl Node { lastself = ancestor; } for ancestor in other.ancestors() { - if &ancestor == abstract_self { + if ancestor == abstract_self { // step 5. return NodeConstants::DOCUMENT_POSITION_CONTAINED_BY + NodeConstants::DOCUMENT_POSITION_FOLLOWING; @@ -1720,11 +1819,11 @@ impl Node { } for child in lastself.traverse_preorder() { - if &child == other { + if child == other { // step 6. return NodeConstants::DOCUMENT_POSITION_PRECEDING; } - if &child == abstract_self { + if child == abstract_self { // step 7. return NodeConstants::DOCUMENT_POSITION_FOLLOWING; } @@ -1734,10 +1833,10 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-contains - pub fn Contains(&self, abstract_self: &JS, maybe_other: Option>) -> bool { + pub fn Contains(&self, abstract_self: &JSRef, maybe_other: Option>) -> bool { match maybe_other { None => false, - Some(ref other) => abstract_self.is_inclusive_ancestor_of(other) + Some(ref other) => abstract_self.unrooted().is_inclusive_ancestor_of(other) } } @@ -1763,34 +1862,34 @@ impl Node { // Low-level pointer stitching // - pub fn set_parent_node(&mut self, new_parent_node: Option>) { + pub fn set_parent_node(&mut self, new_parent_node: Option>) { let doc = self.owner_doc().clone(); doc.get().wait_until_safe_to_modify_dom(); - self.parent_node = new_parent_node + self.parent_node = new_parent_node.map(|node| node.unrooted()) } - pub fn set_first_child(&mut self, new_first_child: Option>) { + pub fn set_first_child(&mut self, new_first_child: Option>) { let doc = self.owner_doc().clone(); doc.get().wait_until_safe_to_modify_dom(); - self.first_child = new_first_child + self.first_child = new_first_child.map(|node| node.unrooted()) } - pub fn set_last_child(&mut self, new_last_child: Option>) { + pub fn set_last_child(&mut self, new_last_child: Option>) { let doc = self.owner_doc().clone(); doc.get().wait_until_safe_to_modify_dom(); - self.last_child = new_last_child + self.last_child = new_last_child.map(|node| node.unrooted()) } - pub fn set_prev_sibling(&mut self, new_prev_sibling: Option>) { + pub fn set_prev_sibling(&mut self, new_prev_sibling: Option>) { let doc = self.owner_doc().clone(); doc.get().wait_until_safe_to_modify_dom(); - self.prev_sibling = new_prev_sibling + self.prev_sibling = new_prev_sibling.map(|node| node.unrooted()) } - pub fn set_next_sibling(&mut self, new_next_sibling: Option>) { + pub fn set_next_sibling(&mut self, new_next_sibling: Option>) { let doc = self.owner_doc().clone(); doc.get().wait_until_safe_to_modify_dom(); - self.next_sibling = new_next_sibling + self.next_sibling = new_next_sibling.map(|node| node.unrooted()) } pub fn get_hover_state(&self) -> bool { diff --git a/src/components/script/dom/nodelist.rs b/src/components/script/dom/nodelist.rs index 714f0e34079..751c15ab098 100644 --- a/src/components/script/dom/nodelist.rs +++ b/src/components/script/dom/nodelist.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::NodeListBinding; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::node::{Node, NodeHelpers}; use dom::window::Window; @@ -31,18 +31,18 @@ impl NodeList { } } - pub fn new(window: &JS, + pub fn new(window: &JSRef, list_type: NodeListType) -> JS { - reflect_dom_object(~NodeList::new_inherited(window.clone(), list_type), + reflect_dom_object(~NodeList::new_inherited(window.unrooted(), list_type), window, NodeListBinding::Wrap) } - pub fn new_simple_list(window: &JS, elements: Vec>) -> JS { + pub fn new_simple_list(window: &JSRef, elements: Vec>) -> JS { NodeList::new(window, Simple(elements)) } - pub fn new_child_list(window: &JS, node: &JS) -> JS { - NodeList::new(window, Children(node.clone())) + pub fn new_child_list(window: &JSRef, node: &JSRef) -> JS { + NodeList::new(window, Children(node.unrooted())) } pub fn Length(&self) -> u32 { diff --git a/src/components/script/dom/processinginstruction.rs b/src/components/script/dom/processinginstruction.rs index e39286d9aaa..7064f8d3ca7 100644 --- a/src/components/script/dom/processinginstruction.rs +++ b/src/components/script/dom/processinginstruction.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::ProcessingInstructionBinding; use dom::bindings::codegen::InheritTypes::ProcessingInstructionDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::characterdata::CharacterData; use dom::document::Document; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -35,8 +35,8 @@ impl ProcessingInstruction { } } - pub fn new(target: DOMString, data: DOMString, document: &JS) -> JS { - let node = ProcessingInstruction::new_inherited(target, data, document.clone()); + pub fn new(target: DOMString, data: DOMString, document: &JSRef) -> JS { + let node = ProcessingInstruction::new_inherited(target, data, document.unrooted()); Node::reflect_node(~node, document, ProcessingInstructionBinding::Wrap) } } diff --git a/src/components/script/dom/testbinding.rs b/src/components/script/dom/testbinding.rs index 6283b5a350e..e05cec800bb 100644 --- a/src/components/script/dom/testbinding.rs +++ b/src/components/script/dom/testbinding.rs @@ -2,7 +2,7 @@ * 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; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::codegen::BindingDeclarations::TestBindingBinding; use dom::bindings::codegen::UnionTypes::HTMLElementOrLong; use self::TestBindingBinding::TestEnum; @@ -51,8 +51,12 @@ impl TestBinding { pub fn SetByteStringAttribute(&self, _: ByteString) {} pub fn EnumAttribute(&self) -> TestEnum { _empty } pub fn SetEnumAttribute(&self, _: TestEnum) {} - pub fn InterfaceAttribute(&self) -> JS { Blob::new(&self.window) } - pub fn SetInterfaceAttribute(&self, _: &JS) {} + pub fn InterfaceAttribute(&self) -> JS { + let roots = RootCollection::new(); + let window = self.window.root(&roots); + Blob::new(&window.root_ref()) + } + pub fn SetInterfaceAttribute(&self, _: &JSRef) {} pub fn AnyAttribute(&self, _: *JSContext) -> JSVal { NullValue() } pub fn SetAnyAttribute(&self, _: *JSContext, _: JSVal) {} @@ -83,8 +87,12 @@ impl TestBinding { pub fn GetStringAttributeNullable(&self) -> Option { Some(~"") } pub fn SetStringAttributeNullable(&self, _: Option) {} pub fn GetEnumAttributeNullable(&self) -> Option { Some(_empty) } - pub fn GetInterfaceAttributeNullable(&self) -> Option> { Some(Blob::new(&self.window)) } - pub fn SetInterfaceAttributeNullable(&self, _: Option>) {} + pub fn GetInterfaceAttributeNullable(&self) -> Option> { + let roots = RootCollection::new(); + let window = self.window.root(&roots); + Some(Blob::new(&window.root_ref())) + } + pub fn SetInterfaceAttributeNullable(&self, _: Option>) {} pub fn PassBoolean(&self, _: bool) {} pub fn PassByte(&self, _: i8) {} @@ -100,7 +108,7 @@ impl TestBinding { pub fn PassString(&self, _: DOMString) {} pub fn PassByteString(&self, _: ByteString) {} pub fn PassEnum(&self, _: TestEnum) {} - pub fn PassInterface(&self, _: &JS) {} + pub fn PassInterface(&self, _: &JSRef) {} pub fn PassUnion(&self, _: HTMLElementOrLong) {} pub fn PassAny(&self, _: *JSContext, _: JSVal) {} @@ -118,7 +126,7 @@ impl TestBinding { pub fn PassNullableString(&self, _: Option) {} pub fn PassNullableByteString(&self, _: Option) {} // pub fn PassNullableEnum(&self, _: Option) {} - pub fn PassNullableInterface(&self, _: Option>) {} + pub fn PassNullableInterface(&self, _: Option>) {} pub fn PassNullableUnion(&self, _: Option) {} pub fn PassNullableAny(&self, _: *JSContext, _: Option) {} @@ -136,7 +144,7 @@ impl TestBinding { pub fn PassOptionalString(&self, _: Option) {} pub fn PassOptionalByteString(&self, _: Option) {} pub fn PassOptionalEnum(&self, _: Option) {} - pub fn PassOptionalInterface(&self, _: Option>) {} + pub fn PassOptionalInterface(&self, _: Option>) {} pub fn PassOptionalUnion(&self, _: Option) {} pub fn PassOptionalAny(&self, _: *JSContext, _: Option) {} @@ -183,7 +191,7 @@ impl TestBinding { pub fn PassOptionalNullableStringWithDefault(&self, _: Option) {} pub fn PassOptionalNullableByteStringWithDefault(&self, _: Option) {} // pub fn PassOptionalNullableEnumWithDefault(&self, _: Option) {} - pub fn PassOptionalNullableInterfaceWithDefault(&self, _: Option>) {} + pub fn PassOptionalNullableInterfaceWithDefault(&self, _: Option>) {} pub fn PassOptionalNullableUnionWithDefault(&self, _: Option) {} pub fn PassOptionalAnyWithDefault(&self, _: *JSContext, _: JSVal) {} diff --git a/src/components/script/dom/text.rs b/src/components/script/dom/text.rs index 417ae255cb9..61c37d2ad52 100644 --- a/src/components/script/dom/text.rs +++ b/src/components/script/dom/text.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::TextBinding; use dom::bindings::codegen::InheritTypes::TextDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::error::Fallible; use dom::characterdata::CharacterData; use dom::document::Document; @@ -35,13 +35,16 @@ impl Text { } } - pub fn new(text: DOMString, document: &JS) -> JS { - let node = Text::new_inherited(text, document.clone()); + pub fn new(text: DOMString, document: &JSRef) -> JS { + let node = Text::new_inherited(text, document.unrooted()); Node::reflect_node(~node, document, TextBinding::Wrap) } - pub fn Constructor(owner: &JS, text: DOMString) -> Fallible> { - Ok(Text::new(text.clone(), &owner.get().Document())) + pub fn Constructor(owner: &JSRef, text: DOMString) -> Fallible> { + let roots = RootCollection::new(); + let document = owner.get().Document(); + let document = document.root(&roots); + Ok(Text::new(text.clone(), &document.root_ref())) } pub fn SplitText(&self, _offset: u32) -> Fallible> { diff --git a/src/components/script/dom/uievent.rs b/src/components/script/dom/uievent.rs index 7a2c94fb052..50c97ee8373 100644 --- a/src/components/script/dom/uievent.rs +++ b/src/components/script/dom/uievent.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::UIEventBinding; use dom::bindings::codegen::InheritTypes::UIEventDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference}; use dom::bindings::error::Fallible; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::event::{Event, EventTypeId, UIEventTypeId}; @@ -36,18 +36,20 @@ impl UIEvent { } } - pub fn new(window: &JS) -> JS { + pub fn new(window: &JSRef) -> JS { reflect_dom_object(~UIEvent::new_inherited(UIEventTypeId), window, UIEventBinding::Wrap) } - pub fn Constructor(owner: &JS, + pub fn Constructor(owner: &JSRef, type_: DOMString, init: &UIEventBinding::UIEventInit) -> Fallible> { + let roots = RootCollection::new(); let mut ev = UIEvent::new(owner); + let view = init.view.as_ref().map(|view| view.root(&roots)); ev.get_mut().InitUIEvent(type_, init.parent.bubbles, init.parent.cancelable, - init.view.clone(), init.detail); + view.root_ref(), init.detail); Ok(ev) } @@ -63,10 +65,10 @@ impl UIEvent { type_: DOMString, can_bubble: bool, cancelable: bool, - view: Option>, + view: Option>, detail: i32) { self.event.InitEvent(type_, can_bubble, cancelable); - self.view = view; + self.view = view.map(|view| view.unrooted()); self.detail = detail; } diff --git a/src/components/script/dom/validitystate.rs b/src/components/script/dom/validitystate.rs index 042d41a829a..9a03134169f 100644 --- a/src/components/script/dom/validitystate.rs +++ b/src/components/script/dom/validitystate.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::ValidityStateBinding; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::window::Window; @@ -23,8 +23,8 @@ impl ValidityState { } } - pub fn new(window: &JS) -> JS { - reflect_dom_object(~ValidityState::new_inherited(window.clone()), + pub fn new(window: &JSRef) -> JS { + reflect_dom_object(~ValidityState::new_inherited(window.unrooted()), window, ValidityStateBinding::Wrap) } diff --git a/src/components/script/dom/webidls/TestBinding.webidl b/src/components/script/dom/webidls/TestBinding.webidl index 89325125da2..883e24c329e 100644 --- a/src/components/script/dom/webidls/TestBinding.webidl +++ b/src/components/script/dom/webidls/TestBinding.webidl @@ -156,7 +156,7 @@ interface TestBinding { void passOptionalNullableString(optional DOMString? arg); void passOptionalNullableByteString(optional ByteString? arg); // void passOptionalNullableEnum(optional TestEnum? arg); - void passOptionalNullableInterface(optional Blob? arg); + //void passOptionalNullableInterface(optional Blob? arg); //XXXjdm disabled until later commit void passOptionalNullableUnion(optional (HTMLElement or long)? arg); void passOptionalBooleanWithDefault(optional boolean arg = false); diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index 1e4f7167f45..a1155434d89 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -3,8 +3,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::WindowBinding; -use dom::bindings::js::JS; -use dom::bindings::trace::Untraceable; +use dom::bindings::js::{JS, JSRef}; +use dom::bindings::trace::{Traceable, Untraceable}; use dom::bindings::utils::{Reflectable, Reflector}; use dom::browsercontext::BrowserContext; use dom::document::Document; @@ -35,33 +35,25 @@ use std::rc::Rc; use serialize::{Encoder, Encodable}; use url::Url; +#[deriving(Eq, Encodable, TotalEq)] +pub struct TimerId(i32); + +#[deriving(Encodable)] pub struct TimerHandle { - pub handle: i32, - pub cancel_chan: Option>, + pub handle: TimerId, + pub data: TimerData, + pub cancel_chan: Untraceable>>, } -impl, E> Encodable for TimerHandle { - fn encode(&self, _s: &mut S) -> Result<(), E> { - Ok(()) - } -} - -impl Hash for TimerHandle { +impl Hash for TimerId { fn hash(&self, state: &mut sip::SipState) { - self.handle.hash(state); + let TimerId(id) = *self; + id.hash(state); } } -impl Eq for TimerHandle { - fn eq(&self, other: &TimerHandle) -> bool { - self.handle == other.handle - } -} - -impl TotalEq for TimerHandle { } - impl TimerHandle { - fn cancel(&self) { + fn cancel(&mut self) { self.cancel_chan.as_ref().map(|chan| chan.send(())); } } @@ -74,7 +66,7 @@ pub struct Window { pub location: Option>, pub navigator: Option>, pub image_cache_task: ImageCacheTask, - pub active_timers: ~HashMap, + pub active_timers: ~HashMap, pub next_timer_handle: i32, pub compositor: Untraceable<~ScriptListener>, pub browser_context: Option, @@ -98,7 +90,7 @@ impl Window { #[unsafe_destructor] impl Drop for Window { fn drop(&mut self) { - for timer_handle in self.active_timers.values() { + for (_, timer_handle) in self.active_timers.mut_iter() { timer_handle.cancel(); } } @@ -107,10 +99,10 @@ impl Drop for Window { // Holder for the various JS values associated with setTimeout // (ie. function value to invoke and all arguments to pass // to the function when calling it) +#[deriving(Encodable)] pub struct TimerData { - pub handle: i32, pub is_interval: bool, - pub funval: JSVal, + pub funval: Traceable, } impl Window { @@ -160,21 +152,21 @@ impl Window { None } - pub fn Location(&mut self, abstract_self: &JS) -> JS { + pub fn Location(&mut self, abstract_self: &JSRef) -> JS { if self.location.is_none() { self.location = Some(Location::new(abstract_self, self.page.clone())); } self.location.get_ref().clone() } - pub fn Console(&mut self, abstract_self: &JS) -> JS { + pub fn Console(&mut self, abstract_self: &JSRef) -> JS { if self.console.is_none() { self.console = Some(Console::new(abstract_self)); } self.console.get_ref().clone() } - pub fn Navigator(&mut self, abstract_self: &JS) -> JS { + pub fn Navigator(&mut self, abstract_self: &JSRef) -> JS { if self.navigator.is_none() { self.navigator = Some(Navigator::new(abstract_self)); } @@ -243,13 +235,8 @@ impl Window { let id = select.wait(); if id == timeout_handle.id() { timeout_port.recv(); - let data = ~TimerData { - handle: handle, - is_interval: is_interval, - funval: callback, - }; let ScriptChan(ref chan) = chan; - chan.send(FireTimerMsg(page_id, data)); + chan.send(FireTimerMsg(page_id, TimerId(handle))); if !is_interval { break; } @@ -258,7 +245,16 @@ impl Window { } } }); - self.active_timers.insert(handle, TimerHandle { handle: handle, cancel_chan: Some(cancel_chan) }); + let timer_id = TimerId(handle); + let timer = TimerHandle { + handle: timer_id, + cancel_chan: Untraceable::new(Some(cancel_chan)), + data: TimerData { + is_interval: is_interval, + funval: Traceable::new(callback), + } + }; + self.active_timers.insert(timer_id, timer); handle } @@ -267,11 +263,12 @@ impl Window { } pub fn ClearTimeout(&mut self, handle: i32) { - let timer_handle = self.active_timers.pop(&handle); + let mut timer_handle = self.active_timers.pop(&TimerId(handle)); match timer_handle { - Some(handle) => handle.cancel(), + Some(ref mut handle) => handle.cancel(), None => { } } + self.active_timers.remove(&TimerId(handle)); } pub fn SetInterval(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32 { @@ -282,11 +279,11 @@ impl Window { self.ClearTimeout(handle); } - pub fn Window(&self, abstract_self: &JS) -> JS { - abstract_self.clone() + pub fn Window(&self, abstract_self: &JSRef) -> JS { + abstract_self.unrooted() } - pub fn Self(&self, abstract_self: &JS) -> JS { + pub fn Self(&self, abstract_self: &JSRef) -> JS { self.Window(abstract_self) } diff --git a/src/components/script/dom/xmlhttprequest.rs b/src/components/script/dom/xmlhttprequest.rs index 76099a4d0d0..9f2bbf180b5 100644 --- a/src/components/script/dom/xmlhttprequest.rs +++ b/src/components/script/dom/xmlhttprequest.rs @@ -10,7 +10,7 @@ use dom::bindings::codegen::InheritTypes::XMLHttpRequestDerived; use dom::document::Document; use dom::eventtarget::{EventTarget, XMLHttpRequestTargetTypeId}; use dom::bindings::error::Fallible; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use js::jsapi::JSContext; use js::jsval::{JSVal, NullValue}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; @@ -41,7 +41,7 @@ pub struct XMLHttpRequest { } impl XMLHttpRequest { - pub fn new_inherited(owner: &JS) -> XMLHttpRequest { + pub fn new_inherited(owner: &JSRef) -> XMLHttpRequest { XMLHttpRequest { eventtarget: XMLHttpRequestEventTarget::new_inherited(XMLHttpRequestTypeId), ready_state: 0, @@ -56,12 +56,12 @@ impl XMLHttpRequest { response_xml: None } } - pub fn new(window: &JS) -> JS { + pub fn new(window: &JSRef) -> JS { reflect_dom_object(~XMLHttpRequest::new_inherited(window), window, XMLHttpRequestBinding::Wrap) } - pub fn Constructor(owner: &JS) -> Fallible> { + pub fn Constructor(owner: &JSRef) -> Fallible> { Ok(XMLHttpRequest::new(owner)) } pub fn ReadyState(&self) -> u16 { diff --git a/src/components/script/dom/xmlhttprequestupload.rs b/src/components/script/dom/xmlhttprequestupload.rs index bcfb2d02c47..5e06d51b1d3 100644 --- a/src/components/script/dom/xmlhttprequestupload.rs +++ b/src/components/script/dom/xmlhttprequestupload.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::XMLHttpRequestUploadDerived; use dom::bindings::codegen::BindingDeclarations::XMLHttpRequestUploadBinding; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::eventtarget::{EventTarget, XMLHttpRequestTargetTypeId}; use dom::window::Window; @@ -22,7 +22,7 @@ impl XMLHttpRequestUpload { eventtarget:XMLHttpRequestEventTarget::new_inherited(XMLHttpRequestUploadTypeId) } } - pub fn new(window: &JS) -> JS { + pub fn new(window: &JSRef) -> JS { reflect_dom_object(~XMLHttpRequestUpload::new_inherited(), window, XMLHttpRequestUploadBinding::Wrap) diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 18945f9062a..771b75f3e9c 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, TextCast, ElementCast}; use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::utils::Reflectable; use dom::document::Document; use dom::element::{AttributeHandlers, HTMLLinkElementTypeId, HTMLIFrameElementTypeId}; @@ -75,16 +75,19 @@ pub struct HtmlParserResult { } trait NodeWrapping { - unsafe fn to_hubbub_node(&self) -> hubbub::NodeDataPtr; - unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr) -> Self; + unsafe fn to_hubbub_node(&self, roots: &RootCollection) -> hubbub::NodeDataPtr; + unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr, roots: Option<&RootCollection>) -> Self; } impl NodeWrapping for JS { - unsafe fn to_hubbub_node(&self) -> hubbub::NodeDataPtr { + unsafe fn to_hubbub_node(&self, roots: &RootCollection) -> hubbub::NodeDataPtr { + roots.root_raw(self.reflector().get_jsobject()); cast::transmute(self.get()) } - unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr) -> JS { - JS::from_raw(cast::transmute(n)) + unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr, roots: Option<&RootCollection>) -> JS { + let js = JS::from_raw(cast::transmute(n)); + let _ = roots.map(|roots| roots.unroot_raw(js.reflector().get_jsobject())); + js } } @@ -160,7 +163,7 @@ fn js_script_listener(to_parent: Sender, // Silly macros to handle constructing DOM nodes. This produces bad code and should be optimized // via atomization (issue #85). -pub fn build_element_from_tag(tag: DOMString, document: &JS) -> JS { +pub fn build_element_from_tag(tag: DOMString, document: &JSRef) -> JS { // TODO (Issue #85): use atoms handle_element!(document, tag, "a", HTMLAnchorElement); handle_element!(document, tag, "applet", HTMLAppletElement); @@ -246,7 +249,7 @@ pub fn build_element_from_tag(tag: DOMString, document: &JS) -> JS, + document: &mut JSRef, url: Url, resource_task: ResourceTask) -> HtmlParserResult { @@ -292,7 +295,9 @@ pub fn parse_html(page: &Page, let mut parser = hubbub::Parser("UTF-8", false); debug!("created parser"); - parser.set_document_node(unsafe { document.to_hubbub_node() }); + let roots = RootCollection::new(); + + parser.set_document_node(unsafe { document.unrooted().to_hubbub_node(&roots) }); parser.enable_scripting(true); parser.enable_styling(true); @@ -309,7 +314,7 @@ pub fn parse_html(page: &Page, let tmp_borrow = doc_cell.borrow(); let tmp = &*tmp_borrow; let comment: JS = NodeCast::from(&Comment::new(data, *tmp)); - unsafe { comment.to_hubbub_node() } + unsafe { comment.to_hubbub_node(&roots) } }, create_doctype: |doctype: ~hubbub::Doctype| { debug!("create doctype"); @@ -322,15 +327,16 @@ pub fn parse_html(page: &Page, let tmp = &*tmp_borrow; let doctype_node = DocumentType::new(name, public_id, system_id, *tmp); unsafe { - doctype_node.to_hubbub_node() + doctype_node.to_hubbub_node(&roots) } }, create_element: |tag: ~hubbub::Tag| { - debug!("create element"); + debug!("create element {:?}", tag.name.clone()); // NOTE: tmp vars are workaround for lifetime issues. Both required. let tmp_borrow = doc_cell.borrow(); let tmp = &*tmp_borrow; let mut element = build_element_from_tag(tag.name.clone(), *tmp); + let _element_root = element.root(&roots); debug!("-- attach attrs"); for attr in tag.attributes.iter() { @@ -389,7 +395,7 @@ pub fn parse_html(page: &Page, _ => {} } - unsafe { element.to_hubbub_node() } + unsafe { element.to_hubbub_node(&roots) } }, create_text: |data: ~str| { debug!("create text"); @@ -397,16 +403,17 @@ pub fn parse_html(page: &Page, let tmp_borrow = doc_cell.borrow(); let tmp = &*tmp_borrow; let text = Text::new(data, *tmp); - unsafe { text.to_hubbub_node() } + unsafe { text.to_hubbub_node(&roots) } }, ref_node: |_| {}, unref_node: |_| {}, append_child: |parent: hubbub::NodeDataPtr, child: hubbub::NodeDataPtr| { unsafe { debug!("append child {:x} {:x}", parent, child); - let mut parent: JS = NodeWrapping::from_hubbub_node(parent); - let mut child: JS = NodeWrapping::from_hubbub_node(child); - assert!(parent.AppendChild(&mut child).is_ok()); + let mut parent: JS = NodeWrapping::from_hubbub_node(parent, None); + let child: JS = NodeWrapping::from_hubbub_node(child, Some(&roots)); + let child = child.root(&roots); + assert!(parent.AppendChild(&mut child.root_ref()).is_ok()); } child }, @@ -457,7 +464,7 @@ pub fn parse_html(page: &Page, }, complete_script: |script| { unsafe { - let script: JS = NodeWrapping::from_hubbub_node(script); + let script: JS = NodeWrapping::from_hubbub_node(script, None); match script.get_attribute(Null, "src") { Some(src) => { debug!("found script: {:s}", src.get().Value()); diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index a9cd5edbaff..f442ddae7c1 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -7,9 +7,9 @@ use dom::bindings::codegen::RegisterBindings; use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, ElementCast, EventCast}; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference}; use dom::bindings::trace::{Traceable, Untraceable}; -use dom::bindings::utils::{Reflectable, GlobalStaticData, with_gc_enabled, wrap_for_same_compartment}; +use dom::bindings::utils::{Reflectable, GlobalStaticData, wrap_for_same_compartment}; use dom::document::{Document, HTMLDocument}; use dom::element::{Element, AttributeHandlers}; use dom::event::{Event_, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent}; @@ -17,7 +17,7 @@ use dom::event::Event; use dom::uievent::UIEvent; use dom::eventtarget::EventTarget; use dom::node::{Node, NodeHelpers}; -use dom::window::{TimerData, Window}; +use dom::window::{TimerId, Window}; use html::hubbub_html_parser::HtmlParserResult; use html::hubbub_html_parser::{HtmlDiscoveredStyle, HtmlDiscoveredIFrame, HtmlDiscoveredScript}; use html::hubbub_html_parser; @@ -32,7 +32,7 @@ use layout_interface; use geom::point::Point2D; use geom::size::Size2D; use js::global::DEBUG_FNS; -use js::jsapi::{JSObject, JS_InhibitGC, JS_AllowGC, JS_CallFunctionValue, JS_DefineFunctions}; +use js::jsapi::{JSObject, JS_CallFunctionValue, JS_DefineFunctions}; use js::jsapi::JS_SetWrapObjectCallbacks; use js::jsval::NullValue; use js::rust::{Cx, RtUtils}; @@ -73,7 +73,7 @@ pub enum ScriptMsg { /// Window resized. Sends a DOM event eventually, but first we combine events. ResizeMsg(PipelineId, Size2D), /// Fires a JavaScript timeout. - FireTimerMsg(PipelineId, ~TimerData), + FireTimerMsg(PipelineId, TimerId), /// Notifies script that reflow is finished. ReflowCompleteMsg(PipelineId, uint), /// Notifies script that window has been resized but to not take immediate action. @@ -427,10 +427,6 @@ impl Page { js_context.set_default_options_and_version(); js_context.set_logging_error_reporter(); - unsafe { - JS_InhibitGC(js_context.deref().ptr); - } - let mut js_info = self.mut_js_info(); *js_info = Some(JSPageInfo { dom_static: GlobalStaticData(), @@ -554,11 +550,7 @@ impl<'a> Drop for ScriptMemoryFailsafe<'a> { Some(owner) => { let mut page_tree = owner.page_tree.borrow_mut(); for page in page_tree.iter() { - let mut js_info = page.mut_js_info(); - unsafe { - JS_AllowGC(js_info.get_ref().js_context.deref().deref().ptr); - } - *js_info = None; + *page.mut_js_info() = None; } } None => (), @@ -700,7 +692,7 @@ impl ScriptTask { AttachLayoutMsg(new_layout_info) => self.handle_new_layout(new_layout_info), LoadMsg(id, url) => self.load(id, url), SendEventMsg(id, event) => self.handle_event(id, event), - FireTimerMsg(id, timer_data) => self.handle_fire_timer_msg(id, timer_data), + FireTimerMsg(id, timer_id) => self.handle_fire_timer_msg(id, timer_id), NavigateMsg(direction) => self.handle_navigate_msg(direction), ReflowCompleteMsg(id, reflow_id) => self.handle_reflow_complete_msg(id, reflow_id), ResizeInactiveMsg(id, new_size) => self.handle_resize_inactive_msg(id, new_size), @@ -733,35 +725,35 @@ impl ScriptTask { } /// Handles a timer that fired. - fn handle_fire_timer_msg(&self, id: PipelineId, timer_data: ~TimerData) { + fn handle_fire_timer_msg(&self, id: PipelineId, timer_id: TimerId) { let mut page_tree = self.page_tree.borrow_mut(); let page = page_tree.find(id).expect("ScriptTask: received fire timer msg for a pipeline ID not associated with this script task. This is a bug.").page(); let frame = page.frame(); let mut window = frame.get_ref().window.clone(); - { - let timer_handle = window.get().active_timers.find(&timer_data.handle); - if timer_handle.is_none() { - return; + let is_interval; + match window.get().active_timers.find(&timer_id) { + None => return, + Some(timer_handle) => { + let this_value = window.reflector().get_jsobject(); + + // TODO: Support extra arguments. This requires passing a `*JSVal` array as `argv`. + let rval = NullValue(); + let js_info = page.js_info(); + let cx = js_info.get_ref().js_context.deref().deref().ptr; + unsafe { + JS_CallFunctionValue(cx, this_value, *timer_handle.data.funval, + 0, ptr::null(), &rval); + } + + is_interval = timer_handle.data.is_interval; } } - if !timer_data.is_interval { - window.get_mut().active_timers.remove(&timer_data.handle); + if !is_interval { + window.get_mut().active_timers.remove(&timer_id); } - - let this_value = window.reflector().get_jsobject(); - - // TODO: Support extra arguments. This requires passing a `*JSVal` array as `argv`. - let rval = NullValue(); - let js_info = page.js_info(); - let cx = js_info.get_ref().js_context.deref().deref().ptr; - with_gc_enabled(cx, || { - unsafe { - JS_CallFunctionValue(cx, this_value, timer_data.funval, 0, ptr::null(), &rval); - } - }); } /// Handles a notification that reflow completed. @@ -849,6 +841,8 @@ impl ScriptTask { fn load(&self, pipeline_id: PipelineId, url: Url) { debug!("ScriptTask: loading {:?} on page {:?}", url, pipeline_id); + let roots = RootCollection::new(); + let mut page_tree = self.page_tree.borrow_mut(); let page_tree = page_tree.find(pipeline_id).expect("ScriptTask: received a load message for a layout channel that is not associated with this script task. This @@ -875,13 +869,15 @@ impl ScriptTask { self.chan.clone(), self.compositor.dup(), self.image_cache_task.clone()); + let window_root = window.root(&roots); page.initialize_js_info(cx.clone(), window.reflector().get_jsobject()); - let mut document = Document::new(&window, Some(url.clone()), HTMLDocument, None); + let mut document = Document::new(&window_root.root_ref(), Some(url.clone()), HTMLDocument, None); + let doc_root = document.root(&roots); window.get_mut().init_browser_context(&document); { let mut js_info = page.mut_js_info(); - RegisterBindings::Register(&window, js_info.get_mut_ref()); + RegisterBindings::Register(&window_root.root_ref(), js_info.get_mut_ref()); } self.compositor.set_ready_state(Loading); @@ -889,7 +885,7 @@ impl ScriptTask { // // Note: We can parse the next document in parallel with any previous documents. let html_parsing_result = hubbub_html_parser::parse_html(page, - &mut document, + &mut doc_root.root_ref(), url.clone(), self.resource_task.clone()); @@ -965,26 +961,28 @@ impl ScriptTask { // Evaluate every script in the document. for file in js_scripts.iter() { - with_gc_enabled((*cx).ptr, || { - let global_obj = window.reflector().get_jsobject(); - //FIXME: this should have some kind of error handling, or explicitly - // drop an exception on the floor. - match cx.evaluate_script(global_obj, file.data.clone(), file.url.to_str(), 1) { - Ok(_) => (), - Err(_) => println!("evaluate_script failed") - } - }); + let global_obj = window.reflector().get_jsobject(); + //FIXME: this should have some kind of error handling, or explicitly + // drop an exception on the floor. + match cx.evaluate_script(global_obj, file.data.clone(), file.url.to_str(), 1) { + Ok(_) => (), + Err(_) => println!("evaluate_script failed") + } } // 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 mut event = Event::new(&window); + let mut event = Event::new(&window_root.root_ref()); event.get_mut().InitEvent(~"load", false, false); + let event = event.root(&roots); let doctarget = EventTargetCast::from(&document); + let doctarget = doctarget.root(&roots); let mut wintarget: JS = EventTargetCast::from(&window); - let winclone = wintarget.clone(); - let _ = wintarget.get_mut().dispatch_event_with_target(&winclone, Some(doctarget), &mut event); + let wintarget_root = wintarget.root(&roots); + let _ = wintarget.get_mut().dispatch_event_with_target(&wintarget_root.root_ref(), + Some(doctarget.root_ref()), + &mut event.root_ref()); let mut fragment_node = page.fragment_node.deref().borrow_mut(); *fragment_node = fragment.map_or(None, |fragid| page.find_fragment_node(fragid)); @@ -1009,48 +1007,58 @@ impl ScriptTask { /// /// TODO: Actually perform DOM event dispatch. fn handle_event(&self, pipeline_id: PipelineId, event: Event_) { - let mut page_tree = self.page_tree.borrow_mut(); - let page = page_tree.find(pipeline_id).expect("ScriptTask: received an event - message for a layout channel that is not associated with this script task. This - is a bug.").page(); + fn get_page<'a>(page_tree: &'a mut PageTree, pipeline_id: PipelineId) -> &'a Page { + page_tree.find(pipeline_id).expect("ScriptTask: received an event \ + message for a layout channel that is not associated with this script task.\ + This is a bug.").page() + } match event { ResizeEvent(new_width, new_height) => { debug!("script got resize event: {:u}, {:u}", new_width, new_height); - { - let mut window_size = page.window_size.deref().borrow_mut(); - *window_size = Size2D(new_width, new_height); - } + let window = { + let mut page_tree = self.page_tree.borrow_mut(); + let page = get_page(&mut *page_tree, pipeline_id); + { + let mut window_size = page.window_size.deref().borrow_mut(); + *window_size = Size2D(new_width, new_height); + } - { let frame = page.frame(); if frame.is_some() { page.damage(ReflowDocumentDamage); page.reflow(ReflowForDisplay, self.chan.clone(), self.compositor) } - } - let mut fragment_node = page.fragment_node.deref().borrow_mut(); - match fragment_node.take() { - Some(node) => self.scroll_fragment_point(pipeline_id, node), - None => {} - } + let mut fragment_node = page.fragment_node.deref().borrow_mut(); + match fragment_node.take() { + Some(node) => self.scroll_fragment_point(pipeline_id, node), + None => {} + } - let frame = page.frame(); - match *frame { - Some(ref frame) => { + frame.as_ref().map(|frame| frame.window.clone()) + }; + + match window { + Some(ref window) => { // http://dev.w3.org/csswg/cssom-view/#resizing-viewports // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-resize - let mut uievent = UIEvent::new(&frame.window); - uievent.get_mut().InitUIEvent(~"resize", false, false, Some(frame.window.clone()), 0i32); - let event: &mut JS = &mut EventCast::from(&uievent); + let roots = RootCollection::new(); + let window_root = window.root(&roots); - let mut wintarget: JS = EventTargetCast::from(&frame.window); - let winclone = wintarget.clone(); - let _ = wintarget.get_mut().dispatch_event_with_target(&winclone, None, event); + let mut uievent = UIEvent::new(&window_root.root_ref()); + uievent.get_mut().InitUIEvent(~"resize", false, false, Some(window_root).root_ref(), 0i32); + let event: JS = EventCast::from(&uievent); + let event = event.root(&roots); + + let mut wintarget: JS = EventTargetCast::from(window); + let targetroot = wintarget.root(&roots); + let _ = wintarget.get_mut().dispatch_event_with_target(&targetroot.root_ref(), + None, + &mut event.root_ref()); } - None =>() + None => () } } @@ -1058,6 +1066,8 @@ impl ScriptTask { ReflowEvent => { debug!("script got reflow event"); + let mut page_tree = self.page_tree.borrow_mut(); + let page = get_page(&mut *page_tree, pipeline_id); let frame = page.frame(); if frame.is_some() { page.damage(MatchSelectorsDocumentDamage); @@ -1067,6 +1077,8 @@ impl ScriptTask { ClickEvent(_button, point) => { debug!("ClickEvent: clicked at {:?}", point); + let mut page_tree = self.page_tree.borrow_mut(); + let page = get_page(&mut *page_tree, pipeline_id); match page.hit_test(&point) { Some(node_address) => { debug!("node address is {:?}", node_address); @@ -1087,7 +1099,9 @@ impl ScriptTask { if node.is_element() { let element: JS = ElementCast::to(&node).unwrap(); if "a" == element.get().local_name { - self.load_url_from_element(page, &element) + let roots = RootCollection::new(); + let element = element.root(&roots); + self.load_url_from_element(page, &element.root_ref()) } } } @@ -1098,6 +1112,8 @@ impl ScriptTask { MouseDownEvent(..) => {} MouseUpEvent(..) => {} MouseMoveEvent(point) => { + let mut page_tree = self.page_tree.borrow_mut(); + let page = get_page(&mut *page_tree, pipeline_id); match page.get_nodes_under_mouse(&point) { Some(node_address) => { @@ -1165,9 +1181,9 @@ impl ScriptTask { } } - fn load_url_from_element(&self, page: &Page, element: &JS) { + fn load_url_from_element(&self, page: &Page, element: &JSRef) { // if the node's element is "a," load url from href attr - let attr = element.get_attribute(Null, "href"); + let attr = element.unrooted().get_attribute(Null, "href"); for href in attr.iter() { debug!("ScriptTask: clicked on link to {:s}", href.get().Value()); let click_frag = href.get().value_ref().starts_with("#"); @@ -1202,9 +1218,6 @@ fn shut_down_layout(page: &Page) { // compartment to shutdown, run GC, etc. let mut js_info = page.mut_js_info(); - unsafe { - JS_AllowGC(js_info.get_ref().js_context.deref().deref().ptr); - } let mut frame = page.mut_frame(); *frame = None; From d7b96db33ca8f2b8a162df38e0f00e95f5ea6fa1 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 31 Mar 2014 18:41:28 -0400 Subject: [PATCH 02/16] Implement safe rooting strategy via Unrooted, Root, JSRef, and JS. --- src/components/main/layout/wrapper.rs | 4 +- src/components/script/dom/attr.rs | 16 +- src/components/script/dom/attrlist.rs | 10 +- .../dom/bindings/codegen/CodegenRust.py | 46 +- .../dom/bindings/codegen/Configuration.py | 1 + src/components/script/dom/bindings/js.rs | 207 ++++- src/components/script/dom/bindings/utils.rs | 14 +- src/components/script/dom/blob.rs | 8 +- src/components/script/dom/browsercontext.rs | 8 +- src/components/script/dom/clientrect.rs | 4 +- src/components/script/dom/clientrectlist.rs | 14 +- src/components/script/dom/comment.rs | 6 +- src/components/script/dom/console.rs | 4 +- src/components/script/dom/document.rs | 284 +++---- src/components/script/dom/documentfragment.rs | 10 +- src/components/script/dom/documenttype.rs | 4 +- src/components/script/dom/domexception.rs | 4 +- .../script/dom/domimplementation.rs | 86 +- src/components/script/dom/domparser.rs | 8 +- src/components/script/dom/element.rs | 253 +++--- src/components/script/dom/event.rs | 21 +- src/components/script/dom/eventdispatcher.rs | 37 +- src/components/script/dom/eventtarget.rs | 12 +- src/components/script/dom/formdata.rs | 6 +- .../script/dom/htmlanchorelement.rs | 4 +- .../script/dom/htmlappletelement.rs | 4 +- src/components/script/dom/htmlareaelement.rs | 4 +- src/components/script/dom/htmlaudioelement.rs | 4 +- src/components/script/dom/htmlbaseelement.rs | 4 +- src/components/script/dom/htmlbodyelement.rs | 4 +- src/components/script/dom/htmlbrelement.rs | 4 +- .../script/dom/htmlbuttonelement.rs | 13 +- .../script/dom/htmlcanvaselement.rs | 4 +- src/components/script/dom/htmlcollection.rs | 73 +- src/components/script/dom/htmldataelement.rs | 4 +- .../script/dom/htmldatalistelement.rs | 10 +- .../script/dom/htmldirectoryelement.rs | 4 +- src/components/script/dom/htmldivelement.rs | 4 +- src/components/script/dom/htmldlistelement.rs | 4 +- src/components/script/dom/htmlelement.rs | 12 +- src/components/script/dom/htmlembedelement.rs | 6 +- .../script/dom/htmlfieldsetelement.rs | 25 +- src/components/script/dom/htmlfontelement.rs | 4 +- src/components/script/dom/htmlformelement.rs | 15 +- src/components/script/dom/htmlframeelement.rs | 8 +- .../script/dom/htmlframesetelement.rs | 4 +- src/components/script/dom/htmlheadelement.rs | 4 +- .../script/dom/htmlheadingelement.rs | 4 +- src/components/script/dom/htmlhrelement.rs | 4 +- src/components/script/dom/htmlhtmlelement.rs | 4 +- .../script/dom/htmliframeelement.rs | 20 +- src/components/script/dom/htmlimageelement.rs | 74 +- src/components/script/dom/htmlinputelement.rs | 4 +- src/components/script/dom/htmllabelelement.rs | 4 +- .../script/dom/htmllegendelement.rs | 4 +- src/components/script/dom/htmllielement.rs | 4 +- src/components/script/dom/htmllinkelement.rs | 4 +- src/components/script/dom/htmlmainelement.rs | 4 +- src/components/script/dom/htmlmapelement.rs | 13 +- src/components/script/dom/htmlmetaelement.rs | 4 +- src/components/script/dom/htmlmeterelement.rs | 4 +- src/components/script/dom/htmlmodelement.rs | 4 +- .../script/dom/htmlobjectelement.rs | 37 +- src/components/script/dom/htmlolistelement.rs | 4 +- .../script/dom/htmloptgroupelement.rs | 4 +- .../script/dom/htmloptionelement.rs | 6 +- .../script/dom/htmloutputelement.rs | 15 +- .../script/dom/htmlparagraphelement.rs | 4 +- src/components/script/dom/htmlparamelement.rs | 4 +- src/components/script/dom/htmlpreelement.rs | 4 +- .../script/dom/htmlprogresselement.rs | 4 +- src/components/script/dom/htmlquoteelement.rs | 4 +- .../script/dom/htmlscriptelement.rs | 6 +- .../script/dom/htmlselectelement.rs | 21 +- src/components/script/dom/htmlserializer.rs | 46 +- .../script/dom/htmlsourceelement.rs | 4 +- src/components/script/dom/htmlspanelement.rs | 4 +- src/components/script/dom/htmlstyleelement.rs | 21 +- .../script/dom/htmltablecaptionelement.rs | 4 +- .../script/dom/htmltablecolelement.rs | 4 +- .../script/dom/htmltabledatacellelement.rs | 4 +- src/components/script/dom/htmltableelement.rs | 4 +- .../script/dom/htmltableheadercellelement.rs | 4 +- .../script/dom/htmltablerowelement.rs | 4 +- .../script/dom/htmltablesectionelement.rs | 4 +- .../script/dom/htmltemplateelement.rs | 4 +- .../script/dom/htmltextareaelement.rs | 4 +- src/components/script/dom/htmltimeelement.rs | 4 +- src/components/script/dom/htmltitleelement.rs | 4 +- src/components/script/dom/htmltrackelement.rs | 4 +- src/components/script/dom/htmlulistelement.rs | 4 +- .../script/dom/htmlunknownelement.rs | 4 +- src/components/script/dom/htmlvideoelement.rs | 4 +- src/components/script/dom/location.rs | 4 +- src/components/script/dom/mouseevent.rs | 14 +- src/components/script/dom/navigator.rs | 4 +- src/components/script/dom/node.rs | 765 +++++++++--------- src/components/script/dom/nodelist.rs | 29 +- .../script/dom/processinginstruction.rs | 4 +- src/components/script/dom/testbinding.rs | 10 +- src/components/script/dom/text.rs | 8 +- src/components/script/dom/uievent.rs | 16 +- src/components/script/dom/validitystate.rs | 4 +- src/components/script/dom/virtualmethods.rs | 30 +- src/components/script/dom/window.rs | 38 +- src/components/script/dom/xmlhttprequest.rs | 24 +- .../script/dom/xmlhttprequestupload.rs | 4 +- .../script/html/hubbub_html_parser.rs | 91 ++- src/components/script/script_task.rs | 157 ++-- 109 files changed, 1568 insertions(+), 1326 deletions(-) diff --git a/src/components/main/layout/wrapper.rs b/src/components/main/layout/wrapper.rs index 162c06d52a9..b9532e2d31c 100644 --- a/src/components/main/layout/wrapper.rs +++ b/src/components/main/layout/wrapper.rs @@ -40,7 +40,7 @@ use script::dom::element::{Element, HTMLAreaElementTypeId, HTMLAnchorElementType use script::dom::element::{HTMLLinkElementTypeId}; use script::dom::htmliframeelement::HTMLIFrameElement; use script::dom::htmlimageelement::HTMLImageElement; -use script::dom::node::{DocumentNodeTypeId, ElementNodeTypeId, Node, NodeTypeId, NodeHelpers}; +use script::dom::node::{DocumentNodeTypeId, ElementNodeTypeId, Node, NodeTypeId, LayoutNodeHelpers}; use script::dom::text::Text; use servo_msg::constellation_msg::{PipelineId, SubpageId}; use servo_util::namespace; @@ -163,7 +163,7 @@ impl<'ln> TLayoutNode for LayoutNode<'ln> { } fn type_id(&self) -> Option { - Some(self.node.type_id()) + Some(self.node.type_id_for_layout()) } unsafe fn get_jsmanaged<'a>(&'a self) -> &'a JS { diff --git a/src/components/script/dom/attr.rs b/src/components/script/dom/attr.rs index 5b5fc39d1c9..d6c2d530862 100644 --- a/src/components/script/dom/attr.rs +++ b/src/components/script/dom/attr.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::AttrBinding; use dom::bindings::codegen::InheritTypes::NodeCast; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted, RootCollection}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::element::Element; use dom::node::Node; @@ -45,7 +45,7 @@ impl Reflectable for Attr { impl Attr { fn new_inherited(local_name: DOMString, value: DOMString, name: DOMString, namespace: Namespace, - prefix: Option, owner: JS) -> Attr { + prefix: Option, owner: &JSRef) -> Attr { Attr { reflector_: Reflector::new(), local_name: local_name, @@ -53,25 +53,27 @@ impl Attr { name: name, //TODO: Intern attribute names namespace: namespace, prefix: prefix, - owner: owner, + owner: owner.unrooted(), } } pub fn new(window: &JSRef, local_name: DOMString, value: DOMString, name: DOMString, namespace: Namespace, - prefix: Option, owner: JS) -> JS { + prefix: Option, owner: &JSRef) -> Unrooted { let attr = Attr::new_inherited(local_name, value, name, namespace, prefix, owner); reflect_dom_object(~attr, window, AttrBinding::Wrap) } pub fn set_value(&mut self, set_type: AttrSettingType, value: DOMString) { - let node: JS = NodeCast::from(&self.owner); + let roots = RootCollection::new(); + let owner = self.owner.root(&roots); + let node: &JSRef = NodeCast::from_ref(&*owner); let namespace_is_null = self.namespace == namespace::Null; match set_type { ReplacedAttr => { if namespace_is_null { - vtable_for(&node).before_remove_attr(self.local_name.clone(), self.value.clone()); + vtable_for(node).before_remove_attr(self.local_name.clone(), self.value.clone()); } } FirstSetAttr => {} @@ -80,7 +82,7 @@ impl Attr { self.value = value; if namespace_is_null { - vtable_for(&node).after_set_attr(self.local_name.clone(), self.value.clone()); + vtable_for(node).after_set_attr(self.local_name.clone(), self.value.clone()); } } diff --git a/src/components/script/dom/attrlist.rs b/src/components/script/dom/attrlist.rs index ed476897c82..78f8211e3e0 100644 --- a/src/components/script/dom/attrlist.rs +++ b/src/components/script/dom/attrlist.rs @@ -4,7 +4,7 @@ use dom::attr::Attr; use dom::bindings::codegen::BindingDeclarations::AttrListBinding; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::element::Element; use dom::window::Window; @@ -25,7 +25,7 @@ impl AttrList { } } - pub fn new(window: &JSRef, elem: &JSRef) -> JS { + pub fn new(window: &JSRef, elem: &JSRef) -> Unrooted { reflect_dom_object(~AttrList::new_inherited(window.unrooted(), elem.unrooted()), window, AttrListBinding::Wrap) } @@ -34,11 +34,11 @@ impl AttrList { self.owner.get().attrs.len() as u32 } - pub fn Item(&self, index: u32) -> Option> { - self.owner.get().attrs.as_slice().get(index as uint).map(|x| x.clone()) + pub fn Item(&self, index: u32) -> Option> { + self.owner.get().attrs.as_slice().get(index as uint).map(|x| Unrooted::new(x.clone())) } - pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { + pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { let item = self.Item(index); *found = item.is_some(); item diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 5d4f6cc9bf4..30ff08e21ff 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -1008,6 +1008,13 @@ def typeNeedsCx(type, retVal=False): return True return type.isCallback() or type.isAny() or type.isObject() +def typeRetValNeedsRooting(type): + if type is None: + return False + if type.nullable(): + type = type.inner + return type.isGeckoInterface() and not type.isCallback() + def memberIsCreator(member): return member.getExtendedAttribute("Creator") is not None @@ -1039,7 +1046,7 @@ def getRetvalDeclarationForType(returnType, descriptorProvider): if returnType.isGeckoInterface(): descriptor = descriptorProvider.getDescriptor( returnType.unroll().inner.identifier.name) - result = CGGeneric(descriptor.nativeType) + result = CGGeneric(descriptor.returnType) if returnType.nullable(): result = CGWrapper(result, pre="Option<", post=">") return result @@ -2235,6 +2242,14 @@ class CGCallGenerator(CGThing): self.cgRoot.append(CGGeneric("}")) self.cgRoot.append(CGGeneric("result = result_fallible.unwrap();")) + if typeRetValNeedsRooting(returnType): + rooted_value = CGGeneric("result.root(&roots).root_ref().unrooted()") + if returnType.nullable(): + rooted_value = CGWrapper(rooted_value, pre="result.map(|result| ", post=")") + rooted_value = CGWrapper(rooted_value, pre="let result = ", post=";") + + self.cgRoot.append(rooted_value) + def define(self): return self.cgRoot.define() @@ -4306,7 +4321,7 @@ class CGBindingRoot(CGThing): 'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}', 'dom::types::*', 'dom::bindings', - 'dom::bindings::js::{JS, JSRef, RootCollection, RootedReference}', + 'dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Unrooted}', 'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}', 'dom::bindings::utils::{ConstantSpec, cx_for_dom_object, Default}', 'dom::bindings::utils::{dom_object_slot, DOM_OBJECT_SLOT, DOMClass}', @@ -5277,8 +5292,9 @@ class GlobalGenRoots(): descriptors = config.getDescriptors(register=True, hasInterfaceObject=True) allprotos = [CGGeneric("#![allow(unused_imports)]\n"), CGGeneric("use dom::types::*;\n"), - CGGeneric("use dom::bindings::js::{JS, JSRef};\n"), + CGGeneric("use dom::bindings::js::{JS, JSRef, Unrooted};\n"), CGGeneric("use dom::bindings::trace::JSTraceable;\n"), + CGGeneric("use dom::bindings::utils::Reflectable;\n"), CGGeneric("use serialize::{Encodable, Encoder};\n"), CGGeneric("use js::jsapi::JSTracer;\n\n")] for descriptor in descriptors: @@ -5310,7 +5326,7 @@ class GlobalGenRoots(): } #[inline(always)] - fn to(base: &JS) -> Option> { + fn to(base: &JS) -> Option> { match base.get().${checkFn}() { true => unsafe { Some(base.clone().transmute()) }, false => None @@ -5318,7 +5334,23 @@ class GlobalGenRoots(): } #[inline(always)] - unsafe fn to_unchecked(base: &JS) -> JS { + fn to_ref<'a, 'b, T: ${toBound}+Reflectable>(base: &'a JSRef<'b, T>) -> Option<&'a JSRef<'b, Self>> { + match base.get().${checkFn}() { + true => unsafe { Some(base.transmute()) }, + false => None + } + } + + #[inline(always)] + fn to_mut_ref<'a, 'b, T: ${toBound}+Reflectable>(base: &'a mut JSRef<'b, T>) -> Option<&'a mut JSRef<'b, Self>> { + match base.get().${checkFn}() { + true => unsafe { Some(base.transmute_mut()) }, + false => None + } + } + + #[inline(always)] + unsafe fn to_unchecked(base: &JS) -> JS { assert!(base.get().${checkFn}()); base.clone().transmute() } @@ -5330,6 +5362,10 @@ class GlobalGenRoots(): fn from_mut_ref<'a, 'b, T: ${fromBound}>(derived: &'a mut JSRef<'b, T>) -> &'a mut JSRef<'b, Self> { unsafe { derived.transmute_mut() } } + + fn from_unrooted(derived: Unrooted) -> Unrooted { + unsafe { derived.transmute() } + } } ''').substitute({'checkFn': 'is_' + name.lower(), 'castTraitName': name + 'Cast', diff --git a/src/components/script/dom/bindings/codegen/Configuration.py b/src/components/script/dom/bindings/codegen/Configuration.py index a1ccb460ee2..eedb200c75e 100644 --- a/src/components/script/dom/bindings/codegen/Configuration.py +++ b/src/components/script/dom/bindings/codegen/Configuration.py @@ -133,6 +133,7 @@ class Descriptor(DescriptorProvider): else: nativeTypeDefault = 'JS<%s>' % ifaceName + self.returnType = "Unrooted<%s>" % ifaceName self.nativeType = desc.get('nativeType', nativeTypeDefault) self.concreteType = desc.get('concreteType', ifaceName) self.needsAbstract = desc.get('needsAbstract', []) diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs index dac459f9c03..2386777cac9 100644 --- a/src/components/script/dom/bindings/js.rs +++ b/src/components/script/dom/bindings/js.rs @@ -10,8 +10,52 @@ use layout_interface::TrustedNodeAddress; use std::cast; use std::cell::{Cell, RefCell}; use std::ptr; -//use std::ops::{Deref, DerefMut}; +/// A type that represents a JS-owned value that may or may not be rooted. +/// Importantly, it requires rooting in order to interact with the value in any way. +/// Can be assigned into JS-owned member fields (ie. JS types) safely via the +/// `JS::assign` method or `OptionalAssignable::assign` (for Option> fields). +pub struct Unrooted { + inner: JS +} + +impl Eq for Unrooted { + fn eq(&self, other: &Unrooted) -> bool { + self.inner == other.inner + } +} + +impl Unrooted { + /// Create a new Unrooted value from a JS-owned value. + pub fn new(inner: JS) -> Unrooted { + Unrooted { + inner: inner + } + } + + /// Create a new Unrooted value from a rooted value. + pub fn new_rooted<'a>(root: &JSRef<'a, T>) -> Unrooted { + Unrooted { + inner: root.unrooted() + } + } + + /// Root this unrooted value. + pub fn root<'a, 'b>(self, collection: &'a RootCollection) -> Root<'a, 'b, T> { + collection.new_root(&self.inner) + } + + unsafe fn inner(&self) -> JS { + self.inner.clone() + } + + //XXXjdm It would be lovely if this could be private. + pub unsafe fn transmute(self) -> Unrooted { + cast::transmute(self) + } +} + +/// A rooted, JS-owned value. Must only be used as a field in other JS-owned types. pub struct JS { ptr: RefCell<*mut T> } @@ -32,12 +76,15 @@ impl Clone for JS { } impl JS { + /// Create a new JS-reflected DOM object; returns an Unrooted type because the new value + /// is not safe to use until it is rooted. pub fn new(obj: ~T, window: &JSRef, - wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~T) -> JS) -> JS { - wrap_fn(window.get().get_cx(), window, obj) + wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~T) -> JS) -> Unrooted { + Unrooted::new(wrap_fn(window.get().get_cx(), window, obj)) } + /// Create a new JS-owned value wrapped from a raw Rust pointer. pub unsafe fn from_raw(raw: *mut T) -> JS { JS { ptr: RefCell::new(raw) @@ -45,6 +92,7 @@ impl JS { } + /// 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 { let TrustedNodeAddress(addr) = inner; JS { @@ -52,7 +100,8 @@ impl JS { } } - pub fn root<'a>(&self, collection: &'a RootCollection) -> Root<'a, T> { + /// Root this JS-owned value to prevent its collection as garbage. + pub fn root<'a, 'b>(&self, collection: &'a RootCollection) -> Root<'a, 'b, T> { collection.new_root(self) } } @@ -67,7 +116,7 @@ impl Reflectable for JS { } } -impl JS { +impl JS { pub fn get<'a>(&'a self) -> &'a T { let borrowed = self.ptr.borrow(); unsafe { @@ -88,6 +137,13 @@ impl JS { pub unsafe fn unsafe_get(&self) -> *mut T { cast::transmute_copy(&self.ptr) } + + /// Store an unrooted value in this field. This is safe under the assumption that JS + /// 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(&mut self, val: Unrooted) { + *self = unsafe { val.inner() }; + } } impl JS { @@ -105,17 +161,86 @@ pub trait RootedReference { fn root_ref<'a>(&'a self) -> Option>; } -impl<'a, T: Reflectable> RootedReference for Option> { +impl<'a, 'b, T: Reflectable> RootedReference for Option> { fn root_ref<'a>(&'a self) -> Option> { self.as_ref().map(|root| root.root_ref()) } } +// This trait should never be public; it allows access to unrooted values, and is thus +// easy to misuse. +/*definitely not public*/ trait Assignable { + fn get_js(&self) -> JS; +} + +impl Assignable for JS { + fn get_js(&self) -> JS { + self.clone() + } +} + +impl<'a, T> Assignable for JSRef<'a, T> { + fn get_js(&self) -> JS { + self.unrooted() + } +} + +// Assignable should not be exposed publically, since it's used to +// extract unrooted values in a safe way WHEN USED CORRECTLY. +impl Assignable for Unrooted { + fn get_js(&self) -> JS { + unsafe { self.inner() } + } +} + +pub trait OptionalAssignable { + fn assign(&mut self, val: Option); +} + +impl, U: Reflectable> OptionalAssignable for Option> { + fn assign(&mut self, val: Option) { + *self = val.map(|val| val.get_js()); + } +} + +pub trait OptionalRootable { + fn root<'a, 'b>(self, roots: &'a RootCollection) -> Option>; +} + +impl OptionalRootable for Option> { + fn root<'a, 'b>(self, roots: &'a RootCollection) -> Option> { + self.map(|inner| inner.root(roots)) + } +} + +pub trait ResultRootable { + fn root<'a, 'b>(self, roots: &'a RootCollection) -> Result, U>; +} + +impl ResultRootable for Result, U> { + fn root<'a, 'b>(self, roots: &'a RootCollection) -> Result, U> { + self.map(|inner| inner.root(roots)) + } +} + +/// Provides a facility to push unrooted values onto lists of rooted values. This is safe +/// under the assumption that said lists are reachable via the GC graph, and therefore the +/// new values are transitively rooted for the lifetime of their new owner. +pub trait UnrootedPushable { + fn push_unrooted(&mut self, val: Unrooted); +} + +impl UnrootedPushable for Vec> { + fn push_unrooted(&mut self, val: Unrooted) { + unsafe { self.push(val.inner()) }; + } +} + #[deriving(Eq, Clone)] struct RootReference(*JSObject); impl RootReference { - fn new<'a, T: Reflectable>(unrooted: &Root<'a, T>) -> RootReference { + fn new<'a, 'b, T: Reflectable>(unrooted: &Root<'a, 'b, T>) -> RootReference { RootReference(unrooted.rooted()) } @@ -126,6 +251,7 @@ impl RootReference { static MAX_STACK_ROOTS: uint = 10; +/// An opaque, LIFO rooting mechanism. pub struct RootCollection { roots: [Cell, ..MAX_STACK_ROOTS], current: Cell, @@ -139,7 +265,7 @@ impl RootCollection { } } - fn new_root<'a, T: Reflectable>(&'a self, unrooted: &JS) -> Root<'a, T> { + fn new_root<'a, 'b, T: Reflectable>(&'a self, unrooted: &JS) -> Root<'a, 'b, T> { Root::new(self, unrooted) } @@ -147,13 +273,15 @@ impl RootCollection { let current = self.current.get(); assert!(current < MAX_STACK_ROOTS); self.roots[current].set(unrooted); + debug!(" rooting {:?}", unrooted); self.current.set(current + 1); } - fn root<'a, T: Reflectable>(&self, unrooted: &Root<'a, T>) { + fn root<'a, 'b, T: Reflectable>(&self, unrooted: &Root<'a, 'b, T>) { self.root_impl(RootReference::new(unrooted)); } + /// Root a raw JS pointer. pub fn root_raw(&self, unrooted: *JSObject) { self.root_impl(RootReference(unrooted)); } @@ -162,29 +290,41 @@ impl RootCollection { let mut current = self.current.get(); assert!(current != 0); current -= 1; + debug!("unrooting {:?} (expecting {:?}", self.roots[current].get(), rooted); assert!(self.roots[current].get() == rooted); self.roots[current].set(RootReference::null()); self.current.set(current); } - fn unroot<'a, T: Reflectable>(&self, rooted: &Root<'a, T>) { + fn unroot<'a, 'b, T: Reflectable>(&self, rooted: &Root<'a, 'b, T>) { self.unroot_impl(RootReference::new(rooted)); } + /// Unroot a raw JS pointer. Must occur in reverse order to its rooting. pub fn unroot_raw(&self, rooted: *JSObject) { self.unroot_impl(RootReference(rooted)); } } -pub struct Root<'a, T> { +/// A rooted JS value. The JS value is pinned for the duration of this object's lifetime; +/// roots are additive, so this object's destruction will not invalidate other roots +/// for the same JS value. Roots cannot outlive the associated RootCollection object. +/// Attempts to transfer ownership of a Root via moving will trigger dynamic unrooting +/// failures due to incorrect ordering. +pub struct Root<'a, 'b, T> { root_list: &'a RootCollection, + jsref: JSRef<'b, T>, ptr: RefCell<*mut T>, } -impl<'a, T: Reflectable> Root<'a, T> { - fn new(roots: &'a RootCollection, unrooted: &JS) -> Root<'a, T> { +impl<'a, 'b, T: Reflectable> Root<'a, 'b, T> { + fn new(roots: &'a RootCollection, unrooted: &JS) -> Root<'a, 'b, T> { let root = Root { root_list: roots, + jsref: JSRef { + ptr: unrooted.ptr.clone(), + chain: unsafe { ::std::cast::transmute_region(&()) }, + }, ptr: unrooted.ptr.clone() }; roots.root(&root); @@ -209,24 +349,27 @@ impl<'a, T: Reflectable> Root<'a, T> { self.reflector().get_jsobject() } + fn internal_root_ref<'a>(&'a self) -> &'a JSRef<'b, T> { + &'a self.jsref + } + + fn mut_internal_root_ref<'a>(&'a mut self) -> &'a mut JSRef<'b, T> { + &'a mut self.jsref + } + pub fn root_ref<'b>(&'b self) -> JSRef<'b,T> { - unsafe { - JSRef { - ptr: self.ptr.clone(), - chain: ::std::cast::transmute_region(&()), - } - } + self.internal_root_ref().clone() } } #[unsafe_destructor] -impl<'a, T: Reflectable> Drop for Root<'a, T> { +impl<'a, 'b, T: Reflectable> Drop for Root<'a, 'b, T> { fn drop(&mut self) { self.root_list.unroot(self); } } -impl<'a, T: Reflectable> Reflectable for Root<'a, T> { +impl<'a, 'b, T: Reflectable> Reflectable for Root<'a, 'b, T> { fn reflector<'a>(&'a self) -> &'a Reflector { self.get().reflector() } @@ -236,17 +379,29 @@ impl<'a, T: Reflectable> Reflectable for Root<'a, T> { } } -/*impl<'a, T> Deref for Root<'a, T> { - fn deref<'a>(&'a self) -> &'a T { +impl<'a, 'b, T: Reflectable> Deref> for Root<'a, 'b, T> { + fn deref<'c>(&'c self) -> &'c JSRef<'b, T> { + self.internal_root_ref() + } +} + +impl<'a, 'b, T: Reflectable> DerefMut> for Root<'a, 'b, T> { + fn deref_mut<'c>(&'c mut self) -> &'c mut JSRef<'b, T> { + self.mut_internal_root_ref() + } +} + +impl<'a, T: Reflectable> Deref for JSRef<'a, T> { + fn deref<'b>(&'b self) -> &'b T { self.get() } } -impl<'a, T> DerefMut for Root<'a, T> { - fn deref_mut<'a>(&'a mut self) -> &'a mut T { +impl<'a, T: Reflectable> DerefMut for JSRef<'a, T> { + fn deref_mut<'b>(&'b mut self) -> &'b mut T { self.get_mut() } -}*/ +} /// Encapsulates a reference to something that is guaranteed to be alive. This is freely copyable. pub struct JSRef<'a, T> { diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index 7f240070ea1..80aa9c364ee 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -5,7 +5,7 @@ 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}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; use dom::bindings::trace::Untraceable; use dom::browsercontext; use dom::window; @@ -391,7 +391,7 @@ pub fn reflect_dom_object (obj: ~T, window: &JSRef, wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~T) -> JS) - -> JS { + -> Unrooted { JS::new(obj, window, wrap_fn) } @@ -613,18 +613,20 @@ pub extern fn outerize_global(_cx: *JSContext, obj: JSHandleObject) -> *JSObject } /// Returns the global object of the realm that the given JS object was created in. -pub fn global_object_for_js_object(obj: *JSObject) -> JS { +pub fn global_object_for_js_object(obj: *JSObject) -> Unrooted { unsafe { let global = GetGlobalForObjectCrossCompartment(obj); let clasp = JS_GetClass(global); assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0); - FromJSValConvertible::from_jsval(ptr::null(), ObjectOrNullValue(global), ()) - .ok().expect("found DOM global that doesn't unwrap to Window") + Unrooted::new( + FromJSValConvertible::from_jsval(ptr::null(), ObjectOrNullValue(global), ()) + .ok().expect("found DOM global that doesn't unwrap to Window")) } } fn cx_for_dom_reflector(obj: *JSObject) -> *JSContext { - let win = global_object_for_js_object(obj); + let roots = RootCollection::new(); + let win = global_object_for_js_object(obj).root(&roots); let js_info = win.get().page().js_info(); match *js_info { Some(ref info) => info.js_context.deref().deref().ptr, diff --git a/src/components/script/dom/blob.rs b/src/components/script/dom/blob.rs index 8dba1775ff6..0399568063d 100644 --- a/src/components/script/dom/blob.rs +++ b/src/components/script/dom/blob.rs @@ -2,7 +2,7 @@ * 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, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::Fallible; use dom::bindings::codegen::BindingDeclarations::BlobBinding; @@ -23,7 +23,7 @@ impl Blob { } } - pub fn new(window: &JSRef) -> JS { + pub fn new(window: &JSRef) -> Unrooted { reflect_dom_object(~Blob::new_inherited(window.unrooted()), window, BlobBinding::Wrap) @@ -31,7 +31,7 @@ impl Blob { } impl Blob { - pub fn Constructor(window: &JSRef) -> Fallible> { + pub fn Constructor(window: &JSRef) -> Fallible> { Ok(Blob::new(window)) } @@ -43,7 +43,7 @@ impl Blob { ~"" } - pub fn Slice(&self, _start: Option, _end: Option, _contentType: Option) -> JS { + pub fn Slice(&self, _start: Option, _end: Option, _contentType: Option) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); Blob::new(&window.root_ref()) diff --git a/src/components/script/dom/browsercontext.rs b/src/components/script/dom/browsercontext.rs index 86540c12a53..fbb63420520 100644 --- a/src/components/script/dom/browsercontext.rs +++ b/src/components/script/dom/browsercontext.rs @@ -2,7 +2,7 @@ * 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; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::trace::Traceable; use dom::bindings::utils::Reflectable; use dom::document::Document; @@ -22,7 +22,7 @@ pub struct BrowserContext { } impl BrowserContext { - pub fn new(document: &JS) -> BrowserContext { + pub fn new(document: &JSRef) -> BrowserContext { let mut context = BrowserContext { history: vec!(SessionHistoryEntry::new(document)), active_index: 0, @@ -71,9 +71,9 @@ pub struct SessionHistoryEntry { } impl SessionHistoryEntry { - fn new(document: &JS) -> SessionHistoryEntry { + fn new(document: &JSRef) -> SessionHistoryEntry { SessionHistoryEntry { - document: document.clone(), + document: document.unrooted(), children: vec!() } } diff --git a/src/components/script/dom/clientrect.rs b/src/components/script/dom/clientrect.rs index 977c4569bf5..4e4e2dbdcc6 100644 --- a/src/components/script/dom/clientrect.rs +++ b/src/components/script/dom/clientrect.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::ClientRectBinding; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::window::Window; use servo_util::geometry::Au; @@ -34,7 +34,7 @@ impl ClientRect { pub fn new(window: &JSRef, top: Au, bottom: Au, - left: Au, right: Au) -> JS { + left: Au, right: Au) -> Unrooted { let rect = ClientRect::new_inherited(window.unrooted(), top, bottom, left, right); reflect_dom_object(~rect, window, ClientRectBinding::Wrap) } diff --git a/src/components/script/dom/clientrectlist.rs b/src/components/script/dom/clientrectlist.rs index abd87c47455..a9beec896e8 100644 --- a/src/components/script/dom/clientrectlist.rs +++ b/src/components/script/dom/clientrectlist.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::ClientRectListBinding; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::clientrect::ClientRect; use dom::window::Window; @@ -17,16 +17,16 @@ pub struct ClientRectList { impl ClientRectList { pub fn new_inherited(window: JS, - rects: Vec>) -> ClientRectList { + rects: Vec>) -> ClientRectList { ClientRectList { reflector_: Reflector::new(), - rects: rects, + rects: rects.iter().map(|rect| rect.unrooted()).collect(), window: window, } } pub fn new(window: &JSRef, - rects: Vec>) -> JS { + rects: Vec>) -> Unrooted { reflect_dom_object(~ClientRectList::new_inherited(window.unrooted(), rects), window, ClientRectListBinding::Wrap) } @@ -35,15 +35,15 @@ impl ClientRectList { self.rects.len() as u32 } - pub fn Item(&self, index: u32) -> Option> { + pub fn Item(&self, index: u32) -> Option> { if index < self.rects.len() as u32 { - Some(self.rects.get(index as uint).clone()) + Some(Unrooted::new(self.rects.get(index as uint).clone())) } else { None } } - pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { + pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { *found = index < self.rects.len() as u32; self.Item(index) } diff --git a/src/components/script/dom/comment.rs b/src/components/script/dom/comment.rs index a0786441fe6..779fb6415e9 100644 --- a/src/components/script/dom/comment.rs +++ b/src/components/script/dom/comment.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::CommentDerived; use dom::bindings::codegen::BindingDeclarations::CommentBinding; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; use dom::bindings::error::Fallible; use dom::characterdata::CharacterData; use dom::document::Document; @@ -35,12 +35,12 @@ impl Comment { } } - pub fn new(text: DOMString, document: &JSRef) -> JS { + pub fn new(text: DOMString, document: &JSRef) -> Unrooted { let node = Comment::new_inherited(text, document.unrooted()); Node::reflect_node(~node, document, CommentBinding::Wrap) } - pub fn Constructor(owner: &JSRef, data: DOMString) -> Fallible> { + pub fn Constructor(owner: &JSRef, data: DOMString) -> Fallible> { let roots = RootCollection::new(); let document = owner.get().Document(); let document = document.root(&roots); diff --git a/src/components/script/dom/console.rs b/src/components/script/dom/console.rs index a7908c6bc4f..ce41ed45212 100644 --- a/src/components/script/dom/console.rs +++ b/src/components/script/dom/console.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::ConsoleBinding; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JSRef, Unrooted}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::window::Window; use servo_util::str::DOMString; @@ -20,7 +20,7 @@ impl Console { } } - pub fn new(window: &JSRef) -> JS { + pub fn new(window: &JSRef) -> Unrooted { reflect_dom_object(~Console::new_inherited(), window, ConsoleBinding::Wrap) } diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index 44b141dcea5..e2984a1bf82 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -3,11 +3,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::InheritTypes::{DocumentDerived, EventCast, HTMLElementCast}; -use dom::bindings::codegen::InheritTypes::{DocumentBase, NodeCast, DocumentCast}; use dom::bindings::codegen::InheritTypes::{HTMLHeadElementCast, TextCast, ElementCast}; -use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, HTMLHtmlElementCast}; +use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, HTMLHtmlElementCast, NodeCast}; use dom::bindings::codegen::BindingDeclarations::DocumentBinding; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalAssignable}; +use dom::bindings::js::OptionalRootable; use dom::bindings::trace::Untraceable; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::{ErrorResult, Fallible, NotSupported, InvalidCharacter, HierarchyRequest, NamespaceError}; @@ -22,14 +22,14 @@ use dom::element::{HTMLBodyElementTypeId, HTMLFrameSetElementTypeId}; use dom::event::Event; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlcollection::{HTMLCollection, CollectionFilter}; -use dom::nodelist::NodeList; use dom::htmlelement::HTMLElement; use dom::htmlheadelement::HTMLHeadElement; use dom::htmlhtmlelement::HTMLHtmlElement; use dom::htmltitleelement::HTMLTitleElement; use dom::mouseevent::MouseEvent; -use dom::node::{Node, ElementNodeTypeId, DocumentNodeTypeId, NodeHelpers, INode}; -use dom::node::{CloneChildren, DoNotCloneChildren}; +use dom::node::{Node, ElementNodeTypeId, DocumentNodeTypeId, NodeHelpers, AppendChild}; +use dom::node::{CloneChildren, DoNotCloneChildren, RemoveChild, ReplaceChild}; +use dom::nodelist::NodeList; use dom::text::Text; use dom::processinginstruction::ProcessingInstruction; use dom::uievent::UIEvent; @@ -77,21 +77,19 @@ impl DocumentDerived for EventTarget { } impl Document { - pub fn reflect_document - (document: ~D, - window: &JSRef, - wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~D) -> JS) - -> JS { + pub fn reflect_document(document: ~Document, + window: &JSRef, + wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~Document) -> JS) + -> Unrooted { let roots = RootCollection::new(); assert!(document.reflector().get_jsobject().is_null()); - let raw_doc = reflect_dom_object(document, window, wrap_fn); + let mut raw_doc = reflect_dom_object(document, window, wrap_fn).root(&roots); assert!(raw_doc.reflector().get_jsobject().is_not_null()); - let document = DocumentCast::from(&raw_doc); - let document_root = document.root(&roots); - let mut node: JS = NodeCast::from(&document); - node.get_mut().set_owner_doc(&document_root.root_ref()); - raw_doc + let mut doc_alias = raw_doc.clone(); + let node: &mut JSRef = NodeCast::from_mut_ref(&mut doc_alias); + node.get_mut().set_owner_doc(&*raw_doc); + Unrooted::new_rooted(&*raw_doc) } pub fn new_inherited(window: JS, @@ -124,7 +122,7 @@ impl Document { } } - pub fn new(window: &JSRef, url: Option, doctype: IsHTMLDocument, content_type: Option) -> JS { + pub fn new(window: &JSRef, url: Option, doctype: IsHTMLDocument, content_type: Option) -> Unrooted { let document = Document::new_inherited(window.unrooted(), url, doctype, content_type); Document::reflect_document(~document, window, DocumentBinding::Wrap) } @@ -138,7 +136,7 @@ impl Document { impl Document { // http://dom.spec.whatwg.org/#dom-document - pub fn Constructor(owner: &JSRef) -> Fallible> { + pub fn Constructor(owner: &JSRef) -> Fallible> { Ok(Document::new(owner, None, NonHTMLDocument, None)) } } @@ -155,13 +153,13 @@ impl Reflectable for Document { impl Document { // http://dom.spec.whatwg.org/#dom-document-implementation - pub fn Implementation(&mut self) -> JS { + pub fn Implementation(&mut self) -> Unrooted { if self.implementation.is_none() { let roots = RootCollection::new(); let window = self.window.root(&roots); - self.implementation = Some(DOMImplementation::new(&window.root_ref())); + self.implementation.assign(Some(DOMImplementation::new(&*window))); } - self.implementation.get_ref().clone() + Unrooted::new(self.implementation.get_ref().clone()) } // http://dom.spec.whatwg.org/#dom-document-url @@ -205,25 +203,29 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-doctype - pub fn GetDoctype(&self) -> Option> { - self.node.children().find(|child| child.is_doctype()) - .map(|node| DocumentTypeCast::to(&node).unwrap()) + pub fn GetDoctype(&self) -> Option> { + self.node.children().find(|child| { + child.is_doctype() + }).map(|node| { + let doctype: &JSRef = DocumentTypeCast::to_ref(&node).unwrap(); + Unrooted::new(doctype.unrooted()) + }) } // http://dom.spec.whatwg.org/#dom-document-documentelement - pub fn GetDocumentElement(&self) -> Option> { - self.node.child_elements().next() + pub fn GetDocumentElement(&self) -> Option> { + self.node.child_elements().next().map(|elem| Unrooted::new_rooted(&elem)) } // http://dom.spec.whatwg.org/#dom-document-getelementsbytagname - pub fn GetElementsByTagName(&self, abstract_self: &JSRef, tag_name: DOMString) -> JS { + pub fn GetElementsByTagName(&self, abstract_self: &JSRef, tag_name: DOMString) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); - HTMLCollection::by_tag_name(&window.root_ref(), NodeCast::from_ref(abstract_self), tag_name) + HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(abstract_self), tag_name) } // http://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens - pub fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, tag_name: DOMString) -> JS { + pub fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, tag_name: DOMString) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -231,28 +233,28 @@ impl Document { Some(namespace) => Namespace::from_str(namespace), None => Null }; - HTMLCollection::by_tag_name_ns(&window.root_ref(), NodeCast::from_ref(abstract_self), tag_name, namespace) + HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(abstract_self), tag_name, namespace) } // http://dom.spec.whatwg.org/#dom-document-getelementsbyclassname - pub fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> JS { + pub fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); - HTMLCollection::by_class_name(&window.root_ref(), NodeCast::from_ref(abstract_self), classes) + HTMLCollection::by_class_name(&*window, NodeCast::from_ref(abstract_self), classes) } // http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid - pub fn GetElementById(&self, id: DOMString) -> Option> { + pub fn GetElementById(&self, id: DOMString) -> Option> { match self.idmap.find_equiv(&id) { None => None, - Some(ref elements) => Some(elements.get(0).clone()), + Some(ref elements) => Some(Unrooted::new(elements.get(0).clone())), } } // http://dom.spec.whatwg.org/#dom-document-createelement pub fn CreateElement(&self, abstract_self: &JSRef, local_name: DOMString) - -> Fallible> { + -> Fallible> { if xml_name_type(local_name) == InvalidXMLName { debug!("Not a valid element name"); return Err(InvalidCharacter); @@ -264,7 +266,7 @@ impl Document { // http://dom.spec.whatwg.org/#dom-document-createelementns pub fn CreateElementNS(&self, abstract_self: &JSRef, namespace: Option, - qualified_name: DOMString) -> Fallible> { + qualified_name: DOMString) -> Fallible> { let ns = Namespace::from_str(null_str_as_empty_ref(&namespace)); match xml_name_type(qualified_name) { InvalidXMLName => { @@ -308,24 +310,24 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-createdocumentfragment - pub fn CreateDocumentFragment(&self, abstract_self: &JSRef) -> JS { + pub fn CreateDocumentFragment(&self, abstract_self: &JSRef) -> Unrooted { DocumentFragment::new(abstract_self) } // http://dom.spec.whatwg.org/#dom-document-createtextnode pub fn CreateTextNode(&self, abstract_self: &JSRef, data: DOMString) - -> JS { + -> Unrooted { Text::new(data, abstract_self) } // http://dom.spec.whatwg.org/#dom-document-createcomment - pub fn CreateComment(&self, abstract_self: &JSRef, data: DOMString) -> JS { + pub fn CreateComment(&self, abstract_self: &JSRef, data: DOMString) -> Unrooted { Comment::new(data, abstract_self) } // http://dom.spec.whatwg.org/#dom-document-createprocessinginstruction pub fn CreateProcessingInstruction(&self, abstract_self: &JSRef, target: DOMString, - data: DOMString) -> Fallible> { + data: DOMString) -> Fallible> { // Step 1. if xml_name_type(target) == InvalidXMLName { return Err(InvalidCharacter); @@ -341,9 +343,9 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-importnode - pub fn ImportNode(&self, abstract_self: &JSRef, node: &JSRef, deep: bool) -> Fallible> { + pub fn ImportNode(&self, abstract_self: &JSRef, node: &JSRef, deep: bool) -> Fallible> { // Step 1. - if node.unrooted().is_document() { + if node.is_document() { return Err(NotSupported); } @@ -357,30 +359,29 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-adoptnode - pub fn AdoptNode(&self, abstract_self: &JSRef, node: &JSRef) -> Fallible> { + pub fn AdoptNode(&self, abstract_self: &JSRef, node: &mut JSRef) -> Fallible> { // Step 1. - if node.unrooted().is_document() { + if node.is_document() { return Err(NotSupported); } // Step 2. - let mut adoptee = node.clone(); - Node::adopt(&mut adoptee, abstract_self); + Node::adopt(node, abstract_self); // Step 3. - Ok(adoptee.unrooted()) + Ok(Unrooted::new_rooted(node)) } // http://dom.spec.whatwg.org/#dom-document-createevent - pub fn CreateEvent(&self, interface: DOMString) -> Fallible> { + pub fn CreateEvent(&self, interface: DOMString) -> Fallible> { let roots = RootCollection::new(); let window = self.window.root(&roots); match interface.to_ascii_lower().as_slice() { // FIXME: Implement CustomEvent (http://dom.spec.whatwg.org/#customevent) - "uievents" | "uievent" => Ok(EventCast::from(&UIEvent::new(&window.root_ref()))), - "mouseevents" | "mouseevent" => Ok(EventCast::from(&MouseEvent::new(&window.root_ref()))), - "htmlevents" | "events" | "event" => Ok(Event::new(&window.root_ref())), + "uievents" | "uievent" => Ok(EventCast::from_unrooted(UIEvent::new(&*window))), + "mouseevents" | "mouseevent" => Ok(EventCast::from_unrooted(MouseEvent::new(&*window))), + "htmlevents" | "events" | "event" => Ok(Event::new(&*window)), _ => Err(NotSupported) } } @@ -388,14 +389,15 @@ impl Document { // http://www.whatwg.org/specs/web-apps/current-work/#document.title pub fn Title(&self, _: &JSRef) -> DOMString { let mut title = ~""; - self.GetDocumentElement().map(|root| { - let root: JS = NodeCast::from(&root); - root.traverse_preorder() + let roots = RootCollection::new(); + self.GetDocumentElement().root(&roots).map(|root| { + let root: &JSRef = NodeCast::from_ref(&*root); + root.traverse_preorder(&roots) .find(|node| node.type_id() == ElementNodeTypeId(HTMLTitleElementTypeId)) .map(|title_elem| { - for child in title_elem.children() { + for child in title_elem.deref().children() { if child.is_text() { - let text: JS = TextCast::to(&child).unwrap(); + let text: &JSRef = TextCast::to_ref(&child).unwrap(); title.push_str(text.get().characterdata.data.as_slice()); } } @@ -410,9 +412,9 @@ impl Document { pub fn SetTitle(&self, abstract_self: &JSRef, title: DOMString) -> ErrorResult { let roots = RootCollection::new(); - self.GetDocumentElement().map(|root| { - let root: JS = NodeCast::from(&root); - let mut head_node = root.traverse_preorder().find(|child| { + self.GetDocumentElement().root(&roots).map(|root| { + let root: &JSRef = NodeCast::from_ref(&*root); + let mut head_node = root.traverse_preorder(&roots).find(|child| { child.get().type_id == ElementNodeTypeId(HTMLHeadElementTypeId) }); head_node.as_mut().map(|head| { @@ -422,25 +424,21 @@ impl Document { match title_node { Some(ref mut title_node) => { - for title_child in title_node.children() { - let title_child = title_child.root(&roots); - assert!(title_node.RemoveChild(&mut title_child.root_ref()).is_ok()); + for mut title_child in title_node.children() { + assert!(RemoveChild(&mut *title_node, &mut title_child).is_ok()); } - let new_text = self.CreateTextNode(abstract_self, title.clone()); - let new_text = new_text.root(&roots); + let mut new_text = self.CreateTextNode(abstract_self, title.clone()).root(&roots); - assert!(title_node.AppendChild(NodeCast::from_mut_ref(&mut new_text.root_ref())).is_ok()); + assert!(AppendChild(&mut *title_node, NodeCast::from_mut_ref(&mut *new_text)).is_ok()); }, None => { - let mut new_title: JS = - NodeCast::from(&HTMLTitleElement::new(~"title", abstract_self)); - let new_title_root = new_title.root(&roots); + let mut new_title = HTMLTitleElement::new(~"title", abstract_self).root(&roots); + let new_title: &mut JSRef = NodeCast::from_mut_ref(&mut *new_title); - let new_text = self.CreateTextNode(abstract_self, title.clone()); - let new_text = new_text.root(&roots); + let mut new_text = self.CreateTextNode(abstract_self, title.clone()).root(&roots); - assert!(new_title.AppendChild(NodeCast::from_mut_ref(&mut new_text.root_ref())).is_ok()); - assert!(head.AppendChild(&mut new_title_root.root_ref()).is_ok()); + assert!(AppendChild(&mut *new_title, NodeCast::from_mut_ref(&mut *new_text)).is_ok()); + assert!(AppendChild(&mut *head, &mut *new_title).is_ok()); }, } }); @@ -448,33 +446,44 @@ impl Document { Ok(()) } - fn get_html_element(&self) -> Option> { - self.GetDocumentElement().filtered(|root| { - root.get().node.type_id == ElementNodeTypeId(HTMLHtmlElementTypeId) - }).map(|elem| HTMLHtmlElementCast::to(&elem).unwrap()) + fn get_html_element(&self) -> Option> { + let roots = RootCollection::new(); + self.GetDocumentElement().root(&roots).filtered(|root| { + root.node.type_id == ElementNodeTypeId(HTMLHtmlElementTypeId) + }).map(|elem| { + Unrooted::new_rooted(HTMLHtmlElementCast::to_ref(&*elem).unwrap()) + }) } // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-head - pub fn GetHead(&self) -> Option> { + pub fn GetHead(&self) -> Option> { + let roots = RootCollection::new(); self.get_html_element().and_then(|root| { - let node: JS = NodeCast::from(&root); + let root = root.root(&roots); + let node: &JSRef = NodeCast::from_ref(&*root); node.children().find(|child| { child.type_id() == ElementNodeTypeId(HTMLHeadElementTypeId) - }).map(|node| HTMLHeadElementCast::to(&node).unwrap()) + }).map(|node| { + Unrooted::new_rooted(HTMLHeadElementCast::to_ref(&node).unwrap()) + }) }) } // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body - pub fn GetBody(&self, _: &JSRef) -> Option> { + pub fn GetBody(&self, _: &JSRef) -> Option> { + let roots = RootCollection::new(); self.get_html_element().and_then(|root| { - let node: JS = NodeCast::from(&root); + let root = root.root(&roots); + let node: &JSRef = NodeCast::from_ref(&*root); node.children().find(|child| { match child.type_id() { ElementNodeTypeId(HTMLBodyElementTypeId) | ElementNodeTypeId(HTMLFrameSetElementTypeId) => true, _ => false } - }).map(|node| HTMLElementCast::to(&node).unwrap()) + }).map(|node| { + Unrooted::new_rooted(HTMLElementCast::to_ref(&node).unwrap()) + }) }) } @@ -494,28 +503,28 @@ impl Document { } // Step 2. - let old_body: Option> = self.GetBody(abstract_self); - if old_body == new_body.as_ref().map(|new_body| new_body.unrooted()) { + let mut old_body = self.GetBody(abstract_self).root(&roots); + //FIXME: covariant lifetime workaround. do not judge. + if old_body.as_ref().map(|body| body.deref()) == new_body.as_ref().map(|a| &*a) { return Ok(()); } // Step 3. - match self.get_html_element() { + match self.get_html_element().root(&roots) { // Step 4. None => return Err(HierarchyRequest), - Some(root) => { + Some(ref mut root) => { let mut new_body_unwrapped = new_body.unwrap(); let new_body: &mut JSRef = NodeCast::from_mut_ref(&mut new_body_unwrapped); - let mut root: JS = NodeCast::from(&root); + let root: &mut JSRef = NodeCast::from_mut_ref(&mut **root); match old_body { - Some(child) => { - let child: JS = NodeCast::from(&child); - let child = child.root(&roots); + Some(ref mut child) => { + let child: &mut JSRef = NodeCast::from_mut_ref(&mut **child); - assert!(root.ReplaceChild(new_body, &mut child.root_ref()).is_ok()) + assert!(ReplaceChild(&mut *root, new_body, child).is_ok()) } - None => assert!(root.AppendChild(new_body).is_ok()) + None => assert!(AppendChild(&mut *root, new_body).is_ok()) }; } } @@ -523,20 +532,22 @@ impl Document { } // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-getelementsbyname - pub fn GetElementsByName(&self, name: DOMString) -> JS { + pub fn GetElementsByName(&self, name: DOMString) -> Unrooted { + let roots = RootCollection::new(); + self.createNodeList(|node| { if !node.get().is_element() { return false; } - let element: JS = ElementCast::to(&node.unrooted()).unwrap(); - element.get_attribute(Null, "name").map_or(false, |attr| { - attr.get().value_ref() == name + let element: &JSRef = ElementCast::to_ref(node).unwrap(); + element.get_attribute(Null, "name").root(&roots).map_or(false, |mut attr| { + attr.value_ref() == name }) }) } - pub fn Images(&self, abstract_self: &JSRef) -> JS { + pub fn Images(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -548,10 +559,10 @@ impl Document { } } let filter = ~ImagesFilter; - HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) } - pub fn Embeds(&self, abstract_self: &JSRef) -> JS { + pub fn Embeds(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -563,15 +574,15 @@ impl Document { } } let filter = ~EmbedsFilter; - HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) } - pub fn Plugins(&self, abstract_self: &JSRef) -> JS { + pub fn Plugins(&self, abstract_self: &JSRef) -> Unrooted { // FIXME: https://github.com/mozilla/servo/issues/1847 self.Embeds(abstract_self) } - pub fn Links(&self, abstract_self: &JSRef) -> JS { + pub fn Links(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -580,14 +591,14 @@ impl Document { impl CollectionFilter for LinksFilter { fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { (elem.get().local_name == ~"a" || elem.get().local_name == ~"area") && - elem.unrooted().get_attribute(Null, "href").is_some() + elem.get_attribute(Null, "href").is_some() } } let filter = ~LinksFilter; - HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) } - pub fn Forms(&self, abstract_self: &JSRef) -> JS { + pub fn Forms(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -599,10 +610,10 @@ impl Document { } } let filter = ~FormsFilter; - HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) } - pub fn Scripts(&self, abstract_self: &JSRef) -> JS { + pub fn Scripts(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -614,10 +625,10 @@ impl Document { } } let filter = ~ScriptsFilter; - HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) } - pub fn Anchors(&self, abstract_self: &JSRef) -> JS { + pub fn Anchors(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -625,14 +636,14 @@ impl Document { struct AnchorsFilter; impl CollectionFilter for AnchorsFilter { fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { - elem.get().local_name == ~"a" && elem.unrooted().get_attribute(Null, "name").is_some() + elem.get().local_name == ~"a" && elem.get_attribute(Null, "name").is_some() } } let filter = ~AnchorsFilter; - HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) } - pub fn Applets(&self, abstract_self: &JSRef) -> JS { + pub fn Applets(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -644,40 +655,39 @@ impl Document { } } let filter = ~AppletsFilter; - HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) } - pub fn Location(&mut self, _abstract_self: &JSRef) -> JS { + pub fn Location(&mut self, _abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); - self.window.get_mut().Location(&window.root_ref()) + self.window.get_mut().Location(&*window) } - pub fn Children(&self, abstract_self: &JSRef) -> JS { + pub fn Children(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); - HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self)) + HTMLCollection::children(&*window, NodeCast::from_ref(abstract_self)) } - pub fn createNodeList(&self, callback: |node: &JSRef| -> bool) -> JS { + pub fn createNodeList(&self, callback: |node: &JSRef| -> bool) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); let mut nodes = vec!(); - match self.GetDocumentElement() { + match self.GetDocumentElement().root(&roots) { None => {}, Some(root) => { - let root: JS = NodeCast::from(&root); - for child in root.traverse_preorder() { - let child = child.root(&roots); - if callback(&child.root_ref()) { - nodes.push(child.root_ref().unrooted()); + let root: &JSRef = NodeCast::from_ref(&*root); + for child in root.traverse_preorder(&roots) { + if callback(&child) { + nodes.push(child); } } } } - NodeList::new_simple_list(&window.root_ref(), nodes) + NodeList::new_simple_list(&*window, nodes) } pub fn content_changed(&self) { @@ -697,12 +707,14 @@ impl Document { pub fn unregister_named_element(&mut self, abstract_self: &JSRef, id: DOMString) { + let roots = RootCollection::new(); let mut is_empty = false; match self.idmap.find_mut(&id) { None => {}, Some(elements) => { let position = elements.iter() - .position(|element| element == &abstract_self.unrooted()) + .map(|elem| elem.root(&roots)) + .position(|element| &*element == abstract_self) .expect("This element should be in registered."); elements.remove(position); is_empty = elements.is_empty(); @@ -717,26 +729,28 @@ impl Document { pub fn register_named_element(&mut self, element: &JSRef, id: DOMString) { + let roots = RootCollection::new(); assert!({ - let node: JS = NodeCast::from(&element.unrooted()); + let node: &JSRef = NodeCast::from_ref(element); node.is_in_doc() }); // FIXME https://github.com/mozilla/rust/issues/13195 // Use mangle() when it exists again. - let root = self.GetDocumentElement().expect("The element is in the document, so there must be a document element."); + let root = self.GetDocumentElement().expect("The element is in the document, so there must be a document element.").root(&roots); match self.idmap.find_mut(&id) { Some(elements) => { - let new_node = NodeCast::from_ref(element); + let new_node: &JSRef = NodeCast::from_ref(element); let mut head : uint = 0u; - let root: JS = NodeCast::from(&root); - for node in root.traverse_preorder() { - match ElementCast::to(&node) { + let root: &JSRef = NodeCast::from_ref(&*root); + for node in root.traverse_preorder(&roots) { + let elem: Option<&JSRef> = ElementCast::to_ref(&node); + match elem { Some(elem) => { - if elements.get(head) == &elem { + if elements.get(head) == &elem.unrooted() { head = head + 1; } - if new_node.unrooted() == node || head == elements.len() { + if new_node == &node || head == elements.len() { break; } } diff --git a/src/components/script/dom/documentfragment.rs b/src/components/script/dom/documentfragment.rs index e10e9e1204c..629b68ffdec 100644 --- a/src/components/script/dom/documentfragment.rs +++ b/src/components/script/dom/documentfragment.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::{DocumentFragmentDerived, NodeCast}; use dom::bindings::codegen::BindingDeclarations::DocumentFragmentBinding; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; use dom::bindings::error::Fallible; use dom::document::Document; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -34,14 +34,14 @@ impl DocumentFragment { } } - pub fn new(document: &JSRef) -> JS { + pub fn new(document: &JSRef) -> Unrooted { let node = DocumentFragment::new_inherited(document.unrooted()); Node::reflect_node(~node, document, DocumentFragmentBinding::Wrap) } } impl DocumentFragment { - pub fn Constructor(owner: &JSRef) -> Fallible> { + pub fn Constructor(owner: &JSRef) -> Fallible> { let roots = RootCollection::new(); let document = owner.get().Document(); let document = document.root(&roots); @@ -51,9 +51,9 @@ impl DocumentFragment { } impl DocumentFragment { - pub fn Children(&self, abstract_self: &JSRef) -> JS { + pub fn Children(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); - let window = window_from_node(&abstract_self.unrooted()).root(&roots); + let window = window_from_node(abstract_self).root(&roots); HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self)) } } diff --git a/src/components/script/dom/documenttype.rs b/src/components/script/dom/documenttype.rs index dacce041f5c..21b1a784456 100644 --- a/src/components/script/dom/documenttype.rs +++ b/src/components/script/dom/documenttype.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::DocumentTypeDerived; use dom::bindings::codegen::BindingDeclarations::DocumentTypeBinding; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::document::Document; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::node::{Node, DoctypeNodeTypeId}; @@ -46,7 +46,7 @@ impl DocumentType { public_id: Option, system_id: Option, document: &JSRef) - -> JS { + -> Unrooted { let documenttype = DocumentType::new_inherited(name, public_id, system_id, diff --git a/src/components/script/dom/domexception.rs b/src/components/script/dom/domexception.rs index db562d08c71..08a8c364deb 100644 --- a/src/components/script/dom/domexception.rs +++ b/src/components/script/dom/domexception.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::DOMExceptionBinding; use dom::bindings::codegen::BindingDeclarations::DOMExceptionBinding::DOMExceptionConstants; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JSRef, Unrooted}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::window::Window; use servo_util::str::DOMString; @@ -49,7 +49,7 @@ impl DOMException { } } - pub fn new(window: &JSRef, code: DOMErrorName) -> JS { + pub fn new(window: &JSRef, code: DOMErrorName) -> Unrooted { reflect_dom_object(~DOMException::new_inherited(code), window, DOMExceptionBinding::Wrap) } } diff --git a/src/components/script/dom/domimplementation.rs b/src/components/script/dom/domimplementation.rs index e002cf9d28c..7cc9e5ef0d0 100644 --- a/src/components/script/dom/domimplementation.rs +++ b/src/components/script/dom/domimplementation.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::DOMImplementationBinding; use dom::bindings::codegen::InheritTypes::NodeCast; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, 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}; @@ -14,7 +14,7 @@ use dom::htmlbodyelement::HTMLBodyElement; use dom::htmlheadelement::HTMLHeadElement; use dom::htmlhtmlelement::HTMLHtmlElement; use dom::htmltitleelement::HTMLTitleElement; -use dom::node::{Node, INode}; +use dom::node::{Node, AppendChild}; use dom::text::Text; use dom::window::Window; use servo_util::str::DOMString; @@ -33,7 +33,7 @@ impl DOMImplementation { } } - pub fn new(owner: &JSRef) -> JS { + pub fn new(owner: &JSRef) -> Unrooted { reflect_dom_object(~DOMImplementation::new_inherited(owner.unrooted()), owner, DOMImplementationBinding::Wrap) } @@ -52,7 +52,7 @@ impl Reflectable for DOMImplementation { // http://dom.spec.whatwg.org/#domimplementation impl DOMImplementation { // http://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype - pub fn CreateDocumentType(&self, qname: DOMString, pubid: DOMString, sysid: DOMString) -> Fallible> { + pub fn CreateDocumentType(&self, qname: DOMString, pubid: DOMString, sysid: DOMString) -> Fallible> { let roots = RootCollection::new(); match xml_name_type(qname) { // Step 1. @@ -70,37 +70,39 @@ impl DOMImplementation { // http://dom.spec.whatwg.org/#dom-domimplementation-createdocument pub fn CreateDocument(&self, namespace: Option, qname: DOMString, - mut maybe_doctype: Option>) -> Fallible> { + mut maybe_doctype: Option>) -> Fallible> { let roots = RootCollection::new(); let win = self.owner.root(&roots); // Step 1. - let doc = Document::new(&win.root_ref(), None, NonHTMLDocument, None); - let doc_root = doc.root(&roots); - let mut doc_node: JS = NodeCast::from(&doc); - + let mut doc = Document::new(&win.root_ref(), None, NonHTMLDocument, None).root(&roots); // Step 2-3. let mut maybe_elem = if qname.is_empty() { None } else { - match doc.get().CreateElementNS(&doc_root.root_ref(), namespace, qname) { + match doc.get().CreateElementNS(&*doc, namespace, qname) { Err(error) => return Err(error), Ok(elem) => Some(elem) } }; - // Step 4. - match maybe_doctype { - None => (), - Some(ref mut doctype) => assert!(doc_node.AppendChild(NodeCast::from_mut_ref(doctype)).is_ok()) - } + { + let doc_node: &mut JSRef = NodeCast::from_mut_ref(&mut *doc); - // Step 5. - match maybe_elem { - None => (), - Some(ref elem) => { - let elem = elem.root(&roots); - assert!(doc_node.AppendChild(NodeCast::from_mut_ref(&mut elem.root_ref())).is_ok()) + // Step 4. + match maybe_doctype { + None => (), + Some(ref mut doctype) => { + assert!(AppendChild(doc_node, NodeCast::from_mut_ref(doctype)).is_ok()) + } + } + + // Step 5. + match maybe_elem.root(&roots) { + None => (), + Some(mut elem) => { + assert!(AppendChild(doc_node, NodeCast::from_mut_ref(&mut *elem)).is_ok()) + } } } @@ -108,65 +110,59 @@ impl DOMImplementation { // FIXME: https://github.com/mozilla/servo/issues/1522 // Step 7. - Ok(doc) + Ok(Unrooted::new_rooted(&*doc)) } // http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument - pub fn CreateHTMLDocument(&self, title: Option) -> JS { + pub fn CreateHTMLDocument(&self, title: Option) -> Unrooted { let roots = RootCollection::new(); let owner = self.owner.root(&roots); // Step 1-2. - let doc = Document::new(&owner.root_ref(), None, HTMLDocument, None); - let doc_root = doc.root(&roots); - let mut doc_node: JS = NodeCast::from(&doc); + let mut doc = Document::new(&owner.root_ref(), None, HTMLDocument, None).root(&roots); + let mut doc_alias = doc.clone(); + let doc_node: &mut JSRef = NodeCast::from_mut_ref(&mut doc_alias); { // Step 3. - let doc_type = DocumentType::new(~"html", None, None, &doc_root.root_ref()); - let doc_type = doc_type.root(&roots); - assert!(doc_node.AppendChild(NodeCast::from_mut_ref(&mut doc_type.root_ref())).is_ok()); + let mut doc_type = DocumentType::new(~"html", None, None, &*doc).root(&roots); + assert!(AppendChild(&mut *doc_node, NodeCast::from_mut_ref(&mut *doc_type)).is_ok()); } { // Step 4. - let mut doc_html = NodeCast::from(&HTMLHtmlElement::new(~"html", &doc_root.root_ref())); - let doc_html_root = {doc_html.root(&roots)}; - assert!(doc_node.AppendChild(&mut doc_html_root.root_ref()).is_ok()); + let mut doc_html = NodeCast::from_unrooted(HTMLHtmlElement::new(~"html", &*doc)).root(&roots); + assert!(AppendChild(&mut *doc_node, &mut *doc_html).is_ok()); { // Step 5. - let mut doc_head = NodeCast::from(&HTMLHeadElement::new(~"head", &doc_root.root_ref())); - let doc_head_root = doc_head.root(&roots); - assert!(doc_html.AppendChild(&mut doc_head_root.root_ref()).is_ok()); + let mut doc_head = NodeCast::from_unrooted(HTMLHeadElement::new(~"head", &*doc)).root(&roots); + assert!(AppendChild(&mut *doc_html, &mut *doc_head).is_ok()); // Step 6. match title { None => (), Some(title_str) => { // Step 6.1. - let mut doc_title = NodeCast::from(&HTMLTitleElement::new(~"title", &doc_root.root_ref())); - let doc_title_root = doc_title.root(&roots); - assert!(doc_head.AppendChild(&mut doc_title_root.root_ref()).is_ok()); + let mut doc_title = NodeCast::from_unrooted(HTMLTitleElement::new(~"title", &*doc)).root(&roots); + assert!(AppendChild(&mut *doc_head, &mut *doc_title).is_ok()); // Step 6.2. - let title_text = Text::new(title_str, &doc_root.root_ref()); - let title_text = title_text.root(&roots); - assert!(doc_title.AppendChild(NodeCast::from_mut_ref(&mut title_text.root_ref())).is_ok()); + let mut title_text = Text::new(title_str, &*doc).root(&roots); + assert!(AppendChild(&mut *doc_title, NodeCast::from_mut_ref(&mut *title_text)).is_ok()); } } } // Step 7. - let doc_body = HTMLBodyElement::new(~"body", &doc_root.root_ref()); - let doc_body = doc_body.root(&roots); - assert!(doc_html.AppendChild(NodeCast::from_mut_ref(&mut doc_body.root_ref())).is_ok()); + let mut doc_body = HTMLBodyElement::new(~"body", &*doc).root(&roots); + assert!(AppendChild(&mut *doc_html, NodeCast::from_mut_ref(&mut *doc_body)).is_ok()); } // Step 8. // FIXME: https://github.com/mozilla/servo/issues/1522 // Step 9. - doc + Unrooted::new_rooted(&*doc) } } diff --git a/src/components/script/dom/domparser.rs b/src/components/script/dom/domparser.rs index d11c7270057..6d77273e11e 100644 --- a/src/components/script/dom/domparser.rs +++ b/src/components/script/dom/domparser.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::DOMParserBinding; use dom::bindings::codegen::BindingDeclarations::DOMParserBinding::SupportedTypeValues::{Text_html, Text_xml}; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object}; use dom::bindings::error::{Fallible, FailureUnknown}; use dom::document::{Document, HTMLDocument, NonHTMLDocument}; @@ -25,19 +25,19 @@ impl DOMParser { } } - pub fn new(owner: &JSRef) -> JS { + pub fn new(owner: &JSRef) -> Unrooted { reflect_dom_object(~DOMParser::new_inherited(owner.unrooted()), owner, DOMParserBinding::Wrap) } - pub fn Constructor(owner: &JSRef) -> Fallible> { + pub fn Constructor(owner: &JSRef) -> Fallible> { Ok(DOMParser::new(owner)) } pub fn ParseFromString(&self, _s: DOMString, ty: DOMParserBinding::SupportedType) - -> Fallible> { + -> Fallible> { let roots = RootCollection::new(); let owner = self.owner.root(&roots); match ty { diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index 179f2c7571d..e0901de01d8 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -4,11 +4,12 @@ //! Element nodes. -use dom::attr::{Attr, AttrSettingType, ReplacedAttr, FirstSetAttr}; +use dom::attr::{Attr, ReplacedAttr, FirstSetAttr}; use dom::attrlist::AttrList; use dom::bindings::codegen::BindingDeclarations::ElementBinding; use dom::bindings::codegen::InheritTypes::{ElementDerived, NodeCast}; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, UnrootedPushable}; +use dom::bindings::js::{OptionalAssignable, OptionalRootable, Root}; use dom::bindings::utils::{Reflectable, Reflector}; use dom::bindings::error::{ErrorResult, Fallible, NamespaceError, InvalidCharacter}; use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type}; @@ -152,14 +153,15 @@ impl Element { } } - pub fn new(local_name: DOMString, namespace: Namespace, prefix: Option, document: &JSRef) -> JS { + pub fn new(local_name: DOMString, namespace: Namespace, prefix: Option, document: &JSRef) -> Unrooted { let element = Element::new_inherited(ElementTypeId, local_name, namespace, prefix, document.unrooted()); Node::reflect_node(~element, document, ElementBinding::Wrap) } pub fn html_element_in_html_document(&self) -> bool { + let roots = RootCollection::new(); self.namespace == namespace::HTML && - self.node.owner_doc().get().is_html_document + self.node.owner_doc().root(&roots).is_html_document } } @@ -168,7 +170,7 @@ impl Element { if self.namespace != namespace::HTML { return false } - let owner_doc: *JS = self.node.owner_doc(); + let owner_doc: *JS = self.node.owner_doc_for_layout(); let owner_doc: **Document = owner_doc as **Document; (**owner_doc).is_html_document } @@ -189,15 +191,15 @@ impl Element { } pub trait AttributeHandlers { - fn get_attribute(&self, namespace: Namespace, name: &str) -> Option>; + fn get_attribute(&self, namespace: Namespace, name: &str) -> Option>; fn set_attr(&mut self, name: DOMString, value: DOMString) -> ErrorResult; fn set_attribute(&mut self, namespace: Namespace, name: DOMString, value: DOMString) -> ErrorResult; fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString, name: DOMString, namespace: Namespace, - prefix: Option, cb: |&JS| -> bool); - fn SetAttribute(&mut self, name: DOMString, value: DOMString) -> ErrorResult; - fn SetAttributeNS(&mut self, namespace_url: Option, + prefix: Option, cb: |&JSRef| -> bool); + fn SetAttribute_(&mut self, name: DOMString, value: DOMString) -> ErrorResult; + fn SetAttributeNS_(&mut self, namespace_url: Option, name: DOMString, value: DOMString) -> ErrorResult; fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult; @@ -212,18 +214,18 @@ pub trait AttributeHandlers { fn set_uint_attribute(&mut self, name: &str, value: u32); } -impl AttributeHandlers for JS { - fn get_attribute(&self, namespace: Namespace, name: &str) -> Option> { +impl<'a> AttributeHandlers for JSRef<'a, Element> { + fn get_attribute(&self, namespace: Namespace, name: &str) -> Option> { if self.get().html_element_in_html_document() { self.get().attrs.iter().find(|attr| { let attr = attr.get(); name.to_ascii_lower() == attr.local_name && attr.namespace == namespace - }).map(|x| x.clone()) + }).map(|x| Unrooted::new(x.clone())) } else { self.get().attrs.iter().find(|attr| { let attr = attr.get(); name == attr.local_name && attr.namespace == namespace - }).map(|x| x.clone()) + }).map(|x| Unrooted::new(x.clone())) } } @@ -245,10 +247,11 @@ impl AttributeHandlers for JS { None => {} } - let node: JS = NodeCast::from(self); - node.get().wait_until_safe_to_modify_dom(); + let self_alias = self.clone(); + let node: &JSRef = NodeCast::from_ref(&self_alias); + node.wait_until_safe_to_modify_dom(); - let position: |&JS| -> bool = + let position: |&JSRef| -> bool = if self.get().html_element_in_html_document() { |attr| attr.get().local_name.eq_ignore_ascii_case(local_name) } else { @@ -260,33 +263,31 @@ impl AttributeHandlers for JS { fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString, name: DOMString, namespace: Namespace, - prefix: Option, cb: |&JS| -> bool) { + prefix: Option, cb: |&JSRef| -> bool) { let roots = RootCollection::new(); - let node: JS = NodeCast::from(self); - let idx = self.get().attrs.iter().position(cb); - let (mut attr, set_type): (JS, AttrSettingType) = match idx { - Some(idx) => { - let attr = self.get_mut().attrs.get(idx).clone(); - (attr, ReplacedAttr) - } - + let idx = self.get().attrs.iter() + .map(|attr| attr.root(&roots)) + .position(|attr| cb(&*attr)); + let (idx, set_type) = match idx { + Some(idx) => (idx, ReplacedAttr), None => { - let doc = node.get().owner_doc().get(); - let window = doc.window.root(&roots); - let attr = Attr::new(&window.root_ref(), local_name.clone(), value.clone(), - name, namespace.clone(), prefix, self.clone()); - self.get_mut().attrs.push(attr.clone()); - (attr, FirstSetAttr) + let window = window_from_node(self).root(&roots); + let attr = Attr::new(&*window, local_name.clone(), value.clone(), + name, namespace.clone(), prefix, self); + self.get_mut().attrs.push_unrooted(attr); + (self.get().attrs.len() - 1, FirstSetAttr) } }; - attr.get_mut().set_value(set_type, value); + self.get_mut().attrs.get_mut(idx).get_mut().set_value(set_type, value); } // http://dom.spec.whatwg.org/#dom-element-setattribute - fn SetAttribute(&mut self, name: DOMString, value: DOMString) -> ErrorResult { - let node: JS = NodeCast::from(self); - node.get().wait_until_safe_to_modify_dom(); + fn SetAttribute_(&mut self, name: DOMString, value: DOMString) -> ErrorResult { + { + let node: &JSRef = NodeCast::from_ref(self); + node.get().wait_until_safe_to_modify_dom(); + } // Step 1. match xml_name_type(name) { @@ -308,10 +309,12 @@ impl AttributeHandlers for JS { Ok(()) } - fn SetAttributeNS(&mut self, namespace_url: Option, - name: DOMString, value: DOMString) -> ErrorResult { - let node: JS = NodeCast::from(self); - node.get().wait_until_safe_to_modify_dom(); + fn SetAttributeNS_(&mut self, namespace_url: Option, + name: DOMString, value: DOMString) -> ErrorResult { + { + let node: &JSRef = NodeCast::from_ref(self); + node.get().wait_until_safe_to_modify_dom(); + } // Step 1. let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace_url)); @@ -368,8 +371,9 @@ impl AttributeHandlers for JS { fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult { let (_, local_name) = get_attribute_parts(name.clone()); - let node: JS = NodeCast::from(self); - node.get().wait_until_safe_to_modify_dom(); + let self_alias = self.clone(); + let node: &JSRef = NodeCast::from_ref(&self_alias); + node.wait_until_safe_to_modify_dom(); let idx = self.get().attrs.iter().position(|attr| { attr.get().local_name == local_name @@ -380,7 +384,7 @@ impl AttributeHandlers for JS { Some(idx) => { if namespace == namespace::Null { let removed_raw_value = self.get().attrs.get(idx).get().Value(); - vtable_for(&node).before_remove_attr(local_name.clone(), removed_raw_value); + vtable_for(node).before_remove_attr(local_name.clone(), removed_raw_value); } self.get_mut().attrs.remove(idx); @@ -391,14 +395,15 @@ impl AttributeHandlers for JS { } fn notify_attribute_changed(&self, local_name: DOMString) { - let node: JS = NodeCast::from(self); + let roots = RootCollection::new(); + let node: &JSRef = NodeCast::from_ref(self); if node.is_in_doc() { let damage = match local_name.as_slice() { "style" | "id" | "class" => MatchSelectorsDocumentDamage, _ => ContentChangedDocumentDamage }; - let document = node.get().owner_doc(); - document.get().damage_and_reflow(damage); + let document = node.owner_doc().root(&roots); + document.deref().damage_and_reflow(damage); } } @@ -417,8 +422,12 @@ impl AttributeHandlers for JS { } fn get_string_attribute(&self, name: &str) -> DOMString { + let roots = RootCollection::new(); match self.get_attribute(Null, name) { - Some(x) => x.get().Value(), + Some(x) => { + let x = x.root(&roots); + x.deref().Value() + } None => ~"" } } @@ -478,65 +487,72 @@ impl Element { // http://dom.spec.whatwg.org/#dom-element-id pub fn Id(&self, abstract_self: &JSRef) -> DOMString { - abstract_self.unrooted().get_string_attribute("id") + abstract_self.get_string_attribute("id") } // http://dom.spec.whatwg.org/#dom-element-id pub fn SetId(&mut self, abstract_self: &mut JSRef, id: DOMString) { - abstract_self.unrooted().set_string_attribute("id", id); + abstract_self.set_string_attribute("id", id); } // http://dom.spec.whatwg.org/#dom-element-classname pub fn ClassName(&self, abstract_self: &JSRef) -> DOMString { - abstract_self.unrooted().get_string_attribute("class") + abstract_self.get_string_attribute("class") } // http://dom.spec.whatwg.org/#dom-element-classname pub fn SetClassName(&self, abstract_self: &mut JSRef, class: DOMString) { - abstract_self.unrooted().set_string_attribute("class", class); + abstract_self.set_string_attribute("class", class); } // http://dom.spec.whatwg.org/#dom-element-attributes - pub fn Attributes(&mut self, abstract_self: &JSRef) -> JS { + pub fn Attributes(&mut self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); match self.attr_list { None => { - let doc = self.node.owner_doc(); - let doc = doc.get(); - let window = doc.window.root(&roots); + let doc = self.node.owner_doc().root(&roots); + let window = doc.deref().window.root(&roots); let list = AttrList::new(&window.root_ref(), abstract_self); - self.attr_list = Some(list.clone()); - list + self.attr_list.assign(Some(list)); + Unrooted::new(self.attr_list.get_ref().clone()) } - Some(ref list) => list.clone() + Some(ref list) => Unrooted::new(list.clone()) } } // http://dom.spec.whatwg.org/#dom-element-getattribute pub fn GetAttribute(&self, abstract_self: &JSRef, name: DOMString) -> Option { + let roots = RootCollection::new(); let name = if abstract_self.get().html_element_in_html_document() { name.to_ascii_lower() } else { name }; - abstract_self.unrooted().get_attribute(Null, name).map(|s| s.get().Value()) + abstract_self.get_attribute(Null, name) + .map(|s| { + let s = s.root(&roots); + s.deref().Value() + }) } // http://dom.spec.whatwg.org/#dom-element-getattributens pub fn GetAttributeNS(&self, abstract_self: &JSRef, namespace: Option, local_name: DOMString) -> Option { + let roots = RootCollection::new(); let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace)); - abstract_self.unrooted() - .get_attribute(namespace, local_name) - .map(|attr| attr.get().value.clone()) + abstract_self.get_attribute(namespace, local_name) + .map(|attr| { + let attr = attr.root(&roots); + attr.deref().Value() + }) } // http://dom.spec.whatwg.org/#dom-element-setattribute pub fn SetAttribute(&self, abstract_self: &mut JSRef, name: DOMString, value: DOMString) -> ErrorResult { - abstract_self.unrooted().SetAttribute(name, value) + abstract_self.SetAttribute_(name, value) } // http://dom.spec.whatwg.org/#dom-element-setattributens @@ -545,7 +561,7 @@ impl Element { namespace_url: Option, name: DOMString, value: DOMString) -> ErrorResult { - abstract_self.unrooted().SetAttributeNS(namespace_url, name, value) + abstract_self.SetAttributeNS_(namespace_url, name, value) } // http://dom.spec.whatwg.org/#dom-element-removeattribute @@ -557,7 +573,7 @@ impl Element { } else { name }; - abstract_self.unrooted().remove_attribute(namespace::Null, name) + abstract_self.remove_attribute(namespace::Null, name) } // http://dom.spec.whatwg.org/#dom-element-removeattributens @@ -566,7 +582,7 @@ impl Element { namespace: Option, localname: DOMString) -> ErrorResult { let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace)); - abstract_self.unrooted().remove_attribute(namespace, localname) + abstract_self.remove_attribute(namespace, localname) } // http://dom.spec.whatwg.org/#dom-element-hasattribute @@ -582,63 +598,55 @@ impl Element { self.GetAttributeNS(abstract_self, namespace, local_name).is_some() } - pub fn GetElementsByTagName(&self, abstract_self: &JSRef, localname: DOMString) -> JS { + pub fn GetElementsByTagName(&self, abstract_self: &JSRef, localname: DOMString) -> Unrooted { let roots = RootCollection::new(); - let doc = self.node.owner_doc(); - let doc = doc.get(); - let window = doc.window.root(&roots); - HTMLCollection::by_tag_name(&window.root_ref(), NodeCast::from_ref(abstract_self), localname) + let window = window_from_node(abstract_self).root(&roots); + HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(abstract_self), localname) } pub fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, - localname: DOMString) -> JS { + localname: DOMString) -> Unrooted { let roots = RootCollection::new(); - let doc = self.node.owner_doc(); - let doc = doc.get(); let namespace = match maybe_ns { Some(namespace) => Namespace::from_str(namespace), None => Null }; - let window = doc.window.root(&roots); - HTMLCollection::by_tag_name_ns(&window.root_ref(), NodeCast::from_ref(abstract_self), localname, namespace) + let window = window_from_node(abstract_self).root(&roots); + HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(abstract_self), localname, namespace) } - pub fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> JS { + pub fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> Unrooted { let roots = RootCollection::new(); - let doc = self.node.owner_doc(); - let doc = doc.get(); - let window = doc.window.root(&roots); - HTMLCollection::by_class_name(&window.root_ref(), NodeCast::from_ref(abstract_self), classes) + let window = window_from_node(abstract_self).root(&roots); + HTMLCollection::by_class_name(&*window, NodeCast::from_ref(abstract_self), classes) } // http://dev.w3.org/csswg/cssom-view/#dom-element-getclientrects - pub fn GetClientRects(&self, abstract_self: &JSRef) -> JS { + pub fn GetClientRects(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); - let doc = self.node.owner_doc(); - let win = doc.get().window.root(&roots); - let node: JS = NodeCast::from(&abstract_self.unrooted()); + let win = window_from_node(abstract_self).root(&roots); + let node: &JSRef = NodeCast::from_ref(abstract_self); let rects = node.get_content_boxes(); - let rects = rects.iter().map(|r| { + let rects: ~[Root] = rects.iter().map(|r| { ClientRect::new( - &win.root_ref(), + &*win, r.origin.y, r.origin.y + r.size.height, r.origin.x, - r.origin.x + r.size.width) + r.origin.x + r.size.width).root(&roots) }).collect(); - ClientRectList::new(&win.root_ref(), rects) + ClientRectList::new(&*win, rects.iter().map(|rect| rect.deref().clone()).collect()) } // http://dev.w3.org/csswg/cssom-view/#dom-element-getboundingclientrect - pub fn GetBoundingClientRect(&self, abstract_self: &JSRef) -> JS { + pub fn GetBoundingClientRect(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); - let doc = self.node.owner_doc(); - let win = doc.get().window.root(&roots); - let node: JS = NodeCast::from(&abstract_self.unrooted()); + let win = window_from_node(abstract_self).root(&roots); + let node: &JSRef = NodeCast::from_ref(abstract_self); let rect = node.get_bounding_content_box(); ClientRect::new( - &win.root_ref(), + &*win, rect.origin.y, rect.origin.y + rect.size.height, rect.origin.x, @@ -647,16 +655,18 @@ impl Element { pub fn GetInnerHTML(&self, abstract_self: &JSRef) -> Fallible { //XXX TODO: XML case - Ok(serialize(&mut NodeIterator::new(NodeCast::from(&abstract_self.unrooted()), false, false))) + let roots = RootCollection::new(); + Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(abstract_self), false, false))) } pub fn GetOuterHTML(&self, abstract_self: &JSRef) -> Fallible { - Ok(serialize(&mut NodeIterator::new(NodeCast::from(&abstract_self.unrooted()), true, false))) + let roots = RootCollection::new(); + Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(abstract_self), true, false))) } - pub fn Children(&self, abstract_self: &JSRef) -> JS { + pub fn Children(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); - let window = window_from_node(&abstract_self.unrooted()).root(&roots); + let window = window_from_node(abstract_self).root(&roots); HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self)) } } @@ -674,10 +684,10 @@ pub fn get_attribute_parts(name: DOMString) -> (Option<~str>, ~str) { (prefix, local_name) } -impl VirtualMethods for JS { +impl<'a> VirtualMethods for JSRef<'a, Element> { fn super_type(&self) -> Option<~VirtualMethods:> { - let node: JS = NodeCast::from(self); - Some(~node as ~VirtualMethods:) + let node: &JSRef = NodeCast::from_ref(self); + Some(~node.clone() as ~VirtualMethods:) } fn after_set_attr(&mut self, name: DOMString, value: DOMString) { @@ -687,20 +697,18 @@ impl VirtualMethods for JS { _ => (), } - let node: JS = NodeCast::from(self); match name.as_slice() { "style" => { - let doc = node.get().owner_doc(); + let doc = document_from_node(self).root(&roots); let base_url = doc.get().url().clone(); self.get_mut().style_attribute = Some(style::parse_style_attribute(value, &base_url)) } - "id" if node.is_in_doc() => { - // XXX: this dual declaration are workaround to avoid the compile error: - // "borrowed value does not live long enough" - let mut doc = node.get().owner_doc().clone(); - let doc = doc.get_mut(); - let elem = self.root(&roots); - doc.register_named_element(&elem.root_ref(), value.clone()); + "id" => { + let node: &JSRef = NodeCast::from_ref(self); + if node.is_in_doc() { + let mut doc = document_from_node(self).root(&roots); + doc.register_named_element(self, value.clone()); + } } _ => () } @@ -715,18 +723,16 @@ impl VirtualMethods for JS { _ => (), } - let node: JS = NodeCast::from(self); match name.as_slice() { "style" => { self.get_mut().style_attribute = None } - "id" if node.is_in_doc() => { - // XXX: this dual declaration are workaround to avoid the compile error: - // "borrowed value does not live long enough" - let mut doc = node.get().owner_doc().clone(); - let doc = doc.get_mut(); - let elem = self.root(&roots); - doc.unregister_named_element(&elem.root_ref(), value); + "id" => { + let node: &JSRef = NodeCast::from_ref(self); + if node.is_in_doc() { + let mut doc = document_from_node(self).root(&roots); + doc.unregister_named_element(self, value); + } } _ => () } @@ -743,9 +749,9 @@ impl VirtualMethods for JS { match self.get_attribute(Null, "id") { Some(attr) => { - let mut doc = document_from_node(self); - let elem = self.root(&roots); - doc.get_mut().register_named_element(&elem.root_ref(), attr.get().Value()); + let attr = attr.root(&roots); + let mut doc = document_from_node(self).root(&roots); + doc.register_named_element(self, attr.deref().Value()); } _ => () } @@ -758,11 +764,10 @@ impl VirtualMethods for JS { _ => (), } - match self.get_attribute(Null, "id") { + match self.get_attribute(Null, "id").root(&roots) { Some(attr) => { - let mut doc = document_from_node(self); - let elem = self.root(&roots); - doc.get_mut().unregister_named_element(&elem.root_ref(), attr.get().Value()); + let mut doc = document_from_node(self).root(&roots); + doc.unregister_named_element(self, attr.deref().Value()); } _ => () } diff --git a/src/components/script/dom/event.rs b/src/components/script/dom/event.rs index 89c250dbc95..68f83a5d509 100644 --- a/src/components/script/dom/event.rs +++ b/src/components/script/dom/event.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::EventBinding; use dom::bindings::codegen::BindingDeclarations::EventBinding::EventConstants; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted, RootCollection}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::Fallible; use dom::eventtarget::EventTarget; @@ -80,7 +80,7 @@ impl Event { } } - pub fn new(window: &JSRef) -> JS { + pub fn new(window: &JSRef) -> Unrooted { reflect_dom_object(~Event::new_inherited(HTMLEventTypeId), window, EventBinding::Wrap) @@ -94,12 +94,12 @@ impl Event { self.type_.clone() } - pub fn GetTarget(&self) -> Option> { - self.target.clone() + pub fn GetTarget(&self) -> Option> { + self.target.as_ref().map(|target| Unrooted::new(target.clone())) } - pub fn GetCurrentTarget(&self) -> Option> { - self.current_target.clone() + pub fn GetCurrentTarget(&self) -> Option> { + self.current_target.as_ref().map(|target| Unrooted::new(target.clone())) } pub fn DefaultPrevented(&self) -> bool { @@ -157,10 +157,11 @@ impl Event { pub fn Constructor(global: &JSRef, type_: DOMString, - init: &EventBinding::EventInit) -> Fallible> { - let mut ev = Event::new(global); - ev.get_mut().InitEvent(type_, init.bubbles, init.cancelable); - Ok(ev) + init: &EventBinding::EventInit) -> Fallible> { + let roots = RootCollection::new(); + let mut ev = Event::new(global).root(&roots); + ev.InitEvent(type_, init.bubbles, init.cancelable); + Ok(Unrooted::new_rooted(&*ev)) } } diff --git a/src/components/script/dom/eventdispatcher.rs b/src/components/script/dom/eventdispatcher.rs index b8fbce59974..9d45b398e02 100644 --- a/src/components/script/dom/eventdispatcher.rs +++ b/src/components/script/dom/eventdispatcher.rs @@ -4,35 +4,32 @@ use dom::bindings::callback::ReportExceptions; use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, NodeDerived}; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JSRef, OptionalAssignable, RootCollection, Root}; use dom::eventtarget::{Capturing, Bubbling, EventTarget}; use dom::event::{Event, PhaseAtTarget, PhaseNone, PhaseBubbling, PhaseCapturing}; use dom::node::{Node, NodeHelpers}; // See http://dom.spec.whatwg.org/#concept-event-dispatch for the full dispatch algorithm -pub fn dispatch_event(target: &JSRef, - pseudo_target: Option>, - event: &mut JSRef) -> bool { +pub fn dispatch_event<'a>(target: &JSRef<'a, EventTarget>, + pseudo_target: Option>, + event: &mut JSRef) -> bool { + let roots = RootCollection::new(); assert!(!event.get().dispatching); { let event = event.get_mut(); - event.target = pseudo_target.map(|pseudo_target| { - pseudo_target.unrooted() - }).or_else(|| { - Some(target.unrooted()) - }); + event.target.assign(Some(pseudo_target.unwrap_or(target.clone()))); event.dispatching = true; } let type_ = event.get().type_.clone(); //TODO: no chain if not participating in a tree - let chain: Vec> = if target.get().is_node() { - let target_node: JS = NodeCast::to(&target.unrooted()).unwrap(); + let mut chain: Vec> = if target.get().is_node() { + let target_node: &JSRef = NodeCast::to_ref(target).unwrap(); target_node.ancestors().map(|ancestor| { - let ancestor_target: JS = EventTargetCast::from(&ancestor); - ancestor_target + let ancestor_target: &JSRef = EventTargetCast::from_ref(&ancestor); + ancestor_target.unrooted().root(&roots) }).collect() } else { vec!() @@ -44,9 +41,9 @@ pub fn dispatch_event(target: &JSRef, /* capturing */ for cur_target in chain.as_slice().rev_iter() { - let stopped = match cur_target.get().get_listeners_for(type_, Capturing) { + let stopped = match cur_target.get_listeners_for(type_, Capturing) { Some(listeners) => { - event.get_mut().current_target = Some(cur_target.clone()); + event.current_target.assign(Some(cur_target.deref().clone())); for listener in listeners.iter() { //FIXME: this should have proper error handling, or explicitly // drop the exception on the floor @@ -72,7 +69,7 @@ pub fn dispatch_event(target: &JSRef, { let event = event.get_mut(); event.phase = PhaseAtTarget; - event.current_target = Some(target.unrooted()); + event.current_target.assign(Some(target.clone())); } let opt_listeners = target.get().get_listeners(type_); @@ -95,7 +92,7 @@ pub fn dispatch_event(target: &JSRef, for cur_target in chain.iter() { let stopped = match cur_target.get().get_listeners_for(type_, Bubbling) { Some(listeners) => { - event.get_mut().current_target = Some(cur_target.clone()); + event.get_mut().current_target.assign(Some(cur_target.deref().clone())); for listener in listeners.iter() { //FIXME: this should have proper error handling or explicitly // drop exceptions on the floor. @@ -116,6 +113,12 @@ pub fn dispatch_event(target: &JSRef, } } + // Root ordering restrictions mean we need to unroot the chain entries + // in the same order they were rooted. + while chain.len() > 0 { + let _ = chain.pop(); + } + let event = event.get_mut(); event.dispatching = false; event.phase = PhaseNone; diff --git a/src/components/script/dom/eventtarget.rs b/src/components/script/dom/eventtarget.rs index b77834e7cc4..67dc0ac7af9 100644 --- a/src/components/script/dom/eventtarget.rs +++ b/src/components/script/dom/eventtarget.rs @@ -2,7 +2,7 @@ * 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}; +use dom::bindings::js::JSRef; use dom::bindings::utils::{Reflectable, Reflector}; use dom::bindings::error::{Fallible, InvalidState}; use dom::bindings::codegen::BindingDeclarations::EventListenerBinding; @@ -107,10 +107,10 @@ impl EventTarget { self.dispatch_event_with_target(abstract_self, None, event) } - pub fn dispatch_event_with_target(&self, - abstract_self: &JSRef, - abstract_target: Option>, - event: &mut JSRef) -> Fallible { + pub fn dispatch_event_with_target<'a>(&self, + abstract_self: &JSRef<'a, EventTarget>, + abstract_target: Option>, + event: &mut JSRef) -> Fallible { if event.get().dispatching || !event.get().initialized { return Err(InvalidState); } @@ -128,7 +128,7 @@ impl Reflectable for EventTarget { } } -impl VirtualMethods for JS { +impl<'a> VirtualMethods for JSRef<'a, EventTarget> { fn super_type(&self) -> Option<~VirtualMethods:> { None } diff --git a/src/components/script/dom/formdata.rs b/src/components/script/dom/formdata.rs index 4b6d61c1d82..e1a7b0e7ddb 100644 --- a/src/components/script/dom/formdata.rs +++ b/src/components/script/dom/formdata.rs @@ -5,7 +5,7 @@ use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::{Fallible}; use dom::bindings::codegen::BindingDeclarations::FormDataBinding; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::blob::Blob; use dom::htmlformelement::HTMLFormElement; use dom::window::Window; @@ -37,12 +37,12 @@ impl FormData { } } - pub fn new(form: Option>, window: &JSRef) -> JS { + pub fn new(form: Option>, window: &JSRef) -> Unrooted { reflect_dom_object(~FormData::new_inherited(form, window.unrooted()), window, FormDataBinding::Wrap) } pub fn Constructor(window: &JSRef, form: Option>) - -> Fallible> { + -> Fallible> { Ok(FormData::new(form, window)) } diff --git a/src/components/script/dom/htmlanchorelement.rs b/src/components/script/dom/htmlanchorelement.rs index 7edd9116dea..d03723402eb 100644 --- a/src/components/script/dom/htmlanchorelement.rs +++ b/src/components/script/dom/htmlanchorelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLAnchorElementBinding; use dom::bindings::codegen::InheritTypes::HTMLAnchorElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLAnchorElementTypeId; @@ -34,7 +34,7 @@ impl HTMLAnchorElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLAnchorElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLAnchorElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlappletelement.rs b/src/components/script/dom/htmlappletelement.rs index d2b9fcf2e80..ea253003fd4 100644 --- a/src/components/script/dom/htmlappletelement.rs +++ b/src/components/script/dom/htmlappletelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLAppletElementBinding; use dom::bindings::codegen::InheritTypes::HTMLAppletElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLAppletElementTypeId; @@ -34,7 +34,7 @@ impl HTMLAppletElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLAppletElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLAppletElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlareaelement.rs b/src/components/script/dom/htmlareaelement.rs index f4950d46ad7..d98f2033b77 100644 --- a/src/components/script/dom/htmlareaelement.rs +++ b/src/components/script/dom/htmlareaelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLAreaElementBinding; use dom::bindings::codegen::InheritTypes::HTMLAreaElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLAreaElementTypeId; @@ -34,7 +34,7 @@ impl HTMLAreaElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLAreaElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLAreaElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlaudioelement.rs b/src/components/script/dom/htmlaudioelement.rs index 2b0b86a36f1..a4ea33c7052 100644 --- a/src/components/script/dom/htmlaudioelement.rs +++ b/src/components/script/dom/htmlaudioelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLAudioElementBinding; use dom::bindings::codegen::InheritTypes::HTMLAudioElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::document::Document; use dom::element::HTMLAudioElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,7 +33,7 @@ impl HTMLAudioElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLAudioElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLAudioElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlbaseelement.rs b/src/components/script/dom/htmlbaseelement.rs index c7d206f3c65..bfaf1a74410 100644 --- a/src/components/script/dom/htmlbaseelement.rs +++ b/src/components/script/dom/htmlbaseelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLBaseElementBinding; use dom::bindings::codegen::InheritTypes::HTMLBaseElementDerived; use dom::bindings::error::ErrorResult; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::document::Document; use dom::element::HTMLBaseElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -34,7 +34,7 @@ impl HTMLBaseElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLBaseElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLBaseElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlbodyelement.rs b/src/components/script/dom/htmlbodyelement.rs index 466c60c6430..22b41c283ba 100644 --- a/src/components/script/dom/htmlbodyelement.rs +++ b/src/components/script/dom/htmlbodyelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLBodyElementBinding; use dom::bindings::codegen::InheritTypes::HTMLBodyElementDerived; use dom::bindings::error::ErrorResult; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::document::Document; use dom::element::HTMLBodyElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -34,7 +34,7 @@ impl HTMLBodyElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLBodyElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLBodyElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlbrelement.rs b/src/components/script/dom/htmlbrelement.rs index e537b1b2c2a..5e23734042c 100644 --- a/src/components/script/dom/htmlbrelement.rs +++ b/src/components/script/dom/htmlbrelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLBRElementBinding; use dom::bindings::codegen::InheritTypes::HTMLBRElementDerived; use dom::bindings::error::ErrorResult; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::document::Document; use dom::element::HTMLBRElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -34,7 +34,7 @@ impl HTMLBRElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLBRElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLBRElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlbuttonelement.rs b/src/components/script/dom/htmlbuttonelement.rs index cee5e13946c..30f031f8058 100644 --- a/src/components/script/dom/htmlbuttonelement.rs +++ b/src/components/script/dom/htmlbuttonelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLButtonElementBinding; use dom::bindings::codegen::InheritTypes::HTMLButtonElementDerived; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLButtonElementTypeId; @@ -36,7 +36,7 @@ impl HTMLButtonElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLButtonElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLButtonElementBinding::Wrap) } @@ -59,7 +59,7 @@ impl HTMLButtonElement { Ok(()) } - pub fn GetForm(&self) -> Option> { + pub fn GetForm(&self) -> Option> { None } @@ -134,11 +134,10 @@ impl HTMLButtonElement { pub fn SetWillValidate(&mut self, _will_validate: bool) { } - pub fn Validity(&self) -> JS { + pub fn Validity(&self) -> Unrooted { let roots = RootCollection::new(); - let doc = self.htmlelement.element.node.owner_doc(); - let doc = doc.get(); - ValidityState::new(&doc.window.root(&roots).root_ref()) + let doc = self.htmlelement.element.node.owner_doc().root(&roots); + ValidityState::new(&*doc.deref().window.root(&roots)) } pub fn SetValidity(&mut self, _validity: JS) { diff --git a/src/components/script/dom/htmlcanvaselement.rs b/src/components/script/dom/htmlcanvaselement.rs index 4c825780216..469bb8b8643 100644 --- a/src/components/script/dom/htmlcanvaselement.rs +++ b/src/components/script/dom/htmlcanvaselement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLCanvasElementBinding; use dom::bindings::codegen::InheritTypes::HTMLCanvasElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::{ErrorResult}; use dom::document::Document; use dom::element::HTMLCanvasElementTypeId; @@ -34,7 +34,7 @@ impl HTMLCanvasElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLCanvasElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLCanvasElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlcollection.rs b/src/components/script/dom/htmlcollection.rs index 8529d4daf64..73b4835ff2e 100644 --- a/src/components/script/dom/htmlcollection.rs +++ b/src/components/script/dom/htmlcollection.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast}; use dom::bindings::codegen::BindingDeclarations::HTMLCollectionBinding; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::element::{Element, AttributeHandlers}; use dom::node::{Node, NodeHelpers}; @@ -46,19 +46,19 @@ impl HTMLCollection { } } - pub fn new(window: &JSRef, collection: CollectionTypeId) -> JS { + pub fn new(window: &JSRef, collection: CollectionTypeId) -> Unrooted { reflect_dom_object(~HTMLCollection::new_inherited(window.unrooted(), collection), window, HTMLCollectionBinding::Wrap) } } impl HTMLCollection { - pub fn create(window: &JSRef, root: &JSRef, filter: ~CollectionFilter) -> JS { + pub fn create(window: &JSRef, root: &JSRef, filter: ~CollectionFilter) -> Unrooted { HTMLCollection::new(window, Live(root.unrooted(), filter)) } pub fn by_tag_name(window: &JSRef, root: &JSRef, tag: DOMString) - -> JS { + -> Unrooted { struct TagNameFilter { tag: DOMString } @@ -74,7 +74,7 @@ impl HTMLCollection { } pub fn by_tag_name_ns(window: &JSRef, root: &JSRef, tag: DOMString, - namespace: Namespace) -> JS { + namespace: Namespace) -> Unrooted { struct TagNameNSFilter { tag: DOMString, namespace: Namespace @@ -92,13 +92,13 @@ impl HTMLCollection { } pub fn by_class_name(window: &JSRef, root: &JSRef, classes: DOMString) - -> JS { + -> Unrooted { struct ClassNameFilter { classes: Vec } impl CollectionFilter for ClassNameFilter { fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { - self.classes.iter().all(|class| elem.unrooted().has_class(*class)) + self.classes.iter().all(|class| elem.has_class(*class)) } } let filter = ClassNameFilter { @@ -107,11 +107,11 @@ impl HTMLCollection { HTMLCollection::create(window, root, ~filter) } - pub fn children(window: &JSRef, root: &JSRef) -> JS { + pub fn children(window: &JSRef, root: &JSRef) -> Unrooted { struct ElementChildFilter; impl CollectionFilter for ElementChildFilter { fn filter(&self, elem: &JSRef, root: &JSRef) -> bool { - root.unrooted().is_parent_of(NodeCast::from_ref(elem)) + root.is_parent_of(NodeCast::from_ref(elem)) } } HTMLCollection::create(window, root, ~ElementChildFilter) @@ -125,43 +125,43 @@ impl HTMLCollection { match self.collection { Static(ref elems) => elems.len() as u32, Live(ref root, ref filter) => { - let root_root = root.root(&roots); - root.traverse_preorder() + let root = root.root(&roots); + root.deref().traverse_preorder(&roots) .count(|child| { - let elem: Option> = ElementCast::to(&child); - elem.map_or(false, |elem| { - let elem = elem.root(&roots); - filter.filter(&elem.root_ref(), &root_root.root_ref()) - }) + let elem: Option<&JSRef> = ElementCast::to_ref(&child); + elem.map_or(false, |elem| filter.filter(elem, &*root)) }) as u32 } } } // http://dom.spec.whatwg.org/#dom-htmlcollection-item - pub fn Item(&self, index: u32) -> Option> { + pub fn Item(&self, index: u32) -> Option> { let roots = RootCollection::new(); match self.collection { Static(ref elems) => elems .as_slice() .get(index as uint) - .map(|elem| elem.clone()), + .map(|elem| Unrooted::new(elem.clone())), Live(ref root, ref filter) => { - let root_root = root.root(&roots); - root.traverse_preorder() - .filter_map(|node| ElementCast::to(&node)) - .filter(|elem| { - let elem = elem.root(&roots); - filter.filter(&elem.root_ref(), &root_root.root_ref()) + let root = root.root(&roots); + root.deref().traverse_preorder(&roots) + .filter_map(|node| { + let elem: Option<&JSRef> = ElementCast::to_ref(&node); + elem.filtered(|&elem| filter.filter(elem, &*root)) + .and_then(|elem| Some(elem.clone())) }) - .nth(index as uint).clone() + .nth(index as uint) + .clone() + .map(|elem| Unrooted::new_rooted(&elem)) } } } // http://dom.spec.whatwg.org/#dom-htmlcollection-nameditem - pub fn NamedItem(&self, key: DOMString) -> Option> { + pub fn NamedItem(&self, key: DOMString) -> Option> { let roots = RootCollection::new(); + // Step 1. if key.is_empty() { return None; @@ -170,35 +170,36 @@ impl HTMLCollection { // Step 2. match self.collection { Static(ref elems) => elems.iter() + .map(|elem| elem.root(&roots)) .find(|elem| { elem.get_string_attribute("name") == key || elem.get_string_attribute("id") == key }) - .map(|maybe_elem| maybe_elem.clone()), + .map(|maybe_elem| Unrooted::new_rooted(&*maybe_elem)), Live(ref root, ref filter) => { - let root_root = root.root(&roots); - root.traverse_preorder() - .filter_map(|node| ElementCast::to(&node)) - .filter(|elem| { - let elem = elem.root(&roots); - filter.filter(&elem.root_ref(), &root_root.root_ref()) + let root = root.root(&roots); + root.deref().traverse_preorder(&roots) + .filter_map(|node| { + let elem: Option<&JSRef> = ElementCast::to_ref(&node); + elem.filtered(|&elem| filter.filter(elem, &*root)) + .and_then(|elem| Some(elem.clone())) }) .find(|elem| { elem.get_string_attribute("name") == key || elem.get_string_attribute("id") == key }) - .map(|maybe_elem| maybe_elem.clone()) + .map(|maybe_elem| Unrooted::new_rooted(&maybe_elem)) } } } } impl HTMLCollection { - pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { + pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { let maybe_elem = self.Item(index); *found = maybe_elem.is_some(); maybe_elem } - pub fn NamedGetter(&self, maybe_name: Option, found: &mut bool) -> Option> { + pub fn NamedGetter(&self, maybe_name: Option, found: &mut bool) -> Option> { match maybe_name { Some(name) => { let maybe_elem = self.NamedItem(name); diff --git a/src/components/script/dom/htmldataelement.rs b/src/components/script/dom/htmldataelement.rs index b95c77acc07..767b3b18598 100644 --- a/src/components/script/dom/htmldataelement.rs +++ b/src/components/script/dom/htmldataelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDataElementBinding; use dom::bindings::codegen::InheritTypes::HTMLDataElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLDataElementTypeId; @@ -34,7 +34,7 @@ impl HTMLDataElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLDataElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLDataElementBinding::Wrap) } diff --git a/src/components/script/dom/htmldatalistelement.rs b/src/components/script/dom/htmldatalistelement.rs index b341a34dcb0..e4ac02bd83f 100644 --- a/src/components/script/dom/htmldatalistelement.rs +++ b/src/components/script/dom/htmldatalistelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDataListElementBinding; use dom::bindings::codegen::InheritTypes::{HTMLDataListElementDerived, NodeCast}; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; use dom::document::Document; use dom::element::{Element, HTMLDataListElementTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -34,14 +34,14 @@ impl HTMLDataListElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLDataListElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLDataListElementBinding::Wrap) } } impl HTMLDataListElement { - pub fn Options(&self, abstract_self: &JSRef) -> JS { + pub fn Options(&self, abstract_self: &JSRef) -> Unrooted { struct HTMLDataListOptionsFilter; impl CollectionFilter for HTMLDataListOptionsFilter { fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { @@ -51,7 +51,7 @@ impl HTMLDataListElement { let roots = RootCollection::new(); let node: &JSRef = NodeCast::from_ref(abstract_self); let filter = ~HTMLDataListOptionsFilter; - let window = window_from_node(&node.unrooted()).root(&roots); - HTMLCollection::create(&window.root_ref(), node, filter) + let window = window_from_node(node).root(&roots); + HTMLCollection::create(&*window, node, filter) } } diff --git a/src/components/script/dom/htmldirectoryelement.rs b/src/components/script/dom/htmldirectoryelement.rs index 84ee0b539b6..f4b77ee5cf0 100644 --- a/src/components/script/dom/htmldirectoryelement.rs +++ b/src/components/script/dom/htmldirectoryelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDirectoryElementBinding; use dom::bindings::codegen::InheritTypes::HTMLDirectoryElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLDirectoryElementTypeId; @@ -34,7 +34,7 @@ impl HTMLDirectoryElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLDirectoryElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLDirectoryElementBinding::Wrap) } diff --git a/src/components/script/dom/htmldivelement.rs b/src/components/script/dom/htmldivelement.rs index 723a2088307..6053582738d 100644 --- a/src/components/script/dom/htmldivelement.rs +++ b/src/components/script/dom/htmldivelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDivElementBinding; use dom::bindings::codegen::InheritTypes::HTMLDivElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLDivElementTypeId; @@ -34,7 +34,7 @@ impl HTMLDivElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLDivElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLDivElementBinding::Wrap) } diff --git a/src/components/script/dom/htmldlistelement.rs b/src/components/script/dom/htmldlistelement.rs index 8f3523189b7..113547af9d6 100644 --- a/src/components/script/dom/htmldlistelement.rs +++ b/src/components/script/dom/htmldlistelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDListElementBinding; use dom::bindings::codegen::InheritTypes::HTMLDListElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLDListElementTypeId; @@ -34,7 +34,7 @@ impl HTMLDListElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLDListElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLDListElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlelement.rs b/src/components/script/dom/htmlelement.rs index a7852aec276..d49ce843bd1 100644 --- a/src/components/script/dom/htmlelement.rs +++ b/src/components/script/dom/htmlelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLElementBinding; use dom::bindings::codegen::InheritTypes::ElementCast; use dom::bindings::codegen::InheritTypes::HTMLElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::{ErrorResult, Fallible}; use dom::document::Document; use dom::element::{Element, ElementTypeId, HTMLElementTypeId}; @@ -39,7 +39,7 @@ impl HTMLElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLElement::new_inherited(HTMLElementTypeId, localName, document.unrooted()); Node::reflect_node(~element, document, HTMLElementBinding::Wrap) } @@ -143,7 +143,7 @@ impl HTMLElement { Ok(()) } - pub fn GetOffsetParent(&self) -> Option> { + pub fn GetOffsetParent(&self) -> Option> { None } @@ -164,9 +164,9 @@ impl HTMLElement { } } -impl VirtualMethods for JS { +impl<'a> VirtualMethods for JSRef<'a, HTMLElement> { fn super_type(&self) -> Option<~VirtualMethods:> { - let element: JS = ElementCast::from(self); - Some(~element as ~VirtualMethods:) + let element: &JSRef = ElementCast::from_ref(self); + Some(~element.clone() as ~VirtualMethods:) } } diff --git a/src/components/script/dom/htmlembedelement.rs b/src/components/script/dom/htmlembedelement.rs index 73a915c4cc7..864e1a1829c 100644 --- a/src/components/script/dom/htmlembedelement.rs +++ b/src/components/script/dom/htmlembedelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLEmbedElementBinding; use dom::bindings::codegen::InheritTypes::HTMLEmbedElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLEmbedElementTypeId; @@ -34,7 +34,7 @@ impl HTMLEmbedElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLEmbedElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLEmbedElementBinding::Wrap) } @@ -89,7 +89,7 @@ impl HTMLEmbedElement { Ok(()) } - pub fn GetSVGDocument(&self) -> Option> { + pub fn GetSVGDocument(&self) -> Option> { None } } diff --git a/src/components/script/dom/htmlfieldsetelement.rs b/src/components/script/dom/htmlfieldsetelement.rs index 3b1141f403e..1bb9146e4e7 100644 --- a/src/components/script/dom/htmlfieldsetelement.rs +++ b/src/components/script/dom/htmlfieldsetelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFieldSetElementBinding; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLFieldSetElementDerived, NodeCast}; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLFieldSetElementTypeId}; @@ -37,7 +37,7 @@ impl HTMLFieldSetElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLFieldSetElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLFieldSetElementBinding::Wrap) } @@ -52,7 +52,7 @@ impl HTMLFieldSetElement { Ok(()) } - pub fn GetForm(&self) -> Option> { + pub fn GetForm(&self) -> Option> { None } @@ -69,33 +69,32 @@ impl HTMLFieldSetElement { } // http://www.whatwg.org/html/#dom-fieldset-elements - pub fn Elements(&self, abstract_self: &JSRef) -> JS { + pub fn Elements(&self, abstract_self: &JSRef) -> Unrooted { struct ElementsFilter; impl CollectionFilter for ElementsFilter { fn filter(&self, elem: &JSRef, root: &JSRef) -> bool { static tag_names: StaticStringVec = &["button", "fieldset", "input", "keygen", "object", "output", "select", "textarea"]; - let root: &JS = &ElementCast::to(&root.unrooted()).unwrap(); - &elem.unrooted() != root && tag_names.iter().any(|&tag_name| tag_name == elem.get().local_name) + let root: &JSRef = ElementCast::to_ref(root).unwrap(); + elem != root && tag_names.iter().any(|&tag_name| tag_name == elem.get().local_name) } } let roots = RootCollection::new(); let node: &JSRef = NodeCast::from_ref(abstract_self); let filter = ~ElementsFilter; - let window = window_from_node(&node.unrooted()).root(&roots); - HTMLCollection::create(&window.root_ref(), node, filter) + let window = window_from_node(node).root(&roots); + HTMLCollection::create(&*window, node, filter) } pub fn WillValidate(&self) -> bool { false } - pub fn Validity(&self) -> JS { + pub fn Validity(&self) -> Unrooted { let roots = RootCollection::new(); - let doc = self.htmlelement.element.node.owner_doc(); - let doc = doc.get(); - let window = doc.window.root(&roots); - ValidityState::new(&window.root_ref()) + let doc = self.htmlelement.element.node.owner_doc().root(&roots); + let window = doc.deref().window.root(&roots); + ValidityState::new(&*window) } pub fn ValidationMessage(&self) -> DOMString { diff --git a/src/components/script/dom/htmlfontelement.rs b/src/components/script/dom/htmlfontelement.rs index f28971e7c43..fefc9c0f4df 100644 --- a/src/components/script/dom/htmlfontelement.rs +++ b/src/components/script/dom/htmlfontelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFontElementBinding; use dom::bindings::codegen::InheritTypes::HTMLFontElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLFontElementTypeId; @@ -34,7 +34,7 @@ impl HTMLFontElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLFontElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLFontElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlformelement.rs b/src/components/script/dom/htmlformelement.rs index 0e7159c61b9..329b9e07baf 100644 --- a/src/components/script/dom/htmlformelement.rs +++ b/src/components/script/dom/htmlformelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFormElementBinding; use dom::bindings::codegen::InheritTypes::HTMLFormElementDerived; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLFormElementTypeId}; @@ -35,7 +35,7 @@ impl HTMLFormElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLFormElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLFormElementBinding::Wrap) } @@ -114,13 +114,12 @@ impl HTMLFormElement { Ok(()) } - pub fn Elements(&self) -> JS { + pub fn Elements(&self) -> Unrooted { // FIXME: https://github.com/mozilla/servo/issues/1844 let roots = RootCollection::new(); - let doc = self.htmlelement.element.node.owner_doc(); - let doc = doc.get(); - let window = doc.window.root(&roots); - HTMLCollection::new(&window.root_ref(), Static(vec!())) + let doc = self.htmlelement.element.node.owner_doc().root(&roots); + let window = doc.deref().window.root(&roots); + HTMLCollection::new(&*window, Static(vec!())) } pub fn Length(&self) -> i32 { @@ -138,7 +137,7 @@ impl HTMLFormElement { false } - pub fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> JS { + pub fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Unrooted { fail!("Not implemented.") } } diff --git a/src/components/script/dom/htmlframeelement.rs b/src/components/script/dom/htmlframeelement.rs index 535c0398690..180124bf6dd 100644 --- a/src/components/script/dom/htmlframeelement.rs +++ b/src/components/script/dom/htmlframeelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFrameElementBinding; use dom::bindings::codegen::InheritTypes::HTMLFrameElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLFrameElementTypeId; @@ -35,7 +35,7 @@ impl HTMLFrameElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLFrameElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLFrameElementBinding::Wrap) } @@ -90,11 +90,11 @@ impl HTMLFrameElement { Ok(()) } - pub fn GetContentDocument(&self) -> Option> { + pub fn GetContentDocument(&self) -> Option> { None } - pub fn GetContentWindow(&self) -> Option> { + pub fn GetContentWindow(&self) -> Option> { None } diff --git a/src/components/script/dom/htmlframesetelement.rs b/src/components/script/dom/htmlframesetelement.rs index 29691e01397..9177c197ae8 100644 --- a/src/components/script/dom/htmlframesetelement.rs +++ b/src/components/script/dom/htmlframesetelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFrameSetElementBinding; use dom::bindings::codegen::InheritTypes::HTMLFrameSetElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLFrameSetElementTypeId; @@ -34,7 +34,7 @@ impl HTMLFrameSetElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLFrameSetElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLFrameSetElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlheadelement.rs b/src/components/script/dom/htmlheadelement.rs index 3f2037d7188..6b10c6078c3 100644 --- a/src/components/script/dom/htmlheadelement.rs +++ b/src/components/script/dom/htmlheadelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLHeadElementBinding; use dom::bindings::codegen::InheritTypes::HTMLHeadElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::document::Document; use dom::element::HTMLHeadElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,7 +33,7 @@ impl HTMLHeadElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLHeadElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLHeadElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlheadingelement.rs b/src/components/script/dom/htmlheadingelement.rs index 40844eb36e5..4574189d7bf 100644 --- a/src/components/script/dom/htmlheadingelement.rs +++ b/src/components/script/dom/htmlheadingelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLHeadingElementBinding; use dom::bindings::codegen::InheritTypes::HTMLHeadingElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::document::Document; use dom::element::HTMLHeadingElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -45,7 +45,7 @@ impl HTMLHeadingElement { } } - pub fn new(localName: DOMString, document: &JSRef, level: HeadingLevel) -> JS { + pub fn new(localName: DOMString, document: &JSRef, level: HeadingLevel) -> Unrooted { let element = HTMLHeadingElement::new_inherited(localName, document.unrooted(), level); Node::reflect_node(~element, document, HTMLHeadingElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlhrelement.rs b/src/components/script/dom/htmlhrelement.rs index 28bdd2ed3de..14098388c1d 100644 --- a/src/components/script/dom/htmlhrelement.rs +++ b/src/components/script/dom/htmlhrelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLHRElementBinding; use dom::bindings::codegen::InheritTypes::HTMLHRElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLHRElementTypeId; @@ -34,7 +34,7 @@ impl HTMLHRElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLHRElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLHRElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlhtmlelement.rs b/src/components/script/dom/htmlhtmlelement.rs index 391bf7b2465..1930ce271c2 100644 --- a/src/components/script/dom/htmlhtmlelement.rs +++ b/src/components/script/dom/htmlhtmlelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLHtmlElementBinding; use dom::bindings::codegen::InheritTypes::HTMLHtmlElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLHtmlElementTypeId; @@ -34,7 +34,7 @@ impl HTMLHtmlElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLHtmlElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLHtmlElementBinding::Wrap) } diff --git a/src/components/script/dom/htmliframeelement.rs b/src/components/script/dom/htmliframeelement.rs index c037f17f9a5..c157e2ad445 100644 --- a/src/components/script/dom/htmliframeelement.rs +++ b/src/components/script/dom/htmliframeelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLIFrameElementBinding; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLIFrameElementDerived, HTMLElementCast}; use dom::bindings::error::ErrorResult; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::trace::Untraceable; use dom::document::Document; use dom::element::{HTMLIFrameElementTypeId, Element}; @@ -74,7 +74,7 @@ impl HTMLIFrameElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLIFrameElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLIFrameElementBinding::Wrap) } @@ -106,12 +106,12 @@ impl HTMLIFrameElement { } pub fn Sandbox(&self, abstract_self: &JSRef) -> DOMString { - let element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &JSRef = ElementCast::from_ref(abstract_self); element.get_string_attribute("sandbox") } pub fn SetSandbox(&mut self, abstract_self: &mut JSRef, sandbox: DOMString) { - let mut element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_string_attribute("sandbox", sandbox); } @@ -139,11 +139,11 @@ impl HTMLIFrameElement { Ok(()) } - pub fn GetContentDocument(&self) -> Option> { + pub fn GetContentDocument(&self) -> Option> { None } - pub fn GetContentWindow(&self) -> Option> { + pub fn GetContentWindow(&self) -> Option> { None } @@ -195,15 +195,15 @@ impl HTMLIFrameElement { Ok(()) } - pub fn GetSVGDocument(&self) -> Option> { + pub fn GetSVGDocument(&self) -> Option> { None } } -impl VirtualMethods for JS { +impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> { fn super_type(&self) -> Option<~VirtualMethods:> { - let htmlelement: JS = HTMLElementCast::from(self); - Some(~htmlelement as ~VirtualMethods:) + let htmlelement: &JSRef = HTMLElementCast::from_ref(self); + Some(~htmlelement.clone() as ~VirtualMethods:) } fn after_set_attr(&mut self, name: DOMString, value: DOMString) { diff --git a/src/components/script/dom/htmlimageelement.rs b/src/components/script/dom/htmlimageelement.rs index d986f5d07e8..04528c54283 100644 --- a/src/components/script/dom/htmlimageelement.rs +++ b/src/components/script/dom/htmlimageelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLImageElementBinding; use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast, HTMLElementCast, HTMLImageElementDerived}; use dom::bindings::error::ErrorResult; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted, RootCollection}; use dom::bindings::trace::Untraceable; use dom::document::Document; use dom::element::{Element, HTMLImageElementTypeId}; @@ -43,7 +43,7 @@ impl HTMLImageElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLImageElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLImageElementBinding::Wrap) } @@ -57,9 +57,10 @@ impl HTMLImageElement { /// Makes the local `image` member match the status of the `src` attribute and starts /// prefetching the image. This method must be called after `src` is changed. fn update_image(&mut self, value: Option, url: Option) { + let roots = RootCollection::new(); let elem = &mut self.htmlelement.element; - let document = elem.node.owner_doc(); - let window = document.get().window.get(); + let document = elem.node.owner_doc().root(&roots); + let window = document.deref().window.root(&roots); let image_cache = &window.image_cache_task; match value { None => { @@ -80,22 +81,22 @@ impl HTMLImageElement { } pub fn Alt(&self, abstract_self: &JSRef) -> DOMString { - let element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &JSRef = ElementCast::from_ref(abstract_self); element.get_string_attribute("alt") } - pub fn SetAlt(&mut self, abstract_self: &JSRef, alt: DOMString) { - let mut element: JS = ElementCast::from(&abstract_self.unrooted()); + pub fn SetAlt(&mut self, abstract_self: &mut JSRef, alt: DOMString) { + let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_string_attribute("alt", alt) } pub fn Src(&self, abstract_self: &JSRef) -> DOMString { - let element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &JSRef = ElementCast::from_ref(abstract_self); element.get_string_attribute("src") } pub fn SetSrc(&mut self, abstract_self: &mut JSRef, src: DOMString) { - let mut element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_url_attribute("src", src) } @@ -108,44 +109,44 @@ impl HTMLImageElement { } pub fn UseMap(&self, abstract_self: &JSRef) -> DOMString { - let element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &JSRef = ElementCast::from_ref(abstract_self); element.get_string_attribute("useMap") } pub fn SetUseMap(&mut self, abstract_self: &mut JSRef, use_map: DOMString) { - let mut element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_string_attribute("useMap", use_map) } pub fn IsMap(&self, abstract_self: &JSRef) -> bool { - let element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &JSRef = ElementCast::from_ref(abstract_self); from_str::(element.get_string_attribute("hspace")).unwrap() } pub fn SetIsMap(&self, abstract_self: &mut JSRef, is_map: bool) { - let mut element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_string_attribute("isMap", is_map.to_str()) } pub fn Width(&self, abstract_self: &JSRef) -> u32 { - let node: JS = NodeCast::from(&abstract_self.unrooted()); + let node: &JSRef = NodeCast::from_ref(abstract_self); let rect = node.get_bounding_content_box(); to_px(rect.size.width) as u32 } - pub fn SetWidth(&mut self, abstract_self: &JSRef, width: u32) { - let mut elem: JS = ElementCast::from(&abstract_self.unrooted()); + pub fn SetWidth(&mut self, abstract_self: &mut JSRef, width: u32) { + let elem: &mut JSRef = ElementCast::from_mut_ref(abstract_self); elem.set_uint_attribute("width", width) } pub fn Height(&self, abstract_self: &JSRef) -> u32 { - let node: JS = NodeCast::from(&abstract_self.unrooted()); + let node: &JSRef = NodeCast::from_ref(abstract_self); let rect = node.get_bounding_content_box(); to_px(rect.size.height) as u32 } - pub fn SetHeight(&mut self, abstract_self: &JSRef, height: u32) { - let mut elem: JS = ElementCast::from(&abstract_self.unrooted()); + pub fn SetHeight(&mut self, abstract_self: &mut JSRef, height: u32) { + let elem: &mut JSRef = ElementCast::from_mut_ref(abstract_self); elem.set_uint_attribute("height", height) } @@ -162,87 +163,88 @@ impl HTMLImageElement { } pub fn Name(&self, abstract_self: &JSRef) -> DOMString { - let element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &JSRef = ElementCast::from_ref(abstract_self); element.get_string_attribute("name") } pub fn SetName(&mut self, abstract_self: &mut JSRef, name: DOMString) { - let mut element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_string_attribute("name", name) } pub fn Align(&self, abstract_self: &JSRef) -> DOMString { - let element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &JSRef = ElementCast::from_ref(abstract_self); element.get_string_attribute("longdesc") } pub fn SetAlign(&mut self, abstract_self: &mut JSRef, align: DOMString) { - let mut element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_string_attribute("align", align) } pub fn Hspace(&self, abstract_self: &JSRef) -> u32 { - let element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &JSRef = ElementCast::from_ref(abstract_self); from_str::(element.get_string_attribute("hspace")).unwrap() } pub fn SetHspace(&mut self, abstract_self: &mut JSRef, hspace: u32) { - let mut element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_uint_attribute("hspace", hspace) } pub fn Vspace(&self, abstract_self: &JSRef) -> u32 { - let element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &JSRef = ElementCast::from_ref(abstract_self); from_str::(element.get_string_attribute("vspace")).unwrap() } pub fn SetVspace(&mut self, abstract_self: &mut JSRef, vspace: u32) { - let mut element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_uint_attribute("vspace", vspace) } pub fn LongDesc(&self, abstract_self: &JSRef) -> DOMString { - let element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &JSRef = ElementCast::from_ref(abstract_self); element.get_string_attribute("longdesc") } pub fn SetLongDesc(&mut self, abstract_self: &mut JSRef, longdesc: DOMString) { - let mut element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_string_attribute("longdesc", longdesc) } pub fn Border(&self, abstract_self: &JSRef) -> DOMString { - let element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &JSRef = ElementCast::from_ref(abstract_self); element.get_string_attribute("border") } pub fn SetBorder(&mut self, abstract_self: &mut JSRef, border: DOMString) { - let mut element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_string_attribute("border", border) } } -impl VirtualMethods for JS { +impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> { fn super_type(&self) -> Option<~VirtualMethods:> { - let htmlelement: JS = HTMLElementCast::from(self); - Some(~htmlelement as ~VirtualMethods:) + let htmlelement: &JSRef = HTMLElementCast::from_ref(self); + Some(~htmlelement.clone() as ~VirtualMethods:) } fn after_set_attr(&mut self, name: DOMString, value: DOMString) { + let roots = RootCollection::new(); match self.super_type() { Some(ref mut s) => s.after_set_attr(name.clone(), value.clone()), _ => (), } if "src" == name { - let window = window_from_node(self); + let window = window_from_node(self).root(&roots); let url = Some(window.get().get_url()); self.get_mut().update_image(Some(value), url); } } fn before_remove_attr(&mut self, name: DOMString, value: DOMString) { - match self.super_type() { + match self.super_type() { Some(ref mut s) => s.before_remove_attr(name.clone(), value.clone()), _ => (), } diff --git a/src/components/script/dom/htmlinputelement.rs b/src/components/script/dom/htmlinputelement.rs index 90914fbc7bb..55d8fc7c1a7 100644 --- a/src/components/script/dom/htmlinputelement.rs +++ b/src/components/script/dom/htmlinputelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLInputElementBinding; use dom::bindings::codegen::InheritTypes::HTMLInputElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::{ErrorResult, Fallible}; use dom::document::Document; use dom::element::HTMLInputElementTypeId; @@ -34,7 +34,7 @@ impl HTMLInputElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLInputElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLInputElementBinding::Wrap) } diff --git a/src/components/script/dom/htmllabelelement.rs b/src/components/script/dom/htmllabelelement.rs index 5c920fd75eb..dcd080f7f24 100644 --- a/src/components/script/dom/htmllabelelement.rs +++ b/src/components/script/dom/htmllabelelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLLabelElementBinding; use dom::bindings::codegen::InheritTypes::HTMLLabelElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::document::Document; use dom::element::HTMLLabelElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,7 +33,7 @@ impl HTMLLabelElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLLabelElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLLabelElementBinding::Wrap) } diff --git a/src/components/script/dom/htmllegendelement.rs b/src/components/script/dom/htmllegendelement.rs index ee6199808eb..696247f40db 100644 --- a/src/components/script/dom/htmllegendelement.rs +++ b/src/components/script/dom/htmllegendelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLLegendElementBinding; use dom::bindings::codegen::InheritTypes::HTMLLegendElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLLegendElementTypeId; @@ -34,7 +34,7 @@ impl HTMLLegendElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLLegendElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLLegendElementBinding::Wrap) } diff --git a/src/components/script/dom/htmllielement.rs b/src/components/script/dom/htmllielement.rs index 2a7501b08e9..d3b625e5987 100644 --- a/src/components/script/dom/htmllielement.rs +++ b/src/components/script/dom/htmllielement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLLIElementBinding; use dom::bindings::codegen::InheritTypes::HTMLLIElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLLIElementTypeId; @@ -34,7 +34,7 @@ impl HTMLLIElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLLIElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLLIElementBinding::Wrap) } diff --git a/src/components/script/dom/htmllinkelement.rs b/src/components/script/dom/htmllinkelement.rs index 528ea303a2c..3d474d1af64 100644 --- a/src/components/script/dom/htmllinkelement.rs +++ b/src/components/script/dom/htmllinkelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLLinkElementBinding; use dom::bindings::codegen::InheritTypes::HTMLLinkElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLLinkElementTypeId; @@ -34,7 +34,7 @@ impl HTMLLinkElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLLinkElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLLinkElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlmainelement.rs b/src/components/script/dom/htmlmainelement.rs index 74bc99c0149..ad9a2c6af1e 100644 --- a/src/components/script/dom/htmlmainelement.rs +++ b/src/components/script/dom/htmlmainelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLMainElementBinding; use dom::bindings::codegen::InheritTypes::HTMLMainElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::document::Document; use dom::element::HTMLMainElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,7 +33,7 @@ impl HTMLMainElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLMainElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLMainElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlmapelement.rs b/src/components/script/dom/htmlmapelement.rs index aff393505af..18dfd17e88b 100644 --- a/src/components/script/dom/htmlmapelement.rs +++ b/src/components/script/dom/htmlmapelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLMapElementBinding; use dom::bindings::codegen::InheritTypes::HTMLMapElementDerived; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLMapElementTypeId; @@ -35,7 +35,7 @@ impl HTMLMapElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLMapElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLMapElementBinding::Wrap) } @@ -50,12 +50,11 @@ impl HTMLMapElement { Ok(()) } - pub fn Areas(&self) -> JS { + pub fn Areas(&self) -> Unrooted { let roots = RootCollection::new(); // FIXME: https://github.com/mozilla/servo/issues/1845 - let doc = self.htmlelement.element.node.owner_doc(); - let doc = doc.get(); - let window = doc.window.root(&roots); - HTMLCollection::new(&window.root_ref(), Static(vec!())) + let doc = self.htmlelement.element.node.owner_doc().root(&roots); + let window = doc.deref().window.root(&roots); + HTMLCollection::new(&*window, Static(vec!())) } } diff --git a/src/components/script/dom/htmlmetaelement.rs b/src/components/script/dom/htmlmetaelement.rs index 191a49f2444..737cc6710fc 100644 --- a/src/components/script/dom/htmlmetaelement.rs +++ b/src/components/script/dom/htmlmetaelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLMetaElementBinding; use dom::bindings::codegen::InheritTypes::HTMLMetaElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLMetaElementTypeId; @@ -34,7 +34,7 @@ impl HTMLMetaElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLMetaElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLMetaElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlmeterelement.rs b/src/components/script/dom/htmlmeterelement.rs index 19bac1c9797..9d5f699ae14 100644 --- a/src/components/script/dom/htmlmeterelement.rs +++ b/src/components/script/dom/htmlmeterelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLMeterElementBinding; use dom::bindings::codegen::InheritTypes::HTMLMeterElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLMeterElementTypeId; @@ -34,7 +34,7 @@ impl HTMLMeterElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLMeterElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLMeterElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlmodelement.rs b/src/components/script/dom/htmlmodelement.rs index b934ef74b86..41ed8244a9d 100644 --- a/src/components/script/dom/htmlmodelement.rs +++ b/src/components/script/dom/htmlmodelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLModElementBinding; use dom::bindings::codegen::InheritTypes::HTMLModElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLModElementTypeId; @@ -34,7 +34,7 @@ impl HTMLModElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLModElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLModElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlobjectelement.rs b/src/components/script/dom/htmlobjectelement.rs index f3f48cba313..4814ac4b337 100644 --- a/src/components/script/dom/htmlobjectelement.rs +++ b/src/components/script/dom/htmlobjectelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLObjectElementBinding; use dom::bindings::codegen::InheritTypes::HTMLObjectElementDerived; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast}; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLObjectElementTypeId}; @@ -47,7 +47,7 @@ impl HTMLObjectElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLObjectElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLObjectElementBinding::Wrap) } @@ -57,15 +57,16 @@ trait ProcessDataURL { fn process_data_url(&mut self, image_cache: ImageCacheTask, url: Option); } -impl ProcessDataURL for JS { +impl<'a> ProcessDataURL for JSRef<'a, HTMLObjectElement> { // Makes the local `data` member match the status of the `data` attribute and starts /// prefetching the image. This method must be called after `data` is changed. fn process_data_url(&mut self, image_cache: ImageCacheTask, url: Option) { - let elem: JS = ElementCast::from(self); + let roots = RootCollection::new(); + let elem: &JSRef = ElementCast::from_ref(self); // TODO: support other values - match (elem.get_attribute(Null, "type").map(|x| x.get().Value()), - elem.get_attribute(Null, "data").map(|x| x.get().Value())) { + match (elem.get_attribute(Null, "type").map(|x| x.root(&roots).Value()), + elem.get_attribute(Null, "data").map(|x| x.root(&roots).Value())) { (None, Some(uri)) => { if is_image_data(uri) { let data_url = parse_url(uri, url); @@ -111,7 +112,7 @@ impl HTMLObjectElement { Ok(()) } - pub fn GetForm(&self) -> Option> { + pub fn GetForm(&self) -> Option> { None } @@ -131,11 +132,11 @@ impl HTMLObjectElement { Ok(()) } - pub fn GetContentDocument(&self) -> Option> { + pub fn GetContentDocument(&self) -> Option> { None } - pub fn GetContentWindow(&self) -> Option> { + pub fn GetContentWindow(&self) -> Option> { None } @@ -143,11 +144,10 @@ impl HTMLObjectElement { false } - pub fn Validity(&self) -> JS { + pub fn Validity(&self) -> Unrooted { let roots = RootCollection::new(); - let doc = self.htmlelement.element.node.owner_doc(); - let doc = doc.get(); - let window = doc.window.root(&roots); + let doc = self.htmlelement.element.node.owner_doc().root(&roots); + let window = doc.deref().window.root(&roots); ValidityState::new(&window.root_ref()) } @@ -242,25 +242,26 @@ impl HTMLObjectElement { Ok(()) } - pub fn GetSVGDocument(&self) -> Option> { + pub fn GetSVGDocument(&self) -> Option> { None } } -impl VirtualMethods for JS { +impl<'a> VirtualMethods for JSRef<'a, HTMLObjectElement> { fn super_type(&self) -> Option<~VirtualMethods:> { - let htmlelement: JS = HTMLElementCast::from(self); - Some(~htmlelement as ~VirtualMethods:) + let htmlelement: &JSRef = HTMLElementCast::from_ref(self); + Some(~htmlelement.clone() as ~VirtualMethods:) } fn after_set_attr(&mut self, name: DOMString, value: DOMString) { + let roots = RootCollection::new(); match self.super_type() { Some(ref mut s) => s.after_set_attr(name.clone(), value), _ => (), } if "data" == name { - let window = window_from_node(self); + let window = window_from_node(self).root(&roots); let url = Some(window.get().get_url()); self.process_data_url(window.get().image_cache_task.clone(), url); } diff --git a/src/components/script/dom/htmlolistelement.rs b/src/components/script/dom/htmlolistelement.rs index a62acc013c6..1330e2cbd40 100644 --- a/src/components/script/dom/htmlolistelement.rs +++ b/src/components/script/dom/htmlolistelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLOListElementBinding; use dom::bindings::codegen::InheritTypes::HTMLOListElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLOListElementTypeId; @@ -34,7 +34,7 @@ impl HTMLOListElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLOListElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLOListElementBinding::Wrap) } diff --git a/src/components/script/dom/htmloptgroupelement.rs b/src/components/script/dom/htmloptgroupelement.rs index 3ef4df88ab9..d5eab9bec46 100644 --- a/src/components/script/dom/htmloptgroupelement.rs +++ b/src/components/script/dom/htmloptgroupelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLOptGroupElementBinding; use dom::bindings::codegen::InheritTypes::HTMLOptGroupElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLOptGroupElementTypeId; @@ -34,7 +34,7 @@ impl HTMLOptGroupElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLOptGroupElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLOptGroupElementBinding::Wrap) } diff --git a/src/components/script/dom/htmloptionelement.rs b/src/components/script/dom/htmloptionelement.rs index 5119ce17b73..bf1f594009e 100644 --- a/src/components/script/dom/htmloptionelement.rs +++ b/src/components/script/dom/htmloptionelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLOptionElementBinding; use dom::bindings::codegen::InheritTypes::HTMLOptionElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLOptionElementTypeId; @@ -35,7 +35,7 @@ impl HTMLOptionElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLOptionElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLOptionElementBinding::Wrap) } @@ -50,7 +50,7 @@ impl HTMLOptionElement { Ok(()) } - pub fn GetForm(&self) -> Option> { + pub fn GetForm(&self) -> Option> { None } diff --git a/src/components/script/dom/htmloutputelement.rs b/src/components/script/dom/htmloutputelement.rs index 4f5dae6d8c0..a72d9410d20 100644 --- a/src/components/script/dom/htmloutputelement.rs +++ b/src/components/script/dom/htmloutputelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLOutputElementBinding; use dom::bindings::codegen::InheritTypes::HTMLOutputElementDerived; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLOutputElementTypeId; @@ -36,14 +36,14 @@ impl HTMLOutputElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLOutputElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLOutputElementBinding::Wrap) } } impl HTMLOutputElement { - pub fn GetForm(&self) -> Option> { + pub fn GetForm(&self) -> Option> { None } @@ -82,12 +82,11 @@ impl HTMLOutputElement { pub fn SetWillValidate(&mut self, _will_validate: bool) { } - pub fn Validity(&self) -> JS { + pub fn Validity(&self) -> Unrooted { let roots = RootCollection::new(); - let doc = self.htmlelement.element.node.owner_doc(); - let doc = doc.get(); - let window = doc.window.root(&roots); - ValidityState::new(&window.root_ref()) + let doc = self.htmlelement.element.node.owner_doc().root(&roots); + let window = doc.deref().window.root(&roots); + ValidityState::new(&*window) } pub fn SetValidity(&mut self, _validity: JS) { diff --git a/src/components/script/dom/htmlparagraphelement.rs b/src/components/script/dom/htmlparagraphelement.rs index b473a81613e..d5dafd6abda 100644 --- a/src/components/script/dom/htmlparagraphelement.rs +++ b/src/components/script/dom/htmlparagraphelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLParagraphElementBinding; use dom::bindings::codegen::InheritTypes::HTMLParagraphElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLParagraphElementTypeId; @@ -34,7 +34,7 @@ impl HTMLParagraphElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLParagraphElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLParagraphElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlparamelement.rs b/src/components/script/dom/htmlparamelement.rs index c33b68fc932..db4d9ec1b89 100644 --- a/src/components/script/dom/htmlparamelement.rs +++ b/src/components/script/dom/htmlparamelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLParamElementBinding; use dom::bindings::codegen::InheritTypes::HTMLParamElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLParamElementTypeId; @@ -34,7 +34,7 @@ impl HTMLParamElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLParamElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLParamElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlpreelement.rs b/src/components/script/dom/htmlpreelement.rs index cfbc2ddc3fe..e2c404074bd 100644 --- a/src/components/script/dom/htmlpreelement.rs +++ b/src/components/script/dom/htmlpreelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLPreElementBinding; use dom::bindings::codegen::InheritTypes::HTMLPreElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLPreElementTypeId; @@ -34,7 +34,7 @@ impl HTMLPreElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLPreElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLPreElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlprogresselement.rs b/src/components/script/dom/htmlprogresselement.rs index ec76ab7d41d..024025afa6d 100644 --- a/src/components/script/dom/htmlprogresselement.rs +++ b/src/components/script/dom/htmlprogresselement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLProgressElementBinding; use dom::bindings::codegen::InheritTypes::HTMLProgressElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::{ErrorResult, Fallible}; use dom::document::Document; use dom::element::HTMLProgressElementTypeId; @@ -34,7 +34,7 @@ impl HTMLProgressElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLProgressElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLProgressElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlquoteelement.rs b/src/components/script/dom/htmlquoteelement.rs index 0ec36d39711..9c67c2ac2f4 100644 --- a/src/components/script/dom/htmlquoteelement.rs +++ b/src/components/script/dom/htmlquoteelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLQuoteElementBinding; use dom::bindings::codegen::InheritTypes::HTMLQuoteElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLQuoteElementTypeId; @@ -34,7 +34,7 @@ impl HTMLQuoteElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLQuoteElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLQuoteElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlscriptelement.rs b/src/components/script/dom/htmlscriptelement.rs index 3be3739542a..808b05a12cf 100644 --- a/src/components/script/dom/htmlscriptelement.rs +++ b/src/components/script/dom/htmlscriptelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLScriptElementBinding; use dom::bindings::codegen::InheritTypes::HTMLScriptElementDerived; use dom::bindings::codegen::InheritTypes::ElementCast; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{HTMLScriptElementTypeId, Element, AttributeHandlers}; @@ -35,7 +35,7 @@ impl HTMLScriptElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLScriptElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLScriptElementBinding::Wrap) } @@ -43,7 +43,7 @@ impl HTMLScriptElement { impl HTMLScriptElement { pub fn Src(&self, abstract_self: &JSRef) -> DOMString { - let element: JS = ElementCast::from(&abstract_self.unrooted()); + let element: &JSRef = ElementCast::from_ref(abstract_self); element.get_url_attribute("src") } diff --git a/src/components/script/dom/htmlselectelement.rs b/src/components/script/dom/htmlselectelement.rs index 53a738e1a97..666cb529774 100644 --- a/src/components/script/dom/htmlselectelement.rs +++ b/src/components/script/dom/htmlselectelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLSelectElementBinding; use dom::bindings::codegen::InheritTypes::HTMLSelectElementDerived; use dom::bindings::codegen::UnionTypes::{HTMLElementOrLong, HTMLOptionElementOrHTMLOptGroupElement}; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLSelectElementTypeId}; @@ -38,7 +38,7 @@ impl HTMLSelectElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLSelectElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLSelectElementBinding::Wrap) } @@ -61,7 +61,7 @@ impl HTMLSelectElement { Ok(()) } - pub fn GetForm(&self) -> Option> { + pub fn GetForm(&self) -> Option> { None } @@ -109,15 +109,15 @@ impl HTMLSelectElement { Ok(()) } - pub fn Item(&self, _index: u32) -> Option> { + pub fn Item(&self, _index: u32) -> Option> { None } - pub fn NamedItem(&self, _name: DOMString) -> Option> { + pub fn NamedItem(&self, _name: DOMString) -> Option> { None } - pub fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option> { + pub fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option> { None } @@ -153,12 +153,11 @@ impl HTMLSelectElement { pub fn SetWillValidate(&mut self, _will_validate: bool) { } - pub fn Validity(&self) -> JS { + pub fn Validity(&self) -> Unrooted { let roots = RootCollection::new(); - let doc = self.htmlelement.element.node.owner_doc(); - let doc = doc.get(); - let window = doc.window.root(&roots); - ValidityState::new(&window.root_ref()) + let doc = self.htmlelement.element.node.owner_doc().root(&roots); + let window = doc.deref().window.root(&roots); + ValidityState::new(&*window) } pub fn SetValidity(&mut self, _validity: JS) { diff --git a/src/components/script/dom/htmlserializer.rs b/src/components/script/dom/htmlserializer.rs index e99982822ed..55c1ba03d9e 100644 --- a/src/components/script/dom/htmlserializer.rs +++ b/src/components/script/dom/htmlserializer.rs @@ -4,15 +4,15 @@ use servo_util::namespace; use dom::attr::Attr; -use dom::bindings::codegen::InheritTypes::{ElementCast, TextCast, CommentCast}; +use dom::bindings::codegen::InheritTypes::{ElementCast, TextCast, CommentCast, NodeCast}; use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, CharacterDataCast}; use dom::bindings::codegen::InheritTypes::ProcessingInstructionCast; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JSRef, RootCollection}; use dom::characterdata::CharacterData; use dom::comment::Comment; use dom::documenttype::DocumentType; use dom::element::Element; -use dom::node::NodeIterator; +use dom::node::{Node, NodeIterator}; use dom::node::{DoctypeNodeTypeId, DocumentFragmentNodeTypeId, CommentNodeTypeId}; use dom::node::{DocumentNodeTypeId, ElementNodeTypeId, ProcessingInstructionNodeTypeId}; use dom::node::{TextNodeTypeId, NodeHelpers}; @@ -20,7 +20,6 @@ use dom::processinginstruction::ProcessingInstruction; use dom::text::Text; pub fn serialize(iterator: &mut NodeIterator) -> ~str { - let roots = RootCollection::new(); let mut html = ~""; let mut open_elements: Vec<~str> = vec!(); @@ -31,29 +30,25 @@ pub fn serialize(iterator: &mut NodeIterator) -> ~str { html.push_str( match node.type_id() { ElementNodeTypeId(..) => { - let elem: JS = ElementCast::to(&node).unwrap(); - let elem = elem.root(&roots); - serialize_elem(&elem.root_ref(), &mut open_elements) + let elem: &JSRef = ElementCast::to_ref(&node).unwrap(); + serialize_elem(elem, &mut open_elements) } CommentNodeTypeId => { - let comment: JS = CommentCast::to(&node).unwrap(); - let comment = comment.root(&roots); - serialize_comment(&comment.root_ref()) + let comment: &JSRef = CommentCast::to_ref(&node).unwrap(); + serialize_comment(comment) } TextNodeTypeId => { - let text: JS = TextCast::to(&node).unwrap(); - let text = text.root(&roots); - serialize_text(&text.root_ref()) + let text: &JSRef = TextCast::to_ref(&node).unwrap(); + serialize_text(text) } DoctypeNodeTypeId => { - let doctype: JS = DocumentTypeCast::to(&node).unwrap(); - let doctype = doctype.root(&roots); - serialize_doctype(&doctype.root_ref()) + let doctype: &JSRef = DocumentTypeCast::to_ref(&node).unwrap(); + serialize_doctype(doctype) } ProcessingInstructionNodeTypeId => { - let processing_instruction: JS = ProcessingInstructionCast::to(&node).unwrap(); - let processing_instruction = processing_instruction.root(&roots); - serialize_processing_instruction(&processing_instruction.root_ref()) + let processing_instruction: &JSRef = + ProcessingInstructionCast::to_ref(&node).unwrap(); + serialize_processing_instruction(processing_instruction) } DocumentFragmentNodeTypeId => { ~"" @@ -75,9 +70,11 @@ fn serialize_comment(comment: &JSRef) -> ~str { } fn serialize_text(text: &JSRef) -> ~str { - match text.get().characterdata.node.parent_node { + let roots = RootCollection::new(); + let text_node: &JSRef = NodeCast::from_ref(text); + match text_node.parent_node().map(|node| node.root(&roots)) { Some(ref parent) if parent.is_element() => { - let elem: JS = ElementCast::to(parent).unwrap(); + let elem: &JSRef = ElementCast::to_ref(&**parent).unwrap(); match elem.get().local_name.as_slice() { "style" | "script" | "xmp" | "iframe" | "noembed" | "noframes" | "plaintext" | @@ -104,14 +101,15 @@ fn serialize_elem(elem: &JSRef, open_elements: &mut Vec<~str>) -> ~str let mut rv = ~"<" + elem.get().local_name; for attr in elem.get().attrs.iter() { let attr = attr.root(&roots); - rv.push_str(serialize_attr(&attr.root_ref())); + rv.push_str(serialize_attr(&*attr)); }; rv.push_str(">"); match elem.get().local_name.as_slice() { "pre" | "listing" | "textarea" if elem.get().namespace == namespace::HTML => { - match elem.get().node.first_child { + let node: &JSRef = NodeCast::from_ref(elem); + match node.first_child().map(|child| child.root(&roots)) { Some(ref child) if child.is_text() => { - let text: JS = CharacterDataCast::to(child).unwrap(); + let text: &JSRef = CharacterDataCast::to_ref(&**child).unwrap(); if text.get().data.len() > 0 && text.get().data[0] == 0x0A as u8 { rv.push_str("\x0A"); } diff --git a/src/components/script/dom/htmlsourceelement.rs b/src/components/script/dom/htmlsourceelement.rs index 8db513bfbd2..ef7ec5c9108 100644 --- a/src/components/script/dom/htmlsourceelement.rs +++ b/src/components/script/dom/htmlsourceelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLSourceElementBinding; use dom::bindings::codegen::InheritTypes::HTMLSourceElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLSourceElementTypeId; @@ -34,7 +34,7 @@ impl HTMLSourceElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLSourceElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLSourceElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlspanelement.rs b/src/components/script/dom/htmlspanelement.rs index 20e95ae4b8d..3867fa591de 100644 --- a/src/components/script/dom/htmlspanelement.rs +++ b/src/components/script/dom/htmlspanelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLSpanElementBinding; use dom::bindings::codegen::InheritTypes::HTMLSpanElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::document::Document; use dom::element::HTMLSpanElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,7 +33,7 @@ impl HTMLSpanElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLSpanElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLSpanElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlstyleelement.rs b/src/components/script/dom/htmlstyleelement.rs index be43a40f27d..ec2a997586b 100644 --- a/src/components/script/dom/htmlstyleelement.rs +++ b/src/components/script/dom/htmlstyleelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLStyleElementBinding; use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLStyleElementDerived, NodeCast}; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLStyleElementTypeId; @@ -37,7 +37,7 @@ impl HTMLStyleElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLStyleElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLStyleElementBinding::Wrap) } @@ -80,28 +80,27 @@ pub trait StyleElementHelpers { fn parse_own_css(&self); } -impl StyleElementHelpers for JS { +impl<'a> StyleElementHelpers for JSRef<'a, HTMLStyleElement> { fn parse_own_css(&self) { let roots = RootCollection::new(); - let node: JS = NodeCast::from(self); - let node_root = node.root(&roots); - let win = window_from_node(&node); + let node: &JSRef = NodeCast::from_ref(self); + let win = window_from_node(node).root(&roots); let url = win.get().page().get_url(); - let data = node.get().GetTextContent(&node_root.root_ref()).expect("Element.textContent must be a string"); + let data = node.get().GetTextContent(node).expect("Element.textContent must be a string"); let sheet = parse_inline_css(url, data); let LayoutChan(ref layout_chan) = *win.get().page().layout_chan; layout_chan.send(AddStylesheetMsg(sheet)); } } -impl VirtualMethods for JS { +impl<'a> VirtualMethods for JSRef<'a, HTMLStyleElement> { fn super_type(&self) -> Option<~VirtualMethods:> { - let htmlelement: JS = HTMLElementCast::from(self); - Some(~htmlelement as ~VirtualMethods:) + let htmlelement: &JSRef = HTMLElementCast::from_ref(self); + Some(~htmlelement.clone() as ~VirtualMethods:) } - fn child_inserted(&mut self, child: &JS) { + fn child_inserted(&mut self, child: &JSRef) { match self.super_type() { Some(ref mut s) => s.child_inserted(child), _ => (), diff --git a/src/components/script/dom/htmltablecaptionelement.rs b/src/components/script/dom/htmltablecaptionelement.rs index 6aa88d6c05a..ba83cd93ae8 100644 --- a/src/components/script/dom/htmltablecaptionelement.rs +++ b/src/components/script/dom/htmltablecaptionelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableCaptionElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableCaptionElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableCaptionElementTypeId; @@ -34,7 +34,7 @@ impl HTMLTableCaptionElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLTableCaptionElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableCaptionElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltablecolelement.rs b/src/components/script/dom/htmltablecolelement.rs index cc967f14c49..c8b8c74ad6b 100644 --- a/src/components/script/dom/htmltablecolelement.rs +++ b/src/components/script/dom/htmltablecolelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableColElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableColElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableColElementTypeId; @@ -34,7 +34,7 @@ impl HTMLTableColElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLTableColElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableColElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltabledatacellelement.rs b/src/components/script/dom/htmltabledatacellelement.rs index 7a6185d6ec2..830740127f0 100644 --- a/src/components/script/dom/htmltabledatacellelement.rs +++ b/src/components/script/dom/htmltabledatacellelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableDataCellElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableDataCellElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::document::Document; use dom::element::HTMLTableDataCellElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,7 +33,7 @@ impl HTMLTableDataCellElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLTableDataCellElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableDataCellElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltableelement.rs b/src/components/script/dom/htmltableelement.rs index 20948ff1d67..8150c68d3a6 100644 --- a/src/components/script/dom/htmltableelement.rs +++ b/src/components/script/dom/htmltableelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableElementTypeId; @@ -34,7 +34,7 @@ impl HTMLTableElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLTableElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltableheadercellelement.rs b/src/components/script/dom/htmltableheadercellelement.rs index 47057fd0fa2..90dba152b44 100644 --- a/src/components/script/dom/htmltableheadercellelement.rs +++ b/src/components/script/dom/htmltableheadercellelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableHeaderCellElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableHeaderCellElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::document::Document; use dom::element::HTMLTableHeaderCellElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,7 +33,7 @@ impl HTMLTableHeaderCellElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLTableHeaderCellElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableHeaderCellElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltablerowelement.rs b/src/components/script/dom/htmltablerowelement.rs index 1256dbfdabc..2b77faeadab 100644 --- a/src/components/script/dom/htmltablerowelement.rs +++ b/src/components/script/dom/htmltablerowelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableRowElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableRowElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableRowElementTypeId; @@ -34,7 +34,7 @@ impl HTMLTableRowElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLTableRowElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableRowElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltablesectionelement.rs b/src/components/script/dom/htmltablesectionelement.rs index 3689bba1f48..b44aba6e9dc 100644 --- a/src/components/script/dom/htmltablesectionelement.rs +++ b/src/components/script/dom/htmltablesectionelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableSectionElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableSectionElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableSectionElementTypeId; @@ -34,7 +34,7 @@ impl HTMLTableSectionElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLTableSectionElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableSectionElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltemplateelement.rs b/src/components/script/dom/htmltemplateelement.rs index 9880dc0b34d..f645e1815d3 100644 --- a/src/components/script/dom/htmltemplateelement.rs +++ b/src/components/script/dom/htmltemplateelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTemplateElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTemplateElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::document::Document; use dom::element::HTMLTemplateElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,7 +33,7 @@ impl HTMLTemplateElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLTemplateElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTemplateElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltextareaelement.rs b/src/components/script/dom/htmltextareaelement.rs index 4f4c7b55c9d..4955085c751 100644 --- a/src/components/script/dom/htmltextareaelement.rs +++ b/src/components/script/dom/htmltextareaelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTextAreaElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTextAreaElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::{ErrorResult, Fallible}; use dom::document::Document; use dom::element::HTMLTextAreaElementTypeId; @@ -34,7 +34,7 @@ impl HTMLTextAreaElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLTextAreaElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTextAreaElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltimeelement.rs b/src/components/script/dom/htmltimeelement.rs index 938a1013876..df74323fc01 100644 --- a/src/components/script/dom/htmltimeelement.rs +++ b/src/components/script/dom/htmltimeelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTimeElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTimeElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTimeElementTypeId; @@ -34,7 +34,7 @@ impl HTMLTimeElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLTimeElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTimeElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltitleelement.rs b/src/components/script/dom/htmltitleelement.rs index 3fe46fe1b81..2c1af9b5291 100644 --- a/src/components/script/dom/htmltitleelement.rs +++ b/src/components/script/dom/htmltitleelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTitleElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTitleElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTitleElementTypeId; @@ -34,7 +34,7 @@ impl HTMLTitleElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLTitleElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTitleElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltrackelement.rs b/src/components/script/dom/htmltrackelement.rs index 19a58090dcf..408da82d53b 100644 --- a/src/components/script/dom/htmltrackelement.rs +++ b/src/components/script/dom/htmltrackelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTrackElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTrackElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTrackElementTypeId; @@ -34,7 +34,7 @@ impl HTMLTrackElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLTrackElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTrackElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlulistelement.rs b/src/components/script/dom/htmlulistelement.rs index 1fe1be79af1..c2661a5ee46 100644 --- a/src/components/script/dom/htmlulistelement.rs +++ b/src/components/script/dom/htmlulistelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLUListElementBinding; use dom::bindings::codegen::InheritTypes::HTMLUListElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLUListElementTypeId; @@ -34,7 +34,7 @@ impl HTMLUListElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLUListElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLUListElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlunknownelement.rs b/src/components/script/dom/htmlunknownelement.rs index aa472bb04fc..da68e0c51bf 100644 --- a/src/components/script/dom/htmlunknownelement.rs +++ b/src/components/script/dom/htmlunknownelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLUnknownElementBinding; use dom::bindings::codegen::InheritTypes::HTMLUnknownElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::document::Document; use dom::element::HTMLUnknownElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,7 +33,7 @@ impl HTMLUnknownElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLUnknownElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLUnknownElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlvideoelement.rs b/src/components/script/dom/htmlvideoelement.rs index 3587ab4931a..aba9c3c3436 100644 --- a/src/components/script/dom/htmlvideoelement.rs +++ b/src/components/script/dom/htmlvideoelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLVideoElementBinding; use dom::bindings::codegen::InheritTypes::HTMLVideoElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLVideoElementTypeId; @@ -34,7 +34,7 @@ impl HTMLVideoElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> JS { + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { let element = HTMLVideoElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLVideoElementBinding::Wrap) } diff --git a/src/components/script/dom/location.rs b/src/components/script/dom/location.rs index fa0aaf103d7..762da0a383b 100644 --- a/src/components/script/dom/location.rs +++ b/src/components/script/dom/location.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::LocationBinding; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JSRef, Unrooted}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::Fallible; use dom::window::Window; @@ -29,7 +29,7 @@ impl Location { } } - pub fn new(window: &JSRef, page: Rc) -> JS { + pub fn new(window: &JSRef, page: Rc) -> Unrooted { reflect_dom_object(~Location::new_inherited(page), window, LocationBinding::Wrap) diff --git a/src/components/script/dom/mouseevent.rs b/src/components/script/dom/mouseevent.rs index a1f08aa72e0..b771b1b091c 100644 --- a/src/components/script/dom/mouseevent.rs +++ b/src/components/script/dom/mouseevent.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::MouseEventBinding; use dom::bindings::codegen::InheritTypes::MouseEventDerived; -use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference}; +use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Unrooted}; use dom::bindings::error::Fallible; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::event::{Event, MouseEventTypeId}; @@ -51,7 +51,7 @@ impl MouseEvent { } } - pub fn new(window: &JSRef) -> JS { + pub fn new(window: &JSRef) -> Unrooted { reflect_dom_object(~MouseEvent::new_inherited(), window, MouseEventBinding::Wrap) @@ -59,9 +59,9 @@ impl MouseEvent { pub fn Constructor(owner: &JSRef, type_: DOMString, - init: &MouseEventBinding::MouseEventInit) -> Fallible> { + init: &MouseEventBinding::MouseEventInit) -> Fallible> { let roots = RootCollection::new(); - let mut ev = MouseEvent::new(owner); + let mut ev = MouseEvent::new(owner).root(&roots); let view = init.view.as_ref().map(|view| view.root(&roots)); let related_target = init.relatedTarget.as_ref().map(|relatedTarget| relatedTarget.root(&roots)); ev.get_mut().InitMouseEvent(type_, init.bubbles, init.cancelable, view.root_ref(), @@ -69,7 +69,7 @@ impl MouseEvent { init.clientX, init.clientY, init.ctrlKey, init.altKey, init.shiftKey, init.metaKey, init.button, related_target.root_ref()); - Ok(ev) + Ok(Unrooted::new_rooted(&*ev)) } pub fn ScreenX(&self) -> i32 { @@ -113,8 +113,8 @@ impl MouseEvent { 0 } - pub fn GetRelatedTarget(&self) -> Option> { - self.related_target.clone() + pub fn GetRelatedTarget(&self) -> Option> { + self.related_target.clone().map(|target| Unrooted::new(target)) } pub fn GetModifierState(&self, _keyArg: DOMString) -> bool { diff --git a/src/components/script/dom/navigator.rs b/src/components/script/dom/navigator.rs index 63779428d94..494175cb6b8 100644 --- a/src/components/script/dom/navigator.rs +++ b/src/components/script/dom/navigator.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::NavigatorBinding; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JSRef, Unrooted}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::Fallible; use dom::window::Window; @@ -21,7 +21,7 @@ impl Navigator { } } - pub fn new(window: &JSRef) -> JS { + pub fn new(window: &JSRef) -> Unrooted { reflect_dom_object(~Navigator::new_inherited(), window, NavigatorBinding::Wrap) diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 4d40d8daeb7..6758efeb65d 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -10,7 +10,9 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, TextCast, NodeCast}; use dom::bindings::codegen::InheritTypes::{CharacterDataCast, NodeBase, NodeDerived}; use dom::bindings::codegen::InheritTypes::{ProcessingInstructionCast, EventTargetCast}; use dom::bindings::codegen::BindingDeclarations::NodeBinding::NodeConstants; -use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference}; +use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Unrooted, Root}; +use dom::bindings::js::{OptionalAssignable, UnrootedPushable, OptionalRootable}; +use dom::bindings::js::ResultRootable; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::{ErrorResult, Fallible, NotFound, HierarchyRequest}; use dom::bindings::utils; @@ -222,30 +224,19 @@ pub enum NodeTypeId { ProcessingInstructionNodeTypeId, } -pub trait INode { - fn AppendChild(&mut self, node: &mut JSRef) -> Fallible>; - fn ReplaceChild(&mut self, node: &mut JSRef, child: &mut JSRef) -> Fallible>; - fn RemoveChild(&mut self, node: &mut JSRef) -> Fallible>; +pub fn AppendChild<'a>(self_: &mut JSRef<'a, Node>, node: &mut JSRef) -> Fallible> { + let mut self_alias = self_.clone(); + self_.get_mut().AppendChild(&mut self_alias, node) } -impl INode for JS { - fn AppendChild(&mut self, node: &mut JSRef) -> Fallible> { - let roots = RootCollection::new(); - let self_node = self.root(&roots); - self.get_mut().AppendChild(&mut self_node.root_ref(), node) - } +pub fn ReplaceChild<'a>(self_: &mut JSRef<'a, Node>, node: &mut JSRef, child: &mut JSRef) -> Fallible> { + let mut self_alias = self_.clone(); + self_.get_mut().ReplaceChild(&mut self_alias, node, child) +} - fn ReplaceChild(&mut self, node: &mut JSRef, child: &mut JSRef) -> Fallible> { - let roots = RootCollection::new(); - let self_node = self.root(&roots); - self.get_mut().ReplaceChild(&mut self_node.root_ref(), node, child) - } - - fn RemoveChild(&mut self, node: &mut JSRef) -> Fallible> { - let roots = RootCollection::new(); - let self_node = self.root(&roots); - self.get_mut().RemoveChild(&mut self_node.root_ref(), node) - } +pub fn RemoveChild<'a>(self_: &mut JSRef<'a, Node>, node: &mut JSRef) -> Fallible> { + let mut self_alias = self_.clone(); + self_.get_mut().RemoveChild(&mut self_alias, node) } pub trait NodeHelpers { @@ -259,11 +250,11 @@ pub trait NodeHelpers { fn type_id(&self) -> NodeTypeId; - fn parent_node(&self) -> Option>; - fn first_child(&self) -> Option>; - fn last_child(&self) -> Option>; - fn prev_sibling(&self) -> Option>; - fn next_sibling(&self) -> Option>; + fn parent_node(&self) -> Option>; + fn first_child(&self) -> Option>; + fn last_child(&self) -> Option>; + fn prev_sibling(&self) -> Option>; + fn next_sibling(&self) -> Option>; fn is_element(&self) -> bool; fn is_document(&self) -> bool; @@ -283,18 +274,17 @@ pub trait NodeHelpers { fn dump_indent(&self, indent: uint); fn debug_str(&self) -> ~str; - fn traverse_preorder(&self) -> TreeIterator; - fn sequential_traverse_postorder(&self) -> TreeIterator; + fn traverse_preorder<'a>(&self, roots: &'a RootCollection) -> TreeIterator<'a>; + fn sequential_traverse_postorder<'a>(&self, roots: &'a RootCollection) -> TreeIterator<'a>; fn inclusively_following_siblings(&self) -> AbstractNodeChildrenIterator; - fn from_untrusted_node_address(runtime: *JSRuntime, candidate: UntrustedNodeAddress) -> Self; fn to_trusted_node_address(&self) -> TrustedNodeAddress; fn get_bounding_content_box(&self) -> Rect; fn get_content_boxes(&self) -> Vec>; } -impl NodeHelpers for JS { +impl<'a> NodeHelpers for JSRef<'a, Node> { /// Dumps the subtree rooted at this node, for debugging. fn dump(&self) { self.dump_indent(0); @@ -343,26 +333,26 @@ impl NodeHelpers for JS { self.get().type_id } - fn parent_node(&self) -> Option> { - self.get().parent_node.clone() + fn parent_node(&self) -> Option> { + self.get().parent_node.clone().map(|node| Unrooted::new(node)) } - fn first_child(&self) -> Option> { - self.get().first_child.clone() + fn first_child(&self) -> Option> { + self.get().first_child.clone().map(|node| Unrooted::new(node)) } - fn last_child(&self) -> Option> { - self.get().last_child.clone() + fn last_child(&self) -> Option> { + self.get().last_child.clone().map(|node| Unrooted::new(node)) } /// Returns the previous sibling of this node. Fails if this node is borrowed mutably. - fn prev_sibling(&self) -> Option> { - self.get().prev_sibling.clone() + fn prev_sibling(&self) -> Option> { + self.get().prev_sibling.clone().map(|node| Unrooted::new(node)) } /// Returns the next sibling of this node. Fails if this node is borrowed mutably. - fn next_sibling(&self) -> Option> { - self.get().next_sibling.clone() + fn next_sibling(&self) -> Option> { + self.get().next_sibling.clone().map(|node| Unrooted::new(node)) } #[inline] @@ -388,10 +378,7 @@ impl NodeHelpers for JS { #[inline] fn is_doctype(&self) -> bool { - match self.type_id() { - DoctypeNodeTypeId => true, - _ => false - } + self.get().is_doctype() } #[inline] @@ -406,25 +393,28 @@ impl NodeHelpers for JS { // http://dom.spec.whatwg.org/#node-is-inserted fn node_inserted(&self) { + let roots = RootCollection::new(); assert!(self.parent_node().is_some()); - let document = document_from_node(self); + let document = document_from_node(self).root(&roots); if self.is_in_doc() { - for node in self.traverse_preorder() { + for node in self.traverse_preorder(&roots) { vtable_for(&node).bind_to_tree(); } } - self.parent_node().map(|parent| vtable_for(&parent).child_inserted(self)); + self.parent_node().root(&roots) + .map(|parent| vtable_for(&*parent).child_inserted(self)); document.get().content_changed(); } // http://dom.spec.whatwg.org/#node-is-removed fn node_removed(&self) { + let roots = RootCollection::new(); assert!(self.parent_node().is_none()); - let document = document_from_node(self); + let document = document_from_node(self).root(&roots); - for node in self.traverse_preorder() { + for node in self.traverse_preorder(&roots) { // XXX how about if the node wasn't in the tree in the first place? vtable_for(&node).unbind_from_tree(); } @@ -439,49 +429,45 @@ impl NodeHelpers for JS { /// Adds a new child to the end of this node's list of children. /// /// Fails unless `new_child` is disconnected from the tree. - fn add_child(&mut self, new_child_root: &mut JSRef, before: Option>) { + fn add_child(&mut self, new_child: &mut JSRef, mut before: Option>) { let roots = RootCollection::new(); - let mut new_child = new_child_root.unrooted(); assert!(new_child.parent_node().is_none()); assert!(new_child.prev_sibling().is_none()); assert!(new_child.next_sibling().is_none()); match before { - Some(before_root) => { - let mut before = before_root.unrooted(); + Some(ref mut before) => { // XXX Should assert that parent is self. assert!(before.parent_node().is_some()); match before.prev_sibling() { None => { // XXX Should assert that before is the first child of // self. - self.get_mut().set_first_child(Some(new_child_root.clone())); + self.get_mut().set_first_child(Some(new_child.clone())); }, - Some(mut prev_sibling) => { - let prev_sibling_root = prev_sibling.root(&roots); - prev_sibling.get_mut().set_next_sibling(Some(new_child_root.clone())); - new_child.get_mut().set_prev_sibling(Some(prev_sibling_root.root_ref())); + Some(prev_sibling) => { + let mut prev_sibling = prev_sibling.root(&roots); + prev_sibling.get_mut().set_next_sibling(Some(new_child.clone())); + new_child.get_mut().set_prev_sibling(Some((*prev_sibling).clone())); }, } - before.get_mut().set_prev_sibling(Some(new_child_root.clone())); - new_child.get_mut().set_next_sibling(Some(before_root.clone())); + before.get_mut().set_prev_sibling(Some(new_child.clone())); + new_child.get_mut().set_next_sibling(Some(before.clone())); }, None => { - match self.last_child() { - None => self.get_mut().set_first_child(Some(new_child_root.clone())), + match self.last_child().map(|child| child.root(&roots)) { + None => self.get_mut().set_first_child(Some(new_child.clone())), Some(mut last_child) => { - let last_child_root = last_child.root(&roots); assert!(last_child.next_sibling().is_none()); - last_child.get_mut().set_next_sibling(Some(new_child_root.clone())); - new_child.get_mut().set_prev_sibling(Some(last_child_root.root_ref())); + last_child.get_mut().set_next_sibling(Some(new_child.clone())); + new_child.get_mut().set_prev_sibling(Some((*last_child).clone())); } } - self.get_mut().set_last_child(Some(new_child_root.clone())); + self.get_mut().set_last_child(Some(new_child.clone())); }, } - let self_root = self.root(&roots); - new_child.get_mut().set_parent_node(Some(self_root.root_ref())); + new_child.get_mut().set_parent_node(Some(self.clone())); } /// Removes the given child from this node's list of children. @@ -531,69 +517,53 @@ impl NodeHelpers for JS { } /// Iterates over this node and all its descendants, in preorder. - fn traverse_preorder(&self) -> TreeIterator { - let roots = RootCollection::new(); + fn traverse_preorder<'a>(&self, roots: &'a RootCollection) -> TreeIterator<'a> { let mut nodes = vec!(); - let self_root = self.root(&roots); - gather_abstract_nodes(&self_root.root_ref(), &mut nodes, false); + gather_abstract_nodes(self, roots, &mut nodes, false); TreeIterator::new(nodes) } /// Iterates over this node and all its descendants, in postorder. - fn sequential_traverse_postorder(&self) -> TreeIterator { - let roots = RootCollection::new(); + fn sequential_traverse_postorder<'a>(&self, roots: &'a RootCollection) -> TreeIterator<'a> { let mut nodes = vec!(); - let self_root = self.root(&roots); - gather_abstract_nodes(&self_root.root_ref(), &mut nodes, true); + gather_abstract_nodes(self, roots, &mut nodes, true); TreeIterator::new(nodes) } fn inclusively_following_siblings(&self) -> AbstractNodeChildrenIterator { + let roots = RootCollection::new(); AbstractNodeChildrenIterator { - current_node: Some(self.clone()), + current_node: Some((*self.unrooted().root(&roots)).clone()), + roots: roots, } } fn is_inclusive_ancestor_of(&self, parent: &JSRef) -> bool { - let parent = &parent.unrooted(); - self == parent || parent.ancestors().any(|ancestor| ancestor == *self) + self == parent || parent.ancestors().any(|ancestor| &ancestor == self) } fn following_siblings(&self) -> AbstractNodeChildrenIterator { + let roots = RootCollection::new(); AbstractNodeChildrenIterator { - current_node: self.next_sibling(), + current_node: self.next_sibling().map(|node| (*node.root(&roots)).clone()), + roots: roots, } } fn is_parent_of(&self, child: &JSRef) -> bool { - match child.unrooted().parent_node() { - Some(ref parent) if parent == self => true, + match child.parent_node() { + Some(ref parent) if *parent == Unrooted::new_rooted(self) => true, _ => false } } - /// If the given untrusted node address represents a valid DOM node in the given runtime, - /// returns it. - fn from_untrusted_node_address(runtime: *JSRuntime, candidate: UntrustedNodeAddress) - -> JS { - unsafe { - let candidate: uintptr_t = cast::transmute(candidate); - let object: *JSObject = jsfriendapi::bindgen::JS_GetAddressableObject(runtime, - candidate); - if object.is_null() { - fail!("Attempted to create a `JS` from an invalid pointer!") - } - let boxed_node: *mut Node = utils::unwrap(object); - JS::from_raw(boxed_node) - } - } - fn to_trusted_node_address(&self) -> TrustedNodeAddress { TrustedNodeAddress(self.get() as *Node as *libc::c_void) } fn get_bounding_content_box(&self) -> Rect { - let window = window_from_node(self); + let roots = RootCollection::new(); + let window = window_from_node(self).root(&roots); let page = window.get().page(); let (chan, port) = channel(); let addr = self.to_trusted_node_address(); @@ -602,7 +572,8 @@ impl NodeHelpers for JS { } fn get_content_boxes(&self) -> Vec> { - let window = window_from_node(self); + let roots = RootCollection::new(); + let window = window_from_node(self).root(&roots); let page = window.get().page(); let (chan, port) = channel(); let addr = self.to_trusted_node_address(); @@ -611,54 +582,86 @@ impl NodeHelpers for JS { } } +/// If the given untrusted node address represents a valid DOM node in the given runtime, +/// returns it. +pub fn from_untrusted_node_address(runtime: *JSRuntime, candidate: UntrustedNodeAddress) + -> Unrooted { + unsafe { + let candidate: uintptr_t = cast::transmute(candidate); + let object: *JSObject = jsfriendapi::bindgen::JS_GetAddressableObject(runtime, + candidate); + if object.is_null() { + fail!("Attempted to create a `JS` from an invalid pointer!") + } + let boxed_node: *mut Node = utils::unwrap(object); + Unrooted::new(JS::from_raw(boxed_node)) + } +} + +pub trait LayoutNodeHelpers { + fn type_id_for_layout(&self) -> NodeTypeId; +} + +impl LayoutNodeHelpers for JS { + fn type_id_for_layout(&self) -> NodeTypeId { + unsafe { + let node: **Node = cast::transmute::<*JS, + **Node>(self); + (**node).type_id + } + } +} + // // Iteration and traversal // -pub type ChildElementIterator<'a> = Map<'a, JS, - JS, - Filter<'a, JS, AbstractNodeChildrenIterator>>; +pub type ChildElementIterator<'a, 'b> = Map<'a, JSRef<'b, Node>, + JSRef<'b, Element>, + Filter<'a, JSRef<'b, Node>, AbstractNodeChildrenIterator<'b>>>; -pub struct AbstractNodeChildrenIterator { - current_node: Option>, +pub struct AbstractNodeChildrenIterator<'a> { + current_node: Option>, + roots: RootCollection, } -impl Iterator> for AbstractNodeChildrenIterator { - fn next(&mut self) -> Option> { +impl<'a> Iterator> for AbstractNodeChildrenIterator<'a> { + fn next(&mut self) -> Option> { let node = self.current_node.clone(); self.current_node = node.clone().and_then(|node| { - node.next_sibling() + node.next_sibling().map(|node| (*node.root(&self.roots)).clone()) }); node } } -pub struct AncestorIterator { - current: Option>, +pub struct AncestorIterator<'a> { + current: Option>, + roots: RootCollection, } -impl Iterator> for AncestorIterator { - fn next(&mut self) -> Option> { +impl<'a> Iterator> for AncestorIterator<'a> { + fn next(&mut self) -> Option> { if self.current.is_none() { return None; } // FIXME: Do we need two clones here? let x = self.current.get_ref().clone(); - self.current = x.parent_node(); - Some(x.clone()) + self.current = x.parent_node().map(|node| (*node.root(&self.roots)).clone()); + Some(x) } } // FIXME: Do this without precomputing a vector of refs. // Easy for preorder; harder for postorder. -pub struct TreeIterator { - nodes: Vec>, +pub struct TreeIterator<'a> { + nodes: Vec>, index: uint, } -impl TreeIterator { - fn new(nodes: Vec>) -> TreeIterator { +impl<'a> TreeIterator<'a> { + fn new(nodes: Vec>) -> TreeIterator<'a> { TreeIterator { nodes: nodes, index: 0, @@ -666,8 +669,8 @@ impl TreeIterator { } } -impl Iterator> for TreeIterator { - fn next(&mut self) -> Option> { +impl<'a> Iterator> for TreeIterator<'a> { + fn next(&mut self) -> Option> { if self.index >= self.nodes.len() { None } else { @@ -678,7 +681,8 @@ impl Iterator> for TreeIterator { } } -pub struct NodeIterator { +pub struct NodeIterator<'a> { + roots: &'a RootCollection, pub start_node: JS, pub current_node: Option>, pub depth: uint, @@ -686,10 +690,14 @@ pub struct NodeIterator { include_descendants_of_void: bool } -impl NodeIterator { - pub fn new(start_node: JS, include_start: bool, include_descendants_of_void: bool) -> NodeIterator { +impl<'a> NodeIterator<'a> { + pub fn new<'a, 'b>(roots: &'a RootCollection, + start_node: &JSRef<'b, Node>, + include_start: bool, + include_descendants_of_void: bool) -> NodeIterator<'a> { NodeIterator { - start_node: start_node, + roots: roots, + start_node: start_node.unrooted(), current_node: None, depth: 0, include_start: include_start, @@ -697,54 +705,54 @@ impl NodeIterator { } } - fn next_child(&self, node: &JSRef) -> Option> { + fn next_child<'b>(&self, node: &JSRef<'b, Node>) -> Option> { if !self.include_descendants_of_void && node.get().is_element() { - let elem: JS = ElementCast::to(&node.unrooted()).unwrap(); + let elem: &JSRef = ElementCast::to_ref(node).unwrap(); if elem.get().is_void() { None } else { - node.get().first_child.clone() + node.first_child().map(|child| (*child.root(self.roots)).clone()) } } else { - node.get().first_child.clone() + node.first_child().map(|child| (*child.root(self.roots)).clone()) } } } -impl Iterator> for NodeIterator { - fn next(&mut self) -> Option> { - let roots = RootCollection::new(); - self.current_node = match self.current_node { +impl<'a, 'b> Iterator> for NodeIterator<'a> { + fn next(&mut self) -> Option> { + self.current_node = match self.current_node.as_ref().map(|node| node.root(self.roots)) { None => { if self.include_start { Some(self.start_node.clone()) } else { - let start_node = self.start_node.root(&roots); - self.next_child(&start_node.root_ref()) + self.next_child(&*self.start_node.root(self.roots)) + .map(|child| child.unrooted()) } }, - Some(ref node) => { - let node_root = node.root(&roots); - match self.next_child(&node_root.root_ref()) { + Some(node) => { + match self.next_child(&*node) { Some(child) => { self.depth += 1; - Some(child.clone()) + Some(child.unrooted()) }, - None if node == &self.start_node => None, + None if node.deref().unrooted() == self.start_node => None, None => { - match node.next_sibling() { - Some(sibling) => Some(sibling), + match node.deref().next_sibling().root(self.roots) { + Some(sibling) => Some(sibling.deref().unrooted()), None => { - let mut candidate = node.clone(); + let mut candidate = node.deref().clone(); while candidate.next_sibling().is_none() { - candidate = candidate.parent_node().expect("Got to root without reaching start node"); + candidate = (*candidate.parent_node() + .expect("Got to root without reaching start node") + .root(self.roots)).clone(); self.depth -= 1; - if candidate == self.start_node { + if candidate.unrooted() == self.start_node { break; } } - if candidate != self.start_node { - candidate.next_sibling() + if candidate.unrooted() != self.start_node { + candidate.next_sibling().map(|node| node.root(self.roots).unrooted()) } else { None } @@ -754,21 +762,19 @@ impl Iterator> for NodeIterator { } } }; - self.current_node.clone() + self.current_node.clone().map(|node| (*node.root(self.roots)).clone()) } } -fn gather_abstract_nodes(cur: &JSRef, refs: &mut Vec>, postorder: bool) { - let roots = RootCollection::new(); +fn gather_abstract_nodes<'a>(cur: &JSRef, roots: &'a RootCollection, refs: &mut Vec>, postorder: bool) { if !postorder { - refs.push(cur.unrooted()); + refs.push((*cur.unrooted().root(roots)).clone()); } - for kid in cur.unrooted().children() { - let kid = kid.root(&roots); - gather_abstract_nodes(&kid.root_ref(), refs, postorder) + for kid in cur.children() { + gather_abstract_nodes(&kid, roots, refs, postorder) } if postorder { - refs.push(cur.unrooted()); + refs.push((*cur.unrooted().root(roots)).clone()); } } @@ -783,8 +789,10 @@ fn as_uintptr(t: &T) -> uintptr_t { t as *T as uintptr_t } impl Node { pub fn ancestors(&self) -> AncestorIterator { + let roots = RootCollection::new(); AncestorIterator { - current: self.parent_node.clone(), + current: self.parent_node.clone().map(|node| (*node.root(&roots)).clone()), + roots: roots, } } @@ -795,7 +803,18 @@ impl Node { } } - pub fn owner_doc<'a>(&'a self) -> &'a JS { + pub fn is_doctype(&self) -> bool { + match self.type_id { + DoctypeNodeTypeId => true, + _ => false + } + } + + pub fn owner_doc(&self) -> Unrooted { + Unrooted::new(self.owner_doc.get_ref().clone()) + } + + pub fn owner_doc_for_layout<'a>(&'a self) -> &'a JS { self.owner_doc.get_ref() } @@ -804,17 +823,21 @@ impl Node { } pub fn children(&self) -> AbstractNodeChildrenIterator { + let roots = RootCollection::new(); AbstractNodeChildrenIterator { - current_node: self.first_child.clone(), + current_node: self.first_child.clone().map(|node| (*node.root(&roots)).clone()), + roots: roots, } } pub fn child_elements(&self) -> ChildElementIterator { self.children() - .filter(|node| node.is_element()) + .filter(|node| { + node.is_element() + }) .map(|node| { - let elem: JS = ElementCast::to(&node).unwrap(); - elem + let elem: &JSRef = ElementCast::to_ref(&node).unwrap(); + elem.clone() }) } @@ -822,13 +845,13 @@ impl Node { (node: ~N, document: &JSRef, wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~N) -> JS) - -> JS { + -> Unrooted { let roots = RootCollection::new(); assert!(node.reflector().get_jsobject().is_null()); let window = document.get().window.root(&roots); - let node = reflect_dom_object(node, &window.root_ref(), wrap_fn); + let node = reflect_dom_object(node, &window.root_ref(), wrap_fn).root(&roots); assert!(node.reflector().get_jsobject().is_not_null()); - node + Unrooted::new_rooted(&*node) } pub fn new_inherited(type_id: NodeTypeId, doc: JS) -> Node { @@ -919,26 +942,33 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-ownerdocument - pub fn GetOwnerDocument(&self) -> Option> { + pub fn GetOwnerDocument(&self) -> Option> { match self.type_id { ElementNodeTypeId(..) | CommentNodeTypeId | TextNodeTypeId | ProcessingInstructionNodeTypeId | DoctypeNodeTypeId | - DocumentFragmentNodeTypeId => Some(self.owner_doc().clone()), + DocumentFragmentNodeTypeId => Some(self.owner_doc()), DocumentNodeTypeId => None } } // http://dom.spec.whatwg.org/#dom-node-parentnode - pub fn GetParentNode(&self) -> Option> { - self.parent_node.clone() + pub fn GetParentNode(&self) -> Option> { + self.parent_node.clone().map(|node| Unrooted::new(node)) } // http://dom.spec.whatwg.org/#dom-node-parentelement - pub fn GetParentElement(&self) -> Option> { - self.parent_node.clone().and_then(|parent| ElementCast::to(&parent)) + pub fn GetParentElement(&self) -> Option> { + let roots = RootCollection::new(); + self.parent_node.clone() + .and_then(|parent| { + let parent = parent.root(&roots); + ElementCast::to_ref(&*parent).map(|elem| { + Unrooted::new_rooted(elem) + }) + }) } // http://dom.spec.whatwg.org/#dom-node-haschildnodes @@ -947,39 +977,37 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-childnodes - pub fn ChildNodes(&mut self, abstract_self: &JSRef) -> JS { + pub fn ChildNodes(&mut self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); match self.child_list { None => { - let doc = self.owner_doc().clone(); - let doc = doc.get(); - let window = doc.window.root(&roots); - let list = NodeList::new_child_list(&window.root_ref(), abstract_self); - self.child_list = Some(list.clone()); - list + let doc = self.owner_doc().root(&roots); + let window = doc.deref().window.root(&roots); + self.child_list.assign(Some(NodeList::new_child_list(&*window, abstract_self))); + Unrooted::new(self.child_list.get_ref().clone()) } - Some(ref list) => list.clone() + Some(ref list) => Unrooted::new(list.clone()) } } // http://dom.spec.whatwg.org/#dom-node-firstchild - pub fn GetFirstChild(&self) -> Option> { - self.first_child.clone() + pub fn GetFirstChild(&self) -> Option> { + self.first_child.clone().map(|node| Unrooted::new(node)) } // http://dom.spec.whatwg.org/#dom-node-lastchild - pub fn GetLastChild(&self) -> Option> { - self.last_child.clone() + pub fn GetLastChild(&self) -> Option> { + self.last_child.clone().map(|node| Unrooted::new(node)) } // http://dom.spec.whatwg.org/#dom-node-previoussibling - pub fn GetPreviousSibling(&self) -> Option> { - self.prev_sibling.clone() + pub fn GetPreviousSibling(&self) -> Option> { + self.prev_sibling.clone().map(|node| Unrooted::new(node)) } // http://dom.spec.whatwg.org/#dom-node-nextsibling - pub fn GetNextSibling(&self) -> Option> { - self.next_sibling.clone() + pub fn GetNextSibling(&self) -> Option> { + self.next_sibling.clone().map(|node| Unrooted::new(node)) } // http://dom.spec.whatwg.org/#dom-node-nodevalue @@ -1012,13 +1040,14 @@ impl Node { // http://dom.spec.whatwg.org/#dom-node-textcontent pub fn GetTextContent(&self, abstract_self: &JSRef) -> Option { + let roots = RootCollection::new(); match self.type_id { DocumentFragmentNodeTypeId | ElementNodeTypeId(..) => { let mut content = ~""; - for node in abstract_self.unrooted().traverse_preorder() { + for node in abstract_self.traverse_preorder(&roots) { if node.is_text() { - let text: JS = TextCast::to(&node).unwrap(); + let text: &JSRef = TextCast::to_ref(&node).unwrap(); content.push_str(text.get().characterdata.data.as_slice()); } } @@ -1027,7 +1056,7 @@ impl Node { CommentNodeTypeId | TextNodeTypeId | ProcessingInstructionNodeTypeId => { - let characterdata: JS = CharacterDataCast::to(&abstract_self.unrooted()).unwrap(); + let characterdata: &JSRef = CharacterDataCast::to_ref(abstract_self).unwrap(); Some(characterdata.get().Data()) } DoctypeNodeTypeId | @@ -1051,9 +1080,8 @@ impl Node { } else { let document = self.owner_doc(); let document = document.root(&roots); - Some(NodeCast::from(&document.get().CreateTextNode(&document.root_ref(), value))) - }; - let node = node.map(|node| node.root(&roots)); + Some(NodeCast::from_unrooted(document.deref().CreateTextNode(&*document, value))) + }.root(&roots); // Step 3. Node::replace_all(node.root_ref(), abstract_self); @@ -1067,7 +1095,7 @@ impl Node { characterdata.get_mut().data = value.clone(); // Notify the document that the content of this node is different - let document = self.owner_doc(); + let document = self.owner_doc().root(&roots); document.get().content_changed(); } DoctypeNodeTypeId | @@ -1077,21 +1105,20 @@ impl Node { } // http://dom.spec.whatwg.org/#concept-node-adopt - pub fn adopt(node_root: &mut JSRef, document: &JSRef) { + pub fn adopt(node: &mut JSRef, document: &JSRef) { let roots = RootCollection::new(); - let node = node_root.unrooted(); // Step 1. - match node.parent_node() { - Some(ref mut parent) => { - let parent = parent.root(&roots); - Node::remove(node_root, &mut parent.root_ref(), Unsuppressed); + match node.parent_node().root(&roots) { + Some(mut parent) => { + Node::remove(node, &mut *parent, Unsuppressed); } None => (), } // Step 2. - if document_from_node(&node) != document.unrooted() { - for mut descendant in node.traverse_preorder() { + let node_doc = document_from_node(node).root(&roots); + if &*node_doc != document { + for mut descendant in node.traverse_preorder(&roots) { descendant.get_mut().set_owner_doc(document); } } @@ -1101,11 +1128,9 @@ impl Node { } // http://dom.spec.whatwg.org/#concept-node-pre-insert - fn pre_insert(node_root: &mut JSRef, parent_root: &mut JSRef, child: Option>) - -> Fallible> { + fn pre_insert(node: &mut JSRef, parent: &mut JSRef, child: Option>) + -> Fallible> { let roots = RootCollection::new(); - let node = node_root.unrooted(); - let parent = parent_root.unrooted(); // Step 1. match parent.type_id() { DocumentNodeTypeId | @@ -1115,7 +1140,7 @@ impl Node { } // Step 2. - if node.is_inclusive_ancestor_of(parent_root) { + if node.is_inclusive_ancestor_of(parent) { return Err(HierarchyRequest); } @@ -1128,13 +1153,13 @@ impl Node { // Step 4-5. match node.type_id() { TextNodeTypeId => { - match node.parent_node() { + match node.parent_node().root(&roots) { Some(ref parent) if parent.is_document() => return Err(HierarchyRequest), _ => () } } DoctypeNodeTypeId => { - match node.parent_node() { + match node.parent_node().root(&roots) { Some(ref parent) if !parent.is_document() => return Err(HierarchyRequest), _ => () } @@ -1147,7 +1172,6 @@ impl Node { } // Step 6. - let child = child.map(|child| child.unrooted()); match parent.type_id() { DocumentNodeTypeId => { match node.type_id() { @@ -1168,7 +1192,7 @@ impl Node { } match child { Some(ref child) if child.inclusively_following_siblings() - .any(|child| child.is_doctype()) => { + .any(|child| child.deref().is_doctype()) => { return Err(HierarchyRequest); } _ => (), @@ -1187,7 +1211,7 @@ impl Node { } match child { Some(ref child) if child.inclusively_following_siblings() - .any(|child| child.is_doctype()) => { + .any(|child| child.deref().is_doctype()) => { return Err(HierarchyRequest); } _ => (), @@ -1195,14 +1219,14 @@ impl Node { }, // Step 6.3 DoctypeNodeTypeId => { - if parent.children().any(|c| c.is_doctype()) { + if parent.children().any(|c| c.deref().is_doctype()) { return Err(HierarchyRequest); } match child { Some(ref child) => { if parent.children() .take_while(|c| c != child) - .any(|c| c.is_element()) { + .any(|c| c.deref().is_element()) { return Err(HierarchyRequest); } }, @@ -1226,31 +1250,26 @@ impl Node { // Step 7-8. let referenceChild = match child { - Some(ref child) if child == &node => node.next_sibling(), + Some(ref child) if child == node => node.next_sibling().map(|node| (*node.root(&roots)).clone()), _ => child }; - let referenceChild = referenceChild.map(|child| child.root(&roots)); // Step 9. - let document = document_from_node(&parent); - let document = document.root(&roots); - Node::adopt(node_root, &document.root_ref()); + let document = document_from_node(parent).root(&roots); + Node::adopt(node, &*document); // Step 10. - Node::insert(node_root, parent_root, referenceChild.root_ref(), Unsuppressed); + Node::insert(node, parent, referenceChild, Unsuppressed); // Step 11. - return Ok(node) + return Ok(Unrooted::new_rooted(node)) } // http://dom.spec.whatwg.org/#concept-node-insert - fn insert(node_root: &mut JSRef, - parent_root: &mut JSRef, + fn insert(node: &mut JSRef, + parent: &mut JSRef, child: Option>, suppress_observers: SuppressObserver) { - let roots = RootCollection::new(); - let node = node_root.unrooted(); - let mut parent = parent_root.unrooted(); // XXX assert owner_doc // Step 1-3: ranges. // Step 4. @@ -1263,9 +1282,8 @@ impl Node { // Step 6: DocumentFragment. match node.type_id() { DocumentFragmentNodeTypeId => { - for c in node.children() { - let c = c.root(&roots); - Node::remove(&mut c.root_ref(), node_root, Suppressed); + for mut c in node.children() { + Node::remove(&mut c, node, Suppressed); } }, _ => (), @@ -1274,7 +1292,7 @@ impl Node { // Step 7: mutation records. // Step 8. for node in nodes.mut_iter() { - parent.add_child(node_root, child.clone()); + parent.add_child(node, child.clone()); node.get_mut().flags.set_is_in_doc(parent.is_in_doc()); } @@ -1290,23 +1308,20 @@ impl Node { } // http://dom.spec.whatwg.org/#concept-node-replace-all - pub fn replace_all(mut node_root: Option>, parent_root: &mut JSRef) { + pub fn replace_all(mut node: Option>, parent: &mut JSRef) { let roots = RootCollection::new(); - let node = node_root.as_ref().map(|node| node.unrooted()); - let parent = parent_root.unrooted(); // Step 1. - match node_root { + match node { Some(ref mut node) => { - let document = document_from_node(&parent); - let document = document.root(&roots); - Node::adopt(node, &document.root_ref()); + let document = document_from_node(parent).root(&roots); + Node::adopt(node, &*document); } None => (), } // Step 2. - let removedNodes: Vec> = parent.children().collect(); + let removedNodes: Vec> = parent.children().collect(); // Step 3. let addedNodes = match node { @@ -1318,14 +1333,13 @@ impl Node { }; // Step 4. - for child in parent.children() { - let child = child.root(&roots); - Node::remove(&mut child.root_ref(), parent_root, Suppressed); + for mut child in parent.children() { + Node::remove(&mut child, parent, Suppressed); } // Step 5. - match node_root { - Some(ref mut node) => Node::insert(node, parent_root, None, Suppressed), + match node { + Some(ref mut node) => Node::insert(node, parent, None, Suppressed), None => (), } @@ -1341,10 +1355,10 @@ impl Node { } // http://dom.spec.whatwg.org/#concept-node-pre-remove - fn pre_remove(child: &mut JSRef, parent: &mut JSRef) -> Fallible> { + fn pre_remove(child: &mut JSRef, parent: &mut JSRef) -> Fallible> { // Step 1. - match child.unrooted().parent_node() { - Some(ref node) if node != &parent.unrooted() => return Err(NotFound), + match child.parent_node() { + Some(ref node) if *node != Unrooted::new_rooted(parent) => return Err(NotFound), _ => () } @@ -1352,19 +1366,17 @@ impl Node { Node::remove(child, parent, Unsuppressed); // Step 3. - Ok(child.unrooted()) + Ok(Unrooted::new_rooted(child)) } // http://dom.spec.whatwg.org/#concept-node-remove - fn remove(node_root: &mut JSRef, parent: &mut JSRef, suppress_observers: SuppressObserver) { - let mut parent = parent.unrooted(); - let mut node = node_root.unrooted(); - assert!(node.parent_node().map_or(false, |ref node_parent| node_parent == &parent)); + fn remove(node: &mut JSRef, parent: &mut JSRef, suppress_observers: SuppressObserver) { + assert!(node.parent_node().map_or(false, |node_parent| node_parent == Unrooted::new_rooted(parent))); // Step 1-5: ranges. // Step 6-7: mutation observers. // Step 8. - parent.remove_child(node_root); + parent.remove_child(node); node.get_mut().flags.set_is_in_doc(false); // Step 9. @@ -1376,94 +1388,95 @@ impl Node { // http://dom.spec.whatwg.org/#concept-node-clone pub fn clone(node: &JSRef, maybe_doc: Option<&JSRef>, - clone_children: CloneChildrenFlag) -> JS { + clone_children: CloneChildrenFlag) -> Unrooted { let roots = RootCollection::new(); // Step 1. let mut document = match maybe_doc { - Some(doc) => doc.unrooted(), - None => node.get().owner_doc().clone() + Some(doc) => doc.unrooted().root(&roots), + None => node.get().owner_doc().root(&roots) }; - let document_root = document.root(&roots); // Step 2. // XXXabinader: clone() for each node as trait? - let copy: JS = match node.get().type_id { + let mut copy: Root = match node.type_id() { DoctypeNodeTypeId => { - let doctype: JS = DocumentTypeCast::to(&node.unrooted()).unwrap(); + let doctype: &JSRef = DocumentTypeCast::to_ref(node).unwrap(); let doctype = doctype.get(); let doctype = DocumentType::new(doctype.name.clone(), Some(doctype.public_id.clone()), - Some(doctype.system_id.clone()), &document_root.root_ref()); - NodeCast::from(&doctype) + Some(doctype.system_id.clone()), &*document); + NodeCast::from_unrooted(doctype) }, DocumentFragmentNodeTypeId => { - let doc_fragment = DocumentFragment::new(&document_root.root_ref()); - NodeCast::from(&doc_fragment) + let doc_fragment = DocumentFragment::new(&*document); + NodeCast::from_unrooted(doc_fragment) }, CommentNodeTypeId => { - let comment: JS = CommentCast::to(&node.unrooted()).unwrap(); + let comment: &JSRef = CommentCast::to_ref(node).unwrap(); let comment = comment.get(); - let comment = Comment::new(comment.characterdata.data.clone(), &document_root.root_ref()); - NodeCast::from(&comment) + let comment = Comment::new(comment.characterdata.data.clone(), &*document); + NodeCast::from_unrooted(comment) }, DocumentNodeTypeId => { - let document: JS = DocumentCast::to(&node.unrooted()).unwrap(); + let document: &JSRef = DocumentCast::to_ref(node).unwrap(); let document = document.get(); let is_html_doc = match document.is_html_document { true => HTMLDocument, false => NonHTMLDocument }; let window = document.window.root(&roots); - let document = Document::new(&window.root_ref(), Some(document.url().clone()), + let document = Document::new(&*window, Some(document.url().clone()), is_html_doc, None); - NodeCast::from(&document) + NodeCast::from_unrooted(document) }, ElementNodeTypeId(..) => { - let element: JS = ElementCast::to(&node.unrooted()).unwrap(); + let element: &JSRef = ElementCast::to_ref(node).unwrap(); let element = element.get(); - let element = build_element_from_tag(element.local_name.clone(), &document_root.root_ref()); - NodeCast::from(&element) + let element = build_element_from_tag(element.local_name.clone(), &*document); + NodeCast::from_unrooted(element) }, TextNodeTypeId => { - let text: JS = TextCast::to(&node.unrooted()).unwrap(); + let text: &JSRef = TextCast::to_ref(node).unwrap(); let text = text.get(); - let text = Text::new(text.characterdata.data.clone(), &document_root.root_ref()); - NodeCast::from(&text) + let text = Text::new(text.characterdata.data.clone(), &*document); + NodeCast::from_unrooted(text) }, ProcessingInstructionNodeTypeId => { - let pi: JS = ProcessingInstructionCast::to(&node.unrooted()).unwrap(); + let pi: &JSRef = ProcessingInstructionCast::to_ref(node).unwrap(); let pi = pi.get(); let pi = ProcessingInstruction::new(pi.target.clone(), - pi.characterdata.data.clone(), &document_root.root_ref()); - NodeCast::from(&pi) + pi.characterdata.data.clone(), &*document); + NodeCast::from_unrooted(pi) }, - }; + }.root(&roots); // Step 3. - if copy.is_document() { - document = DocumentCast::to(©).unwrap(); - } - let document_root = document.root(&roots); - assert!(copy.get().owner_doc() == &document); + let document = if copy.is_document() { + let doc: &JSRef = DocumentCast::to_ref(&*copy).unwrap(); + doc.unrooted().root(&roots) + } else { + document.unrooted().root(&roots) + }; + assert!(&*copy.get().owner_doc().root(&roots) == &*document); // Step 4 (some data already copied in step 2). match node.get().type_id { DocumentNodeTypeId => { - let node_doc: JS = DocumentCast::to(&node.unrooted()).unwrap(); + let node_doc: &JSRef = DocumentCast::to_ref(node).unwrap(); let node_doc = node_doc.get(); - let mut copy_doc: JS = DocumentCast::to(©).unwrap(); + let copy_doc: &mut JSRef = DocumentCast::to_mut_ref(&mut *copy).unwrap(); let copy_doc = copy_doc.get_mut(); copy_doc.set_encoding_name(node_doc.encoding_name.clone()); copy_doc.set_quirks_mode(node_doc.quirks_mode()); }, ElementNodeTypeId(..) => { - let node_elem: JS = ElementCast::to(&node.unrooted()).unwrap(); + let node_elem: &JSRef = ElementCast::to_ref(node).unwrap(); let node_elem = node_elem.get(); - let mut copy_elem: JS = ElementCast::to(©).unwrap(); + let copy_elem: &mut JSRef = ElementCast::to_mut_ref(&mut *copy).unwrap(); // XXX: to avoid double borrowing compile error. we might be able to fix this after #1854 - let copy_elem_alias: JS = copy_elem.clone(); + let copy_elem_alias = copy_elem.clone(); let copy_elem = copy_elem.get_mut(); // FIXME: https://github.com/mozilla/servo/issues/1737 @@ -1471,10 +1484,11 @@ impl Node { let window = document.get().window.root(&roots); for attr in node_elem.attrs.iter() { let attr = attr.get(); - copy_elem.attrs.push(Attr::new(&window.root_ref(), - attr.local_name.clone(), attr.value.clone(), - attr.name.clone(), attr.namespace.clone(), - attr.prefix.clone(), copy_elem_alias.clone())); + copy_elem.attrs.push_unrooted( + Attr::new(&*window, + attr.local_name.clone(), attr.value.clone(), + attr.name.clone(), attr.namespace.clone(), + attr.prefix.clone(), ©_elem_alias)); } }, _ => () @@ -1485,41 +1499,37 @@ impl Node { // Step 6. if clone_children == CloneChildren { for ref child in node.get().children() { - let child = child.root(&roots); - let child_copy = Node::clone(&child.root_ref(), Some(&document_root.root_ref()), clone_children).root(&roots); - let copy = copy.root(&roots); - let _inserted_node = Node::pre_insert(&mut child_copy.root_ref(), &mut copy.root_ref(), None); + let mut child_copy = Node::clone(&*child, Some(&*document), clone_children).root(&roots); + let _inserted_node = Node::pre_insert(&mut *child_copy, &mut *copy, None); } } // Step 7. - copy + Unrooted::new_rooted(&*copy) } // http://dom.spec.whatwg.org/#dom-node-insertbefore pub fn InsertBefore(&self, abstract_self: &mut JSRef, node: &mut JSRef, child: Option>) - -> Fallible> { + -> Fallible> { Node::pre_insert(node, abstract_self, child) } pub fn wait_until_safe_to_modify_dom(&self) { - let document = self.owner_doc(); + let roots = RootCollection::new(); + let document = self.owner_doc().root(&roots); document.get().wait_until_safe_to_modify_dom(); } // http://dom.spec.whatwg.org/#dom-node-appendchild pub fn AppendChild(&self, abstract_self: &mut JSRef, node: &mut JSRef) - -> Fallible> { + -> Fallible> { Node::pre_insert(node, abstract_self, None) } // http://dom.spec.whatwg.org/#concept-node-replace - pub fn ReplaceChild(&self, parent_root: &mut JSRef, node_root: &mut JSRef, child_root: &mut JSRef) - -> Fallible> { + pub fn ReplaceChild(&self, parent: &mut JSRef, node: &mut JSRef, child: &mut JSRef) + -> Fallible> { let roots = RootCollection::new(); - let parent = parent_root.unrooted(); - let node = node_root.unrooted(); - let child = child_root.unrooted(); // Step 1. match parent.type_id() { @@ -1530,12 +1540,12 @@ impl Node { } // Step 2. - if node.is_inclusive_ancestor_of(parent_root) { + if node.is_inclusive_ancestor_of(parent) { return Err(HierarchyRequest); } // Step 3. - if !parent.is_parent_of(child_root) { + if !parent.is_parent_of(child) { return Err(NotFound); } @@ -1566,11 +1576,11 @@ impl Node { 0 => (), // Step 6.1.2 1 => { - if parent.child_elements().any(|c| NodeCast::from(&c) != child) { + if parent.child_elements().any(|c| NodeCast::from_ref(&c) != child) { return Err(HierarchyRequest); } if child.following_siblings() - .any(|child| child.is_doctype()) { + .any(|child| child.deref().is_doctype()) { return Err(HierarchyRequest); } }, @@ -1580,22 +1590,22 @@ impl Node { }, // Step 6.2 ElementNodeTypeId(..) => { - if parent.child_elements().any(|c| NodeCast::from(&c) != child) { + if parent.child_elements().any(|c| NodeCast::from_ref(&c) != child) { return Err(HierarchyRequest); } if child.following_siblings() - .any(|child| child.is_doctype()) { + .any(|child| child.deref().is_doctype()) { return Err(HierarchyRequest); } }, // Step 6.3 DoctypeNodeTypeId => { - if parent.children().any(|c| c.is_doctype() && c != child) { + if parent.children().any(|c| c.deref().is_doctype() && &c != child) { return Err(HierarchyRequest); } if parent.children() - .take_while(|c| c != &child) - .any(|c| c.is_element()) { + .take_while(|c| c != child) + .any(|c| c.deref().is_element()) { return Err(HierarchyRequest); } }, @@ -1609,29 +1619,27 @@ impl Node { } // Ok if not caught by previous error checks. - if node == child { - return Ok(child); + if node.unrooted() == child.unrooted() { + return Ok(Unrooted::new_rooted(child)); } // Step 7-8. - let next_sibling = child.next_sibling(); + let next_sibling = child.next_sibling().map(|node| (*node.root(&roots)).clone()); let reference_child = match next_sibling { - Some(ref sibling) if sibling == &node => node.next_sibling(), + Some(ref sibling) if sibling == node => node.next_sibling().map(|node| (*node.root(&roots)).clone()), _ => next_sibling }; - let reference_child = reference_child.map(|child| child.root(&roots)); // Step 9. - let document = document_from_node(&parent); - let document = document.root(&roots); - Node::adopt(node_root, &document.root_ref()); + let document = document_from_node(parent).root(&roots); + Node::adopt(node, &*document); { // Step 10. - Node::remove(child_root, parent_root, Suppressed); + Node::remove(child, parent, Suppressed); // Step 11. - Node::insert(node_root, parent_root, reference_child.root_ref(), Suppressed); + Node::insert(node, parent, reference_child, Suppressed); } // Step 12-14. @@ -1646,40 +1654,38 @@ impl Node { } // Step 15. - Ok(child) + Ok(Unrooted::new_rooted(child)) } // http://dom.spec.whatwg.org/#dom-node-removechild pub fn RemoveChild(&self, abstract_self: &mut JSRef, node: &mut JSRef) - -> Fallible> { + -> Fallible> { Node::pre_remove(node, abstract_self) } // http://dom.spec.whatwg.org/#dom-node-normalize pub fn Normalize(&mut self, abstract_self: &mut JSRef) { let roots = RootCollection::new(); - let mut abstract_self = abstract_self.unrooted(); let mut prev_text = None; for mut child in self.children() { if child.is_text() { - let characterdata: JS = CharacterDataCast::to(&child).unwrap(); + let mut child_alias = child.clone(); + let characterdata: &JSRef = CharacterDataCast::to_ref(&child).unwrap(); if characterdata.get().Length() == 0 { - let child = child.root(&roots); - abstract_self.remove_child(&mut child.root_ref()); + abstract_self.remove_child(&mut child_alias); } else { match prev_text { - Some(ref text_node) => { - let mut prev_characterdata: JS = CharacterDataCast::to(text_node).unwrap(); + Some(ref mut text_node) => { + let prev_characterdata: &mut JSRef = CharacterDataCast::to_mut_ref(text_node).unwrap(); let _ = prev_characterdata.get_mut().AppendData(characterdata.get().Data()); - let child = child.root(&roots); - abstract_self.remove_child(&mut child.root_ref()); + abstract_self.remove_child(&mut child_alias); }, - None => prev_text = Some(child) + None => prev_text = Some(child_alias) } } } else { - let c = child.root(&roots); - child.get_mut().Normalize(&mut c.root_ref()); + let mut c = child.clone(); + child.get_mut().Normalize(&mut c); prev_text = None; } @@ -1687,7 +1693,7 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-clonenode - pub fn CloneNode(&self, abstract_self: &mut JSRef, deep: bool) -> JS { + pub fn CloneNode(&self, abstract_self: &mut JSRef, deep: bool) -> Unrooted { match deep { true => Node::clone(abstract_self, None, CloneChildren), false => Node::clone(abstract_self, None, DoNotCloneChildren) @@ -1735,16 +1741,12 @@ impl Node { }) } fn is_equal_node(this: &JSRef, node: &JSRef) -> bool { - let roots = RootCollection::new(); - let this_node = this.unrooted(); - let other = node.unrooted(); - // Step 2. - if this_node.type_id() != other.type_id() { + if this.type_id() != node.type_id() { return false; } - match other.type_id() { + match node.type_id() { // Step 3. DoctypeNodeTypeId if !is_equal_doctype(this, node) => return false, ElementNodeTypeId(..) if !is_equal_element(this, node) => return false, @@ -1757,15 +1759,13 @@ impl Node { } // Step 5. - if this_node.children().len() != other.children().len() { + if this.children().len() != node.children().len() { return false; } // Step 6. - this_node.children().zip(other.children()).all(|(ref child, ref other_child)| { - let child = child.root(&roots); - let other_child = other_child.root(&roots); - is_equal_node(&child.root_ref(), &other_child.root_ref()) + this.children().zip(node.children()).all(|(ref child, ref other_child)| { + is_equal_node(child, other_child) }) } match maybe_node { @@ -1777,9 +1777,8 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-comparedocumentposition - pub fn CompareDocumentPosition(&self, abstract_self_root: &JSRef, other_root: &JSRef) -> u16 { - let other = other_root.unrooted(); - let abstract_self = abstract_self_root.unrooted(); + pub fn CompareDocumentPosition(&self, abstract_self: &JSRef, other: &JSRef) -> u16 { + let roots = RootCollection::new(); if abstract_self == other { // step 2. 0 @@ -1787,25 +1786,25 @@ impl Node { let mut lastself = abstract_self.clone(); let mut lastother = other.clone(); for ancestor in abstract_self.ancestors() { - if ancestor == other { + if &ancestor == other { // step 4. return NodeConstants::DOCUMENT_POSITION_CONTAINS + NodeConstants::DOCUMENT_POSITION_PRECEDING; } - lastself = ancestor; + lastself = ancestor.clone(); } for ancestor in other.ancestors() { - if ancestor == abstract_self { + if &ancestor == abstract_self { // step 5. return NodeConstants::DOCUMENT_POSITION_CONTAINED_BY + NodeConstants::DOCUMENT_POSITION_FOLLOWING; } - lastother = ancestor; + lastother = ancestor.clone(); } if lastself != lastother { - let abstract_uint: uintptr_t = as_uintptr(&abstract_self.get()); - let other_uint: uintptr_t = as_uintptr(&other.get()); + let abstract_uint: uintptr_t = as_uintptr(&*abstract_self); + let other_uint: uintptr_t = as_uintptr(&*other); let random = if abstract_uint < other_uint { NodeConstants::DOCUMENT_POSITION_FOLLOWING @@ -1818,12 +1817,12 @@ impl Node { NodeConstants::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC; } - for child in lastself.traverse_preorder() { - if child == other { + for child in lastself.traverse_preorder(&roots) { + if &child == other { // step 6. return NodeConstants::DOCUMENT_POSITION_PRECEDING; } - if child == abstract_self { + if &child == abstract_self { // step 7. return NodeConstants::DOCUMENT_POSITION_FOLLOWING; } @@ -1836,7 +1835,7 @@ impl Node { pub fn Contains(&self, abstract_self: &JSRef, maybe_other: Option>) -> bool { match maybe_other { None => false, - Some(ref other) => abstract_self.unrooted().is_inclusive_ancestor_of(other) + Some(ref other) => abstract_self.is_inclusive_ancestor_of(other) } } @@ -1863,33 +1862,38 @@ impl Node { // pub fn set_parent_node(&mut self, new_parent_node: Option>) { - let doc = self.owner_doc().clone(); + let roots = RootCollection::new(); + let doc = self.owner_doc().root(&roots); doc.get().wait_until_safe_to_modify_dom(); - self.parent_node = new_parent_node.map(|node| node.unrooted()) + self.parent_node.assign(new_parent_node); } pub fn set_first_child(&mut self, new_first_child: Option>) { - let doc = self.owner_doc().clone(); + let roots = RootCollection::new(); + let doc = self.owner_doc().root(&roots); doc.get().wait_until_safe_to_modify_dom(); - self.first_child = new_first_child.map(|node| node.unrooted()) + self.first_child.assign(new_first_child); } pub fn set_last_child(&mut self, new_last_child: Option>) { - let doc = self.owner_doc().clone(); + let roots = RootCollection::new(); + let doc = self.owner_doc().root(&roots); doc.get().wait_until_safe_to_modify_dom(); - self.last_child = new_last_child.map(|node| node.unrooted()) + self.last_child.assign(new_last_child); } pub fn set_prev_sibling(&mut self, new_prev_sibling: Option>) { - let doc = self.owner_doc().clone(); + let roots = RootCollection::new(); + let doc = self.owner_doc().root(&roots); doc.get().wait_until_safe_to_modify_dom(); - self.prev_sibling = new_prev_sibling.map(|node| node.unrooted()) + self.prev_sibling.assign(new_prev_sibling); } pub fn set_next_sibling(&mut self, new_next_sibling: Option>) { - let doc = self.owner_doc().clone(); + let roots = RootCollection::new(); + let doc = self.owner_doc().root(&roots); doc.get().wait_until_safe_to_modify_dom(); - self.next_sibling = new_next_sibling.map(|node| node.unrooted()) + self.next_sibling.assign(new_next_sibling); } pub fn get_hover_state(&self) -> bool { @@ -1940,19 +1944,20 @@ impl Reflectable for Node { } } -pub fn document_from_node(derived: &JS) -> JS { - let node: JS = NodeCast::from(derived); - node.get().owner_doc().clone() +pub fn document_from_node(derived: &JSRef) -> Unrooted { + let node: &JSRef = NodeCast::from_ref(derived); + node.owner_doc() } -pub fn window_from_node(derived: &JS) -> JS { - let document: JS = document_from_node(derived); - document.get().window.clone() +pub fn window_from_node(derived: &JSRef) -> Unrooted { + let roots = RootCollection::new(); + let document = document_from_node(derived).root(&roots); + Unrooted::new(document.deref().window.clone()) } -impl VirtualMethods for JS { +impl<'a> VirtualMethods for JSRef<'a, Node> { fn super_type(&self) -> Option<~VirtualMethods:> { - let eventtarget: JS = EventTargetCast::from(self); - Some(~eventtarget as ~VirtualMethods:) + let eventtarget: &JSRef = EventTargetCast::from_ref(self); + Some(~eventtarget.clone() as ~VirtualMethods:) } } diff --git a/src/components/script/dom/nodelist.rs b/src/components/script/dom/nodelist.rs index 751c15ab098..219731034f1 100644 --- a/src/components/script/dom/nodelist.rs +++ b/src/components/script/dom/nodelist.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::NodeListBinding; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted, RootCollection}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::node::{Node, NodeHelpers}; use dom::window::Window; @@ -32,35 +32,44 @@ impl NodeList { } pub fn new(window: &JSRef, - list_type: NodeListType) -> JS { + list_type: NodeListType) -> Unrooted { reflect_dom_object(~NodeList::new_inherited(window.unrooted(), list_type), window, NodeListBinding::Wrap) } - pub fn new_simple_list(window: &JSRef, elements: Vec>) -> JS { - NodeList::new(window, Simple(elements)) + pub fn new_simple_list(window: &JSRef, elements: Vec>) -> Unrooted { + NodeList::new(window, Simple(elements.iter().map(|element| element.unrooted()).collect())) } - pub fn new_child_list(window: &JSRef, node: &JSRef) -> JS { + pub fn new_child_list(window: &JSRef, node: &JSRef) -> Unrooted { NodeList::new(window, Children(node.unrooted())) } pub fn Length(&self) -> u32 { + let roots = RootCollection::new(); match self.list_type { Simple(ref elems) => elems.len() as u32, - Children(ref node) => node.children().len() as u32 + Children(ref node) => { + let node = node.root(&roots); + node.deref().children().len() as u32 + } } } - pub fn Item(&self, index: u32) -> Option> { + pub fn Item(&self, index: u32) -> Option> { + let roots = RootCollection::new(); match self.list_type { _ if index >= self.Length() => None, - Simple(ref elems) => Some(elems.get(index as uint).clone()), - Children(ref node) => node.children().nth(index as uint) + Simple(ref elems) => Some(Unrooted::new(elems.get(index as uint).clone())), + Children(ref node) => { + let node = node.root(&roots); + node.deref().children().nth(index as uint) + .map(|child| Unrooted::new_rooted(&child)) + } } } - pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { + pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { let item = self.Item(index); *found = item.is_some(); item diff --git a/src/components/script/dom/processinginstruction.rs b/src/components/script/dom/processinginstruction.rs index 7064f8d3ca7..c094e4ae654 100644 --- a/src/components/script/dom/processinginstruction.rs +++ b/src/components/script/dom/processinginstruction.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::ProcessingInstructionBinding; use dom::bindings::codegen::InheritTypes::ProcessingInstructionDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::characterdata::CharacterData; use dom::document::Document; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -35,7 +35,7 @@ impl ProcessingInstruction { } } - pub fn new(target: DOMString, data: DOMString, document: &JSRef) -> JS { + pub fn new(target: DOMString, data: DOMString, document: &JSRef) -> Unrooted { let node = ProcessingInstruction::new_inherited(target, data, document.unrooted()); Node::reflect_node(~node, document, ProcessingInstructionBinding::Wrap) } diff --git a/src/components/script/dom/testbinding.rs b/src/components/script/dom/testbinding.rs index e05cec800bb..76bb587b134 100644 --- a/src/components/script/dom/testbinding.rs +++ b/src/components/script/dom/testbinding.rs @@ -2,7 +2,7 @@ * 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, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; use dom::bindings::codegen::BindingDeclarations::TestBindingBinding; use dom::bindings::codegen::UnionTypes::HTMLElementOrLong; use self::TestBindingBinding::TestEnum; @@ -51,10 +51,10 @@ impl TestBinding { pub fn SetByteStringAttribute(&self, _: ByteString) {} pub fn EnumAttribute(&self) -> TestEnum { _empty } pub fn SetEnumAttribute(&self, _: TestEnum) {} - pub fn InterfaceAttribute(&self) -> JS { + pub fn InterfaceAttribute(&self) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); - Blob::new(&window.root_ref()) + Blob::new(&*window) } pub fn SetInterfaceAttribute(&self, _: &JSRef) {} pub fn AnyAttribute(&self, _: *JSContext) -> JSVal { NullValue() } @@ -87,10 +87,10 @@ impl TestBinding { pub fn GetStringAttributeNullable(&self) -> Option { Some(~"") } pub fn SetStringAttributeNullable(&self, _: Option) {} pub fn GetEnumAttributeNullable(&self) -> Option { Some(_empty) } - pub fn GetInterfaceAttributeNullable(&self) -> Option> { + pub fn GetInterfaceAttributeNullable(&self) -> Option> { let roots = RootCollection::new(); let window = self.window.root(&roots); - Some(Blob::new(&window.root_ref())) + Some(Blob::new(&(*window))) } pub fn SetInterfaceAttributeNullable(&self, _: Option>) {} diff --git a/src/components/script/dom/text.rs b/src/components/script/dom/text.rs index 61c37d2ad52..cdcfdac6af3 100644 --- a/src/components/script/dom/text.rs +++ b/src/components/script/dom/text.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::TextBinding; use dom::bindings::codegen::InheritTypes::TextDerived; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; use dom::bindings::error::Fallible; use dom::characterdata::CharacterData; use dom::document::Document; @@ -35,19 +35,19 @@ impl Text { } } - pub fn new(text: DOMString, document: &JSRef) -> JS { + pub fn new(text: DOMString, document: &JSRef) -> Unrooted { let node = Text::new_inherited(text, document.unrooted()); Node::reflect_node(~node, document, TextBinding::Wrap) } - pub fn Constructor(owner: &JSRef, text: DOMString) -> Fallible> { + pub fn Constructor(owner: &JSRef, text: DOMString) -> Fallible> { let roots = RootCollection::new(); let document = owner.get().Document(); let document = document.root(&roots); Ok(Text::new(text.clone(), &document.root_ref())) } - pub fn SplitText(&self, _offset: u32) -> Fallible> { + pub fn SplitText(&self, _offset: u32) -> Fallible> { fail!("unimplemented") } diff --git a/src/components/script/dom/uievent.rs b/src/components/script/dom/uievent.rs index 50c97ee8373..f42edeb42bf 100644 --- a/src/components/script/dom/uievent.rs +++ b/src/components/script/dom/uievent.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::UIEventBinding; use dom::bindings::codegen::InheritTypes::UIEventDerived; -use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference}; +use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Unrooted}; use dom::bindings::error::Fallible; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::event::{Event, EventTypeId, UIEventTypeId}; @@ -36,7 +36,7 @@ impl UIEvent { } } - pub fn new(window: &JSRef) -> JS { + pub fn new(window: &JSRef) -> Unrooted { reflect_dom_object(~UIEvent::new_inherited(UIEventTypeId), window, UIEventBinding::Wrap) @@ -44,17 +44,17 @@ impl UIEvent { pub fn Constructor(owner: &JSRef, type_: DOMString, - init: &UIEventBinding::UIEventInit) -> Fallible> { + init: &UIEventBinding::UIEventInit) -> Fallible> { let roots = RootCollection::new(); - let mut ev = UIEvent::new(owner); + let mut ev = UIEvent::new(owner).root(&roots); let view = init.view.as_ref().map(|view| view.root(&roots)); ev.get_mut().InitUIEvent(type_, init.parent.bubbles, init.parent.cancelable, view.root_ref(), init.detail); - Ok(ev) + Ok(Unrooted::new_rooted(&*ev)) } - pub fn GetView(&self) -> Option> { - self.view.clone() + pub fn GetView(&self) -> Option> { + self.view.clone().map(|view| Unrooted::new(view)) } pub fn Detail(&self) -> i32 { @@ -97,7 +97,7 @@ impl UIEvent { 0 } - pub fn GetRangeParent(&self) -> Option> { + pub fn GetRangeParent(&self) -> Option> { //TODO None } diff --git a/src/components/script/dom/validitystate.rs b/src/components/script/dom/validitystate.rs index 9a03134169f..02b0b9a7a11 100644 --- a/src/components/script/dom/validitystate.rs +++ b/src/components/script/dom/validitystate.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::ValidityStateBinding; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::window::Window; @@ -23,7 +23,7 @@ impl ValidityState { } } - pub fn new(window: &JSRef) -> JS { + pub fn new(window: &JSRef) -> Unrooted { reflect_dom_object(~ValidityState::new_inherited(window.unrooted()), window, ValidityStateBinding::Wrap) diff --git a/src/components/script/dom/virtualmethods.rs b/src/components/script/dom/virtualmethods.rs index 85ae37cb032..bf4681fab3b 100644 --- a/src/components/script/dom/virtualmethods.rs +++ b/src/components/script/dom/virtualmethods.rs @@ -8,7 +8,7 @@ use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast; use dom::bindings::codegen::InheritTypes::HTMLImageElementCast; use dom::bindings::codegen::InheritTypes::HTMLObjectElementCast; use dom::bindings::codegen::InheritTypes::HTMLStyleElementCast; -use dom::bindings::js::JS; +use dom::bindings::js::JSRef; use dom::element::Element; use dom::element::{ElementTypeId, HTMLImageElementTypeId}; use dom::element::{HTMLIFrameElementTypeId, HTMLObjectElementTypeId, HTMLStyleElementTypeId}; @@ -62,7 +62,7 @@ pub trait VirtualMethods { } /// Called on the parent when a node is added to its child list. - fn child_inserted(&mut self, child: &JS) { + fn child_inserted(&mut self, child: &JSRef) { match self.super_type() { Some(ref mut s) => s.child_inserted(child), _ => (), @@ -74,31 +74,31 @@ pub trait VirtualMethods { /// method call on the trait object will invoke the corresponding method on the /// concrete type, propagating up the parent hierarchy unless otherwise /// interrupted. -pub fn vtable_for<'a>(node: &JS) -> ~VirtualMethods: { +pub fn vtable_for<'a>(node: &JSRef) -> ~VirtualMethods: { match node.get().type_id { ElementNodeTypeId(HTMLImageElementTypeId) => { - let element: JS = HTMLImageElementCast::to(node).unwrap(); - ~element as ~VirtualMethods: + let element: &JSRef = HTMLImageElementCast::to_ref(node).unwrap(); + ~element.clone() as ~VirtualMethods: } ElementNodeTypeId(HTMLIFrameElementTypeId) => { - let element: JS = HTMLIFrameElementCast::to(node).unwrap(); - ~element as ~VirtualMethods: + let element: &JSRef = HTMLIFrameElementCast::to_ref(node).unwrap(); + ~element.clone() as ~VirtualMethods: } ElementNodeTypeId(HTMLObjectElementTypeId) => { - let element: JS = HTMLObjectElementCast::to(node).unwrap(); - ~element as ~VirtualMethods: + let element: &JSRef = HTMLObjectElementCast::to_ref(node).unwrap(); + ~element.clone() as ~VirtualMethods: } ElementNodeTypeId(HTMLStyleElementTypeId) => { - let element: JS = HTMLStyleElementCast::to(node).unwrap(); - ~element as ~VirtualMethods: + let element: &JSRef = HTMLStyleElementCast::to_ref(node).unwrap(); + ~element.clone() as ~VirtualMethods: } ElementNodeTypeId(ElementTypeId) => { - let element: JS = ElementCast::to(node).unwrap(); - ~element as ~VirtualMethods: + let element: &JSRef = ElementCast::to_ref(node).unwrap(); + ~element.clone() as ~VirtualMethods: } ElementNodeTypeId(_) => { - let element: JS = HTMLElementCast::to(node).unwrap(); - ~element as ~VirtualMethods: + let element: &JSRef = HTMLElementCast::to_ref(node).unwrap(); + ~element.clone() as ~VirtualMethods: } _ => { ~node.clone() as ~VirtualMethods: diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index a1155434d89..ff46c27ed79 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::WindowBinding; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted, OptionalAssignable}; use dom::bindings::trace::{Traceable, Untraceable}; use dom::bindings::utils::{Reflectable, Reflector}; use dom::browsercontext::BrowserContext; @@ -116,9 +116,9 @@ impl Window { chan.send(ExitWindowMsg(self.page.id.clone())); } - pub fn Document(&self) -> JS { + pub fn Document(&self) -> Unrooted { let frame = self.page().frame(); - frame.get_ref().document.clone() + Unrooted::new(frame.get_ref().document.clone()) } pub fn Name(&self) -> DOMString { @@ -148,29 +148,29 @@ impl Window { pub fn Blur(&self) { } - pub fn GetFrameElement(&self) -> Option> { + pub fn GetFrameElement(&self) -> Option> { None } - pub fn Location(&mut self, abstract_self: &JSRef) -> JS { + pub fn Location(&mut self, abstract_self: &JSRef) -> Unrooted { if self.location.is_none() { - self.location = Some(Location::new(abstract_self, self.page.clone())); + self.location.assign(Some(Location::new(abstract_self, self.page.clone()))); } - self.location.get_ref().clone() + Unrooted::new(self.location.get_ref().clone()) } - pub fn Console(&mut self, abstract_self: &JSRef) -> JS { + pub fn Console(&mut self, abstract_self: &JSRef) -> Unrooted { if self.console.is_none() { - self.console = Some(Console::new(abstract_self)); + self.console.assign(Some(Console::new(abstract_self))); } - self.console.get_ref().clone() + Unrooted::new(self.console.get_ref().clone()) } - pub fn Navigator(&mut self, abstract_self: &JSRef) -> JS { + pub fn Navigator(&mut self, abstract_self: &JSRef) -> Unrooted { if self.navigator.is_none() { - self.navigator = Some(Navigator::new(abstract_self)); + self.navigator.assign(Some(Navigator::new(abstract_self))); } - self.navigator.get_ref().clone() + Unrooted::new(self.navigator.get_ref().clone()) } pub fn Confirm(&self, _message: DOMString) -> bool { @@ -279,11 +279,11 @@ impl Window { self.ClearTimeout(handle); } - pub fn Window(&self, abstract_self: &JSRef) -> JS { - abstract_self.unrooted() + pub fn Window(&self, abstract_self: &JSRef) -> Unrooted { + Unrooted::new_rooted(abstract_self) } - pub fn Self(&self, abstract_self: &JSRef) -> JS { + pub fn Self(&self, abstract_self: &JSRef) -> Unrooted { self.Window(abstract_self) } @@ -301,7 +301,7 @@ impl Window { self.page().join_layout(); } - pub fn init_browser_context(&mut self, doc: &JS) { + pub fn init_browser_context(&mut self, doc: &JSRef) { self.browser_context = Some(BrowserContext::new(doc)); } @@ -310,7 +310,7 @@ impl Window { script_chan: ScriptChan, compositor: ~ScriptListener, image_cache_task: ImageCacheTask) - -> JS { + -> Unrooted { let win = ~Window { eventtarget: EventTarget::new_inherited(WindowTypeId), script_chan: script_chan, @@ -325,6 +325,6 @@ impl Window { browser_context: None, }; - WindowBinding::Wrap(cx, win) + Unrooted::new(WindowBinding::Wrap(cx, win)) } } diff --git a/src/components/script/dom/xmlhttprequest.rs b/src/components/script/dom/xmlhttprequest.rs index 9f2bbf180b5..8327135d566 100644 --- a/src/components/script/dom/xmlhttprequest.rs +++ b/src/components/script/dom/xmlhttprequest.rs @@ -10,7 +10,7 @@ use dom::bindings::codegen::InheritTypes::XMLHttpRequestDerived; use dom::document::Document; use dom::eventtarget::{EventTarget, XMLHttpRequestTargetTypeId}; use dom::bindings::error::Fallible; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{JS, JSRef, Unrooted, OptionalAssignable}; use js::jsapi::JSContext; use js::jsval::{JSVal, NullValue}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; @@ -31,7 +31,7 @@ pub struct XMLHttpRequest { ready_state: u16, timeout: u32, with_credentials: bool, - upload: JS, + upload: Option>, response_url: DOMString, status: u16, status_text: ByteString, @@ -42,26 +42,28 @@ pub struct XMLHttpRequest { impl XMLHttpRequest { pub fn new_inherited(owner: &JSRef) -> XMLHttpRequest { - XMLHttpRequest { + let mut xhr = XMLHttpRequest { eventtarget: XMLHttpRequestEventTarget::new_inherited(XMLHttpRequestTypeId), ready_state: 0, timeout: 0u32, with_credentials: false, - upload: XMLHttpRequestUpload::new(owner), + upload: None, response_url: ~"", status: 0, status_text: ByteString::new(vec!()), response_type: _empty, response_text: ~"", response_xml: None - } + }; + xhr.upload.assign(Some(XMLHttpRequestUpload::new(owner))); + xhr } - pub fn new(window: &JSRef) -> JS { + pub fn new(window: &JSRef) -> Unrooted { reflect_dom_object(~XMLHttpRequest::new_inherited(window), window, XMLHttpRequestBinding::Wrap) } - pub fn Constructor(owner: &JSRef) -> Fallible> { + pub fn Constructor(owner: &JSRef) -> Fallible> { Ok(XMLHttpRequest::new(owner)) } pub fn ReadyState(&self) -> u16 { @@ -89,8 +91,8 @@ impl XMLHttpRequest { pub fn SetWithCredentials(&mut self, with_credentials: bool) { self.with_credentials = with_credentials } - pub fn Upload(&self) -> JS { - self.upload.clone() + pub fn Upload(&self) -> Unrooted { + Unrooted::new(self.upload.get_ref().clone()) } pub fn Send(&self, _data: Option) { @@ -128,8 +130,8 @@ impl XMLHttpRequest { pub fn ResponseText(&self) -> DOMString { self.response_text.clone() } - pub fn GetResponseXML(&self) -> Option> { - self.response_xml.clone() + pub fn GetResponseXML(&self) -> Option> { + self.response_xml.clone().map(|response| Unrooted::new(response)) } } diff --git a/src/components/script/dom/xmlhttprequestupload.rs b/src/components/script/dom/xmlhttprequestupload.rs index 5e06d51b1d3..8e251dd4e8f 100644 --- a/src/components/script/dom/xmlhttprequestupload.rs +++ b/src/components/script/dom/xmlhttprequestupload.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::XMLHttpRequestUploadDerived; use dom::bindings::codegen::BindingDeclarations::XMLHttpRequestUploadBinding; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::{Unrooted, JSRef}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::eventtarget::{EventTarget, XMLHttpRequestTargetTypeId}; use dom::window::Window; @@ -22,7 +22,7 @@ impl XMLHttpRequestUpload { eventtarget:XMLHttpRequestEventTarget::new_inherited(XMLHttpRequestUploadTypeId) } } - pub fn new(window: &JSRef) -> JS { + pub fn new(window: &JSRef) -> Unrooted { reflect_dom_object(~XMLHttpRequestUpload::new_inherited(), window, XMLHttpRequestUploadBinding::Wrap) diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 771b75f3e9c..a90a696063c 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, TextCast, ElementCast}; use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalRootable}; use dom::bindings::utils::Reflectable; use dom::document::Document; use dom::element::{AttributeHandlers, HTMLLinkElementTypeId, HTMLIFrameElementTypeId}; @@ -12,7 +12,7 @@ use dom::htmlelement::HTMLElement; use dom::htmlheadingelement::{Heading1, Heading2, Heading3, Heading4, Heading5, Heading6}; use dom::htmliframeelement::IFrameSize; use dom::htmlformelement::HTMLFormElement; -use dom::node::{ElementNodeTypeId, INode, NodeHelpers}; +use dom::node::{ElementNodeTypeId, NodeHelpers, AppendChild}; use dom::types::*; use html::cssparse::{StylesheetProvenance, UrlProvenance, spawn_css_parser}; use script_task::Page; @@ -39,7 +39,7 @@ macro_rules! handle_element( $ctor: ident $(, $arg:expr )*) => ( if $string == $localName { - return ElementCast::from(&$ctor::new($localName, $document $(, $arg)*)); + return ElementCast::from_unrooted($ctor::new($localName, $document $(, $arg)*)); } ) ) @@ -74,21 +74,22 @@ pub struct HtmlParserResult { pub discovery_port: Receiver, } -trait NodeWrapping { +trait NodeWrapping { unsafe fn to_hubbub_node(&self, roots: &RootCollection) -> hubbub::NodeDataPtr; - unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr, roots: Option<&RootCollection>) -> Self; } -impl NodeWrapping for JS { +impl<'a, T: NodeBase+Reflectable> NodeWrapping for JSRef<'a, T> { unsafe fn to_hubbub_node(&self, roots: &RootCollection) -> hubbub::NodeDataPtr { roots.root_raw(self.reflector().get_jsobject()); cast::transmute(self.get()) } - unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr, roots: Option<&RootCollection>) -> JS { - let js = JS::from_raw(cast::transmute(n)); - let _ = roots.map(|roots| roots.unroot_raw(js.reflector().get_jsobject())); - js - } +} + +unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr, + roots: Option<&RootCollection>) -> Unrooted { + let js = JS::from_raw(cast::transmute(n)); + let _ = roots.map(|roots| roots.unroot_raw(js.reflector().get_jsobject())); + Unrooted::new(js) } /** @@ -163,7 +164,7 @@ fn js_script_listener(to_parent: Sender, // Silly macros to handle constructing DOM nodes. This produces bad code and should be optimized // via atomization (issue #85). -pub fn build_element_from_tag(tag: DOMString, document: &JSRef) -> JS { +pub fn build_element_from_tag(tag: DOMString, document: &JSRef) -> Unrooted { // TODO (Issue #85): use atoms handle_element!(document, tag, "a", HTMLAnchorElement); handle_element!(document, tag, "applet", HTMLAppletElement); @@ -245,7 +246,7 @@ pub fn build_element_from_tag(tag: DOMString, document: &JSRef) -> JS< handle_element!(document, tag, "ul", HTMLUListElement); handle_element!(document, tag, "video", HTMLVideoElement); - return ElementCast::from(&HTMLUnknownElement::new(tag, document)); + return ElementCast::from_unrooted(HTMLUnknownElement::new(tag, document)); } pub fn parse_html(page: &Page, @@ -297,7 +298,7 @@ pub fn parse_html(page: &Page, let roots = RootCollection::new(); - parser.set_document_node(unsafe { document.unrooted().to_hubbub_node(&roots) }); + parser.set_document_node(unsafe { document.to_hubbub_node(&roots) }); parser.enable_scripting(true); parser.enable_styling(true); @@ -313,7 +314,8 @@ pub fn parse_html(page: &Page, // NOTE: tmp vars are workaround for lifetime issues. Both required. let tmp_borrow = doc_cell.borrow(); let tmp = &*tmp_borrow; - let comment: JS = NodeCast::from(&Comment::new(data, *tmp)); + let comment = Comment::new(data, *tmp).root(&roots); + let comment: &JSRef = NodeCast::from_ref(&*comment); unsafe { comment.to_hubbub_node(&roots) } }, create_doctype: |doctype: ~hubbub::Doctype| { @@ -325,9 +327,9 @@ pub fn parse_html(page: &Page, // NOTE: tmp vars are workaround for lifetime issues. Both required. let tmp_borrow = doc_cell.borrow(); let tmp = &*tmp_borrow; - let doctype_node = DocumentType::new(name, public_id, system_id, *tmp); + let doctype_node = DocumentType::new(name, public_id, system_id, *tmp).root(&roots); unsafe { - doctype_node.to_hubbub_node(&roots) + doctype_node.deref().to_hubbub_node(&roots) } }, create_element: |tag: ~hubbub::Tag| { @@ -335,8 +337,7 @@ pub fn parse_html(page: &Page, // NOTE: tmp vars are workaround for lifetime issues. Both required. let tmp_borrow = doc_cell.borrow(); let tmp = &*tmp_borrow; - let mut element = build_element_from_tag(tag.name.clone(), *tmp); - let _element_root = element.root(&roots); + let mut element = build_element_from_tag(tag.name.clone(), *tmp).root(&roots); debug!("-- attach attrs"); for attr in tag.attributes.iter() { @@ -346,21 +347,32 @@ pub fn parse_html(page: &Page, attr.value.clone()).is_ok()); } + //FIXME: workaround for https://github.com/mozilla/rust/issues/13246; + // we get unrooting order failures if these are inside the match. + let rel = { + let rel = element.get_attribute(Null, "rel").root(&roots); + rel.map(|a| a.deref().Value()) + }; + let href = { + let href= element.get_attribute(Null, "href").root(&roots); + href.map(|a| a.deref().Value()) + }; + let src_opt = { + let src_opt = element.get_attribute(Null, "src").root(&roots); + src_opt.map(|a| a.deref().Value()) + }; + // Spawn additional parsing, network loads, etc. from tag and attrs match element.get().node.type_id { // Handle CSS style sheets from elements ElementNodeTypeId(HTMLLinkElementTypeId) => { - match (element.get_attribute(Null, "rel"), - element.get_attribute(Null, "href")) { - (Some(ref rel), Some(ref href)) if rel.get() - .value_ref() - .split(HTML_SPACE_CHARACTERS. - as_slice()) + match (rel, href) { + (Some(ref rel), Some(ref href)) if rel.split(HTML_SPACE_CHARACTERS.as_slice()) .any(|s| { s.eq_ignore_ascii_case("stylesheet") }) => { - debug!("found CSS stylesheet: {:s}", href.get().value_ref()); - let url = parse_url(href.get().value_ref(), Some(url2.clone())); + debug!("found CSS stylesheet: {:s}", *href); + let url = parse_url(href.as_slice(), Some(url2.clone())); css_chan2.send(CSSTaskNewFile(UrlProvenance(url, resource_task.clone()))); } _ => {} @@ -369,11 +381,9 @@ pub fn parse_html(page: &Page, ElementNodeTypeId(HTMLIFrameElementTypeId) => { let iframe_chan = discovery_chan.clone(); - let mut iframe_element: JS = - HTMLIFrameElementCast::to(&element).unwrap(); + let iframe_element: &mut JSRef = + HTMLIFrameElementCast::to_mut_ref(&mut *element).unwrap(); let sandboxed = iframe_element.get().is_sandboxed(); - let elem: JS = ElementCast::from(&iframe_element); - let src_opt = elem.get_attribute(Null, "src").map(|x| x.get().Value()); for src in src_opt.iter() { let iframe_url = parse_url(*src, Some(url2.clone())); iframe_element.get_mut().set_frame(iframe_url.clone()); @@ -402,18 +412,17 @@ pub fn parse_html(page: &Page, // NOTE: tmp vars are workaround for lifetime issues. Both required. let tmp_borrow = doc_cell.borrow(); let tmp = &*tmp_borrow; - let text = Text::new(data, *tmp); - unsafe { text.to_hubbub_node(&roots) } + let text = Text::new(data, *tmp).root(&roots); + unsafe { text.deref().to_hubbub_node(&roots) } }, ref_node: |_| {}, unref_node: |_| {}, append_child: |parent: hubbub::NodeDataPtr, child: hubbub::NodeDataPtr| { unsafe { debug!("append child {:x} {:x}", parent, child); - let mut parent: JS = NodeWrapping::from_hubbub_node(parent, None); - let child: JS = NodeWrapping::from_hubbub_node(child, Some(&roots)); - let child = child.root(&roots); - assert!(parent.AppendChild(&mut child.root_ref()).is_ok()); + let mut child = from_hubbub_node(child, Some(&roots)).root(&roots); + let mut parent = from_hubbub_node(parent, None).root(&roots); + assert!(AppendChild(&mut *parent, &mut *child).is_ok()); } child }, @@ -464,8 +473,8 @@ pub fn parse_html(page: &Page, }, complete_script: |script| { unsafe { - let script: JS = NodeWrapping::from_hubbub_node(script, None); - match script.get_attribute(Null, "src") { + let script: &JSRef = &*from_hubbub_node(script, None).root(&roots); + match script.get_attribute(Null, "src").root(&roots) { Some(src) => { debug!("found script: {:s}", src.get().Value()); let new_url = parse_url(src.get().value_ref(), Some(url3.clone())); @@ -473,11 +482,11 @@ pub fn parse_html(page: &Page, } None => { let mut data = vec!(); - let scriptnode: JS = NodeCast::from(&script); + let scriptnode: &JSRef = NodeCast::from_ref(script); debug!("iterating over children {:?}", scriptnode.first_child()); for child in scriptnode.children() { debug!("child = {:?}", child); - let text: JS = TextCast::to(&child).unwrap(); + let text: &JSRef = TextCast::to_ref(&child).unwrap(); data.push(text.get().characterdata.data.to_str()); // FIXME: Bad copy. } diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index f442ddae7c1..f29a18b850a 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -7,7 +7,8 @@ use dom::bindings::codegen::RegisterBindings; use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, ElementCast, EventCast}; -use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalAssignable}; +use dom::bindings::js::OptionalRootable; use dom::bindings::trace::{Traceable, Untraceable}; use dom::bindings::utils::{Reflectable, GlobalStaticData, wrap_for_same_compartment}; use dom::document::{Document, HTMLDocument}; @@ -16,6 +17,7 @@ use dom::event::{Event_, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent, M use dom::event::Event; use dom::uievent::UIEvent; use dom::eventtarget::EventTarget; +use dom::node; use dom::node::{Node, NodeHelpers}; use dom::window::{TimerId, Window}; use html::hubbub_html_parser::HtmlParserResult; @@ -272,14 +274,15 @@ impl Page { /// Adds the given damage. pub fn damage(&self, level: DocumentDamageLevel) { + let roots = RootCollection::new(); let root = match *self.frame() { None => return, Some(ref frame) => frame.document.get().GetDocumentElement() }; - match root { + match root.root(&roots) { None => {}, Some(root) => { - let root: JS = NodeCast::from(&root); + let root: &JSRef = NodeCast::from_ref(&*root); let mut damage = *self.damage.deref().borrow_mut(); match damage { None => {} @@ -351,6 +354,8 @@ impl Page { goal: ReflowGoal, script_chan: ScriptChan, compositor: &ScriptListener) { + let roots = RootCollection::new(); + let root = match *self.frame() { None => return, Some(ref frame) => { @@ -358,7 +363,7 @@ impl Page { } }; - match root { + match root.root(&roots) { None => {}, Some(root) => { debug!("script: performing reflow for goal {:?}", goal); @@ -377,7 +382,7 @@ impl Page { let mut last_reflow_id = self.last_reflow_id.deref().borrow_mut(); *last_reflow_id += 1; - let root: JS = NodeCast::from(&root); + let root: &JSRef = NodeCast::from_ref(&*root); let mut damage = self.damage.deref().borrow_mut(); let window_size = self.window_size.deref().borrow(); @@ -401,19 +406,21 @@ impl Page { } } - fn find_fragment_node(&self, fragid: ~str) -> Option> { - let document = self.frame().get_ref().document.clone(); + fn find_fragment_node(&self, fragid: ~str) -> Option> { + let roots = RootCollection::new(); + let document = self.frame().get_ref().document.root(&roots); match document.get().GetElementById(fragid.to_owned()) { Some(node) => Some(node), None => { - let doc_node: JS = NodeCast::from(&document); - let mut anchors = doc_node.traverse_preorder().filter(|node| node.is_anchor_element()); + let doc_node: &JSRef = NodeCast::from_ref(&*document); + let mut anchors = doc_node.traverse_preorder(&roots) + .filter(|node| node.is_anchor_element()); anchors.find(|node| { - let elem: JS = ElementCast::to(node).unwrap(); - elem.get_attribute(Null, "name").map_or(false, |attr| { + let elem: &JSRef = ElementCast::to_ref(node).unwrap(); + elem.get_attribute(Null, "name").root(&roots).map_or(false, |attr| { attr.get().value_ref() == fragid }) - }).map(|node| ElementCast::to(&node).unwrap()) + }).map(|node| Unrooted::new_rooted(ElementCast::to_ref(&node).unwrap())) } } } @@ -435,13 +442,15 @@ impl Page { } pub fn hit_test(&self, point: &Point2D) -> Option { + let roots = RootCollection::new(); let frame = self.frame(); let document = frame.get_ref().document.clone(); - let root = document.get().GetDocumentElement(); + let root = document.get().GetDocumentElement().root(&roots); if root.is_none() { return None; } - let root: JS = NodeCast::from(&root.unwrap()); + let root = root.unwrap(); + let root: &JSRef = NodeCast::from_ref(&*root); let (chan, port) = channel(); let address = match self.query_layout(HitTestQuery(root.to_trusted_node_address(), *point, chan), port) { Ok(HitTestResponse(node_address)) => { @@ -456,13 +465,15 @@ impl Page { } pub fn get_nodes_under_mouse(&self, point: &Point2D) -> Option> { + let roots = RootCollection::new(); let frame = self.frame(); let document = frame.get_ref().document.clone(); - let root = document.get().GetDocumentElement(); + let root = document.get().GetDocumentElement().root(&roots); if root.is_none() { return None; } - let root: JS = NodeCast::from(&root.unwrap()); + let root = root.unwrap(); + let root: &JSRef = NodeCast::from_ref(&*root); let (chan, port) = channel(); let address = match self.query_layout(MouseOverQuery(root.to_trusted_node_address(), *point, chan), port) { Ok(MouseOverResponse(node_address)) => { @@ -868,16 +879,14 @@ impl ScriptTask { page_tree.page.clone(), self.chan.clone(), self.compositor.dup(), - self.image_cache_task.clone()); - let window_root = window.root(&roots); + self.image_cache_task.clone()).root(&roots); page.initialize_js_info(cx.clone(), window.reflector().get_jsobject()); - let mut document = Document::new(&window_root.root_ref(), Some(url.clone()), HTMLDocument, None); - let doc_root = document.root(&roots); - window.get_mut().init_browser_context(&document); + let mut document = Document::new(&*window, Some(url.clone()), HTMLDocument, None).root(&roots); + window.get_mut().init_browser_context(&*document); { let mut js_info = page.mut_js_info(); - RegisterBindings::Register(&window_root.root_ref(), js_info.get_mut_ref()); + RegisterBindings::Register(&*window, js_info.get_mut_ref()); } self.compositor.set_ready_state(Loading); @@ -885,7 +894,7 @@ impl ScriptTask { // // Note: We can parse the next document in parallel with any previous documents. let html_parsing_result = hubbub_html_parser::parse_html(page, - &mut doc_root.root_ref(), + &mut *document, url.clone(), self.resource_task.clone()); @@ -897,8 +906,8 @@ impl ScriptTask { // Create the root frame. let mut frame = page.mut_frame(); *frame = Some(Frame { - document: document.clone(), - window: window.clone(), + document: document.deref().unrooted(), + window: window.deref().unrooted(), }); } @@ -973,26 +982,24 @@ 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 mut event = Event::new(&window_root.root_ref()); + let mut event = Event::new(&*window).root(&roots); event.get_mut().InitEvent(~"load", false, false); - let event = event.root(&roots); - let doctarget = EventTargetCast::from(&document); - let doctarget = doctarget.root(&roots); - let mut wintarget: JS = EventTargetCast::from(&window); - let wintarget_root = wintarget.root(&roots); - let _ = wintarget.get_mut().dispatch_event_with_target(&wintarget_root.root_ref(), - Some(doctarget.root_ref()), - &mut event.root_ref()); + let doctarget: &JSRef = EventTargetCast::from_ref(&*document); + let wintarget: &mut JSRef = EventTargetCast::from_mut_ref(&mut *window); + let wintarget_alias = wintarget.clone(); + let _ = wintarget.get_mut().dispatch_event_with_target(&wintarget_alias, + Some((*doctarget).clone()), + &mut *event); let mut fragment_node = page.fragment_node.deref().borrow_mut(); - *fragment_node = fragment.map_or(None, |fragid| page.find_fragment_node(fragid)); + (*fragment_node).assign(fragment.map_or(None, |fragid| page.find_fragment_node(fragid))); let ConstellationChan(ref chan) = self.constellation_chan; chan.send(LoadCompleteMsg(page.id, url)); } - fn scroll_fragment_point(&self, pipeline_id: PipelineId, node: JS) { - let node: JS = NodeCast::from(&node); + fn scroll_fragment_point(&self, pipeline_id: PipelineId, node: &JSRef) { + let node: &JSRef = NodeCast::from_ref(node); let rect = node.get_bounding_content_box(); let point = Point2D(to_frac_px(rect.origin.x).to_f32().unwrap(), to_frac_px(rect.origin.y).to_f32().unwrap()); @@ -1015,6 +1022,7 @@ impl ScriptTask { match event { ResizeEvent(new_width, new_height) => { + let roots = RootCollection::new(); debug!("script got resize event: {:u}, {:u}", new_width, new_height); let window = { @@ -1032,31 +1040,28 @@ impl ScriptTask { } let mut fragment_node = page.fragment_node.deref().borrow_mut(); - match fragment_node.take() { - Some(node) => self.scroll_fragment_point(pipeline_id, node), + match fragment_node.take().map(|node| node.root(&roots)) { + Some(node) => self.scroll_fragment_point(pipeline_id, &*node), None => {} } - frame.as_ref().map(|frame| frame.window.clone()) + frame.as_ref().map(|frame| Unrooted::new(frame.window.clone())) }; - match window { - Some(ref window) => { + match window.root(&roots) { + Some(mut window) => { // http://dev.w3.org/csswg/cssom-view/#resizing-viewports // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-resize - let roots = RootCollection::new(); - let window_root = window.root(&roots); + let mut uievent = UIEvent::new(&*window).root(&roots); + uievent.get_mut().InitUIEvent(~"resize", false, false, + Some((*window).clone()), 0i32); + let event: &mut JSRef = EventCast::from_mut_ref(&mut *uievent); - let mut uievent = UIEvent::new(&window_root.root_ref()); - uievent.get_mut().InitUIEvent(~"resize", false, false, Some(window_root).root_ref(), 0i32); - let event: JS = EventCast::from(&uievent); - let event = event.root(&roots); - - let mut wintarget: JS = EventTargetCast::from(window); - let targetroot = wintarget.root(&roots); - let _ = wintarget.get_mut().dispatch_event_with_target(&targetroot.root_ref(), + let wintarget: &mut JSRef = EventTargetCast::from_mut_ref(&mut *window); + let wintarget_alias = wintarget.clone(); + let _ = wintarget.get_mut().dispatch_event_with_target(&wintarget_alias, None, - &mut event.root_ref()); + &mut *event); } None => () } @@ -1076,32 +1081,31 @@ impl ScriptTask { } ClickEvent(_button, point) => { + let roots = RootCollection::new(); debug!("ClickEvent: clicked at {:?}", point); let mut page_tree = self.page_tree.borrow_mut(); let page = get_page(&mut *page_tree, pipeline_id); match page.hit_test(&point) { Some(node_address) => { debug!("node address is {:?}", node_address); - let mut node: JS = - NodeHelpers::from_untrusted_node_address(self.js_runtime.deref().ptr, - node_address); - debug!("clicked on {:s}", node.debug_str()); + let mut node = + node::from_untrusted_node_address(self.js_runtime.deref().ptr, + node_address).root(&roots); + debug!("clicked on {:s}", node.deref().debug_str()); // Traverse node generations until a node that is an element is // found. - while !node.is_element() { - match node.parent_node() { - Some(parent) => node = parent, + while !node.deref().is_element() { + match node.deref().parent_node() { + Some(parent) => node = parent.root(&roots), None => break, } } - if node.is_element() { - let element: JS = ElementCast::to(&node).unwrap(); + if node.deref().is_element() { + let element: &JSRef = ElementCast::to_ref(&*node).unwrap(); if "a" == element.get().local_name { - let roots = RootCollection::new(); - let element = element.root(&roots); - self.load_url_from_element(page, &element.root_ref()) + self.load_url_from_element(page, element) } } } @@ -1112,6 +1116,7 @@ impl ScriptTask { MouseDownEvent(..) => {} MouseUpEvent(..) => {} MouseMoveEvent(point) => { + let roots = RootCollection::new(); let mut page_tree = self.page_tree.borrow_mut(); let page = get_page(&mut *page_tree, pipeline_id); match page.get_nodes_under_mouse(&point) { @@ -1124,6 +1129,7 @@ impl ScriptTask { match *mouse_over_targets { Some(ref mut mouse_over_targets) => { for node in mouse_over_targets.mut_iter() { + let mut node = node.root(&roots); node.set_hover_state(false); } } @@ -1131,14 +1137,14 @@ impl ScriptTask { } for node_address in node_address.iter() { - let mut node: JS = - NodeHelpers::from_untrusted_node_address( - self.js_runtime.deref().ptr, *node_address); + let mut node = + node::from_untrusted_node_address( + self.js_runtime.deref().ptr, *node_address).root(&roots); // Traverse node generations until a node that is an element is // found. while !node.is_element() { match node.parent_node() { - Some(parent) => node = parent, + Some(parent) => node = parent.root(&roots), None => break, } } @@ -1149,12 +1155,12 @@ impl ScriptTask { match *mouse_over_targets { Some(ref mouse_over_targets) => { if !target_compare { - target_compare = !mouse_over_targets.contains(&node); + target_compare = !mouse_over_targets.contains(&node.unrooted()); } } None => {} } - target_list.push(node); + target_list.push(node.unrooted()); } } match *mouse_over_targets { @@ -1182,9 +1188,10 @@ impl ScriptTask { } fn load_url_from_element(&self, page: &Page, element: &JSRef) { + let roots = RootCollection::new(); // if the node's element is "a," load url from href attr - let attr = element.unrooted().get_attribute(Null, "href"); - for href in attr.iter() { + let attr = element.get_attribute(Null, "href"); + for href in attr.root(&roots).iter() { debug!("ScriptTask: clicked on link to {:s}", href.get().Value()); let click_frag = href.get().value_ref().starts_with("#"); let base_url = Some(page.get_url()); @@ -1192,8 +1199,8 @@ impl ScriptTask { let url = parse_url(href.get().value_ref(), base_url); if click_frag { - match page.find_fragment_node(url.fragment.unwrap()) { - Some(node) => self.scroll_fragment_point(page.id, node), + match page.find_fragment_node(url.fragment.unwrap()).root(&roots) { + Some(node) => self.scroll_fragment_point(page.id, &*node), None => {} } } else { From dfdda0098a3f169a37c100b36d4dd36ec1d815aa Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 10 Apr 2014 17:11:08 -0400 Subject: [PATCH 03/16] Remove JS::get/get_mut to enforce sound rooting practices. --- src/components/main/layout/construct.rs | 5 +- src/components/main/layout/wrapper.rs | 6 +- src/components/script/dom/attrlist.rs | 8 ++- .../dom/bindings/codegen/CodegenRust.py | 29 ++------ .../script/dom/bindings/conversions.rs | 4 +- src/components/script/dom/bindings/js.rs | 34 +++++----- src/components/script/dom/bindings/utils.rs | 11 ++-- src/components/script/dom/browsercontext.rs | 16 +++-- src/components/script/dom/document.rs | 11 ++-- .../script/dom/domimplementation.rs | 6 +- src/components/script/dom/element.rs | 37 +++++------ src/components/script/dom/node.rs | 66 +++++++++---------- src/components/script/script_task.rs | 12 ++-- 13 files changed, 114 insertions(+), 131 deletions(-) diff --git a/src/components/main/layout/construct.rs b/src/components/main/layout/construct.rs index 72ce8e09b97..46f5c5ef287 100644 --- a/src/components/main/layout/construct.rs +++ b/src/components/main/layout/construct.rs @@ -45,7 +45,6 @@ use layout::wrapper::{Before, BeforeBlock, After, AfterBlock, Normal}; use gfx::display_list::OpaqueNode; use gfx::font_context::FontContext; -use script::dom::bindings::codegen::InheritTypes::TextCast; use script::dom::bindings::js::JS; use script::dom::element::{HTMLIFrameElementTypeId, HTMLImageElementTypeId}; use script::dom::element::{HTMLObjectElementTypeId}; @@ -1064,8 +1063,8 @@ impl<'ln> NodeUtils for ThreadSafeLayoutNode<'ln> { match self.type_id() { Some(TextNodeTypeId) => { unsafe { - let text: JS = TextCast::to(self.get_jsmanaged()).unwrap(); - if !is_whitespace(text.get().characterdata.data) { + let text: JS = self.get_jsmanaged().transmute_copy(); + if !is_whitespace((*text.unsafe_get()).characterdata.data) { return false } diff --git a/src/components/main/layout/wrapper.rs b/src/components/main/layout/wrapper.rs index b9532e2d31c..d779845c5b5 100644 --- a/src/components/main/layout/wrapper.rs +++ b/src/components/main/layout/wrapper.rs @@ -242,7 +242,7 @@ impl<'ln> TNode> for LayoutNode<'ln> { fn as_element(&self) -> LayoutElement<'ln> { unsafe { let elem: JS = self.node.transmute_copy(); - let element = elem.get(); + let element = &*elem.unsafe_get(); LayoutElement { element: cast::transmute_region(element), } @@ -509,10 +509,10 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { /// Returns the next sibling of this node. Unsafe and private because this can lead to races. unsafe fn next_sibling(&self) -> Option> { if self.pseudo == Before || self.pseudo == BeforeBlock { - return self.get().first_child_ref().map(|node| self.new_with_this_lifetime(node)) + return (*self.get_jsmanaged().unsafe_get()).first_child_ref().map(|node| self.new_with_this_lifetime(node)) } - self.node.get().next_sibling_ref().map(|node| self.new_with_this_lifetime(node)) + (*self.get_jsmanaged().unsafe_get()).next_sibling_ref().map(|node| self.new_with_this_lifetime(node)) } /// Returns an iterator over this node's children. diff --git a/src/components/script/dom/attrlist.rs b/src/components/script/dom/attrlist.rs index 78f8211e3e0..273378347f0 100644 --- a/src/components/script/dom/attrlist.rs +++ b/src/components/script/dom/attrlist.rs @@ -4,7 +4,7 @@ use dom::attr::Attr; use dom::bindings::codegen::BindingDeclarations::AttrListBinding; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Unrooted, RootCollection}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::element::Element; use dom::window::Window; @@ -31,11 +31,13 @@ impl AttrList { } pub fn Length(&self) -> u32 { - self.owner.get().attrs.len() as u32 + let roots = RootCollection::new(); + self.owner.root(&roots).attrs.len() as u32 } pub fn Item(&self, index: u32) -> Option> { - self.owner.get().attrs.as_slice().get(index as uint).map(|x| Unrooted::new(x.clone())) + let roots = RootCollection::new(); + self.owner.root(&roots).attrs.as_slice().get(index as uint).map(|x| Unrooted::new(x.clone())) } pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 30ff08e21ff..74de0fe75d4 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -2243,12 +2243,7 @@ class CGCallGenerator(CGThing): self.cgRoot.append(CGGeneric("result = result_fallible.unwrap();")) if typeRetValNeedsRooting(returnType): - rooted_value = CGGeneric("result.root(&roots).root_ref().unrooted()") - if returnType.nullable(): - rooted_value = CGWrapper(rooted_value, pre="result.map(|result| ", post=")") - rooted_value = CGWrapper(rooted_value, pre="let result = ", post=";") - - self.cgRoot.append(rooted_value) + self.cgRoot.append(CGGeneric("let result = result.root(&roots);")) def define(self): return self.cgRoot.define() @@ -4321,7 +4316,7 @@ class CGBindingRoot(CGThing): 'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}', 'dom::types::*', 'dom::bindings', - 'dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Unrooted}', + 'dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Unrooted, OptionalRootable}', 'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}', 'dom::bindings::utils::{ConstantSpec, cx_for_dom_object, Default}', 'dom::bindings::utils::{dom_object_slot, DOM_OBJECT_SLOT, DOMClass}', @@ -5320,19 +5315,6 @@ class GlobalGenRoots(): derived += [CGGeneric('\n')] cast = [CGGeneric(string.Template('''pub trait ${castTraitName} { - #[inline(always)] - fn from(derived: &JS) -> JS { - unsafe { derived.clone().transmute() } - } - - #[inline(always)] - fn to(base: &JS) -> Option> { - match base.get().${checkFn}() { - true => unsafe { Some(base.clone().transmute()) }, - false => None - } - } - #[inline(always)] fn to_ref<'a, 'b, T: ${toBound}+Reflectable>(base: &'a JSRef<'b, T>) -> Option<&'a JSRef<'b, Self>> { match base.get().${checkFn}() { @@ -5350,19 +5332,16 @@ class GlobalGenRoots(): } #[inline(always)] - unsafe fn to_unchecked(base: &JS) -> JS { - assert!(base.get().${checkFn}()); - base.clone().transmute() - } - fn from_ref<'a, 'b, T: ${fromBound}>(derived: &'a JSRef<'b, T>) -> &'a JSRef<'b, Self> { unsafe { derived.transmute() } } + #[inline(always)] fn from_mut_ref<'a, 'b, T: ${fromBound}>(derived: &'a mut JSRef<'b, T>) -> &'a mut JSRef<'b, Self> { unsafe { derived.transmute_mut() } } + #[inline(always)] fn from_unrooted(derived: Unrooted) -> Unrooted { unsafe { derived.transmute() } } diff --git a/src/components/script/dom/bindings/conversions.rs b/src/components/script/dom/bindings/conversions.rs index 90c0251ba2f..02d6983cf3b 100644 --- a/src/components/script/dom/bindings/conversions.rs +++ b/src/components/script/dom/bindings/conversions.rs @@ -2,7 +2,7 @@ * 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}; +use dom::bindings::js::{JS, JSRef, Root}; use dom::bindings::str::ByteString; use dom::bindings::utils::{Reflectable, Reflector}; use dom::bindings::utils::jsstring_to_str; @@ -316,7 +316,7 @@ impl FromJSValConvertible<()> for JS { } } -impl ToJSValConvertible for JS { +impl<'a, 'b, T: Reflectable> ToJSValConvertible for Root<'a, 'b, T> { fn to_jsval(&self, cx: *JSContext) -> JSVal { self.reflector().to_jsval(cx) } diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs index 2386777cac9..3a3b6bd7166 100644 --- a/src/components/script/dom/bindings/js.rs +++ b/src/components/script/dom/bindings/js.rs @@ -106,31 +106,23 @@ impl JS { } } +//XXXjdm This is disappointing. This only gets called from trace hooks, in theory, +// so it's safe to assume that self is rooted and thereby safe to access. impl Reflectable for JS { fn reflector<'a>(&'a self) -> &'a Reflector { - self.get().reflector() + unsafe { + (*self.unsafe_get()).reflector() + } } fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector { - self.get_mut().mut_reflector() + unsafe { + (*self.unsafe_get()).mut_reflector() + } } } impl JS { - pub fn get<'a>(&'a self) -> &'a T { - let borrowed = self.ptr.borrow(); - unsafe { - &**borrowed - } - } - - pub fn get_mut<'a>(&'a mut self) -> &'a mut T { - let mut borrowed = self.ptr.borrow_mut(); - unsafe { - &mut **borrowed - } - } - /// 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.) @@ -213,6 +205,16 @@ impl OptionalRootable for Option> { } } +pub trait OptionalRootedRootable { + fn root<'a, 'b>(&self, roots: &'a RootCollection) -> Option>; +} + +impl OptionalRootedRootable for Option> { + fn root<'a, 'b>(&self, roots: &'a RootCollection) -> Option> { + self.as_ref().map(|inner| inner.root(roots)) + } +} + pub trait ResultRootable { fn root<'a, 'b>(self, roots: &'a RootCollection) -> Result, U>; } diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index 80aa9c364ee..65725b9d923 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -5,7 +5,7 @@ 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, RootCollection, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, Root}; use dom::bindings::trace::Untraceable; use dom::browsercontext; use dom::window; @@ -602,13 +602,16 @@ pub extern fn wrap_for_same_compartment(cx: *JSContext, obj: *JSObject) -> *JSOb pub extern fn outerize_global(_cx: *JSContext, obj: JSHandleObject) -> *JSObject { unsafe { + let roots = RootCollection::new(); debug!("outerizing"); let obj = *obj.unnamed; - let win: JS = + let win: Root = unwrap_jsmanaged(obj, IDLInterface::get_prototype_id(None::), - IDLInterface::get_prototype_depth(None::)).unwrap(); - win.get().browser_context.get_ref().window_proxy() + IDLInterface::get_prototype_depth(None::)) + .unwrap() + .root(&roots); + win.deref().browser_context.get_ref().window_proxy() } } diff --git a/src/components/script/dom/browsercontext.rs b/src/components/script/dom/browsercontext.rs index fbb63420520..4a452ccd2ae 100644 --- a/src/components/script/dom/browsercontext.rs +++ b/src/components/script/dom/browsercontext.rs @@ -2,7 +2,7 @@ * 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}; +use dom::bindings::js::{JS, JSRef, Unrooted, RootCollection}; use dom::bindings::trace::Traceable; use dom::bindings::utils::Reflectable; use dom::document::Document; @@ -32,13 +32,14 @@ impl BrowserContext { context } - pub fn active_document(&self) -> JS { - self.history.get(self.active_index).document.clone() + pub fn active_document(&self) -> Unrooted { + Unrooted::new(self.history.get(self.active_index).document.clone()) } - pub fn active_window(&self) -> JS { - let doc = self.active_document(); - doc.get().window.clone() + pub fn active_window(&self) -> Unrooted { + let roots = RootCollection::new(); + let doc = self.active_document().root(&roots); + Unrooted::new(doc.deref().window.clone()) } pub fn window_proxy(&self) -> *JSObject { @@ -47,7 +48,8 @@ impl BrowserContext { } pub fn create_window_proxy(&self) -> *JSObject { - let win = self.active_window(); + let roots = RootCollection::new(); + let win = self.active_window().root(&roots); let page = win.get().page(); let js_info = page.js_info(); diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index e2984a1bf82..d0ffb203282 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -660,8 +660,9 @@ impl Document { pub fn Location(&mut self, _abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); - let window = self.window.root(&roots); - self.window.get_mut().Location(&*window) + let mut window = self.window.root(&roots); + let window_alias = self.window.root(&roots); + window.get_mut().Location(&*window_alias) } pub fn Children(&self, abstract_self: &JSRef) -> Unrooted { @@ -695,11 +696,13 @@ impl Document { } pub fn damage_and_reflow(&self, damage: DocumentDamageLevel) { - self.window.get().damage_and_reflow(damage); + let roots = RootCollection::new(); + self.window.root(&roots).damage_and_reflow(damage); } pub fn wait_until_safe_to_modify_dom(&self) { - self.window.get().wait_until_safe_to_modify_dom(); + let roots = RootCollection::new(); + self.window.root(&roots).wait_until_safe_to_modify_dom(); } diff --git a/src/components/script/dom/domimplementation.rs b/src/components/script/dom/domimplementation.rs index 7cc9e5ef0d0..0e824306343 100644 --- a/src/components/script/dom/domimplementation.rs +++ b/src/components/script/dom/domimplementation.rs @@ -61,9 +61,9 @@ impl DOMImplementation { Name => Err(NamespaceError), // Step 3. QName => { - let document = self.owner.get().Document(); - let document = document.root(&roots); - Ok(DocumentType::new(qname, Some(pubid), Some(sysid), &document.root_ref())) + let owner = self.owner.root(&roots); + let document = owner.deref().Document().root(&roots); + Ok(DocumentType::new(qname, Some(pubid), Some(sysid), &*document)) } } } diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index e0901de01d8..a3bdeb22d3e 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -216,16 +216,15 @@ pub trait AttributeHandlers { impl<'a> AttributeHandlers for JSRef<'a, Element> { fn get_attribute(&self, namespace: Namespace, name: &str) -> Option> { + let roots = RootCollection::new(); if self.get().html_element_in_html_document() { - self.get().attrs.iter().find(|attr| { - let attr = attr.get(); + self.get().attrs.iter().map(|attr| attr.root(&roots)).find(|attr| { name.to_ascii_lower() == attr.local_name && attr.namespace == namespace - }).map(|x| Unrooted::new(x.clone())) + }).map(|x| Unrooted::new_rooted(&*x)) } else { - self.get().attrs.iter().find(|attr| { - let attr = attr.get(); + self.get().attrs.iter().map(|attr| attr.root(&roots)).find(|attr| { name == attr.local_name && attr.namespace == namespace - }).map(|x| Unrooted::new(x.clone())) + }).map(|x| Unrooted::new_rooted(&*x)) } } @@ -279,7 +278,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } }; - self.get_mut().attrs.get_mut(idx).get_mut().set_value(set_type, value); + self.get_mut().attrs.get(idx).root(&roots).set_value(set_type, value); } // http://dom.spec.whatwg.org/#dom-element-setattribute @@ -369,21 +368,22 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult { + let roots = RootCollection::new(); let (_, local_name) = get_attribute_parts(name.clone()); let self_alias = self.clone(); let node: &JSRef = NodeCast::from_ref(&self_alias); node.wait_until_safe_to_modify_dom(); - let idx = self.get().attrs.iter().position(|attr| { - attr.get().local_name == local_name + let idx = self.get().attrs.iter().map(|attr| attr.root(&roots)).position(|attr| { + attr.local_name == local_name }); match idx { None => (), Some(idx) => { if namespace == namespace::Null { - let removed_raw_value = self.get().attrs.get(idx).get().Value(); + let removed_raw_value = self.get().attrs.get(idx).root(&roots).Value(); vtable_for(node).before_remove_attr(local_name.clone(), removed_raw_value); } @@ -528,11 +528,8 @@ impl Element { } else { name }; - abstract_self.get_attribute(Null, name) - .map(|s| { - let s = s.root(&roots); - s.deref().Value() - }) + abstract_self.get_attribute(Null, name).root(&roots) + .map(|s| s.deref().Value()) } // http://dom.spec.whatwg.org/#dom-element-getattributens @@ -541,11 +538,8 @@ impl Element { local_name: DOMString) -> Option { let roots = RootCollection::new(); let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace)); - abstract_self.get_attribute(namespace, local_name) - .map(|attr| { - let attr = attr.root(&roots); - attr.deref().Value() - }) + abstract_self.get_attribute(namespace, local_name).root(&roots) + .map(|attr| attr.deref().Value()) } // http://dom.spec.whatwg.org/#dom-element-setattribute @@ -747,9 +741,8 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { _ => (), } - match self.get_attribute(Null, "id") { + match self.get_attribute(Null, "id").root(&roots) { Some(attr) => { - let attr = attr.root(&roots); let mut doc = document_from_node(self).root(&roots); doc.register_named_element(self, attr.deref().Value()); } diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 6758efeb65d..fd911b3f0ba 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -11,8 +11,8 @@ use dom::bindings::codegen::InheritTypes::{CharacterDataCast, NodeBase, NodeDeri use dom::bindings::codegen::InheritTypes::{ProcessingInstructionCast, EventTargetCast}; use dom::bindings::codegen::BindingDeclarations::NodeBinding::NodeConstants; use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Unrooted, Root}; -use dom::bindings::js::{OptionalAssignable, UnrootedPushable, OptionalRootable}; -use dom::bindings::js::ResultRootable; +use dom::bindings::js::{OptionalAssignable, UnrootedPushable, OptionalRootedRootable}; +use dom::bindings::js::{ResultRootable, OptionalRootable}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::{ErrorResult, Fallible, NotFound, HierarchyRequest}; use dom::bindings::utils; @@ -479,27 +479,25 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { let child_node = child.get_mut(); assert!(child_node.parent_node.is_some()); - match child_node.prev_sibling { + match child_node.prev_sibling.root(&roots) { None => { let next_sibling = child_node.next_sibling.as_ref().map(|next| next.root(&roots)); this_node.set_first_child(next_sibling.root_ref()); } Some(ref mut prev_sibling) => { - let prev_sibling_node = prev_sibling.get_mut(); let next_sibling = child_node.next_sibling.as_ref().map(|next| next.root(&roots)); - prev_sibling_node.set_next_sibling(next_sibling.root_ref()); + prev_sibling.set_next_sibling(next_sibling.root_ref()); } } - match child_node.next_sibling { + match child_node.next_sibling.root(&roots) { None => { let prev_sibling = child_node.prev_sibling.as_ref().map(|prev| prev.root(&roots)); this_node.set_last_child(prev_sibling.root_ref()); } Some(ref mut next_sibling) => { - let next_sibling_node = next_sibling.get_mut(); let prev_sibling = child_node.prev_sibling.as_ref().map(|prev| prev.root(&roots)); - next_sibling_node.set_prev_sibling(prev_sibling.root_ref()); + next_sibling.set_prev_sibling(prev_sibling.root_ref()); } } @@ -916,18 +914,18 @@ impl Node { pub fn NodeName(&self, abstract_self: &JSRef) -> DOMString { match self.type_id { ElementNodeTypeId(..) => { - let elem: JS = ElementCast::to(&abstract_self.unrooted()).unwrap(); + let elem: &JSRef = ElementCast::to_ref(abstract_self).unwrap(); elem.get().TagName() } TextNodeTypeId => ~"#text", ProcessingInstructionNodeTypeId => { - let processing_instruction: JS = - ProcessingInstructionCast::to(&abstract_self.unrooted()).unwrap(); + let processing_instruction: &JSRef = + ProcessingInstructionCast::to_ref(abstract_self).unwrap(); processing_instruction.get().Target() } CommentNodeTypeId => ~"#comment", DoctypeNodeTypeId => { - let doctype: JS = DocumentTypeCast::to(&abstract_self.unrooted()).unwrap(); + let doctype: &JSRef = DocumentTypeCast::to_ref(abstract_self).unwrap(); doctype.get().name.clone() }, DocumentFragmentNodeTypeId => ~"#document-fragment", @@ -1016,7 +1014,7 @@ impl Node { CommentNodeTypeId | TextNodeTypeId | ProcessingInstructionNodeTypeId => { - let chardata: JS = CharacterDataCast::to(&abstract_self.unrooted()).unwrap(); + let chardata: &JSRef = CharacterDataCast::to_ref(abstract_self).unwrap(); Some(chardata.get().Data()) } _ => { @@ -1091,7 +1089,7 @@ impl Node { ProcessingInstructionNodeTypeId => { self.wait_until_safe_to_modify_dom(); - let mut characterdata: JS = CharacterDataCast::to(&abstract_self.unrooted()).unwrap(); + let characterdata: &mut JSRef = CharacterDataCast::to_mut_ref(abstract_self).unwrap(); characterdata.get_mut().data = value.clone(); // Notify the document that the content of this node is different @@ -1482,13 +1480,12 @@ impl Node { // FIXME: https://github.com/mozilla/servo/issues/1737 copy_elem.namespace = node_elem.namespace.clone(); let window = document.get().window.root(&roots); - for attr in node_elem.attrs.iter() { - let attr = attr.get(); + for attr in node_elem.attrs.iter().map(|attr| attr.root(&roots)) { copy_elem.attrs.push_unrooted( Attr::new(&*window, - attr.local_name.clone(), attr.value.clone(), - attr.name.clone(), attr.namespace.clone(), - attr.prefix.clone(), ©_elem_alias)); + attr.deref().local_name.clone(), attr.deref().value.clone(), + attr.deref().name.clone(), attr.deref().namespace.clone(), + attr.deref().prefix.clone(), ©_elem_alias)); } }, _ => () @@ -1703,40 +1700,41 @@ impl Node { // http://dom.spec.whatwg.org/#dom-node-isequalnode pub fn IsEqualNode(&self, abstract_self: &JSRef, maybe_node: Option>) -> bool { fn is_equal_doctype(node: &JSRef, other: &JSRef) -> bool { - let doctype: JS = DocumentTypeCast::to(&node.unrooted()).unwrap(); - let other_doctype: JS = DocumentTypeCast::to(&other.unrooted()).unwrap(); + let doctype: &JSRef = DocumentTypeCast::to_ref(node).unwrap(); + let other_doctype: &JSRef = DocumentTypeCast::to_ref(other).unwrap(); (doctype.get().name == other_doctype.get().name) && (doctype.get().public_id == other_doctype.get().public_id) && (doctype.get().system_id == other_doctype.get().system_id) } fn is_equal_element(node: &JSRef, other: &JSRef) -> bool { - let element: JS = ElementCast::to(&node.unrooted()).unwrap(); - let other_element: JS = ElementCast::to(&other.unrooted()).unwrap(); + let element: &JSRef = ElementCast::to_ref(node).unwrap(); + let other_element: &JSRef = ElementCast::to_ref(other).unwrap(); // FIXME: namespace prefix (element.get().namespace == other_element.get().namespace) && (element.get().local_name == other_element.get().local_name) && (element.get().attrs.len() == other_element.get().attrs.len()) } fn is_equal_processinginstruction(node: &JSRef, other: &JSRef) -> bool { - let pi: JS = ProcessingInstructionCast::to(&node.unrooted()).unwrap(); - let other_pi: JS = ProcessingInstructionCast::to(&other.unrooted()).unwrap(); + let pi: &JSRef = ProcessingInstructionCast::to_ref(node).unwrap(); + let other_pi: &JSRef = ProcessingInstructionCast::to_ref(other).unwrap(); (pi.get().target == other_pi.get().target) && (pi.get().characterdata.data == other_pi.get().characterdata.data) } fn is_equal_characterdata(node: &JSRef, other: &JSRef) -> bool { - let characterdata: JS = CharacterDataCast::to(&node.unrooted()).unwrap(); - let other_characterdata: JS = CharacterDataCast::to(&other.unrooted()).unwrap(); + let characterdata: &JSRef = CharacterDataCast::to_ref(node).unwrap(); + let other_characterdata: &JSRef = CharacterDataCast::to_ref(other).unwrap(); characterdata.get().data == other_characterdata.get().data } fn is_equal_element_attrs(node: &JSRef, other: &JSRef) -> bool { - let element: JS = ElementCast::to(&node.unrooted()).unwrap(); - let other_element: JS = ElementCast::to(&other.unrooted()).unwrap(); + let roots = RootCollection::new(); + let element: &JSRef = ElementCast::to_ref(node).unwrap(); + let other_element: &JSRef = ElementCast::to_ref(other).unwrap(); assert!(element.get().attrs.len() == other_element.get().attrs.len()); - element.get().attrs.iter().all(|attr| { - other_element.get().attrs.iter().any(|other_attr| { - (attr.get().namespace == other_attr.get().namespace) && - (attr.get().local_name == other_attr.get().local_name) && - (attr.get().value == other_attr.get().value) + element.get().attrs.iter().map(|attr| attr.root(&roots)).all(|attr| { + other_element.get().attrs.iter().map(|attr| attr.root(&roots)).any(|other_attr| { + (attr.namespace == other_attr.namespace) && + (attr.local_name == other_attr.local_name) && + (attr.value == other_attr.value) }) }) } diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index f29a18b850a..36fc83b1aee 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -277,7 +277,7 @@ impl Page { let roots = RootCollection::new(); let root = match *self.frame() { None => return, - Some(ref frame) => frame.document.get().GetDocumentElement() + Some(ref frame) => frame.document.root(&roots).GetDocumentElement() }; match root.root(&roots) { None => {}, @@ -359,7 +359,7 @@ impl Page { let root = match *self.frame() { None => return, Some(ref frame) => { - frame.document.get().GetDocumentElement() + frame.document.root(&roots).GetDocumentElement() } }; @@ -444,7 +444,7 @@ impl Page { pub fn hit_test(&self, point: &Point2D) -> Option { let roots = RootCollection::new(); let frame = self.frame(); - let document = frame.get_ref().document.clone(); + let document = frame.get_ref().document.root(&roots); let root = document.get().GetDocumentElement().root(&roots); if root.is_none() { return None; @@ -467,7 +467,7 @@ impl Page { pub fn get_nodes_under_mouse(&self, point: &Point2D) -> Option> { let roots = RootCollection::new(); let frame = self.frame(); - let document = frame.get_ref().document.clone(); + let document = frame.get_ref().document.root(&roots); let root = document.get().GetDocumentElement().root(&roots); if root.is_none() { return None; @@ -737,11 +737,13 @@ impl ScriptTask { /// Handles a timer that fired. fn handle_fire_timer_msg(&self, id: PipelineId, timer_id: TimerId) { + let roots = RootCollection::new(); + let mut page_tree = self.page_tree.borrow_mut(); let page = page_tree.find(id).expect("ScriptTask: received fire timer msg for a pipeline ID not associated with this script task. This is a bug.").page(); let frame = page.frame(); - let mut window = frame.get_ref().window.clone(); + let mut window = frame.get_ref().window.root(&roots); let is_interval; match window.get().active_timers.find(&timer_id) { From 76783b029e5e10da7fd61ab356a8f80a1eaf32e0 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 10 Apr 2014 21:29:54 -0400 Subject: [PATCH 04/16] Move WebIDL methods to traits implemented by JSRef types. --- src/components/script/dom/attr.rs | 23 +- src/components/script/dom/attrlist.rs | 14 +- .../dom/bindings/codegen/CodegenRust.py | 71 +- src/components/script/dom/blob.rs | 19 +- src/components/script/dom/characterdata.rs | 31 +- src/components/script/dom/clientrect.rs | 22 +- src/components/script/dom/clientrectlist.rs | 14 +- src/components/script/dom/comment.rs | 11 +- src/components/script/dom/console.rs | 20 +- src/components/script/dom/document.rs | 380 +++++----- src/components/script/dom/documentfragment.rs | 14 +- src/components/script/dom/documenttype.rs | 15 +- src/components/script/dom/domexception.rs | 14 +- .../script/dom/domimplementation.rs | 23 +- src/components/script/dom/domparser.rs | 14 +- src/components/script/dom/element.rs | 120 ++-- src/components/script/dom/event.rs | 62 +- src/components/script/dom/eventdispatcher.rs | 3 +- src/components/script/dom/eventtarget.rs | 55 +- src/components/script/dom/formdata.rs | 14 +- .../script/dom/htmlanchorelement.rs | 83 ++- .../script/dom/htmlappletelement.rs | 71 +- src/components/script/dom/htmlareaelement.rs | 53 +- src/components/script/dom/htmlaudioelement.rs | 3 + src/components/script/dom/htmlbaseelement.rs | 18 +- src/components/script/dom/htmlbodyelement.rs | 42 +- src/components/script/dom/htmlbrelement.rs | 12 +- .../script/dom/htmlbuttonelement.rs | 93 ++- .../script/dom/htmlcanvaselement.rs | 18 +- src/components/script/dom/htmlcollection.rs | 22 +- src/components/script/dom/htmldataelement.rs | 12 +- .../script/dom/htmldatalistelement.rs | 9 +- .../script/dom/htmldirectoryelement.rs | 12 +- src/components/script/dom/htmldivelement.rs | 12 +- src/components/script/dom/htmldlistelement.rs | 18 +- src/components/script/dom/htmlelement.rs | 95 ++- src/components/script/dom/htmlembedelement.rs | 45 +- .../script/dom/htmlfieldsetelement.rs | 42 +- src/components/script/dom/htmlfontelement.rs | 24 +- src/components/script/dom/htmlformelement.rs | 78 ++- src/components/script/dom/htmlframeelement.rs | 60 +- .../script/dom/htmlframesetelement.rs | 18 +- src/components/script/dom/htmlheadelement.rs | 3 + .../script/dom/htmlheadingelement.rs | 12 +- src/components/script/dom/htmlhrelement.rs | 36 +- src/components/script/dom/htmlhtmlelement.rs | 12 +- .../script/dom/htmliframeelement.rs | 92 ++- src/components/script/dom/htmlimageelement.rs | 94 ++- src/components/script/dom/htmlinputelement.rs | 240 ++++--- src/components/script/dom/htmllabelelement.rs | 12 +- .../script/dom/htmllegendelement.rs | 12 +- src/components/script/dom/htmllielement.rs | 18 +- src/components/script/dom/htmllinkelement.rs | 66 +- src/components/script/dom/htmlmainelement.rs | 3 + src/components/script/dom/htmlmapelement.rs | 15 +- src/components/script/dom/htmlmediaelement.rs | 110 ++- src/components/script/dom/htmlmetaelement.rs | 30 +- src/components/script/dom/htmlmeterelement.rs | 42 +- src/components/script/dom/htmlmodelement.rs | 18 +- .../script/dom/htmlobjectelement.rs | 129 ++-- src/components/script/dom/htmlolistelement.rs | 30 +- .../script/dom/htmloptgroupelement.rs | 18 +- .../script/dom/htmloptionelement.rs | 48 +- .../script/dom/htmloutputelement.rs | 54 +- .../script/dom/htmlparagraphelement.rs | 12 +- src/components/script/dom/htmlparamelement.rs | 30 +- src/components/script/dom/htmlpreelement.rs | 12 +- .../script/dom/htmlprogresselement.rs | 24 +- src/components/script/dom/htmlquoteelement.rs | 12 +- .../script/dom/htmlscriptelement.rs | 60 +- .../script/dom/htmlselectelement.rs | 111 ++- .../script/dom/htmlsourceelement.rs | 24 +- src/components/script/dom/htmlspanelement.rs | 3 + src/components/script/dom/htmlstyleelement.rs | 33 +- .../script/dom/htmltablecaptionelement.rs | 12 +- .../script/dom/htmltablecellelement.rs | 98 ++- .../script/dom/htmltablecolelement.rs | 42 +- .../script/dom/htmltabledatacellelement.rs | 3 + src/components/script/dom/htmltableelement.rs | 81 ++- .../script/dom/htmltableheadercellelement.rs | 3 + .../script/dom/htmltablerowelement.rs | 51 +- .../script/dom/htmltablesectionelement.rs | 33 +- .../script/dom/htmltemplateelement.rs | 3 + .../script/dom/htmltextareaelement.rs | 129 ++-- src/components/script/dom/htmltimeelement.rs | 12 +- src/components/script/dom/htmltitleelement.rs | 12 +- src/components/script/dom/htmltrackelement.rs | 39 +- src/components/script/dom/htmlulistelement.rs | 18 +- .../script/dom/htmlunknownelement.rs | 3 + src/components/script/dom/htmlvideoelement.rs | 30 +- src/components/script/dom/location.rs | 78 ++- src/components/script/dom/mouseevent.rs | 109 ++- src/components/script/dom/navigator.rs | 54 +- src/components/script/dom/node.rs | 652 +++++++++--------- src/components/script/dom/nodelist.rs | 14 +- .../script/dom/processinginstruction.rs | 9 +- src/components/script/dom/testbinding.rs | 520 +++++++++----- src/components/script/dom/text.rs | 19 +- src/components/script/dom/uievent.rs | 73 +- src/components/script/dom/validitystate.rs | 33 +- src/components/script/dom/window.rs | 129 ++-- src/components/script/dom/xmlhttprequest.rs | 73 +- .../script/dom/xmlhttprequesteventtarget.rs | 3 + .../script/dom/xmlhttprequestupload.rs | 3 + .../script/html/hubbub_html_parser.rs | 3 +- src/components/script/script_task.rs | 21 +- 106 files changed, 3644 insertions(+), 1912 deletions(-) diff --git a/src/components/script/dom/attr.rs b/src/components/script/dom/attr.rs index d6c2d530862..5c37ca45632 100644 --- a/src/components/script/dom/attr.rs +++ b/src/components/script/dom/attr.rs @@ -91,31 +91,40 @@ impl Attr { } } -impl Attr { - pub fn LocalName(&self) -> DOMString { +pub trait AttrMethods { + fn LocalName(&self) -> DOMString; + fn Value(&self) -> DOMString; + fn SetValue(&mut self, value: DOMString); + fn Name(&self) -> DOMString; + fn GetNamespaceURI(&self) -> Option; + fn GetPrefix(&self) -> Option; +} + +impl<'a> AttrMethods for JSRef<'a, Attr> { + fn LocalName(&self) -> DOMString { self.local_name.clone() } - pub fn Value(&self) -> DOMString { + fn Value(&self) -> DOMString { self.value.clone() } - pub fn SetValue(&mut self, value: DOMString) { + fn SetValue(&mut self, value: DOMString) { self.set_value(ReplacedAttr, value); } - pub fn Name(&self) -> DOMString { + fn Name(&self) -> DOMString { self.name.clone() } - pub fn GetNamespaceURI(&self) -> Option { + fn GetNamespaceURI(&self) -> Option { match self.namespace.to_str() { "" => None, url => Some(url.to_owned()), } } - pub fn GetPrefix(&self) -> Option { + fn GetPrefix(&self) -> Option { self.prefix.clone() } } diff --git a/src/components/script/dom/attrlist.rs b/src/components/script/dom/attrlist.rs index 273378347f0..eca2deade79 100644 --- a/src/components/script/dom/attrlist.rs +++ b/src/components/script/dom/attrlist.rs @@ -29,18 +29,26 @@ impl AttrList { reflect_dom_object(~AttrList::new_inherited(window.unrooted(), elem.unrooted()), window, AttrListBinding::Wrap) } +} - pub fn Length(&self) -> u32 { +pub trait AttrListMethods { + fn Length(&self) -> u32; + fn Item(&self, index: u32) -> Option>; + fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option>; +} + +impl<'a> AttrListMethods for JSRef<'a, AttrList> { + fn Length(&self) -> u32 { let roots = RootCollection::new(); self.owner.root(&roots).attrs.len() as u32 } - pub fn Item(&self, index: u32) -> Option> { + fn Item(&self, index: u32) -> Option> { let roots = RootCollection::new(); self.owner.root(&roots).attrs.as_slice().get(index as uint).map(|x| Unrooted::new(x.clone())) } - pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { + fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { let item = self.Item(index); *found = item.is_some(); item diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 74de0fe75d4..a8b75a75456 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -1395,7 +1395,7 @@ class CGImports(CGWrapper): """ Generates the appropriate import/use statements. """ - def __init__(self, child, imports): + def __init__(self, child, descriptors, imports): """ Adds a set of imports. """ @@ -1415,6 +1415,10 @@ class CGImports(CGWrapper): 'dead_code', ] + for d in descriptors: + name = d.interface.identifier.name + imports.append('dom::%s::%sMethods' % (name.lower(), name)) + statements = ['#![allow(%s)]' % ','.join(ignored_warnings)] statements.extend('use %s;' % i for i in sorted(imports)) @@ -2499,7 +2503,8 @@ class CGSpecializedMethod(CGAbstractExternMethod): return CGWrapper(CGMethodCall(argsPre, nativeName, self.method.isStatic(), self.descriptor, self.method), pre=extraPre + - " let this = &mut *this;\n").define() + " let this = JS::from_raw(this);\n" + + " let mut this = this.root(&roots);\n").define() class CGGenericGetter(CGAbstractBindingMethod): """ @@ -2558,7 +2563,8 @@ class CGSpecializedGetter(CGAbstractExternMethod): return CGWrapper(CGIndenter(CGGetterCall(argsPre, self.attr.type, nativeName, self.descriptor, self.attr)), pre=extraPre + - " let this = &mut *this;\n").define() + " let this = JS::from_raw(this);\n" + + " let mut this = this.root(&roots);\n").define() class CGGenericSetter(CGAbstractBindingMethod): """ @@ -2617,7 +2623,8 @@ class CGSpecializedSetter(CGAbstractExternMethod): return CGWrapper(CGIndenter(CGSetterCall(argsPre, self.attr.type, nativeName, self.descriptor, self.attr)), pre=extraPre + - " let this = &mut *this;\n").define() + " let this = JS::from_raw(this);\n" + + " let mut this = this.root(&roots);\n").define() class CGMemberJITInfo(CGThing): @@ -3508,14 +3515,14 @@ class CGProxyNamedSetter(CGProxySpecialOperation): class CGProxyUnwrap(CGAbstractMethod): def __init__(self, descriptor): args = [Argument('*JSObject', 'obj')] - CGAbstractMethod.__init__(self, descriptor, "UnwrapProxy", '*' + descriptor.concreteType, args, alwaysInline=True) + CGAbstractMethod.__init__(self, descriptor, "UnwrapProxy", '*mut ' + descriptor.concreteType, args, alwaysInline=True) def definition_body(self): return """ /*if (xpc::WrapperFactory::IsXrayWrapper(obj)) { obj = js::UnwrapObject(obj); }*/ //MOZ_ASSERT(IsProxy(obj)); - let box_: *%s = cast::transmute(GetProxyPrivate(obj).to_private()); + let box_: *mut %s = cast::transmute(GetProxyPrivate(obj).to_private()); return box_;""" % (self.descriptor.concreteType) class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): @@ -3540,9 +3547,11 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): templateValues = {'jsvalRef': '(*desc).value', 'successCode': fillDescriptor} get = ("if index.is_some() {\n" + " let index = index.unwrap();\n" + - " let this: *%s = UnwrapProxy(proxy);\n" + + " let this = UnwrapProxy(proxy);\n" + + " let this = JS::from_raw(this);\n" + + " let mut this = this.root(&roots);\n" + CGIndenter(CGProxyIndexedGetter(self.descriptor, templateValues)).define() + "\n" + - "}\n") % (self.descriptor.concreteType) + "}\n") if indexedSetter or self.descriptor.operations['NamedSetter']: setOrIndexedGet += "if set != 0 {\n" @@ -3585,9 +3594,11 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): namedGet = ("\n" + "if set == 0 && RUST_JSID_IS_STRING(id) != 0 && !HasPropertyOnPrototype(cx, proxy, id) {\n" + " let name = Some(jsid_to_str(cx, id));\n" + - " let this: *%s = UnwrapProxy(proxy);\n" + + " let this = UnwrapProxy(proxy);\n" + + " let this = JS::from_raw(this);\n" + + " let mut this = this.root(&roots);\n" + CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() + "\n" + - "}\n") % (self.descriptor.concreteType) + "}\n") else: namedGet = "" @@ -3628,10 +3639,12 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod): set += ("let index = GetArrayIndexFromId(cx, id);\n" + "if index.is_some() {\n" + " let index = index.unwrap();\n" + - " let this: *mut %s = UnwrapProxy(proxy) as *mut %s;\n" + + " let this = UnwrapProxy(proxy);\n" + + " let this = JS::from_raw(this);\n" + + " let mut this = this.root(&roots);\n" + CGIndenter(CGProxyIndexedSetter(self.descriptor)).define() + " return 1;\n" + - "}\n") % (self.descriptor.concreteType, self.descriptor.concreteType) + "}\n") elif self.descriptor.operations['IndexedGetter']: set += ("if GetArrayIndexFromId(cx, id).is_some() {\n" + " return 0;\n" + @@ -3644,20 +3657,24 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod): raise TypeError("Can't handle creator that's different from the setter") set += ("if RUST_JSID_IS_STRING(id) != 0 {\n" + " let name = Some(jsid_to_str(cx, id));\n" + - " let this: *%s = UnwrapProxy(proxy);\n" + + " let this = UnwrapProxy(proxy);\n" + + " let this = JS::from_raw(this);\n" + + " let mut this = this.root(&roots);\n" + CGIndenter(CGProxyNamedSetter(self.descriptor)).define() + "\n" + - "}\n") % (self.descriptor.concreteType) + "}\n") elif self.descriptor.operations['NamedGetter']: set += ("if RUST_JSID_IS_STRING(id) {\n" + " let name = Some(jsid_to_str(cx, id));\n" + - " let this: %%s = UnwrapProxy(proxy);\n" + + " let this = UnwrapProxy(proxy);\n" + + " let this = JS::from_raw(this);\n" + + " let mut this = this.root(&roots);\n" + CGIndenter(CGProxyNamedGetter(self.descriptor)).define() + " if (found) {\n" " return 0;\n" + " //return ThrowErrorMessage(cx, MSG_NO_PROPERTY_SETTER, \"%s\");\n" + " }\n" + " return 1;\n" - "}\n") % (self.descriptor.concreteType, self.descriptor.name) + "}\n") % (self.descriptor.name) return set + """return proxyhandler::defineProperty_(%s);""" % ", ".join(a.name for a in self.args) def definition_body(self): @@ -3675,11 +3692,13 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod): indexed = ("let index = GetArrayIndexFromId(cx, id);\n" + "if index.is_some() {\n" + " let index = index.unwrap();\n" + - " let this: *%s = UnwrapProxy(proxy);\n" + + " let this = UnwrapProxy(proxy);\n" + + " let this = JS::from_raw(this);\n" + + " let mut this = this.root(&roots);\n" + CGIndenter(CGProxyIndexedGetter(self.descriptor)).define() + "\n" + " *bp = found as JSBool;\n" + " return 1;\n" + - "}\n\n") % (self.descriptor.concreteType) + "}\n\n") else: indexed = "" @@ -3687,12 +3706,14 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod): if namedGetter: named = ("if RUST_JSID_IS_STRING(id) != 0 && !HasPropertyOnPrototype(cx, proxy, id) {\n" + " let name = Some(jsid_to_str(cx, id));\n" + - " let this: *%s = UnwrapProxy(proxy);\n" + + " let this = UnwrapProxy(proxy);\n" + + " let this = JS::from_raw(this);\n" + + " let mut this = this.root(&roots);\n" + CGIndenter(CGProxyNamedGetter(self.descriptor)).define() + "\n" + " *bp = found as JSBool;\n" " return 1;\n" "}\n" + - "\n") % (self.descriptor.concreteType) + "\n") else: named = "" @@ -3740,6 +3761,8 @@ if expando.is_not_null() { "if index.is_some() {\n" + " let index = index.unwrap();\n" + " let this = UnwrapProxy(proxy);\n" + + " let this = JS::from_raw(this);\n" + + " let mut this = this.root(&roots);\n" + CGIndenter(CGProxyIndexedGetter(self.descriptor, templateValues)).define()) getIndexedOrExpando += """ // Even if we don't have this index, we don't forward the @@ -3756,6 +3779,8 @@ if expando.is_not_null() { getNamed = ("if (JSID_IS_STRING(id)) {\n" + " let name = Some(jsid_to_str(cx, id));\n" + " let this = UnwrapProxy(proxy);\n" + + " let this = JS::from_raw(this);\n" + + " let mut this = this.root(&roots);\n" + CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() + "}\n") % (self.descriptor.concreteType) else: @@ -4288,7 +4313,7 @@ class CGBindingRoot(CGThing): # Add imports #XXXjdm This should only import the namespace for the current binding, # not every binding ever. - curr = CGImports(curr, [ + curr = CGImports(curr, descriptors, [ 'js', 'js::{JS_ARGV, JS_CALLEE, JS_THIS_OBJECT}', 'js::{JSCLASS_GLOBAL_SLOT_COUNT, JSCLASS_IS_DOMJSCLASS}', @@ -5253,7 +5278,7 @@ class GlobalGenRoots(): @staticmethod def RegisterBindings(config): # TODO - Generate the methods we want - return CGImports(CGRegisterProtos(config), [ + return CGImports(CGRegisterProtos(config), [], [ 'dom::bindings::codegen', 'dom::bindings::js::{JS, JSRef}', 'dom::window::Window', @@ -5372,7 +5397,7 @@ class GlobalGenRoots(): curr = UnionTypes(config.getDescriptors()) - curr = CGImports(curr, [ + curr = CGImports(curr, [], [ 'dom::bindings::utils::unwrap_jsmanaged', 'dom::bindings::codegen::PrototypeList', 'dom::bindings::conversions::{FromJSValConvertible, ToJSValConvertible}', diff --git a/src/components/script/dom/blob.rs b/src/components/script/dom/blob.rs index 0399568063d..a40715f00f2 100644 --- a/src/components/script/dom/blob.rs +++ b/src/components/script/dom/blob.rs @@ -28,28 +28,35 @@ impl Blob { window, BlobBinding::Wrap) } -} -impl Blob { pub fn Constructor(window: &JSRef) -> Fallible> { Ok(Blob::new(window)) } +} - pub fn Size(&self) -> u64 { +pub trait BlobMethods { + fn Size(&self) -> u64; + fn Type(&self) -> DOMString; + fn Slice(&self, _start: Option, _end: Option, _contentType: Option) -> Unrooted; + fn Close(&self); +} + +impl<'a> BlobMethods for JSRef<'a, Blob> { + fn Size(&self) -> u64 { 0 } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn Slice(&self, _start: Option, _end: Option, _contentType: Option) -> Unrooted { + fn Slice(&self, _start: Option, _end: Option, _contentType: Option) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); Blob::new(&window.root_ref()) } - pub fn Close(&self) {} + fn Close(&self) {} } impl Reflectable for Blob { diff --git a/src/components/script/dom/characterdata.rs b/src/components/script/dom/characterdata.rs index f85246ee12c..44962eea8a9 100644 --- a/src/components/script/dom/characterdata.rs +++ b/src/components/script/dom/characterdata.rs @@ -5,7 +5,7 @@ //! DOM bindings for `CharacterData`. use dom::bindings::codegen::InheritTypes::CharacterDataDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::{Fallible, ErrorResult, IndexSize}; use dom::bindings::utils::{Reflectable, Reflector}; use dom::document::Document; @@ -37,38 +37,51 @@ impl CharacterData { data: data } } +} - pub fn Data(&self) -> DOMString { +pub trait CharacterDataMethods { + fn Data(&self) -> DOMString; + fn SetData(&mut self, arg: DOMString) -> ErrorResult; + fn Length(&self) -> u32; + fn SubstringData(&self, offset: u32, count: u32) -> Fallible; + fn AppendData(&mut self, arg: DOMString) -> ErrorResult; + fn InsertData(&mut self, _offset: u32, _arg: DOMString) -> ErrorResult; + fn DeleteData(&mut self, _offset: u32, _count: u32) -> ErrorResult; + fn ReplaceData(&mut self, _offset: u32, _count: u32, _arg: DOMString) -> ErrorResult; +} + +impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> { + fn Data(&self) -> DOMString { self.data.clone() } - pub fn SetData(&mut self, arg: DOMString) -> ErrorResult { + fn SetData(&mut self, arg: DOMString) -> ErrorResult { self.data = arg; Ok(()) } - pub fn Length(&self) -> u32 { + fn Length(&self) -> u32 { self.data.len() as u32 } - pub fn SubstringData(&self, offset: u32, count: u32) -> Fallible { + fn SubstringData(&self, offset: u32, count: u32) -> Fallible { Ok(self.data.slice(offset as uint, count as uint).to_str()) } - pub fn AppendData(&mut self, arg: DOMString) -> ErrorResult { + fn AppendData(&mut self, arg: DOMString) -> ErrorResult { self.data.push_str(arg); Ok(()) } - pub fn InsertData(&mut self, offset: u32, arg: DOMString) -> ErrorResult { + fn InsertData(&mut self, offset: u32, arg: DOMString) -> ErrorResult { self.ReplaceData(offset, 0, arg) } - pub fn DeleteData(&mut self, offset: u32, count: u32) -> ErrorResult { + fn DeleteData(&mut self, offset: u32, count: u32) -> ErrorResult { self.ReplaceData(offset, count, ~"") } - pub fn ReplaceData(&mut self, offset: u32, count: u32, arg: DOMString) -> ErrorResult { + fn ReplaceData(&mut self, offset: u32, count: u32, arg: DOMString) -> ErrorResult { let length = self.data.len() as u32; if offset > length { return Err(IndexSize); diff --git a/src/components/script/dom/clientrect.rs b/src/components/script/dom/clientrect.rs index 4e4e2dbdcc6..8f07c6b8175 100644 --- a/src/components/script/dom/clientrect.rs +++ b/src/components/script/dom/clientrect.rs @@ -38,29 +38,39 @@ impl ClientRect { let rect = ClientRect::new_inherited(window.unrooted(), top, bottom, left, right); reflect_dom_object(~rect, window, ClientRectBinding::Wrap) } +} +pub trait ClientRectMethods { + fn Top(&self) -> f32; + fn Bottom(&self) -> f32; + fn Left(&self) -> f32; + fn Right(&self) -> f32; + fn Width(&self) -> f32; + fn Height(&self) -> f32; +} - pub fn Top(&self) -> f32 { +impl<'a> ClientRectMethods for JSRef<'a, ClientRect> { + fn Top(&self) -> f32 { self.top } - pub fn Bottom(&self) -> f32 { + fn Bottom(&self) -> f32 { self.bottom } - pub fn Left(&self) -> f32 { + fn Left(&self) -> f32 { self.left } - pub fn Right(&self) -> f32 { + fn Right(&self) -> f32 { self.right } - pub fn Width(&self) -> f32 { + fn Width(&self) -> f32 { (self.right - self.left).abs() } - pub fn Height(&self) -> f32 { + fn Height(&self) -> f32 { (self.bottom - self.top).abs() } } diff --git a/src/components/script/dom/clientrectlist.rs b/src/components/script/dom/clientrectlist.rs index a9beec896e8..30cbb1043e3 100644 --- a/src/components/script/dom/clientrectlist.rs +++ b/src/components/script/dom/clientrectlist.rs @@ -30,12 +30,20 @@ impl ClientRectList { reflect_dom_object(~ClientRectList::new_inherited(window.unrooted(), rects), window, ClientRectListBinding::Wrap) } +} - pub fn Length(&self) -> u32 { +pub trait ClientRectListMethods { + fn Length(&self) -> u32; + fn Item(&self, index: u32) -> Option>; + fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option>; +} + +impl<'a> ClientRectListMethods for JSRef<'a, ClientRectList> { + fn Length(&self) -> u32 { self.rects.len() as u32 } - pub fn Item(&self, index: u32) -> Option> { + fn Item(&self, index: u32) -> Option> { if index < self.rects.len() as u32 { Some(Unrooted::new(self.rects.get(index as uint).clone())) } else { @@ -43,7 +51,7 @@ impl ClientRectList { } } - pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { + fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { *found = index < self.rects.len() as u32; self.Item(index) } diff --git a/src/components/script/dom/comment.rs b/src/components/script/dom/comment.rs index 779fb6415e9..0814cb7b25c 100644 --- a/src/components/script/dom/comment.rs +++ b/src/components/script/dom/comment.rs @@ -10,7 +10,7 @@ use dom::characterdata::CharacterData; use dom::document::Document; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::node::{CommentNodeTypeId, Node}; -use dom::window::Window; +use dom::window::{Window, WindowMethods}; use servo_util::str::DOMString; /// An HTML comment. @@ -42,9 +42,10 @@ impl Comment { pub fn Constructor(owner: &JSRef, data: DOMString) -> Fallible> { let roots = RootCollection::new(); - let document = owner.get().Document(); - let document = document.root(&roots); - - Ok(Comment::new(data, &document.root_ref())) + let document = owner.Document().root(&roots); + Ok(Comment::new(data, &*document)) } } + +pub trait CommentMethods { +} diff --git a/src/components/script/dom/console.rs b/src/components/script/dom/console.rs index ce41ed45212..ce919980f26 100644 --- a/src/components/script/dom/console.rs +++ b/src/components/script/dom/console.rs @@ -23,24 +23,34 @@ impl Console { pub fn new(window: &JSRef) -> Unrooted { reflect_dom_object(~Console::new_inherited(), window, ConsoleBinding::Wrap) } +} - pub fn Log(&self, message: DOMString) { +pub trait ConsoleMethods { + fn Log(&self, message: DOMString); + fn Debug(&self, message: DOMString); + fn Info(&self, message: DOMString); + fn Warn(&self, message: DOMString); + fn Error(&self, message: DOMString); +} + +impl<'a> ConsoleMethods for JSRef<'a, Console> { + fn Log(&self, message: DOMString) { println!("{:s}", message); } - pub fn Debug(&self, message: DOMString) { + fn Debug(&self, message: DOMString) { println!("{:s}", message); } - pub fn Info(&self, message: DOMString) { + fn Info(&self, message: DOMString) { println!("{:s}", message); } - pub fn Warn(&self, message: DOMString) { + fn Warn(&self, message: DOMString) { println!("{:s}", message); } - pub fn Error(&self, message: DOMString) { + fn Error(&self, message: DOMString) { println!("{:s}", message); } } diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index d0ffb203282..f435b6186af 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -33,7 +33,7 @@ use dom::nodelist::NodeList; use dom::text::Text; use dom::processinginstruction::ProcessingInstruction; use dom::uievent::UIEvent; -use dom::window::Window; +use dom::window::{Window, WindowMethods}; use dom::location::Location; use html::hubbub_html_parser::build_element_from_tag; use hubbub::hubbub::{QuirksMode, NoQuirks, LimitedQuirks, FullQuirks}; @@ -122,22 +122,108 @@ impl Document { } } + // http://dom.spec.whatwg.org/#dom-document + pub fn Constructor(owner: &JSRef) -> Fallible> { + Ok(Document::new(owner, None, NonHTMLDocument, None)) + } + pub fn new(window: &JSRef, url: Option, doctype: IsHTMLDocument, content_type: Option) -> Unrooted { let document = Document::new_inherited(window.unrooted(), url, doctype, content_type); Document::reflect_document(~document, window, DocumentBinding::Wrap) } -} -impl Document { pub fn url<'a>(&'a self) -> &'a Url { &*self.url } -} -impl Document { - // http://dom.spec.whatwg.org/#dom-document - pub fn Constructor(owner: &JSRef) -> Fallible> { - Ok(Document::new(owner, None, NonHTMLDocument, None)) + pub fn quirks_mode(&self) -> QuirksMode { + *self.quirks_mode + } + + pub fn set_quirks_mode(&mut self, mode: QuirksMode) { + *self.quirks_mode = mode; + } + + pub fn set_encoding_name(&mut self, name: DOMString) { + self.encoding_name = name; + } + + pub fn content_changed(&self) { + self.damage_and_reflow(ContentChangedDocumentDamage); + } + + pub fn damage_and_reflow(&self, damage: DocumentDamageLevel) { + let roots = RootCollection::new(); + self.window.root(&roots).damage_and_reflow(damage); + } + + pub fn wait_until_safe_to_modify_dom(&self) { + let roots = RootCollection::new(); + self.window.root(&roots).wait_until_safe_to_modify_dom(); + } + + + /// Remove any existing association between the provided id and any elements in this document. + pub fn unregister_named_element(&mut self, + abstract_self: &JSRef, + id: DOMString) { + let roots = RootCollection::new(); + let mut is_empty = false; + match self.idmap.find_mut(&id) { + None => {}, + Some(elements) => { + let position = elements.iter() + .map(|elem| elem.root(&roots)) + .position(|element| &*element == abstract_self) + .expect("This element should be in registered."); + elements.remove(position); + is_empty = elements.is_empty(); + } + } + if is_empty { + self.idmap.remove(&id); + } + } + + /// Associate an element present in this document with the provided id. + pub fn register_named_element(&mut self, + abstract_self: &JSRef, + element: &JSRef, + id: DOMString) { + let roots = RootCollection::new(); + assert!({ + let node: &JSRef = NodeCast::from_ref(element); + node.is_in_doc() + }); + + // FIXME https://github.com/mozilla/rust/issues/13195 + // Use mangle() when it exists again. + let root = abstract_self.GetDocumentElement().expect("The element is in the document, so there must be a document element.").root(&roots); + match self.idmap.find_mut(&id) { + Some(elements) => { + let new_node: &JSRef = NodeCast::from_ref(element); + let mut head : uint = 0u; + let root: &JSRef = NodeCast::from_ref(&*root); + for node in root.traverse_preorder(&roots) { + let elem: Option<&JSRef> = ElementCast::to_ref(&node); + match elem { + Some(elem) => { + if elements.get(head) == &elem.unrooted() { + head = head + 1; + } + if new_node == &node || head == elements.len() { + break; + } + } + None => {} + } + } + elements.insert(head, element.unrooted()); + return; + }, + None => (), + } + self.idmap.insert(id, vec!(element.unrooted())); } } @@ -151,9 +237,87 @@ impl Reflectable for Document { } } -impl Document { +trait DocumentHelpers { + fn createNodeList(&self, callback: |node: &JSRef| -> bool) -> Unrooted; + fn get_html_element(&self) -> Option>; +} + +impl<'a> DocumentHelpers for JSRef<'a, Document> { + fn createNodeList(&self, callback: |node: &JSRef| -> bool) -> Unrooted { + let roots = RootCollection::new(); + let window = self.window.root(&roots); + + let mut nodes = vec!(); + match self.GetDocumentElement().root(&roots) { + None => {}, + Some(root) => { + let root: &JSRef = NodeCast::from_ref(&*root); + for child in root.traverse_preorder(&roots) { + if callback(&child) { + nodes.push(child); + } + } + } + } + + NodeList::new_simple_list(&*window, nodes) + } + + fn get_html_element(&self) -> Option> { + let roots = RootCollection::new(); + self.GetDocumentElement().root(&roots).filtered(|root| { + root.node.type_id == ElementNodeTypeId(HTMLHtmlElementTypeId) + }).map(|elem| { + Unrooted::new_rooted(HTMLHtmlElementCast::to_ref(&*elem).unwrap()) + }) + } +} + +pub trait DocumentMethods { + fn Implementation(&mut self) -> Unrooted; + fn URL(&self) -> DOMString; + fn DocumentURI(&self) -> DOMString; + fn CompatMode(&self) -> DOMString; + fn CharacterSet(&self) -> DOMString; + fn ContentType(&self) -> DOMString; + fn GetDoctype(&self) -> Option>; + fn GetDocumentElement(&self) -> Option>; + fn GetElementsByTagName(&self, abstract_self: &JSRef, tag_name: DOMString) -> Unrooted; + fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, tag_name: DOMString) -> Unrooted; + fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> Unrooted; + fn GetElementById(&self, id: DOMString) -> Option>; + fn CreateElement(&self, abstract_self: &JSRef, local_name: DOMString) -> Fallible>; + fn CreateElementNS(&self, abstract_self: &JSRef, + namespace: Option, + qualified_name: DOMString) -> Fallible>; + fn CreateDocumentFragment(&self, abstract_self: &JSRef) -> Unrooted; + fn CreateTextNode(&self, abstract_self: &JSRef, data: DOMString) -> Unrooted; + fn CreateComment(&self, abstract_self: &JSRef, data: DOMString) -> Unrooted; + fn CreateProcessingInstruction(&self, abstract_self: &JSRef, target: DOMString, data: DOMString) -> Fallible>; + fn ImportNode(&self, abstract_self: &JSRef, node: &JSRef, deep: bool) -> Fallible>; + fn AdoptNode(&self, abstract_self: &JSRef, node: &mut JSRef) -> Fallible>; + fn CreateEvent(&self, interface: DOMString) -> Fallible>; + fn Title(&self, _: &JSRef) -> DOMString; + fn SetTitle(&self, abstract_self: &JSRef, title: DOMString) -> ErrorResult; + fn GetHead(&self) -> Option>; + fn GetBody(&self, _: &JSRef) -> Option>; + fn SetBody(&self, abstract_self: &JSRef, new_body: Option>) -> ErrorResult; + fn GetElementsByName(&self, name: DOMString) -> Unrooted; + fn Images(&self, abstract_self: &JSRef) -> Unrooted; + fn Embeds(&self, abstract_self: &JSRef) -> Unrooted; + fn Plugins(&self, abstract_self: &JSRef) -> Unrooted; + fn Links(&self, abstract_self: &JSRef) -> Unrooted; + fn Forms(&self, abstract_self: &JSRef) -> Unrooted; + fn Scripts(&self, abstract_self: &JSRef) -> Unrooted; + fn Anchors(&self, abstract_self: &JSRef) -> Unrooted; + fn Applets(&self, abstract_self: &JSRef) -> Unrooted; + fn Location(&mut self, _abstract_self: &JSRef) -> Unrooted; + fn Children(&self, abstract_self: &JSRef) -> Unrooted; +} + +impl<'a> DocumentMethods for JSRef<'a, Document> { // http://dom.spec.whatwg.org/#dom-document-implementation - pub fn Implementation(&mut self) -> Unrooted { + fn Implementation(&mut self) -> Unrooted { if self.implementation.is_none() { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -163,47 +327,35 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-url - pub fn URL(&self) -> DOMString { + fn URL(&self) -> DOMString { self.url().to_str() } // http://dom.spec.whatwg.org/#dom-document-documenturi - pub fn DocumentURI(&self) -> DOMString { + fn DocumentURI(&self) -> DOMString { self.URL() } // http://dom.spec.whatwg.org/#dom-document-compatmode - pub fn CompatMode(&self) -> DOMString { + fn CompatMode(&self) -> DOMString { match *self.quirks_mode { NoQuirks => ~"CSS1Compat", LimitedQuirks | FullQuirks => ~"BackCompat" } } - pub fn quirks_mode(&self) -> QuirksMode { - *self.quirks_mode - } - - pub fn set_quirks_mode(&mut self, mode: QuirksMode) { - *self.quirks_mode = mode; - } - // http://dom.spec.whatwg.org/#dom-document-characterset - pub fn CharacterSet(&self) -> DOMString { + fn CharacterSet(&self) -> DOMString { self.encoding_name.to_ascii_lower() } - pub fn set_encoding_name(&mut self, name: DOMString) { - self.encoding_name = name; - } - // http://dom.spec.whatwg.org/#dom-document-content_type - pub fn ContentType(&self) -> DOMString { + fn ContentType(&self) -> DOMString { self.content_type.clone() } // http://dom.spec.whatwg.org/#dom-document-doctype - pub fn GetDoctype(&self) -> Option> { + fn GetDoctype(&self) -> Option> { self.node.children().find(|child| { child.is_doctype() }).map(|node| { @@ -213,19 +365,19 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-documentelement - pub fn GetDocumentElement(&self) -> Option> { + fn GetDocumentElement(&self) -> Option> { self.node.child_elements().next().map(|elem| Unrooted::new_rooted(&elem)) } // http://dom.spec.whatwg.org/#dom-document-getelementsbytagname - pub fn GetElementsByTagName(&self, abstract_self: &JSRef, tag_name: DOMString) -> Unrooted { + fn GetElementsByTagName(&self, abstract_self: &JSRef, tag_name: DOMString) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(abstract_self), tag_name) } // http://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens - pub fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, tag_name: DOMString) -> Unrooted { + fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, tag_name: DOMString) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -237,7 +389,7 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-getelementsbyclassname - pub fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> Unrooted { + fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -245,7 +397,7 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid - pub fn GetElementById(&self, id: DOMString) -> Option> { + fn GetElementById(&self, id: DOMString) -> Option> { match self.idmap.find_equiv(&id) { None => None, Some(ref elements) => Some(Unrooted::new(elements.get(0).clone())), @@ -253,7 +405,7 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-createelement - pub fn CreateElement(&self, abstract_self: &JSRef, local_name: DOMString) + fn CreateElement(&self, abstract_self: &JSRef, local_name: DOMString) -> Fallible> { if xml_name_type(local_name) == InvalidXMLName { debug!("Not a valid element name"); @@ -264,9 +416,9 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-createelementns - pub fn CreateElementNS(&self, abstract_self: &JSRef, - namespace: Option, - qualified_name: DOMString) -> Fallible> { + fn CreateElementNS(&self, abstract_self: &JSRef, + namespace: Option, + qualified_name: DOMString) -> Fallible> { let ns = Namespace::from_str(null_str_as_empty_ref(&namespace)); match xml_name_type(qualified_name) { InvalidXMLName => { @@ -310,23 +462,23 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-createdocumentfragment - pub fn CreateDocumentFragment(&self, abstract_self: &JSRef) -> Unrooted { + fn CreateDocumentFragment(&self, abstract_self: &JSRef) -> Unrooted { DocumentFragment::new(abstract_self) } // http://dom.spec.whatwg.org/#dom-document-createtextnode - pub fn CreateTextNode(&self, abstract_self: &JSRef, data: DOMString) + fn CreateTextNode(&self, abstract_self: &JSRef, data: DOMString) -> Unrooted { Text::new(data, abstract_self) } // http://dom.spec.whatwg.org/#dom-document-createcomment - pub fn CreateComment(&self, abstract_self: &JSRef, data: DOMString) -> Unrooted { + fn CreateComment(&self, abstract_self: &JSRef, data: DOMString) -> Unrooted { Comment::new(data, abstract_self) } // http://dom.spec.whatwg.org/#dom-document-createprocessinginstruction - pub fn CreateProcessingInstruction(&self, abstract_self: &JSRef, target: DOMString, + fn CreateProcessingInstruction(&self, abstract_self: &JSRef, target: DOMString, data: DOMString) -> Fallible> { // Step 1. if xml_name_type(target) == InvalidXMLName { @@ -343,7 +495,7 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-importnode - pub fn ImportNode(&self, abstract_self: &JSRef, node: &JSRef, deep: bool) -> Fallible> { + fn ImportNode(&self, abstract_self: &JSRef, node: &JSRef, deep: bool) -> Fallible> { // Step 1. if node.is_document() { return Err(NotSupported); @@ -359,7 +511,7 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-adoptnode - pub fn AdoptNode(&self, abstract_self: &JSRef, node: &mut JSRef) -> Fallible> { + fn AdoptNode(&self, abstract_self: &JSRef, node: &mut JSRef) -> Fallible> { // Step 1. if node.is_document() { return Err(NotSupported); @@ -373,7 +525,7 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-createevent - pub fn CreateEvent(&self, interface: DOMString) -> Fallible> { + fn CreateEvent(&self, interface: DOMString) -> Fallible> { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -387,7 +539,7 @@ impl Document { } // http://www.whatwg.org/specs/web-apps/current-work/#document.title - pub fn Title(&self, _: &JSRef) -> DOMString { + fn Title(&self, _: &JSRef) -> DOMString { let mut title = ~""; let roots = RootCollection::new(); self.GetDocumentElement().root(&roots).map(|root| { @@ -409,7 +561,7 @@ impl Document { } // http://www.whatwg.org/specs/web-apps/current-work/#document.title - pub fn SetTitle(&self, abstract_self: &JSRef, title: DOMString) -> ErrorResult { + fn SetTitle(&self, abstract_self: &JSRef, title: DOMString) -> ErrorResult { let roots = RootCollection::new(); self.GetDocumentElement().root(&roots).map(|root| { @@ -446,17 +598,8 @@ impl Document { Ok(()) } - fn get_html_element(&self) -> Option> { - let roots = RootCollection::new(); - self.GetDocumentElement().root(&roots).filtered(|root| { - root.node.type_id == ElementNodeTypeId(HTMLHtmlElementTypeId) - }).map(|elem| { - Unrooted::new_rooted(HTMLHtmlElementCast::to_ref(&*elem).unwrap()) - }) - } - // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-head - pub fn GetHead(&self) -> Option> { + fn GetHead(&self) -> Option> { let roots = RootCollection::new(); self.get_html_element().and_then(|root| { let root = root.root(&roots); @@ -470,7 +613,7 @@ impl Document { } // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body - pub fn GetBody(&self, _: &JSRef) -> Option> { + fn GetBody(&self, _: &JSRef) -> Option> { let roots = RootCollection::new(); self.get_html_element().and_then(|root| { let root = root.root(&roots); @@ -488,7 +631,7 @@ impl Document { } // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body - pub fn SetBody(&self, abstract_self: &JSRef, new_body: Option>) -> ErrorResult { + fn SetBody(&self, abstract_self: &JSRef, new_body: Option>) -> ErrorResult { let roots = RootCollection::new(); // Step 1. @@ -532,7 +675,7 @@ impl Document { } // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-getelementsbyname - pub fn GetElementsByName(&self, name: DOMString) -> Unrooted { + fn GetElementsByName(&self, name: DOMString) -> Unrooted { let roots = RootCollection::new(); self.createNodeList(|node| { @@ -547,7 +690,7 @@ impl Document { }) } - pub fn Images(&self, abstract_self: &JSRef) -> Unrooted { + fn Images(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -562,7 +705,7 @@ impl Document { HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) } - pub fn Embeds(&self, abstract_self: &JSRef) -> Unrooted { + fn Embeds(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -577,12 +720,12 @@ impl Document { HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) } - pub fn Plugins(&self, abstract_self: &JSRef) -> Unrooted { + fn Plugins(&self, abstract_self: &JSRef) -> Unrooted { // FIXME: https://github.com/mozilla/servo/issues/1847 self.Embeds(abstract_self) } - pub fn Links(&self, abstract_self: &JSRef) -> Unrooted { + fn Links(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -598,7 +741,7 @@ impl Document { HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) } - pub fn Forms(&self, abstract_self: &JSRef) -> Unrooted { + fn Forms(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -613,7 +756,7 @@ impl Document { HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) } - pub fn Scripts(&self, abstract_self: &JSRef) -> Unrooted { + fn Scripts(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -628,7 +771,7 @@ impl Document { HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) } - pub fn Anchors(&self, abstract_self: &JSRef) -> Unrooted { + fn Anchors(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -643,7 +786,7 @@ impl Document { HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) } - pub fn Applets(&self, abstract_self: &JSRef) -> Unrooted { + fn Applets(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -658,113 +801,16 @@ impl Document { HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) } - pub fn Location(&mut self, _abstract_self: &JSRef) -> Unrooted { + fn Location(&mut self, _abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let mut window = self.window.root(&roots); let window_alias = self.window.root(&roots); - window.get_mut().Location(&*window_alias) + window.Location(&*window_alias) } - pub fn Children(&self, abstract_self: &JSRef) -> Unrooted { + fn Children(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); HTMLCollection::children(&*window, NodeCast::from_ref(abstract_self)) } - - pub fn createNodeList(&self, callback: |node: &JSRef| -> bool) -> Unrooted { - let roots = RootCollection::new(); - let window = self.window.root(&roots); - - let mut nodes = vec!(); - match self.GetDocumentElement().root(&roots) { - None => {}, - Some(root) => { - let root: &JSRef = NodeCast::from_ref(&*root); - for child in root.traverse_preorder(&roots) { - if callback(&child) { - nodes.push(child); - } - } - } - } - - NodeList::new_simple_list(&*window, nodes) - } - - pub fn content_changed(&self) { - self.damage_and_reflow(ContentChangedDocumentDamage); - } - - pub fn damage_and_reflow(&self, damage: DocumentDamageLevel) { - let roots = RootCollection::new(); - self.window.root(&roots).damage_and_reflow(damage); - } - - pub fn wait_until_safe_to_modify_dom(&self) { - let roots = RootCollection::new(); - self.window.root(&roots).wait_until_safe_to_modify_dom(); - } - - - /// Remove any existing association between the provided id and any elements in this document. - pub fn unregister_named_element(&mut self, - abstract_self: &JSRef, - id: DOMString) { - let roots = RootCollection::new(); - let mut is_empty = false; - match self.idmap.find_mut(&id) { - None => {}, - Some(elements) => { - let position = elements.iter() - .map(|elem| elem.root(&roots)) - .position(|element| &*element == abstract_self) - .expect("This element should be in registered."); - elements.remove(position); - is_empty = elements.is_empty(); - } - } - if is_empty { - self.idmap.remove(&id); - } - } - - /// Associate an element present in this document with the provided id. - pub fn register_named_element(&mut self, - element: &JSRef, - id: DOMString) { - let roots = RootCollection::new(); - assert!({ - let node: &JSRef = NodeCast::from_ref(element); - node.is_in_doc() - }); - - // FIXME https://github.com/mozilla/rust/issues/13195 - // Use mangle() when it exists again. - let root = self.GetDocumentElement().expect("The element is in the document, so there must be a document element.").root(&roots); - match self.idmap.find_mut(&id) { - Some(elements) => { - let new_node: &JSRef = NodeCast::from_ref(element); - let mut head : uint = 0u; - let root: &JSRef = NodeCast::from_ref(&*root); - for node in root.traverse_preorder(&roots) { - let elem: Option<&JSRef> = ElementCast::to_ref(&node); - match elem { - Some(elem) => { - if elements.get(head) == &elem.unrooted() { - head = head + 1; - } - if new_node == &node || head == elements.len() { - break; - } - } - None => {} - } - } - elements.insert(head, element.unrooted()); - return; - }, - None => (), - } - self.idmap.insert(id, vec!(element.unrooted())); - } } diff --git a/src/components/script/dom/documentfragment.rs b/src/components/script/dom/documentfragment.rs index 629b68ffdec..aee61d03b51 100644 --- a/src/components/script/dom/documentfragment.rs +++ b/src/components/script/dom/documentfragment.rs @@ -10,7 +10,7 @@ use dom::document::Document; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlcollection::HTMLCollection; use dom::node::{DocumentFragmentNodeTypeId, Node, window_from_node}; -use dom::window::Window; +use dom::window::{Window, WindowMethods}; #[deriving(Encodable)] pub struct DocumentFragment { @@ -38,20 +38,22 @@ impl DocumentFragment { let node = DocumentFragment::new_inherited(document.unrooted()); Node::reflect_node(~node, document, DocumentFragmentBinding::Wrap) } -} -impl DocumentFragment { pub fn Constructor(owner: &JSRef) -> Fallible> { let roots = RootCollection::new(); - let document = owner.get().Document(); + let document = owner.Document(); let document = document.root(&roots); Ok(DocumentFragment::new(&document.root_ref())) } } -impl DocumentFragment { - pub fn Children(&self, abstract_self: &JSRef) -> Unrooted { +pub trait DocumentFragmentMethods { + fn Children(&self, abstract_self: &JSRef) -> Unrooted; +} + +impl<'a> DocumentFragmentMethods for JSRef<'a, DocumentFragment> { + fn Children(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = window_from_node(abstract_self).root(&roots); HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self)) diff --git a/src/components/script/dom/documenttype.rs b/src/components/script/dom/documenttype.rs index 21b1a784456..26772db65ec 100644 --- a/src/components/script/dom/documenttype.rs +++ b/src/components/script/dom/documenttype.rs @@ -55,16 +55,23 @@ impl DocumentType { } } -impl DocumentType { - pub fn Name(&self) -> DOMString { +pub trait DocumentTypeMethods { + fn Name(&self) -> DOMString; + fn PublicId(&self) -> DOMString; + fn SystemId(&self) -> DOMString; +} + +impl<'a> DocumentTypeMethods for JSRef<'a, DocumentType> { + fn Name(&self) -> DOMString { self.name.clone() } - pub fn PublicId(&self) -> DOMString { + fn PublicId(&self) -> DOMString { self.public_id.clone() } - pub fn SystemId(&self) -> DOMString { + fn SystemId(&self) -> DOMString { self.system_id.clone() } } + diff --git a/src/components/script/dom/domexception.rs b/src/components/script/dom/domexception.rs index 08a8c364deb..78d43b047f1 100644 --- a/src/components/script/dom/domexception.rs +++ b/src/components/script/dom/domexception.rs @@ -64,9 +64,15 @@ impl Reflectable for DOMException { } } -impl DOMException { +pub trait DOMExceptionMethods { + fn Code(&self) -> u16; + fn Name(&self) -> DOMString; + fn Message(&self) -> DOMString; +} + +impl<'a> DOMExceptionMethods for JSRef<'a, DOMException> { // http://dom.spec.whatwg.org/#dom-domexception-code - pub fn Code(&self) -> u16 { + fn Code(&self) -> u16 { match self.code { // http://dom.spec.whatwg.org/#concept-throw EncodingError => 0, @@ -75,12 +81,12 @@ impl DOMException { } // http://dom.spec.whatwg.org/#error-names-0 - pub fn Name(&self) -> DOMString { + fn Name(&self) -> DOMString { self.code.to_str() } // http://dom.spec.whatwg.org/#error-names-0 - pub fn Message(&self) -> DOMString { + fn Message(&self) -> DOMString { match self.code { IndexSizeError => ~"The index is not in the allowed range.", HierarchyRequestError => ~"The operation would yield an incorrect node tree.", diff --git a/src/components/script/dom/domimplementation.rs b/src/components/script/dom/domimplementation.rs index 0e824306343..a8f889ddd8c 100644 --- a/src/components/script/dom/domimplementation.rs +++ b/src/components/script/dom/domimplementation.rs @@ -8,7 +8,7 @@ use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, 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}; +use dom::document::{Document, HTMLDocument, NonHTMLDocument, DocumentMethods}; use dom::documenttype::DocumentType; use dom::htmlbodyelement::HTMLBodyElement; use dom::htmlheadelement::HTMLHeadElement; @@ -16,7 +16,7 @@ use dom::htmlhtmlelement::HTMLHtmlElement; use dom::htmltitleelement::HTMLTitleElement; use dom::node::{Node, AppendChild}; use dom::text::Text; -use dom::window::Window; +use dom::window::{Window, WindowMethods}; use servo_util::str::DOMString; #[deriving(Encodable)] @@ -49,10 +49,17 @@ impl Reflectable for DOMImplementation { } } +pub trait DOMImplementationMethods { + fn CreateDocumentType(&self, qname: DOMString, pubid: DOMString, sysid: DOMString) -> Fallible>; + fn CreateDocument(&self, namespace: Option, qname: DOMString, + mut maybe_doctype: Option>) -> Fallible>; + fn CreateHTMLDocument(&self, title: Option) -> Unrooted; +} + // http://dom.spec.whatwg.org/#domimplementation -impl DOMImplementation { +impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { // http://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype - pub fn CreateDocumentType(&self, qname: DOMString, pubid: DOMString, sysid: DOMString) -> Fallible> { + fn CreateDocumentType(&self, qname: DOMString, pubid: DOMString, sysid: DOMString) -> Fallible> { let roots = RootCollection::new(); match xml_name_type(qname) { // Step 1. @@ -69,8 +76,8 @@ impl DOMImplementation { } // http://dom.spec.whatwg.org/#dom-domimplementation-createdocument - pub fn CreateDocument(&self, namespace: Option, qname: DOMString, - mut maybe_doctype: Option>) -> Fallible> { + fn CreateDocument(&self, namespace: Option, qname: DOMString, + mut maybe_doctype: Option>) -> Fallible> { let roots = RootCollection::new(); let win = self.owner.root(&roots); @@ -80,7 +87,7 @@ impl DOMImplementation { let mut maybe_elem = if qname.is_empty() { None } else { - match doc.get().CreateElementNS(&*doc, namespace, qname) { + match doc.deref().CreateElementNS(&*doc, namespace, qname) { Err(error) => return Err(error), Ok(elem) => Some(elem) } @@ -114,7 +121,7 @@ impl DOMImplementation { } // http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument - pub fn CreateHTMLDocument(&self, title: Option) -> Unrooted { + fn CreateHTMLDocument(&self, title: Option) -> Unrooted { let roots = RootCollection::new(); let owner = self.owner.root(&roots); diff --git a/src/components/script/dom/domparser.rs b/src/components/script/dom/domparser.rs index 6d77273e11e..9f8785e6fd7 100644 --- a/src/components/script/dom/domparser.rs +++ b/src/components/script/dom/domparser.rs @@ -33,11 +33,17 @@ impl DOMParser { pub fn Constructor(owner: &JSRef) -> Fallible> { Ok(DOMParser::new(owner)) } +} - pub fn ParseFromString(&self, - _s: DOMString, - ty: DOMParserBinding::SupportedType) - -> Fallible> { +pub trait DOMParserMethods { + fn ParseFromString(&self, _s: DOMString, ty: DOMParserBinding::SupportedType) -> Fallible>; +} + +impl<'a> DOMParserMethods for JSRef<'a, DOMParser> { + fn ParseFromString(&self, + _s: DOMString, + ty: DOMParserBinding::SupportedType) + -> Fallible> { let roots = RootCollection::new(); let owner = self.owner.root(&roots); match ty { diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index a3bdeb22d3e..2a66aec0221 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -4,7 +4,7 @@ //! Element nodes. -use dom::attr::{Attr, ReplacedAttr, FirstSetAttr}; +use dom::attr::{Attr, ReplacedAttr, FirstSetAttr, AttrMethods}; use dom::attrlist::AttrList; use dom::bindings::codegen::BindingDeclarations::ElementBinding; use dom::bindings::codegen::InheritTypes::{ElementDerived, NodeCast}; @@ -458,23 +458,51 @@ impl Element { } } -impl Element { +pub trait ElementMethods { + fn NamespaceURI(&self) -> DOMString; + fn LocalName(&self) -> DOMString; + fn GetPrefix(&self) -> Option; + fn TagName(&self) -> DOMString; + fn Id(&self, abstract_self: &JSRef) -> DOMString; + fn SetId(&mut self, abstract_self: &mut JSRef, id: DOMString); + fn ClassName(&self, abstract_self: &JSRef) -> DOMString; + fn SetClassName(&self, abstract_self: &mut JSRef, class: DOMString); + fn Attributes(&mut self, abstract_self: &JSRef) -> Unrooted; + fn GetAttribute(&self, abstract_self: &JSRef, name: DOMString) -> Option; + fn GetAttributeNS(&self, abstract_self: &JSRef, namespace: Option, local_name: DOMString) -> Option; + fn SetAttribute(&self, abstract_self: &mut JSRef, name: DOMString, value: DOMString) -> ErrorResult; + fn SetAttributeNS(&self, abstract_self: &mut JSRef, namespace_url: Option, name: DOMString, value: DOMString) -> ErrorResult; + fn RemoveAttribute(&mut self, abstract_self: &mut JSRef, name: DOMString) -> ErrorResult; + fn RemoveAttributeNS(&mut self, abstract_self: &mut JSRef, namespace: Option, localname: DOMString) -> ErrorResult; + fn HasAttribute(&self, abstract_self: &JSRef, name: DOMString) -> bool; + fn HasAttributeNS(&self, abstract_self: &JSRef, namespace: Option, local_name: DOMString) -> bool; + fn GetElementsByTagName(&self, abstract_self: &JSRef, localname: DOMString) -> Unrooted; + fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, localname: DOMString) -> Unrooted; + fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> Unrooted; + fn GetClientRects(&self, abstract_self: &JSRef) -> Unrooted; + fn GetBoundingClientRect(&self, abstract_self: &JSRef) -> Unrooted; + fn GetInnerHTML(&self, abstract_self: &JSRef) -> Fallible; + fn GetOuterHTML(&self, abstract_self: &JSRef) -> Fallible; + fn Children(&self, abstract_self: &JSRef) -> Unrooted; +} + +impl<'a> ElementMethods for JSRef<'a, Element> { // http://dom.spec.whatwg.org/#dom-element-namespaceuri - pub fn NamespaceURI(&self) -> DOMString { + fn NamespaceURI(&self) -> DOMString { self.namespace.to_str().to_owned() } - pub fn LocalName(&self) -> DOMString { + fn LocalName(&self) -> DOMString { self.local_name.clone() } // http://dom.spec.whatwg.org/#dom-element-prefix - pub fn GetPrefix(&self) -> Option { + fn GetPrefix(&self) -> Option { self.prefix.clone() } // http://dom.spec.whatwg.org/#dom-element-tagname - pub fn TagName(&self) -> DOMString { + fn TagName(&self) -> DOMString { match self.prefix { None => { self.local_name.to_ascii_upper() @@ -486,42 +514,42 @@ impl Element { } // http://dom.spec.whatwg.org/#dom-element-id - pub fn Id(&self, abstract_self: &JSRef) -> DOMString { + fn Id(&self, abstract_self: &JSRef) -> DOMString { abstract_self.get_string_attribute("id") } // http://dom.spec.whatwg.org/#dom-element-id - pub fn SetId(&mut self, abstract_self: &mut JSRef, id: DOMString) { + fn SetId(&mut self, abstract_self: &mut JSRef, id: DOMString) { abstract_self.set_string_attribute("id", id); } // http://dom.spec.whatwg.org/#dom-element-classname - pub fn ClassName(&self, abstract_self: &JSRef) -> DOMString { + fn ClassName(&self, abstract_self: &JSRef) -> DOMString { abstract_self.get_string_attribute("class") } // http://dom.spec.whatwg.org/#dom-element-classname - pub fn SetClassName(&self, abstract_self: &mut JSRef, class: DOMString) { + fn SetClassName(&self, abstract_self: &mut JSRef, class: DOMString) { abstract_self.set_string_attribute("class", class); } // http://dom.spec.whatwg.org/#dom-element-attributes - pub fn Attributes(&mut self, abstract_self: &JSRef) -> Unrooted { + fn Attributes(&mut self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); match self.attr_list { - None => { - let doc = self.node.owner_doc().root(&roots); - let window = doc.deref().window.root(&roots); - let list = AttrList::new(&window.root_ref(), abstract_self); - self.attr_list.assign(Some(list)); - Unrooted::new(self.attr_list.get_ref().clone()) - } - Some(ref list) => Unrooted::new(list.clone()) + None => (), + Some(ref list) => return Unrooted::new(list.clone()), } + + let doc = self.node.owner_doc().root(&roots); + let window = doc.deref().window.root(&roots); + let list = AttrList::new(&window.root_ref(), abstract_self); + self.attr_list.assign(Some(list)); + Unrooted::new(self.attr_list.get_ref().clone()) } // http://dom.spec.whatwg.org/#dom-element-getattribute - pub fn GetAttribute(&self, abstract_self: &JSRef, name: DOMString) -> Option { + fn GetAttribute(&self, abstract_self: &JSRef, name: DOMString) -> Option { let roots = RootCollection::new(); let name = if abstract_self.get().html_element_in_html_document() { name.to_ascii_lower() @@ -533,7 +561,7 @@ impl Element { } // http://dom.spec.whatwg.org/#dom-element-getattributens - pub fn GetAttributeNS(&self, abstract_self: &JSRef, + fn GetAttributeNS(&self, abstract_self: &JSRef, namespace: Option, local_name: DOMString) -> Option { let roots = RootCollection::new(); @@ -543,25 +571,25 @@ impl Element { } // http://dom.spec.whatwg.org/#dom-element-setattribute - pub fn SetAttribute(&self, abstract_self: &mut JSRef, - name: DOMString, - value: DOMString) -> ErrorResult { + fn SetAttribute(&self, abstract_self: &mut JSRef, + name: DOMString, + value: DOMString) -> ErrorResult { abstract_self.SetAttribute_(name, value) } // http://dom.spec.whatwg.org/#dom-element-setattributens - pub fn SetAttributeNS(&self, - abstract_self: &mut JSRef, - namespace_url: Option, - name: DOMString, - value: DOMString) -> ErrorResult { + fn SetAttributeNS(&self, + abstract_self: &mut JSRef, + namespace_url: Option, + name: DOMString, + value: DOMString) -> ErrorResult { abstract_self.SetAttributeNS_(namespace_url, name, value) } // http://dom.spec.whatwg.org/#dom-element-removeattribute - pub fn RemoveAttribute(&mut self, - abstract_self: &mut JSRef, - name: DOMString) -> ErrorResult { + fn RemoveAttribute(&mut self, + abstract_self: &mut JSRef, + name: DOMString) -> ErrorResult { let name = if self.html_element_in_html_document() { name.to_ascii_lower() } else { @@ -571,7 +599,7 @@ impl Element { } // http://dom.spec.whatwg.org/#dom-element-removeattributens - pub fn RemoveAttributeNS(&mut self, + fn RemoveAttributeNS(&mut self, abstract_self: &mut JSRef, namespace: Option, localname: DOMString) -> ErrorResult { @@ -580,25 +608,25 @@ impl Element { } // http://dom.spec.whatwg.org/#dom-element-hasattribute - pub fn HasAttribute(&self, abstract_self: &JSRef, + fn HasAttribute(&self, abstract_self: &JSRef, name: DOMString) -> bool { self.GetAttribute(abstract_self, name).is_some() } // http://dom.spec.whatwg.org/#dom-element-hasattributens - pub fn HasAttributeNS(&self, abstract_self: &JSRef, + fn HasAttributeNS(&self, abstract_self: &JSRef, namespace: Option, local_name: DOMString) -> bool { self.GetAttributeNS(abstract_self, namespace, local_name).is_some() } - pub fn GetElementsByTagName(&self, abstract_self: &JSRef, localname: DOMString) -> Unrooted { + fn GetElementsByTagName(&self, abstract_self: &JSRef, localname: DOMString) -> Unrooted { let roots = RootCollection::new(); let window = window_from_node(abstract_self).root(&roots); HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(abstract_self), localname) } - pub fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, + fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, localname: DOMString) -> Unrooted { let roots = RootCollection::new(); let namespace = match maybe_ns { @@ -609,14 +637,14 @@ impl Element { HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(abstract_self), localname, namespace) } - pub fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> Unrooted { + fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> Unrooted { let roots = RootCollection::new(); let window = window_from_node(abstract_self).root(&roots); HTMLCollection::by_class_name(&*window, NodeCast::from_ref(abstract_self), classes) } // http://dev.w3.org/csswg/cssom-view/#dom-element-getclientrects - pub fn GetClientRects(&self, abstract_self: &JSRef) -> Unrooted { + fn GetClientRects(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let win = window_from_node(abstract_self).root(&roots); let node: &JSRef = NodeCast::from_ref(abstract_self); @@ -634,7 +662,7 @@ impl Element { } // http://dev.w3.org/csswg/cssom-view/#dom-element-getboundingclientrect - pub fn GetBoundingClientRect(&self, abstract_self: &JSRef) -> Unrooted { + fn GetBoundingClientRect(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let win = window_from_node(abstract_self).root(&roots); let node: &JSRef = NodeCast::from_ref(abstract_self); @@ -647,18 +675,18 @@ impl Element { rect.origin.x + rect.size.width) } - pub fn GetInnerHTML(&self, abstract_self: &JSRef) -> Fallible { + fn GetInnerHTML(&self, abstract_self: &JSRef) -> Fallible { //XXX TODO: XML case let roots = RootCollection::new(); Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(abstract_self), false, false))) } - pub fn GetOuterHTML(&self, abstract_self: &JSRef) -> Fallible { + fn GetOuterHTML(&self, abstract_self: &JSRef) -> Fallible { let roots = RootCollection::new(); Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(abstract_self), true, false))) } - pub fn Children(&self, abstract_self: &JSRef) -> Unrooted { + fn Children(&self, abstract_self: &JSRef) -> Unrooted { let roots = RootCollection::new(); let window = window_from_node(abstract_self).root(&roots); HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self)) @@ -701,7 +729,8 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { let node: &JSRef = NodeCast::from_ref(self); if node.is_in_doc() { let mut doc = document_from_node(self).root(&roots); - doc.register_named_element(self, value.clone()); + let doc_alias = (*doc).clone(); + doc.register_named_element(&doc_alias, self, value.clone()); } } _ => () @@ -744,7 +773,8 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { match self.get_attribute(Null, "id").root(&roots) { Some(attr) => { let mut doc = document_from_node(self).root(&roots); - doc.register_named_element(self, attr.deref().Value()); + let doc_alias = (*doc).clone(); + doc.register_named_element(&doc_alias, self, attr.deref().Value()); } _ => () } diff --git a/src/components/script/dom/event.rs b/src/components/script/dom/event.rs index 68f83a5d509..08fdc818ed6 100644 --- a/src/components/script/dom/event.rs +++ b/src/components/script/dom/event.rs @@ -86,54 +86,81 @@ impl Event { EventBinding::Wrap) } - pub fn EventPhase(&self) -> u16 { + pub fn Constructor(global: &JSRef, + type_: DOMString, + init: &EventBinding::EventInit) -> Fallible> { + let roots = RootCollection::new(); + let mut ev = Event::new(global).root(&roots); + ev.InitEvent(type_, init.bubbles, init.cancelable); + Ok(Unrooted::new_rooted(&*ev)) + } +} + +pub trait EventMethods { + fn EventPhase(&self) -> u16; + fn Type(&self) -> DOMString; + fn GetTarget(&self) -> Option>; + fn GetCurrentTarget(&self) -> Option>; + fn DefaultPrevented(&self) -> bool; + fn PreventDefault(&mut self); + fn StopPropagation(&mut self); + fn StopImmediatePropagation(&mut self); + fn Bubbles(&self) -> bool; + fn Cancelable(&self) -> bool; + fn TimeStamp(&self) -> u64; + fn InitEvent(&mut self, type_: DOMString, bubbles: bool, cancelable: bool); + fn IsTrusted(&self) -> bool; +} + +impl<'a> EventMethods for JSRef<'a, Event> { + fn EventPhase(&self) -> u16 { self.phase as u16 } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { self.type_.clone() } - pub fn GetTarget(&self) -> Option> { + fn GetTarget(&self) -> Option> { self.target.as_ref().map(|target| Unrooted::new(target.clone())) } - pub fn GetCurrentTarget(&self) -> Option> { + fn GetCurrentTarget(&self) -> Option> { self.current_target.as_ref().map(|target| Unrooted::new(target.clone())) } - pub fn DefaultPrevented(&self) -> bool { + fn DefaultPrevented(&self) -> bool { self.canceled } - pub fn PreventDefault(&mut self) { + fn PreventDefault(&mut self) { if self.cancelable { self.canceled = true } } - pub fn StopPropagation(&mut self) { + fn StopPropagation(&mut self) { self.stop_propagation = true; } - pub fn StopImmediatePropagation(&mut self) { + fn StopImmediatePropagation(&mut self) { self.stop_immediate = true; self.stop_propagation = true; } - pub fn Bubbles(&self) -> bool { + fn Bubbles(&self) -> bool { self.bubbles } - pub fn Cancelable(&self) -> bool { + fn Cancelable(&self) -> bool { self.cancelable } - pub fn TimeStamp(&self) -> u64 { + fn TimeStamp(&self) -> u64 { self.timestamp } - pub fn InitEvent(&mut self, + fn InitEvent(&mut self, type_: DOMString, bubbles: bool, cancelable: bool) { @@ -151,18 +178,9 @@ impl Event { self.cancelable = cancelable; } - pub fn IsTrusted(&self) -> bool { + fn IsTrusted(&self) -> bool { self.trusted } - - pub fn Constructor(global: &JSRef, - type_: DOMString, - init: &EventBinding::EventInit) -> Fallible> { - let roots = RootCollection::new(); - let mut ev = Event::new(global).root(&roots); - ev.InitEvent(type_, init.bubbles, init.cancelable); - Ok(Unrooted::new_rooted(&*ev)) - } } impl Reflectable for Event { diff --git a/src/components/script/dom/eventdispatcher.rs b/src/components/script/dom/eventdispatcher.rs index 9d45b398e02..a70533da2a1 100644 --- a/src/components/script/dom/eventdispatcher.rs +++ b/src/components/script/dom/eventdispatcher.rs @@ -6,7 +6,7 @@ use dom::bindings::callback::ReportExceptions; use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, NodeDerived}; use dom::bindings::js::{JSRef, OptionalAssignable, RootCollection, Root}; use dom::eventtarget::{Capturing, Bubbling, EventTarget}; -use dom::event::{Event, PhaseAtTarget, PhaseNone, PhaseBubbling, PhaseCapturing}; +use dom::event::{Event, PhaseAtTarget, PhaseNone, PhaseBubbling, PhaseCapturing, EventMethods}; use dom::node::{Node, NodeHelpers}; // See http://dom.spec.whatwg.org/#concept-event-dispatch for the full dispatch algorithm @@ -119,7 +119,6 @@ pub fn dispatch_event<'a>(target: &JSRef<'a, EventTarget>, let _ = chain.pop(); } - let event = event.get_mut(); event.dispatching = false; event.phase = PhaseNone; event.current_target = None; diff --git a/src/components/script/dom/eventtarget.rs b/src/components/script/dom/eventtarget.rs index 67dc0ac7af9..d743a011227 100644 --- a/src/components/script/dom/eventtarget.rs +++ b/src/components/script/dom/eventtarget.rs @@ -65,10 +65,35 @@ impl EventTarget { }) } - pub fn AddEventListener(&mut self, - ty: DOMString, - listener: Option, - capture: bool) { + pub fn dispatch_event_with_target<'a>(&self, + abstract_self: &JSRef<'a, EventTarget>, + abstract_target: Option>, + event: &mut JSRef) -> Fallible { + if event.get().dispatching || !event.get().initialized { + return Err(InvalidState); + } + Ok(dispatch_event(abstract_self, abstract_target, event)) + } +} + +pub trait EventTargetMethods { + fn AddEventListener(&mut self, + ty: DOMString, + listener: Option, + capture: bool); + fn RemoveEventListener(&mut self, + ty: DOMString, + listener: Option, + capture: bool); + fn DispatchEvent(&self, abstract_self: &JSRef, + event: &mut JSRef) -> Fallible; +} + +impl<'a> EventTargetMethods for JSRef<'a, EventTarget> { + fn AddEventListener(&mut self, + ty: DOMString, + listener: Option, + capture: bool) { for &listener in listener.iter() { let entry = self.handlers.find_or_insert_with(ty.clone(), |_| vec!()); let phase = if capture { Capturing } else { Bubbling }; @@ -82,10 +107,10 @@ impl EventTarget { } } - pub fn RemoveEventListener(&mut self, - ty: DOMString, - listener: Option, - capture: bool) { + fn RemoveEventListener(&mut self, + ty: DOMString, + listener: Option, + capture: bool) { for &listener in listener.iter() { let mut entry = self.handlers.find_mut(&ty); for entry in entry.mut_iter() { @@ -102,20 +127,10 @@ impl EventTarget { } } - pub fn DispatchEvent(&self, abstract_self: &JSRef, - event: &mut JSRef) -> Fallible { + fn DispatchEvent(&self, abstract_self: &JSRef, + event: &mut JSRef) -> Fallible { self.dispatch_event_with_target(abstract_self, None, event) } - - pub fn dispatch_event_with_target<'a>(&self, - abstract_self: &JSRef<'a, EventTarget>, - abstract_target: Option>, - event: &mut JSRef) -> Fallible { - if event.get().dispatching || !event.get().initialized { - return Err(InvalidState); - } - Ok(dispatch_event(abstract_self, abstract_target, event)) - } } impl Reflectable for EventTarget { diff --git a/src/components/script/dom/formdata.rs b/src/components/script/dom/formdata.rs index e1a7b0e7ddb..88be3e4314e 100644 --- a/src/components/script/dom/formdata.rs +++ b/src/components/script/dom/formdata.rs @@ -41,12 +41,18 @@ impl FormData { reflect_dom_object(~FormData::new_inherited(form, window.unrooted()), window, FormDataBinding::Wrap) } - pub fn Constructor(window: &JSRef, form: Option>) - -> Fallible> { + pub fn Constructor(window: &JSRef, form: Option>) -> Fallible> { Ok(FormData::new(form, window)) } +} - pub fn Append(&mut self, name: DOMString, value: &JSRef, filename: Option) { +pub trait FormDataMethods { + fn Append(&mut self, name: DOMString, value: &JSRef, filename: Option); + fn Append_(&mut self, name: DOMString, value: DOMString); +} + +impl<'a> FormDataMethods for JSRef<'a, FormData> { + fn Append(&mut self, name: DOMString, value: &JSRef, filename: Option) { let blob = BlobData { blob: value.unrooted(), name: filename.unwrap_or(~"default") @@ -54,7 +60,7 @@ impl FormData { self.data.insert(name.clone(), blob); } - pub fn Append_(&mut self, name: DOMString, value: DOMString) { + fn Append_(&mut self, name: DOMString, value: DOMString) { self.data.insert(name, StringData(value)); } } diff --git a/src/components/script/dom/htmlanchorelement.rs b/src/components/script/dom/htmlanchorelement.rs index d03723402eb..22e7846269c 100644 --- a/src/components/script/dom/htmlanchorelement.rs +++ b/src/components/script/dom/htmlanchorelement.rs @@ -40,108 +40,137 @@ impl HTMLAnchorElement { } } -impl HTMLAnchorElement { - pub fn Href(&self) -> DOMString { +pub trait HTMLAnchorElementMethods { + fn Href(&self) -> DOMString; + fn SetHref(&mut self, _href: DOMString) -> ErrorResult; + fn Target(&self) -> DOMString; + fn SetTarget(&self, _target: DOMString) -> ErrorResult; + fn Download(&self) -> DOMString; + fn SetDownload(&self, _download: DOMString) -> ErrorResult; + fn Ping(&self) -> DOMString; + fn SetPing(&self, _ping: DOMString) -> ErrorResult; + fn Rel(&self) -> DOMString; + fn SetRel(&self, _rel: DOMString) -> ErrorResult; + fn Hreflang(&self) -> DOMString; + fn SetHreflang(&self, _href_lang: DOMString) -> ErrorResult; + fn Type(&self) -> DOMString; + fn SetType(&mut self, _type: DOMString) -> ErrorResult; + fn Text(&self) -> DOMString; + fn SetText(&mut self, _text: DOMString) -> ErrorResult; + fn Coords(&self) -> DOMString; + fn SetCoords(&mut self, _coords: DOMString) -> ErrorResult; + fn Charset(&self) -> DOMString; + fn SetCharset(&mut self, _charset: DOMString) -> ErrorResult; + fn Name(&self) -> DOMString; + fn SetName(&mut self, _name: DOMString) -> ErrorResult; + fn Rev(&self) -> DOMString; + fn SetRev(&mut self, _rev: DOMString) -> ErrorResult; + fn Shape(&self) -> DOMString; + fn SetShape(&mut self, _shape: DOMString) -> ErrorResult; +} + +impl<'a> HTMLAnchorElementMethods for JSRef<'a, HTMLAnchorElement> { + fn Href(&self) -> DOMString { ~"" } - pub fn SetHref(&mut self, _href: DOMString) -> ErrorResult { + fn SetHref(&mut self, _href: DOMString) -> ErrorResult { Ok(()) } - pub fn Target(&self) -> DOMString { + fn Target(&self) -> DOMString { ~"" } - pub fn SetTarget(&self, _target: DOMString) -> ErrorResult { + fn SetTarget(&self, _target: DOMString) -> ErrorResult { Ok(()) } - pub fn Download(&self) -> DOMString { + fn Download(&self) -> DOMString { ~"" } - pub fn SetDownload(&self, _download: DOMString) -> ErrorResult { + fn SetDownload(&self, _download: DOMString) -> ErrorResult { Ok(()) } - pub fn Ping(&self) -> DOMString { + fn Ping(&self) -> DOMString { ~"" } - pub fn SetPing(&self, _ping: DOMString) -> ErrorResult { + fn SetPing(&self, _ping: DOMString) -> ErrorResult { Ok(()) } - pub fn Rel(&self) -> DOMString { + fn Rel(&self) -> DOMString { ~"" } - pub fn SetRel(&self, _rel: DOMString) -> ErrorResult { + fn SetRel(&self, _rel: DOMString) -> ErrorResult { Ok(()) } - pub fn Hreflang(&self) -> DOMString { + fn Hreflang(&self) -> DOMString { ~"" } - pub fn SetHreflang(&self, _href_lang: DOMString) -> ErrorResult { + fn SetHreflang(&self, _href_lang: DOMString) -> ErrorResult { Ok(()) } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn SetType(&mut self, _type: DOMString) -> ErrorResult { + fn SetType(&mut self, _type: DOMString) -> ErrorResult { Ok(()) } - pub fn Text(&self) -> DOMString { + fn Text(&self) -> DOMString { ~"" } - pub fn SetText(&mut self, _text: DOMString) -> ErrorResult { + fn SetText(&mut self, _text: DOMString) -> ErrorResult { Ok(()) } - pub fn Coords(&self) -> DOMString { + fn Coords(&self) -> DOMString { ~"" } - pub fn SetCoords(&mut self, _coords: DOMString) -> ErrorResult { + fn SetCoords(&mut self, _coords: DOMString) -> ErrorResult { Ok(()) } - pub fn Charset(&self) -> DOMString { + fn Charset(&self) -> DOMString { ~"" } - pub fn SetCharset(&mut self, _charset: DOMString) -> ErrorResult { + fn SetCharset(&mut self, _charset: DOMString) -> ErrorResult { Ok(()) } - pub fn Name(&self) -> DOMString { + fn Name(&self) -> DOMString { ~"" } - pub fn SetName(&mut self, _name: DOMString) -> ErrorResult { + fn SetName(&mut self, _name: DOMString) -> ErrorResult { Ok(()) } - pub fn Rev(&self) -> DOMString { + fn Rev(&self) -> DOMString { ~"" } - pub fn SetRev(&mut self, _rev: DOMString) -> ErrorResult { + fn SetRev(&mut self, _rev: DOMString) -> ErrorResult { Ok(()) } - pub fn Shape(&self) -> DOMString { + fn Shape(&self) -> DOMString { ~"" } - pub fn SetShape(&mut self, _shape: DOMString) -> ErrorResult { + fn SetShape(&mut self, _shape: DOMString) -> ErrorResult { Ok(()) } } diff --git a/src/components/script/dom/htmlappletelement.rs b/src/components/script/dom/htmlappletelement.rs index ea253003fd4..bcf7481d4d7 100644 --- a/src/components/script/dom/htmlappletelement.rs +++ b/src/components/script/dom/htmlappletelement.rs @@ -40,92 +40,117 @@ impl HTMLAppletElement { } } -impl HTMLAppletElement { - pub fn Align(&self) -> DOMString { +pub trait HTMLAppletElementMethods { + fn Align(&self) -> DOMString; + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult; + fn Alt(&self) -> DOMString; + fn SetAlt(&self, _alt: DOMString) -> ErrorResult; + fn Archive(&self) -> DOMString; + fn SetArchive(&self, _archive: DOMString) -> ErrorResult; + fn Code(&self) -> DOMString; + fn SetCode(&self, _code: DOMString) -> ErrorResult; + fn CodeBase(&self) -> DOMString; + fn SetCodeBase(&self, _code_base: DOMString) -> ErrorResult; + fn Height(&self) -> DOMString; + fn SetHeight(&self, _height: DOMString) -> ErrorResult; + fn Hspace(&self) -> u32; + fn SetHspace(&mut self, _hspace: u32) -> ErrorResult; + fn Name(&self) -> DOMString; + fn SetName(&mut self, _name: DOMString) -> ErrorResult; + fn Object(&self) -> DOMString; + fn SetObject(&mut self, _object: DOMString) -> ErrorResult; + fn Vspace(&self) -> u32; + fn SetVspace(&mut self, _vspace: u32) -> ErrorResult; + fn Width(&self) -> DOMString; + fn SetWidth(&mut self, _width: DOMString) -> ErrorResult; +} + +impl<'a> HTMLAppletElementMethods for JSRef<'a, HTMLAppletElement> { + fn Align(&self) -> DOMString { ~"" } - pub fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { Ok(()) } - pub fn Alt(&self) -> DOMString { + fn Alt(&self) -> DOMString { ~"" } - pub fn SetAlt(&self, _alt: DOMString) -> ErrorResult { + fn SetAlt(&self, _alt: DOMString) -> ErrorResult { Ok(()) } - pub fn Archive(&self) -> DOMString { + fn Archive(&self) -> DOMString { ~"" } - pub fn SetArchive(&self, _archive: DOMString) -> ErrorResult { + fn SetArchive(&self, _archive: DOMString) -> ErrorResult { Ok(()) } - pub fn Code(&self) -> DOMString { + fn Code(&self) -> DOMString { ~"" } - pub fn SetCode(&self, _code: DOMString) -> ErrorResult { + fn SetCode(&self, _code: DOMString) -> ErrorResult { Ok(()) } - pub fn CodeBase(&self) -> DOMString { + fn CodeBase(&self) -> DOMString { ~"" } - pub fn SetCodeBase(&self, _code_base: DOMString) -> ErrorResult { + fn SetCodeBase(&self, _code_base: DOMString) -> ErrorResult { Ok(()) } - pub fn Height(&self) -> DOMString { + fn Height(&self) -> DOMString { ~"" } - pub fn SetHeight(&self, _height: DOMString) -> ErrorResult { + fn SetHeight(&self, _height: DOMString) -> ErrorResult { Ok(()) } - pub fn Hspace(&self) -> u32 { + fn Hspace(&self) -> u32 { 0 } - pub fn SetHspace(&mut self, _hspace: u32) -> ErrorResult { + fn SetHspace(&mut self, _hspace: u32) -> ErrorResult { Ok(()) } - pub fn Name(&self) -> DOMString { + fn Name(&self) -> DOMString { ~"" } - pub fn SetName(&mut self, _name: DOMString) -> ErrorResult { + fn SetName(&mut self, _name: DOMString) -> ErrorResult { Ok(()) } - pub fn Object(&self) -> DOMString { + fn Object(&self) -> DOMString { ~"" } - pub fn SetObject(&mut self, _object: DOMString) -> ErrorResult { + fn SetObject(&mut self, _object: DOMString) -> ErrorResult { Ok(()) } - pub fn Vspace(&self) -> u32 { + fn Vspace(&self) -> u32 { 0 } - pub fn SetVspace(&mut self, _vspace: u32) -> ErrorResult { + fn SetVspace(&mut self, _vspace: u32) -> ErrorResult { Ok(()) } - pub fn Width(&self) -> DOMString { + fn Width(&self) -> DOMString { ~"" } - pub fn SetWidth(&mut self, _width: DOMString) -> ErrorResult { + fn SetWidth(&mut self, _width: DOMString) -> ErrorResult { Ok(()) } } diff --git a/src/components/script/dom/htmlareaelement.rs b/src/components/script/dom/htmlareaelement.rs index d98f2033b77..d22e8a45a67 100644 --- a/src/components/script/dom/htmlareaelement.rs +++ b/src/components/script/dom/htmlareaelement.rs @@ -40,68 +40,87 @@ impl HTMLAreaElement { } } -impl HTMLAreaElement { - pub fn Alt(&self) -> DOMString { +pub trait HTMLAreaElementMethods { + fn Alt(&self) -> DOMString; + fn SetAlt(&self, _alt: DOMString) -> ErrorResult; + fn Coords(&self) -> DOMString; + fn SetCoords(&self, _coords: DOMString) -> ErrorResult; + fn Shape(&self) -> DOMString; + fn SetShape(&self, _shape: DOMString) -> ErrorResult; + fn Href(&self) -> DOMString; + fn SetHref(&self, _href: DOMString) -> ErrorResult; + fn Target(&self) -> DOMString; + fn SetTarget(&self, _target: DOMString) -> ErrorResult; + fn Download(&self) -> DOMString; + fn SetDownload(&self, _download: DOMString) -> ErrorResult; + fn Ping(&self) -> DOMString; + fn SetPing(&self, _ping: DOMString) -> ErrorResult; + fn NoHref(&self) -> bool; + fn SetNoHref(&mut self, _no_href: bool) -> ErrorResult; +} + +impl<'a> HTMLAreaElementMethods for JSRef<'a, HTMLAreaElement> { + fn Alt(&self) -> DOMString { ~"" } - pub fn SetAlt(&self, _alt: DOMString) -> ErrorResult { + fn SetAlt(&self, _alt: DOMString) -> ErrorResult { Ok(()) } - pub fn Coords(&self) -> DOMString { + fn Coords(&self) -> DOMString { ~"" } - pub fn SetCoords(&self, _coords: DOMString) -> ErrorResult { + fn SetCoords(&self, _coords: DOMString) -> ErrorResult { Ok(()) } - pub fn Shape(&self) -> DOMString { + fn Shape(&self) -> DOMString { ~"" } - pub fn SetShape(&self, _shape: DOMString) -> ErrorResult { + fn SetShape(&self, _shape: DOMString) -> ErrorResult { Ok(()) } - pub fn Href(&self) -> DOMString { + fn Href(&self) -> DOMString { ~"" } - pub fn SetHref(&self, _href: DOMString) -> ErrorResult { + fn SetHref(&self, _href: DOMString) -> ErrorResult { Ok(()) } - pub fn Target(&self) -> DOMString { + fn Target(&self) -> DOMString { ~"" } - pub fn SetTarget(&self, _target: DOMString) -> ErrorResult { + fn SetTarget(&self, _target: DOMString) -> ErrorResult { Ok(()) } - pub fn Download(&self) -> DOMString { + fn Download(&self) -> DOMString { ~"" } - pub fn SetDownload(&self, _download: DOMString) -> ErrorResult { + fn SetDownload(&self, _download: DOMString) -> ErrorResult { Ok(()) } - pub fn Ping(&self) -> DOMString { + fn Ping(&self) -> DOMString { ~"" } - pub fn SetPing(&self, _ping: DOMString) -> ErrorResult { + fn SetPing(&self, _ping: DOMString) -> ErrorResult { Ok(()) } - pub fn NoHref(&self) -> bool { + fn NoHref(&self) -> bool { false } - pub fn SetNoHref(&mut self, _no_href: bool) -> ErrorResult { + fn SetNoHref(&mut self, _no_href: bool) -> ErrorResult { Ok(()) } } diff --git a/src/components/script/dom/htmlaudioelement.rs b/src/components/script/dom/htmlaudioelement.rs index a4ea33c7052..7e3826dd4c6 100644 --- a/src/components/script/dom/htmlaudioelement.rs +++ b/src/components/script/dom/htmlaudioelement.rs @@ -38,3 +38,6 @@ impl HTMLAudioElement { Node::reflect_node(~element, document, HTMLAudioElementBinding::Wrap) } } + +pub trait HTMLAudioElementMethods { +} diff --git a/src/components/script/dom/htmlbaseelement.rs b/src/components/script/dom/htmlbaseelement.rs index bfaf1a74410..83cdf3607ac 100644 --- a/src/components/script/dom/htmlbaseelement.rs +++ b/src/components/script/dom/htmlbaseelement.rs @@ -40,20 +40,28 @@ impl HTMLBaseElement { } } -impl HTMLBaseElement { - pub fn Href(&self) -> DOMString { +pub trait HTMLBaseElementMethods { + fn Href(&self) -> DOMString; + fn SetHref(&self, _href: DOMString) -> ErrorResult; + fn Target(&self) -> DOMString; + fn SetTarget(&self, _target: DOMString) -> ErrorResult; +} + +impl<'a> HTMLBaseElementMethods for JSRef<'a, HTMLBaseElement> { + fn Href(&self) -> DOMString { ~"" } - pub fn SetHref(&self, _href: DOMString) -> ErrorResult { + fn SetHref(&self, _href: DOMString) -> ErrorResult { Ok(()) } - pub fn Target(&self) -> DOMString { + fn Target(&self) -> DOMString { ~"" } - pub fn SetTarget(&self, _target: DOMString) -> ErrorResult { + fn SetTarget(&self, _target: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlbodyelement.rs b/src/components/script/dom/htmlbodyelement.rs index 22b41c283ba..cb59f0c6fb4 100644 --- a/src/components/script/dom/htmlbodyelement.rs +++ b/src/components/script/dom/htmlbodyelement.rs @@ -40,52 +40,68 @@ impl HTMLBodyElement { } } -impl HTMLBodyElement { - pub fn Text(&self) -> DOMString { +pub trait HTMLBodyElementMethods { + fn Text(&self) -> DOMString; + fn SetText(&mut self, _text: DOMString) -> ErrorResult; + fn Link(&self) -> DOMString; + fn SetLink(&self, _link: DOMString) -> ErrorResult; + fn VLink(&self) -> DOMString; + fn SetVLink(&self, _v_link: DOMString) -> ErrorResult; + fn ALink(&self) -> DOMString; + fn SetALink(&self, _a_link: DOMString) -> ErrorResult; + fn BgColor(&self) -> DOMString; + fn SetBgColor(&self, _bg_color: DOMString) -> ErrorResult; + fn Background(&self) -> DOMString; + fn SetBackground(&self, _background: DOMString) -> ErrorResult; +} + +impl<'a> HTMLBodyElementMethods for JSRef<'a, HTMLBodyElement> { + fn Text(&self) -> DOMString { ~"" } - pub fn SetText(&mut self, _text: DOMString) -> ErrorResult { + fn SetText(&mut self, _text: DOMString) -> ErrorResult { Ok(()) } - pub fn Link(&self) -> DOMString { + fn Link(&self) -> DOMString { ~"" } - pub fn SetLink(&self, _link: DOMString) -> ErrorResult { + fn SetLink(&self, _link: DOMString) -> ErrorResult { Ok(()) } - pub fn VLink(&self) -> DOMString { + fn VLink(&self) -> DOMString { ~"" } - pub fn SetVLink(&self, _v_link: DOMString) -> ErrorResult { + fn SetVLink(&self, _v_link: DOMString) -> ErrorResult { Ok(()) } - pub fn ALink(&self) -> DOMString { + fn ALink(&self) -> DOMString { ~"" } - pub fn SetALink(&self, _a_link: DOMString) -> ErrorResult { + fn SetALink(&self, _a_link: DOMString) -> ErrorResult { Ok(()) } - pub fn BgColor(&self) -> DOMString { + fn BgColor(&self) -> DOMString { ~"" } - pub fn SetBgColor(&self, _bg_color: DOMString) -> ErrorResult { + fn SetBgColor(&self, _bg_color: DOMString) -> ErrorResult { Ok(()) } - pub fn Background(&self) -> DOMString { + fn Background(&self) -> DOMString { ~"" } - pub fn SetBackground(&self, _background: DOMString) -> ErrorResult { + fn SetBackground(&self, _background: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlbrelement.rs b/src/components/script/dom/htmlbrelement.rs index 5e23734042c..5b06b1467ea 100644 --- a/src/components/script/dom/htmlbrelement.rs +++ b/src/components/script/dom/htmlbrelement.rs @@ -40,12 +40,18 @@ impl HTMLBRElement { } } -impl HTMLBRElement { - pub fn Clear(&self) -> DOMString { +pub trait HTMLBRElementMethods { + fn Clear(&self) -> DOMString; + fn SetClear(&mut self, _text: DOMString) -> ErrorResult; +} + +impl<'a> HTMLBRElementMethods for JSRef<'a, HTMLBRElement> { + fn Clear(&self) -> DOMString { ~"" } - pub fn SetClear(&mut self, _text: DOMString) -> ErrorResult { + fn SetClear(&mut self, _text: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlbuttonelement.rs b/src/components/script/dom/htmlbuttonelement.rs index 30f031f8058..2b2b04aca35 100644 --- a/src/components/script/dom/htmlbuttonelement.rs +++ b/src/components/script/dom/htmlbuttonelement.rs @@ -42,119 +42,152 @@ impl HTMLButtonElement { } } -impl HTMLButtonElement { - pub fn Autofocus(&self) -> bool { +pub trait HTMLButtonElementMethods { + fn Autofocus(&self) -> bool; + fn SetAutofocus(&mut self, _autofocus: bool) -> ErrorResult; + fn Disabled(&self) -> bool; + fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult; + fn GetForm(&self) -> Option>; + fn FormAction(&self) -> DOMString; + fn SetFormAction(&mut self, _formaction: DOMString) -> ErrorResult; + fn FormEnctype(&self) -> DOMString; + fn SetFormEnctype(&mut self, _formenctype: DOMString) -> ErrorResult; + fn FormMethod(&self) -> DOMString; + fn SetFormMethod(&mut self, _formmethod: DOMString) -> ErrorResult; + fn FormNoValidate(&self) -> bool; + fn SetFormNoValidate(&mut self, _novalidate: bool) -> ErrorResult; + fn FormTarget(&self) -> DOMString; + fn SetFormTarget(&mut self, _formtarget: DOMString) -> ErrorResult; + fn Name(&self) -> DOMString; + fn SetName(&mut self, _name: DOMString) -> ErrorResult; + fn Type(&self) -> DOMString; + fn SetType(&mut self, _type: DOMString) -> ErrorResult; + fn Value(&self) -> DOMString; + fn SetValue(&mut self, _value: DOMString) -> ErrorResult; + fn WillValidate(&self) -> bool; + fn SetWillValidate(&mut self, _will_validate: bool); + fn Validity(&self) -> Unrooted; + fn SetValidity(&mut self, _validity: JS); + fn ValidationMessage(&self) -> DOMString; + fn SetValidationMessage(&mut self, _message: DOMString) -> ErrorResult; + fn CheckValidity(&self) -> bool; + fn SetCustomValidity(&mut self, _error: DOMString); +} + +impl<'a> HTMLButtonElementMethods for JSRef<'a, HTMLButtonElement> { + fn Autofocus(&self) -> bool { false } - pub fn SetAutofocus(&mut self, _autofocus: bool) -> ErrorResult { + fn SetAutofocus(&mut self, _autofocus: bool) -> ErrorResult { Ok(()) } - pub fn Disabled(&self) -> bool { + fn Disabled(&self) -> bool { false } - pub fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult { + fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult { Ok(()) } - pub fn GetForm(&self) -> Option> { + fn GetForm(&self) -> Option> { None } - pub fn FormAction(&self) -> DOMString { + fn FormAction(&self) -> DOMString { ~"" } - pub fn SetFormAction(&mut self, _formaction: DOMString) -> ErrorResult { + fn SetFormAction(&mut self, _formaction: DOMString) -> ErrorResult { Ok(()) } - pub fn FormEnctype(&self) -> DOMString { + fn FormEnctype(&self) -> DOMString { ~"" } - pub fn SetFormEnctype(&mut self, _formenctype: DOMString) -> ErrorResult { + fn SetFormEnctype(&mut self, _formenctype: DOMString) -> ErrorResult { Ok(()) } - pub fn FormMethod(&self) -> DOMString { + fn FormMethod(&self) -> DOMString { ~"" } - pub fn SetFormMethod(&mut self, _formmethod: DOMString) -> ErrorResult { + fn SetFormMethod(&mut self, _formmethod: DOMString) -> ErrorResult { Ok(()) } - pub fn FormNoValidate(&self) -> bool { + fn FormNoValidate(&self) -> bool { false } - pub fn SetFormNoValidate(&mut self, _novalidate: bool) -> ErrorResult { + fn SetFormNoValidate(&mut self, _novalidate: bool) -> ErrorResult { Ok(()) } - pub fn FormTarget(&self) -> DOMString { + fn FormTarget(&self) -> DOMString { ~"" } - pub fn SetFormTarget(&mut self, _formtarget: DOMString) -> ErrorResult { + fn SetFormTarget(&mut self, _formtarget: DOMString) -> ErrorResult { Ok(()) } - pub fn Name(&self) -> DOMString { + fn Name(&self) -> DOMString { ~"" } - pub fn SetName(&mut self, _name: DOMString) -> ErrorResult { + fn SetName(&mut self, _name: DOMString) -> ErrorResult { Ok(()) } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn SetType(&mut self, _type: DOMString) -> ErrorResult { + fn SetType(&mut self, _type: DOMString) -> ErrorResult { Ok(()) } - pub fn Value(&self) -> DOMString { + fn Value(&self) -> DOMString { ~"" } - pub fn SetValue(&mut self, _value: DOMString) -> ErrorResult { + fn SetValue(&mut self, _value: DOMString) -> ErrorResult { Ok(()) } - pub fn WillValidate(&self) -> bool { + fn WillValidate(&self) -> bool { false } - pub fn SetWillValidate(&mut self, _will_validate: bool) { + fn SetWillValidate(&mut self, _will_validate: bool) { } - pub fn Validity(&self) -> Unrooted { + fn Validity(&self) -> Unrooted { let roots = RootCollection::new(); let doc = self.htmlelement.element.node.owner_doc().root(&roots); ValidityState::new(&*doc.deref().window.root(&roots)) } - pub fn SetValidity(&mut self, _validity: JS) { + fn SetValidity(&mut self, _validity: JS) { } - pub fn ValidationMessage(&self) -> DOMString { + fn ValidationMessage(&self) -> DOMString { ~"" } - pub fn SetValidationMessage(&mut self, _message: DOMString) -> ErrorResult { + fn SetValidationMessage(&mut self, _message: DOMString) -> ErrorResult { Ok(()) } - pub fn CheckValidity(&self) -> bool { + fn CheckValidity(&self) -> bool { true } - pub fn SetCustomValidity(&mut self, _error: DOMString) { + fn SetCustomValidity(&mut self, _error: DOMString) { } } + diff --git a/src/components/script/dom/htmlcanvaselement.rs b/src/components/script/dom/htmlcanvaselement.rs index 469bb8b8643..32af35a06b7 100644 --- a/src/components/script/dom/htmlcanvaselement.rs +++ b/src/components/script/dom/htmlcanvaselement.rs @@ -40,20 +40,28 @@ impl HTMLCanvasElement { } } -impl HTMLCanvasElement { - pub fn Width(&self) -> u32 { +pub trait HTMLCanvasElementMethods { + fn Width(&self) -> u32; + fn SetWidth(&mut self, _width: u32) -> ErrorResult; + fn Height(&self) -> u32; + fn SetHeight(&mut self, _height: u32) -> ErrorResult; +} + +impl<'a> HTMLCanvasElementMethods for JSRef<'a, HTMLCanvasElement> { + fn Width(&self) -> u32 { 0 } - pub fn SetWidth(&mut self, _width: u32) -> ErrorResult { + fn SetWidth(&mut self, _width: u32) -> ErrorResult { Ok(()) } - pub fn Height(&self) -> u32 { + fn Height(&self) -> u32 { 0 } - pub fn SetHeight(&mut self, _height: u32) -> ErrorResult { + fn SetHeight(&mut self, _height: u32) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlcollection.rs b/src/components/script/dom/htmlcollection.rs index 73b4835ff2e..77ddb563805 100644 --- a/src/components/script/dom/htmlcollection.rs +++ b/src/components/script/dom/htmlcollection.rs @@ -118,9 +118,17 @@ impl HTMLCollection { } } -impl HTMLCollection { +pub trait HTMLCollectionMethods { + fn Length(&self) -> u32; + fn Item(&self, index: u32) -> Option>; + fn NamedItem(&self, key: DOMString) -> Option>; + fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option>; + fn NamedGetter(&self, maybe_name: Option, found: &mut bool) -> Option>; +} + +impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> { // http://dom.spec.whatwg.org/#dom-htmlcollection-length - pub fn Length(&self) -> u32 { + fn Length(&self) -> u32 { let roots = RootCollection::new(); match self.collection { Static(ref elems) => elems.len() as u32, @@ -136,7 +144,7 @@ impl HTMLCollection { } // http://dom.spec.whatwg.org/#dom-htmlcollection-item - pub fn Item(&self, index: u32) -> Option> { + fn Item(&self, index: u32) -> Option> { let roots = RootCollection::new(); match self.collection { Static(ref elems) => elems @@ -159,7 +167,7 @@ impl HTMLCollection { } // http://dom.spec.whatwg.org/#dom-htmlcollection-nameditem - pub fn NamedItem(&self, key: DOMString) -> Option> { + fn NamedItem(&self, key: DOMString) -> Option> { let roots = RootCollection::new(); // Step 1. @@ -190,16 +198,14 @@ impl HTMLCollection { } } } -} -impl HTMLCollection { - pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { + fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { let maybe_elem = self.Item(index); *found = maybe_elem.is_some(); maybe_elem } - pub fn NamedGetter(&self, maybe_name: Option, found: &mut bool) -> Option> { + fn NamedGetter(&self, maybe_name: Option, found: &mut bool) -> Option> { match maybe_name { Some(name) => { let maybe_elem = self.NamedItem(name); diff --git a/src/components/script/dom/htmldataelement.rs b/src/components/script/dom/htmldataelement.rs index 767b3b18598..4e412665595 100644 --- a/src/components/script/dom/htmldataelement.rs +++ b/src/components/script/dom/htmldataelement.rs @@ -40,12 +40,18 @@ impl HTMLDataElement { } } -impl HTMLDataElement { - pub fn Value(&self) -> DOMString { +pub trait HTMLDataElementMethods { + fn Value(&self) -> DOMString; + fn SetValue(&mut self, _value: DOMString) -> ErrorResult; +} + +impl<'a> HTMLDataElementMethods for JSRef<'a, HTMLDataElement> { + fn Value(&self) -> DOMString { ~"" } - pub fn SetValue(&mut self, _value: DOMString) -> ErrorResult { + fn SetValue(&mut self, _value: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmldatalistelement.rs b/src/components/script/dom/htmldatalistelement.rs index e4ac02bd83f..9fcb291ae4f 100644 --- a/src/components/script/dom/htmldatalistelement.rs +++ b/src/components/script/dom/htmldatalistelement.rs @@ -40,8 +40,12 @@ impl HTMLDataListElement { } } -impl HTMLDataListElement { - pub fn Options(&self, abstract_self: &JSRef) -> Unrooted { +pub trait HTMLDataListElementMethods { + fn Options(&self, abstract_self: &JSRef) -> Unrooted; +} + +impl<'a> HTMLDataListElementMethods for JSRef<'a, HTMLDataListElement> { + fn Options(&self, abstract_self: &JSRef) -> Unrooted { struct HTMLDataListOptionsFilter; impl CollectionFilter for HTMLDataListOptionsFilter { fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { @@ -55,3 +59,4 @@ impl HTMLDataListElement { HTMLCollection::create(&*window, node, filter) } } + diff --git a/src/components/script/dom/htmldirectoryelement.rs b/src/components/script/dom/htmldirectoryelement.rs index f4b77ee5cf0..cc7dd99920b 100644 --- a/src/components/script/dom/htmldirectoryelement.rs +++ b/src/components/script/dom/htmldirectoryelement.rs @@ -40,12 +40,18 @@ impl HTMLDirectoryElement { } } -impl HTMLDirectoryElement { - pub fn Compact(&self) -> bool { +pub trait HTMLDirectoryElementMethods { + fn Compact(&self) -> bool; + fn SetCompact(&mut self, _compact: bool) -> ErrorResult; +} + +impl<'a> HTMLDirectoryElementMethods for JSRef<'a, HTMLDirectoryElement> { + fn Compact(&self) -> bool { false } - pub fn SetCompact(&mut self, _compact: bool) -> ErrorResult { + fn SetCompact(&mut self, _compact: bool) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmldivelement.rs b/src/components/script/dom/htmldivelement.rs index 6053582738d..d50b95c72cd 100644 --- a/src/components/script/dom/htmldivelement.rs +++ b/src/components/script/dom/htmldivelement.rs @@ -40,12 +40,18 @@ impl HTMLDivElement { } } -impl HTMLDivElement { - pub fn Align(&self) -> DOMString { +pub trait HTMLDivElementMethods { + fn Align(&self) -> DOMString; + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult; +} + +impl<'a> HTMLDivElementMethods for JSRef<'a, HTMLDivElement> { + fn Align(&self) -> DOMString { ~"" } - pub fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmldlistelement.rs b/src/components/script/dom/htmldlistelement.rs index 113547af9d6..838c694a33c 100644 --- a/src/components/script/dom/htmldlistelement.rs +++ b/src/components/script/dom/htmldlistelement.rs @@ -40,20 +40,28 @@ impl HTMLDListElement { } } -impl HTMLDListElement { - pub fn Compact(&self) -> bool { +pub trait HTMLDListElementMethods { + fn Compact(&self) -> bool; + fn SetCompact(&mut self, _compact: bool) -> ErrorResult; + fn Type(&self) -> DOMString; + fn SetType(&mut self, _type: DOMString) -> ErrorResult; +} + +impl<'a> HTMLDListElementMethods for JSRef<'a, HTMLDListElement> { + fn Compact(&self) -> bool { false } - pub fn SetCompact(&mut self, _compact: bool) -> ErrorResult { + fn SetCompact(&mut self, _compact: bool) -> ErrorResult { Ok(()) } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn SetType(&mut self, _type: DOMString) -> ErrorResult { + fn SetType(&mut self, _type: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlelement.rs b/src/components/script/dom/htmlelement.rs index d49ce843bd1..c7596688cdb 100644 --- a/src/components/script/dom/htmlelement.rs +++ b/src/components/script/dom/htmlelement.rs @@ -45,121 +45,154 @@ impl HTMLElement { } } -impl HTMLElement { - pub fn Title(&self) -> DOMString { +pub trait HTMLElementMethods { + fn Title(&self) -> DOMString; + fn SetTitle(&mut self, _title: DOMString); + fn Lang(&self) -> DOMString; + fn SetLang(&mut self, _lang: DOMString); + fn Dir(&self) -> DOMString; + fn SetDir(&mut self, _dir: DOMString) -> ErrorResult; + fn GetItemValue(&self, _cx: *JSContext) -> Fallible; + fn SetItemValue(&mut self, _cx: *JSContext, _val: JSVal) -> ErrorResult; + fn Hidden(&self) -> bool; + fn SetHidden(&mut self, _hidden: bool) -> ErrorResult; + fn Click(&self); + fn TabIndex(&self) -> i32; + fn SetTabIndex(&mut self, _index: i32) -> ErrorResult; + fn Focus(&self) -> ErrorResult; + fn Blur(&self) -> ErrorResult; + fn AccessKey(&self) -> DOMString; + fn SetAccessKey(&self, _key: DOMString) -> ErrorResult; + fn AccessKeyLabel(&self) -> DOMString; + fn Draggable(&self) -> bool; + fn SetDraggable(&mut self, _draggable: bool) -> ErrorResult; + fn ContentEditable(&self) -> DOMString; + fn SetContentEditable(&mut self, _val: DOMString) -> ErrorResult; + fn IsContentEditable(&self) -> bool; + fn Spellcheck(&self) -> bool; + fn SetSpellcheck(&self, _val: bool) -> ErrorResult; + fn GetOffsetParent(&self) -> Option>; + fn OffsetTop(&self) -> i32; + fn OffsetLeft(&self) -> i32; + fn OffsetWidth(&self) -> i32; + fn OffsetHeight(&self) -> i32; +} + +impl<'a> HTMLElementMethods for JSRef<'a, HTMLElement> { + fn Title(&self) -> DOMString { ~"" } - pub fn SetTitle(&mut self, _title: DOMString) { + fn SetTitle(&mut self, _title: DOMString) { } - pub fn Lang(&self) -> DOMString { + fn Lang(&self) -> DOMString { ~"" } - pub fn SetLang(&mut self, _lang: DOMString) { + fn SetLang(&mut self, _lang: DOMString) { } - pub fn Dir(&self) -> DOMString { + fn Dir(&self) -> DOMString { ~"" } - pub fn SetDir(&mut self, _dir: DOMString) -> ErrorResult { + fn SetDir(&mut self, _dir: DOMString) -> ErrorResult { Ok(()) } - pub fn GetItemValue(&self, _cx: *JSContext) -> Fallible { + fn GetItemValue(&self, _cx: *JSContext) -> Fallible { Ok(NullValue()) } - pub fn SetItemValue(&mut self, _cx: *JSContext, _val: JSVal) -> ErrorResult { + fn SetItemValue(&mut self, _cx: *JSContext, _val: JSVal) -> ErrorResult { Ok(()) } - pub fn Hidden(&self) -> bool { + fn Hidden(&self) -> bool { false } - pub fn SetHidden(&mut self, _hidden: bool) -> ErrorResult { + fn SetHidden(&mut self, _hidden: bool) -> ErrorResult { Ok(()) } - pub fn Click(&self) { + fn Click(&self) { } - pub fn TabIndex(&self) -> i32 { + fn TabIndex(&self) -> i32 { 0 } - pub fn SetTabIndex(&mut self, _index: i32) -> ErrorResult { + fn SetTabIndex(&mut self, _index: i32) -> ErrorResult { Ok(()) } - pub fn Focus(&self) -> ErrorResult { + fn Focus(&self) -> ErrorResult { Ok(()) } - pub fn Blur(&self) -> ErrorResult { + fn Blur(&self) -> ErrorResult { Ok(()) } - pub fn AccessKey(&self) -> DOMString { + fn AccessKey(&self) -> DOMString { ~"" } - pub fn SetAccessKey(&self, _key: DOMString) -> ErrorResult { + fn SetAccessKey(&self, _key: DOMString) -> ErrorResult { Ok(()) } - pub fn AccessKeyLabel(&self) -> DOMString { + fn AccessKeyLabel(&self) -> DOMString { ~"" } - pub fn Draggable(&self) -> bool { + fn Draggable(&self) -> bool { false } - pub fn SetDraggable(&mut self, _draggable: bool) -> ErrorResult { + fn SetDraggable(&mut self, _draggable: bool) -> ErrorResult { Ok(()) } - pub fn ContentEditable(&self) -> DOMString { + fn ContentEditable(&self) -> DOMString { ~"" } - pub fn SetContentEditable(&mut self, _val: DOMString) -> ErrorResult { + fn SetContentEditable(&mut self, _val: DOMString) -> ErrorResult { Ok(()) } - pub fn IsContentEditable(&self) -> bool { + fn IsContentEditable(&self) -> bool { false } - pub fn Spellcheck(&self) -> bool { + fn Spellcheck(&self) -> bool { false } - pub fn SetSpellcheck(&self, _val: bool) -> ErrorResult { + fn SetSpellcheck(&self, _val: bool) -> ErrorResult { Ok(()) } - pub fn GetOffsetParent(&self) -> Option> { + fn GetOffsetParent(&self) -> Option> { None } - pub fn OffsetTop(&self) -> i32 { + fn OffsetTop(&self) -> i32 { 0 } - pub fn OffsetLeft(&self) -> i32 { + fn OffsetLeft(&self) -> i32 { 0 } - pub fn OffsetWidth(&self) -> i32 { + fn OffsetWidth(&self) -> i32 { 0 } - pub fn OffsetHeight(&self) -> i32 { + fn OffsetHeight(&self) -> i32 { 0 } } diff --git a/src/components/script/dom/htmlembedelement.rs b/src/components/script/dom/htmlembedelement.rs index 864e1a1829c..715f113987e 100644 --- a/src/components/script/dom/htmlembedelement.rs +++ b/src/components/script/dom/htmlembedelement.rs @@ -40,56 +40,73 @@ impl HTMLEmbedElement { } } -impl HTMLEmbedElement { - pub fn Src(&self) -> DOMString { +pub trait HTMLEmbedElementMethods { + fn Src(&self) -> DOMString; + fn SetSrc(&mut self, _src: DOMString) -> ErrorResult; + fn Type(&self) -> DOMString; + fn SetType(&mut self, _type: DOMString) -> ErrorResult; + fn Width(&self) -> DOMString; + fn SetWidth(&mut self, _width: DOMString) -> ErrorResult; + fn Height(&self) -> DOMString; + fn SetHeight(&mut self, _height: DOMString) -> ErrorResult; + fn Align(&self) -> DOMString; + fn SetAlign(&mut self, _type: DOMString) -> ErrorResult; + fn Name(&self) -> DOMString; + fn SetName(&mut self, _type: DOMString) -> ErrorResult; + fn GetSVGDocument(&self) -> Option>; +} + +impl<'a> HTMLEmbedElementMethods for JSRef<'a, HTMLEmbedElement> { + fn Src(&self) -> DOMString { ~"" } - pub fn SetSrc(&mut self, _src: DOMString) -> ErrorResult { + fn SetSrc(&mut self, _src: DOMString) -> ErrorResult { Ok(()) } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn SetType(&mut self, _type: DOMString) -> ErrorResult { + fn SetType(&mut self, _type: DOMString) -> ErrorResult { Ok(()) } - pub fn Width(&self) -> DOMString { + fn Width(&self) -> DOMString { ~"" } - pub fn SetWidth(&mut self, _width: DOMString) -> ErrorResult { + fn SetWidth(&mut self, _width: DOMString) -> ErrorResult { Ok(()) } - pub fn Height(&self) -> DOMString { + fn Height(&self) -> DOMString { ~"" } - pub fn SetHeight(&mut self, _height: DOMString) -> ErrorResult { + fn SetHeight(&mut self, _height: DOMString) -> ErrorResult { Ok(()) } - pub fn Align(&self) -> DOMString { + fn Align(&self) -> DOMString { ~"" } - pub fn SetAlign(&mut self, _type: DOMString) -> ErrorResult { + fn SetAlign(&mut self, _type: DOMString) -> ErrorResult { Ok(()) } - pub fn Name(&self) -> DOMString { + fn Name(&self) -> DOMString { ~"" } - pub fn SetName(&mut self, _type: DOMString) -> ErrorResult { + fn SetName(&mut self, _type: DOMString) -> ErrorResult { Ok(()) } - pub fn GetSVGDocument(&self) -> Option> { + fn GetSVGDocument(&self) -> Option> { None } } + diff --git a/src/components/script/dom/htmlfieldsetelement.rs b/src/components/script/dom/htmlfieldsetelement.rs index 1bb9146e4e7..4f3d06d987c 100644 --- a/src/components/script/dom/htmlfieldsetelement.rs +++ b/src/components/script/dom/htmlfieldsetelement.rs @@ -43,33 +43,48 @@ impl HTMLFieldSetElement { } } -impl HTMLFieldSetElement { - pub fn Disabled(&self) -> bool { +pub trait HTMLFieldSetElementMethods { + fn Disabled(&self) -> bool; + fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult; + fn GetForm(&self) -> Option>; + fn Name(&self) -> DOMString; + fn SetName(&mut self, _name: DOMString) -> ErrorResult; + fn Type(&self) -> DOMString; + fn Elements(&self, abstract_self: &JSRef) -> Unrooted; + fn WillValidate(&self) -> bool; + fn Validity(&self) -> Unrooted; + fn ValidationMessage(&self) -> DOMString; + fn CheckValidity(&self) -> bool; + fn SetCustomValidity(&mut self, _error: DOMString); +} + +impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> { + fn Disabled(&self) -> bool { false } - pub fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult { + fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult { Ok(()) } - pub fn GetForm(&self) -> Option> { + fn GetForm(&self) -> Option> { None } - pub fn Name(&self) -> DOMString { + fn Name(&self) -> DOMString { ~"" } - pub fn SetName(&mut self, _name: DOMString) -> ErrorResult { + fn SetName(&mut self, _name: DOMString) -> ErrorResult { Ok(()) } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } // http://www.whatwg.org/html/#dom-fieldset-elements - pub fn Elements(&self, abstract_self: &JSRef) -> Unrooted { + fn Elements(&self, abstract_self: &JSRef) -> Unrooted { struct ElementsFilter; impl CollectionFilter for ElementsFilter { fn filter(&self, elem: &JSRef, root: &JSRef) -> bool { @@ -86,25 +101,26 @@ impl HTMLFieldSetElement { HTMLCollection::create(&*window, node, filter) } - pub fn WillValidate(&self) -> bool { + fn WillValidate(&self) -> bool { false } - pub fn Validity(&self) -> Unrooted { + fn Validity(&self) -> Unrooted { let roots = RootCollection::new(); let doc = self.htmlelement.element.node.owner_doc().root(&roots); let window = doc.deref().window.root(&roots); ValidityState::new(&*window) } - pub fn ValidationMessage(&self) -> DOMString { + fn ValidationMessage(&self) -> DOMString { ~"" } - pub fn CheckValidity(&self) -> bool { + fn CheckValidity(&self) -> bool { false } - pub fn SetCustomValidity(&mut self, _error: DOMString) { + fn SetCustomValidity(&mut self, _error: DOMString) { } } + diff --git a/src/components/script/dom/htmlfontelement.rs b/src/components/script/dom/htmlfontelement.rs index fefc9c0f4df..eca6b946b23 100644 --- a/src/components/script/dom/htmlfontelement.rs +++ b/src/components/script/dom/htmlfontelement.rs @@ -40,28 +40,38 @@ impl HTMLFontElement { } } -impl HTMLFontElement { - pub fn Color(&self) -> DOMString { +pub trait HTMLFontElementMethods { + fn Color(&self) -> DOMString; + fn SetColor(&mut self, _color: DOMString) -> ErrorResult; + fn Face(&self) -> DOMString; + fn SetFace(&mut self, _face: DOMString) -> ErrorResult; + fn Size(&self) -> DOMString; + fn SetSize(&mut self, _size: DOMString) -> ErrorResult; +} + +impl<'a> HTMLFontElementMethods for JSRef<'a, HTMLFontElement> { + fn Color(&self) -> DOMString { ~"" } - pub fn SetColor(&mut self, _color: DOMString) -> ErrorResult { + fn SetColor(&mut self, _color: DOMString) -> ErrorResult { Ok(()) } - pub fn Face(&self) -> DOMString { + fn Face(&self) -> DOMString { ~"" } - pub fn SetFace(&mut self, _face: DOMString) -> ErrorResult { + fn SetFace(&mut self, _face: DOMString) -> ErrorResult { Ok(()) } - pub fn Size(&self) -> DOMString { + fn Size(&self) -> DOMString { ~"" } - pub fn SetSize(&mut self, _size: DOMString) -> ErrorResult { + fn SetSize(&mut self, _size: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlformelement.rs b/src/components/script/dom/htmlformelement.rs index 329b9e07baf..f045c1437c3 100644 --- a/src/components/script/dom/htmlformelement.rs +++ b/src/components/script/dom/htmlformelement.rs @@ -41,80 +41,107 @@ impl HTMLFormElement { } } -impl HTMLFormElement { - pub fn AcceptCharset(&self) -> DOMString { +pub trait HTMLFormElementMethods { + fn AcceptCharset(&self) -> DOMString; + fn SetAcceptCharset(&mut self, _accept_charset: DOMString) -> ErrorResult; + fn Action(&self) -> DOMString; + fn SetAction(&mut self, _action: DOMString) -> ErrorResult; + fn Autocomplete(&self) -> DOMString; + fn SetAutocomplete(&mut self, _autocomplete: DOMString) -> ErrorResult; + fn Enctype(&self) -> DOMString; + fn SetEnctype(&mut self, _enctype: DOMString) -> ErrorResult; + fn Encoding(&self) -> DOMString; + fn SetEncoding(&mut self, _encoding: DOMString) -> ErrorResult; + fn Method(&self) -> DOMString; + fn SetMethod(&mut self, _method: DOMString) -> ErrorResult; + fn Name(&self) -> DOMString; + fn SetName(&mut self, _name: DOMString) -> ErrorResult; + fn NoValidate(&self) -> bool; + fn SetNoValidate(&mut self, _no_validate: bool) -> ErrorResult; + fn Target(&self) -> DOMString; + fn SetTarget(&mut self, _target: DOMString) -> ErrorResult; + fn Elements(&self) -> Unrooted; + fn Length(&self) -> i32; + fn Submit(&self) -> ErrorResult; + fn Reset(&self); + fn CheckValidity(&self) -> bool; + fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Unrooted; +} + +impl<'a> HTMLFormElementMethods for JSRef<'a, HTMLFormElement> { + fn AcceptCharset(&self) -> DOMString { ~"" } - pub fn SetAcceptCharset(&mut self, _accept_charset: DOMString) -> ErrorResult { + fn SetAcceptCharset(&mut self, _accept_charset: DOMString) -> ErrorResult { Ok(()) } - pub fn Action(&self) -> DOMString { + fn Action(&self) -> DOMString { ~"" } - pub fn SetAction(&mut self, _action: DOMString) -> ErrorResult { + fn SetAction(&mut self, _action: DOMString) -> ErrorResult { Ok(()) } - pub fn Autocomplete(&self) -> DOMString { + fn Autocomplete(&self) -> DOMString { ~"" } - pub fn SetAutocomplete(&mut self, _autocomplete: DOMString) -> ErrorResult { + fn SetAutocomplete(&mut self, _autocomplete: DOMString) -> ErrorResult { Ok(()) } - pub fn Enctype(&self) -> DOMString { + fn Enctype(&self) -> DOMString { ~"" } - pub fn SetEnctype(&mut self, _enctype: DOMString) -> ErrorResult { + fn SetEnctype(&mut self, _enctype: DOMString) -> ErrorResult { Ok(()) } - pub fn Encoding(&self) -> DOMString { + fn Encoding(&self) -> DOMString { ~"" } - pub fn SetEncoding(&mut self, _encoding: DOMString) -> ErrorResult { + fn SetEncoding(&mut self, _encoding: DOMString) -> ErrorResult { Ok(()) } - pub fn Method(&self) -> DOMString { + fn Method(&self) -> DOMString { ~"" } - pub fn SetMethod(&mut self, _method: DOMString) -> ErrorResult { + fn SetMethod(&mut self, _method: DOMString) -> ErrorResult { Ok(()) } - pub fn Name(&self) -> DOMString { + fn Name(&self) -> DOMString { ~"" } - pub fn SetName(&mut self, _name: DOMString) -> ErrorResult { + fn SetName(&mut self, _name: DOMString) -> ErrorResult { Ok(()) } - pub fn NoValidate(&self) -> bool { + fn NoValidate(&self) -> bool { false } - pub fn SetNoValidate(&mut self, _no_validate: bool) -> ErrorResult { + fn SetNoValidate(&mut self, _no_validate: bool) -> ErrorResult { Ok(()) } - pub fn Target(&self) -> DOMString { + fn Target(&self) -> DOMString { ~"" } - pub fn SetTarget(&mut self, _target: DOMString) -> ErrorResult { + fn SetTarget(&mut self, _target: DOMString) -> ErrorResult { Ok(()) } - pub fn Elements(&self) -> Unrooted { + fn Elements(&self) -> Unrooted { // FIXME: https://github.com/mozilla/servo/issues/1844 let roots = RootCollection::new(); let doc = self.htmlelement.element.node.owner_doc().root(&roots); @@ -122,22 +149,23 @@ impl HTMLFormElement { HTMLCollection::new(&*window, Static(vec!())) } - pub fn Length(&self) -> i32 { + fn Length(&self) -> i32 { 0 } - pub fn Submit(&self) -> ErrorResult { + fn Submit(&self) -> ErrorResult { Ok(()) } - pub fn Reset(&self) { + fn Reset(&self) { } - pub fn CheckValidity(&self) -> bool { + fn CheckValidity(&self) -> bool { false } - pub fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Unrooted { + fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Unrooted { fail!("Not implemented.") } } + diff --git a/src/components/script/dom/htmlframeelement.rs b/src/components/script/dom/htmlframeelement.rs index 180124bf6dd..5dd705b494f 100644 --- a/src/components/script/dom/htmlframeelement.rs +++ b/src/components/script/dom/htmlframeelement.rs @@ -41,76 +41,98 @@ impl HTMLFrameElement { } } -impl HTMLFrameElement { - pub fn Name(&self) -> DOMString { +pub trait HTMLFrameElementMethods { + fn Name(&self) -> DOMString; + fn SetName(&mut self, _name: DOMString) -> ErrorResult; + fn Scrolling(&self) -> DOMString; + fn SetScrolling(&mut self, _scrolling: DOMString) -> ErrorResult; + fn Src(&self) -> DOMString; + fn SetSrc(&mut self, _src: DOMString) -> ErrorResult; + fn FrameBorder(&self) -> DOMString; + fn SetFrameBorder(&mut self, _frameborder: DOMString) -> ErrorResult; + fn LongDesc(&self) -> DOMString; + fn SetLongDesc(&mut self, _longdesc: DOMString) -> ErrorResult; + fn NoResize(&self) -> bool; + fn SetNoResize(&mut self, _no_resize: bool) -> ErrorResult; + fn GetContentDocument(&self) -> Option>; + fn GetContentWindow(&self) -> Option>; + fn MarginHeight(&self) -> DOMString; + fn SetMarginHeight(&mut self, _height: DOMString) -> ErrorResult; + fn MarginWidth(&self) -> DOMString; + fn SetMarginWidth(&mut self, _height: DOMString) -> ErrorResult; +} + +impl<'a> HTMLFrameElementMethods for JSRef<'a, HTMLFrameElement> { + fn Name(&self) -> DOMString { ~"" } - pub fn SetName(&mut self, _name: DOMString) -> ErrorResult { + fn SetName(&mut self, _name: DOMString) -> ErrorResult { Ok(()) } - pub fn Scrolling(&self) -> DOMString { + fn Scrolling(&self) -> DOMString { ~"" } - pub fn SetScrolling(&mut self, _scrolling: DOMString) -> ErrorResult { + fn SetScrolling(&mut self, _scrolling: DOMString) -> ErrorResult { Ok(()) } - pub fn Src(&self) -> DOMString { + fn Src(&self) -> DOMString { ~"" } - pub fn SetSrc(&mut self, _src: DOMString) -> ErrorResult { + fn SetSrc(&mut self, _src: DOMString) -> ErrorResult { Ok(()) } - pub fn FrameBorder(&self) -> DOMString { + fn FrameBorder(&self) -> DOMString { ~"" } - pub fn SetFrameBorder(&mut self, _frameborder: DOMString) -> ErrorResult { + fn SetFrameBorder(&mut self, _frameborder: DOMString) -> ErrorResult { Ok(()) } - pub fn LongDesc(&self) -> DOMString { + fn LongDesc(&self) -> DOMString { ~"" } - pub fn SetLongDesc(&mut self, _longdesc: DOMString) -> ErrorResult { + fn SetLongDesc(&mut self, _longdesc: DOMString) -> ErrorResult { Ok(()) } - pub fn NoResize(&self) -> bool { + fn NoResize(&self) -> bool { false } - pub fn SetNoResize(&mut self, _no_resize: bool) -> ErrorResult { + fn SetNoResize(&mut self, _no_resize: bool) -> ErrorResult { Ok(()) } - pub fn GetContentDocument(&self) -> Option> { + fn GetContentDocument(&self) -> Option> { None } - pub fn GetContentWindow(&self) -> Option> { + fn GetContentWindow(&self) -> Option> { None } - pub fn MarginHeight(&self) -> DOMString { + fn MarginHeight(&self) -> DOMString { ~"" } - pub fn SetMarginHeight(&mut self, _height: DOMString) -> ErrorResult { + fn SetMarginHeight(&mut self, _height: DOMString) -> ErrorResult { Ok(()) } - pub fn MarginWidth(&self) -> DOMString { + fn MarginWidth(&self) -> DOMString { ~"" } - pub fn SetMarginWidth(&mut self, _height: DOMString) -> ErrorResult { + fn SetMarginWidth(&mut self, _height: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlframesetelement.rs b/src/components/script/dom/htmlframesetelement.rs index 9177c197ae8..1e58cba197a 100644 --- a/src/components/script/dom/htmlframesetelement.rs +++ b/src/components/script/dom/htmlframesetelement.rs @@ -40,20 +40,28 @@ impl HTMLFrameSetElement { } } -impl HTMLFrameSetElement { - pub fn Cols(&self) -> DOMString { +pub trait HTMLFrameSetElementMethods { + fn Cols(&self) -> DOMString; + fn SetCols(&mut self, _cols: DOMString) -> ErrorResult; + fn Rows(&self) -> DOMString; + fn SetRows(&mut self, _rows: DOMString) -> ErrorResult; +} + +impl<'a> HTMLFrameSetElementMethods for JSRef<'a, HTMLFrameSetElement> { + fn Cols(&self) -> DOMString { ~"" } - pub fn SetCols(&mut self, _cols: DOMString) -> ErrorResult { + fn SetCols(&mut self, _cols: DOMString) -> ErrorResult { Ok(()) } - pub fn Rows(&self) -> DOMString { + fn Rows(&self) -> DOMString { ~"" } - pub fn SetRows(&mut self, _rows: DOMString) -> ErrorResult { + fn SetRows(&mut self, _rows: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlheadelement.rs b/src/components/script/dom/htmlheadelement.rs index 6b10c6078c3..440a95310f6 100644 --- a/src/components/script/dom/htmlheadelement.rs +++ b/src/components/script/dom/htmlheadelement.rs @@ -38,3 +38,6 @@ impl HTMLHeadElement { Node::reflect_node(~element, document, HTMLHeadElementBinding::Wrap) } } + +pub trait HTMLHeadElementMethods { +} diff --git a/src/components/script/dom/htmlheadingelement.rs b/src/components/script/dom/htmlheadingelement.rs index 4574189d7bf..f05ef59a211 100644 --- a/src/components/script/dom/htmlheadingelement.rs +++ b/src/components/script/dom/htmlheadingelement.rs @@ -51,11 +51,17 @@ impl HTMLHeadingElement { } } -impl HTMLHeadingElement { - pub fn Align(&self) -> DOMString { +pub trait HTMLHeadingElementMethods { + fn Align(&self) -> DOMString; + fn SetAlign(&mut self, _align: DOMString); +} + +impl<'a> HTMLHeadingElementMethods for JSRef<'a, HTMLHeadingElement> { + fn Align(&self) -> DOMString { ~"" } - pub fn SetAlign(&mut self, _align: DOMString) { + fn SetAlign(&mut self, _align: DOMString) { } } + diff --git a/src/components/script/dom/htmlhrelement.rs b/src/components/script/dom/htmlhrelement.rs index 14098388c1d..2ad58999b61 100644 --- a/src/components/script/dom/htmlhrelement.rs +++ b/src/components/script/dom/htmlhrelement.rs @@ -40,44 +40,58 @@ impl HTMLHRElement { } } -impl HTMLHRElement { - pub fn Align(&self) -> DOMString { +pub trait HTMLHRElementMethods { + fn Align(&self) -> DOMString; + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult; + fn Color(&self) -> DOMString; + fn SetColor(&mut self, _color: DOMString) -> ErrorResult; + fn NoShade(&self) -> bool; + fn SetNoShade(&self, _no_shade: bool) -> ErrorResult; + fn Size(&self) -> DOMString; + fn SetSize(&mut self, _size: DOMString) -> ErrorResult; + fn Width(&self) -> DOMString; + fn SetWidth(&mut self, _width: DOMString) -> ErrorResult; +} + +impl<'a> HTMLHRElementMethods for JSRef<'a, HTMLHRElement> { + fn Align(&self) -> DOMString { ~"" } - pub fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { Ok(()) } - pub fn Color(&self) -> DOMString { + fn Color(&self) -> DOMString { ~"" } - pub fn SetColor(&mut self, _color: DOMString) -> ErrorResult { + fn SetColor(&mut self, _color: DOMString) -> ErrorResult { Ok(()) } - pub fn NoShade(&self) -> bool { + fn NoShade(&self) -> bool { false } - pub fn SetNoShade(&self, _no_shade: bool) -> ErrorResult { + fn SetNoShade(&self, _no_shade: bool) -> ErrorResult { Ok(()) } - pub fn Size(&self) -> DOMString { + fn Size(&self) -> DOMString { ~"" } - pub fn SetSize(&mut self, _size: DOMString) -> ErrorResult { + fn SetSize(&mut self, _size: DOMString) -> ErrorResult { Ok(()) } - pub fn Width(&self) -> DOMString { + fn Width(&self) -> DOMString { ~"" } - pub fn SetWidth(&mut self, _width: DOMString) -> ErrorResult { + fn SetWidth(&mut self, _width: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlhtmlelement.rs b/src/components/script/dom/htmlhtmlelement.rs index 1930ce271c2..e30968f91f4 100644 --- a/src/components/script/dom/htmlhtmlelement.rs +++ b/src/components/script/dom/htmlhtmlelement.rs @@ -40,12 +40,18 @@ impl HTMLHtmlElement { } } -impl HTMLHtmlElement { - pub fn Version(&self) -> DOMString { +pub trait HTMLHtmlElementMethods { + fn Version(&self) -> DOMString; + fn SetVersion(&mut self, _version: DOMString) -> ErrorResult; +} + +impl<'a> HTMLHtmlElementMethods for JSRef<'a, HTMLHtmlElement> { + fn Version(&self) -> DOMString { ~"" } - pub fn SetVersion(&mut self, _version: DOMString) -> ErrorResult { + fn SetVersion(&mut self, _version: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmliframeelement.rs b/src/components/script/dom/htmliframeelement.rs index c157e2ad445..316468342f1 100644 --- a/src/components/script/dom/htmliframeelement.rs +++ b/src/components/script/dom/htmliframeelement.rs @@ -80,122 +80,154 @@ impl HTMLIFrameElement { } } -impl HTMLIFrameElement { - pub fn Src(&self) -> DOMString { +pub trait HTMLIFrameElementMethods { + fn Src(&self) -> DOMString; + fn SetSrc(&mut self, _src: DOMString) -> ErrorResult; + fn Srcdoc(&self) -> DOMString; + fn SetSrcdoc(&mut self, _srcdoc: DOMString) -> ErrorResult; + fn Name(&self) -> DOMString; + fn SetName(&mut self, _name: DOMString) -> ErrorResult; + fn Sandbox(&self, abstract_self: &JSRef) -> DOMString; + fn SetSandbox(&mut self, abstract_self: &mut JSRef, sandbox: DOMString); + fn AllowFullscreen(&self) -> bool; + fn SetAllowFullscreen(&mut self, _allow: bool) -> ErrorResult; + fn Width(&self) -> DOMString; + fn SetWidth(&mut self, _width: DOMString) -> ErrorResult; + fn Height(&self) -> DOMString; + fn SetHeight(&mut self, _height: DOMString) -> ErrorResult; + fn GetContentDocument(&self) -> Option>; + fn GetContentWindow(&self) -> Option>; + fn Align(&self) -> DOMString; + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult; + fn Scrolling(&self) -> DOMString; + fn SetScrolling(&mut self, _scrolling: DOMString) -> ErrorResult; + fn FrameBorder(&self) -> DOMString; + fn SetFrameBorder(&mut self, _frameborder: DOMString) -> ErrorResult; + fn LongDesc(&self) -> DOMString; + fn SetLongDesc(&mut self, _longdesc: DOMString) -> ErrorResult; + fn MarginHeight(&self) -> DOMString; + fn SetMarginHeight(&mut self, _marginheight: DOMString) -> ErrorResult; + fn MarginWidth(&self) -> DOMString; + fn SetMarginWidth(&mut self, _marginwidth: DOMString) -> ErrorResult; + fn GetSVGDocument(&self) -> Option>; +} + +impl<'a> HTMLIFrameElementMethods for JSRef<'a, HTMLIFrameElement> { + fn Src(&self) -> DOMString { ~"" } - pub fn SetSrc(&mut self, _src: DOMString) -> ErrorResult { + fn SetSrc(&mut self, _src: DOMString) -> ErrorResult { Ok(()) } - pub fn Srcdoc(&self) -> DOMString { + fn Srcdoc(&self) -> DOMString { ~"" } - pub fn SetSrcdoc(&mut self, _srcdoc: DOMString) -> ErrorResult { + fn SetSrcdoc(&mut self, _srcdoc: DOMString) -> ErrorResult { Ok(()) } - pub fn Name(&self) -> DOMString { + fn Name(&self) -> DOMString { ~"" } - pub fn SetName(&mut self, _name: DOMString) -> ErrorResult { + fn SetName(&mut self, _name: DOMString) -> ErrorResult { Ok(()) } - pub fn Sandbox(&self, abstract_self: &JSRef) -> DOMString { + fn Sandbox(&self, abstract_self: &JSRef) -> DOMString { let element: &JSRef = ElementCast::from_ref(abstract_self); element.get_string_attribute("sandbox") } - pub fn SetSandbox(&mut self, abstract_self: &mut JSRef, sandbox: DOMString) { + fn SetSandbox(&mut self, abstract_self: &mut JSRef, sandbox: DOMString) { let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_string_attribute("sandbox", sandbox); } - pub fn AllowFullscreen(&self) -> bool { + fn AllowFullscreen(&self) -> bool { false } - pub fn SetAllowFullscreen(&mut self, _allow: bool) -> ErrorResult { + fn SetAllowFullscreen(&mut self, _allow: bool) -> ErrorResult { Ok(()) } - pub fn Width(&self) -> DOMString { + fn Width(&self) -> DOMString { ~"" } - pub fn SetWidth(&mut self, _width: DOMString) -> ErrorResult { + fn SetWidth(&mut self, _width: DOMString) -> ErrorResult { Ok(()) } - pub fn Height(&self) -> DOMString { + fn Height(&self) -> DOMString { ~"" } - pub fn SetHeight(&mut self, _height: DOMString) -> ErrorResult { + fn SetHeight(&mut self, _height: DOMString) -> ErrorResult { Ok(()) } - pub fn GetContentDocument(&self) -> Option> { + fn GetContentDocument(&self) -> Option> { None } - pub fn GetContentWindow(&self) -> Option> { + fn GetContentWindow(&self) -> Option> { None } - pub fn Align(&self) -> DOMString { + fn Align(&self) -> DOMString { ~"" } - pub fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { Ok(()) } - pub fn Scrolling(&self) -> DOMString { + fn Scrolling(&self) -> DOMString { ~"" } - pub fn SetScrolling(&mut self, _scrolling: DOMString) -> ErrorResult { + fn SetScrolling(&mut self, _scrolling: DOMString) -> ErrorResult { Ok(()) } - pub fn FrameBorder(&self) -> DOMString { + fn FrameBorder(&self) -> DOMString { ~"" } - pub fn SetFrameBorder(&mut self, _frameborder: DOMString) -> ErrorResult { + fn SetFrameBorder(&mut self, _frameborder: DOMString) -> ErrorResult { Ok(()) } - pub fn LongDesc(&self) -> DOMString { + fn LongDesc(&self) -> DOMString { ~"" } - pub fn SetLongDesc(&mut self, _longdesc: DOMString) -> ErrorResult { + fn SetLongDesc(&mut self, _longdesc: DOMString) -> ErrorResult { Ok(()) } - pub fn MarginHeight(&self) -> DOMString { + fn MarginHeight(&self) -> DOMString { ~"" } - pub fn SetMarginHeight(&mut self, _marginheight: DOMString) -> ErrorResult { + fn SetMarginHeight(&mut self, _marginheight: DOMString) -> ErrorResult { Ok(()) } - pub fn MarginWidth(&self) -> DOMString { + fn MarginWidth(&self) -> DOMString { ~"" } - pub fn SetMarginWidth(&mut self, _marginwidth: DOMString) -> ErrorResult { + fn SetMarginWidth(&mut self, _marginwidth: DOMString) -> ErrorResult { Ok(()) } - pub fn GetSVGDocument(&self) -> Option> { + fn GetSVGDocument(&self) -> Option> { None } } diff --git a/src/components/script/dom/htmlimageelement.rs b/src/components/script/dom/htmlimageelement.rs index 04528c54283..efe6a0401d6 100644 --- a/src/components/script/dom/htmlimageelement.rs +++ b/src/components/script/dom/htmlimageelement.rs @@ -47,9 +47,7 @@ impl HTMLImageElement { let element = HTMLImageElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLImageElementBinding::Wrap) } -} -impl HTMLImageElement { pub fn image<'a>(&'a self) -> &'a Option { &*self.image } @@ -79,145 +77,179 @@ impl HTMLImageElement { } } } +} - pub fn Alt(&self, abstract_self: &JSRef) -> DOMString { +pub trait HTMLImageElementMethods { + fn Alt(&self, abstract_self: &JSRef) -> DOMString; + fn SetAlt(&mut self, abstract_self: &mut JSRef, alt: DOMString); + fn Src(&self, abstract_self: &JSRef) -> DOMString; + fn SetSrc(&mut self, abstract_self: &mut JSRef, src: DOMString); + fn CrossOrigin(&self) -> DOMString; + fn SetCrossOrigin(&mut self, _cross_origin: DOMString) -> ErrorResult; + fn UseMap(&self, abstract_self: &JSRef) -> DOMString; + fn SetUseMap(&mut self, abstract_self: &mut JSRef, use_map: DOMString); + fn IsMap(&self, abstract_self: &JSRef) -> bool; + fn SetIsMap(&self, abstract_self: &mut JSRef, is_map: bool); + fn Width(&self, abstract_self: &JSRef) -> u32; + fn SetWidth(&mut self, abstract_self: &mut JSRef, width: u32); + fn Height(&self, abstract_self: &JSRef) -> u32; + fn SetHeight(&mut self, abstract_self: &mut JSRef, height: u32); + fn NaturalWidth(&self) -> u32; + fn NaturalHeight(&self) -> u32; + fn Complete(&self) -> bool; + fn Name(&self, abstract_self: &JSRef) -> DOMString; + fn SetName(&mut self, abstract_self: &mut JSRef, name: DOMString); + fn Align(&self, abstract_self: &JSRef) -> DOMString; + fn SetAlign(&mut self, abstract_self: &mut JSRef, align: DOMString); + fn Hspace(&self, abstract_self: &JSRef) -> u32; + fn SetHspace(&mut self, abstract_self: &mut JSRef, hspace: u32); + fn Vspace(&self, abstract_self: &JSRef) -> u32; + fn SetVspace(&mut self, abstract_self: &mut JSRef, vspace: u32); + fn LongDesc(&self, abstract_self: &JSRef) -> DOMString; + fn SetLongDesc(&mut self, abstract_self: &mut JSRef, longdesc: DOMString); + fn Border(&self, abstract_self: &JSRef) -> DOMString; + fn SetBorder(&mut self, abstract_self: &mut JSRef, border: DOMString); +} + +impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { + fn Alt(&self, abstract_self: &JSRef) -> DOMString { let element: &JSRef = ElementCast::from_ref(abstract_self); element.get_string_attribute("alt") } - pub fn SetAlt(&mut self, abstract_self: &mut JSRef, alt: DOMString) { + fn SetAlt(&mut self, abstract_self: &mut JSRef, alt: DOMString) { let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_string_attribute("alt", alt) } - pub fn Src(&self, abstract_self: &JSRef) -> DOMString { + fn Src(&self, abstract_self: &JSRef) -> DOMString { let element: &JSRef = ElementCast::from_ref(abstract_self); element.get_string_attribute("src") } - pub fn SetSrc(&mut self, abstract_self: &mut JSRef, src: DOMString) { + fn SetSrc(&mut self, abstract_self: &mut JSRef, src: DOMString) { let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_url_attribute("src", src) } - pub fn CrossOrigin(&self) -> DOMString { + fn CrossOrigin(&self) -> DOMString { ~"" } - pub fn SetCrossOrigin(&mut self, _cross_origin: DOMString) -> ErrorResult { + fn SetCrossOrigin(&mut self, _cross_origin: DOMString) -> ErrorResult { Ok(()) } - pub fn UseMap(&self, abstract_self: &JSRef) -> DOMString { + fn UseMap(&self, abstract_self: &JSRef) -> DOMString { let element: &JSRef = ElementCast::from_ref(abstract_self); element.get_string_attribute("useMap") } - pub fn SetUseMap(&mut self, abstract_self: &mut JSRef, use_map: DOMString) { + fn SetUseMap(&mut self, abstract_self: &mut JSRef, use_map: DOMString) { let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_string_attribute("useMap", use_map) } - pub fn IsMap(&self, abstract_self: &JSRef) -> bool { + fn IsMap(&self, abstract_self: &JSRef) -> bool { let element: &JSRef = ElementCast::from_ref(abstract_self); from_str::(element.get_string_attribute("hspace")).unwrap() } - pub fn SetIsMap(&self, abstract_self: &mut JSRef, is_map: bool) { + fn SetIsMap(&self, abstract_self: &mut JSRef, is_map: bool) { let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_string_attribute("isMap", is_map.to_str()) } - pub fn Width(&self, abstract_self: &JSRef) -> u32 { + fn Width(&self, abstract_self: &JSRef) -> u32 { let node: &JSRef = NodeCast::from_ref(abstract_self); let rect = node.get_bounding_content_box(); to_px(rect.size.width) as u32 } - pub fn SetWidth(&mut self, abstract_self: &mut JSRef, width: u32) { + fn SetWidth(&mut self, abstract_self: &mut JSRef, width: u32) { let elem: &mut JSRef = ElementCast::from_mut_ref(abstract_self); elem.set_uint_attribute("width", width) } - pub fn Height(&self, abstract_self: &JSRef) -> u32 { + fn Height(&self, abstract_self: &JSRef) -> u32 { let node: &JSRef = NodeCast::from_ref(abstract_self); let rect = node.get_bounding_content_box(); to_px(rect.size.height) as u32 } - pub fn SetHeight(&mut self, abstract_self: &mut JSRef, height: u32) { + fn SetHeight(&mut self, abstract_self: &mut JSRef, height: u32) { let elem: &mut JSRef = ElementCast::from_mut_ref(abstract_self); elem.set_uint_attribute("height", height) } - pub fn NaturalWidth(&self) -> u32 { + fn NaturalWidth(&self) -> u32 { 0 } - pub fn NaturalHeight(&self) -> u32 { + fn NaturalHeight(&self) -> u32 { 0 } - pub fn Complete(&self) -> bool { + fn Complete(&self) -> bool { false } - pub fn Name(&self, abstract_self: &JSRef) -> DOMString { + fn Name(&self, abstract_self: &JSRef) -> DOMString { let element: &JSRef = ElementCast::from_ref(abstract_self); element.get_string_attribute("name") } - pub fn SetName(&mut self, abstract_self: &mut JSRef, name: DOMString) { + fn SetName(&mut self, abstract_self: &mut JSRef, name: DOMString) { let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_string_attribute("name", name) } - pub fn Align(&self, abstract_self: &JSRef) -> DOMString { + fn Align(&self, abstract_self: &JSRef) -> DOMString { let element: &JSRef = ElementCast::from_ref(abstract_self); element.get_string_attribute("longdesc") } - pub fn SetAlign(&mut self, abstract_self: &mut JSRef, align: DOMString) { + fn SetAlign(&mut self, abstract_self: &mut JSRef, align: DOMString) { let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_string_attribute("align", align) } - pub fn Hspace(&self, abstract_self: &JSRef) -> u32 { + fn Hspace(&self, abstract_self: &JSRef) -> u32 { let element: &JSRef = ElementCast::from_ref(abstract_self); from_str::(element.get_string_attribute("hspace")).unwrap() } - pub fn SetHspace(&mut self, abstract_self: &mut JSRef, hspace: u32) { + fn SetHspace(&mut self, abstract_self: &mut JSRef, hspace: u32) { let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_uint_attribute("hspace", hspace) } - pub fn Vspace(&self, abstract_self: &JSRef) -> u32 { + fn Vspace(&self, abstract_self: &JSRef) -> u32 { let element: &JSRef = ElementCast::from_ref(abstract_self); from_str::(element.get_string_attribute("vspace")).unwrap() } - pub fn SetVspace(&mut self, abstract_self: &mut JSRef, vspace: u32) { + fn SetVspace(&mut self, abstract_self: &mut JSRef, vspace: u32) { let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_uint_attribute("vspace", vspace) } - pub fn LongDesc(&self, abstract_self: &JSRef) -> DOMString { + fn LongDesc(&self, abstract_self: &JSRef) -> DOMString { let element: &JSRef = ElementCast::from_ref(abstract_self); element.get_string_attribute("longdesc") } - pub fn SetLongDesc(&mut self, abstract_self: &mut JSRef, longdesc: DOMString) { + fn SetLongDesc(&mut self, abstract_self: &mut JSRef, longdesc: DOMString) { let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_string_attribute("longdesc", longdesc) } - pub fn Border(&self, abstract_self: &JSRef) -> DOMString { + fn Border(&self, abstract_self: &JSRef) -> DOMString { let element: &JSRef = ElementCast::from_ref(abstract_self); element.get_string_attribute("border") } - pub fn SetBorder(&mut self, abstract_self: &mut JSRef, border: DOMString) { + fn SetBorder(&mut self, abstract_self: &mut JSRef, border: DOMString) { let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); element.set_string_attribute("border", border) } diff --git a/src/components/script/dom/htmlinputelement.rs b/src/components/script/dom/htmlinputelement.rs index 55d8fc7c1a7..f56578c6cdd 100644 --- a/src/components/script/dom/htmlinputelement.rs +++ b/src/components/script/dom/htmlinputelement.rs @@ -40,310 +40,392 @@ impl HTMLInputElement { } } -impl HTMLInputElement { - pub fn Accept(&self) -> DOMString { +pub trait HTMLInputElementMethods { + fn Accept(&self) -> DOMString; + fn SetAccept(&mut self, _accept: DOMString) -> ErrorResult; + fn Alt(&self) -> DOMString; + fn SetAlt(&mut self, _alt: DOMString) -> ErrorResult; + fn Autocomplete(&self) -> DOMString; + fn SetAutocomplete(&mut self, _autocomple: DOMString) -> ErrorResult; + fn Autofocus(&self) -> bool; + fn SetAutofocus(&mut self, _autofocus: bool) -> ErrorResult; + fn DefaultChecked(&self) -> bool; + fn SetDefaultChecked(&mut self, _default_checked: bool) -> ErrorResult; + fn Checked(&self) -> bool; + fn SetChecked(&mut self, _checked: bool); + fn Disabled(&self) -> bool; + fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult; + fn FormAction(&self) -> DOMString; + fn SetFormAction(&mut self, _form_action: DOMString) -> ErrorResult; + fn FormEnctype(&self) -> DOMString; + fn SetFormEnctype(&mut self, _form_enctype: DOMString) -> ErrorResult; + fn FormMethod(&self) -> DOMString; + fn SetFormMethod(&mut self, _form_method: DOMString) -> ErrorResult; + fn FormNoValidate(&self) -> bool; + fn SetFormNoValidate(&mut self, _form_no_validate: bool) -> ErrorResult; + fn FormTarget(&self) -> DOMString; + fn SetFormTarget(&mut self, _form_target: DOMString) -> ErrorResult; + fn Height(&self) -> u32; + fn SetHeight(&mut self, _height: u32) -> ErrorResult; + fn Indeterminate(&self) -> bool; + fn SetIndeterminate(&mut self, _indeterminate: bool); + fn InputMode(&self) -> DOMString; + fn SetInputMode(&mut self, _input_mode: DOMString) -> ErrorResult; + fn Max(&self) -> DOMString; + fn SetMax(&mut self, _max: DOMString) -> ErrorResult; + fn MaxLength(&self) -> i32; + fn SetMaxLength(&mut self, _max_length: i32) -> ErrorResult; + fn Min(&self) -> DOMString; + fn SetMin(&mut self, _min: DOMString) -> ErrorResult; + fn Multiple(&self) -> bool; + fn SetMultiple(&mut self, _multiple: bool) -> ErrorResult; + fn Name(&self) -> DOMString; + fn SetName(&mut self, _name: DOMString) -> ErrorResult; + fn Pattern(&self) -> DOMString; + fn SetPattern(&mut self, _pattern: DOMString) -> ErrorResult; + fn Placeholder(&self) -> DOMString; + fn SetPlaceholder(&mut self, _placeholder: DOMString) -> ErrorResult; + fn ReadOnly(&self) -> bool; + fn SetReadOnly(&mut self, _read_only: bool) -> ErrorResult; + fn Required(&self) -> bool; + fn SetRequired(&mut self, _required: bool) -> ErrorResult; + fn Size(&self) -> u32; + fn SetSize(&mut self, _size: u32) -> ErrorResult; + fn Src(&self) -> DOMString; + fn SetSrc(&mut self, _src: DOMString) -> ErrorResult; + fn Step(&self) -> DOMString; + fn SetStep(&mut self, _step: DOMString) -> ErrorResult; + fn Type(&self) -> DOMString; + fn SetType(&mut self, _type: DOMString) -> ErrorResult; + fn DefaultValue(&self) -> DOMString; + fn SetDefaultValue(&mut self, _default_value: DOMString) -> ErrorResult; + fn Value(&self) -> DOMString; + fn SetValue(&mut self, _value: DOMString) -> ErrorResult; + fn Width(&self) -> u32; + fn SetWidth(&mut self, _width: u32); + fn WillValidate(&self) -> bool; + fn SetWillValidate(&self, _will_validate: bool); + fn GetValidationMessage(&self) -> Fallible; + fn CheckValidity(&self) -> bool; + fn SetCustomValidity(&self, _error: DOMString); + fn Select(&self); + fn GetSelectionStart(&self) -> Fallible; + fn SetSelectionStart(&mut self, _selection_start: i32) -> ErrorResult; + fn GetSelectionEnd(&self) -> Fallible; + fn SetSelectionEnd(&mut self, _selection_end: i32) -> ErrorResult; + fn GetSelectionDirection(&self) -> Fallible; + fn SetSelectionDirection(&mut self, _selection_direction: DOMString) -> ErrorResult; + fn Align(&self) -> DOMString; + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult; + fn UseMap(&self) -> DOMString; + fn SetUseMap(&mut self, _align: DOMString) -> ErrorResult; +} + +impl<'a> HTMLInputElementMethods for JSRef<'a, HTMLInputElement> { + fn Accept(&self) -> DOMString { ~"" } - pub fn SetAccept(&mut self, _accept: DOMString) -> ErrorResult { + fn SetAccept(&mut self, _accept: DOMString) -> ErrorResult { Ok(()) } - pub fn Alt(&self) -> DOMString { + fn Alt(&self) -> DOMString { ~"" } - pub fn SetAlt(&mut self, _alt: DOMString) -> ErrorResult { + fn SetAlt(&mut self, _alt: DOMString) -> ErrorResult { Ok(()) } - pub fn Autocomplete(&self) -> DOMString { + fn Autocomplete(&self) -> DOMString { ~"" } - pub fn SetAutocomplete(&mut self, _autocomple: DOMString) -> ErrorResult { + fn SetAutocomplete(&mut self, _autocomple: DOMString) -> ErrorResult { Ok(()) } - pub fn Autofocus(&self) -> bool { + fn Autofocus(&self) -> bool { false } - pub fn SetAutofocus(&mut self, _autofocus: bool) -> ErrorResult { + fn SetAutofocus(&mut self, _autofocus: bool) -> ErrorResult { Ok(()) } - pub fn DefaultChecked(&self) -> bool { + fn DefaultChecked(&self) -> bool { false } - pub fn SetDefaultChecked(&mut self, _default_checked: bool) -> ErrorResult { + fn SetDefaultChecked(&mut self, _default_checked: bool) -> ErrorResult { Ok(()) } - pub fn Checked(&self) -> bool { + fn Checked(&self) -> bool { false } - pub fn SetChecked(&mut self, _checked: bool) { + fn SetChecked(&mut self, _checked: bool) { } - pub fn Disabled(&self) -> bool { + fn Disabled(&self) -> bool { false } - pub fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult { + fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult { Ok(()) } - pub fn FormAction(&self) -> DOMString { + fn FormAction(&self) -> DOMString { ~"" } - pub fn SetFormAction(&mut self, _form_action: DOMString) -> ErrorResult { + fn SetFormAction(&mut self, _form_action: DOMString) -> ErrorResult { Ok(()) } - pub fn FormEnctype(&self) -> DOMString { + fn FormEnctype(&self) -> DOMString { ~"" } - pub fn SetFormEnctype(&mut self, _form_enctype: DOMString) -> ErrorResult { + fn SetFormEnctype(&mut self, _form_enctype: DOMString) -> ErrorResult { Ok(()) } - pub fn FormMethod(&self) -> DOMString { + fn FormMethod(&self) -> DOMString { ~"" } - pub fn SetFormMethod(&mut self, _form_method: DOMString) -> ErrorResult { + fn SetFormMethod(&mut self, _form_method: DOMString) -> ErrorResult { Ok(()) } - pub fn FormNoValidate(&self) -> bool { + fn FormNoValidate(&self) -> bool { false } - pub fn SetFormNoValidate(&mut self, _form_no_validate: bool) -> ErrorResult { + fn SetFormNoValidate(&mut self, _form_no_validate: bool) -> ErrorResult { Ok(()) } - pub fn FormTarget(&self) -> DOMString { + fn FormTarget(&self) -> DOMString { ~"" } - pub fn SetFormTarget(&mut self, _form_target: DOMString) -> ErrorResult { + fn SetFormTarget(&mut self, _form_target: DOMString) -> ErrorResult { Ok(()) } - pub fn Height(&self) -> u32 { + fn Height(&self) -> u32 { 0 } - pub fn SetHeight(&mut self, _height: u32) -> ErrorResult { + fn SetHeight(&mut self, _height: u32) -> ErrorResult { Ok(()) } - pub fn Indeterminate(&self) -> bool { + fn Indeterminate(&self) -> bool { false } - pub fn SetIndeterminate(&mut self, _indeterminate: bool) { + fn SetIndeterminate(&mut self, _indeterminate: bool) { } - pub fn InputMode(&self) -> DOMString { + fn InputMode(&self) -> DOMString { ~"" } - pub fn SetInputMode(&mut self, _input_mode: DOMString) -> ErrorResult { + fn SetInputMode(&mut self, _input_mode: DOMString) -> ErrorResult { Ok(()) } - pub fn Max(&self) -> DOMString { + fn Max(&self) -> DOMString { ~"" } - pub fn SetMax(&mut self, _max: DOMString) -> ErrorResult { + fn SetMax(&mut self, _max: DOMString) -> ErrorResult { Ok(()) } - pub fn MaxLength(&self) -> i32 { + fn MaxLength(&self) -> i32 { 0 } - pub fn SetMaxLength(&mut self, _max_length: i32) -> ErrorResult { + fn SetMaxLength(&mut self, _max_length: i32) -> ErrorResult { Ok(()) } - pub fn Min(&self) -> DOMString { + fn Min(&self) -> DOMString { ~"" } - pub fn SetMin(&mut self, _min: DOMString) -> ErrorResult { + fn SetMin(&mut self, _min: DOMString) -> ErrorResult { Ok(()) } - pub fn Multiple(&self) -> bool { + fn Multiple(&self) -> bool { false } - pub fn SetMultiple(&mut self, _multiple: bool) -> ErrorResult { + fn SetMultiple(&mut self, _multiple: bool) -> ErrorResult { Ok(()) } - pub fn Name(&self) -> DOMString { + fn Name(&self) -> DOMString { ~"" } - pub fn SetName(&mut self, _name: DOMString) -> ErrorResult { + fn SetName(&mut self, _name: DOMString) -> ErrorResult { Ok(()) } - pub fn Pattern(&self) -> DOMString { + fn Pattern(&self) -> DOMString { ~"" } - pub fn SetPattern(&mut self, _pattern: DOMString) -> ErrorResult { + fn SetPattern(&mut self, _pattern: DOMString) -> ErrorResult { Ok(()) } - pub fn Placeholder(&self) -> DOMString { + fn Placeholder(&self) -> DOMString { ~"" } - pub fn SetPlaceholder(&mut self, _placeholder: DOMString) -> ErrorResult { + fn SetPlaceholder(&mut self, _placeholder: DOMString) -> ErrorResult { Ok(()) } - pub fn ReadOnly(&self) -> bool { + fn ReadOnly(&self) -> bool { false } - pub fn SetReadOnly(&mut self, _read_only: bool) -> ErrorResult { + fn SetReadOnly(&mut self, _read_only: bool) -> ErrorResult { Ok(()) } - pub fn Required(&self) -> bool { + fn Required(&self) -> bool { false } - pub fn SetRequired(&mut self, _required: bool) -> ErrorResult { + fn SetRequired(&mut self, _required: bool) -> ErrorResult { Ok(()) } - pub fn Size(&self) -> u32 { + fn Size(&self) -> u32 { 0 } - pub fn SetSize(&mut self, _size: u32) -> ErrorResult { + fn SetSize(&mut self, _size: u32) -> ErrorResult { Ok(()) } - pub fn Src(&self) -> DOMString { + fn Src(&self) -> DOMString { ~"" } - pub fn SetSrc(&mut self, _src: DOMString) -> ErrorResult { + fn SetSrc(&mut self, _src: DOMString) -> ErrorResult { Ok(()) } - pub fn Step(&self) -> DOMString { + fn Step(&self) -> DOMString { ~"" } - pub fn SetStep(&mut self, _step: DOMString) -> ErrorResult { + fn SetStep(&mut self, _step: DOMString) -> ErrorResult { Ok(()) } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn SetType(&mut self, _type: DOMString) -> ErrorResult { + fn SetType(&mut self, _type: DOMString) -> ErrorResult { Ok(()) } - pub fn DefaultValue(&self) -> DOMString { + fn DefaultValue(&self) -> DOMString { ~"" } - pub fn SetDefaultValue(&mut self, _default_value: DOMString) -> ErrorResult { + fn SetDefaultValue(&mut self, _default_value: DOMString) -> ErrorResult { Ok(()) } - pub fn Value(&self) -> DOMString { + fn Value(&self) -> DOMString { ~"" } - pub fn SetValue(&mut self, _value: DOMString) -> ErrorResult { + fn SetValue(&mut self, _value: DOMString) -> ErrorResult { Ok(()) } - pub fn Width(&self) -> u32 { + fn Width(&self) -> u32 { 0 } - pub fn SetWidth(&mut self, _width: u32) { + fn SetWidth(&mut self, _width: u32) { } - pub fn WillValidate(&self) -> bool { + fn WillValidate(&self) -> bool { false } - pub fn SetWillValidate(&self, _will_validate: bool) { + fn SetWillValidate(&self, _will_validate: bool) { } - pub fn GetValidationMessage(&self) -> Fallible { + fn GetValidationMessage(&self) -> Fallible { Ok(~"") } - pub fn CheckValidity(&self) -> bool { + fn CheckValidity(&self) -> bool { false } - pub fn SetCustomValidity(&self, _error: DOMString) { + fn SetCustomValidity(&self, _error: DOMString) { } - pub fn Select(&self) { + fn Select(&self) { } - pub fn GetSelectionStart(&self) -> Fallible { + fn GetSelectionStart(&self) -> Fallible { Ok(0) } - pub fn SetSelectionStart(&mut self, _selection_start: i32) -> ErrorResult { + fn SetSelectionStart(&mut self, _selection_start: i32) -> ErrorResult { Ok(()) } - pub fn GetSelectionEnd(&self) -> Fallible { + fn GetSelectionEnd(&self) -> Fallible { Ok(0) } - pub fn SetSelectionEnd(&mut self, _selection_end: i32) -> ErrorResult { + fn SetSelectionEnd(&mut self, _selection_end: i32) -> ErrorResult { Ok(()) } - pub fn GetSelectionDirection(&self) -> Fallible { + fn GetSelectionDirection(&self) -> Fallible { Ok(~"") } - pub fn SetSelectionDirection(&mut self, _selection_direction: DOMString) -> ErrorResult { + fn SetSelectionDirection(&mut self, _selection_direction: DOMString) -> ErrorResult { Ok(()) } - pub fn Align(&self) -> DOMString { + fn Align(&self) -> DOMString { ~"" } - pub fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { Ok(()) } - pub fn UseMap(&self) -> DOMString { + fn UseMap(&self) -> DOMString { ~"" } - pub fn SetUseMap(&mut self, _align: DOMString) -> ErrorResult { + fn SetUseMap(&mut self, _align: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmllabelelement.rs b/src/components/script/dom/htmllabelelement.rs index dcd080f7f24..c11132a7e9b 100644 --- a/src/components/script/dom/htmllabelelement.rs +++ b/src/components/script/dom/htmllabelelement.rs @@ -39,11 +39,17 @@ impl HTMLLabelElement { } } -impl HTMLLabelElement { - pub fn HtmlFor(&self) -> DOMString { +pub trait HTMLLabelElementMethods { + fn HtmlFor(&self) -> DOMString; + fn SetHtmlFor(&mut self, _html_for: DOMString); +} + +impl<'a> HTMLLabelElementMethods for JSRef<'a, HTMLLabelElement> { + fn HtmlFor(&self) -> DOMString { ~"" } - pub fn SetHtmlFor(&mut self, _html_for: DOMString) { + fn SetHtmlFor(&mut self, _html_for: DOMString) { } } + diff --git a/src/components/script/dom/htmllegendelement.rs b/src/components/script/dom/htmllegendelement.rs index 696247f40db..22ddb92aca5 100644 --- a/src/components/script/dom/htmllegendelement.rs +++ b/src/components/script/dom/htmllegendelement.rs @@ -40,12 +40,18 @@ impl HTMLLegendElement { } } -impl HTMLLegendElement { - pub fn Align(&self) -> DOMString { +pub trait HTMLLegendElementMethods { + fn Align(&self) -> DOMString; + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult; +} + +impl<'a> HTMLLegendElementMethods for JSRef<'a, HTMLLegendElement> { + fn Align(&self) -> DOMString { ~"" } - pub fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmllielement.rs b/src/components/script/dom/htmllielement.rs index d3b625e5987..97dee3e3f25 100644 --- a/src/components/script/dom/htmllielement.rs +++ b/src/components/script/dom/htmllielement.rs @@ -40,20 +40,28 @@ impl HTMLLIElement { } } -impl HTMLLIElement { - pub fn Value(&self) -> i32 { +pub trait HTMLLIElementMethods { + fn Value(&self) -> i32; + fn SetValue(&mut self, _value: i32) -> ErrorResult; + fn Type(&self) -> DOMString; + fn SetType(&mut self, _type: DOMString) -> ErrorResult; +} + +impl<'a> HTMLLIElementMethods for JSRef<'a, HTMLLIElement> { + fn Value(&self) -> i32 { 0 } - pub fn SetValue(&mut self, _value: i32) -> ErrorResult { + fn SetValue(&mut self, _value: i32) -> ErrorResult { Ok(()) } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn SetType(&mut self, _type: DOMString) -> ErrorResult { + fn SetType(&mut self, _type: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmllinkelement.rs b/src/components/script/dom/htmllinkelement.rs index 3d474d1af64..f40bd112585 100644 --- a/src/components/script/dom/htmllinkelement.rs +++ b/src/components/script/dom/htmllinkelement.rs @@ -40,83 +40,107 @@ impl HTMLLinkElement { } } -impl HTMLLinkElement { - pub fn Disabled(&self) -> bool { +pub trait HTMLLinkElementMethods { + fn Disabled(&self) -> bool; + fn SetDisabled(&mut self, _disable: bool); + fn Href(&self) -> DOMString; + fn SetHref(&mut self, _href: DOMString) -> ErrorResult; + fn CrossOrigin(&self) -> DOMString; + fn SetCrossOrigin(&mut self, _cross_origin: DOMString) -> ErrorResult; + fn Rel(&self) -> DOMString; + fn SetRel(&mut self, _rel: DOMString) -> ErrorResult; + fn Media(&self) -> DOMString; + fn SetMedia(&mut self, _media: DOMString) -> ErrorResult; + fn Hreflang(&self) -> DOMString; + fn SetHreflang(&mut self, _href: DOMString) -> ErrorResult; + fn Type(&self) -> DOMString; + fn SetType(&mut self, _type: DOMString) -> ErrorResult; + fn Charset(&self) -> DOMString; + fn SetCharset(&mut self, _charset: DOMString) -> ErrorResult; + fn Rev(&self) -> DOMString; + fn SetRev(&mut self, _rev: DOMString) -> ErrorResult; + fn Target(&self) -> DOMString; + fn SetTarget(&mut self, _target: DOMString) -> ErrorResult; +} + +impl<'a> HTMLLinkElementMethods for JSRef<'a, HTMLLinkElement> { + fn Disabled(&self) -> bool { false } - pub fn SetDisabled(&mut self, _disable: bool) { + fn SetDisabled(&mut self, _disable: bool) { } - pub fn Href(&self) -> DOMString { + fn Href(&self) -> DOMString { ~"" } - pub fn SetHref(&mut self, _href: DOMString) -> ErrorResult { + fn SetHref(&mut self, _href: DOMString) -> ErrorResult { Ok(()) } - pub fn CrossOrigin(&self) -> DOMString { + fn CrossOrigin(&self) -> DOMString { ~"" } - pub fn SetCrossOrigin(&mut self, _cross_origin: DOMString) -> ErrorResult { + fn SetCrossOrigin(&mut self, _cross_origin: DOMString) -> ErrorResult { Ok(()) } - pub fn Rel(&self) -> DOMString { + fn Rel(&self) -> DOMString { ~"" } - pub fn SetRel(&mut self, _rel: DOMString) -> ErrorResult { + fn SetRel(&mut self, _rel: DOMString) -> ErrorResult { Ok(()) } - pub fn Media(&self) -> DOMString { + fn Media(&self) -> DOMString { ~"" } - pub fn SetMedia(&mut self, _media: DOMString) -> ErrorResult { + fn SetMedia(&mut self, _media: DOMString) -> ErrorResult { Ok(()) } - pub fn Hreflang(&self) -> DOMString { + fn Hreflang(&self) -> DOMString { ~"" } - pub fn SetHreflang(&mut self, _href: DOMString) -> ErrorResult { + fn SetHreflang(&mut self, _href: DOMString) -> ErrorResult { Ok(()) } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn SetType(&mut self, _type: DOMString) -> ErrorResult { + fn SetType(&mut self, _type: DOMString) -> ErrorResult { Ok(()) } - pub fn Charset(&self) -> DOMString { + fn Charset(&self) -> DOMString { ~"" } - pub fn SetCharset(&mut self, _charset: DOMString) -> ErrorResult { + fn SetCharset(&mut self, _charset: DOMString) -> ErrorResult { Ok(()) } - pub fn Rev(&self) -> DOMString { + fn Rev(&self) -> DOMString { ~"" } - pub fn SetRev(&mut self, _rev: DOMString) -> ErrorResult { + fn SetRev(&mut self, _rev: DOMString) -> ErrorResult { Ok(()) } - pub fn Target(&self) -> DOMString { + fn Target(&self) -> DOMString { ~"" } - pub fn SetTarget(&mut self, _target: DOMString) -> ErrorResult { + fn SetTarget(&mut self, _target: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlmainelement.rs b/src/components/script/dom/htmlmainelement.rs index ad9a2c6af1e..4024f1ee7fa 100644 --- a/src/components/script/dom/htmlmainelement.rs +++ b/src/components/script/dom/htmlmainelement.rs @@ -38,3 +38,6 @@ impl HTMLMainElement { Node::reflect_node(~element, document, HTMLMainElementBinding::Wrap) } } + +pub trait HTMLMainElementMethods { +} diff --git a/src/components/script/dom/htmlmapelement.rs b/src/components/script/dom/htmlmapelement.rs index 18dfd17e88b..dbc55463351 100644 --- a/src/components/script/dom/htmlmapelement.rs +++ b/src/components/script/dom/htmlmapelement.rs @@ -41,16 +41,22 @@ impl HTMLMapElement { } } -impl HTMLMapElement { - pub fn Name(&self) -> DOMString { +pub trait HTMLMapElementMethods { + fn Name(&self) -> DOMString; + fn SetName(&mut self, _name: DOMString) -> ErrorResult; + fn Areas(&self) -> Unrooted; +} + +impl<'a> HTMLMapElementMethods for JSRef<'a, HTMLMapElement> { + fn Name(&self) -> DOMString { ~"" } - pub fn SetName(&mut self, _name: DOMString) -> ErrorResult { + fn SetName(&mut self, _name: DOMString) -> ErrorResult { Ok(()) } - pub fn Areas(&self) -> Unrooted { + fn Areas(&self) -> Unrooted { let roots = RootCollection::new(); // FIXME: https://github.com/mozilla/servo/issues/1845 let doc = self.htmlelement.element.node.owner_doc().root(&roots); @@ -58,3 +64,4 @@ impl HTMLMapElement { HTMLCollection::new(&*window, Static(vec!())) } } + diff --git a/src/components/script/dom/htmlmediaelement.rs b/src/components/script/dom/htmlmediaelement.rs index 179c8e97407..4f68a11f9c0 100644 --- a/src/components/script/dom/htmlmediaelement.rs +++ b/src/components/script/dom/htmlmediaelement.rs @@ -2,7 +2,7 @@ * 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; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::codegen::InheritTypes::HTMLMediaElementDerived; use dom::bindings::error::ErrorResult; use dom::document::Document; @@ -35,139 +35,177 @@ impl HTMLMediaElement { } } -impl HTMLMediaElement { - pub fn Src(&self) -> DOMString { +pub trait HTMLMediaElementMethods { + fn Src(&self) -> DOMString; + fn SetSrc(&mut self, _src: DOMString) -> ErrorResult; + fn CurrentSrc(&self) -> DOMString; + fn CrossOrigin(&self) -> DOMString; + fn SetCrossOrigin(&mut self, _cross_origin: DOMString) -> ErrorResult; + fn Preload(&self) -> DOMString; + fn SetPreload(&mut self, _preload: DOMString) -> ErrorResult; + fn Load(&self); + fn CanPlayType(&self, _type: DOMString) -> DOMString; + fn ReadyState(&self) -> u16; + fn Seeking(&self) -> bool; + fn CurrentTime(&self) -> f64; + fn SetCurrentTime(&mut self, _current_time: f64) -> ErrorResult; + fn GetDuration(&self) -> f64; + fn Paused(&self) -> bool; + fn DefaultPlaybackRate(&self) -> f64; + fn SetDefaultPlaybackRate(&mut self, _default_playback_rate: f64) -> ErrorResult; + fn PlaybackRate(&self) -> f64; + fn SetPlaybackRate(&mut self, _playback_rate: f64) -> ErrorResult; + fn Ended(&self) -> bool; + fn Autoplay(&self) -> bool; + fn SetAutoplay(&mut self, _autoplay: bool) -> ErrorResult; + fn Loop(&self) -> bool; + fn SetLoop(&mut self, _loop: bool) -> ErrorResult; + fn Play(&self) -> ErrorResult; + fn Pause(&self) -> ErrorResult; + fn Controls(&self) -> bool; + fn SetControls(&mut self, _controls: bool) -> ErrorResult; + fn Volume(&self) -> f64; + fn SetVolume(&mut self, _volume: f64) -> ErrorResult; + fn Muted(&self) -> bool; + fn SetMuted(&mut self, _muted: bool); + fn DefaultMuted(&self) -> bool; + fn SetDefaultMuted(&mut self, _default_muted: bool) -> ErrorResult; +} + +impl<'a> HTMLMediaElementMethods for JSRef<'a, HTMLMediaElement> { + fn Src(&self) -> DOMString { ~"" } - pub fn SetSrc(&mut self, _src: DOMString) -> ErrorResult { + fn SetSrc(&mut self, _src: DOMString) -> ErrorResult { Ok(()) } - pub fn CurrentSrc(&self) -> DOMString { + fn CurrentSrc(&self) -> DOMString { ~"" } - pub fn CrossOrigin(&self) -> DOMString { + fn CrossOrigin(&self) -> DOMString { ~"" } - pub fn SetCrossOrigin(&mut self, _cross_origin: DOMString) -> ErrorResult { + fn SetCrossOrigin(&mut self, _cross_origin: DOMString) -> ErrorResult { Ok(()) } - pub fn Preload(&self) -> DOMString { + fn Preload(&self) -> DOMString { ~"" } - pub fn SetPreload(&mut self, _preload: DOMString) -> ErrorResult { + fn SetPreload(&mut self, _preload: DOMString) -> ErrorResult { Ok(()) } - pub fn Load(&self) { + fn Load(&self) { } - pub fn CanPlayType(&self, _type: DOMString) -> DOMString { + fn CanPlayType(&self, _type: DOMString) -> DOMString { ~"" } - pub fn ReadyState(&self) -> u16 { + fn ReadyState(&self) -> u16 { 0 } - pub fn Seeking(&self) -> bool { + fn Seeking(&self) -> bool { false } - pub fn CurrentTime(&self) -> f64 { + fn CurrentTime(&self) -> f64 { 0f64 } - pub fn SetCurrentTime(&mut self, _current_time: f64) -> ErrorResult { + fn SetCurrentTime(&mut self, _current_time: f64) -> ErrorResult { Ok(()) } - pub fn GetDuration(&self) -> f64 { + fn GetDuration(&self) -> f64 { 0f64 } - pub fn Paused(&self) -> bool { + fn Paused(&self) -> bool { false } - pub fn DefaultPlaybackRate(&self) -> f64 { + fn DefaultPlaybackRate(&self) -> f64 { 0f64 } - pub fn SetDefaultPlaybackRate(&mut self, _default_playback_rate: f64) -> ErrorResult { + fn SetDefaultPlaybackRate(&mut self, _default_playback_rate: f64) -> ErrorResult { Ok(()) } - pub fn PlaybackRate(&self) -> f64 { + fn PlaybackRate(&self) -> f64 { 0f64 } - pub fn SetPlaybackRate(&mut self, _playback_rate: f64) -> ErrorResult { + fn SetPlaybackRate(&mut self, _playback_rate: f64) -> ErrorResult { Ok(()) } - pub fn Ended(&self) -> bool { + fn Ended(&self) -> bool { false } - pub fn Autoplay(&self) -> bool { + fn Autoplay(&self) -> bool { false } - pub fn SetAutoplay(&mut self, _autoplay: bool) -> ErrorResult { + fn SetAutoplay(&mut self, _autoplay: bool) -> ErrorResult { Ok(()) } - pub fn Loop(&self) -> bool { + fn Loop(&self) -> bool { false } - pub fn SetLoop(&mut self, _loop: bool) -> ErrorResult { + fn SetLoop(&mut self, _loop: bool) -> ErrorResult { Ok(()) } - pub fn Play(&self) -> ErrorResult { + fn Play(&self) -> ErrorResult { Ok(()) } - pub fn Pause(&self) -> ErrorResult { + fn Pause(&self) -> ErrorResult { Ok(()) } - pub fn Controls(&self) -> bool { + fn Controls(&self) -> bool { false } - pub fn SetControls(&mut self, _controls: bool) -> ErrorResult { + fn SetControls(&mut self, _controls: bool) -> ErrorResult { Ok(()) } - pub fn Volume(&self) -> f64 { + fn Volume(&self) -> f64 { 0f64 } - pub fn SetVolume(&mut self, _volume: f64) -> ErrorResult { + fn SetVolume(&mut self, _volume: f64) -> ErrorResult { Ok(()) } - pub fn Muted(&self) -> bool { + fn Muted(&self) -> bool { false } - pub fn SetMuted(&mut self, _muted: bool) { + fn SetMuted(&mut self, _muted: bool) { } - pub fn DefaultMuted(&self) -> bool { + fn DefaultMuted(&self) -> bool { false } - pub fn SetDefaultMuted(&mut self, _default_muted: bool) -> ErrorResult { + fn SetDefaultMuted(&mut self, _default_muted: bool) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlmetaelement.rs b/src/components/script/dom/htmlmetaelement.rs index 737cc6710fc..89520346b53 100644 --- a/src/components/script/dom/htmlmetaelement.rs +++ b/src/components/script/dom/htmlmetaelement.rs @@ -40,36 +40,48 @@ impl HTMLMetaElement { } } -impl HTMLMetaElement { - pub fn Name(&self) -> DOMString { +pub trait HTMLMetaElementMethods { + fn Name(&self) -> DOMString; + fn SetName(&mut self, _name: DOMString) -> ErrorResult; + fn HttpEquiv(&self) -> DOMString; + fn SetHttpEquiv(&mut self, _http_equiv: DOMString) -> ErrorResult; + fn Content(&self) -> DOMString; + fn SetContent(&mut self, _content: DOMString) -> ErrorResult; + fn Scheme(&self) -> DOMString; + fn SetScheme(&mut self, _scheme: DOMString) -> ErrorResult; +} + +impl<'a> HTMLMetaElementMethods for JSRef<'a, HTMLMetaElement> { + fn Name(&self) -> DOMString { ~"" } - pub fn SetName(&mut self, _name: DOMString) -> ErrorResult { + fn SetName(&mut self, _name: DOMString) -> ErrorResult { Ok(()) } - pub fn HttpEquiv(&self) -> DOMString { + fn HttpEquiv(&self) -> DOMString { ~"" } - pub fn SetHttpEquiv(&mut self, _http_equiv: DOMString) -> ErrorResult { + fn SetHttpEquiv(&mut self, _http_equiv: DOMString) -> ErrorResult { Ok(()) } - pub fn Content(&self) -> DOMString { + fn Content(&self) -> DOMString { ~"" } - pub fn SetContent(&mut self, _content: DOMString) -> ErrorResult { + fn SetContent(&mut self, _content: DOMString) -> ErrorResult { Ok(()) } - pub fn Scheme(&self) -> DOMString { + fn Scheme(&self) -> DOMString { ~"" } - pub fn SetScheme(&mut self, _scheme: DOMString) -> ErrorResult { + fn SetScheme(&mut self, _scheme: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlmeterelement.rs b/src/components/script/dom/htmlmeterelement.rs index 9d5f699ae14..685d96f7a0b 100644 --- a/src/components/script/dom/htmlmeterelement.rs +++ b/src/components/script/dom/htmlmeterelement.rs @@ -40,52 +40,68 @@ impl HTMLMeterElement { } } -impl HTMLMeterElement { - pub fn Value(&self) -> f64 { +pub trait HTMLMeterElementMethods { + fn Value(&self) -> f64; + fn SetValue(&mut self, _value: f64) -> ErrorResult; + fn Min(&self) -> f64; + fn SetMin(&mut self, _min: f64) -> ErrorResult; + fn Max(&self) -> f64; + fn SetMax(&mut self, _max: f64) -> ErrorResult; + fn Low(&self) -> f64; + fn SetLow(&mut self, _low: f64) -> ErrorResult; + fn High(&self) -> f64; + fn SetHigh(&mut self, _high: f64) -> ErrorResult; + fn Optimum(&self) -> f64; + fn SetOptimum(&mut self, _optimum: f64) -> ErrorResult; +} + +impl<'a> HTMLMeterElementMethods for JSRef<'a, HTMLMeterElement> { + fn Value(&self) -> f64 { 0.0 } - pub fn SetValue(&mut self, _value: f64) -> ErrorResult { + fn SetValue(&mut self, _value: f64) -> ErrorResult { Ok(()) } - pub fn Min(&self) -> f64 { + fn Min(&self) -> f64 { 0.0 } - pub fn SetMin(&mut self, _min: f64) -> ErrorResult { + fn SetMin(&mut self, _min: f64) -> ErrorResult { Ok(()) } - pub fn Max(&self) -> f64 { + fn Max(&self) -> f64 { 0.0 } - pub fn SetMax(&mut self, _max: f64) -> ErrorResult { + fn SetMax(&mut self, _max: f64) -> ErrorResult { Ok(()) } - pub fn Low(&self) -> f64 { + fn Low(&self) -> f64 { 0.0 } - pub fn SetLow(&mut self, _low: f64) -> ErrorResult { + fn SetLow(&mut self, _low: f64) -> ErrorResult { Ok(()) } - pub fn High(&self) -> f64 { + fn High(&self) -> f64 { 0.0 } - pub fn SetHigh(&mut self, _high: f64) -> ErrorResult { + fn SetHigh(&mut self, _high: f64) -> ErrorResult { Ok(()) } - pub fn Optimum(&self) -> f64 { + fn Optimum(&self) -> f64 { 0.0 } - pub fn SetOptimum(&mut self, _optimum: f64) -> ErrorResult { + fn SetOptimum(&mut self, _optimum: f64) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlmodelement.rs b/src/components/script/dom/htmlmodelement.rs index 41ed8244a9d..6a9b33106a2 100644 --- a/src/components/script/dom/htmlmodelement.rs +++ b/src/components/script/dom/htmlmodelement.rs @@ -40,20 +40,28 @@ impl HTMLModElement { } } -impl HTMLModElement { - pub fn Cite(&self) -> DOMString { +pub trait HTMLModElementMethods { + fn Cite(&self) -> DOMString; + fn SetCite(&mut self, _cite: DOMString) -> ErrorResult; + fn DateTime(&self) -> DOMString; + fn SetDateTime(&mut self, _datetime: DOMString) -> ErrorResult; +} + +impl<'a> HTMLModElementMethods for JSRef<'a, HTMLModElement> { + fn Cite(&self) -> DOMString { ~"" } - pub fn SetCite(&mut self, _cite: DOMString) -> ErrorResult { + fn SetCite(&mut self, _cite: DOMString) -> ErrorResult { Ok(()) } - pub fn DateTime(&self) -> DOMString { + fn DateTime(&self) -> DOMString { ~"" } - pub fn SetDateTime(&mut self, _datetime: DOMString) -> ErrorResult { + fn SetDateTime(&mut self, _datetime: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlobjectelement.rs b/src/components/script/dom/htmlobjectelement.rs index 4814ac4b337..7fcc3c0a5da 100644 --- a/src/components/script/dom/htmlobjectelement.rs +++ b/src/components/script/dom/htmlobjectelement.rs @@ -2,6 +2,7 @@ * 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::attr::AttrMethods; use dom::bindings::codegen::BindingDeclarations::HTMLObjectElementBinding; use dom::bindings::codegen::InheritTypes::HTMLObjectElementDerived; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast}; @@ -79,170 +80,214 @@ impl<'a> ProcessDataURL for JSRef<'a, HTMLObjectElement> { } } -impl HTMLObjectElement { - pub fn Data(&self) -> DOMString { +pub trait HTMLObjectElementMethods { + fn Data(&self) -> DOMString; + fn SetData(&mut self, _data: DOMString) -> ErrorResult; + fn Type(&self) -> DOMString; + fn SetType(&mut self, _type: DOMString) -> ErrorResult; + fn Name(&self) -> DOMString; + fn SetName(&mut self, _name: DOMString) -> ErrorResult; + fn UseMap(&self) -> DOMString; + fn SetUseMap(&mut self, _use_map: DOMString) -> ErrorResult; + fn GetForm(&self) -> Option>; + fn Width(&self) -> DOMString; + fn SetWidth(&mut self, _width: DOMString) -> ErrorResult; + fn Height(&self) -> DOMString; + fn SetHeight(&mut self, _height: DOMString) -> ErrorResult; + fn GetContentDocument(&self) -> Option>; + fn GetContentWindow(&self) -> Option>; + fn WillValidate(&self) -> bool; + fn Validity(&self) -> Unrooted; + fn ValidationMessage(&self) -> DOMString; + fn CheckValidity(&self) -> bool; + fn SetCustomValidity(&mut self, _error: DOMString); + fn Align(&self) -> DOMString; + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult; + fn Archive(&self) -> DOMString; + fn SetArchive(&mut self, _archive: DOMString) -> ErrorResult; + fn Code(&self) -> DOMString; + fn SetCode(&mut self, _code: DOMString) -> ErrorResult; + fn Declare(&self) -> bool; + fn SetDeclare(&mut self, _declare: bool) -> ErrorResult; + fn Hspace(&self) -> u32; + fn SetHspace(&mut self, _hspace: u32) -> ErrorResult; + fn Standby(&self) -> DOMString; + fn SetStandby(&mut self, _standby: DOMString) -> ErrorResult; + fn Vspace(&self) -> u32; + fn SetVspace(&mut self, _vspace: u32) -> ErrorResult; + fn CodeBase(&self) -> DOMString; + fn SetCodeBase(&mut self, _codebase: DOMString) -> ErrorResult; + fn CodeType(&self) -> DOMString; + fn SetCodeType(&mut self, _codetype: DOMString) -> ErrorResult; + fn Border(&self) -> DOMString; + fn SetBorder(&mut self, _border: DOMString) -> ErrorResult; + fn GetSVGDocument(&self) -> Option>; +} + +impl<'a> HTMLObjectElementMethods for JSRef<'a, HTMLObjectElement> { + fn Data(&self) -> DOMString { ~"" } - pub fn SetData(&mut self, _data: DOMString) -> ErrorResult { + fn SetData(&mut self, _data: DOMString) -> ErrorResult { Ok(()) } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn SetType(&mut self, _type: DOMString) -> ErrorResult { + fn SetType(&mut self, _type: DOMString) -> ErrorResult { Ok(()) } - pub fn Name(&self) -> DOMString { + fn Name(&self) -> DOMString { ~"" } - pub fn SetName(&mut self, _name: DOMString) -> ErrorResult { + fn SetName(&mut self, _name: DOMString) -> ErrorResult { Ok(()) } - pub fn UseMap(&self) -> DOMString { + fn UseMap(&self) -> DOMString { ~"" } - pub fn SetUseMap(&mut self, _use_map: DOMString) -> ErrorResult { + fn SetUseMap(&mut self, _use_map: DOMString) -> ErrorResult { Ok(()) } - pub fn GetForm(&self) -> Option> { + fn GetForm(&self) -> Option> { None } - pub fn Width(&self) -> DOMString { + fn Width(&self) -> DOMString { ~"" } - pub fn SetWidth(&mut self, _width: DOMString) -> ErrorResult { + fn SetWidth(&mut self, _width: DOMString) -> ErrorResult { Ok(()) } - pub fn Height(&self) -> DOMString { + fn Height(&self) -> DOMString { ~"" } - pub fn SetHeight(&mut self, _height: DOMString) -> ErrorResult { + fn SetHeight(&mut self, _height: DOMString) -> ErrorResult { Ok(()) } - pub fn GetContentDocument(&self) -> Option> { + fn GetContentDocument(&self) -> Option> { None } - pub fn GetContentWindow(&self) -> Option> { + fn GetContentWindow(&self) -> Option> { None } - pub fn WillValidate(&self) -> bool { + fn WillValidate(&self) -> bool { false } - pub fn Validity(&self) -> Unrooted { + fn Validity(&self) -> Unrooted { let roots = RootCollection::new(); let doc = self.htmlelement.element.node.owner_doc().root(&roots); let window = doc.deref().window.root(&roots); ValidityState::new(&window.root_ref()) } - pub fn ValidationMessage(&self) -> DOMString { + fn ValidationMessage(&self) -> DOMString { ~"" } - pub fn CheckValidity(&self) -> bool { + fn CheckValidity(&self) -> bool { false } - pub fn SetCustomValidity(&mut self, _error: DOMString) { + fn SetCustomValidity(&mut self, _error: DOMString) { } - pub fn Align(&self) -> DOMString { + fn Align(&self) -> DOMString { ~"" } - pub fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { Ok(()) } - pub fn Archive(&self) -> DOMString { + fn Archive(&self) -> DOMString { ~"" } - pub fn SetArchive(&mut self, _archive: DOMString) -> ErrorResult { + fn SetArchive(&mut self, _archive: DOMString) -> ErrorResult { Ok(()) } - pub fn Code(&self) -> DOMString { + fn Code(&self) -> DOMString { ~"" } - pub fn SetCode(&mut self, _code: DOMString) -> ErrorResult { + fn SetCode(&mut self, _code: DOMString) -> ErrorResult { Ok(()) } - pub fn Declare(&self) -> bool { + fn Declare(&self) -> bool { false } - pub fn SetDeclare(&mut self, _declare: bool) -> ErrorResult { + fn SetDeclare(&mut self, _declare: bool) -> ErrorResult { Ok(()) } - pub fn Hspace(&self) -> u32 { + fn Hspace(&self) -> u32 { 0 } - pub fn SetHspace(&mut self, _hspace: u32) -> ErrorResult { + fn SetHspace(&mut self, _hspace: u32) -> ErrorResult { Ok(()) } - pub fn Standby(&self) -> DOMString { + fn Standby(&self) -> DOMString { ~"" } - pub fn SetStandby(&mut self, _standby: DOMString) -> ErrorResult { + fn SetStandby(&mut self, _standby: DOMString) -> ErrorResult { Ok(()) } - pub fn Vspace(&self) -> u32 { + fn Vspace(&self) -> u32 { 0 } - pub fn SetVspace(&mut self, _vspace: u32) -> ErrorResult { + fn SetVspace(&mut self, _vspace: u32) -> ErrorResult { Ok(()) } - pub fn CodeBase(&self) -> DOMString { + fn CodeBase(&self) -> DOMString { ~"" } - pub fn SetCodeBase(&mut self, _codebase: DOMString) -> ErrorResult { + fn SetCodeBase(&mut self, _codebase: DOMString) -> ErrorResult { Ok(()) } - pub fn CodeType(&self) -> DOMString { + fn CodeType(&self) -> DOMString { ~"" } - pub fn SetCodeType(&mut self, _codetype: DOMString) -> ErrorResult { + fn SetCodeType(&mut self, _codetype: DOMString) -> ErrorResult { Ok(()) } - pub fn Border(&self) -> DOMString { + fn Border(&self) -> DOMString { ~"" } - pub fn SetBorder(&mut self, _border: DOMString) -> ErrorResult { + fn SetBorder(&mut self, _border: DOMString) -> ErrorResult { Ok(()) } - pub fn GetSVGDocument(&self) -> Option> { + fn GetSVGDocument(&self) -> Option> { None } } diff --git a/src/components/script/dom/htmlolistelement.rs b/src/components/script/dom/htmlolistelement.rs index 1330e2cbd40..a7191eb4f31 100644 --- a/src/components/script/dom/htmlolistelement.rs +++ b/src/components/script/dom/htmlolistelement.rs @@ -40,36 +40,48 @@ impl HTMLOListElement { } } -impl HTMLOListElement { - pub fn Reversed(&self) -> bool { +pub trait HTMLOListElementMethods { + fn Reversed(&self) -> bool; + fn SetReversed(&self, _reversed: bool) -> ErrorResult; + fn Start(&self) -> i32; + fn SetStart(&mut self, _start: i32) -> ErrorResult; + fn Type(&self) -> DOMString; + fn SetType(&mut self, _type: DOMString) -> ErrorResult; + fn Compact(&self) -> bool; + fn SetCompact(&self, _compact: bool) -> ErrorResult; +} + +impl<'a> HTMLOListElementMethods for JSRef<'a, HTMLOListElement> { + fn Reversed(&self) -> bool { false } - pub fn SetReversed(&self, _reversed: bool) -> ErrorResult { + fn SetReversed(&self, _reversed: bool) -> ErrorResult { Ok(()) } - pub fn Start(&self) -> i32 { + fn Start(&self) -> i32 { 0 } - pub fn SetStart(&mut self, _start: i32) -> ErrorResult { + fn SetStart(&mut self, _start: i32) -> ErrorResult { Ok(()) } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn SetType(&mut self, _type: DOMString) -> ErrorResult { + fn SetType(&mut self, _type: DOMString) -> ErrorResult { Ok(()) } - pub fn Compact(&self) -> bool { + fn Compact(&self) -> bool { false } - pub fn SetCompact(&self, _compact: bool) -> ErrorResult { + fn SetCompact(&self, _compact: bool) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmloptgroupelement.rs b/src/components/script/dom/htmloptgroupelement.rs index d5eab9bec46..05f4cb5ef03 100644 --- a/src/components/script/dom/htmloptgroupelement.rs +++ b/src/components/script/dom/htmloptgroupelement.rs @@ -40,20 +40,28 @@ impl HTMLOptGroupElement { } } -impl HTMLOptGroupElement { - pub fn Disabled(&self) -> bool { +pub trait HTMLOptGroupElementMethods { + fn Disabled(&self) -> bool; + fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult; + fn Label(&self) -> DOMString; + fn SetLabel(&mut self, _label: DOMString) -> ErrorResult; +} + +impl<'a> HTMLOptGroupElementMethods for JSRef<'a, HTMLOptGroupElement> { + fn Disabled(&self) -> bool { false } - pub fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult { + fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult { Ok(()) } - pub fn Label(&self) -> DOMString { + fn Label(&self) -> DOMString { ~"" } - pub fn SetLabel(&mut self, _label: DOMString) -> ErrorResult { + fn SetLabel(&mut self, _label: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmloptionelement.rs b/src/components/script/dom/htmloptionelement.rs index bf1f594009e..e9793fc1690 100644 --- a/src/components/script/dom/htmloptionelement.rs +++ b/src/components/script/dom/htmloptionelement.rs @@ -41,60 +41,78 @@ impl HTMLOptionElement { } } -impl HTMLOptionElement { - pub fn Disabled(&self) -> bool { +pub trait HTMLOptionElementMethods { + fn Disabled(&self) -> bool; + fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult; + fn GetForm(&self) -> Option>; + fn Label(&self) -> DOMString; + fn SetLabel(&mut self, _label: DOMString) -> ErrorResult; + fn DefaultSelected(&self) -> bool; + fn SetDefaultSelected(&mut self, _default_selected: bool) -> ErrorResult; + fn Selected(&self) -> bool; + fn SetSelected(&mut self, _selected: bool) -> ErrorResult; + fn Value(&self) -> DOMString; + fn SetValue(&mut self, _value: DOMString) -> ErrorResult; + fn Text(&self) -> DOMString; + fn SetText(&mut self, _text: DOMString) -> ErrorResult; + fn Index(&self) -> i32; +} + +impl<'a> HTMLOptionElementMethods for JSRef<'a, HTMLOptionElement> { + fn Disabled(&self) -> bool { false } - pub fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult { + fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult { Ok(()) } - pub fn GetForm(&self) -> Option> { + fn GetForm(&self) -> Option> { None } - pub fn Label(&self) -> DOMString { + fn Label(&self) -> DOMString { ~"" } - pub fn SetLabel(&mut self, _label: DOMString) -> ErrorResult { + fn SetLabel(&mut self, _label: DOMString) -> ErrorResult { Ok(()) } - pub fn DefaultSelected(&self) -> bool { + fn DefaultSelected(&self) -> bool { false } - pub fn SetDefaultSelected(&mut self, _default_selected: bool) -> ErrorResult { + fn SetDefaultSelected(&mut self, _default_selected: bool) -> ErrorResult { Ok(()) } - pub fn Selected(&self) -> bool { + fn Selected(&self) -> bool { false } - pub fn SetSelected(&mut self, _selected: bool) -> ErrorResult { + fn SetSelected(&mut self, _selected: bool) -> ErrorResult { Ok(()) } - pub fn Value(&self) -> DOMString { + fn Value(&self) -> DOMString { ~"" } - pub fn SetValue(&mut self, _value: DOMString) -> ErrorResult { + fn SetValue(&mut self, _value: DOMString) -> ErrorResult { Ok(()) } - pub fn Text(&self) -> DOMString { + fn Text(&self) -> DOMString { ~"" } - pub fn SetText(&mut self, _text: DOMString) -> ErrorResult { + fn SetText(&mut self, _text: DOMString) -> ErrorResult { Ok(()) } - pub fn Index(&self) -> i32 { + fn Index(&self) -> i32 { 0 } } + diff --git a/src/components/script/dom/htmloutputelement.rs b/src/components/script/dom/htmloutputelement.rs index a72d9410d20..c7262b23de0 100644 --- a/src/components/script/dom/htmloutputelement.rs +++ b/src/components/script/dom/htmloutputelement.rs @@ -42,68 +42,88 @@ impl HTMLOutputElement { } } -impl HTMLOutputElement { - pub fn GetForm(&self) -> Option> { +pub trait HTMLOutputElementMethods { + fn GetForm(&self) -> Option>; + fn Name(&self) -> DOMString; + fn SetName(&mut self, _name: DOMString) -> ErrorResult; + fn Type(&self) -> DOMString; + fn DefaultValue(&self) -> DOMString; + fn SetDefaultValue(&mut self, _value: DOMString) -> ErrorResult; + fn Value(&self) -> DOMString; + fn SetValue(&mut self, _value: DOMString) -> ErrorResult; + fn WillValidate(&self) -> bool; + fn SetWillValidate(&mut self, _will_validate: bool); + fn Validity(&self) -> Unrooted; + fn SetValidity(&mut self, _validity: JS); + fn ValidationMessage(&self) -> DOMString; + fn SetValidationMessage(&mut self, _message: DOMString) -> ErrorResult; + fn CheckValidity(&self) -> bool; + fn SetCustomValidity(&mut self, _error: DOMString); +} + +impl<'a> HTMLOutputElementMethods for JSRef<'a, HTMLOutputElement> { + fn GetForm(&self) -> Option> { None } - pub fn Name(&self) -> DOMString { + fn Name(&self) -> DOMString { ~"" } - pub fn SetName(&mut self, _name: DOMString) -> ErrorResult { + fn SetName(&mut self, _name: DOMString) -> ErrorResult { Ok(()) } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn DefaultValue(&self) -> DOMString { + fn DefaultValue(&self) -> DOMString { ~"" } - pub fn SetDefaultValue(&mut self, _value: DOMString) -> ErrorResult { + fn SetDefaultValue(&mut self, _value: DOMString) -> ErrorResult { Ok(()) } - pub fn Value(&self) -> DOMString { + fn Value(&self) -> DOMString { ~"" } - pub fn SetValue(&mut self, _value: DOMString) -> ErrorResult { + fn SetValue(&mut self, _value: DOMString) -> ErrorResult { Ok(()) } - pub fn WillValidate(&self) -> bool { + fn WillValidate(&self) -> bool { false } - pub fn SetWillValidate(&mut self, _will_validate: bool) { + fn SetWillValidate(&mut self, _will_validate: bool) { } - pub fn Validity(&self) -> Unrooted { + fn Validity(&self) -> Unrooted { let roots = RootCollection::new(); let doc = self.htmlelement.element.node.owner_doc().root(&roots); let window = doc.deref().window.root(&roots); ValidityState::new(&*window) } - pub fn SetValidity(&mut self, _validity: JS) { + fn SetValidity(&mut self, _validity: JS) { } - pub fn ValidationMessage(&self) -> DOMString { + fn ValidationMessage(&self) -> DOMString { ~"" } - pub fn SetValidationMessage(&mut self, _message: DOMString) -> ErrorResult { + fn SetValidationMessage(&mut self, _message: DOMString) -> ErrorResult { Ok(()) } - pub fn CheckValidity(&self) -> bool { + fn CheckValidity(&self) -> bool { true } - pub fn SetCustomValidity(&mut self, _error: DOMString) { + fn SetCustomValidity(&mut self, _error: DOMString) { } } + diff --git a/src/components/script/dom/htmlparagraphelement.rs b/src/components/script/dom/htmlparagraphelement.rs index d5dafd6abda..90e3282c915 100644 --- a/src/components/script/dom/htmlparagraphelement.rs +++ b/src/components/script/dom/htmlparagraphelement.rs @@ -40,12 +40,18 @@ impl HTMLParagraphElement { } } -impl HTMLParagraphElement { - pub fn Align(&self) -> DOMString { +pub trait HTMLParagraphElementMethods { + fn Align(&self) -> DOMString; + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult; +} + +impl<'a> HTMLParagraphElementMethods for JSRef<'a, HTMLParagraphElement> { + fn Align(&self) -> DOMString { ~"" } - pub fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlparamelement.rs b/src/components/script/dom/htmlparamelement.rs index db4d9ec1b89..41f45b31d17 100644 --- a/src/components/script/dom/htmlparamelement.rs +++ b/src/components/script/dom/htmlparamelement.rs @@ -40,36 +40,48 @@ impl HTMLParamElement { } } -impl HTMLParamElement { - pub fn Name(&self) -> DOMString { +pub trait HTMLParamElementMethods { + fn Name(&self) -> DOMString; + fn SetName(&mut self, _name: DOMString) -> ErrorResult; + fn Value(&self) -> DOMString; + fn SetValue(&mut self, _value: DOMString) -> ErrorResult; + fn Type(&self) -> DOMString; + fn SetType(&mut self, _type: DOMString) -> ErrorResult; + fn ValueType(&self) -> DOMString; + fn SetValueType(&mut self, _value_type: DOMString) -> ErrorResult; +} + +impl<'a> HTMLParamElementMethods for JSRef<'a, HTMLParamElement> { + fn Name(&self) -> DOMString { ~"" } - pub fn SetName(&mut self, _name: DOMString) -> ErrorResult { + fn SetName(&mut self, _name: DOMString) -> ErrorResult { Ok(()) } - pub fn Value(&self) -> DOMString { + fn Value(&self) -> DOMString { ~"" } - pub fn SetValue(&mut self, _value: DOMString) -> ErrorResult { + fn SetValue(&mut self, _value: DOMString) -> ErrorResult { Ok(()) } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn SetType(&mut self, _type: DOMString) -> ErrorResult { + fn SetType(&mut self, _type: DOMString) -> ErrorResult { Ok(()) } - pub fn ValueType(&self) -> DOMString { + fn ValueType(&self) -> DOMString { ~"" } - pub fn SetValueType(&mut self, _value_type: DOMString) -> ErrorResult { + fn SetValueType(&mut self, _value_type: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlpreelement.rs b/src/components/script/dom/htmlpreelement.rs index e2c404074bd..34eb9923a52 100644 --- a/src/components/script/dom/htmlpreelement.rs +++ b/src/components/script/dom/htmlpreelement.rs @@ -40,12 +40,18 @@ impl HTMLPreElement { } } -impl HTMLPreElement { - pub fn Width(&self) -> i32 { +pub trait HTMLPreElementMethods { + fn Width(&self) -> i32; + fn SetWidth(&mut self, _width: i32) -> ErrorResult; +} + +impl<'a> HTMLPreElementMethods for JSRef<'a, HTMLPreElement> { + fn Width(&self) -> i32 { 0 } - pub fn SetWidth(&mut self, _width: i32) -> ErrorResult { + fn SetWidth(&mut self, _width: i32) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlprogresselement.rs b/src/components/script/dom/htmlprogresselement.rs index 024025afa6d..891df6918fe 100644 --- a/src/components/script/dom/htmlprogresselement.rs +++ b/src/components/script/dom/htmlprogresselement.rs @@ -40,28 +40,38 @@ impl HTMLProgressElement { } } -impl HTMLProgressElement { - pub fn Value(&self) -> f64 { +pub trait HTMLProgressElementMethods { + fn Value(&self) -> f64; + fn SetValue(&mut self, _value: f64) -> ErrorResult; + fn Max(&self) -> f64; + fn SetMax(&mut self, _max: f64) -> ErrorResult; + fn Position(&self) -> f64; + fn GetPositiom(&self) -> Fallible; +} + +impl<'a> HTMLProgressElementMethods for JSRef<'a, HTMLProgressElement> { + fn Value(&self) -> f64 { 0f64 } - pub fn SetValue(&mut self, _value: f64) -> ErrorResult { + fn SetValue(&mut self, _value: f64) -> ErrorResult { Ok(()) } - pub fn Max(&self) -> f64 { + fn Max(&self) -> f64 { 0f64 } - pub fn SetMax(&mut self, _max: f64) -> ErrorResult { + fn SetMax(&mut self, _max: f64) -> ErrorResult { Ok(()) } - pub fn Position(&self) -> f64 { + fn Position(&self) -> f64 { 0f64 } - pub fn GetPositiom(&self) -> Fallible { + fn GetPositiom(&self) -> Fallible { Ok(0f64) } } + diff --git a/src/components/script/dom/htmlquoteelement.rs b/src/components/script/dom/htmlquoteelement.rs index 9c67c2ac2f4..db7edcbede4 100644 --- a/src/components/script/dom/htmlquoteelement.rs +++ b/src/components/script/dom/htmlquoteelement.rs @@ -40,12 +40,18 @@ impl HTMLQuoteElement { } } -impl HTMLQuoteElement { - pub fn Cite(&self) -> DOMString { +pub trait HTMLQuoteElementMethods { + fn Cite(&self) -> DOMString; + fn SetCite(&self, _cite: DOMString) -> ErrorResult; +} + +impl<'a> HTMLQuoteElementMethods for JSRef<'a, HTMLQuoteElement> { + fn Cite(&self) -> DOMString { ~"" } - pub fn SetCite(&self, _cite: DOMString) -> ErrorResult { + fn SetCite(&self, _cite: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlscriptelement.rs b/src/components/script/dom/htmlscriptelement.rs index 808b05a12cf..fabe876a10f 100644 --- a/src/components/script/dom/htmlscriptelement.rs +++ b/src/components/script/dom/htmlscriptelement.rs @@ -41,77 +41,99 @@ impl HTMLScriptElement { } } -impl HTMLScriptElement { - pub fn Src(&self, abstract_self: &JSRef) -> DOMString { +pub trait HTMLScriptElementMethods { + fn Src(&self, abstract_self: &JSRef) -> DOMString; + fn SetSrc(&mut self, _abstract_self: &JSRef, _src: DOMString) -> ErrorResult; + fn Type(&self) -> DOMString; + fn SetType(&mut self, _type: DOMString) -> ErrorResult; + fn Charset(&self) -> DOMString; + fn SetCharset(&mut self, _charset: DOMString) -> ErrorResult; + fn Async(&self) -> bool; + fn SetAsync(&self, _async: bool) -> ErrorResult; + fn Defer(&self) -> bool; + fn SetDefer(&self, _defer: bool) -> ErrorResult; + fn CrossOrigin(&self) -> DOMString; + fn SetCrossOrigin(&mut self, _cross_origin: DOMString) -> ErrorResult; + fn Text(&self) -> DOMString; + fn SetText(&mut self, _text: DOMString) -> ErrorResult; + fn Event(&self) -> DOMString; + fn SetEvent(&mut self, _event: DOMString) -> ErrorResult; + fn HtmlFor(&self) -> DOMString; + fn SetHtmlFor(&mut self, _html_for: DOMString) -> ErrorResult; +} + +impl<'a> HTMLScriptElementMethods for JSRef<'a, HTMLScriptElement> { + fn Src(&self, abstract_self: &JSRef) -> DOMString { let element: &JSRef = ElementCast::from_ref(abstract_self); element.get_url_attribute("src") } - pub fn SetSrc(&mut self, _abstract_self: &JSRef, _src: DOMString) -> ErrorResult { + fn SetSrc(&mut self, _abstract_self: &JSRef, _src: DOMString) -> ErrorResult { Ok(()) } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn SetType(&mut self, _type: DOMString) -> ErrorResult { + fn SetType(&mut self, _type: DOMString) -> ErrorResult { Ok(()) } - pub fn Charset(&self) -> DOMString { + fn Charset(&self) -> DOMString { ~"" } - pub fn SetCharset(&mut self, _charset: DOMString) -> ErrorResult { + fn SetCharset(&mut self, _charset: DOMString) -> ErrorResult { Ok(()) } - pub fn Async(&self) -> bool { + fn Async(&self) -> bool { false } - pub fn SetAsync(&self, _async: bool) -> ErrorResult { + fn SetAsync(&self, _async: bool) -> ErrorResult { Ok(()) } - pub fn Defer(&self) -> bool { + fn Defer(&self) -> bool { false } - pub fn SetDefer(&self, _defer: bool) -> ErrorResult { + fn SetDefer(&self, _defer: bool) -> ErrorResult { Ok(()) } - pub fn CrossOrigin(&self) -> DOMString { + fn CrossOrigin(&self) -> DOMString { ~"" } - pub fn SetCrossOrigin(&mut self, _cross_origin: DOMString) -> ErrorResult { + fn SetCrossOrigin(&mut self, _cross_origin: DOMString) -> ErrorResult { Ok(()) } - pub fn Text(&self) -> DOMString { + fn Text(&self) -> DOMString { ~"" } - pub fn SetText(&mut self, _text: DOMString) -> ErrorResult { + fn SetText(&mut self, _text: DOMString) -> ErrorResult { Ok(()) } - pub fn Event(&self) -> DOMString { + fn Event(&self) -> DOMString { ~"" } - pub fn SetEvent(&mut self, _event: DOMString) -> ErrorResult { + fn SetEvent(&mut self, _event: DOMString) -> ErrorResult { Ok(()) } - pub fn HtmlFor(&self) -> DOMString { + fn HtmlFor(&self) -> DOMString { ~"" } - pub fn SetHtmlFor(&mut self, _html_for: DOMString) -> ErrorResult { + fn SetHtmlFor(&mut self, _html_for: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlselectelement.rs b/src/components/script/dom/htmlselectelement.rs index 666cb529774..6aa15a1e982 100644 --- a/src/components/script/dom/htmlselectelement.rs +++ b/src/components/script/dom/htmlselectelement.rs @@ -44,141 +44,180 @@ impl HTMLSelectElement { } } -impl HTMLSelectElement { - pub fn Autofocus(&self) -> bool { +pub trait HTMLSelectElementMethods { + fn Autofocus(&self) -> bool; + fn SetAutofocus(&mut self, _autofocus: bool) -> ErrorResult; + fn Disabled(&self) -> bool; + fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult; + fn GetForm(&self) -> Option>; + fn Multiple(&self) -> bool; + fn SetMultiple(&mut self, _multiple: bool) -> ErrorResult; + fn Name(&self) -> DOMString; + fn SetName(&mut self, _name: DOMString) -> ErrorResult; + fn Required(&self) -> bool; + fn SetRequired(&mut self, _multiple: bool) -> ErrorResult; + fn Size(&self) -> u32; + fn SetSize(&mut self, _size: u32) -> ErrorResult; + fn Type(&self) -> DOMString; + fn Length(&self) -> u32; + fn SetLength(&mut self, _length: u32) -> ErrorResult; + fn Item(&self, _index: u32) -> Option>; + fn NamedItem(&self, _name: DOMString) -> Option>; + fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option>; + fn IndexedSetter(&mut self, _index: u32, _option: Option>) -> ErrorResult; + fn Remove_(&self); + fn Remove(&self, _index: i32); + fn SelectedIndex(&self) -> i32; + fn SetSelectedIndex(&mut self, _index: i32) -> ErrorResult; + fn Value(&self) -> DOMString; + fn SetValue(&mut self, _value: DOMString); + fn WillValidate(&self) -> bool; + fn SetWillValidate(&mut self, _will_validate: bool); + fn Validity(&self) -> Unrooted; + fn SetValidity(&mut self, _validity: JS); + fn ValidationMessage(&self) -> DOMString; + fn SetValidationMessage(&mut self, _message: DOMString) -> ErrorResult; + fn CheckValidity(&self) -> bool; + fn SetCustomValidity(&mut self, _error: DOMString); + fn Add(&self, _element: HTMLOptionElementOrHTMLOptGroupElement, _before: Option) -> ErrorResult; +} + +impl<'a> HTMLSelectElementMethods for JSRef<'a, HTMLSelectElement> { + fn Autofocus(&self) -> bool { false } - pub fn SetAutofocus(&mut self, _autofocus: bool) -> ErrorResult { + fn SetAutofocus(&mut self, _autofocus: bool) -> ErrorResult { Ok(()) } - pub fn Disabled(&self) -> bool { + fn Disabled(&self) -> bool { false } - pub fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult { + fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult { Ok(()) } - pub fn GetForm(&self) -> Option> { + fn GetForm(&self) -> Option> { None } - pub fn Multiple(&self) -> bool { + fn Multiple(&self) -> bool { false } - pub fn SetMultiple(&mut self, _multiple: bool) -> ErrorResult { + fn SetMultiple(&mut self, _multiple: bool) -> ErrorResult { Ok(()) } - pub fn Name(&self) -> DOMString { + fn Name(&self) -> DOMString { ~"" } - pub fn SetName(&mut self, _name: DOMString) -> ErrorResult { + fn SetName(&mut self, _name: DOMString) -> ErrorResult { Ok(()) } - pub fn Required(&self) -> bool { + fn Required(&self) -> bool { false } - pub fn SetRequired(&mut self, _multiple: bool) -> ErrorResult { + fn SetRequired(&mut self, _multiple: bool) -> ErrorResult { Ok(()) } - pub fn Size(&self) -> u32 { + fn Size(&self) -> u32 { 0 } - pub fn SetSize(&mut self, _size: u32) -> ErrorResult { + fn SetSize(&mut self, _size: u32) -> ErrorResult { Ok(()) } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn Length(&self) -> u32 { + fn Length(&self) -> u32 { 0 } - pub fn SetLength(&mut self, _length: u32) -> ErrorResult { + fn SetLength(&mut self, _length: u32) -> ErrorResult { Ok(()) } - pub fn Item(&self, _index: u32) -> Option> { + fn Item(&self, _index: u32) -> Option> { None } - pub fn NamedItem(&self, _name: DOMString) -> Option> { + fn NamedItem(&self, _name: DOMString) -> Option> { None } - pub fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option> { + fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option> { None } - pub fn IndexedSetter(&mut self, _index: u32, _option: Option>) -> ErrorResult { + fn IndexedSetter(&mut self, _index: u32, _option: Option>) -> ErrorResult { Ok(()) } - pub fn Remove_(&self) { + fn Remove_(&self) { } - pub fn Remove(&self, _index: i32) { + fn Remove(&self, _index: i32) { } - pub fn SelectedIndex(&self) -> i32 { + fn SelectedIndex(&self) -> i32 { 0 } - pub fn SetSelectedIndex(&mut self, _index: i32) -> ErrorResult { + fn SetSelectedIndex(&mut self, _index: i32) -> ErrorResult { Ok(()) } - pub fn Value(&self) -> DOMString { + fn Value(&self) -> DOMString { ~"" } - pub fn SetValue(&mut self, _value: DOMString) { + fn SetValue(&mut self, _value: DOMString) { } - pub fn WillValidate(&self) -> bool { + fn WillValidate(&self) -> bool { false } - pub fn SetWillValidate(&mut self, _will_validate: bool) { + fn SetWillValidate(&mut self, _will_validate: bool) { } - pub fn Validity(&self) -> Unrooted { + fn Validity(&self) -> Unrooted { let roots = RootCollection::new(); let doc = self.htmlelement.element.node.owner_doc().root(&roots); let window = doc.deref().window.root(&roots); ValidityState::new(&*window) } - pub fn SetValidity(&mut self, _validity: JS) { + fn SetValidity(&mut self, _validity: JS) { } - pub fn ValidationMessage(&self) -> DOMString { + fn ValidationMessage(&self) -> DOMString { ~"" } - pub fn SetValidationMessage(&mut self, _message: DOMString) -> ErrorResult { + fn SetValidationMessage(&mut self, _message: DOMString) -> ErrorResult { Ok(()) } - pub fn CheckValidity(&self) -> bool { + fn CheckValidity(&self) -> bool { true } - pub fn SetCustomValidity(&mut self, _error: DOMString) { + fn SetCustomValidity(&mut self, _error: DOMString) { } - pub fn Add(&self, _element: HTMLOptionElementOrHTMLOptGroupElement, _before: Option) -> ErrorResult { + fn Add(&self, _element: HTMLOptionElementOrHTMLOptGroupElement, _before: Option) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlsourceelement.rs b/src/components/script/dom/htmlsourceelement.rs index ef7ec5c9108..76d7cb28bab 100644 --- a/src/components/script/dom/htmlsourceelement.rs +++ b/src/components/script/dom/htmlsourceelement.rs @@ -40,28 +40,38 @@ impl HTMLSourceElement { } } -impl HTMLSourceElement { - pub fn Src(&self) -> DOMString { +pub trait HTMLSourceElementMethods { + fn Src(&self) -> DOMString; + fn SetSrc(&mut self, _src: DOMString) -> ErrorResult; + fn Type(&self) -> DOMString; + fn SetType(&mut self, _type: DOMString) -> ErrorResult; + fn Media(&self) -> DOMString; + fn SetMedia(&mut self, _media: DOMString) -> ErrorResult; +} + +impl<'a> HTMLSourceElementMethods for JSRef<'a, HTMLSourceElement> { + fn Src(&self) -> DOMString { ~"" } - pub fn SetSrc(&mut self, _src: DOMString) -> ErrorResult { + fn SetSrc(&mut self, _src: DOMString) -> ErrorResult { Ok(()) } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn SetType(&mut self, _type: DOMString) -> ErrorResult { + fn SetType(&mut self, _type: DOMString) -> ErrorResult { Ok(()) } - pub fn Media(&self) -> DOMString { + fn Media(&self) -> DOMString { ~"" } - pub fn SetMedia(&mut self, _media: DOMString) -> ErrorResult { + fn SetMedia(&mut self, _media: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlspanelement.rs b/src/components/script/dom/htmlspanelement.rs index 3867fa591de..dac10e30b68 100644 --- a/src/components/script/dom/htmlspanelement.rs +++ b/src/components/script/dom/htmlspanelement.rs @@ -38,3 +38,6 @@ impl HTMLSpanElement { Node::reflect_node(~element, document, HTMLSpanElementBinding::Wrap) } } + +pub trait HTMLSpanElementMethods { +} diff --git a/src/components/script/dom/htmlstyleelement.rs b/src/components/script/dom/htmlstyleelement.rs index ec2a997586b..aac38920342 100644 --- a/src/components/script/dom/htmlstyleelement.rs +++ b/src/components/script/dom/htmlstyleelement.rs @@ -10,7 +10,7 @@ use dom::document::Document; use dom::element::HTMLStyleElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlelement::HTMLElement; -use dom::node::{Node, ElementNodeTypeId, window_from_node}; +use dom::node::{Node, NodeMethods, ElementNodeTypeId, window_from_node}; use dom::virtualmethods::VirtualMethods; use html::cssparse::parse_inline_css; use layout_interface::{AddStylesheetMsg, LayoutChan}; @@ -43,35 +43,46 @@ impl HTMLStyleElement { } } -impl HTMLStyleElement { - pub fn Disabled(&self) -> bool { +pub trait HTMLStyleElementMethods { + fn Disabled(&self) -> bool; + fn SetDisabled(&self, _disabled: bool); + fn Media(&self) -> DOMString; + fn SetMedia(&mut self, _media: DOMString) -> ErrorResult; + fn Type(&self) -> DOMString; + fn SetType(&mut self, _type: DOMString) -> ErrorResult; + fn Scoped(&self) -> bool; + fn SetScoped(&self, _scoped: bool) -> ErrorResult; +} + +impl<'a> HTMLStyleElementMethods for JSRef<'a, HTMLStyleElement> { + fn Disabled(&self) -> bool { false } - pub fn SetDisabled(&self, _disabled: bool) { + fn SetDisabled(&self, _disabled: bool) { } - pub fn Media(&self) -> DOMString { + fn Media(&self) -> DOMString { ~"" } - pub fn SetMedia(&mut self, _media: DOMString) -> ErrorResult { + fn SetMedia(&mut self, _media: DOMString) -> ErrorResult { Ok(()) } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn SetType(&mut self, _type: DOMString) -> ErrorResult { + fn SetType(&mut self, _type: DOMString) -> ErrorResult { Ok(()) } - pub fn Scoped(&self) -> bool { + fn Scoped(&self) -> bool { false } - pub fn SetScoped(&self, _scoped: bool) -> ErrorResult { + fn SetScoped(&self, _scoped: bool) -> ErrorResult { Ok(()) } } @@ -87,7 +98,7 @@ impl<'a> StyleElementHelpers for JSRef<'a, HTMLStyleElement> { let win = window_from_node(node).root(&roots); let url = win.get().page().get_url(); - let data = node.get().GetTextContent(node).expect("Element.textContent must be a string"); + let data = node.GetTextContent(node).expect("Element.textContent must be a string"); let sheet = parse_inline_css(url, data); let LayoutChan(ref layout_chan) = *win.get().page().layout_chan; layout_chan.send(AddStylesheetMsg(sheet)); diff --git a/src/components/script/dom/htmltablecaptionelement.rs b/src/components/script/dom/htmltablecaptionelement.rs index ba83cd93ae8..45f3d6ec079 100644 --- a/src/components/script/dom/htmltablecaptionelement.rs +++ b/src/components/script/dom/htmltablecaptionelement.rs @@ -40,12 +40,18 @@ impl HTMLTableCaptionElement { } } -impl HTMLTableCaptionElement { - pub fn Align(&self) -> DOMString { +pub trait HTMLTableCaptionElementMethods { + fn Align(&self) -> DOMString; + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult; +} + +impl<'a> HTMLTableCaptionElementMethods for JSRef<'a, HTMLTableCaptionElement> { + fn Align(&self) -> DOMString { ~"" } - pub fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmltablecellelement.rs b/src/components/script/dom/htmltablecellelement.rs index b00c1d78fcd..47010ccbac7 100644 --- a/src/components/script/dom/htmltablecellelement.rs +++ b/src/components/script/dom/htmltablecellelement.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::InheritTypes::HTMLTableCellElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{ElementTypeId, HTMLTableDataCellElementTypeId, HTMLTableHeaderCellElementTypeId}; @@ -35,125 +35,159 @@ impl HTMLTableCellElement { } } -impl HTMLTableCellElement { - pub fn ColSpan(&self) -> u32 { +pub trait HTMLTableCellElementMethods { + fn ColSpan(&self) -> u32; + fn SetColSpan(&self, _col_span: u32) -> ErrorResult; + fn RowSpan(&self) -> u32; + fn SetRowSpan(&self, _col_span: u32) -> ErrorResult; + fn Headers(&self) -> DOMString; + fn SetHeaders(&self, _headers: DOMString) -> ErrorResult; + fn CellIndex(&self) -> i32; + fn GetCellIndex(&self, _cell_index: i32) -> ErrorResult; + fn Abbr(&self) -> DOMString; + fn SetAbbr(&self, _abbr: DOMString) -> ErrorResult; + fn Scope(&self) -> DOMString; + fn SetScope(&self, _abbr: DOMString) -> ErrorResult; + fn Align(&self) -> DOMString; + fn SetAlign(&self, _align: DOMString) -> ErrorResult; + fn Axis(&self) -> DOMString; + fn SetAxis(&self, _axis: DOMString) -> ErrorResult; + fn Height(&self) -> DOMString; + fn SetHeight(&self, _height: DOMString) -> ErrorResult; + fn Width(&self) -> DOMString; + fn SetWidth(&self, _width: DOMString) -> ErrorResult; + fn Ch(&self) -> DOMString; + fn SetCh(&self, _ch: DOMString) -> ErrorResult; + fn ChOff(&self) -> DOMString; + fn SetChOff(&self, _ch_off: DOMString) -> ErrorResult; + fn NoWrap(&self) -> bool; + fn SetNoWrap(&self, _no_wrap: bool) -> ErrorResult; + fn VAlign(&self) -> DOMString; + fn SetVAlign(&self, _valign: DOMString) -> ErrorResult; + fn BgColor(&self) -> DOMString; + fn SetBgColor(&self, _bg_color: DOMString) -> ErrorResult; +} + +impl<'a> HTMLTableCellElementMethods for JSRef<'a, HTMLTableCellElement> { + fn ColSpan(&self) -> u32 { 0 } - pub fn SetColSpan(&self, _col_span: u32) -> ErrorResult { + fn SetColSpan(&self, _col_span: u32) -> ErrorResult { Ok(()) } - pub fn RowSpan(&self) -> u32 { + fn RowSpan(&self) -> u32 { 0 } - pub fn SetRowSpan(&self, _col_span: u32) -> ErrorResult { + fn SetRowSpan(&self, _col_span: u32) -> ErrorResult { Ok(()) } - pub fn Headers(&self) -> DOMString { + fn Headers(&self) -> DOMString { ~"" } - pub fn SetHeaders(&self, _headers: DOMString) -> ErrorResult { + fn SetHeaders(&self, _headers: DOMString) -> ErrorResult { Ok(()) } - pub fn CellIndex(&self) -> i32 { + fn CellIndex(&self) -> i32 { 0 } - pub fn GetCellIndex(&self, _cell_index: i32) -> ErrorResult { + fn GetCellIndex(&self, _cell_index: i32) -> ErrorResult { Ok(()) } - pub fn Abbr(&self) -> DOMString { + fn Abbr(&self) -> DOMString { ~"" } - pub fn SetAbbr(&self, _abbr: DOMString) -> ErrorResult { + fn SetAbbr(&self, _abbr: DOMString) -> ErrorResult { Ok(()) } - pub fn Scope(&self) -> DOMString { + fn Scope(&self) -> DOMString { ~"" } - pub fn SetScope(&self, _abbr: DOMString) -> ErrorResult { + fn SetScope(&self, _abbr: DOMString) -> ErrorResult { Ok(()) } - pub fn Align(&self) -> DOMString { + fn Align(&self) -> DOMString { ~"" } - pub fn SetAlign(&self, _align: DOMString) -> ErrorResult { + fn SetAlign(&self, _align: DOMString) -> ErrorResult { Ok(()) } - pub fn Axis(&self) -> DOMString { + fn Axis(&self) -> DOMString { ~"" } - pub fn SetAxis(&self, _axis: DOMString) -> ErrorResult { + fn SetAxis(&self, _axis: DOMString) -> ErrorResult { Ok(()) } - pub fn Height(&self) -> DOMString { + fn Height(&self) -> DOMString { ~"" } - pub fn SetHeight(&self, _height: DOMString) -> ErrorResult { + fn SetHeight(&self, _height: DOMString) -> ErrorResult { Ok(()) } - pub fn Width(&self) -> DOMString { + fn Width(&self) -> DOMString { ~"" } - pub fn SetWidth(&self, _width: DOMString) -> ErrorResult { + fn SetWidth(&self, _width: DOMString) -> ErrorResult { Ok(()) } - pub fn Ch(&self) -> DOMString { + fn Ch(&self) -> DOMString { ~"" } - pub fn SetCh(&self, _ch: DOMString) -> ErrorResult { + fn SetCh(&self, _ch: DOMString) -> ErrorResult { Ok(()) } - pub fn ChOff(&self) -> DOMString { + fn ChOff(&self) -> DOMString { ~"" } - pub fn SetChOff(&self, _ch_off: DOMString) -> ErrorResult { + fn SetChOff(&self, _ch_off: DOMString) -> ErrorResult { Ok(()) } - pub fn NoWrap(&self) -> bool { + fn NoWrap(&self) -> bool { false } - pub fn SetNoWrap(&self, _no_wrap: bool) -> ErrorResult { + fn SetNoWrap(&self, _no_wrap: bool) -> ErrorResult { Ok(()) } - pub fn VAlign(&self) -> DOMString { + fn VAlign(&self) -> DOMString { ~"" } - pub fn SetVAlign(&self, _valign: DOMString) -> ErrorResult { + fn SetVAlign(&self, _valign: DOMString) -> ErrorResult { Ok(()) } - pub fn BgColor(&self) -> DOMString { + fn BgColor(&self) -> DOMString { ~"" } - pub fn SetBgColor(&self, _bg_color: DOMString) -> ErrorResult { + fn SetBgColor(&self, _bg_color: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmltablecolelement.rs b/src/components/script/dom/htmltablecolelement.rs index c8b8c74ad6b..97c85275ee9 100644 --- a/src/components/script/dom/htmltablecolelement.rs +++ b/src/components/script/dom/htmltablecolelement.rs @@ -40,52 +40,68 @@ impl HTMLTableColElement { } } -impl HTMLTableColElement { - pub fn Span(&self) -> u32 { +pub trait HTMLTableColElementMethods { + fn Span(&self) -> u32; + fn SetSpan(&mut self, _span: u32) -> ErrorResult; + fn Align(&self) -> DOMString; + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult; + fn Ch(&self) -> DOMString; + fn SetCh(&mut self, _ch: DOMString) -> ErrorResult; + fn ChOff(&self) -> DOMString; + fn SetChOff(&mut self, _ch_off: DOMString) -> ErrorResult; + fn VAlign(&self) -> DOMString; + fn SetVAlign(&mut self, _v_align: DOMString) -> ErrorResult; + fn Width(&self) -> DOMString; + fn SetWidth(&mut self, _width: DOMString) -> ErrorResult; +} + +impl<'a> HTMLTableColElementMethods for JSRef<'a, HTMLTableColElement> { + fn Span(&self) -> u32 { 0 } - pub fn SetSpan(&mut self, _span: u32) -> ErrorResult { + fn SetSpan(&mut self, _span: u32) -> ErrorResult { Ok(()) } - pub fn Align(&self) -> DOMString { + fn Align(&self) -> DOMString { ~"" } - pub fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { Ok(()) } - pub fn Ch(&self) -> DOMString { + fn Ch(&self) -> DOMString { ~"" } - pub fn SetCh(&mut self, _ch: DOMString) -> ErrorResult { + fn SetCh(&mut self, _ch: DOMString) -> ErrorResult { Ok(()) } - pub fn ChOff(&self) -> DOMString { + fn ChOff(&self) -> DOMString { ~"" } - pub fn SetChOff(&mut self, _ch_off: DOMString) -> ErrorResult { + fn SetChOff(&mut self, _ch_off: DOMString) -> ErrorResult { Ok(()) } - pub fn VAlign(&self) -> DOMString { + fn VAlign(&self) -> DOMString { ~"" } - pub fn SetVAlign(&mut self, _v_align: DOMString) -> ErrorResult { + fn SetVAlign(&mut self, _v_align: DOMString) -> ErrorResult { Ok(()) } - pub fn Width(&self) -> DOMString { + fn Width(&self) -> DOMString { ~"" } - pub fn SetWidth(&mut self, _width: DOMString) -> ErrorResult { + fn SetWidth(&mut self, _width: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmltabledatacellelement.rs b/src/components/script/dom/htmltabledatacellelement.rs index 830740127f0..359e2837744 100644 --- a/src/components/script/dom/htmltabledatacellelement.rs +++ b/src/components/script/dom/htmltabledatacellelement.rs @@ -38,3 +38,6 @@ impl HTMLTableDataCellElement { Node::reflect_node(~element, document, HTMLTableDataCellElementBinding::Wrap) } } + +pub trait HTMLTableDataCellElementMethods { +} diff --git a/src/components/script/dom/htmltableelement.rs b/src/components/script/dom/htmltableelement.rs index 8150c68d3a6..6451e2d7276 100644 --- a/src/components/script/dom/htmltableelement.rs +++ b/src/components/script/dom/htmltableelement.rs @@ -40,99 +40,128 @@ impl HTMLTableElement { } } -impl HTMLTableElement { - pub fn DeleteCaption(&self) { +pub trait HTMLTableElementMethods { + fn DeleteCaption(&self); + fn DeleteTHead(&self); + fn DeleteTFoot(&self); + fn DeleteRow(&mut self, _index: i32) -> ErrorResult; + fn Sortable(&self) -> bool; + fn SetSortable(&self, _sortable: bool); + fn StopSorting(&self); + fn Align(&self) -> DOMString; + fn SetAlign(&self, _align: DOMString) -> ErrorResult; + fn Border(&self) -> DOMString; + fn SetBorder(&self, _border: DOMString) -> ErrorResult; + fn Frame(&self) -> DOMString; + fn SetFrame(&self, _frame: DOMString) -> ErrorResult; + fn Rules(&self) -> DOMString; + fn SetRules(&self, _rules: DOMString) -> ErrorResult; + fn Summary(&self) -> DOMString; + fn SetSummary(&self, _summary: DOMString) -> ErrorResult; + fn Width(&self) -> DOMString; + fn SetWidth(&self, _width: DOMString) -> ErrorResult; + fn BgColor(&self) -> DOMString; + fn SetBgColor(&self, _bg_color: DOMString) -> ErrorResult; + fn CellPadding(&self) -> DOMString; + fn SetCellPadding(&self, _cell_padding: DOMString) -> ErrorResult; + fn CellSpacing(&self) -> DOMString; + fn SetCellSpacing(&self, _cell_spacing: DOMString) -> ErrorResult; +} + +impl<'a> HTMLTableElementMethods for JSRef<'a, HTMLTableElement> { + fn DeleteCaption(&self) { } - pub fn DeleteTHead(&self) { + fn DeleteTHead(&self) { } - pub fn DeleteTFoot(&self) { + fn DeleteTFoot(&self) { } - pub fn DeleteRow(&mut self, _index: i32) -> ErrorResult { + fn DeleteRow(&mut self, _index: i32) -> ErrorResult { Ok(()) } - pub fn Sortable(&self) -> bool { + fn Sortable(&self) -> bool { false } - pub fn SetSortable(&self, _sortable: bool) { + fn SetSortable(&self, _sortable: bool) { } - pub fn StopSorting(&self) { + fn StopSorting(&self) { } - pub fn Align(&self) -> DOMString { + fn Align(&self) -> DOMString { ~"" } - pub fn SetAlign(&self, _align: DOMString) -> ErrorResult { + fn SetAlign(&self, _align: DOMString) -> ErrorResult { Ok(()) } - pub fn Border(&self) -> DOMString { + fn Border(&self) -> DOMString { ~"" } - pub fn SetBorder(&self, _border: DOMString) -> ErrorResult { + fn SetBorder(&self, _border: DOMString) -> ErrorResult { Ok(()) } - pub fn Frame(&self) -> DOMString { + fn Frame(&self) -> DOMString { ~"" } - pub fn SetFrame(&self, _frame: DOMString) -> ErrorResult { + fn SetFrame(&self, _frame: DOMString) -> ErrorResult { Ok(()) } - pub fn Rules(&self) -> DOMString { + fn Rules(&self) -> DOMString { ~"" } - pub fn SetRules(&self, _rules: DOMString) -> ErrorResult { + fn SetRules(&self, _rules: DOMString) -> ErrorResult { Ok(()) } - pub fn Summary(&self) -> DOMString { + fn Summary(&self) -> DOMString { ~"" } - pub fn SetSummary(&self, _summary: DOMString) -> ErrorResult { + fn SetSummary(&self, _summary: DOMString) -> ErrorResult { Ok(()) } - pub fn Width(&self) -> DOMString { + fn Width(&self) -> DOMString { ~"" } - pub fn SetWidth(&self, _width: DOMString) -> ErrorResult { + fn SetWidth(&self, _width: DOMString) -> ErrorResult { Ok(()) } - pub fn BgColor(&self) -> DOMString { + fn BgColor(&self) -> DOMString { ~"" } - pub fn SetBgColor(&self, _bg_color: DOMString) -> ErrorResult { + fn SetBgColor(&self, _bg_color: DOMString) -> ErrorResult { Ok(()) } - pub fn CellPadding(&self) -> DOMString { + fn CellPadding(&self) -> DOMString { ~"" } - pub fn SetCellPadding(&self, _cell_padding: DOMString) -> ErrorResult { + fn SetCellPadding(&self, _cell_padding: DOMString) -> ErrorResult { Ok(()) } - pub fn CellSpacing(&self) -> DOMString { + fn CellSpacing(&self) -> DOMString { ~"" } - pub fn SetCellSpacing(&self, _cell_spacing: DOMString) -> ErrorResult { + fn SetCellSpacing(&self, _cell_spacing: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmltableheadercellelement.rs b/src/components/script/dom/htmltableheadercellelement.rs index 90dba152b44..ce1dc6a8241 100644 --- a/src/components/script/dom/htmltableheadercellelement.rs +++ b/src/components/script/dom/htmltableheadercellelement.rs @@ -38,3 +38,6 @@ impl HTMLTableHeaderCellElement { Node::reflect_node(~element, document, HTMLTableHeaderCellElementBinding::Wrap) } } + +pub trait HTMLTableHeaderCellElementMethods { +} diff --git a/src/components/script/dom/htmltablerowelement.rs b/src/components/script/dom/htmltablerowelement.rs index 2b77faeadab..d7d05516798 100644 --- a/src/components/script/dom/htmltablerowelement.rs +++ b/src/components/script/dom/htmltablerowelement.rs @@ -40,64 +40,83 @@ impl HTMLTableRowElement { } } -impl HTMLTableRowElement { - pub fn RowIndex(&self) -> i32 { +pub trait HTMLTableRowElementMethods { + fn RowIndex(&self) -> i32; + fn GetRowIndex(&self) -> i32; + fn SectionRowIndex(&self) -> i32; + fn GetSectionRowIndex(&self) -> i32; + fn DeleteCell(&mut self, _index: i32) -> ErrorResult; + fn Align(&self) -> DOMString; + fn SetAlign(&self, _align: DOMString) -> ErrorResult; + fn Ch(&self) -> DOMString; + fn SetCh(&self, _ch: DOMString) -> ErrorResult; + fn ChOff(&self) -> DOMString; + fn SetChOff(&self, _ch_off: DOMString) -> ErrorResult; + fn VAlign(&self) -> DOMString; + fn SetVAlign(&self, _v_align: DOMString) -> ErrorResult; + fn BgColor(&self) -> DOMString; + fn SetBgColor(&self, _bg_color: DOMString) -> ErrorResult; +} + +impl<'a> HTMLTableRowElementMethods for JSRef<'a, HTMLTableRowElement> { + fn RowIndex(&self) -> i32 { 0 } - pub fn GetRowIndex(&self) -> i32 { + fn GetRowIndex(&self) -> i32 { 0 } - pub fn SectionRowIndex(&self) -> i32 { + fn SectionRowIndex(&self) -> i32 { 0 } - pub fn GetSectionRowIndex(&self) -> i32 { + fn GetSectionRowIndex(&self) -> i32 { 0 } - pub fn DeleteCell(&mut self, _index: i32) -> ErrorResult { + fn DeleteCell(&mut self, _index: i32) -> ErrorResult { Ok(()) } - pub fn Align(&self) -> DOMString { + fn Align(&self) -> DOMString { ~"" } - pub fn SetAlign(&self, _align: DOMString) -> ErrorResult { + fn SetAlign(&self, _align: DOMString) -> ErrorResult { Ok(()) } - pub fn Ch(&self) -> DOMString { + fn Ch(&self) -> DOMString { ~"" } - pub fn SetCh(&self, _ch: DOMString) -> ErrorResult { + fn SetCh(&self, _ch: DOMString) -> ErrorResult { Ok(()) } - pub fn ChOff(&self) -> DOMString { + fn ChOff(&self) -> DOMString { ~"" } - pub fn SetChOff(&self, _ch_off: DOMString) -> ErrorResult { + fn SetChOff(&self, _ch_off: DOMString) -> ErrorResult { Ok(()) } - pub fn VAlign(&self) -> DOMString { + fn VAlign(&self) -> DOMString { ~"" } - pub fn SetVAlign(&self, _v_align: DOMString) -> ErrorResult { + fn SetVAlign(&self, _v_align: DOMString) -> ErrorResult { Ok(()) } - pub fn BgColor(&self) -> DOMString { + fn BgColor(&self) -> DOMString { ~"" } - pub fn SetBgColor(&self, _bg_color: DOMString) -> ErrorResult { + fn SetBgColor(&self, _bg_color: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmltablesectionelement.rs b/src/components/script/dom/htmltablesectionelement.rs index b44aba6e9dc..62dd52e9758 100644 --- a/src/components/script/dom/htmltablesectionelement.rs +++ b/src/components/script/dom/htmltablesectionelement.rs @@ -40,40 +40,53 @@ impl HTMLTableSectionElement { } } -impl HTMLTableSectionElement { - pub fn DeleteRow(&mut self, _index: i32) -> ErrorResult { +pub trait HTMLTableSectionElementMethods { + fn DeleteRow(&mut self, _index: i32) -> ErrorResult; + fn Align(&self) -> DOMString; + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult; + fn Ch(&self) -> DOMString; + fn SetCh(&mut self, _ch: DOMString) -> ErrorResult; + fn ChOff(&self) -> DOMString; + fn SetChOff(&mut self, _ch_off: DOMString) -> ErrorResult; + fn VAlign(&self) -> DOMString; + fn SetVAlign(&mut self, _v_align: DOMString) -> ErrorResult; +} + +impl<'a> HTMLTableSectionElementMethods for JSRef<'a, HTMLTableSectionElement> { + fn DeleteRow(&mut self, _index: i32) -> ErrorResult { Ok(()) } - pub fn Align(&self) -> DOMString { + fn Align(&self) -> DOMString { ~"" } - pub fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { + fn SetAlign(&mut self, _align: DOMString) -> ErrorResult { Ok(()) } - pub fn Ch(&self) -> DOMString { + fn Ch(&self) -> DOMString { ~"" } - pub fn SetCh(&mut self, _ch: DOMString) -> ErrorResult { + fn SetCh(&mut self, _ch: DOMString) -> ErrorResult { Ok(()) } - pub fn ChOff(&self) -> DOMString { + fn ChOff(&self) -> DOMString { ~"" } - pub fn SetChOff(&mut self, _ch_off: DOMString) -> ErrorResult { + fn SetChOff(&mut self, _ch_off: DOMString) -> ErrorResult { Ok(()) } - pub fn VAlign(&self) -> DOMString { + fn VAlign(&self) -> DOMString { ~"" } - pub fn SetVAlign(&mut self, _v_align: DOMString) -> ErrorResult { + fn SetVAlign(&mut self, _v_align: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmltemplateelement.rs b/src/components/script/dom/htmltemplateelement.rs index f645e1815d3..245ce104439 100644 --- a/src/components/script/dom/htmltemplateelement.rs +++ b/src/components/script/dom/htmltemplateelement.rs @@ -38,3 +38,6 @@ impl HTMLTemplateElement { Node::reflect_node(~element, document, HTMLTemplateElementBinding::Wrap) } } + +pub trait HTMLTemplateElementMethods { +} diff --git a/src/components/script/dom/htmltextareaelement.rs b/src/components/script/dom/htmltextareaelement.rs index 4955085c751..2005a6384e4 100644 --- a/src/components/script/dom/htmltextareaelement.rs +++ b/src/components/script/dom/htmltextareaelement.rs @@ -40,163 +40,208 @@ impl HTMLTextAreaElement { } } -impl HTMLTextAreaElement { - pub fn Autofocus(&self) -> bool { +pub trait HTMLTextAreaElementMethods { + fn Autofocus(&self) -> bool; + fn SetAutofocus(&mut self, _autofocus: bool) -> ErrorResult; + fn Cols(&self) -> u32; + fn SetCols(&self, _cols: u32) -> ErrorResult; + fn Disabled(&self) -> bool; + fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult; + fn MaxLength(&self) -> i32; + fn SetMaxLength(&self, _max_length: i32) -> ErrorResult; + fn Name(&self) -> DOMString; + fn SetName(&mut self, _name: DOMString) -> ErrorResult; + fn Placeholder(&self) -> DOMString; + fn SetPlaceholder(&mut self, _placeholder: DOMString) -> ErrorResult; + fn ReadOnly(&self) -> bool; + fn SetReadOnly(&mut self, _read_only: bool) -> ErrorResult; + fn Required(&self) -> bool; + fn SetRequired(&mut self, _required: bool) -> ErrorResult; + fn Rows(&self) -> u32; + fn SetRows(&self, _rows: u32) -> ErrorResult; + fn Wrap(&self) -> DOMString; + fn SetWrap(&mut self, _wrap: DOMString) -> ErrorResult; + fn Type(&self) -> DOMString; + fn SetType(&mut self, _type: DOMString); + fn DefaultValue(&self) -> DOMString; + fn SetDefaultValue(&mut self, _default_value: DOMString) -> ErrorResult; + fn Value(&self) -> DOMString; + fn SetValue(&mut self, _value: DOMString); + fn TextLength(&self) -> u32; + fn SetTextLength(&self, _text_length: u32) -> ErrorResult; + fn WillValidate(&self) -> bool; + fn SetWillValidate(&mut self, _will_validate: bool) -> ErrorResult; + fn ValidationMessage(&self) -> DOMString; + fn CheckValidity(&self) -> bool; + fn SetCustomValidity(&self, _error: DOMString); + fn Select(&self); + fn GetSelectionStart(&self) -> Fallible; + fn SetSelectionStart(&self, _selection_start: u32) -> ErrorResult; + fn GetSelectionEnd(&self) -> Fallible; + fn SetSelectionEnd(&self, _selection_end: u32) -> ErrorResult; + fn GetSelectionDirection(&self) -> Fallible; + fn SetSelectionDirection(&self, _selection_direction: DOMString) -> ErrorResult; + fn SetRangeText(&self, _replacement: DOMString); +} + +impl<'a> HTMLTextAreaElementMethods for JSRef<'a, HTMLTextAreaElement> { + fn Autofocus(&self) -> bool { false } - pub fn SetAutofocus(&mut self, _autofocus: bool) -> ErrorResult { + fn SetAutofocus(&mut self, _autofocus: bool) -> ErrorResult { Ok(()) } - pub fn Cols(&self) -> u32 { + fn Cols(&self) -> u32 { 0 } - pub fn SetCols(&self, _cols: u32) -> ErrorResult { + fn SetCols(&self, _cols: u32) -> ErrorResult { Ok(()) } - pub fn Disabled(&self) -> bool { + fn Disabled(&self) -> bool { false } - pub fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult { + fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult { Ok(()) } - pub fn MaxLength(&self) -> i32 { + fn MaxLength(&self) -> i32 { 0 } - pub fn SetMaxLength(&self, _max_length: i32) -> ErrorResult { + fn SetMaxLength(&self, _max_length: i32) -> ErrorResult { Ok(()) } - pub fn Name(&self) -> DOMString { + fn Name(&self) -> DOMString { ~"" } - pub fn SetName(&mut self, _name: DOMString) -> ErrorResult { + fn SetName(&mut self, _name: DOMString) -> ErrorResult { Ok(()) } - pub fn Placeholder(&self) -> DOMString { + fn Placeholder(&self) -> DOMString { ~"" } - pub fn SetPlaceholder(&mut self, _placeholder: DOMString) -> ErrorResult { + fn SetPlaceholder(&mut self, _placeholder: DOMString) -> ErrorResult { Ok(()) } - pub fn ReadOnly(&self) -> bool { + fn ReadOnly(&self) -> bool { false } - pub fn SetReadOnly(&mut self, _read_only: bool) -> ErrorResult { + fn SetReadOnly(&mut self, _read_only: bool) -> ErrorResult { Ok(()) } - pub fn Required(&self) -> bool { + fn Required(&self) -> bool { false } - pub fn SetRequired(&mut self, _required: bool) -> ErrorResult { + fn SetRequired(&mut self, _required: bool) -> ErrorResult { Ok(()) } - pub fn Rows(&self) -> u32 { + fn Rows(&self) -> u32 { 0 } - pub fn SetRows(&self, _rows: u32) -> ErrorResult { + fn SetRows(&self, _rows: u32) -> ErrorResult { Ok(()) } - pub fn Wrap(&self) -> DOMString { + fn Wrap(&self) -> DOMString { ~"" } - pub fn SetWrap(&mut self, _wrap: DOMString) -> ErrorResult { + fn SetWrap(&mut self, _wrap: DOMString) -> ErrorResult { Ok(()) } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn SetType(&mut self, _type: DOMString) { + fn SetType(&mut self, _type: DOMString) { } - pub fn DefaultValue(&self) -> DOMString { + fn DefaultValue(&self) -> DOMString { ~"" } - pub fn SetDefaultValue(&mut self, _default_value: DOMString) -> ErrorResult { + fn SetDefaultValue(&mut self, _default_value: DOMString) -> ErrorResult { Ok(()) } - pub fn Value(&self) -> DOMString { + fn Value(&self) -> DOMString { ~"" } - pub fn SetValue(&mut self, _value: DOMString) { + fn SetValue(&mut self, _value: DOMString) { } - pub fn TextLength(&self) -> u32 { + fn TextLength(&self) -> u32 { 0 } - pub fn SetTextLength(&self, _text_length: u32) -> ErrorResult { + fn SetTextLength(&self, _text_length: u32) -> ErrorResult { Ok(()) } - pub fn WillValidate(&self) -> bool { + fn WillValidate(&self) -> bool { false } - pub fn SetWillValidate(&mut self, _will_validate: bool) -> ErrorResult { + fn SetWillValidate(&mut self, _will_validate: bool) -> ErrorResult { Ok(()) } - pub fn ValidationMessage(&self) -> DOMString { + fn ValidationMessage(&self) -> DOMString { ~"" } - pub fn CheckValidity(&self) -> bool { + fn CheckValidity(&self) -> bool { false } - pub fn SetCustomValidity(&self, _error: DOMString) { + fn SetCustomValidity(&self, _error: DOMString) { } - pub fn Select(&self) { + fn Select(&self) { } - pub fn GetSelectionStart(&self) -> Fallible { + fn GetSelectionStart(&self) -> Fallible { Ok(0) } - pub fn SetSelectionStart(&self, _selection_start: u32) -> ErrorResult { + fn SetSelectionStart(&self, _selection_start: u32) -> ErrorResult { Ok(()) } - pub fn GetSelectionEnd(&self) -> Fallible { + fn GetSelectionEnd(&self) -> Fallible { Ok(0) } - pub fn SetSelectionEnd(&self, _selection_end: u32) -> ErrorResult { + fn SetSelectionEnd(&self, _selection_end: u32) -> ErrorResult { Ok(()) } - pub fn GetSelectionDirection(&self) -> Fallible { + fn GetSelectionDirection(&self) -> Fallible { Ok(~"") } - pub fn SetSelectionDirection(&self, _selection_direction: DOMString) -> ErrorResult { + fn SetSelectionDirection(&self, _selection_direction: DOMString) -> ErrorResult { Ok(()) } - pub fn SetRangeText(&self, _replacement: DOMString) { + fn SetRangeText(&self, _replacement: DOMString) { } } + diff --git a/src/components/script/dom/htmltimeelement.rs b/src/components/script/dom/htmltimeelement.rs index df74323fc01..dd2a9b28f97 100644 --- a/src/components/script/dom/htmltimeelement.rs +++ b/src/components/script/dom/htmltimeelement.rs @@ -40,12 +40,18 @@ impl HTMLTimeElement { } } -impl HTMLTimeElement { - pub fn DateTime(&self) -> DOMString { +pub trait HTMLTimeElementMethods { + fn DateTime(&self) -> DOMString; + fn SetDateTime(&mut self, _dateTime: DOMString) -> ErrorResult; +} + +impl<'a> HTMLTimeElementMethods for JSRef<'a, HTMLTimeElement> { + fn DateTime(&self) -> DOMString { ~"" } - pub fn SetDateTime(&mut self, _dateTime: DOMString) -> ErrorResult { + fn SetDateTime(&mut self, _dateTime: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmltitleelement.rs b/src/components/script/dom/htmltitleelement.rs index 2c1af9b5291..c78b26ee4cb 100644 --- a/src/components/script/dom/htmltitleelement.rs +++ b/src/components/script/dom/htmltitleelement.rs @@ -40,12 +40,18 @@ impl HTMLTitleElement { } } -impl HTMLTitleElement { - pub fn Text(&self) -> DOMString { +pub trait HTMLTitleElementMethods { + fn Text(&self) -> DOMString; + fn SetText(&mut self, _text: DOMString) -> ErrorResult; +} + +impl<'a> HTMLTitleElementMethods for JSRef<'a, HTMLTitleElement> { + fn Text(&self) -> DOMString { ~"" } - pub fn SetText(&mut self, _text: DOMString) -> ErrorResult { + fn SetText(&mut self, _text: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmltrackelement.rs b/src/components/script/dom/htmltrackelement.rs index 408da82d53b..db25ab17130 100644 --- a/src/components/script/dom/htmltrackelement.rs +++ b/src/components/script/dom/htmltrackelement.rs @@ -40,48 +40,63 @@ impl HTMLTrackElement { } } -impl HTMLTrackElement { - pub fn Kind(&self) -> DOMString { +pub trait HTMLTrackElementMethods { + fn Kind(&self) -> DOMString; + fn SetKind(&mut self, _kind: DOMString) -> ErrorResult; + fn Src(&self) -> DOMString; + fn SetSrc(&mut self, _src: DOMString) -> ErrorResult; + fn Srclang(&self) -> DOMString; + fn SetSrclang(&mut self, _srclang: DOMString) -> ErrorResult; + fn Label(&self) -> DOMString; + fn SetLabel(&mut self, _label: DOMString) -> ErrorResult; + fn Default(&self) -> bool; + fn SetDefault(&mut self, _default: bool) -> ErrorResult; + fn ReadyState(&self) -> u16; +} + +impl<'a> HTMLTrackElementMethods for JSRef<'a, HTMLTrackElement> { + fn Kind(&self) -> DOMString { ~"" } - pub fn SetKind(&mut self, _kind: DOMString) -> ErrorResult { + fn SetKind(&mut self, _kind: DOMString) -> ErrorResult { Ok(()) } - pub fn Src(&self) -> DOMString { + fn Src(&self) -> DOMString { ~"" } - pub fn SetSrc(&mut self, _src: DOMString) -> ErrorResult { + fn SetSrc(&mut self, _src: DOMString) -> ErrorResult { Ok(()) } - pub fn Srclang(&self) -> DOMString { + fn Srclang(&self) -> DOMString { ~"" } - pub fn SetSrclang(&mut self, _srclang: DOMString) -> ErrorResult { + fn SetSrclang(&mut self, _srclang: DOMString) -> ErrorResult { Ok(()) } - pub fn Label(&self) -> DOMString { + fn Label(&self) -> DOMString { ~"" } - pub fn SetLabel(&mut self, _label: DOMString) -> ErrorResult { + fn SetLabel(&mut self, _label: DOMString) -> ErrorResult { Ok(()) } - pub fn Default(&self) -> bool { + fn Default(&self) -> bool { false } - pub fn SetDefault(&mut self, _default: bool) -> ErrorResult { + fn SetDefault(&mut self, _default: bool) -> ErrorResult { Ok(()) } - pub fn ReadyState(&self) -> u16 { + fn ReadyState(&self) -> u16 { 0 } } + diff --git a/src/components/script/dom/htmlulistelement.rs b/src/components/script/dom/htmlulistelement.rs index c2661a5ee46..bed085157ce 100644 --- a/src/components/script/dom/htmlulistelement.rs +++ b/src/components/script/dom/htmlulistelement.rs @@ -40,20 +40,28 @@ impl HTMLUListElement { } } -impl HTMLUListElement { - pub fn Compact(&self) -> bool { +pub trait HTMLUListElementMethods { + fn Compact(&self) -> bool; + fn SetCompact(&mut self, _compact: bool) -> ErrorResult; + fn Type(&self) -> DOMString; + fn SetType(&mut self, _type: DOMString) -> ErrorResult; +} + +impl<'a> HTMLUListElementMethods for JSRef<'a, HTMLUListElement> { + fn Compact(&self) -> bool { false } - pub fn SetCompact(&mut self, _compact: bool) -> ErrorResult { + fn SetCompact(&mut self, _compact: bool) -> ErrorResult { Ok(()) } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn SetType(&mut self, _type: DOMString) -> ErrorResult { + fn SetType(&mut self, _type: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/htmlunknownelement.rs b/src/components/script/dom/htmlunknownelement.rs index da68e0c51bf..da14d35b69f 100644 --- a/src/components/script/dom/htmlunknownelement.rs +++ b/src/components/script/dom/htmlunknownelement.rs @@ -38,3 +38,6 @@ impl HTMLUnknownElement { Node::reflect_node(~element, document, HTMLUnknownElementBinding::Wrap) } } + +pub trait HTMLUnknownElementMethods { +} diff --git a/src/components/script/dom/htmlvideoelement.rs b/src/components/script/dom/htmlvideoelement.rs index aba9c3c3436..60e9d6a09cf 100644 --- a/src/components/script/dom/htmlvideoelement.rs +++ b/src/components/script/dom/htmlvideoelement.rs @@ -40,36 +40,48 @@ impl HTMLVideoElement { } } -impl HTMLVideoElement { - pub fn Width(&self) -> u32 { +pub trait HTMLVideoElementMethods { + fn Width(&self) -> u32; + fn SetWidth(&mut self, _width: u32) -> ErrorResult; + fn Height(&self) -> u32; + fn SetHeight(&mut self, _height: u32) -> ErrorResult; + fn VideoWidth(&self) -> u32; + fn VideoHeight(&self) -> u32; + fn Poster(&self) -> DOMString; + fn SetPoster(&mut self, _poster: DOMString) -> ErrorResult; +} + +impl<'a> HTMLVideoElementMethods for JSRef<'a, HTMLVideoElement> { + fn Width(&self) -> u32 { 0 } - pub fn SetWidth(&mut self, _width: u32) -> ErrorResult { + fn SetWidth(&mut self, _width: u32) -> ErrorResult { Ok(()) } - pub fn Height(&self) -> u32 { + fn Height(&self) -> u32 { 0 } - pub fn SetHeight(&mut self, _height: u32) -> ErrorResult { + fn SetHeight(&mut self, _height: u32) -> ErrorResult { Ok(()) } - pub fn VideoWidth(&self) -> u32 { + fn VideoWidth(&self) -> u32 { 0 } - pub fn VideoHeight(&self) -> u32 { + fn VideoHeight(&self) -> u32 { 0 } - pub fn Poster(&self) -> DOMString { + fn Poster(&self) -> DOMString { ~"" } - pub fn SetPoster(&mut self, _poster: DOMString) -> ErrorResult { + fn SetPoster(&mut self, _poster: DOMString) -> ErrorResult { Ok(()) } } + diff --git a/src/components/script/dom/location.rs b/src/components/script/dom/location.rs index 762da0a383b..4a28e1c449d 100644 --- a/src/components/script/dom/location.rs +++ b/src/components/script/dom/location.rs @@ -34,104 +34,134 @@ impl Location { window, LocationBinding::Wrap) } +} - pub fn Assign(&self, _url: DOMString) { +pub trait LocationMethods { + fn Assign(&self, _url: DOMString); + fn Replace(&self, _url: DOMString); + fn Reload(&self); + fn Href(&self) -> DOMString; + fn SetHref(&self, _href: DOMString) -> Fallible<()>; + fn Origin(&self) -> DOMString; + fn Protocol(&self) -> DOMString; + fn SetProtocol(&self, _protocol: DOMString); + fn Username(&self) -> DOMString; + fn SetUsername(&self, _username: DOMString); + fn Password(&self) -> DOMString; + fn SetPassword(&self, _password: DOMString); + fn Host(&self) -> DOMString; + fn SetHost(&self, _host: DOMString); + fn Hostname(&self) -> DOMString; + fn SetHostname(&self, _hostname: DOMString); + fn Port(&self) -> DOMString; + fn SetPort(&self, _port: DOMString); + fn Pathname(&self) -> DOMString; + fn SetPathname(&self, _pathname: DOMString); + fn Search(&self) -> DOMString; + fn SetSearch(&self, _search: DOMString); + fn Hash(&self) -> DOMString; + fn SetHash(&self, _hash: DOMString); +} + +impl<'a> LocationMethods for JSRef<'a, Location> { + fn Assign(&self, _url: DOMString) { } - pub fn Replace(&self, _url: DOMString) { + fn Replace(&self, _url: DOMString) { } - pub fn Reload(&self) { + fn Reload(&self) { } - pub fn Href(&self) -> DOMString { + fn Href(&self) -> DOMString { self.page.get_url().to_str() } - pub fn SetHref(&self, _href: DOMString) -> Fallible<()> { + fn SetHref(&self, _href: DOMString) -> Fallible<()> { Ok(()) } - pub fn Origin(&self) -> DOMString { + fn Origin(&self) -> DOMString { ~"" } - pub fn Protocol(&self) -> DOMString { + fn Protocol(&self) -> DOMString { ~"" } - pub fn SetProtocol(&self, _protocol: DOMString) { + fn SetProtocol(&self, _protocol: DOMString) { } - pub fn Username(&self) -> DOMString { + fn Username(&self) -> DOMString { ~"" } - pub fn SetUsername(&self, _username: DOMString) { + fn SetUsername(&self, _username: DOMString) { } - pub fn Password(&self) -> DOMString { + fn Password(&self) -> DOMString { ~"" } - pub fn SetPassword(&self, _password: DOMString) { + fn SetPassword(&self, _password: DOMString) { } - pub fn Host(&self) -> DOMString { + fn Host(&self) -> DOMString { ~"" } - pub fn SetHost(&self, _host: DOMString) { + fn SetHost(&self, _host: DOMString) { } - pub fn Hostname(&self) -> DOMString { + fn Hostname(&self) -> DOMString { ~"" } - pub fn SetHostname(&self, _hostname: DOMString) { + fn SetHostname(&self, _hostname: DOMString) { } - pub fn Port(&self) -> DOMString { + fn Port(&self) -> DOMString { ~"" } - pub fn SetPort(&self, _port: DOMString) { + fn SetPort(&self, _port: DOMString) { } - pub fn Pathname(&self) -> DOMString { + fn Pathname(&self) -> DOMString { ~"" } - pub fn SetPathname(&self, _pathname: DOMString) { + fn SetPathname(&self, _pathname: DOMString) { } - pub fn Search(&self) -> DOMString { + fn Search(&self) -> DOMString { ~"" } - pub fn SetSearch(&self, _search: DOMString) { + fn SetSearch(&self, _search: DOMString) { } - pub fn Hash(&self) -> DOMString { + fn Hash(&self) -> DOMString { ~"" } - pub fn SetHash(&self, _hash: DOMString) { + fn SetHash(&self, _hash: DOMString) { } } + impl Reflectable for Location { fn reflector<'a>(&'a self) -> &'a Reflector { &self.reflector_ diff --git a/src/components/script/dom/mouseevent.rs b/src/components/script/dom/mouseevent.rs index b771b1b091c..fbfc9cf783d 100644 --- a/src/components/script/dom/mouseevent.rs +++ b/src/components/script/dom/mouseevent.rs @@ -3,13 +3,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::MouseEventBinding; -use dom::bindings::codegen::InheritTypes::MouseEventDerived; +use dom::bindings::codegen::InheritTypes::{UIEventCast, MouseEventDerived}; use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Unrooted}; use dom::bindings::error::Fallible; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::event::{Event, MouseEventTypeId}; use dom::eventtarget::EventTarget; -use dom::uievent::UIEvent; +use dom::uievent::{UIEvent, UIEventMethods}; use dom::window::Window; use servo_util::str::DOMString; @@ -64,81 +64,117 @@ impl MouseEvent { let mut ev = MouseEvent::new(owner).root(&roots); let view = init.view.as_ref().map(|view| view.root(&roots)); let related_target = init.relatedTarget.as_ref().map(|relatedTarget| relatedTarget.root(&roots)); - ev.get_mut().InitMouseEvent(type_, init.bubbles, init.cancelable, view.root_ref(), - init.detail, init.screenX, init.screenY, - init.clientX, init.clientY, init.ctrlKey, - init.altKey, init.shiftKey, init.metaKey, - init.button, related_target.root_ref()); + ev.InitMouseEvent(type_, init.bubbles, init.cancelable, view.root_ref(), + init.detail, init.screenX, init.screenY, + init.clientX, init.clientY, init.ctrlKey, + init.altKey, init.shiftKey, init.metaKey, + init.button, related_target.root_ref()); Ok(Unrooted::new_rooted(&*ev)) } +} - pub fn ScreenX(&self) -> i32 { +pub trait MouseEventMethods { + fn ScreenX(&self) -> i32; + fn ScreenY(&self) -> i32; + fn ClientX(&self) -> i32; + fn ClientY(&self) -> i32; + fn CtrlKey(&self) -> bool; + fn ShiftKey(&self) -> bool; + fn AltKey(&self) -> bool; + fn MetaKey(&self) -> bool; + fn Button(&self) -> u16; + fn Buttons(&self)-> u16; + fn GetRelatedTarget(&self) -> Option>; + fn GetModifierState(&self, _keyArg: DOMString) -> bool; + fn InitMouseEvent(&mut self, + typeArg: DOMString, + canBubbleArg: bool, + cancelableArg: bool, + viewArg: Option>, + detailArg: i32, + screenXArg: i32, + screenYArg: i32, + clientXArg: i32, + clientYArg: i32, + ctrlKeyArg: bool, + altKeyArg: bool, + shiftKeyArg: bool, + metaKeyArg: bool, + buttonArg: u16, + relatedTargetArg: Option>); +} + +impl<'a> MouseEventMethods for JSRef<'a, MouseEvent> { + fn ScreenX(&self) -> i32 { self.screen_x } - pub fn ScreenY(&self) -> i32 { + fn ScreenY(&self) -> i32 { self.screen_y } - pub fn ClientX(&self) -> i32 { + fn ClientX(&self) -> i32 { self.client_x } - pub fn ClientY(&self) -> i32 { + fn ClientY(&self) -> i32 { self.client_y } - pub fn CtrlKey(&self) -> bool { + fn CtrlKey(&self) -> bool { self.ctrl_key } - pub fn ShiftKey(&self) -> bool { + fn ShiftKey(&self) -> bool { self.shift_key } - pub fn AltKey(&self) -> bool { + fn AltKey(&self) -> bool { self.alt_key } - pub fn MetaKey(&self) -> bool { + fn MetaKey(&self) -> bool { self.meta_key } - pub fn Button(&self) -> u16 { + fn Button(&self) -> u16 { self.button } - pub fn Buttons(&self)-> u16 { + fn Buttons(&self)-> u16 { //TODO 0 } - pub fn GetRelatedTarget(&self) -> Option> { + fn GetRelatedTarget(&self) -> Option> { self.related_target.clone().map(|target| Unrooted::new(target)) } - pub fn GetModifierState(&self, _keyArg: DOMString) -> bool { + fn GetModifierState(&self, _keyArg: DOMString) -> bool { //TODO false } - pub fn InitMouseEvent(&mut self, - typeArg: DOMString, - canBubbleArg: bool, - cancelableArg: bool, - viewArg: Option>, - detailArg: i32, - screenXArg: i32, - screenYArg: i32, - clientXArg: i32, - clientYArg: i32, - ctrlKeyArg: bool, - altKeyArg: bool, - shiftKeyArg: bool, - metaKeyArg: bool, - buttonArg: u16, - relatedTargetArg: Option>) { - self.mouseevent.InitUIEvent(typeArg, canBubbleArg, cancelableArg, viewArg, detailArg); + fn InitMouseEvent(&mut self, + typeArg: DOMString, + canBubbleArg: bool, + cancelableArg: bool, + viewArg: Option>, + detailArg: i32, + screenXArg: i32, + screenYArg: i32, + clientXArg: i32, + clientYArg: i32, + ctrlKeyArg: bool, + altKeyArg: bool, + shiftKeyArg: bool, + metaKeyArg: bool, + buttonArg: u16, + relatedTargetArg: Option>) { + { + let uievent: &mut JSRef = UIEventCast::from_mut_ref(self); + uievent.InitUIEvent(typeArg, canBubbleArg, cancelableArg, viewArg, detailArg); + } self.screen_x = screenXArg; self.screen_y = screenYArg; self.client_x = clientXArg; @@ -152,6 +188,7 @@ impl MouseEvent { } } + impl Reflectable for MouseEvent { fn reflector<'a>(&'a self) -> &'a Reflector { self.mouseevent.reflector() diff --git a/src/components/script/dom/navigator.rs b/src/components/script/dom/navigator.rs index 494175cb6b8..9e54bffb0c1 100644 --- a/src/components/script/dom/navigator.rs +++ b/src/components/script/dom/navigator.rs @@ -26,72 +26,94 @@ impl Navigator { window, NavigatorBinding::Wrap) } +} - pub fn DoNotTrack(&self) -> DOMString { +pub trait NavigatorMethods { + fn DoNotTrack(&self) -> DOMString; + fn Vendor(&self) -> DOMString; + fn VendorSub(&self) -> DOMString; + fn Product(&self) -> DOMString; + fn ProductSub(&self) -> DOMString; + fn CookieEnabled(&self) -> bool; + fn GetBuildID(&self) -> Fallible; + fn JavaEnabled(&self) -> Fallible; + fn TaintEnabled(&self) -> bool; + fn AppName(&self) -> DOMString; + fn GetAppCodeName(&self) -> Fallible; + fn GetAppVersion(&self) -> Fallible; + fn GetPlatform(&self) -> Fallible; + fn GetUserAgent(&self) -> Fallible; + fn GetLanguage(&self) -> Option; + fn OnLine(&self) -> bool; +} + +impl<'a> NavigatorMethods for JSRef<'a, Navigator> { + fn DoNotTrack(&self) -> DOMString { ~"unspecified" } - pub fn Vendor(&self) -> DOMString { + fn Vendor(&self) -> DOMString { ~"" // Like Gecko } - pub fn VendorSub(&self) -> DOMString { + fn VendorSub(&self) -> DOMString { ~"" // Like Gecko } - pub fn Product(&self) -> DOMString { + fn Product(&self) -> DOMString { ~"Gecko" } - pub fn ProductSub(&self) -> DOMString { + fn ProductSub(&self) -> DOMString { ~"" } - pub fn CookieEnabled(&self) -> bool { + fn CookieEnabled(&self) -> bool { false } - pub fn GetBuildID(&self) -> Fallible { + fn GetBuildID(&self) -> Fallible { Ok(~"") } - pub fn JavaEnabled(&self) -> Fallible { + fn JavaEnabled(&self) -> Fallible { Ok(false) } - pub fn TaintEnabled(&self) -> bool { + fn TaintEnabled(&self) -> bool { false } - pub fn AppName(&self) -> DOMString { + fn AppName(&self) -> DOMString { ~"Netscape" // Like Gecko/Webkit } - pub fn GetAppCodeName(&self) -> Fallible { + fn GetAppCodeName(&self) -> Fallible { Ok(~"Mozilla") // Like Gecko/Webkit } - pub fn GetAppVersion(&self) -> Fallible { + fn GetAppVersion(&self) -> Fallible { Ok(~"") } - pub fn GetPlatform(&self) -> Fallible { + fn GetPlatform(&self) -> Fallible { Ok(~"") } - pub fn GetUserAgent(&self) -> Fallible { + fn GetUserAgent(&self) -> Fallible { Ok(~"") } - pub fn GetLanguage(&self) -> Option { + fn GetLanguage(&self) -> Option { None } - pub fn OnLine(&self) -> bool { + fn OnLine(&self) -> bool { true } } + impl Reflectable for Navigator { fn reflector<'a>(&'a self) -> &'a Reflector { &self.reflector_ diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index fd911b3f0ba..f3aefd223cc 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -16,15 +16,15 @@ use dom::bindings::js::{ResultRootable, OptionalRootable}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::{ErrorResult, Fallible, NotFound, HierarchyRequest}; use dom::bindings::utils; -use dom::characterdata::CharacterData; +use dom::characterdata::{CharacterData, CharacterDataMethods}; use dom::comment::Comment; -use dom::document::{Document, HTMLDocument, NonHTMLDocument}; +use dom::document::{Document, DocumentMethods, HTMLDocument, NonHTMLDocument}; use dom::documentfragment::DocumentFragment; use dom::documenttype::DocumentType; -use dom::element::{Element, ElementTypeId, HTMLAnchorElementTypeId}; +use dom::element::{Element, ElementMethods, ElementTypeId, HTMLAnchorElementTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::nodelist::{NodeList}; -use dom::processinginstruction::ProcessingInstruction; +use dom::processinginstruction::{ProcessingInstruction, ProcessingInstructionMethods}; use dom::text::Text; use dom::virtualmethods::{VirtualMethods, vtable_for}; use dom::window::Window; @@ -226,17 +226,17 @@ pub enum NodeTypeId { pub fn AppendChild<'a>(self_: &mut JSRef<'a, Node>, node: &mut JSRef) -> Fallible> { let mut self_alias = self_.clone(); - self_.get_mut().AppendChild(&mut self_alias, node) + self_.AppendChild(&mut self_alias, node) } pub fn ReplaceChild<'a>(self_: &mut JSRef<'a, Node>, node: &mut JSRef, child: &mut JSRef) -> Fallible> { let mut self_alias = self_.clone(); - self_.get_mut().ReplaceChild(&mut self_alias, node, child) + self_.ReplaceChild(&mut self_alias, node, child) } pub fn RemoveChild<'a>(self_: &mut JSRef<'a, Node>, node: &mut JSRef) -> Fallible> { let mut self_alias = self_.clone(); - self_.get_mut().RemoveChild(&mut self_alias, node) + self_.RemoveChild(&mut self_alias, node) } pub trait NodeHelpers { @@ -839,6 +839,12 @@ impl Node { }) } + pub fn wait_until_safe_to_modify_dom(&self) { + let roots = RootCollection::new(); + let document = self.owner_doc().root(&roots); + document.get().wait_until_safe_to_modify_dom(); + } + pub fn reflect_node (node: ~N, document: &JSRef, @@ -897,211 +903,6 @@ impl Node { } } - // http://dom.spec.whatwg.org/#dom-node-nodetype - pub fn NodeType(&self) -> u16 { - match self.type_id { - ElementNodeTypeId(_) => NodeConstants::ELEMENT_NODE, - TextNodeTypeId => NodeConstants::TEXT_NODE, - ProcessingInstructionNodeTypeId => NodeConstants::PROCESSING_INSTRUCTION_NODE, - CommentNodeTypeId => NodeConstants::COMMENT_NODE, - DocumentNodeTypeId => NodeConstants::DOCUMENT_NODE, - DoctypeNodeTypeId => NodeConstants::DOCUMENT_TYPE_NODE, - DocumentFragmentNodeTypeId => NodeConstants::DOCUMENT_FRAGMENT_NODE, - } - } - - // http://dom.spec.whatwg.org/#dom-node-nodename - pub fn NodeName(&self, abstract_self: &JSRef) -> DOMString { - match self.type_id { - ElementNodeTypeId(..) => { - let elem: &JSRef = ElementCast::to_ref(abstract_self).unwrap(); - elem.get().TagName() - } - TextNodeTypeId => ~"#text", - ProcessingInstructionNodeTypeId => { - let processing_instruction: &JSRef = - ProcessingInstructionCast::to_ref(abstract_self).unwrap(); - processing_instruction.get().Target() - } - CommentNodeTypeId => ~"#comment", - DoctypeNodeTypeId => { - let doctype: &JSRef = DocumentTypeCast::to_ref(abstract_self).unwrap(); - doctype.get().name.clone() - }, - DocumentFragmentNodeTypeId => ~"#document-fragment", - DocumentNodeTypeId => ~"#document" - } - } - - // http://dom.spec.whatwg.org/#dom-node-baseuri - pub fn GetBaseURI(&self) -> Option { - // FIXME (#1824) implement. - None - } - - // http://dom.spec.whatwg.org/#dom-node-ownerdocument - pub fn GetOwnerDocument(&self) -> Option> { - match self.type_id { - ElementNodeTypeId(..) | - CommentNodeTypeId | - TextNodeTypeId | - ProcessingInstructionNodeTypeId | - DoctypeNodeTypeId | - DocumentFragmentNodeTypeId => Some(self.owner_doc()), - DocumentNodeTypeId => None - } - } - - // http://dom.spec.whatwg.org/#dom-node-parentnode - pub fn GetParentNode(&self) -> Option> { - self.parent_node.clone().map(|node| Unrooted::new(node)) - } - - // http://dom.spec.whatwg.org/#dom-node-parentelement - pub fn GetParentElement(&self) -> Option> { - let roots = RootCollection::new(); - self.parent_node.clone() - .and_then(|parent| { - let parent = parent.root(&roots); - ElementCast::to_ref(&*parent).map(|elem| { - Unrooted::new_rooted(elem) - }) - }) - } - - // http://dom.spec.whatwg.org/#dom-node-haschildnodes - pub fn HasChildNodes(&self) -> bool { - self.first_child.is_some() - } - - // http://dom.spec.whatwg.org/#dom-node-childnodes - pub fn ChildNodes(&mut self, abstract_self: &JSRef) -> Unrooted { - let roots = RootCollection::new(); - match self.child_list { - None => { - let doc = self.owner_doc().root(&roots); - let window = doc.deref().window.root(&roots); - self.child_list.assign(Some(NodeList::new_child_list(&*window, abstract_self))); - Unrooted::new(self.child_list.get_ref().clone()) - } - Some(ref list) => Unrooted::new(list.clone()) - } - } - - // http://dom.spec.whatwg.org/#dom-node-firstchild - pub fn GetFirstChild(&self) -> Option> { - self.first_child.clone().map(|node| Unrooted::new(node)) - } - - // http://dom.spec.whatwg.org/#dom-node-lastchild - pub fn GetLastChild(&self) -> Option> { - self.last_child.clone().map(|node| Unrooted::new(node)) - } - - // http://dom.spec.whatwg.org/#dom-node-previoussibling - pub fn GetPreviousSibling(&self) -> Option> { - self.prev_sibling.clone().map(|node| Unrooted::new(node)) - } - - // http://dom.spec.whatwg.org/#dom-node-nextsibling - pub fn GetNextSibling(&self) -> Option> { - self.next_sibling.clone().map(|node| Unrooted::new(node)) - } - - // http://dom.spec.whatwg.org/#dom-node-nodevalue - pub fn GetNodeValue(&self, abstract_self: &JSRef) -> Option { - match self.type_id { - CommentNodeTypeId | - TextNodeTypeId | - ProcessingInstructionNodeTypeId => { - let chardata: &JSRef = CharacterDataCast::to_ref(abstract_self).unwrap(); - Some(chardata.get().Data()) - } - _ => { - None - } - } - } - - // http://dom.spec.whatwg.org/#dom-node-nodevalue - pub fn SetNodeValue(&mut self, abstract_self: &mut JSRef, val: Option) - -> ErrorResult { - match self.type_id { - CommentNodeTypeId | - TextNodeTypeId | - ProcessingInstructionNodeTypeId => { - self.SetTextContent(abstract_self, val) - } - _ => Ok(()) - } - } - - // http://dom.spec.whatwg.org/#dom-node-textcontent - pub fn GetTextContent(&self, abstract_self: &JSRef) -> Option { - let roots = RootCollection::new(); - match self.type_id { - DocumentFragmentNodeTypeId | - ElementNodeTypeId(..) => { - let mut content = ~""; - for node in abstract_self.traverse_preorder(&roots) { - if node.is_text() { - let text: &JSRef = TextCast::to_ref(&node).unwrap(); - content.push_str(text.get().characterdata.data.as_slice()); - } - } - Some(content) - } - CommentNodeTypeId | - TextNodeTypeId | - ProcessingInstructionNodeTypeId => { - let characterdata: &JSRef = CharacterDataCast::to_ref(abstract_self).unwrap(); - Some(characterdata.get().Data()) - } - DoctypeNodeTypeId | - DocumentNodeTypeId => { - None - } - } - } - - // http://dom.spec.whatwg.org/#dom-node-textcontent - pub fn SetTextContent(&mut self, abstract_self: &mut JSRef, value: Option) - -> ErrorResult { - let roots = RootCollection::new(); - let value = null_str_as_empty(&value); - match self.type_id { - DocumentFragmentNodeTypeId | - ElementNodeTypeId(..) => { - // Step 1-2. - let node = if value.len() == 0 { - None - } else { - let document = self.owner_doc(); - let document = document.root(&roots); - Some(NodeCast::from_unrooted(document.deref().CreateTextNode(&*document, value))) - }.root(&roots); - - // Step 3. - Node::replace_all(node.root_ref(), abstract_self); - } - CommentNodeTypeId | - TextNodeTypeId | - ProcessingInstructionNodeTypeId => { - self.wait_until_safe_to_modify_dom(); - - let characterdata: &mut JSRef = CharacterDataCast::to_mut_ref(abstract_self).unwrap(); - characterdata.get_mut().data = value.clone(); - - // Notify the document that the content of this node is different - let document = self.owner_doc().root(&roots); - document.get().content_changed(); - } - DoctypeNodeTypeId | - DocumentNodeTypeId => {} - } - Ok(()) - } - // http://dom.spec.whatwg.org/#concept-node-adopt pub fn adopt(node: &mut JSRef, document: &JSRef) { let roots = RootCollection::new(); @@ -1505,26 +1306,334 @@ impl Node { Unrooted::new_rooted(&*copy) } + // + // Low-level pointer stitching + // + + pub fn set_parent_node(&mut self, new_parent_node: Option>) { + let roots = RootCollection::new(); + let doc = self.owner_doc().root(&roots); + doc.get().wait_until_safe_to_modify_dom(); + self.parent_node.assign(new_parent_node); + } + + pub fn set_first_child(&mut self, new_first_child: Option>) { + let roots = RootCollection::new(); + let doc = self.owner_doc().root(&roots); + doc.get().wait_until_safe_to_modify_dom(); + self.first_child.assign(new_first_child); + } + + pub fn set_last_child(&mut self, new_last_child: Option>) { + let roots = RootCollection::new(); + let doc = self.owner_doc().root(&roots); + doc.get().wait_until_safe_to_modify_dom(); + self.last_child.assign(new_last_child); + } + + pub fn set_prev_sibling(&mut self, new_prev_sibling: Option>) { + let roots = RootCollection::new(); + let doc = self.owner_doc().root(&roots); + doc.get().wait_until_safe_to_modify_dom(); + self.prev_sibling.assign(new_prev_sibling); + } + + pub fn set_next_sibling(&mut self, new_next_sibling: Option>) { + let roots = RootCollection::new(); + let doc = self.owner_doc().root(&roots); + doc.get().wait_until_safe_to_modify_dom(); + self.next_sibling.assign(new_next_sibling); + } + + pub fn get_hover_state(&self) -> bool { + self.flags.get_in_hover_state() + } + + pub fn set_hover_state(&mut self, state: bool) { + self.flags.set_is_in_hover_state(state); + } + + #[inline] + pub fn parent_node_ref<'a>(&'a self) -> Option<&'a JS> { + self.parent_node.as_ref() + } + + #[inline] + pub fn first_child_ref<'a>(&'a self) -> Option<&'a JS> { + self.first_child.as_ref() + } + + #[inline] + pub fn last_child_ref<'a>(&'a self) -> Option<&'a JS> { + self.last_child.as_ref() + } + + #[inline] + pub fn prev_sibling_ref<'a>(&'a self) -> Option<&'a JS> { + self.prev_sibling.as_ref() + } + + #[inline] + pub fn next_sibling_ref<'a>(&'a self) -> Option<&'a JS> { + self.next_sibling.as_ref() + } + + pub unsafe fn get_hover_state_for_layout(&self) -> bool { + let unsafe_this: *Node = cast::transmute::<&Node,*Node>(self); + (*unsafe_this).flags.get_in_hover_state() + } +} + +pub trait NodeMethods { + fn NodeType(&self) -> u16; + fn NodeName(&self, abstract_self: &JSRef) -> DOMString; + fn GetBaseURI(&self) -> Option; + fn GetOwnerDocument(&self) -> Option>; + fn GetParentNode(&self) -> Option>; + fn GetParentElement(&self) -> Option>; + fn HasChildNodes(&self) -> bool; + fn ChildNodes(&mut self, abstract_self: &JSRef) -> Unrooted; + fn GetFirstChild(&self) -> Option>; + fn GetLastChild(&self) -> Option>; + fn GetPreviousSibling(&self) -> Option>; + fn GetNextSibling(&self) -> Option>; + fn GetNodeValue(&self, abstract_self: &JSRef) -> Option; + fn SetNodeValue(&mut self, abstract_self: &mut JSRef, val: Option) -> ErrorResult; + fn GetTextContent(&self, abstract_self: &JSRef) -> Option; + fn SetTextContent(&mut self, abstract_self: &mut JSRef, value: Option) -> ErrorResult; + fn InsertBefore(&self, abstract_self: &mut JSRef, node: &mut JSRef, child: Option>) -> Fallible>; + fn AppendChild(&self, abstract_self: &mut JSRef, node: &mut JSRef) -> Fallible>; + fn ReplaceChild(&self, parent: &mut JSRef, node: &mut JSRef, child: &mut JSRef) -> Fallible>; + fn RemoveChild(&self, abstract_self: &mut JSRef, node: &mut JSRef) -> Fallible>; + fn Normalize(&mut self, abstract_self: &mut JSRef); + fn CloneNode(&self, abstract_self: &mut JSRef, deep: bool) -> Unrooted; + fn IsEqualNode(&self, abstract_self: &JSRef, maybe_node: Option>) -> bool; + fn CompareDocumentPosition(&self, abstract_self: &JSRef, other: &JSRef) -> u16; + fn Contains(&self, abstract_self: &JSRef, maybe_other: Option>) -> bool; + fn LookupPrefix(&self, _prefix: Option) -> Option; + fn LookupNamespaceURI(&self, _namespace: Option) -> Option; + fn IsDefaultNamespace(&self, _namespace: Option) -> bool; +} + +impl<'a> NodeMethods for JSRef<'a, Node> { + // http://dom.spec.whatwg.org/#dom-node-nodetype + fn NodeType(&self) -> u16 { + match self.type_id { + ElementNodeTypeId(_) => NodeConstants::ELEMENT_NODE, + TextNodeTypeId => NodeConstants::TEXT_NODE, + ProcessingInstructionNodeTypeId => NodeConstants::PROCESSING_INSTRUCTION_NODE, + CommentNodeTypeId => NodeConstants::COMMENT_NODE, + DocumentNodeTypeId => NodeConstants::DOCUMENT_NODE, + DoctypeNodeTypeId => NodeConstants::DOCUMENT_TYPE_NODE, + DocumentFragmentNodeTypeId => NodeConstants::DOCUMENT_FRAGMENT_NODE, + } + } + + // http://dom.spec.whatwg.org/#dom-node-nodename + fn NodeName(&self, abstract_self: &JSRef) -> DOMString { + match self.type_id { + ElementNodeTypeId(..) => { + let elem: &JSRef = ElementCast::to_ref(abstract_self).unwrap(); + elem.TagName() + } + TextNodeTypeId => ~"#text", + ProcessingInstructionNodeTypeId => { + let processing_instruction: &JSRef = + ProcessingInstructionCast::to_ref(abstract_self).unwrap(); + processing_instruction.Target() + } + CommentNodeTypeId => ~"#comment", + DoctypeNodeTypeId => { + let doctype: &JSRef = DocumentTypeCast::to_ref(abstract_self).unwrap(); + doctype.get().name.clone() + }, + DocumentFragmentNodeTypeId => ~"#document-fragment", + DocumentNodeTypeId => ~"#document" + } + } + + // http://dom.spec.whatwg.org/#dom-node-baseuri + fn GetBaseURI(&self) -> Option { + // FIXME (#1824) implement. + None + } + + // http://dom.spec.whatwg.org/#dom-node-ownerdocument + fn GetOwnerDocument(&self) -> Option> { + match self.type_id { + ElementNodeTypeId(..) | + CommentNodeTypeId | + TextNodeTypeId | + ProcessingInstructionNodeTypeId | + DoctypeNodeTypeId | + DocumentFragmentNodeTypeId => Some(self.owner_doc()), + DocumentNodeTypeId => None + } + } + + // http://dom.spec.whatwg.org/#dom-node-parentnode + fn GetParentNode(&self) -> Option> { + self.parent_node.clone().map(|node| Unrooted::new(node)) + } + + // http://dom.spec.whatwg.org/#dom-node-parentelement + fn GetParentElement(&self) -> Option> { + let roots = RootCollection::new(); + self.parent_node.clone() + .and_then(|parent| { + let parent = parent.root(&roots); + ElementCast::to_ref(&*parent).map(|elem| { + Unrooted::new_rooted(elem) + }) + }) + } + + // http://dom.spec.whatwg.org/#dom-node-haschildnodes + fn HasChildNodes(&self) -> bool { + self.first_child.is_some() + } + + // http://dom.spec.whatwg.org/#dom-node-childnodes + fn ChildNodes(&mut self, abstract_self: &JSRef) -> Unrooted { + let roots = RootCollection::new(); + match self.child_list { + None => (), + Some(ref list) => return Unrooted::new(list.clone()), + } + + let doc = self.deref().owner_doc().root(&roots); + let window = doc.deref().window.root(&roots); + self.child_list.assign(Some(NodeList::new_child_list(&*window, abstract_self))); + Unrooted::new(self.child_list.get_ref().clone()) + } + + // http://dom.spec.whatwg.org/#dom-node-firstchild + fn GetFirstChild(&self) -> Option> { + self.first_child.clone().map(|node| Unrooted::new(node)) + } + + // http://dom.spec.whatwg.org/#dom-node-lastchild + fn GetLastChild(&self) -> Option> { + self.last_child.clone().map(|node| Unrooted::new(node)) + } + + // http://dom.spec.whatwg.org/#dom-node-previoussibling + fn GetPreviousSibling(&self) -> Option> { + self.prev_sibling.clone().map(|node| Unrooted::new(node)) + } + + // http://dom.spec.whatwg.org/#dom-node-nextsibling + fn GetNextSibling(&self) -> Option> { + self.next_sibling.clone().map(|node| Unrooted::new(node)) + } + + // http://dom.spec.whatwg.org/#dom-node-nodevalue + fn GetNodeValue(&self, abstract_self: &JSRef) -> Option { + match self.type_id { + CommentNodeTypeId | + TextNodeTypeId | + ProcessingInstructionNodeTypeId => { + let chardata: &JSRef = CharacterDataCast::to_ref(abstract_self).unwrap(); + Some(chardata.Data()) + } + _ => { + None + } + } + } + + // http://dom.spec.whatwg.org/#dom-node-nodevalue + fn SetNodeValue(&mut self, abstract_self: &mut JSRef, val: Option) + -> ErrorResult { + match self.type_id { + CommentNodeTypeId | + TextNodeTypeId | + ProcessingInstructionNodeTypeId => { + self.SetTextContent(abstract_self, val) + } + _ => Ok(()) + } + } + + // http://dom.spec.whatwg.org/#dom-node-textcontent + fn GetTextContent(&self, abstract_self: &JSRef) -> Option { + let roots = RootCollection::new(); + match self.type_id { + DocumentFragmentNodeTypeId | + ElementNodeTypeId(..) => { + let mut content = ~""; + for node in abstract_self.traverse_preorder(&roots) { + if node.is_text() { + let text: &JSRef = TextCast::to_ref(&node).unwrap(); + content.push_str(text.get().characterdata.data.as_slice()); + } + } + Some(content) + } + CommentNodeTypeId | + TextNodeTypeId | + ProcessingInstructionNodeTypeId => { + let characterdata: &JSRef = CharacterDataCast::to_ref(abstract_self).unwrap(); + Some(characterdata.Data()) + } + DoctypeNodeTypeId | + DocumentNodeTypeId => { + None + } + } + } + + // http://dom.spec.whatwg.org/#dom-node-textcontent + fn SetTextContent(&mut self, abstract_self: &mut JSRef, value: Option) + -> ErrorResult { + let roots = RootCollection::new(); + let value = null_str_as_empty(&value); + match self.type_id { + DocumentFragmentNodeTypeId | + ElementNodeTypeId(..) => { + // Step 1-2. + let node = if value.len() == 0 { + None + } else { + let document = self.owner_doc().root(&roots); + Some(NodeCast::from_unrooted(document.deref().CreateTextNode(&*document, value))) + }.root(&roots); + + // Step 3. + Node::replace_all(node.root_ref(), abstract_self); + } + CommentNodeTypeId | + TextNodeTypeId | + ProcessingInstructionNodeTypeId => { + self.wait_until_safe_to_modify_dom(); + + let characterdata: &mut JSRef = CharacterDataCast::to_mut_ref(abstract_self).unwrap(); + characterdata.get_mut().data = value.clone(); + + // Notify the document that the content of this node is different + let document = self.owner_doc().root(&roots); + document.get().content_changed(); + } + DoctypeNodeTypeId | + DocumentNodeTypeId => {} + } + Ok(()) + } + // http://dom.spec.whatwg.org/#dom-node-insertbefore - pub fn InsertBefore(&self, abstract_self: &mut JSRef, node: &mut JSRef, child: Option>) + fn InsertBefore(&self, abstract_self: &mut JSRef, node: &mut JSRef, child: Option>) -> Fallible> { Node::pre_insert(node, abstract_self, child) } - pub fn wait_until_safe_to_modify_dom(&self) { - let roots = RootCollection::new(); - let document = self.owner_doc().root(&roots); - document.get().wait_until_safe_to_modify_dom(); - } - // http://dom.spec.whatwg.org/#dom-node-appendchild - pub fn AppendChild(&self, abstract_self: &mut JSRef, node: &mut JSRef) + fn AppendChild(&self, abstract_self: &mut JSRef, node: &mut JSRef) -> Fallible> { Node::pre_insert(node, abstract_self, None) } // http://dom.spec.whatwg.org/#concept-node-replace - pub fn ReplaceChild(&self, parent: &mut JSRef, node: &mut JSRef, child: &mut JSRef) + fn ReplaceChild(&self, parent: &mut JSRef, node: &mut JSRef, child: &mut JSRef) -> Fallible> { let roots = RootCollection::new(); @@ -1655,26 +1764,26 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-removechild - pub fn RemoveChild(&self, abstract_self: &mut JSRef, node: &mut JSRef) + fn RemoveChild(&self, abstract_self: &mut JSRef, node: &mut JSRef) -> Fallible> { Node::pre_remove(node, abstract_self) } // http://dom.spec.whatwg.org/#dom-node-normalize - pub fn Normalize(&mut self, abstract_self: &mut JSRef) { + fn Normalize(&mut self, abstract_self: &mut JSRef) { let roots = RootCollection::new(); let mut prev_text = None; for mut child in self.children() { if child.is_text() { let mut child_alias = child.clone(); let characterdata: &JSRef = CharacterDataCast::to_ref(&child).unwrap(); - if characterdata.get().Length() == 0 { + if characterdata.Length() == 0 { abstract_self.remove_child(&mut child_alias); } else { match prev_text { Some(ref mut text_node) => { let prev_characterdata: &mut JSRef = CharacterDataCast::to_mut_ref(text_node).unwrap(); - let _ = prev_characterdata.get_mut().AppendData(characterdata.get().Data()); + let _ = prev_characterdata.AppendData(characterdata.Data()); abstract_self.remove_child(&mut child_alias); }, None => prev_text = Some(child_alias) @@ -1682,7 +1791,7 @@ impl Node { } } else { let mut c = child.clone(); - child.get_mut().Normalize(&mut c); + child.Normalize(&mut c); prev_text = None; } @@ -1690,7 +1799,7 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-clonenode - pub fn CloneNode(&self, abstract_self: &mut JSRef, deep: bool) -> Unrooted { + fn CloneNode(&self, abstract_self: &mut JSRef, deep: bool) -> Unrooted { match deep { true => Node::clone(abstract_self, None, CloneChildren), false => Node::clone(abstract_self, None, DoNotCloneChildren) @@ -1698,7 +1807,7 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-isequalnode - pub fn IsEqualNode(&self, abstract_self: &JSRef, maybe_node: Option>) -> bool { + fn IsEqualNode(&self, abstract_self: &JSRef, maybe_node: Option>) -> bool { fn is_equal_doctype(node: &JSRef, other: &JSRef) -> bool { let doctype: &JSRef = DocumentTypeCast::to_ref(node).unwrap(); let other_doctype: &JSRef = DocumentTypeCast::to_ref(other).unwrap(); @@ -1775,7 +1884,7 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-comparedocumentposition - pub fn CompareDocumentPosition(&self, abstract_self: &JSRef, other: &JSRef) -> u16 { + fn CompareDocumentPosition(&self, abstract_self: &JSRef, other: &JSRef) -> u16 { let roots = RootCollection::new(); if abstract_self == other { // step 2. @@ -1830,7 +1939,7 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-contains - pub fn Contains(&self, abstract_self: &JSRef, maybe_other: Option>) -> bool { + fn Contains(&self, abstract_self: &JSRef, maybe_other: Option>) -> bool { match maybe_other { None => false, Some(ref other) => abstract_self.is_inclusive_ancestor_of(other) @@ -1838,100 +1947,25 @@ impl Node { } // http://dom.spec.whatwg.org/#dom-node-lookupprefix - pub fn LookupPrefix(&self, _prefix: Option) -> Option { + fn LookupPrefix(&self, _prefix: Option) -> Option { // FIXME (#1826) implement. None } // http://dom.spec.whatwg.org/#dom-node-lookupnamespaceuri - pub fn LookupNamespaceURI(&self, _namespace: Option) -> Option { + fn LookupNamespaceURI(&self, _namespace: Option) -> Option { // FIXME (#1826) implement. None } // http://dom.spec.whatwg.org/#dom-node-isdefaultnamespace - pub fn IsDefaultNamespace(&self, _namespace: Option) -> bool { + fn IsDefaultNamespace(&self, _namespace: Option) -> bool { // FIXME (#1826) implement. false } - - // - // Low-level pointer stitching - // - - pub fn set_parent_node(&mut self, new_parent_node: Option>) { - let roots = RootCollection::new(); - let doc = self.owner_doc().root(&roots); - doc.get().wait_until_safe_to_modify_dom(); - self.parent_node.assign(new_parent_node); - } - - pub fn set_first_child(&mut self, new_first_child: Option>) { - let roots = RootCollection::new(); - let doc = self.owner_doc().root(&roots); - doc.get().wait_until_safe_to_modify_dom(); - self.first_child.assign(new_first_child); - } - - pub fn set_last_child(&mut self, new_last_child: Option>) { - let roots = RootCollection::new(); - let doc = self.owner_doc().root(&roots); - doc.get().wait_until_safe_to_modify_dom(); - self.last_child.assign(new_last_child); - } - - pub fn set_prev_sibling(&mut self, new_prev_sibling: Option>) { - let roots = RootCollection::new(); - let doc = self.owner_doc().root(&roots); - doc.get().wait_until_safe_to_modify_dom(); - self.prev_sibling.assign(new_prev_sibling); - } - - pub fn set_next_sibling(&mut self, new_next_sibling: Option>) { - let roots = RootCollection::new(); - let doc = self.owner_doc().root(&roots); - doc.get().wait_until_safe_to_modify_dom(); - self.next_sibling.assign(new_next_sibling); - } - - pub fn get_hover_state(&self) -> bool { - self.flags.get_in_hover_state() - } - - pub fn set_hover_state(&mut self, state: bool) { - self.flags.set_is_in_hover_state(state); - } - - #[inline] - pub fn parent_node_ref<'a>(&'a self) -> Option<&'a JS> { - self.parent_node.as_ref() - } - - #[inline] - pub fn first_child_ref<'a>(&'a self) -> Option<&'a JS> { - self.first_child.as_ref() - } - - #[inline] - pub fn last_child_ref<'a>(&'a self) -> Option<&'a JS> { - self.last_child.as_ref() - } - - #[inline] - pub fn prev_sibling_ref<'a>(&'a self) -> Option<&'a JS> { - self.prev_sibling.as_ref() - } - - #[inline] - pub fn next_sibling_ref<'a>(&'a self) -> Option<&'a JS> { - self.next_sibling.as_ref() - } - - pub unsafe fn get_hover_state_for_layout(&self) -> bool { - self.flags.get_in_hover_state() - } } + impl Reflectable for Node { fn reflector<'a>(&'a self) -> &'a Reflector { self.eventtarget.reflector() diff --git a/src/components/script/dom/nodelist.rs b/src/components/script/dom/nodelist.rs index 219731034f1..a874a068b65 100644 --- a/src/components/script/dom/nodelist.rs +++ b/src/components/script/dom/nodelist.rs @@ -44,8 +44,16 @@ impl NodeList { pub fn new_child_list(window: &JSRef, node: &JSRef) -> Unrooted { NodeList::new(window, Children(node.unrooted())) } +} - pub fn Length(&self) -> u32 { +pub trait NodeListMethods { + fn Length(&self) -> u32; + fn Item(&self, index: u32) -> Option>; + fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option>; +} + +impl<'a> NodeListMethods for JSRef<'a, NodeList> { + fn Length(&self) -> u32 { let roots = RootCollection::new(); match self.list_type { Simple(ref elems) => elems.len() as u32, @@ -56,7 +64,7 @@ impl NodeList { } } - pub fn Item(&self, index: u32) -> Option> { + fn Item(&self, index: u32) -> Option> { let roots = RootCollection::new(); match self.list_type { _ if index >= self.Length() => None, @@ -69,7 +77,7 @@ impl NodeList { } } - pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { + fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { let item = self.Item(index); *found = item.is_some(); item diff --git a/src/components/script/dom/processinginstruction.rs b/src/components/script/dom/processinginstruction.rs index c094e4ae654..ee88cb51bf6 100644 --- a/src/components/script/dom/processinginstruction.rs +++ b/src/components/script/dom/processinginstruction.rs @@ -41,8 +41,13 @@ impl ProcessingInstruction { } } -impl ProcessingInstruction { - pub fn Target(&self) -> DOMString { +pub trait ProcessingInstructionMethods { + fn Target(&self) -> DOMString; +} + +impl<'a> ProcessingInstructionMethods for JSRef<'a, ProcessingInstruction> { + fn Target(&self) -> DOMString { self.target.clone() } } + diff --git a/src/components/script/dom/testbinding.rs b/src/components/script/dom/testbinding.rs index 76bb587b134..3ad4f8fa202 100644 --- a/src/components/script/dom/testbinding.rs +++ b/src/components/script/dom/testbinding.rs @@ -22,192 +22,372 @@ pub struct TestBinding { pub window: JS, } -impl TestBinding { - pub fn BooleanAttribute(&self) -> bool { false } - pub fn SetBooleanAttribute(&self, _: bool) {} - pub fn ByteAttribute(&self) -> i8 { 0 } - pub fn SetByteAttribute(&self, _: i8) {} - pub fn OctetAttribute(&self) -> u8 { 0 } - pub fn SetOctetAttribute(&self, _: u8) {} - pub fn ShortAttribute(&self) -> i16 { 0 } - pub fn SetShortAttribute(&self, _: i16) {} - pub fn UnsignedShortAttribute(&self) -> u16 { 0 } - pub fn SetUnsignedShortAttribute(&self, _: u16) {} - pub fn LongAttribute(&self) -> i32 { 0 } - pub fn SetLongAttribute(&self, _: i32) {} - pub fn UnsignedLongAttribute(&self) -> u32 { 0 } - pub fn SetUnsignedLongAttribute(&self, _: u32) {} - pub fn LongLongAttribute(&self) -> i64 { 0 } - pub fn SetLongLongAttribute(&self, _: i64) {} - pub fn UnsignedLongLongAttribute(&self) -> u64 { 0 } - pub fn SetUnsignedLongLongAttribute(&self, _: u64) {} - pub fn FloatAttribute(&self) -> f32 { 0. } - pub fn SetFloatAttribute(&self, _: f32) {} - pub fn DoubleAttribute(&self) -> f64 { 0. } - pub fn SetDoubleAttribute(&self, _: f64) {} - pub fn StringAttribute(&self) -> DOMString { ~"" } - pub fn SetStringAttribute(&self, _: DOMString) {} - pub fn ByteStringAttribute(&self) -> ByteString { ByteString::new(vec!()) } - pub fn SetByteStringAttribute(&self, _: ByteString) {} - pub fn EnumAttribute(&self) -> TestEnum { _empty } - pub fn SetEnumAttribute(&self, _: TestEnum) {} - pub fn InterfaceAttribute(&self) -> Unrooted { +pub trait TestBindingMethods { + fn BooleanAttribute(&self) -> bool; + fn SetBooleanAttribute(&self, _: bool); + fn ByteAttribute(&self) -> i8; + fn SetByteAttribute(&self, _: i8); + fn OctetAttribute(&self) -> u8; + fn SetOctetAttribute(&self, _: u8); + fn ShortAttribute(&self) -> i16; + fn SetShortAttribute(&self, _: i16); + fn UnsignedShortAttribute(&self) -> u16; + fn SetUnsignedShortAttribute(&self, _: u16); + fn LongAttribute(&self) -> i32; + fn SetLongAttribute(&self, _: i32); + fn UnsignedLongAttribute(&self) -> u32; + fn SetUnsignedLongAttribute(&self, _: u32); + fn LongLongAttribute(&self) -> i64; + fn SetLongLongAttribute(&self, _: i64); + fn UnsignedLongLongAttribute(&self) -> u64; + fn SetUnsignedLongLongAttribute(&self, _: u64); + fn FloatAttribute(&self) -> f32; + fn SetFloatAttribute(&self, _: f32); + fn DoubleAttribute(&self) -> f64; + fn SetDoubleAttribute(&self, _: f64); + fn StringAttribute(&self) -> DOMString; + fn SetStringAttribute(&self, _: DOMString); + fn ByteStringAttribute(&self) -> ByteString; + fn SetByteStringAttribute(&self, _: ByteString); + fn EnumAttribute(&self) -> TestEnum; + fn SetEnumAttribute(&self, _: TestEnum); + fn InterfaceAttribute(&self) -> Unrooted; + fn SetInterfaceAttribute(&self, _: &JSRef); + fn AnyAttribute(&self, _: *JSContext) -> JSVal; + fn SetAnyAttribute(&self, _: *JSContext, _: JSVal); + + fn GetBooleanAttributeNullable(&self) -> Option; + fn SetBooleanAttributeNullable(&self, _: Option); + fn GetByteAttributeNullable(&self) -> Option; + fn SetByteAttributeNullable(&self, _: Option); + fn GetOctetAttributeNullable(&self) -> Option; + fn SetOctetAttributeNullable(&self, _: Option); + fn GetShortAttributeNullable(&self) -> Option; + fn SetShortAttributeNullable(&self, _: Option); + fn GetUnsignedShortAttributeNullable(&self) -> Option; + fn SetUnsignedShortAttributeNullable(&self, _: Option); + fn GetLongAttributeNullable(&self) -> Option; + fn SetLongAttributeNullable(&self, _: Option); + fn GetUnsignedLongAttributeNullable(&self) -> Option; + fn SetUnsignedLongAttributeNullable(&self, _: Option); + fn GetLongLongAttributeNullable(&self) -> Option; + fn SetLongLongAttributeNullable(&self, _: Option); + fn GetUnsignedLongLongAttributeNullable(&self) -> Option; + fn SetUnsignedLongLongAttributeNullable(&self, _: Option); + fn GetFloatAttributeNullable(&self) -> Option; + fn SetFloatAttributeNullable(&self, _: Option); + fn GetDoubleAttributeNullable(&self) -> Option; + fn SetDoubleAttributeNullable(&self, _: Option); + fn GetByteStringAttributeNullable(&self) -> Option; + fn SetByteStringAttributeNullable(&self, _: Option); + fn GetStringAttributeNullable(&self) -> Option; + fn SetStringAttributeNullable(&self, _: Option); + fn GetEnumAttributeNullable(&self) -> Option; + fn GetInterfaceAttributeNullable(&self) -> Option>; + fn SetInterfaceAttributeNullable(&self, _: Option>); + + fn PassBoolean(&self, _: bool); + fn PassByte(&self, _: i8); + fn PassOctet(&self, _: u8); + fn PassShort(&self, _: i16); + fn PassUnsignedShort(&self, _: u16); + fn PassLong(&self, _: i32); + fn PassUnsignedLong(&self, _: u32); + fn PassLongLong(&self, _: i64); + fn PassUnsignedLongLong(&self, _: u64); + fn PassFloat(&self, _: f32); + fn PassDouble(&self, _: f64); + fn PassString(&self, _: DOMString); + fn PassByteString(&self, _: ByteString); + fn PassEnum(&self, _: TestEnum); + fn PassInterface(&self, _: &JSRef); + fn PassUnion(&self, _: HTMLElementOrLong); + fn PassAny(&self, _: *JSContext, _: JSVal); + + fn PassNullableBoolean(&self, _: Option); + fn PassNullableByte(&self, _: Option); + fn PassNullableOctet(&self, _: Option); + fn PassNullableShort(&self, _: Option); + fn PassNullableUnsignedShort(&self, _: Option); + fn PassNullableLong(&self, _: Option); + fn PassNullableUnsignedLong(&self, _: Option); + fn PassNullableLongLong(&self, _: Option); + fn PassNullableUnsignedLongLong(&self, _: Option); + fn PassNullableFloat(&self, _: Option); + fn PassNullableDouble(&self, _: Option); + fn PassNullableString(&self, _: Option); + fn PassNullableByteString(&self, _: Option) {} + // fn PassNullableEnum(&self, _: Option); + fn PassNullableInterface(&self, _: Option>); + fn PassNullableUnion(&self, _: Option); + fn PassNullableAny(&self, _: *JSContext, _: Option); + + fn PassOptionalBoolean(&self, _: Option); + fn PassOptionalByte(&self, _: Option); + fn PassOptionalOctet(&self, _: Option); + fn PassOptionalShort(&self, _: Option); + fn PassOptionalUnsignedShort(&self, _: Option); + fn PassOptionalLong(&self, _: Option); + fn PassOptionalUnsignedLong(&self, _: Option); + fn PassOptionalLongLong(&self, _: Option); + fn PassOptionalUnsignedLongLong(&self, _: Option); + fn PassOptionalFloat(&self, _: Option); + fn PassOptionalDouble(&self, _: Option); + fn PassOptionalString(&self, _: Option); + fn PassOptionalByteString(&self, _: Option) {} + fn PassOptionalEnum(&self, _: Option); + fn PassOptionalInterface(&self, _: Option>); + fn PassOptionalUnion(&self, _: Option); + fn PassOptionalAny(&self, _: *JSContext, _: Option); + + fn PassOptionalNullableBoolean(&self, _: Option>); + fn PassOptionalNullableByte(&self, _: Option>); + fn PassOptionalNullableOctet(&self, _: Option>); + fn PassOptionalNullableShort(&self, _: Option>); + fn PassOptionalNullableUnsignedShort(&self, _: Option>); + fn PassOptionalNullableLong(&self, _: Option>); + fn PassOptionalNullableUnsignedLong(&self, _: Option>); + fn PassOptionalNullableLongLong(&self, _: Option>); + fn PassOptionalNullableUnsignedLongLong(&self, _: Option>); + fn PassOptionalNullableFloat(&self, _: Option>); + fn PassOptionalNullableDouble(&self, _: Option>); + fn PassOptionalNullableString(&self, _: Option>); + fn PassOptionalNullableByteString(&self, _: Option>) {} + // fn PassOptionalNullableEnum(&self, _: Option>); + fn PassOptionalNullableInterface(&self, _: Option>>); + fn PassOptionalNullableUnion(&self, _: Option>); + + fn PassOptionalBooleanWithDefault(&self, _: bool); + fn PassOptionalByteWithDefault(&self, _: i8); + fn PassOptionalOctetWithDefault(&self, _: u8); + fn PassOptionalShortWithDefault(&self, _: i16); + fn PassOptionalUnsignedShortWithDefault(&self, _: u16); + fn PassOptionalLongWithDefault(&self, _: i32); + fn PassOptionalUnsignedLongWithDefault(&self, _: u32); + fn PassOptionalLongLongWithDefault(&self, _: i64); + fn PassOptionalUnsignedLongLongWithDefault(&self, _: u64); + fn PassOptionalStringWithDefault(&self, _: DOMString); + fn PassOptionalEnumWithDefault(&self, _: TestEnum); + + fn PassOptionalNullableBooleanWithDefault(&self, _: Option); + fn PassOptionalNullableByteWithDefault(&self, _: Option); + fn PassOptionalNullableOctetWithDefault(&self, _: Option); + fn PassOptionalNullableShortWithDefault(&self, _: Option); + fn PassOptionalNullableUnsignedShortWithDefault(&self, _: Option); + fn PassOptionalNullableLongWithDefault(&self, _: Option); + fn PassOptionalNullableUnsignedLongWithDefault(&self, _: Option); + fn PassOptionalNullableLongLongWithDefault(&self, _: Option); + fn PassOptionalNullableUnsignedLongLongWithDefault(&self, _: Option); + fn PassOptionalNullableFloatWithDefault(&self, _: Option); + fn PassOptionalNullableDoubleWithDefault(&self, _: Option); + fn PassOptionalNullableStringWithDefault(&self, _: Option); + fn PassOptionalNullableByteStringWithDefault(&self, _: Option) {} + // fn PassOptionalNullableEnumWithDefault(&self, _: Option); + fn PassOptionalNullableInterfaceWithDefault(&self, _: Option>); + fn PassOptionalNullableUnionWithDefault(&self, _: Option); + fn PassOptionalAnyWithDefault(&self, _: *JSContext, _: JSVal); + + fn PassOptionalNullableBooleanWithNonNullDefault(&self, _: Option); + fn PassOptionalNullableByteWithNonNullDefault(&self, _: Option); + fn PassOptionalNullableOctetWithNonNullDefault(&self, _: Option); + fn PassOptionalNullableShortWithNonNullDefault(&self, _: Option); + fn PassOptionalNullableUnsignedShortWithNonNullDefault(&self, _: Option); + fn PassOptionalNullableLongWithNonNullDefault(&self, _: Option); + fn PassOptionalNullableUnsignedLongWithNonNullDefault(&self, _: Option); + fn PassOptionalNullableLongLongWithNonNullDefault(&self, _: Option); + fn PassOptionalNullableUnsignedLongLongWithNonNullDefault(&self, _: Option); + // fn PassOptionalNullableFloatWithNonNullDefault(&self, _: Option); + // fn PassOptionalNullableDoubleWithNonNullDefault(&self, _: Option); + fn PassOptionalNullableStringWithNonNullDefault(&self, _: Option); + // fn PassOptionalNullableEnumWithNonNullDefault(&self, _: Option); +} + +impl<'a> TestBindingMethods for JSRef<'a, TestBinding> { + fn BooleanAttribute(&self) -> bool { false } + fn SetBooleanAttribute(&self, _: bool) {} + fn ByteAttribute(&self) -> i8 { 0 } + fn SetByteAttribute(&self, _: i8) {} + fn OctetAttribute(&self) -> u8 { 0 } + fn SetOctetAttribute(&self, _: u8) {} + fn ShortAttribute(&self) -> i16 { 0 } + fn SetShortAttribute(&self, _: i16) {} + fn UnsignedShortAttribute(&self) -> u16 { 0 } + fn SetUnsignedShortAttribute(&self, _: u16) {} + fn LongAttribute(&self) -> i32 { 0 } + fn SetLongAttribute(&self, _: i32) {} + fn UnsignedLongAttribute(&self) -> u32 { 0 } + fn SetUnsignedLongAttribute(&self, _: u32) {} + fn LongLongAttribute(&self) -> i64 { 0 } + fn SetLongLongAttribute(&self, _: i64) {} + fn UnsignedLongLongAttribute(&self) -> u64 { 0 } + fn SetUnsignedLongLongAttribute(&self, _: u64) {} + fn FloatAttribute(&self) -> f32 { 0. } + fn SetFloatAttribute(&self, _: f32) {} + fn DoubleAttribute(&self) -> f64 { 0. } + fn SetDoubleAttribute(&self, _: f64) {} + fn StringAttribute(&self) -> DOMString { ~"" } + fn SetStringAttribute(&self, _: DOMString) {} + fn ByteStringAttribute(&self) -> ByteString { ByteString::new(vec!()) } + fn SetByteStringAttribute(&self, _: ByteString) {} + fn EnumAttribute(&self) -> TestEnum { _empty } + fn SetEnumAttribute(&self, _: TestEnum) {} + fn InterfaceAttribute(&self) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); Blob::new(&*window) } - pub fn SetInterfaceAttribute(&self, _: &JSRef) {} - pub fn AnyAttribute(&self, _: *JSContext) -> JSVal { NullValue() } - pub fn SetAnyAttribute(&self, _: *JSContext, _: JSVal) {} + fn SetInterfaceAttribute(&self, _: &JSRef) {} + fn AnyAttribute(&self, _: *JSContext) -> JSVal { NullValue() } + fn SetAnyAttribute(&self, _: *JSContext, _: JSVal) {} - pub fn GetBooleanAttributeNullable(&self) -> Option { Some(false) } - pub fn SetBooleanAttributeNullable(&self, _: Option) {} - pub fn GetByteAttributeNullable(&self) -> Option { Some(0) } - pub fn SetByteAttributeNullable(&self, _: Option) {} - pub fn GetOctetAttributeNullable(&self) -> Option { Some(0) } - pub fn SetOctetAttributeNullable(&self, _: Option) {} - pub fn GetShortAttributeNullable(&self) -> Option { Some(0) } - pub fn SetShortAttributeNullable(&self, _: Option) {} - pub fn GetUnsignedShortAttributeNullable(&self) -> Option { Some(0) } - pub fn SetUnsignedShortAttributeNullable(&self, _: Option) {} - pub fn GetLongAttributeNullable(&self) -> Option { Some(0) } - pub fn SetLongAttributeNullable(&self, _: Option) {} - pub fn GetUnsignedLongAttributeNullable(&self) -> Option { Some(0) } - pub fn SetUnsignedLongAttributeNullable(&self, _: Option) {} - pub fn GetLongLongAttributeNullable(&self) -> Option { Some(0) } - pub fn SetLongLongAttributeNullable(&self, _: Option) {} - pub fn GetUnsignedLongLongAttributeNullable(&self) -> Option { Some(0) } - pub fn SetUnsignedLongLongAttributeNullable(&self, _: Option) {} - pub fn GetFloatAttributeNullable(&self) -> Option { Some(0.) } - pub fn SetFloatAttributeNullable(&self, _: Option) {} - pub fn GetDoubleAttributeNullable(&self) -> Option { Some(0.) } - pub fn SetDoubleAttributeNullable(&self, _: Option) {} - pub fn GetByteStringAttributeNullable(&self) -> Option { Some(ByteString::new(vec!())) } - pub fn SetByteStringAttributeNullable(&self, _: Option) {} - pub fn GetStringAttributeNullable(&self) -> Option { Some(~"") } - pub fn SetStringAttributeNullable(&self, _: Option) {} - pub fn GetEnumAttributeNullable(&self) -> Option { Some(_empty) } - pub fn GetInterfaceAttributeNullable(&self) -> Option> { + fn GetBooleanAttributeNullable(&self) -> Option { Some(false) } + fn SetBooleanAttributeNullable(&self, _: Option) {} + fn GetByteAttributeNullable(&self) -> Option { Some(0) } + fn SetByteAttributeNullable(&self, _: Option) {} + fn GetOctetAttributeNullable(&self) -> Option { Some(0) } + fn SetOctetAttributeNullable(&self, _: Option) {} + fn GetShortAttributeNullable(&self) -> Option { Some(0) } + fn SetShortAttributeNullable(&self, _: Option) {} + fn GetUnsignedShortAttributeNullable(&self) -> Option { Some(0) } + fn SetUnsignedShortAttributeNullable(&self, _: Option) {} + fn GetLongAttributeNullable(&self) -> Option { Some(0) } + fn SetLongAttributeNullable(&self, _: Option) {} + fn GetUnsignedLongAttributeNullable(&self) -> Option { Some(0) } + fn SetUnsignedLongAttributeNullable(&self, _: Option) {} + fn GetLongLongAttributeNullable(&self) -> Option { Some(0) } + fn SetLongLongAttributeNullable(&self, _: Option) {} + fn GetUnsignedLongLongAttributeNullable(&self) -> Option { Some(0) } + fn SetUnsignedLongLongAttributeNullable(&self, _: Option) {} + fn GetFloatAttributeNullable(&self) -> Option { Some(0.) } + fn SetFloatAttributeNullable(&self, _: Option) {} + fn GetDoubleAttributeNullable(&self) -> Option { Some(0.) } + fn SetDoubleAttributeNullable(&self, _: Option) {} + fn GetByteStringAttributeNullable(&self) -> Option { Some(ByteString::new(vec!())) } + fn SetByteStringAttributeNullable(&self, _: Option) {} + fn GetStringAttributeNullable(&self) -> Option { Some(~"") } + fn SetStringAttributeNullable(&self, _: Option) {} + fn GetEnumAttributeNullable(&self) -> Option { Some(_empty) } + fn GetInterfaceAttributeNullable(&self) -> Option> { let roots = RootCollection::new(); let window = self.window.root(&roots); Some(Blob::new(&(*window))) } - pub fn SetInterfaceAttributeNullable(&self, _: Option>) {} + fn SetInterfaceAttributeNullable(&self, _: Option>) {} - pub fn PassBoolean(&self, _: bool) {} - pub fn PassByte(&self, _: i8) {} - pub fn PassOctet(&self, _: u8) {} - pub fn PassShort(&self, _: i16) {} - pub fn PassUnsignedShort(&self, _: u16) {} - pub fn PassLong(&self, _: i32) {} - pub fn PassUnsignedLong(&self, _: u32) {} - pub fn PassLongLong(&self, _: i64) {} - pub fn PassUnsignedLongLong(&self, _: u64) {} - pub fn PassFloat(&self, _: f32) {} - pub fn PassDouble(&self, _: f64) {} - pub fn PassString(&self, _: DOMString) {} - pub fn PassByteString(&self, _: ByteString) {} - pub fn PassEnum(&self, _: TestEnum) {} - pub fn PassInterface(&self, _: &JSRef) {} - pub fn PassUnion(&self, _: HTMLElementOrLong) {} - pub fn PassAny(&self, _: *JSContext, _: JSVal) {} + fn PassBoolean(&self, _: bool) {} + fn PassByte(&self, _: i8) {} + fn PassOctet(&self, _: u8) {} + fn PassShort(&self, _: i16) {} + fn PassUnsignedShort(&self, _: u16) {} + fn PassLong(&self, _: i32) {} + fn PassUnsignedLong(&self, _: u32) {} + fn PassLongLong(&self, _: i64) {} + fn PassUnsignedLongLong(&self, _: u64) {} + fn PassFloat(&self, _: f32) {} + fn PassDouble(&self, _: f64) {} + fn PassString(&self, _: DOMString) {} + fn PassByteString(&self, _: ByteString) {} + fn PassEnum(&self, _: TestEnum) {} + fn PassInterface(&self, _: &JSRef) {} + fn PassUnion(&self, _: HTMLElementOrLong) {} + fn PassAny(&self, _: *JSContext, _: JSVal) {} - pub fn PassNullableBoolean(&self, _: Option) {} - pub fn PassNullableByte(&self, _: Option) {} - pub fn PassNullableOctet(&self, _: Option) {} - pub fn PassNullableShort(&self, _: Option) {} - pub fn PassNullableUnsignedShort(&self, _: Option) {} - pub fn PassNullableLong(&self, _: Option) {} - pub fn PassNullableUnsignedLong(&self, _: Option) {} - pub fn PassNullableLongLong(&self, _: Option) {} - pub fn PassNullableUnsignedLongLong(&self, _: Option) {} - pub fn PassNullableFloat(&self, _: Option) {} - pub fn PassNullableDouble(&self, _: Option) {} - pub fn PassNullableString(&self, _: Option) {} - pub fn PassNullableByteString(&self, _: Option) {} - // pub fn PassNullableEnum(&self, _: Option) {} - pub fn PassNullableInterface(&self, _: Option>) {} - pub fn PassNullableUnion(&self, _: Option) {} - pub fn PassNullableAny(&self, _: *JSContext, _: Option) {} + fn PassNullableBoolean(&self, _: Option) {} + fn PassNullableByte(&self, _: Option) {} + fn PassNullableOctet(&self, _: Option) {} + fn PassNullableShort(&self, _: Option) {} + fn PassNullableUnsignedShort(&self, _: Option) {} + fn PassNullableLong(&self, _: Option) {} + fn PassNullableUnsignedLong(&self, _: Option) {} + fn PassNullableLongLong(&self, _: Option) {} + fn PassNullableUnsignedLongLong(&self, _: Option) {} + fn PassNullableFloat(&self, _: Option) {} + fn PassNullableDouble(&self, _: Option) {} + fn PassNullableString(&self, _: Option) {} + fn PassNullableByteString(&self, _: Option) {} + // fn PassNullableEnum(&self, _: Option) {} + fn PassNullableInterface(&self, _: Option>) {} + fn PassNullableUnion(&self, _: Option) {} + fn PassNullableAny(&self, _: *JSContext, _: Option) {} - pub fn PassOptionalBoolean(&self, _: Option) {} - pub fn PassOptionalByte(&self, _: Option) {} - pub fn PassOptionalOctet(&self, _: Option) {} - pub fn PassOptionalShort(&self, _: Option) {} - pub fn PassOptionalUnsignedShort(&self, _: Option) {} - pub fn PassOptionalLong(&self, _: Option) {} - pub fn PassOptionalUnsignedLong(&self, _: Option) {} - pub fn PassOptionalLongLong(&self, _: Option) {} - pub fn PassOptionalUnsignedLongLong(&self, _: Option) {} - pub fn PassOptionalFloat(&self, _: Option) {} - pub fn PassOptionalDouble(&self, _: Option) {} - pub fn PassOptionalString(&self, _: Option) {} - pub fn PassOptionalByteString(&self, _: Option) {} - pub fn PassOptionalEnum(&self, _: Option) {} - pub fn PassOptionalInterface(&self, _: Option>) {} - pub fn PassOptionalUnion(&self, _: Option) {} - pub fn PassOptionalAny(&self, _: *JSContext, _: Option) {} + fn PassOptionalBoolean(&self, _: Option) {} + fn PassOptionalByte(&self, _: Option) {} + fn PassOptionalOctet(&self, _: Option) {} + fn PassOptionalShort(&self, _: Option) {} + fn PassOptionalUnsignedShort(&self, _: Option) {} + fn PassOptionalLong(&self, _: Option) {} + fn PassOptionalUnsignedLong(&self, _: Option) {} + fn PassOptionalLongLong(&self, _: Option) {} + fn PassOptionalUnsignedLongLong(&self, _: Option) {} + fn PassOptionalFloat(&self, _: Option) {} + fn PassOptionalDouble(&self, _: Option) {} + fn PassOptionalString(&self, _: Option) {} + fn PassOptionalByteString(&self, _: Option) {} + fn PassOptionalEnum(&self, _: Option) {} + fn PassOptionalInterface(&self, _: Option>) {} + fn PassOptionalUnion(&self, _: Option) {} + fn PassOptionalAny(&self, _: *JSContext, _: Option) {} - pub fn PassOptionalNullableBoolean(&self, _: Option>) {} - pub fn PassOptionalNullableByte(&self, _: Option>) {} - pub fn PassOptionalNullableOctet(&self, _: Option>) {} - pub fn PassOptionalNullableShort(&self, _: Option>) {} - pub fn PassOptionalNullableUnsignedShort(&self, _: Option>) {} - pub fn PassOptionalNullableLong(&self, _: Option>) {} - pub fn PassOptionalNullableUnsignedLong(&self, _: Option>) {} - pub fn PassOptionalNullableLongLong(&self, _: Option>) {} - pub fn PassOptionalNullableUnsignedLongLong(&self, _: Option>) {} - pub fn PassOptionalNullableFloat(&self, _: Option>) {} - pub fn PassOptionalNullableDouble(&self, _: Option>) {} - pub fn PassOptionalNullableString(&self, _: Option>) {} - pub fn PassOptionalNullableByteString(&self, _: Option>) {} - // pub fn PassOptionalNullableEnum(&self, _: Option>) {} - pub fn PassOptionalNullableInterface(&self, _: Option>>) {} - pub fn PassOptionalNullableUnion(&self, _: Option>) {} + fn PassOptionalNullableBoolean(&self, _: Option>) {} + fn PassOptionalNullableByte(&self, _: Option>) {} + fn PassOptionalNullableOctet(&self, _: Option>) {} + fn PassOptionalNullableShort(&self, _: Option>) {} + fn PassOptionalNullableUnsignedShort(&self, _: Option>) {} + fn PassOptionalNullableLong(&self, _: Option>) {} + fn PassOptionalNullableUnsignedLong(&self, _: Option>) {} + fn PassOptionalNullableLongLong(&self, _: Option>) {} + fn PassOptionalNullableUnsignedLongLong(&self, _: Option>) {} + fn PassOptionalNullableFloat(&self, _: Option>) {} + fn PassOptionalNullableDouble(&self, _: Option>) {} + fn PassOptionalNullableString(&self, _: Option>) {} + fn PassOptionalNullableByteString(&self, _: Option>) {} + // fn PassOptionalNullableEnum(&self, _: Option>) {} + fn PassOptionalNullableInterface(&self, _: Option>>) {} + fn PassOptionalNullableUnion(&self, _: Option>) {} - pub fn PassOptionalBooleanWithDefault(&self, _: bool) {} - pub fn PassOptionalByteWithDefault(&self, _: i8) {} - pub fn PassOptionalOctetWithDefault(&self, _: u8) {} - pub fn PassOptionalShortWithDefault(&self, _: i16) {} - pub fn PassOptionalUnsignedShortWithDefault(&self, _: u16) {} - pub fn PassOptionalLongWithDefault(&self, _: i32) {} - pub fn PassOptionalUnsignedLongWithDefault(&self, _: u32) {} - pub fn PassOptionalLongLongWithDefault(&self, _: i64) {} - pub fn PassOptionalUnsignedLongLongWithDefault(&self, _: u64) {} - pub fn PassOptionalStringWithDefault(&self, _: DOMString) {} - pub fn PassOptionalEnumWithDefault(&self, _: TestEnum) {} + fn PassOptionalBooleanWithDefault(&self, _: bool) {} + fn PassOptionalByteWithDefault(&self, _: i8) {} + fn PassOptionalOctetWithDefault(&self, _: u8) {} + fn PassOptionalShortWithDefault(&self, _: i16) {} + fn PassOptionalUnsignedShortWithDefault(&self, _: u16) {} + fn PassOptionalLongWithDefault(&self, _: i32) {} + fn PassOptionalUnsignedLongWithDefault(&self, _: u32) {} + fn PassOptionalLongLongWithDefault(&self, _: i64) {} + fn PassOptionalUnsignedLongLongWithDefault(&self, _: u64) {} + fn PassOptionalStringWithDefault(&self, _: DOMString) {} + fn PassOptionalEnumWithDefault(&self, _: TestEnum) {} - pub fn PassOptionalNullableBooleanWithDefault(&self, _: Option) {} - pub fn PassOptionalNullableByteWithDefault(&self, _: Option) {} - pub fn PassOptionalNullableOctetWithDefault(&self, _: Option) {} - pub fn PassOptionalNullableShortWithDefault(&self, _: Option) {} - pub fn PassOptionalNullableUnsignedShortWithDefault(&self, _: Option) {} - pub fn PassOptionalNullableLongWithDefault(&self, _: Option) {} - pub fn PassOptionalNullableUnsignedLongWithDefault(&self, _: Option) {} - pub fn PassOptionalNullableLongLongWithDefault(&self, _: Option) {} - pub fn PassOptionalNullableUnsignedLongLongWithDefault(&self, _: Option) {} - pub fn PassOptionalNullableFloatWithDefault(&self, _: Option) {} - pub fn PassOptionalNullableDoubleWithDefault(&self, _: Option) {} - pub fn PassOptionalNullableStringWithDefault(&self, _: Option) {} - pub fn PassOptionalNullableByteStringWithDefault(&self, _: Option) {} - // pub fn PassOptionalNullableEnumWithDefault(&self, _: Option) {} - pub fn PassOptionalNullableInterfaceWithDefault(&self, _: Option>) {} - pub fn PassOptionalNullableUnionWithDefault(&self, _: Option) {} - pub fn PassOptionalAnyWithDefault(&self, _: *JSContext, _: JSVal) {} + fn PassOptionalNullableBooleanWithDefault(&self, _: Option) {} + fn PassOptionalNullableByteWithDefault(&self, _: Option) {} + fn PassOptionalNullableOctetWithDefault(&self, _: Option) {} + fn PassOptionalNullableShortWithDefault(&self, _: Option) {} + fn PassOptionalNullableUnsignedShortWithDefault(&self, _: Option) {} + fn PassOptionalNullableLongWithDefault(&self, _: Option) {} + fn PassOptionalNullableUnsignedLongWithDefault(&self, _: Option) {} + fn PassOptionalNullableLongLongWithDefault(&self, _: Option) {} + fn PassOptionalNullableUnsignedLongLongWithDefault(&self, _: Option) {} + fn PassOptionalNullableFloatWithDefault(&self, _: Option) {} + fn PassOptionalNullableDoubleWithDefault(&self, _: Option) {} + fn PassOptionalNullableStringWithDefault(&self, _: Option) {} + fn PassOptionalNullableByteStringWithDefault(&self, _: Option) {} + // fn PassOptionalNullableEnumWithDefault(&self, _: Option) {} + fn PassOptionalNullableInterfaceWithDefault(&self, _: Option>) {} + fn PassOptionalNullableUnionWithDefault(&self, _: Option) {} + fn PassOptionalAnyWithDefault(&self, _: *JSContext, _: JSVal) {} - pub fn PassOptionalNullableBooleanWithNonNullDefault(&self, _: Option) {} - pub fn PassOptionalNullableByteWithNonNullDefault(&self, _: Option) {} - pub fn PassOptionalNullableOctetWithNonNullDefault(&self, _: Option) {} - pub fn PassOptionalNullableShortWithNonNullDefault(&self, _: Option) {} - pub fn PassOptionalNullableUnsignedShortWithNonNullDefault(&self, _: Option) {} - pub fn PassOptionalNullableLongWithNonNullDefault(&self, _: Option) {} - pub fn PassOptionalNullableUnsignedLongWithNonNullDefault(&self, _: Option) {} - pub fn PassOptionalNullableLongLongWithNonNullDefault(&self, _: Option) {} - pub fn PassOptionalNullableUnsignedLongLongWithNonNullDefault(&self, _: Option) {} - // pub fn PassOptionalNullableFloatWithNonNullDefault(&self, _: Option) {} - // pub fn PassOptionalNullableDoubleWithNonNullDefault(&self, _: Option) {} - pub fn PassOptionalNullableStringWithNonNullDefault(&self, _: Option) {} - // pub fn PassOptionalNullableEnumWithNonNullDefault(&self, _: Option) {} + fn PassOptionalNullableBooleanWithNonNullDefault(&self, _: Option) {} + fn PassOptionalNullableByteWithNonNullDefault(&self, _: Option) {} + fn PassOptionalNullableOctetWithNonNullDefault(&self, _: Option) {} + fn PassOptionalNullableShortWithNonNullDefault(&self, _: Option) {} + fn PassOptionalNullableUnsignedShortWithNonNullDefault(&self, _: Option) {} + fn PassOptionalNullableLongWithNonNullDefault(&self, _: Option) {} + fn PassOptionalNullableUnsignedLongWithNonNullDefault(&self, _: Option) {} + fn PassOptionalNullableLongLongWithNonNullDefault(&self, _: Option) {} + fn PassOptionalNullableUnsignedLongLongWithNonNullDefault(&self, _: Option) {} + // fn PassOptionalNullableFloatWithNonNullDefault(&self, _: Option) {} + // fn PassOptionalNullableDoubleWithNonNullDefault(&self, _: Option) {} + fn PassOptionalNullableStringWithNonNullDefault(&self, _: Option) {} + // fn PassOptionalNullableEnumWithNonNullDefault(&self, _: Option) {} } impl Reflectable for TestBinding { diff --git a/src/components/script/dom/text.rs b/src/components/script/dom/text.rs index cdcfdac6af3..570c1412833 100644 --- a/src/components/script/dom/text.rs +++ b/src/components/script/dom/text.rs @@ -10,7 +10,7 @@ use dom::characterdata::CharacterData; use dom::document::Document; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::node::{Node, TextNodeTypeId}; -use dom::window::Window; +use dom::window::{Window, WindowMethods}; use servo_util::str::DOMString; /// An HTML text node. @@ -42,16 +42,23 @@ impl Text { pub fn Constructor(owner: &JSRef, text: DOMString) -> Fallible> { let roots = RootCollection::new(); - let document = owner.get().Document(); - let document = document.root(&roots); - Ok(Text::new(text.clone(), &document.root_ref())) + let document = owner.Document().root(&roots); + Ok(Text::new(text.clone(), &*document)) } +} - pub fn SplitText(&self, _offset: u32) -> Fallible> { +pub trait TextMethods { + fn SplitText(&self, _offset: u32) -> Fallible>; + fn GetWholeText(&self) -> Fallible; +} + +impl<'a> TextMethods for JSRef<'a, Text> { + fn SplitText(&self, _offset: u32) -> Fallible> { fail!("unimplemented") } - pub fn GetWholeText(&self) -> Fallible { + fn GetWholeText(&self) -> Fallible { Ok(~"") } } + diff --git a/src/components/script/dom/uievent.rs b/src/components/script/dom/uievent.rs index f42edeb42bf..cb1365181e5 100644 --- a/src/components/script/dom/uievent.rs +++ b/src/components/script/dom/uievent.rs @@ -3,11 +3,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::UIEventBinding; -use dom::bindings::codegen::InheritTypes::UIEventDerived; +use dom::bindings::codegen::InheritTypes::{EventCast, UIEventDerived}; use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Unrooted}; use dom::bindings::error::Fallible; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; -use dom::event::{Event, EventTypeId, UIEventTypeId}; +use dom::event::{Event, EventMethods, EventTypeId, UIEventTypeId}; use dom::node::Node; use dom::window::Window; use servo_util::str::DOMString; @@ -48,80 +48,107 @@ impl UIEvent { let roots = RootCollection::new(); let mut ev = UIEvent::new(owner).root(&roots); let view = init.view.as_ref().map(|view| view.root(&roots)); - ev.get_mut().InitUIEvent(type_, init.parent.bubbles, init.parent.cancelable, - view.root_ref(), init.detail); + ev.InitUIEvent(type_, init.parent.bubbles, init.parent.cancelable, + view.root_ref(), init.detail); Ok(Unrooted::new_rooted(&*ev)) } +} - pub fn GetView(&self) -> Option> { +pub trait UIEventMethods { + fn GetView(&self) -> Option>; + fn Detail(&self) -> i32; + fn LayerX(&self) -> i32; + fn LayerY(&self) -> i32; + fn PageX(&self) -> i32; + fn PageY(&self) -> i32; + fn Which(&self) -> u32; + fn GetRangeParent(&self) -> Option>; + fn RangeOffset(&self) -> i32; + fn CancelBubble(&self) -> bool; + fn SetCancelBubble(&mut self, _val: bool); + fn IsChar(&self) -> bool; + fn InitUIEvent(&mut self, + type_: DOMString, + can_bubble: bool, + cancelable: bool, + view: Option>, + detail: i32); +} + +impl<'a> UIEventMethods for JSRef<'a, UIEvent> { + fn GetView(&self) -> Option> { self.view.clone().map(|view| Unrooted::new(view)) } - pub fn Detail(&self) -> i32 { + fn Detail(&self) -> i32 { self.detail } - pub fn InitUIEvent(&mut self, - type_: DOMString, - can_bubble: bool, - cancelable: bool, - view: Option>, - detail: i32) { - self.event.InitEvent(type_, can_bubble, cancelable); + fn InitUIEvent(&mut self, + type_: DOMString, + can_bubble: bool, + cancelable: bool, + view: Option>, + detail: i32) { + { + let event: &mut JSRef = EventCast::from_mut_ref(self); + event.InitEvent(type_, can_bubble, cancelable); + } self.view = view.map(|view| view.unrooted()); self.detail = detail; } - pub fn LayerX(&self) -> i32 { + fn LayerX(&self) -> i32 { //TODO 0 } - pub fn LayerY(&self) -> i32 { + fn LayerY(&self) -> i32 { //TODO 0 } - pub fn PageX(&self) -> i32 { + fn PageX(&self) -> i32 { //TODO 0 } - pub fn PageY(&self) -> i32 { + fn PageY(&self) -> i32 { //TODO 0 } - pub fn Which(&self) -> u32 { + fn Which(&self) -> u32 { //TODO 0 } - pub fn GetRangeParent(&self) -> Option> { + fn GetRangeParent(&self) -> Option> { //TODO None } - pub fn RangeOffset(&self) -> i32 { + fn RangeOffset(&self) -> i32 { //TODO 0 } - pub fn CancelBubble(&self) -> bool { + fn CancelBubble(&self) -> bool { //TODO false } - pub fn SetCancelBubble(&mut self, _val: bool) { + fn SetCancelBubble(&mut self, _val: bool) { //TODO } - pub fn IsChar(&self) -> bool { + fn IsChar(&self) -> bool { //TODO false } } + impl Reflectable for UIEvent { fn reflector<'a>(&'a self) -> &'a Reflector { self.event.reflector() diff --git a/src/components/script/dom/validitystate.rs b/src/components/script/dom/validitystate.rs index 02b0b9a7a11..d4d829f842b 100644 --- a/src/components/script/dom/validitystate.rs +++ b/src/components/script/dom/validitystate.rs @@ -30,44 +30,57 @@ impl ValidityState { } } -impl ValidityState { - pub fn ValueMissing(&self) -> bool { +pub trait ValidityStateMethods { + fn ValueMissing(&self) -> bool; + fn TypeMismatch(&self) -> bool; + fn PatternMismatch(&self) -> bool; + fn TooLong(&self) -> bool; + fn RangeUnderflow(&self) -> bool; + fn RangeOverflow(&self) -> bool; + fn StepMismatch(&self) -> bool; + fn CustomError(&self) -> bool; + fn Valid(&self) -> bool; +} + +impl<'a> ValidityStateMethods for JSRef<'a, ValidityState> { + fn ValueMissing(&self) -> bool { false } - pub fn TypeMismatch(&self) -> bool { + fn TypeMismatch(&self) -> bool { false } - pub fn PatternMismatch(&self) -> bool { + fn PatternMismatch(&self) -> bool { false } - pub fn TooLong(&self) -> bool { + fn TooLong(&self) -> bool { false } - pub fn RangeUnderflow(&self) -> bool { + fn RangeUnderflow(&self) -> bool { false } - pub fn RangeOverflow(&self) -> bool { + fn RangeOverflow(&self) -> bool { false } - pub fn StepMismatch(&self) -> bool { + fn StepMismatch(&self) -> bool { false } - pub fn CustomError(&self) -> bool { + fn CustomError(&self) -> bool { false } - pub fn Valid(&self) -> bool { + fn Valid(&self) -> bool { true } } + impl Reflectable for ValidityState { fn reflector<'a>(&'a self) -> &'a Reflector { &self.reflector_ diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index ff46c27ed79..dda1a0fa295 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -105,88 +105,146 @@ pub struct TimerData { pub funval: Traceable, } -impl Window { - pub fn Alert(&self, s: DOMString) { +pub trait WindowMethods { + fn Alert(&self, s: DOMString); + fn Close(&self); + fn Document(&self) -> Unrooted; + fn Name(&self) -> DOMString; + fn SetName(&self, _name: DOMString); + fn Status(&self) -> DOMString; + fn SetStatus(&self, _status: DOMString); + fn Closed(&self) -> bool; + fn Stop(&self); + fn Focus(&self); + fn Blur(&self); + fn GetFrameElement(&self) -> Option>; + fn Location(&mut self, abstract_self: &JSRef) -> Unrooted; + fn Console(&mut self, abstract_self: &JSRef) -> Unrooted; + fn Navigator(&mut self, abstract_self: &JSRef) -> Unrooted; + fn Confirm(&self, _message: DOMString) -> bool; + fn Prompt(&self, _message: DOMString, _default: DOMString) -> Option; + fn Print(&self); + fn ShowModalDialog(&self, _cx: *JSContext, _url: DOMString, _argument: Option) -> JSVal; + fn SetTimeout(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32; + fn ClearTimeout(&mut self, handle: i32); + fn SetInterval(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32; + fn ClearInterval(&mut self, handle: i32); + fn Window(&self, abstract_self: &JSRef) -> Unrooted; + fn Self(&self, abstract_self: &JSRef) -> Unrooted; +} + +impl<'a> WindowMethods for JSRef<'a, Window> { + fn Alert(&self, s: DOMString) { // Right now, just print to the console println!("ALERT: {:s}", s); } - pub fn Close(&self) { + fn Close(&self) { let ScriptChan(ref chan) = self.script_chan; chan.send(ExitWindowMsg(self.page.id.clone())); } - pub fn Document(&self) -> Unrooted { + fn Document(&self) -> Unrooted { let frame = self.page().frame(); Unrooted::new(frame.get_ref().document.clone()) } - pub fn Name(&self) -> DOMString { + fn Name(&self) -> DOMString { ~"" } - pub fn SetName(&self, _name: DOMString) { + fn SetName(&self, _name: DOMString) { } - pub fn Status(&self) -> DOMString { + fn Status(&self) -> DOMString { ~"" } - pub fn SetStatus(&self, _status: DOMString) { + fn SetStatus(&self, _status: DOMString) { } - pub fn Closed(&self) -> bool { + fn Closed(&self) -> bool { false } - pub fn Stop(&self) { + fn Stop(&self) { } - pub fn Focus(&self) { + fn Focus(&self) { } - pub fn Blur(&self) { + fn Blur(&self) { } - pub fn GetFrameElement(&self) -> Option> { + fn GetFrameElement(&self) -> Option> { None } - pub fn Location(&mut self, abstract_self: &JSRef) -> Unrooted { + fn Location(&mut self, abstract_self: &JSRef) -> Unrooted { if self.location.is_none() { - self.location.assign(Some(Location::new(abstract_self, self.page.clone()))); + let page = self.deref().page.clone(); + self.location.assign(Some(Location::new(abstract_self, page))); } Unrooted::new(self.location.get_ref().clone()) } - pub fn Console(&mut self, abstract_self: &JSRef) -> Unrooted { + fn Console(&mut self, abstract_self: &JSRef) -> Unrooted { if self.console.is_none() { self.console.assign(Some(Console::new(abstract_self))); } Unrooted::new(self.console.get_ref().clone()) } - pub fn Navigator(&mut self, abstract_self: &JSRef) -> Unrooted { + fn Navigator(&mut self, abstract_self: &JSRef) -> Unrooted { if self.navigator.is_none() { self.navigator.assign(Some(Navigator::new(abstract_self))); } Unrooted::new(self.navigator.get_ref().clone()) } - pub fn Confirm(&self, _message: DOMString) -> bool { + fn Confirm(&self, _message: DOMString) -> bool { false } - pub fn Prompt(&self, _message: DOMString, _default: DOMString) -> Option { + fn Prompt(&self, _message: DOMString, _default: DOMString) -> Option { None } - pub fn Print(&self) { + fn Print(&self) { } - pub fn ShowModalDialog(&self, _cx: *JSContext, _url: DOMString, _argument: Option) -> JSVal { + fn ShowModalDialog(&self, _cx: *JSContext, _url: DOMString, _argument: Option) -> JSVal { NullValue() } + + fn SetTimeout(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32 { + self.set_timeout_or_interval(callback, timeout, false) + } + + fn ClearTimeout(&mut self, handle: i32) { + let mut timer_handle = self.active_timers.pop(&TimerId(handle)); + match timer_handle { + Some(ref mut handle) => handle.cancel(), + None => { } + } + self.active_timers.remove(&TimerId(handle)); + } + + fn SetInterval(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32 { + self.set_timeout_or_interval(callback, timeout, true) + } + + fn ClearInterval(&mut self, handle: i32) { + self.ClearTimeout(handle); + } + + fn Window(&self, abstract_self: &JSRef) -> Unrooted { + Unrooted::new_rooted(abstract_self) + } + + fn Self(&self, abstract_self: &JSRef) -> Unrooted { + self.Window(abstract_self) + } } impl Reflectable for Window { @@ -258,35 +316,6 @@ impl Window { handle } - pub fn SetTimeout(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32 { - self.set_timeout_or_interval(callback, timeout, false) - } - - pub fn ClearTimeout(&mut self, handle: i32) { - let mut timer_handle = self.active_timers.pop(&TimerId(handle)); - match timer_handle { - Some(ref mut handle) => handle.cancel(), - None => { } - } - self.active_timers.remove(&TimerId(handle)); - } - - pub fn SetInterval(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32 { - self.set_timeout_or_interval(callback, timeout, true) - } - - pub fn ClearInterval(&mut self, handle: i32) { - self.ClearTimeout(handle); - } - - pub fn Window(&self, abstract_self: &JSRef) -> Unrooted { - Unrooted::new_rooted(abstract_self) - } - - pub fn Self(&self, abstract_self: &JSRef) -> Unrooted { - self.Window(abstract_self) - } - pub fn damage_and_reflow(&self, damage: DocumentDamageLevel) { // FIXME This should probably be ReflowForQuery, not Display. All queries currently // currently rely on the display list, which means we can't destroy it by diff --git a/src/components/script/dom/xmlhttprequest.rs b/src/components/script/dom/xmlhttprequest.rs index 8327135d566..a0ffa15c772 100644 --- a/src/components/script/dom/xmlhttprequest.rs +++ b/src/components/script/dom/xmlhttprequest.rs @@ -66,71 +66,100 @@ impl XMLHttpRequest { pub fn Constructor(owner: &JSRef) -> Fallible> { Ok(XMLHttpRequest::new(owner)) } - pub fn ReadyState(&self) -> u16 { +} + +pub trait XMLHttpRequestMethods { + fn ReadyState(&self) -> u16; + fn Open(&self, _method: ByteString, _url: DOMString); + fn Open_(&self, _method: ByteString, _url: DOMString, _async: bool, + _username: Option, _password: Option); + fn SetRequestHeader(&self, _name: ByteString, _value: ByteString); + fn Timeout(&self) -> u32; + fn SetTimeout(&mut self, timeout: u32); + fn WithCredentials(&self) -> bool; + fn SetWithCredentials(&mut self, with_credentials: bool); + fn Upload(&self) -> Unrooted; + fn Send(&self, _data: Option); + fn Abort(&self); + fn ResponseURL(&self) -> DOMString; + fn Status(&self) -> u16; + fn StatusText(&self) -> ByteString; + fn GetResponseHeader(&self, _name: ByteString) -> Option; + fn GetAllResponseHeaders(&self) -> ByteString; + fn OverrideMimeType(&self, _mime: DOMString); + fn ResponseType(&self) -> XMLHttpRequestResponseType; + fn SetResponseType(&mut self, response_type: XMLHttpRequestResponseType); + fn Response(&self, _cx: *JSContext) -> JSVal; + fn ResponseText(&self) -> DOMString; + fn GetResponseXML(&self) -> Option>; +} + +impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { + fn ReadyState(&self) -> u16 { self.ready_state } - pub fn Open(&self, _method: ByteString, _url: DOMString) { + fn Open(&self, _method: ByteString, _url: DOMString) { } - pub fn Open_(&self, _method: ByteString, _url: DOMString, _async: bool, + fn Open_(&self, _method: ByteString, _url: DOMString, _async: bool, _username: Option, _password: Option) { } - pub fn SetRequestHeader(&self, _name: ByteString, _value: ByteString) { + fn SetRequestHeader(&self, _name: ByteString, _value: ByteString) { } - pub fn Timeout(&self) -> u32 { + fn Timeout(&self) -> u32 { self.timeout } - pub fn SetTimeout(&mut self, timeout: u32) { + fn SetTimeout(&mut self, timeout: u32) { self.timeout = timeout } - pub fn WithCredentials(&self) -> bool { + fn WithCredentials(&self) -> bool { self.with_credentials } - pub fn SetWithCredentials(&mut self, with_credentials: bool) { + fn SetWithCredentials(&mut self, with_credentials: bool) { self.with_credentials = with_credentials } - pub fn Upload(&self) -> Unrooted { + fn Upload(&self) -> Unrooted { Unrooted::new(self.upload.get_ref().clone()) } - pub fn Send(&self, _data: Option) { + fn Send(&self, _data: Option) { } - pub fn Abort(&self) { + fn Abort(&self) { } - pub fn ResponseURL(&self) -> DOMString { + fn ResponseURL(&self) -> DOMString { self.response_url.clone() } - pub fn Status(&self) -> u16 { + fn Status(&self) -> u16 { self.status } - pub fn StatusText(&self) -> ByteString { + fn StatusText(&self) -> ByteString { self.status_text.clone() } - pub fn GetResponseHeader(&self, _name: ByteString) -> Option { + fn GetResponseHeader(&self, _name: ByteString) -> Option { None } - pub fn GetAllResponseHeaders(&self) -> ByteString { + fn GetAllResponseHeaders(&self) -> ByteString { ByteString::new(vec!()) } - pub fn OverrideMimeType(&self, _mime: DOMString) { + fn OverrideMimeType(&self, _mime: DOMString) { } - pub fn ResponseType(&self) -> XMLHttpRequestResponseType { + fn ResponseType(&self) -> XMLHttpRequestResponseType { self.response_type } - pub fn SetResponseType(&mut self, response_type: XMLHttpRequestResponseType) { + fn SetResponseType(&mut self, response_type: XMLHttpRequestResponseType) { self.response_type = response_type } - pub fn Response(&self, _cx: *JSContext) -> JSVal { + fn Response(&self, _cx: *JSContext) -> JSVal { NullValue() } - pub fn ResponseText(&self) -> DOMString { + fn ResponseText(&self) -> DOMString { self.response_text.clone() } - pub fn GetResponseXML(&self) -> Option> { + fn GetResponseXML(&self) -> Option> { self.response_xml.clone().map(|response| Unrooted::new(response)) } } diff --git a/src/components/script/dom/xmlhttprequesteventtarget.rs b/src/components/script/dom/xmlhttprequesteventtarget.rs index 55708581a1d..68d67fab89b 100644 --- a/src/components/script/dom/xmlhttprequesteventtarget.rs +++ b/src/components/script/dom/xmlhttprequesteventtarget.rs @@ -37,4 +37,7 @@ impl Reflectable for XMLHttpRequestEventTarget { fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector { self.eventtarget.mut_reflector() } +} + +pub trait XMLHttpRequestEventTargetMethods { } \ No newline at end of file diff --git a/src/components/script/dom/xmlhttprequestupload.rs b/src/components/script/dom/xmlhttprequestupload.rs index 8e251dd4e8f..c2332d84ee0 100644 --- a/src/components/script/dom/xmlhttprequestupload.rs +++ b/src/components/script/dom/xmlhttprequestupload.rs @@ -45,4 +45,7 @@ impl XMLHttpRequestUploadDerived for EventTarget { _ => false } } +} + +pub trait XMLHttpRequestUploadMethods { } \ No newline at end of file diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index a90a696063c..0121b023783 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -2,6 +2,7 @@ * 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::attr::AttrMethods; use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, TextCast, ElementCast}; use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast; use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalRootable}; @@ -476,7 +477,7 @@ pub fn parse_html(page: &Page, let script: &JSRef = &*from_hubbub_node(script, None).root(&roots); match script.get_attribute(Null, "src").root(&roots) { Some(src) => { - debug!("found script: {:s}", src.get().Value()); + debug!("found script: {:s}", src.deref().Value()); let new_url = parse_url(src.get().value_ref(), Some(url3.clone())); js_chan2.send(JSTaskNewFile(new_url)); } diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index 36fc83b1aee..df7e6f2b994 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -5,17 +5,18 @@ //! The script task is the task that owns the DOM in memory, runs JavaScript, and spawns parsing //! and layout tasks. +use dom::attr::AttrMethods; use dom::bindings::codegen::RegisterBindings; use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, ElementCast, EventCast}; use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalAssignable}; use dom::bindings::js::OptionalRootable; use dom::bindings::trace::{Traceable, Untraceable}; use dom::bindings::utils::{Reflectable, GlobalStaticData, wrap_for_same_compartment}; -use dom::document::{Document, HTMLDocument}; +use dom::document::{Document, HTMLDocument, DocumentMethods}; use dom::element::{Element, AttributeHandlers}; use dom::event::{Event_, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent}; -use dom::event::Event; -use dom::uievent::UIEvent; +use dom::event::{Event, EventMethods}; +use dom::uievent::{UIEvent, UIEventMethods}; use dom::eventtarget::EventTarget; use dom::node; use dom::node::{Node, NodeHelpers}; @@ -409,7 +410,7 @@ impl Page { fn find_fragment_node(&self, fragid: ~str) -> Option> { let roots = RootCollection::new(); let document = self.frame().get_ref().document.root(&roots); - match document.get().GetElementById(fragid.to_owned()) { + match document.deref().GetElementById(fragid.to_owned()) { Some(node) => Some(node), None => { let doc_node: &JSRef = NodeCast::from_ref(&*document); @@ -445,7 +446,7 @@ impl Page { let roots = RootCollection::new(); let frame = self.frame(); let document = frame.get_ref().document.root(&roots); - let root = document.get().GetDocumentElement().root(&roots); + let root = document.deref().GetDocumentElement().root(&roots); if root.is_none() { return None; } @@ -468,7 +469,7 @@ impl Page { let roots = RootCollection::new(); let frame = self.frame(); let document = frame.get_ref().document.root(&roots); - let root = document.get().GetDocumentElement().root(&roots); + let root = document.deref().GetDocumentElement().root(&roots); if root.is_none() { return None; } @@ -985,7 +986,7 @@ impl ScriptTask { // "load" event as soon as we've finished executing all scripts parsed during // the initial load. let mut event = Event::new(&*window).root(&roots); - event.get_mut().InitEvent(~"load", false, false); + event.InitEvent(~"load", false, false); let doctarget: &JSRef = EventTargetCast::from_ref(&*document); let wintarget: &mut JSRef = EventTargetCast::from_mut_ref(&mut *window); let wintarget_alias = wintarget.clone(); @@ -1055,8 +1056,8 @@ impl ScriptTask { // http://dev.w3.org/csswg/cssom-view/#resizing-viewports // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-resize let mut uievent = UIEvent::new(&*window).root(&roots); - uievent.get_mut().InitUIEvent(~"resize", false, false, - Some((*window).clone()), 0i32); + uievent.InitUIEvent(~"resize", false, false, + Some((*window).clone()), 0i32); let event: &mut JSRef = EventCast::from_mut_ref(&mut *uievent); let wintarget: &mut JSRef = EventTargetCast::from_mut_ref(&mut *window); @@ -1194,7 +1195,7 @@ impl ScriptTask { // if the node's element is "a," load url from href attr let attr = element.get_attribute(Null, "href"); for href in attr.root(&roots).iter() { - debug!("ScriptTask: clicked on link to {:s}", href.get().Value()); + debug!("ScriptTask: clicked on link to {:s}", href.Value()); let click_frag = href.get().value_ref().starts_with("#"); let base_url = Some(page.get_url()); debug!("ScriptTask: current url is {:?}", base_url); From 7daa97c7e5de3dac14b4d1c8a923448b025e3c09 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 10 Apr 2014 22:13:08 -0400 Subject: [PATCH 05/16] Remove abstract_self. --- .../script/dom/bindings/codegen/Bindings.conf | 103 +----- .../dom/bindings/codegen/CodegenRust.py | 18 - .../dom/bindings/codegen/Configuration.py | 1 - src/components/script/dom/document.rs | 176 +++++----- src/components/script/dom/documentfragment.rs | 8 +- .../script/dom/domimplementation.rs | 20 +- src/components/script/dom/element.rs | 331 +++++++++--------- src/components/script/dom/eventdispatcher.rs | 11 +- src/components/script/dom/eventtarget.rs | 25 +- .../script/dom/htmldatalistelement.rs | 6 +- .../script/dom/htmlfieldsetelement.rs | 6 +- .../script/dom/htmliframeelement.rs | 12 +- src/components/script/dom/htmlimageelement.rs | 144 ++++---- .../script/dom/htmlscriptelement.rs | 10 +- src/components/script/dom/htmlstyleelement.rs | 2 +- src/components/script/dom/node.rs | 164 ++++----- src/components/script/dom/window.rs | 33 +- .../script/html/hubbub_html_parser.rs | 8 +- src/components/script/script_task.rs | 15 +- 19 files changed, 483 insertions(+), 610 deletions(-) diff --git a/src/components/script/dom/bindings/codegen/Bindings.conf b/src/components/script/dom/bindings/codegen/Bindings.conf index 053fabae1b2..f3723fb7c9b 100644 --- a/src/components/script/dom/bindings/codegen/Bindings.conf +++ b/src/components/script/dom/bindings/codegen/Bindings.conf @@ -9,8 +9,6 @@ # The configuration table maps each interface name to a |descriptor|. # # Valid fields for all descriptors: -# * needsAbstract: a list of members that require a JS<>-wrapped version of -# self to be passed to the native code. # * createGlobal: True for global objects. # * outerObjectHook: string to use in place of default value for outerObject and thisObject # JS class hooks @@ -26,123 +24,46 @@ DOMInterfaces = { 'ClientRect': {}, 'ClientRectList': {}, 'Console': {}, -'Document': { - 'needsAbstract': [ - 'adoptNode', - 'anchors', - 'applets', - 'body', - 'children', - 'createComment', - 'createDocumentFragment', - 'createElement', - 'createElementNS', - 'createProcessingInstruction', - 'createTextNode', - 'embeds', - 'forms', - 'getElementsByClassName', - 'getElementsByTagName', - 'getElementsByTagNameNS', - 'images', - 'importNode', - 'links', - 'location', - 'plugins', - 'scripts', - 'title', - ], -}, +'Document': {}, 'DOMException': {}, 'DOMImplementation': {}, 'DOMParser': {}, -'Element': { - 'needsAbstract': [ - 'attributes', - 'children', - 'className', - 'getAttribute', - 'getAttributeNS', - 'getBoundingClientRect', - 'getClientRects', - 'getElementsByClassName', - 'getElementsByTagName', - 'getElementsByTagNameNS', - 'hasAttribute', - 'hasAttributeNS', - 'id', - 'innerHTML', - 'outerHTML', - 'removeAttribute', - 'removeAttributeNS', - 'setAttribute', - 'setAttributeNS', - ] -}, +'Element': {}, 'Event': {}, 'EventListener': { 'nativeType': 'EventListenerBinding::EventListener', }, -'EventTarget': { - 'needsAbstract': ['dispatchEvent'] -}, +'EventTarget': {}, 'FormData': {}, 'HTMLCollection': {}, 'Location': {}, 'MouseEvent': {}, 'Navigator': {}, -'Node': { - 'needsAbstract': [ - 'appendChild', - 'childNodes', - 'cloneNode', - 'compareDocumentPosition', - 'contains', - 'insertBefore', - 'isEqualNode', - 'namespaceURI', - 'nodeName', - 'nodeValue', - 'normalize', - 'removeChild', - 'replaceChild', - 'textContent', - ] -}, - +'Node': {}, 'NodeList': {}, - 'UIEvent': {}, 'ValidityState': {}, 'Window': { 'createGlobal': True, 'outerObjectHook': 'Some(bindings::utils::outerize_global)', - 'needsAbstract': [ - 'console', - 'location', - 'navigator', - 'self', - 'window', - ], }, 'XMLHttpRequest': {}, 'XMLHttpRequestEventTarget': {}, 'XMLHttpRequestUpload': {}, +#FIXME(jdm): This should be 'register': False, but then we don't generate enum types 'TestBinding': {}, } # FIXME: This should be renamed: https://github.com/mozilla/servo/issues/1625 -def addHTMLElement(element, concrete=None, needsAbstract=[]): +def addHTMLElement(element): DOMInterfaces[element] = { 'nativeType': 'JS<%s>' % element, - 'concreteType': concrete if concrete else element, - 'needsAbstract': needsAbstract } addHTMLElement('Comment') -addHTMLElement('DocumentFragment', concrete='DocumentFragment', needsAbstract=['children']) +addHTMLElement('DocumentFragment') addHTMLElement('DocumentType') addHTMLElement('Text') addHTMLElement('ProcessingInstruction') @@ -158,12 +79,12 @@ addHTMLElement('HTMLBRElement') addHTMLElement('HTMLCanvasElement') addHTMLElement('HTMLDataElement') addHTMLElement('HTMLDivElement') -addHTMLElement('HTMLDataListElement', needsAbstract=['options']) +addHTMLElement('HTMLDataListElement') addHTMLElement('HTMLDirectoryElement') addHTMLElement('HTMLDListElement') addHTMLElement('HTMLElement') addHTMLElement('HTMLEmbedElement') -addHTMLElement('HTMLFieldSetElement', needsAbstract=['elements']) +addHTMLElement('HTMLFieldSetElement') addHTMLElement('HTMLFontElement') addHTMLElement('HTMLFormElement') addHTMLElement('HTMLFrameElement') @@ -172,8 +93,8 @@ addHTMLElement('HTMLHeadElement') addHTMLElement('HTMLHeadingElement') addHTMLElement('HTMLHtmlElement') addHTMLElement('HTMLHRElement') -addHTMLElement('HTMLIFrameElement', needsAbstract=['sandbox']) -addHTMLElement('HTMLImageElement', needsAbstract=['alt', 'src', 'useMap', 'isMap', 'width', 'height', 'name', 'align', 'hspace', 'vspace', 'longDesc', 'border']) +addHTMLElement('HTMLIFrameElement') +addHTMLElement('HTMLImageElement') addHTMLElement('HTMLInputElement') addHTMLElement('HTMLLabelElement') addHTMLElement('HTMLLegendElement') @@ -195,7 +116,7 @@ addHTMLElement('HTMLParamElement') addHTMLElement('HTMLPreElement') addHTMLElement('HTMLProgressElement') addHTMLElement('HTMLQuoteElement') -addHTMLElement('HTMLScriptElement', needsAbstract=['src']) +addHTMLElement('HTMLScriptElement') addHTMLElement('HTMLSelectElement') addHTMLElement('HTMLSourceElement') addHTMLElement('HTMLSpanElement') diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index a8b75a75456..f73de0ea365 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -2494,12 +2494,6 @@ class CGSpecializedMethod(CGAbstractExternMethod): nativeName = MakeNativeName(name) extraPre = '' argsPre = [] - if name in self.descriptor.needsAbstract: - abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType) - extraPre = """ let mut abstract_this = %s::from_raw(this); - let abstract_this = abstract_this.root(&roots); -""" % abstractName - argsPre = ['&mut abstract_this.root_ref()'] return CGWrapper(CGMethodCall(argsPre, nativeName, self.method.isStatic(), self.descriptor, self.method), pre=extraPre + @@ -2552,12 +2546,6 @@ class CGSpecializedGetter(CGAbstractExternMethod): infallible = ('infallible' in self.descriptor.getExtendedAttributes(self.attr, getter=True)) - if name in self.descriptor.needsAbstract: - abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType) - extraPre = """ let mut abstract_this = %s::from_raw(this); - let abstract_this = abstract_this.root(&roots); -""" % abstractName - argsPre = ['&mut abstract_this.root_ref()'] if self.attr.type.nullable() or not infallible: nativeName = "Get" + nativeName return CGWrapper(CGIndenter(CGGetterCall(argsPre, self.attr.type, nativeName, @@ -2614,12 +2602,6 @@ class CGSpecializedSetter(CGAbstractExternMethod): nativeName = "Set" + MakeNativeName(name) argsPre = [] extraPre = '' - if name in self.descriptor.needsAbstract: - abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType) - extraPre = """ let mut abstract_this = %s::from_raw(this); - let abstract_this = abstract_this.root(&roots); -""" % abstractName - argsPre = ['&mut abstract_this.root_ref()'] return CGWrapper(CGIndenter(CGSetterCall(argsPre, self.attr.type, nativeName, self.descriptor, self.attr)), pre=extraPre + diff --git a/src/components/script/dom/bindings/codegen/Configuration.py b/src/components/script/dom/bindings/codegen/Configuration.py index eedb200c75e..48570a05476 100644 --- a/src/components/script/dom/bindings/codegen/Configuration.py +++ b/src/components/script/dom/bindings/codegen/Configuration.py @@ -136,7 +136,6 @@ class Descriptor(DescriptorProvider): self.returnType = "Unrooted<%s>" % ifaceName self.nativeType = desc.get('nativeType', nativeTypeDefault) self.concreteType = desc.get('concreteType', ifaceName) - self.needsAbstract = desc.get('needsAbstract', []) self.createGlobal = desc.get('createGlobal', False) self.register = desc.get('register', True) self.outerObjectHook = desc.get('outerObjectHook', 'None') diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index f435b6186af..e9f237999a7 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -27,8 +27,8 @@ use dom::htmlheadelement::HTMLHeadElement; use dom::htmlhtmlelement::HTMLHtmlElement; use dom::htmltitleelement::HTMLTitleElement; use dom::mouseevent::MouseEvent; -use dom::node::{Node, ElementNodeTypeId, DocumentNodeTypeId, NodeHelpers, AppendChild}; -use dom::node::{CloneChildren, DoNotCloneChildren, RemoveChild, ReplaceChild}; +use dom::node::{Node, ElementNodeTypeId, DocumentNodeTypeId, NodeHelpers, NodeMethods}; +use dom::node::{CloneChildren, DoNotCloneChildren}; use dom::nodelist::NodeList; use dom::text::Text; use dom::processinginstruction::ProcessingInstruction; @@ -165,7 +165,7 @@ impl Document { /// Remove any existing association between the provided id and any elements in this document. pub fn unregister_named_element(&mut self, - abstract_self: &JSRef, + to_unregister: &JSRef, id: DOMString) { let roots = RootCollection::new(); let mut is_empty = false; @@ -174,7 +174,7 @@ impl Document { Some(elements) => { let position = elements.iter() .map(|elem| elem.root(&roots)) - .position(|element| &*element == abstract_self) + .position(|element| &*element == to_unregister) .expect("This element should be in registered."); elements.remove(position); is_empty = elements.is_empty(); @@ -282,37 +282,35 @@ pub trait DocumentMethods { fn ContentType(&self) -> DOMString; fn GetDoctype(&self) -> Option>; fn GetDocumentElement(&self) -> Option>; - fn GetElementsByTagName(&self, abstract_self: &JSRef, tag_name: DOMString) -> Unrooted; - fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, tag_name: DOMString) -> Unrooted; - fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> Unrooted; + fn GetElementsByTagName(&self, tag_name: DOMString) -> Unrooted; + fn GetElementsByTagNameNS(&self, maybe_ns: Option, tag_name: DOMString) -> Unrooted; + fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted; fn GetElementById(&self, id: DOMString) -> Option>; - fn CreateElement(&self, abstract_self: &JSRef, local_name: DOMString) -> Fallible>; - fn CreateElementNS(&self, abstract_self: &JSRef, - namespace: Option, - qualified_name: DOMString) -> Fallible>; - fn CreateDocumentFragment(&self, abstract_self: &JSRef) -> Unrooted; - fn CreateTextNode(&self, abstract_self: &JSRef, data: DOMString) -> Unrooted; - fn CreateComment(&self, abstract_self: &JSRef, data: DOMString) -> Unrooted; - fn CreateProcessingInstruction(&self, abstract_self: &JSRef, target: DOMString, data: DOMString) -> Fallible>; - fn ImportNode(&self, abstract_self: &JSRef, node: &JSRef, deep: bool) -> Fallible>; - fn AdoptNode(&self, abstract_self: &JSRef, node: &mut JSRef) -> Fallible>; + fn CreateElement(&self, local_name: DOMString) -> Fallible>; + fn CreateElementNS(&self, namespace: Option, qualified_name: DOMString) -> Fallible>; + fn CreateDocumentFragment(&self) -> Unrooted; + fn CreateTextNode(&self, data: DOMString) -> Unrooted; + fn CreateComment(&self, data: DOMString) -> Unrooted; + fn CreateProcessingInstruction(&self, target: DOMString, data: DOMString) -> Fallible>; + fn ImportNode(&self, node: &JSRef, deep: bool) -> Fallible>; + fn AdoptNode(&self, node: &mut JSRef) -> Fallible>; fn CreateEvent(&self, interface: DOMString) -> Fallible>; - fn Title(&self, _: &JSRef) -> DOMString; - fn SetTitle(&self, abstract_self: &JSRef, title: DOMString) -> ErrorResult; + fn Title(&self) -> DOMString; + fn SetTitle(&self, title: DOMString) -> ErrorResult; fn GetHead(&self) -> Option>; - fn GetBody(&self, _: &JSRef) -> Option>; - fn SetBody(&self, abstract_self: &JSRef, new_body: Option>) -> ErrorResult; + fn GetBody(&self) -> Option>; + fn SetBody(&self, new_body: Option>) -> ErrorResult; fn GetElementsByName(&self, name: DOMString) -> Unrooted; - fn Images(&self, abstract_self: &JSRef) -> Unrooted; - fn Embeds(&self, abstract_self: &JSRef) -> Unrooted; - fn Plugins(&self, abstract_self: &JSRef) -> Unrooted; - fn Links(&self, abstract_self: &JSRef) -> Unrooted; - fn Forms(&self, abstract_self: &JSRef) -> Unrooted; - fn Scripts(&self, abstract_self: &JSRef) -> Unrooted; - fn Anchors(&self, abstract_self: &JSRef) -> Unrooted; - fn Applets(&self, abstract_self: &JSRef) -> Unrooted; - fn Location(&mut self, _abstract_self: &JSRef) -> Unrooted; - fn Children(&self, abstract_self: &JSRef) -> Unrooted; + fn Images(&self) -> Unrooted; + fn Embeds(&self) -> Unrooted; + fn Plugins(&self) -> Unrooted; + fn Links(&self) -> Unrooted; + fn Forms(&self) -> Unrooted; + fn Scripts(&self) -> Unrooted; + fn Anchors(&self) -> Unrooted; + fn Applets(&self) -> Unrooted; + fn Location(&mut self) -> Unrooted; + fn Children(&self) -> Unrooted; } impl<'a> DocumentMethods for JSRef<'a, Document> { @@ -370,14 +368,14 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://dom.spec.whatwg.org/#dom-document-getelementsbytagname - fn GetElementsByTagName(&self, abstract_self: &JSRef, tag_name: DOMString) -> Unrooted { + fn GetElementsByTagName(&self, tag_name: DOMString) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); - HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(abstract_self), tag_name) + HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(self), tag_name) } // http://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens - fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, tag_name: DOMString) -> Unrooted { + fn GetElementsByTagNameNS(&self, maybe_ns: Option, tag_name: DOMString) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -385,15 +383,15 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { Some(namespace) => Namespace::from_str(namespace), None => Null }; - HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(abstract_self), tag_name, namespace) + HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(self), tag_name, namespace) } // http://dom.spec.whatwg.org/#dom-document-getelementsbyclassname - fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> Unrooted { + fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); - HTMLCollection::by_class_name(&*window, NodeCast::from_ref(abstract_self), classes) + HTMLCollection::by_class_name(&*window, NodeCast::from_ref(self), classes) } // http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid @@ -405,18 +403,17 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://dom.spec.whatwg.org/#dom-document-createelement - fn CreateElement(&self, abstract_self: &JSRef, local_name: DOMString) - -> Fallible> { + fn CreateElement(&self, local_name: DOMString) -> Fallible> { if xml_name_type(local_name) == InvalidXMLName { debug!("Not a valid element name"); return Err(InvalidCharacter); } let local_name = local_name.to_ascii_lower(); - Ok(build_element_from_tag(local_name, abstract_self)) + Ok(build_element_from_tag(local_name, self)) } // http://dom.spec.whatwg.org/#dom-document-createelementns - fn CreateElementNS(&self, abstract_self: &JSRef, + fn CreateElementNS(&self, namespace: Option, qualified_name: DOMString) -> Fallible> { let ns = Namespace::from_str(null_str_as_empty_ref(&namespace)); @@ -455,30 +452,30 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } if ns == namespace::HTML { - Ok(build_element_from_tag(local_name_from_qname, abstract_self)) + Ok(build_element_from_tag(local_name_from_qname, self)) } else { - Ok(Element::new(local_name_from_qname, ns, prefix_from_qname, abstract_self)) + Ok(Element::new(local_name_from_qname, ns, prefix_from_qname, self)) } } // http://dom.spec.whatwg.org/#dom-document-createdocumentfragment - fn CreateDocumentFragment(&self, abstract_self: &JSRef) -> Unrooted { - DocumentFragment::new(abstract_self) + fn CreateDocumentFragment(&self) -> Unrooted { + DocumentFragment::new(self) } // http://dom.spec.whatwg.org/#dom-document-createtextnode - fn CreateTextNode(&self, abstract_self: &JSRef, data: DOMString) + fn CreateTextNode(&self, data: DOMString) -> Unrooted { - Text::new(data, abstract_self) + Text::new(data, self) } // http://dom.spec.whatwg.org/#dom-document-createcomment - fn CreateComment(&self, abstract_self: &JSRef, data: DOMString) -> Unrooted { - Comment::new(data, abstract_self) + fn CreateComment(&self, data: DOMString) -> Unrooted { + Comment::new(data, self) } // http://dom.spec.whatwg.org/#dom-document-createprocessinginstruction - fn CreateProcessingInstruction(&self, abstract_self: &JSRef, target: DOMString, + fn CreateProcessingInstruction(&self, target: DOMString, data: DOMString) -> Fallible> { // Step 1. if xml_name_type(target) == InvalidXMLName { @@ -491,11 +488,11 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // Step 3. - Ok(ProcessingInstruction::new(target, data, abstract_self)) + Ok(ProcessingInstruction::new(target, data, self)) } // http://dom.spec.whatwg.org/#dom-document-importnode - fn ImportNode(&self, abstract_self: &JSRef, node: &JSRef, deep: bool) -> Fallible> { + fn ImportNode(&self, node: &JSRef, deep: bool) -> Fallible> { // Step 1. if node.is_document() { return Err(NotSupported); @@ -507,18 +504,18 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { false => DoNotCloneChildren }; - Ok(Node::clone(node, Some(abstract_self), clone_children)) + Ok(Node::clone(node, Some(self), clone_children)) } // http://dom.spec.whatwg.org/#dom-document-adoptnode - fn AdoptNode(&self, abstract_self: &JSRef, node: &mut JSRef) -> Fallible> { + fn AdoptNode(&self, node: &mut JSRef) -> Fallible> { // Step 1. if node.is_document() { return Err(NotSupported); } // Step 2. - Node::adopt(node, abstract_self); + Node::adopt(node, self); // Step 3. Ok(Unrooted::new_rooted(node)) @@ -539,7 +536,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://www.whatwg.org/specs/web-apps/current-work/#document.title - fn Title(&self, _: &JSRef) -> DOMString { + fn Title(&self) -> DOMString { let mut title = ~""; let roots = RootCollection::new(); self.GetDocumentElement().root(&roots).map(|root| { @@ -561,7 +558,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://www.whatwg.org/specs/web-apps/current-work/#document.title - fn SetTitle(&self, abstract_self: &JSRef, title: DOMString) -> ErrorResult { + fn SetTitle(&self, title: DOMString) -> ErrorResult { let roots = RootCollection::new(); self.GetDocumentElement().root(&roots).map(|root| { @@ -577,20 +574,20 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { match title_node { Some(ref mut title_node) => { for mut title_child in title_node.children() { - assert!(RemoveChild(&mut *title_node, &mut title_child).is_ok()); + assert!(title_node.RemoveChild(&mut title_child).is_ok()); } - let mut new_text = self.CreateTextNode(abstract_self, title.clone()).root(&roots); + let mut new_text = self.CreateTextNode(title.clone()).root(&roots); - assert!(AppendChild(&mut *title_node, NodeCast::from_mut_ref(&mut *new_text)).is_ok()); + assert!(title_node.AppendChild(NodeCast::from_mut_ref(&mut *new_text)).is_ok()); }, None => { - let mut new_title = HTMLTitleElement::new(~"title", abstract_self).root(&roots); + let mut new_title = HTMLTitleElement::new(~"title", self).root(&roots); let new_title: &mut JSRef = NodeCast::from_mut_ref(&mut *new_title); - let mut new_text = self.CreateTextNode(abstract_self, title.clone()).root(&roots); + let mut new_text = self.CreateTextNode(title.clone()).root(&roots); - assert!(AppendChild(&mut *new_title, NodeCast::from_mut_ref(&mut *new_text)).is_ok()); - assert!(AppendChild(&mut *head, &mut *new_title).is_ok()); + assert!(new_title.AppendChild(NodeCast::from_mut_ref(&mut *new_text)).is_ok()); + assert!(head.AppendChild(&mut *new_title).is_ok()); }, } }); @@ -613,7 +610,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body - fn GetBody(&self, _: &JSRef) -> Option> { + fn GetBody(&self) -> Option> { let roots = RootCollection::new(); self.get_html_element().and_then(|root| { let root = root.root(&roots); @@ -631,7 +628,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body - fn SetBody(&self, abstract_self: &JSRef, new_body: Option>) -> ErrorResult { + fn SetBody(&self, new_body: Option>) -> ErrorResult { let roots = RootCollection::new(); // Step 1. @@ -646,7 +643,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // Step 2. - let mut old_body = self.GetBody(abstract_self).root(&roots); + let mut old_body = self.GetBody().root(&roots); //FIXME: covariant lifetime workaround. do not judge. if old_body.as_ref().map(|body| body.deref()) == new_body.as_ref().map(|a| &*a) { return Ok(()); @@ -665,9 +662,9 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { Some(ref mut child) => { let child: &mut JSRef = NodeCast::from_mut_ref(&mut **child); - assert!(ReplaceChild(&mut *root, new_body, child).is_ok()) + assert!(root.ReplaceChild(new_body, child).is_ok()) } - None => assert!(AppendChild(&mut *root, new_body).is_ok()) + None => assert!(root.AppendChild(new_body).is_ok()) }; } } @@ -690,7 +687,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { }) } - fn Images(&self, abstract_self: &JSRef) -> Unrooted { + fn Images(&self) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -702,10 +699,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } } let filter = ~ImagesFilter; - HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Embeds(&self, abstract_self: &JSRef) -> Unrooted { + fn Embeds(&self) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -717,15 +714,15 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } } let filter = ~EmbedsFilter; - HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Plugins(&self, abstract_self: &JSRef) -> Unrooted { + fn Plugins(&self) -> Unrooted { // FIXME: https://github.com/mozilla/servo/issues/1847 - self.Embeds(abstract_self) + self.Embeds() } - fn Links(&self, abstract_self: &JSRef) -> Unrooted { + fn Links(&self) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -738,10 +735,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } } let filter = ~LinksFilter; - HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Forms(&self, abstract_self: &JSRef) -> Unrooted { + fn Forms(&self) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -753,10 +750,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } } let filter = ~FormsFilter; - HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Scripts(&self, abstract_self: &JSRef) -> Unrooted { + fn Scripts(&self) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -768,10 +765,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } } let filter = ~ScriptsFilter; - HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Anchors(&self, abstract_self: &JSRef) -> Unrooted { + fn Anchors(&self) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -783,10 +780,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } } let filter = ~AnchorsFilter; - HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Applets(&self, abstract_self: &JSRef) -> Unrooted { + fn Applets(&self) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -798,19 +795,18 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } } let filter = ~AppletsFilter; - HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Location(&mut self, _abstract_self: &JSRef) -> Unrooted { + fn Location(&mut self) -> Unrooted { let roots = RootCollection::new(); let mut window = self.window.root(&roots); - let window_alias = self.window.root(&roots); - window.Location(&*window_alias) + window.Location() } - fn Children(&self, abstract_self: &JSRef) -> Unrooted { + fn Children(&self) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); - HTMLCollection::children(&*window, NodeCast::from_ref(abstract_self)) + HTMLCollection::children(&*window, NodeCast::from_ref(self)) } } diff --git a/src/components/script/dom/documentfragment.rs b/src/components/script/dom/documentfragment.rs index aee61d03b51..55e782406b3 100644 --- a/src/components/script/dom/documentfragment.rs +++ b/src/components/script/dom/documentfragment.rs @@ -49,13 +49,13 @@ impl DocumentFragment { } pub trait DocumentFragmentMethods { - fn Children(&self, abstract_self: &JSRef) -> Unrooted; + fn Children(&self) -> Unrooted; } impl<'a> DocumentFragmentMethods for JSRef<'a, DocumentFragment> { - fn Children(&self, abstract_self: &JSRef) -> Unrooted { + fn Children(&self) -> Unrooted { let roots = RootCollection::new(); - let window = window_from_node(abstract_self).root(&roots); - HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self)) + let window = window_from_node(self).root(&roots); + HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(self)) } } diff --git a/src/components/script/dom/domimplementation.rs b/src/components/script/dom/domimplementation.rs index a8f889ddd8c..e339485fbd9 100644 --- a/src/components/script/dom/domimplementation.rs +++ b/src/components/script/dom/domimplementation.rs @@ -14,7 +14,7 @@ use dom::htmlbodyelement::HTMLBodyElement; use dom::htmlheadelement::HTMLHeadElement; use dom::htmlhtmlelement::HTMLHtmlElement; use dom::htmltitleelement::HTMLTitleElement; -use dom::node::{Node, AppendChild}; +use dom::node::{Node, NodeMethods}; use dom::text::Text; use dom::window::{Window, WindowMethods}; use servo_util::str::DOMString; @@ -87,7 +87,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { let mut maybe_elem = if qname.is_empty() { None } else { - match doc.deref().CreateElementNS(&*doc, namespace, qname) { + match doc.CreateElementNS(namespace, qname) { Err(error) => return Err(error), Ok(elem) => Some(elem) } @@ -100,7 +100,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { match maybe_doctype { None => (), Some(ref mut doctype) => { - assert!(AppendChild(doc_node, NodeCast::from_mut_ref(doctype)).is_ok()) + assert!(doc_node.AppendChild(NodeCast::from_mut_ref(doctype)).is_ok()) } } @@ -108,7 +108,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { match maybe_elem.root(&roots) { None => (), Some(mut elem) => { - assert!(AppendChild(doc_node, NodeCast::from_mut_ref(&mut *elem)).is_ok()) + assert!(doc_node.AppendChild(NodeCast::from_mut_ref(&mut *elem)).is_ok()) } } } @@ -133,18 +133,18 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { { // Step 3. let mut doc_type = DocumentType::new(~"html", None, None, &*doc).root(&roots); - assert!(AppendChild(&mut *doc_node, NodeCast::from_mut_ref(&mut *doc_type)).is_ok()); + assert!(doc_node.AppendChild(NodeCast::from_mut_ref(&mut *doc_type)).is_ok()); } { // Step 4. let mut doc_html = NodeCast::from_unrooted(HTMLHtmlElement::new(~"html", &*doc)).root(&roots); - assert!(AppendChild(&mut *doc_node, &mut *doc_html).is_ok()); + assert!(doc_node.AppendChild(&mut *doc_html).is_ok()); { // Step 5. let mut doc_head = NodeCast::from_unrooted(HTMLHeadElement::new(~"head", &*doc)).root(&roots); - assert!(AppendChild(&mut *doc_html, &mut *doc_head).is_ok()); + assert!(doc_html.AppendChild(&mut *doc_head).is_ok()); // Step 6. match title { @@ -152,18 +152,18 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { Some(title_str) => { // Step 6.1. let mut doc_title = NodeCast::from_unrooted(HTMLTitleElement::new(~"title", &*doc)).root(&roots); - assert!(AppendChild(&mut *doc_head, &mut *doc_title).is_ok()); + assert!(doc_head.AppendChild(&mut *doc_title).is_ok()); // Step 6.2. let mut title_text = Text::new(title_str, &*doc).root(&roots); - assert!(AppendChild(&mut *doc_title, NodeCast::from_mut_ref(&mut *title_text)).is_ok()); + assert!(doc_title.AppendChild(NodeCast::from_mut_ref(&mut *title_text)).is_ok()); } } } // Step 7. let mut doc_body = HTMLBodyElement::new(~"body", &*doc).root(&roots); - assert!(AppendChild(&mut *doc_html, NodeCast::from_mut_ref(&mut *doc_body)).is_ok()); + assert!(doc_html.AppendChild(NodeCast::from_mut_ref(&mut *doc_body)).is_ok()); } // Step 8. diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index 2a66aec0221..200ed604777 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -198,9 +198,6 @@ pub trait AttributeHandlers { fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString, name: DOMString, namespace: Namespace, prefix: Option, cb: |&JSRef| -> bool); - fn SetAttribute_(&mut self, name: DOMString, value: DOMString) -> ErrorResult; - fn SetAttributeNS_(&mut self, namespace_url: Option, - name: DOMString, value: DOMString) -> ErrorResult; fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult; fn notify_attribute_changed(&self, local_name: DOMString); @@ -281,100 +278,10 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { self.get_mut().attrs.get(idx).root(&roots).set_value(set_type, value); } - // http://dom.spec.whatwg.org/#dom-element-setattribute - fn SetAttribute_(&mut self, name: DOMString, value: DOMString) -> ErrorResult { - { - let node: &JSRef = NodeCast::from_ref(self); - node.get().wait_until_safe_to_modify_dom(); - } - - // Step 1. - match xml_name_type(name) { - InvalidXMLName => return Err(InvalidCharacter), - _ => {} - } - - // Step 2. - let name = if self.get().html_element_in_html_document() { - name.to_ascii_lower() - } else { - name - }; - - // Step 3-5. - self.do_set_attribute(name.clone(), value, name.clone(), namespace::Null, None, |attr| { - attr.get().name == name - }); - Ok(()) - } - - fn SetAttributeNS_(&mut self, namespace_url: Option, - name: DOMString, value: DOMString) -> ErrorResult { - { - let node: &JSRef = NodeCast::from_ref(self); - node.get().wait_until_safe_to_modify_dom(); - } - - // Step 1. - let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace_url)); - - let name_type = xml_name_type(name); - match name_type { - // Step 2. - InvalidXMLName => return Err(InvalidCharacter), - // Step 3. - Name => return Err(NamespaceError), - QName => {} - } - - // Step 4. - let (prefix, local_name) = get_attribute_parts(name.clone()); - match prefix { - Some(ref prefix_str) => { - // Step 5. - if namespace == namespace::Null { - return Err(NamespaceError); - } - - // Step 6. - if "xml" == prefix_str.as_slice() && namespace != namespace::XML { - return Err(NamespaceError); - } - - // Step 7b. - if "xmlns" == prefix_str.as_slice() && namespace != namespace::XMLNS { - return Err(NamespaceError); - } - }, - None => {} - } - - // Step 7a. - if "xmlns" == name && namespace != namespace::XMLNS { - return Err(NamespaceError); - } - - // Step 8. - if namespace == namespace::XMLNS && "xmlns" != name && Some(~"xmlns") != prefix { - return Err(NamespaceError); - } - - // Step 9. - self.do_set_attribute(local_name.clone(), value, name, namespace.clone(), prefix, |attr| { - attr.get().local_name == local_name && - attr.get().namespace == namespace - }); - Ok(()) - } - fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult { let roots = RootCollection::new(); let (_, local_name) = get_attribute_parts(name.clone()); - let self_alias = self.clone(); - let node: &JSRef = NodeCast::from_ref(&self_alias); - node.wait_until_safe_to_modify_dom(); - let idx = self.get().attrs.iter().map(|attr| attr.root(&roots)).position(|attr| { attr.local_name == local_name }); @@ -382,9 +289,14 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { match idx { None => (), Some(idx) => { + { + let node: &JSRef = NodeCast::from_ref(self); + node.wait_until_safe_to_modify_dom(); + } + if namespace == namespace::Null { let removed_raw_value = self.get().attrs.get(idx).root(&roots).Value(); - vtable_for(node).before_remove_attr(local_name.clone(), removed_raw_value); + vtable_for(NodeCast::from_ref(self)).before_remove_attr(local_name.clone(), removed_raw_value); } self.get_mut().attrs.remove(idx); @@ -463,27 +375,27 @@ pub trait ElementMethods { fn LocalName(&self) -> DOMString; fn GetPrefix(&self) -> Option; fn TagName(&self) -> DOMString; - fn Id(&self, abstract_self: &JSRef) -> DOMString; - fn SetId(&mut self, abstract_self: &mut JSRef, id: DOMString); - fn ClassName(&self, abstract_self: &JSRef) -> DOMString; - fn SetClassName(&self, abstract_self: &mut JSRef, class: DOMString); - fn Attributes(&mut self, abstract_self: &JSRef) -> Unrooted; - fn GetAttribute(&self, abstract_self: &JSRef, name: DOMString) -> Option; - fn GetAttributeNS(&self, abstract_self: &JSRef, namespace: Option, local_name: DOMString) -> Option; - fn SetAttribute(&self, abstract_self: &mut JSRef, name: DOMString, value: DOMString) -> ErrorResult; - fn SetAttributeNS(&self, abstract_self: &mut JSRef, namespace_url: Option, name: DOMString, value: DOMString) -> ErrorResult; - fn RemoveAttribute(&mut self, abstract_self: &mut JSRef, name: DOMString) -> ErrorResult; - fn RemoveAttributeNS(&mut self, abstract_self: &mut JSRef, namespace: Option, localname: DOMString) -> ErrorResult; - fn HasAttribute(&self, abstract_self: &JSRef, name: DOMString) -> bool; - fn HasAttributeNS(&self, abstract_self: &JSRef, namespace: Option, local_name: DOMString) -> bool; - fn GetElementsByTagName(&self, abstract_self: &JSRef, localname: DOMString) -> Unrooted; - fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, localname: DOMString) -> Unrooted; - fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> Unrooted; - fn GetClientRects(&self, abstract_self: &JSRef) -> Unrooted; - fn GetBoundingClientRect(&self, abstract_self: &JSRef) -> Unrooted; - fn GetInnerHTML(&self, abstract_self: &JSRef) -> Fallible; - fn GetOuterHTML(&self, abstract_self: &JSRef) -> Fallible; - fn Children(&self, abstract_self: &JSRef) -> Unrooted; + fn Id(&self) -> DOMString; + fn SetId(&mut self, id: DOMString); + fn ClassName(&self) -> DOMString; + fn SetClassName(&mut self, class: DOMString); + fn Attributes(&mut self) -> Unrooted; + fn GetAttribute(&self, name: DOMString) -> Option; + fn GetAttributeNS(&self, namespace: Option, local_name: DOMString) -> Option; + fn SetAttribute(&mut self, name: DOMString, value: DOMString) -> ErrorResult; + fn SetAttributeNS(&mut self, namespace_url: Option, name: DOMString, value: DOMString) -> ErrorResult; + fn RemoveAttribute(&mut self, name: DOMString) -> ErrorResult; + fn RemoveAttributeNS(&mut self, namespace: Option, localname: DOMString) -> ErrorResult; + fn HasAttribute(&self, name: DOMString) -> bool; + fn HasAttributeNS(&self, namespace: Option, local_name: DOMString) -> bool; + fn GetElementsByTagName(&self, localname: DOMString) -> Unrooted; + fn GetElementsByTagNameNS(&self, maybe_ns: Option, localname: DOMString) -> Unrooted; + fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted; + fn GetClientRects(&self) -> Unrooted; + fn GetBoundingClientRect(&self) -> Unrooted; + fn GetInnerHTML(&self) -> Fallible; + fn GetOuterHTML(&self) -> Fallible; + fn Children(&self) -> Unrooted; } impl<'a> ElementMethods for JSRef<'a, Element> { @@ -514,27 +426,27 @@ impl<'a> ElementMethods for JSRef<'a, Element> { } // http://dom.spec.whatwg.org/#dom-element-id - fn Id(&self, abstract_self: &JSRef) -> DOMString { - abstract_self.get_string_attribute("id") + fn Id(&self) -> DOMString { + self.get_string_attribute("id") } // http://dom.spec.whatwg.org/#dom-element-id - fn SetId(&mut self, abstract_self: &mut JSRef, id: DOMString) { - abstract_self.set_string_attribute("id", id); + fn SetId(&mut self, id: DOMString) { + self.set_string_attribute("id", id); } // http://dom.spec.whatwg.org/#dom-element-classname - fn ClassName(&self, abstract_self: &JSRef) -> DOMString { - abstract_self.get_string_attribute("class") + fn ClassName(&self) -> DOMString { + self.get_string_attribute("class") } // http://dom.spec.whatwg.org/#dom-element-classname - fn SetClassName(&self, abstract_self: &mut JSRef, class: DOMString) { - abstract_self.set_string_attribute("class", class); + fn SetClassName(&mut self, class: DOMString) { + self.set_string_attribute("class", class); } // http://dom.spec.whatwg.org/#dom-element-attributes - fn Attributes(&mut self, abstract_self: &JSRef) -> Unrooted { + fn Attributes(&mut self) -> Unrooted { let roots = RootCollection::new(); match self.attr_list { None => (), @@ -543,111 +455,184 @@ impl<'a> ElementMethods for JSRef<'a, Element> { let doc = self.node.owner_doc().root(&roots); let window = doc.deref().window.root(&roots); - let list = AttrList::new(&window.root_ref(), abstract_self); + let list = AttrList::new(&*window, self); self.attr_list.assign(Some(list)); Unrooted::new(self.attr_list.get_ref().clone()) } // http://dom.spec.whatwg.org/#dom-element-getattribute - fn GetAttribute(&self, abstract_self: &JSRef, name: DOMString) -> Option { + fn GetAttribute(&self, name: DOMString) -> Option { let roots = RootCollection::new(); - let name = if abstract_self.get().html_element_in_html_document() { + let name = if self.get().html_element_in_html_document() { name.to_ascii_lower() } else { name }; - abstract_self.get_attribute(Null, name).root(&roots) + self.get_attribute(Null, name).root(&roots) .map(|s| s.deref().Value()) } // http://dom.spec.whatwg.org/#dom-element-getattributens - fn GetAttributeNS(&self, abstract_self: &JSRef, - namespace: Option, - local_name: DOMString) -> Option { + fn GetAttributeNS(&self, + namespace: Option, + local_name: DOMString) -> Option { let roots = RootCollection::new(); let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace)); - abstract_self.get_attribute(namespace, local_name).root(&roots) + self.get_attribute(namespace, local_name).root(&roots) .map(|attr| attr.deref().Value()) } // http://dom.spec.whatwg.org/#dom-element-setattribute - fn SetAttribute(&self, abstract_self: &mut JSRef, + fn SetAttribute(&mut self, name: DOMString, value: DOMString) -> ErrorResult { - abstract_self.SetAttribute_(name, value) + { + let node: &JSRef = NodeCast::from_ref(self); + node.get().wait_until_safe_to_modify_dom(); + } + + // Step 1. + match xml_name_type(name) { + InvalidXMLName => return Err(InvalidCharacter), + _ => {} + } + + // Step 2. + let name = if self.get().html_element_in_html_document() { + name.to_ascii_lower() + } else { + name + }; + + // Step 3-5. + self.do_set_attribute(name.clone(), value, name.clone(), namespace::Null, None, |attr| { + attr.get().name == name + }); + Ok(()) } // http://dom.spec.whatwg.org/#dom-element-setattributens - fn SetAttributeNS(&self, - abstract_self: &mut JSRef, + fn SetAttributeNS(&mut self, namespace_url: Option, name: DOMString, value: DOMString) -> ErrorResult { - abstract_self.SetAttributeNS_(namespace_url, name, value) + { + let node: &JSRef = NodeCast::from_ref(self); + node.get().wait_until_safe_to_modify_dom(); + } + + // Step 1. + let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace_url)); + + let name_type = xml_name_type(name); + match name_type { + // Step 2. + InvalidXMLName => return Err(InvalidCharacter), + // Step 3. + Name => return Err(NamespaceError), + QName => {} + } + + // Step 4. + let (prefix, local_name) = get_attribute_parts(name.clone()); + match prefix { + Some(ref prefix_str) => { + // Step 5. + if namespace == namespace::Null { + return Err(NamespaceError); + } + + // Step 6. + if "xml" == prefix_str.as_slice() && namespace != namespace::XML { + return Err(NamespaceError); + } + + // Step 7b. + if "xmlns" == prefix_str.as_slice() && namespace != namespace::XMLNS { + return Err(NamespaceError); + } + }, + None => {} + } + + // Step 7a. + if "xmlns" == name && namespace != namespace::XMLNS { + return Err(NamespaceError); + } + + // Step 8. + if namespace == namespace::XMLNS && "xmlns" != name && Some(~"xmlns") != prefix { + return Err(NamespaceError); + } + + // Step 9. + self.do_set_attribute(local_name.clone(), value, name, namespace.clone(), prefix, |attr| { + attr.get().local_name == local_name && + attr.get().namespace == namespace + }); + Ok(()) } // http://dom.spec.whatwg.org/#dom-element-removeattribute fn RemoveAttribute(&mut self, - abstract_self: &mut JSRef, name: DOMString) -> ErrorResult { let name = if self.html_element_in_html_document() { name.to_ascii_lower() } else { name }; - abstract_self.remove_attribute(namespace::Null, name) + self.remove_attribute(namespace::Null, name) } // http://dom.spec.whatwg.org/#dom-element-removeattributens fn RemoveAttributeNS(&mut self, - abstract_self: &mut JSRef, - namespace: Option, - localname: DOMString) -> ErrorResult { + namespace: Option, + localname: DOMString) -> ErrorResult { let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace)); - abstract_self.remove_attribute(namespace, localname) + self.remove_attribute(namespace, localname) } // http://dom.spec.whatwg.org/#dom-element-hasattribute - fn HasAttribute(&self, abstract_self: &JSRef, - name: DOMString) -> bool { - self.GetAttribute(abstract_self, name).is_some() + fn HasAttribute(&self, + name: DOMString) -> bool { + self.GetAttribute(name).is_some() } // http://dom.spec.whatwg.org/#dom-element-hasattributens - fn HasAttributeNS(&self, abstract_self: &JSRef, - namespace: Option, - local_name: DOMString) -> bool { - self.GetAttributeNS(abstract_self, namespace, local_name).is_some() + fn HasAttributeNS(&self, + namespace: Option, + local_name: DOMString) -> bool { + self.GetAttributeNS(namespace, local_name).is_some() } - fn GetElementsByTagName(&self, abstract_self: &JSRef, localname: DOMString) -> Unrooted { + fn GetElementsByTagName(&self, localname: DOMString) -> Unrooted { let roots = RootCollection::new(); - let window = window_from_node(abstract_self).root(&roots); - HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(abstract_self), localname) + let window = window_from_node(self).root(&roots); + HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(self), localname) } - fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, - localname: DOMString) -> Unrooted { + fn GetElementsByTagNameNS(&self, maybe_ns: Option, + localname: DOMString) -> Unrooted { let roots = RootCollection::new(); let namespace = match maybe_ns { Some(namespace) => Namespace::from_str(namespace), None => Null }; - let window = window_from_node(abstract_self).root(&roots); - HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(abstract_self), localname, namespace) + let window = window_from_node(self).root(&roots); + HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(self), localname, namespace) } - fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> Unrooted { + fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted { let roots = RootCollection::new(); - let window = window_from_node(abstract_self).root(&roots); - HTMLCollection::by_class_name(&*window, NodeCast::from_ref(abstract_self), classes) + let window = window_from_node(self).root(&roots); + HTMLCollection::by_class_name(&*window, NodeCast::from_ref(self), classes) } // http://dev.w3.org/csswg/cssom-view/#dom-element-getclientrects - fn GetClientRects(&self, abstract_self: &JSRef) -> Unrooted { + fn GetClientRects(&self) -> Unrooted { let roots = RootCollection::new(); - let win = window_from_node(abstract_self).root(&roots); - let node: &JSRef = NodeCast::from_ref(abstract_self); + let win = window_from_node(self).root(&roots); + let node: &JSRef = NodeCast::from_ref(self); let rects = node.get_content_boxes(); let rects: ~[Root] = rects.iter().map(|r| { ClientRect::new( @@ -662,10 +647,10 @@ impl<'a> ElementMethods for JSRef<'a, Element> { } // http://dev.w3.org/csswg/cssom-view/#dom-element-getboundingclientrect - fn GetBoundingClientRect(&self, abstract_self: &JSRef) -> Unrooted { + fn GetBoundingClientRect(&self) -> Unrooted { let roots = RootCollection::new(); - let win = window_from_node(abstract_self).root(&roots); - let node: &JSRef = NodeCast::from_ref(abstract_self); + let win = window_from_node(self).root(&roots); + let node: &JSRef = NodeCast::from_ref(self); let rect = node.get_bounding_content_box(); ClientRect::new( &*win, @@ -675,21 +660,21 @@ impl<'a> ElementMethods for JSRef<'a, Element> { rect.origin.x + rect.size.width) } - fn GetInnerHTML(&self, abstract_self: &JSRef) -> Fallible { + fn GetInnerHTML(&self) -> Fallible { //XXX TODO: XML case let roots = RootCollection::new(); - Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(abstract_self), false, false))) + Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(self), false, false))) } - fn GetOuterHTML(&self, abstract_self: &JSRef) -> Fallible { + fn GetOuterHTML(&self) -> Fallible { let roots = RootCollection::new(); - Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(abstract_self), true, false))) + Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(self), true, false))) } - fn Children(&self, abstract_self: &JSRef) -> Unrooted { + fn Children(&self) -> Unrooted { let roots = RootCollection::new(); - let window = window_from_node(abstract_self).root(&roots); - HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self)) + let window = window_from_node(self).root(&roots); + HTMLCollection::children(&*window, NodeCast::from_ref(self)) } } diff --git a/src/components/script/dom/eventdispatcher.rs b/src/components/script/dom/eventdispatcher.rs index a70533da2a1..1e0097bbdc4 100644 --- a/src/components/script/dom/eventdispatcher.rs +++ b/src/components/script/dom/eventdispatcher.rs @@ -10,15 +10,18 @@ use dom::event::{Event, PhaseAtTarget, PhaseNone, PhaseBubbling, PhaseCapturing, use dom::node::{Node, NodeHelpers}; // See http://dom.spec.whatwg.org/#concept-event-dispatch for the full dispatch algorithm -pub fn dispatch_event<'a>(target: &JSRef<'a, EventTarget>, - pseudo_target: Option>, - event: &mut JSRef) -> bool { +pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>, + pseudo_target: Option>, + event: &mut JSRef) -> bool { let roots = RootCollection::new(); assert!(!event.get().dispatching); { let event = event.get_mut(); - event.target.assign(Some(pseudo_target.unwrap_or(target.clone()))); + match pseudo_target { + Some(pseudo_target) => event.target.assign(Some(pseudo_target)), + None => event.target.assign(Some(target.clone())), + } event.dispatching = true; } diff --git a/src/components/script/dom/eventtarget.rs b/src/components/script/dom/eventtarget.rs index d743a011227..9cd9c5484f2 100644 --- a/src/components/script/dom/eventtarget.rs +++ b/src/components/script/dom/eventtarget.rs @@ -64,15 +64,22 @@ impl EventTarget { filtered.map(|entry| entry.listener).collect() }) } +} - pub fn dispatch_event_with_target<'a>(&self, - abstract_self: &JSRef<'a, EventTarget>, - abstract_target: Option>, - event: &mut JSRef) -> Fallible { +pub trait EventTargetHelpers { + fn dispatch_event_with_target<'a>(&self, + target: Option>, + event: &mut JSRef) -> Fallible; +} + +impl<'a> EventTargetHelpers for JSRef<'a, EventTarget> { + fn dispatch_event_with_target<'b>(&self, + target: Option>, + event: &mut JSRef) -> Fallible { if event.get().dispatching || !event.get().initialized { return Err(InvalidState); } - Ok(dispatch_event(abstract_self, abstract_target, event)) + Ok(dispatch_event(self, target, event)) } } @@ -85,8 +92,7 @@ pub trait EventTargetMethods { ty: DOMString, listener: Option, capture: bool); - fn DispatchEvent(&self, abstract_self: &JSRef, - event: &mut JSRef) -> Fallible; + fn DispatchEvent(&self, event: &mut JSRef) -> Fallible; } impl<'a> EventTargetMethods for JSRef<'a, EventTarget> { @@ -127,9 +133,8 @@ impl<'a> EventTargetMethods for JSRef<'a, EventTarget> { } } - fn DispatchEvent(&self, abstract_self: &JSRef, - event: &mut JSRef) -> Fallible { - self.dispatch_event_with_target(abstract_self, None, event) + fn DispatchEvent(&self, event: &mut JSRef) -> Fallible { + self.dispatch_event_with_target(None, event) } } diff --git a/src/components/script/dom/htmldatalistelement.rs b/src/components/script/dom/htmldatalistelement.rs index 9fcb291ae4f..ae5dbfbef9e 100644 --- a/src/components/script/dom/htmldatalistelement.rs +++ b/src/components/script/dom/htmldatalistelement.rs @@ -41,11 +41,11 @@ impl HTMLDataListElement { } pub trait HTMLDataListElementMethods { - fn Options(&self, abstract_self: &JSRef) -> Unrooted; + fn Options(&self) -> Unrooted; } impl<'a> HTMLDataListElementMethods for JSRef<'a, HTMLDataListElement> { - fn Options(&self, abstract_self: &JSRef) -> Unrooted { + fn Options(&self) -> Unrooted { struct HTMLDataListOptionsFilter; impl CollectionFilter for HTMLDataListOptionsFilter { fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { @@ -53,7 +53,7 @@ impl<'a> HTMLDataListElementMethods for JSRef<'a, HTMLDataListElement> { } } let roots = RootCollection::new(); - let node: &JSRef = NodeCast::from_ref(abstract_self); + let node: &JSRef = NodeCast::from_ref(self); let filter = ~HTMLDataListOptionsFilter; let window = window_from_node(node).root(&roots); HTMLCollection::create(&*window, node, filter) diff --git a/src/components/script/dom/htmlfieldsetelement.rs b/src/components/script/dom/htmlfieldsetelement.rs index 4f3d06d987c..ef42eb59990 100644 --- a/src/components/script/dom/htmlfieldsetelement.rs +++ b/src/components/script/dom/htmlfieldsetelement.rs @@ -50,7 +50,7 @@ pub trait HTMLFieldSetElementMethods { fn Name(&self) -> DOMString; fn SetName(&mut self, _name: DOMString) -> ErrorResult; fn Type(&self) -> DOMString; - fn Elements(&self, abstract_self: &JSRef) -> Unrooted; + fn Elements(&self) -> Unrooted; fn WillValidate(&self) -> bool; fn Validity(&self) -> Unrooted; fn ValidationMessage(&self) -> DOMString; @@ -84,7 +84,7 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> { } // http://www.whatwg.org/html/#dom-fieldset-elements - fn Elements(&self, abstract_self: &JSRef) -> Unrooted { + fn Elements(&self) -> Unrooted { struct ElementsFilter; impl CollectionFilter for ElementsFilter { fn filter(&self, elem: &JSRef, root: &JSRef) -> bool { @@ -95,7 +95,7 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> { } } let roots = RootCollection::new(); - let node: &JSRef = NodeCast::from_ref(abstract_self); + let node: &JSRef = NodeCast::from_ref(self); let filter = ~ElementsFilter; let window = window_from_node(node).root(&roots); HTMLCollection::create(&*window, node, filter) diff --git a/src/components/script/dom/htmliframeelement.rs b/src/components/script/dom/htmliframeelement.rs index 316468342f1..ee675390183 100644 --- a/src/components/script/dom/htmliframeelement.rs +++ b/src/components/script/dom/htmliframeelement.rs @@ -87,8 +87,8 @@ pub trait HTMLIFrameElementMethods { fn SetSrcdoc(&mut self, _srcdoc: DOMString) -> ErrorResult; fn Name(&self) -> DOMString; fn SetName(&mut self, _name: DOMString) -> ErrorResult; - fn Sandbox(&self, abstract_self: &JSRef) -> DOMString; - fn SetSandbox(&mut self, abstract_self: &mut JSRef, sandbox: DOMString); + fn Sandbox(&self) -> DOMString; + fn SetSandbox(&mut self, sandbox: DOMString); fn AllowFullscreen(&self) -> bool; fn SetAllowFullscreen(&mut self, _allow: bool) -> ErrorResult; fn Width(&self) -> DOMString; @@ -137,13 +137,13 @@ impl<'a> HTMLIFrameElementMethods for JSRef<'a, HTMLIFrameElement> { Ok(()) } - fn Sandbox(&self, abstract_self: &JSRef) -> DOMString { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn Sandbox(&self) -> DOMString { + let element: &JSRef = ElementCast::from_ref(self); element.get_string_attribute("sandbox") } - fn SetSandbox(&mut self, abstract_self: &mut JSRef, sandbox: DOMString) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetSandbox(&mut self, sandbox: DOMString) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_string_attribute("sandbox", sandbox); } diff --git a/src/components/script/dom/htmlimageelement.rs b/src/components/script/dom/htmlimageelement.rs index efe6a0401d6..39c854c1c05 100644 --- a/src/components/script/dom/htmlimageelement.rs +++ b/src/components/script/dom/htmlimageelement.rs @@ -80,55 +80,55 @@ impl HTMLImageElement { } pub trait HTMLImageElementMethods { - fn Alt(&self, abstract_self: &JSRef) -> DOMString; - fn SetAlt(&mut self, abstract_self: &mut JSRef, alt: DOMString); - fn Src(&self, abstract_self: &JSRef) -> DOMString; - fn SetSrc(&mut self, abstract_self: &mut JSRef, src: DOMString); + fn Alt(&self) -> DOMString; + fn SetAlt(&mut self, alt: DOMString); + fn Src(&self) -> DOMString; + fn SetSrc(&mut self, src: DOMString); fn CrossOrigin(&self) -> DOMString; fn SetCrossOrigin(&mut self, _cross_origin: DOMString) -> ErrorResult; - fn UseMap(&self, abstract_self: &JSRef) -> DOMString; - fn SetUseMap(&mut self, abstract_self: &mut JSRef, use_map: DOMString); - fn IsMap(&self, abstract_self: &JSRef) -> bool; - fn SetIsMap(&self, abstract_self: &mut JSRef, is_map: bool); - fn Width(&self, abstract_self: &JSRef) -> u32; - fn SetWidth(&mut self, abstract_self: &mut JSRef, width: u32); - fn Height(&self, abstract_self: &JSRef) -> u32; - fn SetHeight(&mut self, abstract_self: &mut JSRef, height: u32); + fn UseMap(&self) -> DOMString; + fn SetUseMap(&mut self, use_map: DOMString); + fn IsMap(&self) -> bool; + fn SetIsMap(&mut self, is_map: bool); + fn Width(&self) -> u32; + fn SetWidth(&mut self, width: u32); + fn Height(&self) -> u32; + fn SetHeight(&mut self, height: u32); fn NaturalWidth(&self) -> u32; fn NaturalHeight(&self) -> u32; fn Complete(&self) -> bool; - fn Name(&self, abstract_self: &JSRef) -> DOMString; - fn SetName(&mut self, abstract_self: &mut JSRef, name: DOMString); - fn Align(&self, abstract_self: &JSRef) -> DOMString; - fn SetAlign(&mut self, abstract_self: &mut JSRef, align: DOMString); - fn Hspace(&self, abstract_self: &JSRef) -> u32; - fn SetHspace(&mut self, abstract_self: &mut JSRef, hspace: u32); - fn Vspace(&self, abstract_self: &JSRef) -> u32; - fn SetVspace(&mut self, abstract_self: &mut JSRef, vspace: u32); - fn LongDesc(&self, abstract_self: &JSRef) -> DOMString; - fn SetLongDesc(&mut self, abstract_self: &mut JSRef, longdesc: DOMString); - fn Border(&self, abstract_self: &JSRef) -> DOMString; - fn SetBorder(&mut self, abstract_self: &mut JSRef, border: DOMString); + fn Name(&self) -> DOMString; + fn SetName(&mut self, name: DOMString); + fn Align(&self) -> DOMString; + fn SetAlign(&mut self, align: DOMString); + fn Hspace(&self) -> u32; + fn SetHspace(&mut self, hspace: u32); + fn Vspace(&self) -> u32; + fn SetVspace(&mut self, vspace: u32); + fn LongDesc(&self) -> DOMString; + fn SetLongDesc(&mut self, longdesc: DOMString); + fn Border(&self) -> DOMString; + fn SetBorder(&mut self, border: DOMString); } impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { - fn Alt(&self, abstract_self: &JSRef) -> DOMString { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn Alt(&self) -> DOMString { + let element: &JSRef = ElementCast::from_ref(self); element.get_string_attribute("alt") } - fn SetAlt(&mut self, abstract_self: &mut JSRef, alt: DOMString) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetAlt(&mut self, alt: DOMString) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_string_attribute("alt", alt) } - fn Src(&self, abstract_self: &JSRef) -> DOMString { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn Src(&self) -> DOMString { + let element: &JSRef = ElementCast::from_ref(self); element.get_string_attribute("src") } - fn SetSrc(&mut self, abstract_self: &mut JSRef, src: DOMString) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetSrc(&mut self, src: DOMString) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_url_attribute("src", src) } @@ -140,45 +140,45 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { Ok(()) } - fn UseMap(&self, abstract_self: &JSRef) -> DOMString { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn UseMap(&self) -> DOMString { + let element: &JSRef = ElementCast::from_ref(self); element.get_string_attribute("useMap") } - fn SetUseMap(&mut self, abstract_self: &mut JSRef, use_map: DOMString) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetUseMap(&mut self, use_map: DOMString) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_string_attribute("useMap", use_map) } - fn IsMap(&self, abstract_self: &JSRef) -> bool { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn IsMap(&self) -> bool { + let element: &JSRef = ElementCast::from_ref(self); from_str::(element.get_string_attribute("hspace")).unwrap() } - fn SetIsMap(&self, abstract_self: &mut JSRef, is_map: bool) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetIsMap(&mut self, is_map: bool) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_string_attribute("isMap", is_map.to_str()) } - fn Width(&self, abstract_self: &JSRef) -> u32 { - let node: &JSRef = NodeCast::from_ref(abstract_self); + fn Width(&self) -> u32 { + let node: &JSRef = NodeCast::from_ref(self); let rect = node.get_bounding_content_box(); to_px(rect.size.width) as u32 } - fn SetWidth(&mut self, abstract_self: &mut JSRef, width: u32) { - let elem: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetWidth(&mut self, width: u32) { + let elem: &mut JSRef = ElementCast::from_mut_ref(self); elem.set_uint_attribute("width", width) } - fn Height(&self, abstract_self: &JSRef) -> u32 { - let node: &JSRef = NodeCast::from_ref(abstract_self); + fn Height(&self) -> u32 { + let node: &JSRef = NodeCast::from_ref(self); let rect = node.get_bounding_content_box(); to_px(rect.size.height) as u32 } - fn SetHeight(&mut self, abstract_self: &mut JSRef, height: u32) { - let elem: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetHeight(&mut self, height: u32) { + let elem: &mut JSRef = ElementCast::from_mut_ref(self); elem.set_uint_attribute("height", height) } @@ -194,63 +194,63 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { false } - fn Name(&self, abstract_self: &JSRef) -> DOMString { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn Name(&self) -> DOMString { + let element: &JSRef = ElementCast::from_ref(self); element.get_string_attribute("name") } - fn SetName(&mut self, abstract_self: &mut JSRef, name: DOMString) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetName(&mut self, name: DOMString) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_string_attribute("name", name) } - fn Align(&self, abstract_self: &JSRef) -> DOMString { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn Align(&self) -> DOMString { + let element: &JSRef = ElementCast::from_ref(self); element.get_string_attribute("longdesc") } - fn SetAlign(&mut self, abstract_self: &mut JSRef, align: DOMString) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetAlign(&mut self, align: DOMString) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_string_attribute("align", align) } - fn Hspace(&self, abstract_self: &JSRef) -> u32 { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn Hspace(&self) -> u32 { + let element: &JSRef = ElementCast::from_ref(self); from_str::(element.get_string_attribute("hspace")).unwrap() } - fn SetHspace(&mut self, abstract_self: &mut JSRef, hspace: u32) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetHspace(&mut self, hspace: u32) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_uint_attribute("hspace", hspace) } - fn Vspace(&self, abstract_self: &JSRef) -> u32 { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn Vspace(&self) -> u32 { + let element: &JSRef = ElementCast::from_ref(self); from_str::(element.get_string_attribute("vspace")).unwrap() } - fn SetVspace(&mut self, abstract_self: &mut JSRef, vspace: u32) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetVspace(&mut self, vspace: u32) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_uint_attribute("vspace", vspace) } - fn LongDesc(&self, abstract_self: &JSRef) -> DOMString { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn LongDesc(&self) -> DOMString { + let element: &JSRef = ElementCast::from_ref(self); element.get_string_attribute("longdesc") } - fn SetLongDesc(&mut self, abstract_self: &mut JSRef, longdesc: DOMString) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetLongDesc(&mut self, longdesc: DOMString) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_string_attribute("longdesc", longdesc) } - fn Border(&self, abstract_self: &JSRef) -> DOMString { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn Border(&self) -> DOMString { + let element: &JSRef = ElementCast::from_ref(self); element.get_string_attribute("border") } - fn SetBorder(&mut self, abstract_self: &mut JSRef, border: DOMString) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetBorder(&mut self, border: DOMString) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_string_attribute("border", border) } } diff --git a/src/components/script/dom/htmlscriptelement.rs b/src/components/script/dom/htmlscriptelement.rs index fabe876a10f..4d7780d49f7 100644 --- a/src/components/script/dom/htmlscriptelement.rs +++ b/src/components/script/dom/htmlscriptelement.rs @@ -42,8 +42,8 @@ impl HTMLScriptElement { } pub trait HTMLScriptElementMethods { - fn Src(&self, abstract_self: &JSRef) -> DOMString; - fn SetSrc(&mut self, _abstract_self: &JSRef, _src: DOMString) -> ErrorResult; + fn Src(&self) -> DOMString; + fn SetSrc(&mut self, _src: DOMString) -> ErrorResult; fn Type(&self) -> DOMString; fn SetType(&mut self, _type: DOMString) -> ErrorResult; fn Charset(&self) -> DOMString; @@ -63,12 +63,12 @@ pub trait HTMLScriptElementMethods { } impl<'a> HTMLScriptElementMethods for JSRef<'a, HTMLScriptElement> { - fn Src(&self, abstract_self: &JSRef) -> DOMString { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn Src(&self) -> DOMString { + let element: &JSRef = ElementCast::from_ref(self); element.get_url_attribute("src") } - fn SetSrc(&mut self, _abstract_self: &JSRef, _src: DOMString) -> ErrorResult { + fn SetSrc(&mut self, _src: DOMString) -> ErrorResult { Ok(()) } diff --git a/src/components/script/dom/htmlstyleelement.rs b/src/components/script/dom/htmlstyleelement.rs index aac38920342..94255fe92a9 100644 --- a/src/components/script/dom/htmlstyleelement.rs +++ b/src/components/script/dom/htmlstyleelement.rs @@ -98,7 +98,7 @@ impl<'a> StyleElementHelpers for JSRef<'a, HTMLStyleElement> { let win = window_from_node(node).root(&roots); let url = win.get().page().get_url(); - let data = node.GetTextContent(node).expect("Element.textContent must be a string"); + let data = node.GetTextContent().expect("Element.textContent must be a string"); let sheet = parse_inline_css(url, data); let LayoutChan(ref layout_chan) = *win.get().page().layout_chan; layout_chan.send(AddStylesheetMsg(sheet)); diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index f3aefd223cc..aa444865bdb 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -224,21 +224,6 @@ pub enum NodeTypeId { ProcessingInstructionNodeTypeId, } -pub fn AppendChild<'a>(self_: &mut JSRef<'a, Node>, node: &mut JSRef) -> Fallible> { - let mut self_alias = self_.clone(); - self_.AppendChild(&mut self_alias, node) -} - -pub fn ReplaceChild<'a>(self_: &mut JSRef<'a, Node>, node: &mut JSRef, child: &mut JSRef) -> Fallible> { - let mut self_alias = self_.clone(); - self_.ReplaceChild(&mut self_alias, node, child) -} - -pub fn RemoveChild<'a>(self_: &mut JSRef<'a, Node>, node: &mut JSRef) -> Fallible> { - let mut self_alias = self_.clone(); - self_.RemoveChild(&mut self_alias, node) -} - pub trait NodeHelpers { fn ancestors(&self) -> AncestorIterator; fn children(&self) -> AbstractNodeChildrenIterator; @@ -1386,30 +1371,30 @@ impl Node { pub trait NodeMethods { fn NodeType(&self) -> u16; - fn NodeName(&self, abstract_self: &JSRef) -> DOMString; + fn NodeName(&self) -> DOMString; fn GetBaseURI(&self) -> Option; fn GetOwnerDocument(&self) -> Option>; fn GetParentNode(&self) -> Option>; fn GetParentElement(&self) -> Option>; fn HasChildNodes(&self) -> bool; - fn ChildNodes(&mut self, abstract_self: &JSRef) -> Unrooted; + fn ChildNodes(&mut self) -> Unrooted; fn GetFirstChild(&self) -> Option>; fn GetLastChild(&self) -> Option>; fn GetPreviousSibling(&self) -> Option>; fn GetNextSibling(&self) -> Option>; - fn GetNodeValue(&self, abstract_self: &JSRef) -> Option; - fn SetNodeValue(&mut self, abstract_self: &mut JSRef, val: Option) -> ErrorResult; - fn GetTextContent(&self, abstract_self: &JSRef) -> Option; - fn SetTextContent(&mut self, abstract_self: &mut JSRef, value: Option) -> ErrorResult; - fn InsertBefore(&self, abstract_self: &mut JSRef, node: &mut JSRef, child: Option>) -> Fallible>; - fn AppendChild(&self, abstract_self: &mut JSRef, node: &mut JSRef) -> Fallible>; - fn ReplaceChild(&self, parent: &mut JSRef, node: &mut JSRef, child: &mut JSRef) -> Fallible>; - fn RemoveChild(&self, abstract_self: &mut JSRef, node: &mut JSRef) -> Fallible>; - fn Normalize(&mut self, abstract_self: &mut JSRef); - fn CloneNode(&self, abstract_self: &mut JSRef, deep: bool) -> Unrooted; - fn IsEqualNode(&self, abstract_self: &JSRef, maybe_node: Option>) -> bool; - fn CompareDocumentPosition(&self, abstract_self: &JSRef, other: &JSRef) -> u16; - fn Contains(&self, abstract_self: &JSRef, maybe_other: Option>) -> bool; + fn GetNodeValue(&self) -> Option; + fn SetNodeValue(&mut self, val: Option) -> ErrorResult; + fn GetTextContent(&self) -> Option; + fn SetTextContent(&mut self, value: Option) -> ErrorResult; + fn InsertBefore(&mut self, node: &mut JSRef, child: Option>) -> Fallible>; + fn AppendChild(&mut self, node: &mut JSRef) -> Fallible>; + fn ReplaceChild(&mut self, node: &mut JSRef, child: &mut JSRef) -> Fallible>; + fn RemoveChild(&mut self, node: &mut JSRef) -> Fallible>; + fn Normalize(&mut self); + fn CloneNode(&self, deep: bool) -> Unrooted; + fn IsEqualNode(&self, maybe_node: Option>) -> bool; + fn CompareDocumentPosition(&self, other: &JSRef) -> u16; + fn Contains(&self, maybe_other: Option>) -> bool; fn LookupPrefix(&self, _prefix: Option) -> Option; fn LookupNamespaceURI(&self, _namespace: Option) -> Option; fn IsDefaultNamespace(&self, _namespace: Option) -> bool; @@ -1430,21 +1415,21 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-nodename - fn NodeName(&self, abstract_self: &JSRef) -> DOMString { + fn NodeName(&self) -> DOMString { match self.type_id { ElementNodeTypeId(..) => { - let elem: &JSRef = ElementCast::to_ref(abstract_self).unwrap(); + let elem: &JSRef = ElementCast::to_ref(self).unwrap(); elem.TagName() } TextNodeTypeId => ~"#text", ProcessingInstructionNodeTypeId => { let processing_instruction: &JSRef = - ProcessingInstructionCast::to_ref(abstract_self).unwrap(); + ProcessingInstructionCast::to_ref(self).unwrap(); processing_instruction.Target() } CommentNodeTypeId => ~"#comment", DoctypeNodeTypeId => { - let doctype: &JSRef = DocumentTypeCast::to_ref(abstract_self).unwrap(); + let doctype: &JSRef = DocumentTypeCast::to_ref(self).unwrap(); doctype.get().name.clone() }, DocumentFragmentNodeTypeId => ~"#document-fragment", @@ -1494,7 +1479,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-childnodes - fn ChildNodes(&mut self, abstract_self: &JSRef) -> Unrooted { + fn ChildNodes(&mut self) -> Unrooted { let roots = RootCollection::new(); match self.child_list { None => (), @@ -1503,7 +1488,8 @@ impl<'a> NodeMethods for JSRef<'a, Node> { let doc = self.deref().owner_doc().root(&roots); let window = doc.deref().window.root(&roots); - self.child_list.assign(Some(NodeList::new_child_list(&*window, abstract_self))); + let child_list = NodeList::new_child_list(&*window, self); + self.child_list.assign(Some(child_list)); Unrooted::new(self.child_list.get_ref().clone()) } @@ -1528,12 +1514,12 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-nodevalue - fn GetNodeValue(&self, abstract_self: &JSRef) -> Option { + fn GetNodeValue(&self) -> Option { match self.type_id { CommentNodeTypeId | TextNodeTypeId | ProcessingInstructionNodeTypeId => { - let chardata: &JSRef = CharacterDataCast::to_ref(abstract_self).unwrap(); + let chardata: &JSRef = CharacterDataCast::to_ref(self).unwrap(); Some(chardata.Data()) } _ => { @@ -1543,26 +1529,26 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-nodevalue - fn SetNodeValue(&mut self, abstract_self: &mut JSRef, val: Option) + fn SetNodeValue(&mut self, val: Option) -> ErrorResult { match self.type_id { CommentNodeTypeId | TextNodeTypeId | ProcessingInstructionNodeTypeId => { - self.SetTextContent(abstract_self, val) + self.SetTextContent(val) } _ => Ok(()) } } // http://dom.spec.whatwg.org/#dom-node-textcontent - fn GetTextContent(&self, abstract_self: &JSRef) -> Option { + fn GetTextContent(&self) -> Option { let roots = RootCollection::new(); match self.type_id { DocumentFragmentNodeTypeId | ElementNodeTypeId(..) => { let mut content = ~""; - for node in abstract_self.traverse_preorder(&roots) { + for node in self.traverse_preorder(&roots) { if node.is_text() { let text: &JSRef = TextCast::to_ref(&node).unwrap(); content.push_str(text.get().characterdata.data.as_slice()); @@ -1573,7 +1559,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { CommentNodeTypeId | TextNodeTypeId | ProcessingInstructionNodeTypeId => { - let characterdata: &JSRef = CharacterDataCast::to_ref(abstract_self).unwrap(); + let characterdata: &JSRef = CharacterDataCast::to_ref(self).unwrap(); Some(characterdata.Data()) } DoctypeNodeTypeId | @@ -1584,7 +1570,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-textcontent - fn SetTextContent(&mut self, abstract_self: &mut JSRef, value: Option) + fn SetTextContent(&mut self, value: Option) -> ErrorResult { let roots = RootCollection::new(); let value = null_str_as_empty(&value); @@ -1596,19 +1582,21 @@ impl<'a> NodeMethods for JSRef<'a, Node> { None } else { let document = self.owner_doc().root(&roots); - Some(NodeCast::from_unrooted(document.deref().CreateTextNode(&*document, value))) + Some(NodeCast::from_unrooted(document.deref().CreateTextNode(value))) }.root(&roots); // Step 3. - Node::replace_all(node.root_ref(), abstract_self); + Node::replace_all(node.root_ref(), self); } CommentNodeTypeId | TextNodeTypeId | ProcessingInstructionNodeTypeId => { self.wait_until_safe_to_modify_dom(); - let characterdata: &mut JSRef = CharacterDataCast::to_mut_ref(abstract_self).unwrap(); - characterdata.get_mut().data = value.clone(); + { + let characterdata: &mut JSRef = CharacterDataCast::to_mut_ref(self).unwrap(); + characterdata.get_mut().data = value.clone(); + } // Notify the document that the content of this node is different let document = self.owner_doc().root(&roots); @@ -1621,24 +1609,21 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-insertbefore - fn InsertBefore(&self, abstract_self: &mut JSRef, node: &mut JSRef, child: Option>) - -> Fallible> { - Node::pre_insert(node, abstract_self, child) + fn InsertBefore(&mut self, node: &mut JSRef, child: Option>) -> Fallible> { + Node::pre_insert(node, self, child) } // http://dom.spec.whatwg.org/#dom-node-appendchild - fn AppendChild(&self, abstract_self: &mut JSRef, node: &mut JSRef) - -> Fallible> { - Node::pre_insert(node, abstract_self, None) + fn AppendChild(&mut self, node: &mut JSRef) -> Fallible> { + Node::pre_insert(node, self, None) } // http://dom.spec.whatwg.org/#concept-node-replace - fn ReplaceChild(&self, parent: &mut JSRef, node: &mut JSRef, child: &mut JSRef) - -> Fallible> { + fn ReplaceChild(&mut self, node: &mut JSRef, child: &mut JSRef) -> Fallible> { let roots = RootCollection::new(); // Step 1. - match parent.type_id() { + match self.type_id() { DocumentNodeTypeId | DocumentFragmentNodeTypeId | ElementNodeTypeId(..) => (), @@ -1646,19 +1631,19 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // Step 2. - if node.is_inclusive_ancestor_of(parent) { + if node.is_inclusive_ancestor_of(self) { return Err(HierarchyRequest); } // Step 3. - if !parent.is_parent_of(child) { + if !self.is_parent_of(child) { return Err(NotFound); } // Step 4-5. match node.type_id() { - TextNodeTypeId if parent.is_document() => return Err(HierarchyRequest), - DoctypeNodeTypeId if !parent.is_document() => return Err(HierarchyRequest), + TextNodeTypeId if self.is_document() => return Err(HierarchyRequest), + DoctypeNodeTypeId if !self.is_document() => return Err(HierarchyRequest), DocumentFragmentNodeTypeId | DoctypeNodeTypeId | ElementNodeTypeId(..) | @@ -1669,7 +1654,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // Step 6. - match parent.type_id() { + match self.type_id() { DocumentNodeTypeId => { match node.type_id() { // Step 6.1 @@ -1682,7 +1667,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { 0 => (), // Step 6.1.2 1 => { - if parent.child_elements().any(|c| NodeCast::from_ref(&c) != child) { + if self.child_elements().any(|c| NodeCast::from_ref(&c) != child) { return Err(HierarchyRequest); } if child.following_siblings() @@ -1696,7 +1681,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { }, // Step 6.2 ElementNodeTypeId(..) => { - if parent.child_elements().any(|c| NodeCast::from_ref(&c) != child) { + if self.child_elements().any(|c| NodeCast::from_ref(&c) != child) { return Err(HierarchyRequest); } if child.following_siblings() @@ -1706,10 +1691,10 @@ impl<'a> NodeMethods for JSRef<'a, Node> { }, // Step 6.3 DoctypeNodeTypeId => { - if parent.children().any(|c| c.deref().is_doctype() && &c != child) { + if self.children().any(|c| c.deref().is_doctype() && &c != child) { return Err(HierarchyRequest); } - if parent.children() + if self.children() .take_while(|c| c != child) .any(|c| c.deref().is_element()) { return Err(HierarchyRequest); @@ -1737,15 +1722,15 @@ impl<'a> NodeMethods for JSRef<'a, Node> { }; // Step 9. - let document = document_from_node(parent).root(&roots); + let document = document_from_node(self).root(&roots); Node::adopt(node, &*document); { // Step 10. - Node::remove(child, parent, Suppressed); + Node::remove(child, self, Suppressed); // Step 11. - Node::insert(node, parent, reference_child, Suppressed); + Node::insert(node, self, reference_child, Suppressed); } // Step 12-14. @@ -1764,13 +1749,13 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-removechild - fn RemoveChild(&self, abstract_self: &mut JSRef, node: &mut JSRef) + fn RemoveChild(&mut self, node: &mut JSRef) -> Fallible> { - Node::pre_remove(node, abstract_self) + Node::pre_remove(node, self) } // http://dom.spec.whatwg.org/#dom-node-normalize - fn Normalize(&mut self, abstract_self: &mut JSRef) { + fn Normalize(&mut self) { let roots = RootCollection::new(); let mut prev_text = None; for mut child in self.children() { @@ -1778,20 +1763,19 @@ impl<'a> NodeMethods for JSRef<'a, Node> { let mut child_alias = child.clone(); let characterdata: &JSRef = CharacterDataCast::to_ref(&child).unwrap(); if characterdata.Length() == 0 { - abstract_self.remove_child(&mut child_alias); + self.remove_child(&mut child_alias); } else { match prev_text { Some(ref mut text_node) => { let prev_characterdata: &mut JSRef = CharacterDataCast::to_mut_ref(text_node).unwrap(); let _ = prev_characterdata.AppendData(characterdata.Data()); - abstract_self.remove_child(&mut child_alias); + self.remove_child(&mut child_alias); }, None => prev_text = Some(child_alias) } } } else { - let mut c = child.clone(); - child.Normalize(&mut c); + child.Normalize(); prev_text = None; } @@ -1799,15 +1783,15 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-clonenode - fn CloneNode(&self, abstract_self: &mut JSRef, deep: bool) -> Unrooted { + fn CloneNode(&self, deep: bool) -> Unrooted { match deep { - true => Node::clone(abstract_self, None, CloneChildren), - false => Node::clone(abstract_self, None, DoNotCloneChildren) + true => Node::clone(self, None, CloneChildren), + false => Node::clone(self, None, DoNotCloneChildren) } } // http://dom.spec.whatwg.org/#dom-node-isequalnode - fn IsEqualNode(&self, abstract_self: &JSRef, maybe_node: Option>) -> bool { + fn IsEqualNode(&self, maybe_node: Option>) -> bool { fn is_equal_doctype(node: &JSRef, other: &JSRef) -> bool { let doctype: &JSRef = DocumentTypeCast::to_ref(node).unwrap(); let other_doctype: &JSRef = DocumentTypeCast::to_ref(other).unwrap(); @@ -1879,20 +1863,20 @@ impl<'a> NodeMethods for JSRef<'a, Node> { // Step 1. None => false, // Step 2-6. - Some(ref node) => is_equal_node(abstract_self, node) + Some(ref node) => is_equal_node(self, node) } } // http://dom.spec.whatwg.org/#dom-node-comparedocumentposition - fn CompareDocumentPosition(&self, abstract_self: &JSRef, other: &JSRef) -> u16 { + fn CompareDocumentPosition(&self, other: &JSRef) -> u16 { let roots = RootCollection::new(); - if abstract_self == other { + if self == other { // step 2. 0 } else { - let mut lastself = abstract_self.clone(); + let mut lastself = self.clone(); let mut lastother = other.clone(); - for ancestor in abstract_self.ancestors() { + for ancestor in self.ancestors() { if &ancestor == other { // step 4. return NodeConstants::DOCUMENT_POSITION_CONTAINS + @@ -1901,7 +1885,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { lastself = ancestor.clone(); } for ancestor in other.ancestors() { - if &ancestor == abstract_self { + if &ancestor == self { // step 5. return NodeConstants::DOCUMENT_POSITION_CONTAINED_BY + NodeConstants::DOCUMENT_POSITION_FOLLOWING; @@ -1910,7 +1894,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } if lastself != lastother { - let abstract_uint: uintptr_t = as_uintptr(&*abstract_self); + let abstract_uint: uintptr_t = as_uintptr(&*self); let other_uint: uintptr_t = as_uintptr(&*other); let random = if abstract_uint < other_uint { @@ -1929,7 +1913,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { // step 6. return NodeConstants::DOCUMENT_POSITION_PRECEDING; } - if &child == abstract_self { + if &child == self { // step 7. return NodeConstants::DOCUMENT_POSITION_FOLLOWING; } @@ -1939,10 +1923,10 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-contains - fn Contains(&self, abstract_self: &JSRef, maybe_other: Option>) -> bool { + fn Contains(&self, maybe_other: Option>) -> bool { match maybe_other { None => false, - Some(ref other) => abstract_self.is_inclusive_ancestor_of(other) + Some(ref other) => self.is_inclusive_ancestor_of(other) } } diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index dda1a0fa295..04108330cb8 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -118,9 +118,9 @@ pub trait WindowMethods { fn Focus(&self); fn Blur(&self); fn GetFrameElement(&self) -> Option>; - fn Location(&mut self, abstract_self: &JSRef) -> Unrooted; - fn Console(&mut self, abstract_self: &JSRef) -> Unrooted; - fn Navigator(&mut self, abstract_self: &JSRef) -> Unrooted; + fn Location(&mut self) -> Unrooted; + fn Console(&mut self) -> Unrooted; + fn Navigator(&mut self) -> Unrooted; fn Confirm(&self, _message: DOMString) -> bool; fn Prompt(&self, _message: DOMString, _default: DOMString) -> Option; fn Print(&self); @@ -129,8 +129,8 @@ pub trait WindowMethods { fn ClearTimeout(&mut self, handle: i32); fn SetInterval(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32; fn ClearInterval(&mut self, handle: i32); - fn Window(&self, abstract_self: &JSRef) -> Unrooted; - fn Self(&self, abstract_self: &JSRef) -> Unrooted; + fn Window(&self) -> Unrooted; + fn Self(&self) -> Unrooted; } impl<'a> WindowMethods for JSRef<'a, Window> { @@ -180,24 +180,27 @@ impl<'a> WindowMethods for JSRef<'a, Window> { None } - fn Location(&mut self, abstract_self: &JSRef) -> Unrooted { + fn Location(&mut self) -> Unrooted { if self.location.is_none() { let page = self.deref().page.clone(); - self.location.assign(Some(Location::new(abstract_self, page))); + let location = Location::new(self, page); + self.location.assign(Some(location)); } Unrooted::new(self.location.get_ref().clone()) } - fn Console(&mut self, abstract_self: &JSRef) -> Unrooted { + fn Console(&mut self) -> Unrooted { if self.console.is_none() { - self.console.assign(Some(Console::new(abstract_self))); + let console = Console::new(self); + self.console.assign(Some(console)); } Unrooted::new(self.console.get_ref().clone()) } - fn Navigator(&mut self, abstract_self: &JSRef) -> Unrooted { + fn Navigator(&mut self) -> Unrooted { if self.navigator.is_none() { - self.navigator.assign(Some(Navigator::new(abstract_self))); + let navigator = Navigator::new(self); + self.navigator.assign(Some(navigator)); } Unrooted::new(self.navigator.get_ref().clone()) } @@ -238,12 +241,12 @@ impl<'a> WindowMethods for JSRef<'a, Window> { self.ClearTimeout(handle); } - fn Window(&self, abstract_self: &JSRef) -> Unrooted { - Unrooted::new_rooted(abstract_self) + fn Window(&self) -> Unrooted { + Unrooted::new_rooted(self) } - fn Self(&self, abstract_self: &JSRef) -> Unrooted { - self.Window(abstract_self) + fn Self(&self) -> Unrooted { + self.Window() } } diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 0121b023783..f9a4f641ffc 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -5,7 +5,7 @@ use dom::attr::AttrMethods; use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, TextCast, ElementCast}; use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalRootable}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalRootable, Root}; use dom::bindings::utils::Reflectable; use dom::document::Document; use dom::element::{AttributeHandlers, HTMLLinkElementTypeId, HTMLIFrameElementTypeId}; @@ -13,7 +13,7 @@ use dom::htmlelement::HTMLElement; use dom::htmlheadingelement::{Heading1, Heading2, Heading3, Heading4, Heading5, Heading6}; use dom::htmliframeelement::IFrameSize; use dom::htmlformelement::HTMLFormElement; -use dom::node::{ElementNodeTypeId, NodeHelpers, AppendChild}; +use dom::node::{ElementNodeTypeId, NodeHelpers, NodeMethods}; use dom::types::*; use html::cssparse::{StylesheetProvenance, UrlProvenance, spawn_css_parser}; use script_task::Page; @@ -422,8 +422,8 @@ pub fn parse_html(page: &Page, unsafe { debug!("append child {:x} {:x}", parent, child); let mut child = from_hubbub_node(child, Some(&roots)).root(&roots); - let mut parent = from_hubbub_node(parent, None).root(&roots); - assert!(AppendChild(&mut *parent, &mut *child).is_ok()); + let mut parent: Root = from_hubbub_node(parent, None).root(&roots); + assert!(parent.AppendChild(&mut *child).is_ok()); } child }, diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index df7e6f2b994..600f28794a1 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -17,7 +17,7 @@ use dom::element::{Element, AttributeHandlers}; use dom::event::{Event_, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent}; use dom::event::{Event, EventMethods}; use dom::uievent::{UIEvent, UIEventMethods}; -use dom::eventtarget::EventTarget; +use dom::eventtarget::{EventTarget, EventTargetHelpers}; use dom::node; use dom::node::{Node, NodeHelpers}; use dom::window::{TimerId, Window}; @@ -988,11 +988,9 @@ impl ScriptTask { let mut event = Event::new(&*window).root(&roots); event.InitEvent(~"load", false, false); let doctarget: &JSRef = EventTargetCast::from_ref(&*document); - let wintarget: &mut JSRef = EventTargetCast::from_mut_ref(&mut *window); - let wintarget_alias = wintarget.clone(); - let _ = wintarget.get_mut().dispatch_event_with_target(&wintarget_alias, - Some((*doctarget).clone()), - &mut *event); + let wintarget: &JSRef = EventTargetCast::from_ref(&*window); + let _ = wintarget.dispatch_event_with_target(Some((*doctarget).clone()), + &mut *event); let mut fragment_node = page.fragment_node.deref().borrow_mut(); (*fragment_node).assign(fragment.map_or(None, |fragid| page.find_fragment_node(fragid))); @@ -1061,10 +1059,7 @@ impl ScriptTask { let event: &mut JSRef = EventCast::from_mut_ref(&mut *uievent); let wintarget: &mut JSRef = EventTargetCast::from_mut_ref(&mut *window); - let wintarget_alias = wintarget.clone(); - let _ = wintarget.get_mut().dispatch_event_with_target(&wintarget_alias, - None, - &mut *event); + let _ = wintarget.dispatch_event_with_target(None, &mut *event); } None => () } From 109410900c75721a77b970be3bdd830968e47151 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Fri, 11 Apr 2014 14:46:34 -0400 Subject: [PATCH 06/16] Move all methods on T to JSRef or JS as appropriate. --- src/components/main/layout/wrapper.rs | 36 +- src/components/script/dom/document.rs | 224 ++++--- src/components/script/dom/element.rs | 88 ++- .../script/dom/htmlbuttonelement.rs | 6 +- .../script/dom/htmlfieldsetelement.rs | 3 +- src/components/script/dom/htmlformelement.rs | 5 +- .../script/dom/htmliframeelement.rs | 11 +- src/components/script/dom/htmlimageelement.rs | 53 +- src/components/script/dom/htmlmapelement.rs | 5 +- .../script/dom/htmlobjectelement.rs | 5 +- .../script/dom/htmloutputelement.rs | 5 +- .../script/dom/htmlselectelement.rs | 5 +- src/components/script/dom/node.rs | 627 +++++++++--------- .../script/html/hubbub_html_parser.rs | 18 +- src/components/script/script_task.rs | 4 +- 15 files changed, 574 insertions(+), 521 deletions(-) diff --git a/src/components/main/layout/wrapper.rs b/src/components/main/layout/wrapper.rs index d779845c5b5..4aa10c3ba63 100644 --- a/src/components/main/layout/wrapper.rs +++ b/src/components/main/layout/wrapper.rs @@ -37,10 +37,11 @@ use script::dom::bindings::codegen::InheritTypes::{HTMLIFrameElementDerived}; use script::dom::bindings::codegen::InheritTypes::{HTMLImageElementDerived, TextDerived}; use script::dom::bindings::js::JS; use script::dom::element::{Element, HTMLAreaElementTypeId, HTMLAnchorElementTypeId}; -use script::dom::element::{HTMLLinkElementTypeId}; +use script::dom::element::{HTMLLinkElementTypeId, LayoutElementHelpers, RawLayoutElementHelpers}; use script::dom::htmliframeelement::HTMLIFrameElement; -use script::dom::htmlimageelement::HTMLImageElement; -use script::dom::node::{DocumentNodeTypeId, ElementNodeTypeId, Node, NodeTypeId, LayoutNodeHelpers}; +use script::dom::htmlimageelement::{HTMLImageElement, LayoutHTMLImageElementHelpers}; +use script::dom::node::{DocumentNodeTypeId, ElementNodeTypeId, Node, NodeTypeId}; +use script::dom::node::{LayoutNodeHelpers, RawLayoutNodeHelpers}; use script::dom::text::Text; use servo_msg::constellation_msg::{PipelineId, SubpageId}; use servo_util::namespace; @@ -95,7 +96,7 @@ pub trait TLayoutNode { fail!("not an image!") } let image_element: JS = self.get_jsmanaged().transmute_copy(); - (*image_element.unsafe_get()).image().as_ref().map(|url| (*url).clone()) + image_element.image().as_ref().map(|url| (*url).clone()) } } @@ -163,7 +164,9 @@ impl<'ln> TLayoutNode for LayoutNode<'ln> { } fn type_id(&self) -> Option { - Some(self.node.type_id_for_layout()) + unsafe { + Some(self.node.type_id_for_layout()) + } } unsafe fn get_jsmanaged<'a>(&'a self) -> &'a JS { @@ -172,7 +175,7 @@ impl<'ln> TLayoutNode for LayoutNode<'ln> { fn first_child(&self) -> Option> { unsafe { - self.get().first_child_ref().map(|node| self.new_with_this_lifetime(node)) + self.get_jsmanaged().first_child_ref().map(|node| self.new_with_this_lifetime(node)) } } @@ -221,19 +224,19 @@ impl<'ln> LayoutNode<'ln> { impl<'ln> TNode> for LayoutNode<'ln> { fn parent_node(&self) -> Option> { unsafe { - self.get().parent_node_ref().map(|node| self.new_with_this_lifetime(node)) + self.node.parent_node_ref().map(|node| self.new_with_this_lifetime(node)) } } fn prev_sibling(&self) -> Option> { unsafe { - self.get().prev_sibling_ref().map(|node| self.new_with_this_lifetime(node)) + self.node.prev_sibling_ref().map(|node| self.new_with_this_lifetime(node)) } } fn next_sibling(&self) -> Option> { unsafe { - self.get().next_sibling_ref().map(|node| self.new_with_this_lifetime(node)) + self.node.next_sibling_ref().map(|node| self.new_with_this_lifetime(node)) } } @@ -241,6 +244,7 @@ impl<'ln> TNode> for LayoutNode<'ln> { #[inline] fn as_element(&self) -> LayoutElement<'ln> { unsafe { + assert!(self.node.is_element_for_layout()); let elem: JS = self.node.transmute_copy(); let element = &*elem.unsafe_get(); LayoutElement { @@ -258,9 +262,9 @@ impl<'ln> TNode> for LayoutNode<'ln> { } fn match_attr(&self, attr: &AttrSelector, test: |&str| -> bool) -> bool { - let element = self.as_element(); let name = unsafe { - if element.element.html_element_in_html_document_for_layout() { + let element: JS = self.node.transmute_copy(); + if element.html_element_in_html_document_for_layout() { attr.lower_name.as_slice() } else { attr.name.as_slice() @@ -268,6 +272,7 @@ impl<'ln> TNode> for LayoutNode<'ln> { }; match attr.namespace { SpecificNamespace(ref ns) => { + let element = self.as_element(); element.get_attr(ns, name) .map_or(false, |attr| test(attr)) }, @@ -459,7 +464,7 @@ impl<'ln> TLayoutNode for ThreadSafeLayoutNode<'ln> { } unsafe { - self.get().first_child_ref().map(|node| self.new_with_this_lifetime(node)) + self.get_jsmanaged().first_child_ref().map(|node| self.new_with_this_lifetime(node)) } } @@ -509,10 +514,10 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { /// Returns the next sibling of this node. Unsafe and private because this can lead to races. unsafe fn next_sibling(&self) -> Option> { if self.pseudo == Before || self.pseudo == BeforeBlock { - return (*self.get_jsmanaged().unsafe_get()).first_child_ref().map(|node| self.new_with_this_lifetime(node)) + return self.get_jsmanaged().first_child_ref().map(|node| self.new_with_this_lifetime(node)) } - (*self.get_jsmanaged().unsafe_get()).next_sibling_ref().map(|node| self.new_with_this_lifetime(node)) + self.get_jsmanaged().next_sibling_ref().map(|node| self.new_with_this_lifetime(node)) } /// Returns an iterator over this node's children. @@ -527,7 +532,8 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { #[inline] pub fn as_element(&self) -> ThreadSafeLayoutElement { unsafe { - let elem: JS = self.node.get_jsmanaged().transmute_copy(); + assert!(self.get_jsmanaged().is_element_for_layout()); + let elem: JS = self.get_jsmanaged().transmute_copy(); let element = elem.unsafe_get(); // FIXME(pcwalton): Workaround until Rust gets multiple lifetime parameters on // implementations. diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index e9f237999a7..24c1d6eae89 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -76,8 +76,115 @@ impl DocumentDerived for EventTarget { } } +pub trait DocumentHelpers { + fn url<'a>(&'a self) -> &'a Url; + fn quirks_mode(&self) -> QuirksMode; + fn set_quirks_mode(&mut self, mode: QuirksMode); + fn set_encoding_name(&mut self, name: DOMString); + fn content_changed(&self); + fn damage_and_reflow(&self, damage: DocumentDamageLevel); + fn wait_until_safe_to_modify_dom(&self); + fn unregister_named_element(&mut self, to_unregister: &JSRef, id: DOMString); + fn register_named_element(&mut self, element: &JSRef, id: DOMString); +} + +impl<'a> DocumentHelpers for JSRef<'a, Document> { + fn url<'a>(&'a self) -> &'a Url { + &*self.url + } + + fn quirks_mode(&self) -> QuirksMode { + *self.quirks_mode + } + + fn set_quirks_mode(&mut self, mode: QuirksMode) { + *self.quirks_mode = mode; + } + + fn set_encoding_name(&mut self, name: DOMString) { + self.encoding_name = name; + } + + fn content_changed(&self) { + self.damage_and_reflow(ContentChangedDocumentDamage); + } + + fn damage_and_reflow(&self, damage: DocumentDamageLevel) { + let roots = RootCollection::new(); + self.window.root(&roots).damage_and_reflow(damage); + } + + fn wait_until_safe_to_modify_dom(&self) { + let roots = RootCollection::new(); + self.window.root(&roots).wait_until_safe_to_modify_dom(); + } + + + /// Remove any existing association between the provided id and any elements in this document. + fn unregister_named_element(&mut self, + to_unregister: &JSRef, + id: DOMString) { + let roots = RootCollection::new(); + let mut is_empty = false; + match self.idmap.find_mut(&id) { + None => {}, + Some(elements) => { + let position = elements.iter() + .map(|elem| elem.root(&roots)) + .position(|element| &*element == to_unregister) + .expect("This element should be in registered."); + elements.remove(position); + is_empty = elements.is_empty(); + } + } + if is_empty { + self.idmap.remove(&id); + } + } + + /// Associate an element present in this document with the provided id. + fn register_named_element(&mut self, + element: &JSRef, + id: DOMString) { + let roots = RootCollection::new(); + assert!({ + let node: &JSRef = NodeCast::from_ref(element); + node.is_in_doc() + }); + + // FIXME https://github.com/mozilla/rust/issues/13195 + // Use mangle() when it exists again. + let root = self.GetDocumentElement().expect("The element is in the document, so there must be a document element.").root(&roots); + match self.idmap.find_mut(&id) { + Some(elements) => { + let new_node: &JSRef = NodeCast::from_ref(element); + let mut head : uint = 0u; + let root: &JSRef = NodeCast::from_ref(&*root); + for node in root.traverse_preorder(&roots) { + let elem: Option<&JSRef> = ElementCast::to_ref(&node); + match elem { + Some(elem) => { + if elements.get(head) == &elem.unrooted() { + head = head + 1; + } + if new_node == &node || head == elements.len() { + break; + } + } + None => {} + } + } + elements.insert(head, element.unrooted()); + return; + }, + None => (), + } + self.idmap.insert(id, vec!(element.unrooted())); + } +} + impl Document { - pub fn reflect_document(document: ~Document, + pub fn reflect_document(document: ~Document, window: &JSRef, wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~Document) -> JS) -> Unrooted { @@ -88,7 +195,7 @@ impl Document { let mut doc_alias = raw_doc.clone(); let node: &mut JSRef = NodeCast::from_mut_ref(&mut doc_alias); - node.get_mut().set_owner_doc(&*raw_doc); + node.set_owner_doc(&*raw_doc); Unrooted::new_rooted(&*raw_doc) } @@ -131,100 +238,6 @@ impl Document { let document = Document::new_inherited(window.unrooted(), url, doctype, content_type); Document::reflect_document(~document, window, DocumentBinding::Wrap) } - - pub fn url<'a>(&'a self) -> &'a Url { - &*self.url - } - - pub fn quirks_mode(&self) -> QuirksMode { - *self.quirks_mode - } - - pub fn set_quirks_mode(&mut self, mode: QuirksMode) { - *self.quirks_mode = mode; - } - - pub fn set_encoding_name(&mut self, name: DOMString) { - self.encoding_name = name; - } - - pub fn content_changed(&self) { - self.damage_and_reflow(ContentChangedDocumentDamage); - } - - pub fn damage_and_reflow(&self, damage: DocumentDamageLevel) { - let roots = RootCollection::new(); - self.window.root(&roots).damage_and_reflow(damage); - } - - pub fn wait_until_safe_to_modify_dom(&self) { - let roots = RootCollection::new(); - self.window.root(&roots).wait_until_safe_to_modify_dom(); - } - - - /// Remove any existing association between the provided id and any elements in this document. - pub fn unregister_named_element(&mut self, - to_unregister: &JSRef, - id: DOMString) { - let roots = RootCollection::new(); - let mut is_empty = false; - match self.idmap.find_mut(&id) { - None => {}, - Some(elements) => { - let position = elements.iter() - .map(|elem| elem.root(&roots)) - .position(|element| &*element == to_unregister) - .expect("This element should be in registered."); - elements.remove(position); - is_empty = elements.is_empty(); - } - } - if is_empty { - self.idmap.remove(&id); - } - } - - /// Associate an element present in this document with the provided id. - pub fn register_named_element(&mut self, - abstract_self: &JSRef, - element: &JSRef, - id: DOMString) { - let roots = RootCollection::new(); - assert!({ - let node: &JSRef = NodeCast::from_ref(element); - node.is_in_doc() - }); - - // FIXME https://github.com/mozilla/rust/issues/13195 - // Use mangle() when it exists again. - let root = abstract_self.GetDocumentElement().expect("The element is in the document, so there must be a document element.").root(&roots); - match self.idmap.find_mut(&id) { - Some(elements) => { - let new_node: &JSRef = NodeCast::from_ref(element); - let mut head : uint = 0u; - let root: &JSRef = NodeCast::from_ref(&*root); - for node in root.traverse_preorder(&roots) { - let elem: Option<&JSRef> = ElementCast::to_ref(&node); - match elem { - Some(elem) => { - if elements.get(head) == &elem.unrooted() { - head = head + 1; - } - if new_node == &node || head == elements.len() { - break; - } - } - None => {} - } - } - elements.insert(head, element.unrooted()); - return; - }, - None => (), - } - self.idmap.insert(id, vec!(element.unrooted())); - } } impl Reflectable for Document { @@ -237,12 +250,12 @@ impl Reflectable for Document { } } -trait DocumentHelpers { +trait PrivateDocumentHelpers { fn createNodeList(&self, callback: |node: &JSRef| -> bool) -> Unrooted; fn get_html_element(&self) -> Option>; } -impl<'a> DocumentHelpers for JSRef<'a, Document> { +impl<'a> PrivateDocumentHelpers for JSRef<'a, Document> { fn createNodeList(&self, callback: |node: &JSRef| -> bool) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -354,7 +367,8 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://dom.spec.whatwg.org/#dom-document-doctype fn GetDoctype(&self) -> Option> { - self.node.children().find(|child| { + let node: &JSRef = NodeCast::from_ref(self); + node.children().find(|child| { child.is_doctype() }).map(|node| { let doctype: &JSRef = DocumentTypeCast::to_ref(&node).unwrap(); @@ -364,7 +378,8 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://dom.spec.whatwg.org/#dom-document-documentelement fn GetDocumentElement(&self) -> Option> { - self.node.child_elements().next().map(|elem| Unrooted::new_rooted(&elem)) + let node: &JSRef = NodeCast::from_ref(self); + node.child_elements().next().map(|elem| Unrooted::new_rooted(&elem)) } // http://dom.spec.whatwg.org/#dom-document-getelementsbytagname @@ -544,7 +559,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { root.traverse_preorder(&roots) .find(|node| node.type_id() == ElementNodeTypeId(HTMLTitleElementTypeId)) .map(|title_elem| { - for child in title_elem.deref().children() { + for child in title_elem.children() { if child.is_text() { let text: &JSRef = TextCast::to_ref(&child).unwrap(); title.push_str(text.get().characterdata.data.as_slice()); @@ -633,8 +648,9 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // Step 1. match new_body { - Some(ref node) => { - match node.get().element.node.type_id { + Some(ref htmlelem) => { + let node: &JSRef = NodeCast::from_ref(htmlelem); + match node.type_id() { ElementNodeTypeId(HTMLBodyElementTypeId) | ElementNodeTypeId(HTMLFrameSetElementTypeId) => {} _ => return Err(HierarchyRequest) } @@ -676,7 +692,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { let roots = RootCollection::new(); self.createNodeList(|node| { - if !node.get().is_element() { + if !node.is_element() { return false; } diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index 200ed604777..9e8be904788 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -15,12 +15,12 @@ use dom::bindings::error::{ErrorResult, Fallible, NamespaceError, InvalidCharact use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type}; use dom::clientrect::ClientRect; use dom::clientrectlist::ClientRectList; -use dom::document::Document; +use dom::document::{Document, DocumentHelpers}; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlcollection::HTMLCollection; use dom::htmlserializer::serialize; use dom::node::{ElementNodeTypeId, Node, NodeHelpers, NodeIterator, document_from_node}; -use dom::node::window_from_node; +use dom::node::{window_from_node, LayoutNodeHelpers}; use dom::virtualmethods::{VirtualMethods, vtable_for}; use layout_interface::ContentChangedDocumentDamage; use layout_interface::MatchSelectorsDocumentDamage; @@ -157,36 +157,51 @@ impl Element { let element = Element::new_inherited(ElementTypeId, local_name, namespace, prefix, document.unrooted()); Node::reflect_node(~element, document, ElementBinding::Wrap) } +} - pub fn html_element_in_html_document(&self) -> bool { - let roots = RootCollection::new(); - self.namespace == namespace::HTML && - self.node.owner_doc().root(&roots).is_html_document +pub trait RawLayoutElementHelpers { + unsafe fn get_attr_val_for_layout(&self, namespace: &Namespace, name: &str) -> Option<&'static str>; +} + +impl RawLayoutElementHelpers for Element { + #[inline] + unsafe fn get_attr_val_for_layout(&self, namespace: &Namespace, name: &str) + -> Option<&'static str> { + self.attrs.iter().find(|attr: & &JS| { + let attr = attr.unsafe_get(); + name == (*attr).local_name && (*attr).namespace == *namespace + }).map(|attr| { + let attr = attr.unsafe_get(); + cast::transmute((*attr).value.as_slice()) + }) } } -impl Element { - pub unsafe fn html_element_in_html_document_for_layout(&self) -> bool { - if self.namespace != namespace::HTML { +pub trait LayoutElementHelpers { + unsafe fn html_element_in_html_document_for_layout(&self) -> bool; +} + +impl LayoutElementHelpers for JS { + unsafe fn html_element_in_html_document_for_layout(&self) -> bool { + if (*self.unsafe_get()).namespace != namespace::HTML { return false } - let owner_doc: *JS = self.node.owner_doc_for_layout(); - let owner_doc: **Document = owner_doc as **Document; - (**owner_doc).is_html_document + let node: JS = self.transmute_copy(); + let owner_doc = node.owner_doc_for_layout().unsafe_get(); + (*owner_doc).is_html_document } +} - #[inline] - pub unsafe fn get_attr_val_for_layout(&self, namespace: &Namespace, name: &str) - -> Option<&'static str> { - self.attrs.iter().find(|attr: & &JS| { - // unsafely avoid a borrow because this is accessed by many tasks - // during parallel layout - let attr: ***Attr = cast::transmute(attr); - name == (***attr).local_name && (***attr).namespace == *namespace - }).map(|attr| { - let attr: **Attr = cast::transmute(attr); - cast::transmute((**attr).value.as_slice()) - }) +pub trait ElementHelpers { + fn html_element_in_html_document(&self) -> bool; +} + +impl<'a> ElementHelpers for JSRef<'a, Element> { + fn html_element_in_html_document(&self) -> bool { + let roots = RootCollection::new(); + let is_html = self.namespace == namespace::HTML; + let node: &JSRef = NodeCast::from_ref(self); + is_html && node.owner_doc().root(&roots).is_html_document } } @@ -214,7 +229,7 @@ pub trait AttributeHandlers { impl<'a> AttributeHandlers for JSRef<'a, Element> { fn get_attribute(&self, namespace: Namespace, name: &str) -> Option> { let roots = RootCollection::new(); - if self.get().html_element_in_html_document() { + if self.html_element_in_html_document() { self.get().attrs.iter().map(|attr| attr.root(&roots)).find(|attr| { name.to_ascii_lower() == attr.local_name && attr.namespace == namespace }).map(|x| Unrooted::new_rooted(&*x)) @@ -248,7 +263,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { node.wait_until_safe_to_modify_dom(); let position: |&JSRef| -> bool = - if self.get().html_element_in_html_document() { + if self.html_element_in_html_document() { |attr| attr.get().local_name.eq_ignore_ascii_case(local_name) } else { |attr| attr.get().local_name == local_name @@ -453,7 +468,10 @@ impl<'a> ElementMethods for JSRef<'a, Element> { Some(ref list) => return Unrooted::new(list.clone()), } - let doc = self.node.owner_doc().root(&roots); + let doc = { + let node: &JSRef = NodeCast::from_ref(self); + node.owner_doc() + }.root(&roots); let window = doc.deref().window.root(&roots); let list = AttrList::new(&*window, self); self.attr_list.assign(Some(list)); @@ -463,7 +481,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { // http://dom.spec.whatwg.org/#dom-element-getattribute fn GetAttribute(&self, name: DOMString) -> Option { let roots = RootCollection::new(); - let name = if self.get().html_element_in_html_document() { + let name = if self.html_element_in_html_document() { name.to_ascii_lower() } else { name @@ -488,7 +506,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { value: DOMString) -> ErrorResult { { let node: &JSRef = NodeCast::from_ref(self); - node.get().wait_until_safe_to_modify_dom(); + node.wait_until_safe_to_modify_dom(); } // Step 1. @@ -498,7 +516,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { } // Step 2. - let name = if self.get().html_element_in_html_document() { + let name = if self.html_element_in_html_document() { name.to_ascii_lower() } else { name @@ -518,7 +536,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { value: DOMString) -> ErrorResult { { let node: &JSRef = NodeCast::from_ref(self); - node.get().wait_until_safe_to_modify_dom(); + node.wait_until_safe_to_modify_dom(); } // Step 1. @@ -707,15 +725,14 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { match name.as_slice() { "style" => { let doc = document_from_node(self).root(&roots); - let base_url = doc.get().url().clone(); + let base_url = doc.deref().url().clone(); self.get_mut().style_attribute = Some(style::parse_style_attribute(value, &base_url)) } "id" => { let node: &JSRef = NodeCast::from_ref(self); if node.is_in_doc() { let mut doc = document_from_node(self).root(&roots); - let doc_alias = (*doc).clone(); - doc.register_named_element(&doc_alias, self, value.clone()); + doc.register_named_element(self, value.clone()); } } _ => () @@ -758,8 +775,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { match self.get_attribute(Null, "id").root(&roots) { Some(attr) => { let mut doc = document_from_node(self).root(&roots); - let doc_alias = (*doc).clone(); - doc.register_named_element(&doc_alias, self, attr.deref().Value()); + doc.register_named_element(self, attr.deref().Value()); } _ => () } diff --git a/src/components/script/dom/htmlbuttonelement.rs b/src/components/script/dom/htmlbuttonelement.rs index 2b2b04aca35..f37d9926032 100644 --- a/src/components/script/dom/htmlbuttonelement.rs +++ b/src/components/script/dom/htmlbuttonelement.rs @@ -11,7 +11,7 @@ use dom::element::HTMLButtonElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlelement::HTMLElement; use dom::htmlformelement::HTMLFormElement; -use dom::node::{Node, ElementNodeTypeId}; +use dom::node::{Node, ElementNodeTypeId, window_from_node}; use dom::validitystate::ValidityState; use servo_util::str::DOMString; @@ -168,8 +168,8 @@ impl<'a> HTMLButtonElementMethods for JSRef<'a, HTMLButtonElement> { fn Validity(&self) -> Unrooted { let roots = RootCollection::new(); - let doc = self.htmlelement.element.node.owner_doc().root(&roots); - ValidityState::new(&*doc.deref().window.root(&roots)) + let window = window_from_node(self).root(&roots); + ValidityState::new(&*window) } fn SetValidity(&mut self, _validity: JS) { diff --git a/src/components/script/dom/htmlfieldsetelement.rs b/src/components/script/dom/htmlfieldsetelement.rs index ef42eb59990..8da6d36b803 100644 --- a/src/components/script/dom/htmlfieldsetelement.rs +++ b/src/components/script/dom/htmlfieldsetelement.rs @@ -107,8 +107,7 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> { fn Validity(&self) -> Unrooted { let roots = RootCollection::new(); - let doc = self.htmlelement.element.node.owner_doc().root(&roots); - let window = doc.deref().window.root(&roots); + let window = window_from_node(self).root(&roots); ValidityState::new(&*window) } diff --git a/src/components/script/dom/htmlformelement.rs b/src/components/script/dom/htmlformelement.rs index f045c1437c3..d69cbcf3a48 100644 --- a/src/components/script/dom/htmlformelement.rs +++ b/src/components/script/dom/htmlformelement.rs @@ -11,7 +11,7 @@ use dom::element::{Element, HTMLFormElementTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlcollection::{HTMLCollection, Static}; use dom::htmlelement::HTMLElement; -use dom::node::{Node, ElementNodeTypeId}; +use dom::node::{Node, ElementNodeTypeId, window_from_node}; use servo_util::str::DOMString; #[deriving(Encodable)] @@ -144,8 +144,7 @@ impl<'a> HTMLFormElementMethods for JSRef<'a, HTMLFormElement> { fn Elements(&self) -> Unrooted { // FIXME: https://github.com/mozilla/servo/issues/1844 let roots = RootCollection::new(); - let doc = self.htmlelement.element.node.owner_doc().root(&roots); - let window = doc.deref().window.root(&roots); + let window = window_from_node(self).root(&roots); HTMLCollection::new(&*window, Static(vec!())) } diff --git a/src/components/script/dom/htmliframeelement.rs b/src/components/script/dom/htmliframeelement.rs index ee675390183..aa6fc3ceaf3 100644 --- a/src/components/script/dom/htmliframeelement.rs +++ b/src/components/script/dom/htmliframeelement.rs @@ -54,12 +54,17 @@ pub struct IFrameSize { pub subpage_id: SubpageId, } -impl HTMLIFrameElement { - pub fn is_sandboxed(&self) -> bool { +pub trait HTMLIFrameElementHelpers { + fn is_sandboxed(&self) -> bool; + fn set_frame(&mut self, frame: Url); +} + +impl<'a> HTMLIFrameElementHelpers for JSRef<'a, HTMLIFrameElement> { + fn is_sandboxed(&self) -> bool { self.sandbox.is_some() } - pub fn set_frame(&mut self, frame: Url) { + fn set_frame(&mut self, frame: Url) { *self.frame = Some(frame); } } diff --git a/src/components/script/dom/htmlimageelement.rs b/src/components/script/dom/htmlimageelement.rs index 39c854c1c05..423f49a8f14 100644 --- a/src/components/script/dom/htmlimageelement.rs +++ b/src/components/script/dom/htmlimageelement.rs @@ -35,29 +35,18 @@ impl HTMLImageElementDerived for EventTarget { } } -impl HTMLImageElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLImageElement { - HTMLImageElement { - htmlelement: HTMLElement::new_inherited(HTMLImageElementTypeId, localName, document), - image: Untraceable::new(None), - } - } - - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { - let element = HTMLImageElement::new_inherited(localName, document.unrooted()); - Node::reflect_node(~element, document, HTMLImageElementBinding::Wrap) - } - - pub fn image<'a>(&'a self) -> &'a Option { - &*self.image - } +trait PrivateHTMLImageElementHelpers { + fn update_image(&mut self, value: Option, url: Option); +} +impl<'a> PrivateHTMLImageElementHelpers for JSRef<'a, HTMLImageElement> { /// Makes the local `image` member match the status of the `src` attribute and starts /// prefetching the image. This method must be called after `src` is changed. fn update_image(&mut self, value: Option, url: Option) { let roots = RootCollection::new(); - let elem = &mut self.htmlelement.element; - let document = elem.node.owner_doc().root(&roots); + let self_alias = self.clone(); + let node_alias: &JSRef = NodeCast::from_ref(&self_alias); + let document = node_alias.owner_doc().root(&roots); let window = document.deref().window.root(&roots); let image_cache = &window.image_cache_task; match value { @@ -79,6 +68,30 @@ impl HTMLImageElement { } } +impl HTMLImageElement { + pub fn new_inherited(localName: DOMString, document: JS) -> HTMLImageElement { + HTMLImageElement { + htmlelement: HTMLElement::new_inherited(HTMLImageElementTypeId, localName, document), + image: Untraceable::new(None), + } + } + + pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + let element = HTMLImageElement::new_inherited(localName, document.unrooted()); + Node::reflect_node(~element, document, HTMLImageElementBinding::Wrap) + } +} + +pub trait LayoutHTMLImageElementHelpers { + unsafe fn image<'a>(&'a self) -> &'a Option; +} + +impl LayoutHTMLImageElementHelpers for JS { + unsafe fn image<'a>(&'a self) -> &'a Option { + &*(*self.unsafe_get()).image + } +} + pub trait HTMLImageElementMethods { fn Alt(&self) -> DOMString; fn SetAlt(&mut self, alt: DOMString); @@ -271,7 +284,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> { if "src" == name { let window = window_from_node(self).root(&roots); let url = Some(window.get().get_url()); - self.get_mut().update_image(Some(value), url); + self.update_image(Some(value), url); } } @@ -282,7 +295,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> { } if "src" == name { - self.get_mut().update_image(None, None); + self.update_image(None, None); } } } diff --git a/src/components/script/dom/htmlmapelement.rs b/src/components/script/dom/htmlmapelement.rs index dbc55463351..7c6e4b59151 100644 --- a/src/components/script/dom/htmlmapelement.rs +++ b/src/components/script/dom/htmlmapelement.rs @@ -11,7 +11,7 @@ use dom::element::HTMLMapElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlcollection::{HTMLCollection, Static}; use dom::htmlelement::HTMLElement; -use dom::node::{Node, ElementNodeTypeId}; +use dom::node::{Node, ElementNodeTypeId, window_from_node}; use servo_util::str::DOMString; #[deriving(Encodable)] @@ -59,8 +59,7 @@ impl<'a> HTMLMapElementMethods for JSRef<'a, HTMLMapElement> { fn Areas(&self) -> Unrooted { let roots = RootCollection::new(); // FIXME: https://github.com/mozilla/servo/issues/1845 - let doc = self.htmlelement.element.node.owner_doc().root(&roots); - let window = doc.deref().window.root(&roots); + let window = window_from_node(self).root(&roots); HTMLCollection::new(&*window, Static(vec!())) } } diff --git a/src/components/script/dom/htmlobjectelement.rs b/src/components/script/dom/htmlobjectelement.rs index 7fcc3c0a5da..085bd492b11 100644 --- a/src/components/script/dom/htmlobjectelement.rs +++ b/src/components/script/dom/htmlobjectelement.rs @@ -191,9 +191,8 @@ impl<'a> HTMLObjectElementMethods for JSRef<'a, HTMLObjectElement> { fn Validity(&self) -> Unrooted { let roots = RootCollection::new(); - let doc = self.htmlelement.element.node.owner_doc().root(&roots); - let window = doc.deref().window.root(&roots); - ValidityState::new(&window.root_ref()) + let window = window_from_node(self).root(&roots); + ValidityState::new(&*window) } fn ValidationMessage(&self) -> DOMString { diff --git a/src/components/script/dom/htmloutputelement.rs b/src/components/script/dom/htmloutputelement.rs index c7262b23de0..605bb2eeab2 100644 --- a/src/components/script/dom/htmloutputelement.rs +++ b/src/components/script/dom/htmloutputelement.rs @@ -11,7 +11,7 @@ use dom::element::HTMLOutputElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlelement::HTMLElement; use dom::htmlformelement::HTMLFormElement; -use dom::node::{Node, ElementNodeTypeId}; +use dom::node::{Node, ElementNodeTypeId, window_from_node}; use dom::validitystate::ValidityState; use servo_util::str::DOMString; @@ -103,8 +103,7 @@ impl<'a> HTMLOutputElementMethods for JSRef<'a, HTMLOutputElement> { fn Validity(&self) -> Unrooted { let roots = RootCollection::new(); - let doc = self.htmlelement.element.node.owner_doc().root(&roots); - let window = doc.deref().window.root(&roots); + let window = window_from_node(self).root(&roots); ValidityState::new(&*window) } diff --git a/src/components/script/dom/htmlselectelement.rs b/src/components/script/dom/htmlselectelement.rs index 6aa15a1e982..ed99506f01d 100644 --- a/src/components/script/dom/htmlselectelement.rs +++ b/src/components/script/dom/htmlselectelement.rs @@ -12,7 +12,7 @@ use dom::element::{Element, HTMLSelectElementTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlelement::HTMLElement; use dom::htmlformelement::HTMLFormElement; -use dom::node::{Node, ElementNodeTypeId}; +use dom::node::{Node, ElementNodeTypeId, window_from_node}; use dom::htmloptionelement::HTMLOptionElement; use dom::validitystate::ValidityState; use servo_util::str::DOMString; @@ -193,8 +193,7 @@ impl<'a> HTMLSelectElementMethods for JSRef<'a, HTMLSelectElement> { fn Validity(&self) -> Unrooted { let roots = RootCollection::new(); - let doc = self.htmlelement.element.node.owner_doc().root(&roots); - let window = doc.deref().window.root(&roots); + let window = window_from_node(self).root(&roots); ValidityState::new(&*window) } diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index aa444865bdb..99daa05e1a5 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -6,7 +6,7 @@ use dom::attr::Attr; use dom::bindings::codegen::InheritTypes::{CommentCast, DocumentCast, DocumentTypeCast}; -use dom::bindings::codegen::InheritTypes::{ElementCast, TextCast, NodeCast}; +use dom::bindings::codegen::InheritTypes::{ElementCast, TextCast, NodeCast, ElementDerived}; use dom::bindings::codegen::InheritTypes::{CharacterDataCast, NodeBase, NodeDerived}; use dom::bindings::codegen::InheritTypes::{ProcessingInstructionCast, EventTargetCast}; use dom::bindings::codegen::BindingDeclarations::NodeBinding::NodeConstants; @@ -18,7 +18,7 @@ use dom::bindings::error::{ErrorResult, Fallible, NotFound, HierarchyRequest}; use dom::bindings::utils; use dom::characterdata::{CharacterData, CharacterDataMethods}; use dom::comment::Comment; -use dom::document::{Document, DocumentMethods, HTMLDocument, NonHTMLDocument}; +use dom::document::{Document, DocumentMethods, DocumentHelpers, HTMLDocument, NonHTMLDocument}; use dom::documentfragment::DocumentFragment; use dom::documenttype::DocumentType; use dom::element::{Element, ElementMethods, ElementTypeId, HTMLAnchorElementTypeId}; @@ -224,6 +224,174 @@ pub enum NodeTypeId { ProcessingInstructionNodeTypeId, } +trait PrivateNodeHelpers { + fn set_parent_node(&mut self, new_parent_node: Option>); + fn set_first_child(&mut self, new_first_child: Option>); + fn set_last_child(&mut self, new_last_child: Option>); + fn set_prev_sibling(&mut self, new_prev_sibling: Option>); + fn set_next_sibling(&mut self, new_next_sibling: Option>); + + fn node_inserted(&self); + fn node_removed(&self); + fn add_child(&mut self, new_child: &mut JSRef, before: Option>); + fn remove_child(&mut self, child: &mut JSRef); +} + +impl<'a> PrivateNodeHelpers for JSRef<'a, Node> { + // http://dom.spec.whatwg.org/#node-is-inserted + fn node_inserted(&self) { + let roots = RootCollection::new(); + assert!(self.parent_node().is_some()); + let document = document_from_node(self).root(&roots); + + if self.is_in_doc() { + for node in self.traverse_preorder(&roots) { + vtable_for(&node).bind_to_tree(); + } + } + + self.parent_node().root(&roots) + .map(|parent| vtable_for(&*parent).child_inserted(self)); + + document.deref().content_changed(); + } + + // http://dom.spec.whatwg.org/#node-is-removed + fn node_removed(&self) { + let roots = RootCollection::new(); + assert!(self.parent_node().is_none()); + let document = document_from_node(self).root(&roots); + + for node in self.traverse_preorder(&roots) { + // XXX how about if the node wasn't in the tree in the first place? + vtable_for(&node).unbind_from_tree(); + } + + document.deref().content_changed(); + } + + // + // Pointer stitching + // + + /// Adds a new child to the end of this node's list of children. + /// + /// Fails unless `new_child` is disconnected from the tree. + fn add_child(&mut self, new_child: &mut JSRef, mut before: Option>) { + let roots = RootCollection::new(); + assert!(new_child.parent_node().is_none()); + assert!(new_child.prev_sibling().is_none()); + assert!(new_child.next_sibling().is_none()); + match before { + Some(ref mut before) => { + // XXX Should assert that parent is self. + assert!(before.parent_node().is_some()); + match before.prev_sibling() { + None => { + // XXX Should assert that before is the first child of + // self. + self.set_first_child(Some(new_child.clone())); + }, + Some(prev_sibling) => { + let mut prev_sibling = prev_sibling.root(&roots); + prev_sibling.set_next_sibling(Some(new_child.clone())); + new_child.set_prev_sibling(Some((*prev_sibling).clone())); + }, + } + before.set_prev_sibling(Some(new_child.clone())); + new_child.set_next_sibling(Some(before.clone())); + }, + None => { + match self.last_child().map(|child| child.root(&roots)) { + None => self.set_first_child(Some(new_child.clone())), + Some(mut last_child) => { + assert!(last_child.next_sibling().is_none()); + last_child.set_next_sibling(Some(new_child.clone())); + new_child.set_prev_sibling(Some((*last_child).clone())); + } + } + + self.set_last_child(Some(new_child.clone())); + }, + } + + new_child.set_parent_node(Some(self.clone())); + } + + /// Removes the given child from this node's list of children. + /// + /// Fails unless `child` is a child of this node. (FIXME: This is not yet checked.) + fn remove_child(&mut self, child: &mut JSRef) { + let roots = RootCollection::new(); + assert!(child.parent_node.is_some()); + + match child.prev_sibling.root(&roots) { + None => { + let next_sibling = child.next_sibling.as_ref().map(|next| next.root(&roots)); + self.set_first_child(next_sibling.root_ref()); + } + Some(ref mut prev_sibling) => { + let next_sibling = child.next_sibling.as_ref().map(|next| next.root(&roots)); + prev_sibling.set_next_sibling(next_sibling.root_ref()); + } + } + + match child.next_sibling.root(&roots) { + None => { + let prev_sibling = child.prev_sibling.as_ref().map(|prev| prev.root(&roots)); + self.set_last_child(prev_sibling.root_ref()); + } + Some(ref mut next_sibling) => { + let prev_sibling = child.prev_sibling.as_ref().map(|prev| prev.root(&roots)); + next_sibling.set_prev_sibling(prev_sibling.root_ref()); + } + } + + child.set_prev_sibling(None); + child.set_next_sibling(None); + child.set_parent_node(None); + } + + // + // Low-level pointer stitching + // + + fn set_parent_node(&mut self, new_parent_node: Option>) { + let roots = RootCollection::new(); + let doc = self.owner_doc().root(&roots); + doc.deref().wait_until_safe_to_modify_dom(); + self.parent_node.assign(new_parent_node); + } + + fn set_first_child(&mut self, new_first_child: Option>) { + let roots = RootCollection::new(); + let doc = self.owner_doc().root(&roots); + doc.deref().wait_until_safe_to_modify_dom(); + self.first_child.assign(new_first_child); + } + + fn set_last_child(&mut self, new_last_child: Option>) { + let roots = RootCollection::new(); + let doc = self.owner_doc().root(&roots); + doc.deref().wait_until_safe_to_modify_dom(); + self.last_child.assign(new_last_child); + } + + fn set_prev_sibling(&mut self, new_prev_sibling: Option>) { + let roots = RootCollection::new(); + let doc = self.owner_doc().root(&roots); + doc.deref().wait_until_safe_to_modify_dom(); + self.prev_sibling.assign(new_prev_sibling); + } + + fn set_next_sibling(&mut self, new_next_sibling: Option>) { + let roots = RootCollection::new(); + let doc = self.owner_doc().root(&roots); + doc.deref().wait_until_safe_to_modify_dom(); + self.next_sibling.assign(new_next_sibling); + } +} + pub trait NodeHelpers { fn ancestors(&self) -> AncestorIterator; fn children(&self) -> AbstractNodeChildrenIterator; @@ -241,17 +409,17 @@ pub trait NodeHelpers { fn prev_sibling(&self) -> Option>; fn next_sibling(&self) -> Option>; + fn owner_doc(&self) -> Unrooted; + fn set_owner_doc(&mut self, document: &JSRef); + + fn wait_until_safe_to_modify_dom(&self); + fn is_element(&self) -> bool; fn is_document(&self) -> bool; fn is_doctype(&self) -> bool; fn is_text(&self) -> bool; fn is_anchor_element(&self) -> bool; - fn node_inserted(&self); - fn node_removed(&self); - fn add_child(&mut self, new_child: &mut JSRef, before: Option>); - fn remove_child(&mut self, child: &mut JSRef); - fn get_hover_state(&self) -> bool; fn set_hover_state(&mut self, state: bool); @@ -296,19 +464,6 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { format!("{:?}", self.type_id()) } - /// Iterates over all ancestors of this node. - fn ancestors(&self) -> AncestorIterator { - self.get().ancestors() - } - - fn children(&self) -> AbstractNodeChildrenIterator { - self.get().children() - } - - fn child_elements(&self) -> ChildElementIterator { - self.get().child_elements() - } - fn is_in_doc(&self) -> bool { self.get().flags.is_in_doc() } @@ -342,7 +497,10 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { #[inline] fn is_element(&self) -> bool { - self.get().is_element() + match self.type_id { + ElementNodeTypeId(..) => true, + _ => false + } } #[inline] @@ -363,7 +521,10 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { #[inline] fn is_doctype(&self) -> bool { - self.get().is_doctype() + match self.type_id { + DoctypeNodeTypeId => true, + _ => false + } } #[inline] @@ -376,127 +537,12 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { } } - // http://dom.spec.whatwg.org/#node-is-inserted - fn node_inserted(&self) { - let roots = RootCollection::new(); - assert!(self.parent_node().is_some()); - let document = document_from_node(self).root(&roots); - - if self.is_in_doc() { - for node in self.traverse_preorder(&roots) { - vtable_for(&node).bind_to_tree(); - } - } - - self.parent_node().root(&roots) - .map(|parent| vtable_for(&*parent).child_inserted(self)); - document.get().content_changed(); - } - - // http://dom.spec.whatwg.org/#node-is-removed - fn node_removed(&self) { - let roots = RootCollection::new(); - assert!(self.parent_node().is_none()); - let document = document_from_node(self).root(&roots); - - for node in self.traverse_preorder(&roots) { - // XXX how about if the node wasn't in the tree in the first place? - vtable_for(&node).unbind_from_tree(); - } - - document.get().content_changed(); - } - - // - // Pointer stitching - // - - /// Adds a new child to the end of this node's list of children. - /// - /// Fails unless `new_child` is disconnected from the tree. - fn add_child(&mut self, new_child: &mut JSRef, mut before: Option>) { - let roots = RootCollection::new(); - assert!(new_child.parent_node().is_none()); - assert!(new_child.prev_sibling().is_none()); - assert!(new_child.next_sibling().is_none()); - match before { - Some(ref mut before) => { - // XXX Should assert that parent is self. - assert!(before.parent_node().is_some()); - match before.prev_sibling() { - None => { - // XXX Should assert that before is the first child of - // self. - self.get_mut().set_first_child(Some(new_child.clone())); - }, - Some(prev_sibling) => { - let mut prev_sibling = prev_sibling.root(&roots); - prev_sibling.get_mut().set_next_sibling(Some(new_child.clone())); - new_child.get_mut().set_prev_sibling(Some((*prev_sibling).clone())); - }, - } - before.get_mut().set_prev_sibling(Some(new_child.clone())); - new_child.get_mut().set_next_sibling(Some(before.clone())); - }, - None => { - match self.last_child().map(|child| child.root(&roots)) { - None => self.get_mut().set_first_child(Some(new_child.clone())), - Some(mut last_child) => { - assert!(last_child.next_sibling().is_none()); - last_child.get_mut().set_next_sibling(Some(new_child.clone())); - new_child.get_mut().set_prev_sibling(Some((*last_child).clone())); - } - } - - self.get_mut().set_last_child(Some(new_child.clone())); - }, - } - - new_child.get_mut().set_parent_node(Some(self.clone())); - } - - /// Removes the given child from this node's list of children. - /// - /// Fails unless `child` is a child of this node. (FIXME: This is not yet checked.) - fn remove_child(&mut self, child: &mut JSRef) { - let roots = RootCollection::new(); - let this_node = self.get_mut(); - let child_node = child.get_mut(); - assert!(child_node.parent_node.is_some()); - - match child_node.prev_sibling.root(&roots) { - None => { - let next_sibling = child_node.next_sibling.as_ref().map(|next| next.root(&roots)); - this_node.set_first_child(next_sibling.root_ref()); - } - Some(ref mut prev_sibling) => { - let next_sibling = child_node.next_sibling.as_ref().map(|next| next.root(&roots)); - prev_sibling.set_next_sibling(next_sibling.root_ref()); - } - } - - match child_node.next_sibling.root(&roots) { - None => { - let prev_sibling = child_node.prev_sibling.as_ref().map(|prev| prev.root(&roots)); - this_node.set_last_child(prev_sibling.root_ref()); - } - Some(ref mut next_sibling) => { - let prev_sibling = child_node.prev_sibling.as_ref().map(|prev| prev.root(&roots)); - next_sibling.set_prev_sibling(prev_sibling.root_ref()); - } - } - - child_node.set_prev_sibling(None); - child_node.set_next_sibling(None); - child_node.set_parent_node(None); - } - fn get_hover_state(&self) -> bool { - self.get().flags.get_in_hover_state() + self.flags.get_in_hover_state() } fn set_hover_state(&mut self, state: bool) { - self.get_mut().flags.set_is_in_hover_state(state); + self.flags.set_is_in_hover_state(state); } /// Iterates over this node and all its descendants, in preorder. @@ -563,6 +609,48 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { let ContentBoxesResponse(rects) = page.query_layout(ContentBoxesQuery(addr, chan), port); rects } + + fn ancestors(&self) -> AncestorIterator { + let roots = RootCollection::new(); + AncestorIterator { + current: self.parent_node.clone().map(|node| (*node.root(&roots)).clone()), + roots: roots, + } + } + + fn owner_doc(&self) -> Unrooted { + Unrooted::new(self.owner_doc.get_ref().clone()) + } + + fn set_owner_doc(&mut self, document: &JSRef) { + self.owner_doc = Some(document.unrooted()); + } + + fn children(&self) -> AbstractNodeChildrenIterator { + let roots = RootCollection::new(); + AbstractNodeChildrenIterator { + current_node: self.first_child.clone().map(|node| (*node.root(&roots)).clone()), + roots: roots, + } + } + + fn child_elements(&self) -> ChildElementIterator { + self.children() + .filter(|node| { + node.is_element() + }) + .map(|node| { + let elem: &JSRef = ElementCast::to_ref(&node).unwrap(); + elem.clone() + }) + } + + fn wait_until_safe_to_modify_dom(&self) { + let roots = RootCollection::new(); + let document = self.owner_doc().root(&roots); + document.deref().wait_until_safe_to_modify_dom(); + } + } /// If the given untrusted node address represents a valid DOM node in the given runtime, @@ -582,19 +670,69 @@ pub fn from_untrusted_node_address(runtime: *JSRuntime, candidate: UntrustedNode } pub trait LayoutNodeHelpers { - fn type_id_for_layout(&self) -> NodeTypeId; + unsafe fn type_id_for_layout(&self) -> NodeTypeId; + + unsafe fn parent_node_ref<'a>(&'a self) -> Option<&'a JS>; + unsafe fn first_child_ref<'a>(&'a self) -> Option<&'a JS>; + unsafe fn last_child_ref<'a>(&'a self) -> Option<&'a JS>; + unsafe fn prev_sibling_ref<'a>(&'a self) -> Option<&'a JS>; + unsafe fn next_sibling_ref<'a>(&'a self) -> Option<&'a JS>; + + unsafe fn owner_doc_for_layout<'a>(&'a self) -> &'a JS; + + unsafe fn is_element_for_layout(&self) -> bool; } impl LayoutNodeHelpers for JS { - fn type_id_for_layout(&self) -> NodeTypeId { - unsafe { - let node: **Node = cast::transmute::<*JS, - **Node>(self); - (**node).type_id - } + unsafe fn type_id_for_layout(&self) -> NodeTypeId { + (*self.unsafe_get()).type_id + } + + unsafe fn is_element_for_layout(&self) -> bool { + (*self.unsafe_get()).is_element() + } + + #[inline] + unsafe fn parent_node_ref<'a>(&'a self) -> Option<&'a JS> { + (*self.unsafe_get()).parent_node.as_ref() + } + + #[inline] + unsafe fn first_child_ref<'a>(&'a self) -> Option<&'a JS> { + (*self.unsafe_get()).first_child.as_ref() + } + + #[inline] + unsafe fn last_child_ref<'a>(&'a self) -> Option<&'a JS> { + (*self.unsafe_get()).last_child.as_ref() + } + + #[inline] + unsafe fn prev_sibling_ref<'a>(&'a self) -> Option<&'a JS> { + (*self.unsafe_get()).prev_sibling.as_ref() + } + + #[inline] + unsafe fn next_sibling_ref<'a>(&'a self) -> Option<&'a JS> { + (*self.unsafe_get()).next_sibling.as_ref() + } + + unsafe fn owner_doc_for_layout<'a>(&'a self) -> &'a JS { + (*self.unsafe_get()).owner_doc.get_ref() } } +pub trait RawLayoutNodeHelpers { + unsafe fn get_hover_state_for_layout(&self) -> bool; +} + +impl RawLayoutNodeHelpers for Node { + unsafe fn get_hover_state_for_layout(&self) -> bool { + self.flags.get_in_hover_state() + } +} + + // // Iteration and traversal // @@ -689,7 +827,7 @@ impl<'a> NodeIterator<'a> { } fn next_child<'b>(&self, node: &JSRef<'b, Node>) -> Option> { - if !self.include_descendants_of_void && node.get().is_element() { + if !self.include_descendants_of_void && node.is_element() { let elem: &JSRef = ElementCast::to_ref(node).unwrap(); if elem.get().is_void() { None @@ -771,65 +909,6 @@ pub enum CloneChildrenFlag { fn as_uintptr(t: &T) -> uintptr_t { t as *T as uintptr_t } impl Node { - pub fn ancestors(&self) -> AncestorIterator { - let roots = RootCollection::new(); - AncestorIterator { - current: self.parent_node.clone().map(|node| (*node.root(&roots)).clone()), - roots: roots, - } - } - - pub fn is_element(&self) -> bool { - match self.type_id { - ElementNodeTypeId(..) => true, - _ => false - } - } - - pub fn is_doctype(&self) -> bool { - match self.type_id { - DoctypeNodeTypeId => true, - _ => false - } - } - - pub fn owner_doc(&self) -> Unrooted { - Unrooted::new(self.owner_doc.get_ref().clone()) - } - - pub fn owner_doc_for_layout<'a>(&'a self) -> &'a JS { - self.owner_doc.get_ref() - } - - pub fn set_owner_doc(&mut self, document: &JSRef) { - self.owner_doc = Some(document.unrooted()); - } - - pub fn children(&self) -> AbstractNodeChildrenIterator { - let roots = RootCollection::new(); - AbstractNodeChildrenIterator { - current_node: self.first_child.clone().map(|node| (*node.root(&roots)).clone()), - roots: roots, - } - } - - pub fn child_elements(&self) -> ChildElementIterator { - self.children() - .filter(|node| { - node.is_element() - }) - .map(|node| { - let elem: &JSRef = ElementCast::to_ref(&node).unwrap(); - elem.clone() - }) - } - - pub fn wait_until_safe_to_modify_dom(&self) { - let roots = RootCollection::new(); - let document = self.owner_doc().root(&roots); - document.get().wait_until_safe_to_modify_dom(); - } - pub fn reflect_node (node: ~N, document: &JSRef, @@ -873,21 +952,6 @@ impl Node { } } - /// Sends layout data, if any, back to the script task to be destroyed. - pub unsafe fn reap_layout_data(&mut self) { - if self.layout_data.is_present() { - let layout_data = mem::replace(&mut self.layout_data, LayoutDataRef::new()); - let layout_chan = layout_data.take_chan(); - match layout_chan { - None => {} - Some(chan) => { - let LayoutChan(chan) = chan; - chan.send(ReapLayoutDataMsg(layout_data)) - }, - } - } - } - // http://dom.spec.whatwg.org/#concept-node-adopt pub fn adopt(node: &mut JSRef, document: &JSRef) { let roots = RootCollection::new(); @@ -903,7 +967,7 @@ impl Node { let node_doc = document_from_node(node).root(&roots); if &*node_doc != document { for mut descendant in node.traverse_preorder(&roots) { - descendant.get_mut().set_owner_doc(document); + descendant.set_owner_doc(document); } } @@ -976,7 +1040,7 @@ impl Node { } match child { Some(ref child) if child.inclusively_following_siblings() - .any(|child| child.deref().is_doctype()) => { + .any(|child| child.is_doctype()) => { return Err(HierarchyRequest); } _ => (), @@ -995,7 +1059,7 @@ impl Node { } match child { Some(ref child) if child.inclusively_following_siblings() - .any(|child| child.deref().is_doctype()) => { + .any(|child| child.is_doctype()) => { return Err(HierarchyRequest); } _ => (), @@ -1003,14 +1067,14 @@ impl Node { }, // Step 6.3 DoctypeNodeTypeId => { - if parent.children().any(|c| c.deref().is_doctype()) { + if parent.children().any(|c| c.is_doctype()) { return Err(HierarchyRequest); } match child { Some(ref child) => { if parent.children() .take_while(|c| c != child) - .any(|c| c.deref().is_element()) { + .any(|c| c.is_element()) { return Err(HierarchyRequest); } }, @@ -1092,7 +1156,7 @@ impl Node { } // http://dom.spec.whatwg.org/#concept-node-replace-all - pub fn replace_all(mut node: Option>, parent: &mut JSRef) { + fn replace_all(mut node: Option>, parent: &mut JSRef) { let roots = RootCollection::new(); // Step 1. @@ -1178,7 +1242,7 @@ impl Node { // Step 1. let mut document = match maybe_doc { Some(doc) => doc.unrooted().root(&roots), - None => node.get().owner_doc().root(&roots) + None => node.owner_doc().root(&roots) }; // Step 2. @@ -1204,7 +1268,6 @@ impl Node { }, DocumentNodeTypeId => { let document: &JSRef = DocumentCast::to_ref(node).unwrap(); - let document = document.get(); let is_html_doc = match document.is_html_document { true => HTMLDocument, false => NonHTMLDocument @@ -1242,15 +1305,13 @@ impl Node { } else { document.unrooted().root(&roots) }; - assert!(&*copy.get().owner_doc().root(&roots) == &*document); + assert!(&*copy.owner_doc().root(&roots) == &*document); // Step 4 (some data already copied in step 2). match node.get().type_id { DocumentNodeTypeId => { let node_doc: &JSRef = DocumentCast::to_ref(node).unwrap(); - let node_doc = node_doc.get(); let copy_doc: &mut JSRef = DocumentCast::to_mut_ref(&mut *copy).unwrap(); - let copy_doc = copy_doc.get_mut(); copy_doc.set_encoding_name(node_doc.encoding_name.clone()); copy_doc.set_quirks_mode(node_doc.quirks_mode()); }, @@ -1281,7 +1342,7 @@ impl Node { // Step 6. if clone_children == CloneChildren { - for ref child in node.get().children() { + for ref child in node.children() { let mut child_copy = Node::clone(&*child, Some(&*document), clone_children).root(&roots); let _inserted_node = Node::pre_insert(&mut *child_copy, &mut *copy, None); } @@ -1291,81 +1352,19 @@ impl Node { Unrooted::new_rooted(&*copy) } - // - // Low-level pointer stitching - // - - pub fn set_parent_node(&mut self, new_parent_node: Option>) { - let roots = RootCollection::new(); - let doc = self.owner_doc().root(&roots); - doc.get().wait_until_safe_to_modify_dom(); - self.parent_node.assign(new_parent_node); - } - - pub fn set_first_child(&mut self, new_first_child: Option>) { - let roots = RootCollection::new(); - let doc = self.owner_doc().root(&roots); - doc.get().wait_until_safe_to_modify_dom(); - self.first_child.assign(new_first_child); - } - - pub fn set_last_child(&mut self, new_last_child: Option>) { - let roots = RootCollection::new(); - let doc = self.owner_doc().root(&roots); - doc.get().wait_until_safe_to_modify_dom(); - self.last_child.assign(new_last_child); - } - - pub fn set_prev_sibling(&mut self, new_prev_sibling: Option>) { - let roots = RootCollection::new(); - let doc = self.owner_doc().root(&roots); - doc.get().wait_until_safe_to_modify_dom(); - self.prev_sibling.assign(new_prev_sibling); - } - - pub fn set_next_sibling(&mut self, new_next_sibling: Option>) { - let roots = RootCollection::new(); - let doc = self.owner_doc().root(&roots); - doc.get().wait_until_safe_to_modify_dom(); - self.next_sibling.assign(new_next_sibling); - } - - pub fn get_hover_state(&self) -> bool { - self.flags.get_in_hover_state() - } - - pub fn set_hover_state(&mut self, state: bool) { - self.flags.set_is_in_hover_state(state); - } - - #[inline] - pub fn parent_node_ref<'a>(&'a self) -> Option<&'a JS> { - self.parent_node.as_ref() - } - - #[inline] - pub fn first_child_ref<'a>(&'a self) -> Option<&'a JS> { - self.first_child.as_ref() - } - - #[inline] - pub fn last_child_ref<'a>(&'a self) -> Option<&'a JS> { - self.last_child.as_ref() - } - - #[inline] - pub fn prev_sibling_ref<'a>(&'a self) -> Option<&'a JS> { - self.prev_sibling.as_ref() - } - - #[inline] - pub fn next_sibling_ref<'a>(&'a self) -> Option<&'a JS> { - self.next_sibling.as_ref() - } - - pub unsafe fn get_hover_state_for_layout(&self) -> bool { - let unsafe_this: *Node = cast::transmute::<&Node,*Node>(self); - (*unsafe_this).flags.get_in_hover_state() + /// Sends layout data, if any, back to the script task to be destroyed. + unsafe fn reap_layout_data(&mut self) { + if self.layout_data.is_present() { + let layout_data = mem::replace(&mut self.layout_data, LayoutDataRef::new()); + let layout_chan = layout_data.take_chan(); + match layout_chan { + None => {} + Some(chan) => { + let LayoutChan(chan) = chan; + chan.send(ReapLayoutDataMsg(layout_data)) + }, + } + } } } @@ -1486,7 +1485,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { Some(ref list) => return Unrooted::new(list.clone()), } - let doc = self.deref().owner_doc().root(&roots); + let doc = self.owner_doc().root(&roots); let window = doc.deref().window.root(&roots); let child_list = NodeList::new_child_list(&*window, self); self.child_list.assign(Some(child_list)); @@ -1600,7 +1599,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { // Notify the document that the content of this node is different let document = self.owner_doc().root(&roots); - document.get().content_changed(); + document.deref().content_changed(); } DoctypeNodeTypeId | DocumentNodeTypeId => {} @@ -1671,7 +1670,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { return Err(HierarchyRequest); } if child.following_siblings() - .any(|child| child.deref().is_doctype()) { + .any(|child| child.is_doctype()) { return Err(HierarchyRequest); } }, @@ -1685,18 +1684,18 @@ impl<'a> NodeMethods for JSRef<'a, Node> { return Err(HierarchyRequest); } if child.following_siblings() - .any(|child| child.deref().is_doctype()) { + .any(|child| child.is_doctype()) { return Err(HierarchyRequest); } }, // Step 6.3 DoctypeNodeTypeId => { - if self.children().any(|c| c.deref().is_doctype() && &c != child) { + if self.children().any(|c| c.is_doctype() && &c != child) { return Err(HierarchyRequest); } if self.children() .take_while(|c| c != child) - .any(|c| c.deref().is_element()) { + .any(|c| c.is_element()) { return Err(HierarchyRequest); } }, diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index f9a4f641ffc..9326ed6cb15 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -7,11 +7,11 @@ use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, TextCast, Element use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast; use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalRootable, Root}; use dom::bindings::utils::Reflectable; -use dom::document::Document; +use dom::document::{Document, DocumentHelpers}; use dom::element::{AttributeHandlers, HTMLLinkElementTypeId, HTMLIFrameElementTypeId}; use dom::htmlelement::HTMLElement; use dom::htmlheadingelement::{Heading1, Heading2, Heading3, Heading4, Heading5, Heading6}; -use dom::htmliframeelement::IFrameSize; +use dom::htmliframeelement::{IFrameSize, HTMLIFrameElementHelpers}; use dom::htmlformelement::HTMLFormElement; use dom::node::{ElementNodeTypeId, NodeHelpers, NodeMethods}; use dom::types::*; @@ -364,7 +364,11 @@ pub fn parse_html(page: &Page, }; // Spawn additional parsing, network loads, etc. from tag and attrs - match element.get().node.type_id { + let type_id = { + let node: &JSRef = NodeCast::from_ref(&*element); + node.type_id() + }; + match type_id { // Handle CSS style sheets from elements ElementNodeTypeId(HTMLLinkElementTypeId) => { match (rel, href) { @@ -384,10 +388,10 @@ pub fn parse_html(page: &Page, let iframe_chan = discovery_chan.clone(); let iframe_element: &mut JSRef = HTMLIFrameElementCast::to_mut_ref(&mut *element).unwrap(); - let sandboxed = iframe_element.get().is_sandboxed(); + let sandboxed = iframe_element.is_sandboxed(); for src in src_opt.iter() { let iframe_url = parse_url(*src, Some(url2.clone())); - iframe_element.get_mut().set_frame(iframe_url.clone()); + iframe_element.set_frame(iframe_url.clone()); // Subpage Id let subpage_id = *next_subpage_id.borrow(); @@ -463,14 +467,14 @@ pub fn parse_html(page: &Page, // NOTE: tmp vars are workaround for lifetime issues. Both required. let mut tmp_borrow = doc_cell.borrow_mut(); let tmp = &mut *tmp_borrow; - tmp.get_mut().set_quirks_mode(mode); + tmp.set_quirks_mode(mode); }, encoding_change: |encname| { debug!("encoding change"); // NOTE: tmp vars are workaround for lifetime issues. Both required. let mut tmp_borrow = doc_cell.borrow_mut(); let tmp = &mut *tmp_borrow; - tmp.get_mut().set_encoding_name(encname); + tmp.set_encoding_name(encname); }, complete_script: |script| { unsafe { diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index 600f28794a1..d82dace6d99 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -12,7 +12,7 @@ use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalAssignable} use dom::bindings::js::OptionalRootable; use dom::bindings::trace::{Traceable, Untraceable}; use dom::bindings::utils::{Reflectable, GlobalStaticData, wrap_for_same_compartment}; -use dom::document::{Document, HTMLDocument, DocumentMethods}; +use dom::document::{Document, HTMLDocument, DocumentMethods, DocumentHelpers}; use dom::element::{Element, AttributeHandlers}; use dom::event::{Event_, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent}; use dom::event::{Event, EventMethods}; @@ -949,7 +949,7 @@ impl ScriptTask { } // Kick off the initial reflow of the page. - document.get().content_changed(); + document.content_changed(); let fragment = url.fragment.as_ref().map(|ref fragment| fragment.to_owned()); From 8e10daba979a7a30b69ffd66dd4f3b256c39b615 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 17 Apr 2014 17:03:21 -0400 Subject: [PATCH 07/16] Allow controlling GC zeal via JS_GC_ZEAL environment variable. --- src/components/script/script_task.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index d82dace6d99..e319ef18837 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -36,7 +36,7 @@ use geom::point::Point2D; use geom::size::Size2D; use js::global::DEBUG_FNS; use js::jsapi::{JSObject, JS_CallFunctionValue, JS_DefineFunctions}; -use js::jsapi::JS_SetWrapObjectCallbacks; +use js::jsapi::{JS_SetWrapObjectCallbacks, JS_SetGCZeal, JS_DEFAULT_ZEAL_FREQ}; use js::jsval::NullValue; use js::rust::{Cx, RtUtils}; use js; @@ -432,6 +432,10 @@ impl Page { // Note that the order that these variables are initialized is _not_ arbitrary. Switching // them around can -- and likely will -- lead to things breaking. + unsafe { + JS_SetGCZeal(js_context.deref().ptr, 0, JS_DEFAULT_ZEAL_FREQ); + } + js_context.set_default_options_and_version(); js_context.set_logging_error_reporter(); From bbfed381686aef5703da53a104f9c05c6d3475c5 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 17 Apr 2014 17:03:58 -0400 Subject: [PATCH 08/16] Move stack roots into Root types instead of RootCollection, removing the aribtrary 10 roots per stack frame restriction. --- src/components/script/dom/bindings/js.rs | 83 +++++++----------------- 1 file changed, 23 insertions(+), 60 deletions(-) diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs index 3a3b6bd7166..b26d2601139 100644 --- a/src/components/script/dom/bindings/js.rs +++ b/src/components/script/dom/bindings/js.rs @@ -8,8 +8,7 @@ use js::jsapi::{JSObject, JSContext}; use layout_interface::TrustedNodeAddress; use std::cast; -use std::cell::{Cell, RefCell}; -use std::ptr; +use std::cell::RefCell; /// A type that represents a JS-owned value that may or may not be rooted. /// Importantly, it requires rooting in order to interact with the value in any way. @@ -238,32 +237,15 @@ impl UnrootedPushable for Vec> { } } -#[deriving(Eq, Clone)] -struct RootReference(*JSObject); - -impl RootReference { - fn new<'a, 'b, T: Reflectable>(unrooted: &Root<'a, 'b, T>) -> RootReference { - RootReference(unrooted.rooted()) - } - - fn null() -> RootReference { - RootReference(ptr::null()) - } -} - -static MAX_STACK_ROOTS: uint = 10; - /// An opaque, LIFO rooting mechanism. pub struct RootCollection { - roots: [Cell, ..MAX_STACK_ROOTS], - current: Cell, + roots: RefCell<~[*JSObject]>, } impl RootCollection { pub fn new() -> RootCollection { RootCollection { - roots: [Cell::new(RootReference::null()), ..MAX_STACK_ROOTS], - current: Cell::new(0), + roots: RefCell::new(~[]), } } @@ -271,40 +253,27 @@ impl RootCollection { Root::new(self, unrooted) } - fn root_impl(&self, unrooted: RootReference) { - let current = self.current.get(); - assert!(current < MAX_STACK_ROOTS); - self.roots[current].set(unrooted); - debug!(" rooting {:?}", unrooted); - self.current.set(current + 1); - } - fn root<'a, 'b, T: Reflectable>(&self, unrooted: &Root<'a, 'b, T>) { - self.root_impl(RootReference::new(unrooted)); + self.root_raw(unrooted.js_ptr); } /// Root a raw JS pointer. pub fn root_raw(&self, unrooted: *JSObject) { - self.root_impl(RootReference(unrooted)); - } - - fn unroot_impl(&self, rooted: RootReference) { - let mut current = self.current.get(); - assert!(current != 0); - current -= 1; - debug!("unrooting {:?} (expecting {:?}", self.roots[current].get(), rooted); - assert!(self.roots[current].get() == rooted); - self.roots[current].set(RootReference::null()); - self.current.set(current); + let mut roots = self.roots.borrow_mut(); + roots.push(unrooted); + debug!(" rooting {:?}", unrooted); } fn unroot<'a, 'b, T: Reflectable>(&self, rooted: &Root<'a, 'b, T>) { - self.unroot_impl(RootReference::new(rooted)); + self.unroot_raw(rooted.js_ptr); } /// Unroot a raw JS pointer. Must occur in reverse order to its rooting. pub fn unroot_raw(&self, rooted: *JSObject) { - self.unroot_impl(RootReference(rooted)); + let mut roots = self.roots.borrow_mut(); + debug!("unrooting {:?} (expecting {:?}", roots.last().unwrap(), rooted); + assert!(*roots.last().unwrap() == rooted); + roots.pop().unwrap(); } } @@ -314,9 +283,14 @@ impl RootCollection { /// Attempts to transfer ownership of a Root via moving will trigger dynamic unrooting /// failures due to incorrect ordering. pub struct Root<'a, 'b, T> { + /// List that ensures correct dynamic root ordering root_list: &'a RootCollection, + /// Reference to rooted value that must not outlive this container jsref: JSRef<'b, T>, + /// Pointer to underlying Rust data ptr: RefCell<*mut T>, + /// On-stack JS pointer to assuage conservative stack scanner + js_ptr: *JSObject, } impl<'a, 'b, T: Reflectable> Root<'a, 'b, T> { @@ -325,9 +299,10 @@ impl<'a, 'b, T: Reflectable> Root<'a, 'b, T> { root_list: roots, jsref: JSRef { ptr: unrooted.ptr.clone(), - chain: unsafe { ::std::cast::transmute_region(&()) }, + chain: unsafe { cast::transmute_region(&()) }, }, - ptr: unrooted.ptr.clone() + ptr: unrooted.ptr.clone(), + js_ptr: unrooted.reflector().get_jsobject(), }; roots.root(&root); root @@ -347,20 +322,8 @@ impl<'a, 'b, T: Reflectable> Root<'a, 'b, T> { } } - fn rooted(&self) -> *JSObject { - self.reflector().get_jsobject() - } - - fn internal_root_ref<'a>(&'a self) -> &'a JSRef<'b, T> { - &'a self.jsref - } - - fn mut_internal_root_ref<'a>(&'a mut self) -> &'a mut JSRef<'b, T> { - &'a mut self.jsref - } - pub fn root_ref<'b>(&'b self) -> JSRef<'b,T> { - self.internal_root_ref().clone() + self.jsref.clone() } } @@ -383,13 +346,13 @@ impl<'a, 'b, T: Reflectable> Reflectable for Root<'a, 'b, T> { impl<'a, 'b, T: Reflectable> Deref> for Root<'a, 'b, T> { fn deref<'c>(&'c self) -> &'c JSRef<'b, T> { - self.internal_root_ref() + &'a self.jsref } } impl<'a, 'b, T: Reflectable> DerefMut> for Root<'a, 'b, T> { fn deref_mut<'c>(&'c mut self) -> &'c mut JSRef<'b, T> { - self.mut_internal_root_ref() + &'a mut self.jsref } } From 522d3f167b12fa79401eea5525c7b6133cae0f06 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 17 Apr 2014 17:08:00 -0400 Subject: [PATCH 09/16] s/Unrooted/Temporary/g --- src/components/script/dom/attr.rs | 4 +- src/components/script/dom/attrlist.rs | 14 +- .../dom/bindings/codegen/CodegenRust.py | 6 +- .../dom/bindings/codegen/Configuration.py | 2 +- src/components/script/dom/bindings/js.rs | 44 ++--- src/components/script/dom/bindings/utils.rs | 8 +- src/components/script/dom/blob.rs | 10 +- src/components/script/dom/browsercontext.rs | 10 +- src/components/script/dom/clientrect.rs | 4 +- src/components/script/dom/clientrectlist.rs | 14 +- src/components/script/dom/comment.rs | 6 +- src/components/script/dom/console.rs | 4 +- src/components/script/dom/document.rs | 150 +++++++++--------- src/components/script/dom/documentfragment.rs | 10 +- src/components/script/dom/documenttype.rs | 4 +- src/components/script/dom/domexception.rs | 4 +- .../script/dom/domimplementation.rs | 20 +-- src/components/script/dom/domparser.rs | 10 +- src/components/script/dom/element.rs | 44 ++--- src/components/script/dom/event.rs | 20 +-- src/components/script/dom/formdata.rs | 6 +- .../script/dom/htmlanchorelement.rs | 4 +- .../script/dom/htmlappletelement.rs | 4 +- src/components/script/dom/htmlareaelement.rs | 4 +- src/components/script/dom/htmlaudioelement.rs | 4 +- src/components/script/dom/htmlbaseelement.rs | 4 +- src/components/script/dom/htmlbodyelement.rs | 4 +- src/components/script/dom/htmlbrelement.rs | 4 +- .../script/dom/htmlbuttonelement.rs | 12 +- .../script/dom/htmlcanvaselement.rs | 4 +- src/components/script/dom/htmlcollection.rs | 38 ++--- src/components/script/dom/htmldataelement.rs | 4 +- .../script/dom/htmldatalistelement.rs | 8 +- .../script/dom/htmldirectoryelement.rs | 4 +- src/components/script/dom/htmldivelement.rs | 4 +- src/components/script/dom/htmldlistelement.rs | 4 +- src/components/script/dom/htmlelement.rs | 8 +- src/components/script/dom/htmlembedelement.rs | 8 +- .../script/dom/htmlfieldsetelement.rs | 16 +- src/components/script/dom/htmlfontelement.rs | 4 +- src/components/script/dom/htmlformelement.rs | 12 +- src/components/script/dom/htmlframeelement.rs | 12 +- .../script/dom/htmlframesetelement.rs | 4 +- src/components/script/dom/htmlheadelement.rs | 4 +- .../script/dom/htmlheadingelement.rs | 4 +- src/components/script/dom/htmlhrelement.rs | 4 +- src/components/script/dom/htmlhtmlelement.rs | 4 +- .../script/dom/htmliframeelement.rs | 16 +- src/components/script/dom/htmlimageelement.rs | 4 +- src/components/script/dom/htmlinputelement.rs | 4 +- src/components/script/dom/htmllabelelement.rs | 4 +- .../script/dom/htmllegendelement.rs | 4 +- src/components/script/dom/htmllielement.rs | 4 +- src/components/script/dom/htmllinkelement.rs | 4 +- src/components/script/dom/htmlmainelement.rs | 4 +- src/components/script/dom/htmlmapelement.rs | 8 +- src/components/script/dom/htmlmetaelement.rs | 4 +- src/components/script/dom/htmlmeterelement.rs | 4 +- src/components/script/dom/htmlmodelement.rs | 4 +- .../script/dom/htmlobjectelement.rs | 24 +-- src/components/script/dom/htmlolistelement.rs | 4 +- .../script/dom/htmloptgroupelement.rs | 4 +- .../script/dom/htmloptionelement.rs | 8 +- .../script/dom/htmloutputelement.rs | 12 +- .../script/dom/htmlparagraphelement.rs | 4 +- src/components/script/dom/htmlparamelement.rs | 4 +- src/components/script/dom/htmlpreelement.rs | 4 +- .../script/dom/htmlprogresselement.rs | 4 +- src/components/script/dom/htmlquoteelement.rs | 4 +- .../script/dom/htmlscriptelement.rs | 4 +- .../script/dom/htmlselectelement.rs | 24 +-- .../script/dom/htmlsourceelement.rs | 4 +- src/components/script/dom/htmlspanelement.rs | 4 +- src/components/script/dom/htmlstyleelement.rs | 4 +- .../script/dom/htmltablecaptionelement.rs | 4 +- .../script/dom/htmltablecolelement.rs | 4 +- .../script/dom/htmltabledatacellelement.rs | 4 +- src/components/script/dom/htmltableelement.rs | 4 +- .../script/dom/htmltableheadercellelement.rs | 4 +- .../script/dom/htmltablerowelement.rs | 4 +- .../script/dom/htmltablesectionelement.rs | 4 +- .../script/dom/htmltemplateelement.rs | 4 +- .../script/dom/htmltextareaelement.rs | 4 +- src/components/script/dom/htmltimeelement.rs | 4 +- src/components/script/dom/htmltitleelement.rs | 4 +- src/components/script/dom/htmltrackelement.rs | 4 +- src/components/script/dom/htmlulistelement.rs | 4 +- .../script/dom/htmlunknownelement.rs | 4 +- src/components/script/dom/htmlvideoelement.rs | 4 +- src/components/script/dom/location.rs | 4 +- src/components/script/dom/mouseevent.rs | 14 +- src/components/script/dom/navigator.rs | 4 +- src/components/script/dom/node.rs | 144 ++++++++--------- src/components/script/dom/nodelist.rs | 20 +-- .../script/dom/processinginstruction.rs | 4 +- src/components/script/dom/testbinding.rs | 10 +- src/components/script/dom/text.rs | 10 +- src/components/script/dom/uievent.rs | 18 +-- src/components/script/dom/validitystate.rs | 4 +- src/components/script/dom/window.rs | 44 ++--- src/components/script/dom/xmlhttprequest.rs | 18 +-- .../script/dom/xmlhttprequestupload.rs | 4 +- .../script/html/hubbub_html_parser.rs | 8 +- src/components/script/script_task.rs | 8 +- 104 files changed, 565 insertions(+), 565 deletions(-) diff --git a/src/components/script/dom/attr.rs b/src/components/script/dom/attr.rs index 5c37ca45632..fe4ea856cff 100644 --- a/src/components/script/dom/attr.rs +++ b/src/components/script/dom/attr.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::AttrBinding; use dom::bindings::codegen::InheritTypes::NodeCast; -use dom::bindings::js::{JS, JSRef, Unrooted, RootCollection}; +use dom::bindings::js::{JS, JSRef, Temporary, RootCollection}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::element::Element; use dom::node::Node; @@ -59,7 +59,7 @@ impl Attr { pub fn new(window: &JSRef, local_name: DOMString, value: DOMString, name: DOMString, namespace: Namespace, - prefix: Option, owner: &JSRef) -> Unrooted { + prefix: Option, owner: &JSRef) -> Temporary { let attr = Attr::new_inherited(local_name, value, name, namespace, prefix, owner); reflect_dom_object(~attr, window, AttrBinding::Wrap) } diff --git a/src/components/script/dom/attrlist.rs b/src/components/script/dom/attrlist.rs index eca2deade79..7bc7f18bdfa 100644 --- a/src/components/script/dom/attrlist.rs +++ b/src/components/script/dom/attrlist.rs @@ -4,7 +4,7 @@ use dom::attr::Attr; use dom::bindings::codegen::BindingDeclarations::AttrListBinding; -use dom::bindings::js::{JS, JSRef, Unrooted, RootCollection}; +use dom::bindings::js::{JS, JSRef, Temporary, RootCollection}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::element::Element; use dom::window::Window; @@ -25,7 +25,7 @@ impl AttrList { } } - pub fn new(window: &JSRef, elem: &JSRef) -> Unrooted { + pub fn new(window: &JSRef, elem: &JSRef) -> Temporary { reflect_dom_object(~AttrList::new_inherited(window.unrooted(), elem.unrooted()), window, AttrListBinding::Wrap) } @@ -33,8 +33,8 @@ impl AttrList { pub trait AttrListMethods { fn Length(&self) -> u32; - fn Item(&self, index: u32) -> Option>; - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option>; + fn Item(&self, index: u32) -> Option>; + fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option>; } impl<'a> AttrListMethods for JSRef<'a, AttrList> { @@ -43,12 +43,12 @@ impl<'a> AttrListMethods for JSRef<'a, AttrList> { self.owner.root(&roots).attrs.len() as u32 } - fn Item(&self, index: u32) -> Option> { + fn Item(&self, index: u32) -> Option> { let roots = RootCollection::new(); - self.owner.root(&roots).attrs.as_slice().get(index as uint).map(|x| Unrooted::new(x.clone())) + self.owner.root(&roots).attrs.as_slice().get(index as uint).map(|x| Temporary::new(x.clone())) } - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { + fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { let item = self.Item(index); *found = item.is_some(); item diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index f73de0ea365..b7df283d2b8 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -4323,7 +4323,7 @@ class CGBindingRoot(CGThing): 'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}', 'dom::types::*', 'dom::bindings', - 'dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Unrooted, OptionalRootable}', + 'dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Temporary, OptionalRootable}', 'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}', 'dom::bindings::utils::{ConstantSpec, cx_for_dom_object, Default}', 'dom::bindings::utils::{dom_object_slot, DOM_OBJECT_SLOT, DOMClass}', @@ -5294,7 +5294,7 @@ class GlobalGenRoots(): descriptors = config.getDescriptors(register=True, hasInterfaceObject=True) allprotos = [CGGeneric("#![allow(unused_imports)]\n"), CGGeneric("use dom::types::*;\n"), - CGGeneric("use dom::bindings::js::{JS, JSRef, Unrooted};\n"), + CGGeneric("use dom::bindings::js::{JS, JSRef, Temporary};\n"), CGGeneric("use dom::bindings::trace::JSTraceable;\n"), CGGeneric("use dom::bindings::utils::Reflectable;\n"), CGGeneric("use serialize::{Encodable, Encoder};\n"), @@ -5349,7 +5349,7 @@ class GlobalGenRoots(): } #[inline(always)] - fn from_unrooted(derived: Unrooted) -> Unrooted { + fn from_unrooted(derived: Temporary) -> Temporary { unsafe { derived.transmute() } } } diff --git a/src/components/script/dom/bindings/codegen/Configuration.py b/src/components/script/dom/bindings/codegen/Configuration.py index 48570a05476..0ff1754a562 100644 --- a/src/components/script/dom/bindings/codegen/Configuration.py +++ b/src/components/script/dom/bindings/codegen/Configuration.py @@ -133,7 +133,7 @@ class Descriptor(DescriptorProvider): else: nativeTypeDefault = 'JS<%s>' % ifaceName - self.returnType = "Unrooted<%s>" % ifaceName + self.returnType = "Temporary<%s>" % ifaceName self.nativeType = desc.get('nativeType', nativeTypeDefault) self.concreteType = desc.get('concreteType', ifaceName) self.createGlobal = desc.get('createGlobal', False) diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs index b26d2601139..031987181c2 100644 --- a/src/components/script/dom/bindings/js.rs +++ b/src/components/script/dom/bindings/js.rs @@ -14,27 +14,27 @@ use std::cell::RefCell; /// Importantly, it requires rooting in order to interact with the value in any way. /// Can be assigned into JS-owned member fields (ie. JS types) safely via the /// `JS::assign` method or `OptionalAssignable::assign` (for Option> fields). -pub struct Unrooted { +pub struct Temporary { inner: JS } -impl Eq for Unrooted { - fn eq(&self, other: &Unrooted) -> bool { +impl Eq for Temporary { + fn eq(&self, other: &Temporary) -> bool { self.inner == other.inner } } -impl Unrooted { - /// Create a new Unrooted value from a JS-owned value. - pub fn new(inner: JS) -> Unrooted { - Unrooted { +impl Temporary { + /// Create a new Temporary value from a JS-owned value. + pub fn new(inner: JS) -> Temporary { + Temporary { inner: inner } } - /// Create a new Unrooted value from a rooted value. - pub fn new_rooted<'a>(root: &JSRef<'a, T>) -> Unrooted { - Unrooted { + /// Create a new Temporary value from a rooted value. + pub fn new_rooted<'a>(root: &JSRef<'a, T>) -> Temporary { + Temporary { inner: root.unrooted() } } @@ -49,7 +49,7 @@ impl Unrooted { } //XXXjdm It would be lovely if this could be private. - pub unsafe fn transmute(self) -> Unrooted { + pub unsafe fn transmute(self) -> Temporary { cast::transmute(self) } } @@ -75,12 +75,12 @@ impl Clone for JS { } impl JS { - /// Create a new JS-reflected DOM object; returns an Unrooted type because the new value + /// Create a new JS-reflected DOM object; returns an Temporary type because the new value /// is not safe to use until it is rooted. pub fn new(obj: ~T, window: &JSRef, - wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~T) -> JS) -> Unrooted { - Unrooted::new(wrap_fn(window.get().get_cx(), window, obj)) + wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~T) -> JS) -> Temporary { + Temporary::new(wrap_fn(window.get().get_cx(), window, obj)) } /// Create a new JS-owned value wrapped from a raw Rust pointer. @@ -132,7 +132,7 @@ impl JS { /// Store an unrooted value in this field. This is safe under the assumption that JS /// 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(&mut self, val: Unrooted) { + pub fn assign(&mut self, val: Temporary) { *self = unsafe { val.inner() }; } } @@ -178,7 +178,7 @@ impl<'a, T> Assignable for JSRef<'a, T> { // Assignable should not be exposed publically, since it's used to // extract unrooted values in a safe way WHEN USED CORRECTLY. -impl Assignable for Unrooted { +impl Assignable for Temporary { fn get_js(&self) -> JS { unsafe { self.inner() } } @@ -198,7 +198,7 @@ pub trait OptionalRootable { fn root<'a, 'b>(self, roots: &'a RootCollection) -> Option>; } -impl OptionalRootable for Option> { +impl OptionalRootable for Option> { fn root<'a, 'b>(self, roots: &'a RootCollection) -> Option> { self.map(|inner| inner.root(roots)) } @@ -218,7 +218,7 @@ pub trait ResultRootable { fn root<'a, 'b>(self, roots: &'a RootCollection) -> Result, U>; } -impl ResultRootable for Result, U> { +impl ResultRootable for Result, U> { fn root<'a, 'b>(self, roots: &'a RootCollection) -> Result, U> { self.map(|inner| inner.root(roots)) } @@ -227,12 +227,12 @@ impl ResultRootable for Result, U> { /// Provides a facility to push unrooted values onto lists of rooted values. This is safe /// under the assumption that said lists are reachable via the GC graph, and therefore the /// new values are transitively rooted for the lifetime of their new owner. -pub trait UnrootedPushable { - fn push_unrooted(&mut self, val: Unrooted); +pub trait TemporaryPushable { + fn push_unrooted(&mut self, val: Temporary); } -impl UnrootedPushable for Vec> { - fn push_unrooted(&mut self, val: Unrooted) { +impl TemporaryPushable for Vec> { + fn push_unrooted(&mut self, val: Temporary) { unsafe { self.push(val.inner()) }; } } diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index 65725b9d923..cbccb90197a 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -5,7 +5,7 @@ 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, RootCollection, Unrooted, Root}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, Root}; use dom::bindings::trace::Untraceable; use dom::browsercontext; use dom::window; @@ -391,7 +391,7 @@ pub fn reflect_dom_object (obj: ~T, window: &JSRef, wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~T) -> JS) - -> Unrooted { + -> Temporary { JS::new(obj, window, wrap_fn) } @@ -616,12 +616,12 @@ pub extern fn outerize_global(_cx: *JSContext, obj: JSHandleObject) -> *JSObject } /// Returns the global object of the realm that the given JS object was created in. -pub fn global_object_for_js_object(obj: *JSObject) -> Unrooted { +pub fn global_object_for_js_object(obj: *JSObject) -> Temporary { unsafe { let global = GetGlobalForObjectCrossCompartment(obj); let clasp = JS_GetClass(global); assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0); - Unrooted::new( + Temporary::new( FromJSValConvertible::from_jsval(ptr::null(), ObjectOrNullValue(global), ()) .ok().expect("found DOM global that doesn't unwrap to Window")) } diff --git a/src/components/script/dom/blob.rs b/src/components/script/dom/blob.rs index a40715f00f2..10cc93ef089 100644 --- a/src/components/script/dom/blob.rs +++ b/src/components/script/dom/blob.rs @@ -2,7 +2,7 @@ * 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, RootCollection, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::Fallible; use dom::bindings::codegen::BindingDeclarations::BlobBinding; @@ -23,13 +23,13 @@ impl Blob { } } - pub fn new(window: &JSRef) -> Unrooted { + pub fn new(window: &JSRef) -> Temporary { reflect_dom_object(~Blob::new_inherited(window.unrooted()), window, BlobBinding::Wrap) } - pub fn Constructor(window: &JSRef) -> Fallible> { + pub fn Constructor(window: &JSRef) -> Fallible> { Ok(Blob::new(window)) } } @@ -37,7 +37,7 @@ impl Blob { pub trait BlobMethods { fn Size(&self) -> u64; fn Type(&self) -> DOMString; - fn Slice(&self, _start: Option, _end: Option, _contentType: Option) -> Unrooted; + fn Slice(&self, _start: Option, _end: Option, _contentType: Option) -> Temporary; fn Close(&self); } @@ -50,7 +50,7 @@ impl<'a> BlobMethods for JSRef<'a, Blob> { ~"" } - fn Slice(&self, _start: Option, _end: Option, _contentType: Option) -> Unrooted { + fn Slice(&self, _start: Option, _end: Option, _contentType: Option) -> Temporary { let roots = RootCollection::new(); let window = self.window.root(&roots); Blob::new(&window.root_ref()) diff --git a/src/components/script/dom/browsercontext.rs b/src/components/script/dom/browsercontext.rs index 4a452ccd2ae..5b0be5ccf0c 100644 --- a/src/components/script/dom/browsercontext.rs +++ b/src/components/script/dom/browsercontext.rs @@ -2,7 +2,7 @@ * 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, Unrooted, RootCollection}; +use dom::bindings::js::{JS, JSRef, Temporary, RootCollection}; use dom::bindings::trace::Traceable; use dom::bindings::utils::Reflectable; use dom::document::Document; @@ -32,14 +32,14 @@ impl BrowserContext { context } - pub fn active_document(&self) -> Unrooted { - Unrooted::new(self.history.get(self.active_index).document.clone()) + pub fn active_document(&self) -> Temporary { + Temporary::new(self.history.get(self.active_index).document.clone()) } - pub fn active_window(&self) -> Unrooted { + pub fn active_window(&self) -> Temporary { let roots = RootCollection::new(); let doc = self.active_document().root(&roots); - Unrooted::new(doc.deref().window.clone()) + Temporary::new(doc.deref().window.clone()) } pub fn window_proxy(&self) -> *JSObject { diff --git a/src/components/script/dom/clientrect.rs b/src/components/script/dom/clientrect.rs index 8f07c6b8175..ad48fe15d86 100644 --- a/src/components/script/dom/clientrect.rs +++ b/src/components/script/dom/clientrect.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::ClientRectBinding; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::window::Window; use servo_util::geometry::Au; @@ -34,7 +34,7 @@ impl ClientRect { pub fn new(window: &JSRef, top: Au, bottom: Au, - left: Au, right: Au) -> Unrooted { + left: Au, right: Au) -> Temporary { let rect = ClientRect::new_inherited(window.unrooted(), top, bottom, left, right); reflect_dom_object(~rect, window, ClientRectBinding::Wrap) } diff --git a/src/components/script/dom/clientrectlist.rs b/src/components/script/dom/clientrectlist.rs index 30cbb1043e3..2a7c609c958 100644 --- a/src/components/script/dom/clientrectlist.rs +++ b/src/components/script/dom/clientrectlist.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::ClientRectListBinding; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::clientrect::ClientRect; use dom::window::Window; @@ -26,7 +26,7 @@ impl ClientRectList { } pub fn new(window: &JSRef, - rects: Vec>) -> Unrooted { + rects: Vec>) -> Temporary { reflect_dom_object(~ClientRectList::new_inherited(window.unrooted(), rects), window, ClientRectListBinding::Wrap) } @@ -34,8 +34,8 @@ impl ClientRectList { pub trait ClientRectListMethods { fn Length(&self) -> u32; - fn Item(&self, index: u32) -> Option>; - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option>; + fn Item(&self, index: u32) -> Option>; + fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option>; } impl<'a> ClientRectListMethods for JSRef<'a, ClientRectList> { @@ -43,15 +43,15 @@ impl<'a> ClientRectListMethods for JSRef<'a, ClientRectList> { self.rects.len() as u32 } - fn Item(&self, index: u32) -> Option> { + fn Item(&self, index: u32) -> Option> { if index < self.rects.len() as u32 { - Some(Unrooted::new(self.rects.get(index as uint).clone())) + Some(Temporary::new(self.rects.get(index as uint).clone())) } else { None } } - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { + fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { *found = index < self.rects.len() as u32; self.Item(index) } diff --git a/src/components/script/dom/comment.rs b/src/components/script/dom/comment.rs index 0814cb7b25c..33bb395488c 100644 --- a/src/components/script/dom/comment.rs +++ b/src/components/script/dom/comment.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::CommentDerived; use dom::bindings::codegen::BindingDeclarations::CommentBinding; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; use dom::bindings::error::Fallible; use dom::characterdata::CharacterData; use dom::document::Document; @@ -35,12 +35,12 @@ impl Comment { } } - pub fn new(text: DOMString, document: &JSRef) -> Unrooted { + pub fn new(text: DOMString, document: &JSRef) -> Temporary { let node = Comment::new_inherited(text, document.unrooted()); Node::reflect_node(~node, document, CommentBinding::Wrap) } - pub fn Constructor(owner: &JSRef, data: DOMString) -> Fallible> { + pub fn Constructor(owner: &JSRef, data: DOMString) -> Fallible> { let roots = RootCollection::new(); let document = owner.Document().root(&roots); Ok(Comment::new(data, &*document)) diff --git a/src/components/script/dom/console.rs b/src/components/script/dom/console.rs index ce919980f26..a9c60962359 100644 --- a/src/components/script/dom/console.rs +++ b/src/components/script/dom/console.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::ConsoleBinding; -use dom::bindings::js::{JSRef, Unrooted}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::window::Window; use servo_util::str::DOMString; @@ -20,7 +20,7 @@ impl Console { } } - pub fn new(window: &JSRef) -> Unrooted { + pub fn new(window: &JSRef) -> Temporary { reflect_dom_object(~Console::new_inherited(), window, ConsoleBinding::Wrap) } } diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index 24c1d6eae89..09a2a2c2ffa 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::InheritTypes::{DocumentDerived, EventCast, HTMLEleme use dom::bindings::codegen::InheritTypes::{HTMLHeadElementCast, TextCast, ElementCast}; use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, HTMLHtmlElementCast, NodeCast}; use dom::bindings::codegen::BindingDeclarations::DocumentBinding; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalAssignable}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalAssignable}; use dom::bindings::js::OptionalRootable; use dom::bindings::trace::Untraceable; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; @@ -187,7 +187,7 @@ impl Document { pub fn reflect_document(document: ~Document, window: &JSRef, wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~Document) -> JS) - -> Unrooted { + -> Temporary { let roots = RootCollection::new(); assert!(document.reflector().get_jsobject().is_null()); let mut raw_doc = reflect_dom_object(document, window, wrap_fn).root(&roots); @@ -196,7 +196,7 @@ impl Document { let mut doc_alias = raw_doc.clone(); let node: &mut JSRef = NodeCast::from_mut_ref(&mut doc_alias); node.set_owner_doc(&*raw_doc); - Unrooted::new_rooted(&*raw_doc) + Temporary::new_rooted(&*raw_doc) } pub fn new_inherited(window: JS, @@ -230,11 +230,11 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document - pub fn Constructor(owner: &JSRef) -> Fallible> { + pub fn Constructor(owner: &JSRef) -> Fallible> { Ok(Document::new(owner, None, NonHTMLDocument, None)) } - pub fn new(window: &JSRef, url: Option, doctype: IsHTMLDocument, content_type: Option) -> Unrooted { + pub fn new(window: &JSRef, url: Option, doctype: IsHTMLDocument, content_type: Option) -> Temporary { let document = Document::new_inherited(window.unrooted(), url, doctype, content_type); Document::reflect_document(~document, window, DocumentBinding::Wrap) } @@ -251,12 +251,12 @@ impl Reflectable for Document { } trait PrivateDocumentHelpers { - fn createNodeList(&self, callback: |node: &JSRef| -> bool) -> Unrooted; - fn get_html_element(&self) -> Option>; + fn createNodeList(&self, callback: |node: &JSRef| -> bool) -> Temporary; + fn get_html_element(&self) -> Option>; } impl<'a> PrivateDocumentHelpers for JSRef<'a, Document> { - fn createNodeList(&self, callback: |node: &JSRef| -> bool) -> Unrooted { + fn createNodeList(&self, callback: |node: &JSRef| -> bool) -> Temporary { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -276,65 +276,65 @@ impl<'a> PrivateDocumentHelpers for JSRef<'a, Document> { NodeList::new_simple_list(&*window, nodes) } - fn get_html_element(&self) -> Option> { + fn get_html_element(&self) -> Option> { let roots = RootCollection::new(); self.GetDocumentElement().root(&roots).filtered(|root| { root.node.type_id == ElementNodeTypeId(HTMLHtmlElementTypeId) }).map(|elem| { - Unrooted::new_rooted(HTMLHtmlElementCast::to_ref(&*elem).unwrap()) + Temporary::new_rooted(HTMLHtmlElementCast::to_ref(&*elem).unwrap()) }) } } pub trait DocumentMethods { - fn Implementation(&mut self) -> Unrooted; + fn Implementation(&mut self) -> Temporary; fn URL(&self) -> DOMString; fn DocumentURI(&self) -> DOMString; fn CompatMode(&self) -> DOMString; fn CharacterSet(&self) -> DOMString; fn ContentType(&self) -> DOMString; - fn GetDoctype(&self) -> Option>; - fn GetDocumentElement(&self) -> Option>; - fn GetElementsByTagName(&self, tag_name: DOMString) -> Unrooted; - fn GetElementsByTagNameNS(&self, maybe_ns: Option, tag_name: DOMString) -> Unrooted; - fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted; - fn GetElementById(&self, id: DOMString) -> Option>; - fn CreateElement(&self, local_name: DOMString) -> Fallible>; - fn CreateElementNS(&self, namespace: Option, qualified_name: DOMString) -> Fallible>; - fn CreateDocumentFragment(&self) -> Unrooted; - fn CreateTextNode(&self, data: DOMString) -> Unrooted; - fn CreateComment(&self, data: DOMString) -> Unrooted; - fn CreateProcessingInstruction(&self, target: DOMString, data: DOMString) -> Fallible>; - fn ImportNode(&self, node: &JSRef, deep: bool) -> Fallible>; - fn AdoptNode(&self, node: &mut JSRef) -> Fallible>; - fn CreateEvent(&self, interface: DOMString) -> Fallible>; + fn GetDoctype(&self) -> Option>; + fn GetDocumentElement(&self) -> Option>; + fn GetElementsByTagName(&self, tag_name: DOMString) -> Temporary; + fn GetElementsByTagNameNS(&self, maybe_ns: Option, tag_name: DOMString) -> Temporary; + fn GetElementsByClassName(&self, classes: DOMString) -> Temporary; + fn GetElementById(&self, id: DOMString) -> Option>; + fn CreateElement(&self, local_name: DOMString) -> Fallible>; + fn CreateElementNS(&self, namespace: Option, qualified_name: DOMString) -> Fallible>; + fn CreateDocumentFragment(&self) -> Temporary; + fn CreateTextNode(&self, data: DOMString) -> Temporary; + fn CreateComment(&self, data: DOMString) -> Temporary; + fn CreateProcessingInstruction(&self, target: DOMString, data: DOMString) -> Fallible>; + fn ImportNode(&self, node: &JSRef, deep: bool) -> Fallible>; + fn AdoptNode(&self, node: &mut JSRef) -> Fallible>; + fn CreateEvent(&self, interface: DOMString) -> Fallible>; fn Title(&self) -> DOMString; fn SetTitle(&self, title: DOMString) -> ErrorResult; - fn GetHead(&self) -> Option>; - fn GetBody(&self) -> Option>; + fn GetHead(&self) -> Option>; + fn GetBody(&self) -> Option>; fn SetBody(&self, new_body: Option>) -> ErrorResult; - fn GetElementsByName(&self, name: DOMString) -> Unrooted; - fn Images(&self) -> Unrooted; - fn Embeds(&self) -> Unrooted; - fn Plugins(&self) -> Unrooted; - fn Links(&self) -> Unrooted; - fn Forms(&self) -> Unrooted; - fn Scripts(&self) -> Unrooted; - fn Anchors(&self) -> Unrooted; - fn Applets(&self) -> Unrooted; - fn Location(&mut self) -> Unrooted; - fn Children(&self) -> Unrooted; + fn GetElementsByName(&self, name: DOMString) -> Temporary; + fn Images(&self) -> Temporary; + fn Embeds(&self) -> Temporary; + fn Plugins(&self) -> Temporary; + fn Links(&self) -> Temporary; + fn Forms(&self) -> Temporary; + fn Scripts(&self) -> Temporary; + fn Anchors(&self) -> Temporary; + fn Applets(&self) -> Temporary; + fn Location(&mut self) -> Temporary; + fn Children(&self) -> Temporary; } impl<'a> DocumentMethods for JSRef<'a, Document> { // http://dom.spec.whatwg.org/#dom-document-implementation - fn Implementation(&mut self) -> Unrooted { + fn Implementation(&mut self) -> Temporary { if self.implementation.is_none() { let roots = RootCollection::new(); let window = self.window.root(&roots); self.implementation.assign(Some(DOMImplementation::new(&*window))); } - Unrooted::new(self.implementation.get_ref().clone()) + Temporary::new(self.implementation.get_ref().clone()) } // http://dom.spec.whatwg.org/#dom-document-url @@ -366,31 +366,31 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://dom.spec.whatwg.org/#dom-document-doctype - fn GetDoctype(&self) -> Option> { + fn GetDoctype(&self) -> Option> { let node: &JSRef = NodeCast::from_ref(self); node.children().find(|child| { child.is_doctype() }).map(|node| { let doctype: &JSRef = DocumentTypeCast::to_ref(&node).unwrap(); - Unrooted::new(doctype.unrooted()) + Temporary::new(doctype.unrooted()) }) } // http://dom.spec.whatwg.org/#dom-document-documentelement - fn GetDocumentElement(&self) -> Option> { + fn GetDocumentElement(&self) -> Option> { let node: &JSRef = NodeCast::from_ref(self); - node.child_elements().next().map(|elem| Unrooted::new_rooted(&elem)) + node.child_elements().next().map(|elem| Temporary::new_rooted(&elem)) } // http://dom.spec.whatwg.org/#dom-document-getelementsbytagname - fn GetElementsByTagName(&self, tag_name: DOMString) -> Unrooted { + fn GetElementsByTagName(&self, tag_name: DOMString) -> Temporary { let roots = RootCollection::new(); let window = self.window.root(&roots); HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(self), tag_name) } // http://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens - fn GetElementsByTagNameNS(&self, maybe_ns: Option, tag_name: DOMString) -> Unrooted { + fn GetElementsByTagNameNS(&self, maybe_ns: Option, tag_name: DOMString) -> Temporary { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -402,7 +402,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://dom.spec.whatwg.org/#dom-document-getelementsbyclassname - fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted { + fn GetElementsByClassName(&self, classes: DOMString) -> Temporary { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -410,15 +410,15 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid - fn GetElementById(&self, id: DOMString) -> Option> { + fn GetElementById(&self, id: DOMString) -> Option> { match self.idmap.find_equiv(&id) { None => None, - Some(ref elements) => Some(Unrooted::new(elements.get(0).clone())), + Some(ref elements) => Some(Temporary::new(elements.get(0).clone())), } } // http://dom.spec.whatwg.org/#dom-document-createelement - fn CreateElement(&self, local_name: DOMString) -> Fallible> { + fn CreateElement(&self, local_name: DOMString) -> Fallible> { if xml_name_type(local_name) == InvalidXMLName { debug!("Not a valid element name"); return Err(InvalidCharacter); @@ -430,7 +430,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://dom.spec.whatwg.org/#dom-document-createelementns fn CreateElementNS(&self, namespace: Option, - qualified_name: DOMString) -> Fallible> { + qualified_name: DOMString) -> Fallible> { let ns = Namespace::from_str(null_str_as_empty_ref(&namespace)); match xml_name_type(qualified_name) { InvalidXMLName => { @@ -474,24 +474,24 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://dom.spec.whatwg.org/#dom-document-createdocumentfragment - fn CreateDocumentFragment(&self) -> Unrooted { + fn CreateDocumentFragment(&self) -> Temporary { DocumentFragment::new(self) } // http://dom.spec.whatwg.org/#dom-document-createtextnode fn CreateTextNode(&self, data: DOMString) - -> Unrooted { + -> Temporary { Text::new(data, self) } // http://dom.spec.whatwg.org/#dom-document-createcomment - fn CreateComment(&self, data: DOMString) -> Unrooted { + fn CreateComment(&self, data: DOMString) -> Temporary { Comment::new(data, self) } // http://dom.spec.whatwg.org/#dom-document-createprocessinginstruction fn CreateProcessingInstruction(&self, target: DOMString, - data: DOMString) -> Fallible> { + data: DOMString) -> Fallible> { // Step 1. if xml_name_type(target) == InvalidXMLName { return Err(InvalidCharacter); @@ -507,7 +507,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://dom.spec.whatwg.org/#dom-document-importnode - fn ImportNode(&self, node: &JSRef, deep: bool) -> Fallible> { + fn ImportNode(&self, node: &JSRef, deep: bool) -> Fallible> { // Step 1. if node.is_document() { return Err(NotSupported); @@ -523,7 +523,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://dom.spec.whatwg.org/#dom-document-adoptnode - fn AdoptNode(&self, node: &mut JSRef) -> Fallible> { + fn AdoptNode(&self, node: &mut JSRef) -> Fallible> { // Step 1. if node.is_document() { return Err(NotSupported); @@ -533,11 +533,11 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { Node::adopt(node, self); // Step 3. - Ok(Unrooted::new_rooted(node)) + Ok(Temporary::new_rooted(node)) } // http://dom.spec.whatwg.org/#dom-document-createevent - fn CreateEvent(&self, interface: DOMString) -> Fallible> { + fn CreateEvent(&self, interface: DOMString) -> Fallible> { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -611,7 +611,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-head - fn GetHead(&self) -> Option> { + fn GetHead(&self) -> Option> { let roots = RootCollection::new(); self.get_html_element().and_then(|root| { let root = root.root(&roots); @@ -619,13 +619,13 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { node.children().find(|child| { child.type_id() == ElementNodeTypeId(HTMLHeadElementTypeId) }).map(|node| { - Unrooted::new_rooted(HTMLHeadElementCast::to_ref(&node).unwrap()) + Temporary::new_rooted(HTMLHeadElementCast::to_ref(&node).unwrap()) }) }) } // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body - fn GetBody(&self) -> Option> { + fn GetBody(&self) -> Option> { let roots = RootCollection::new(); self.get_html_element().and_then(|root| { let root = root.root(&roots); @@ -637,7 +637,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { _ => false } }).map(|node| { - Unrooted::new_rooted(HTMLElementCast::to_ref(&node).unwrap()) + Temporary::new_rooted(HTMLElementCast::to_ref(&node).unwrap()) }) }) } @@ -688,7 +688,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-getelementsbyname - fn GetElementsByName(&self, name: DOMString) -> Unrooted { + fn GetElementsByName(&self, name: DOMString) -> Temporary { let roots = RootCollection::new(); self.createNodeList(|node| { @@ -703,7 +703,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { }) } - fn Images(&self) -> Unrooted { + fn Images(&self) -> Temporary { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -718,7 +718,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Embeds(&self) -> Unrooted { + fn Embeds(&self) -> Temporary { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -733,12 +733,12 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Plugins(&self) -> Unrooted { + fn Plugins(&self) -> Temporary { // FIXME: https://github.com/mozilla/servo/issues/1847 self.Embeds() } - fn Links(&self) -> Unrooted { + fn Links(&self) -> Temporary { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -754,7 +754,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Forms(&self) -> Unrooted { + fn Forms(&self) -> Temporary { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -769,7 +769,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Scripts(&self) -> Unrooted { + fn Scripts(&self) -> Temporary { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -784,7 +784,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Anchors(&self) -> Unrooted { + fn Anchors(&self) -> Temporary { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -799,7 +799,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Applets(&self) -> Unrooted { + fn Applets(&self) -> Temporary { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -814,13 +814,13 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Location(&mut self) -> Unrooted { + fn Location(&mut self) -> Temporary { let roots = RootCollection::new(); let mut window = self.window.root(&roots); window.Location() } - fn Children(&self) -> Unrooted { + fn Children(&self) -> Temporary { let roots = RootCollection::new(); let window = self.window.root(&roots); HTMLCollection::children(&*window, NodeCast::from_ref(self)) diff --git a/src/components/script/dom/documentfragment.rs b/src/components/script/dom/documentfragment.rs index 55e782406b3..1dfd92c6f66 100644 --- a/src/components/script/dom/documentfragment.rs +++ b/src/components/script/dom/documentfragment.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::{DocumentFragmentDerived, NodeCast}; use dom::bindings::codegen::BindingDeclarations::DocumentFragmentBinding; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; use dom::bindings::error::Fallible; use dom::document::Document; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -34,12 +34,12 @@ impl DocumentFragment { } } - pub fn new(document: &JSRef) -> Unrooted { + pub fn new(document: &JSRef) -> Temporary { let node = DocumentFragment::new_inherited(document.unrooted()); Node::reflect_node(~node, document, DocumentFragmentBinding::Wrap) } - pub fn Constructor(owner: &JSRef) -> Fallible> { + pub fn Constructor(owner: &JSRef) -> Fallible> { let roots = RootCollection::new(); let document = owner.Document(); let document = document.root(&roots); @@ -49,11 +49,11 @@ impl DocumentFragment { } pub trait DocumentFragmentMethods { - fn Children(&self) -> Unrooted; + fn Children(&self) -> Temporary; } impl<'a> DocumentFragmentMethods for JSRef<'a, DocumentFragment> { - fn Children(&self) -> Unrooted { + fn Children(&self) -> Temporary { let roots = RootCollection::new(); let window = window_from_node(self).root(&roots); HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(self)) diff --git a/src/components/script/dom/documenttype.rs b/src/components/script/dom/documenttype.rs index 26772db65ec..9e0c61e3723 100644 --- a/src/components/script/dom/documenttype.rs +++ b/src/components/script/dom/documenttype.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::DocumentTypeDerived; use dom::bindings::codegen::BindingDeclarations::DocumentTypeBinding; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::document::Document; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::node::{Node, DoctypeNodeTypeId}; @@ -46,7 +46,7 @@ impl DocumentType { public_id: Option, system_id: Option, document: &JSRef) - -> Unrooted { + -> Temporary { let documenttype = DocumentType::new_inherited(name, public_id, system_id, diff --git a/src/components/script/dom/domexception.rs b/src/components/script/dom/domexception.rs index 78d43b047f1..d3ef0664383 100644 --- a/src/components/script/dom/domexception.rs +++ b/src/components/script/dom/domexception.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::DOMExceptionBinding; use dom::bindings::codegen::BindingDeclarations::DOMExceptionBinding::DOMExceptionConstants; -use dom::bindings::js::{JSRef, Unrooted}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::window::Window; use servo_util::str::DOMString; @@ -49,7 +49,7 @@ impl DOMException { } } - pub fn new(window: &JSRef, code: DOMErrorName) -> Unrooted { + pub fn new(window: &JSRef, code: DOMErrorName) -> Temporary { reflect_dom_object(~DOMException::new_inherited(code), window, DOMExceptionBinding::Wrap) } } diff --git a/src/components/script/dom/domimplementation.rs b/src/components/script/dom/domimplementation.rs index e339485fbd9..4346e6044c4 100644 --- a/src/components/script/dom/domimplementation.rs +++ b/src/components/script/dom/domimplementation.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::DOMImplementationBinding; use dom::bindings::codegen::InheritTypes::NodeCast; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalRootable}; +use dom::bindings::js::{JS, JSRef, RootCollection, 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}; @@ -33,7 +33,7 @@ impl DOMImplementation { } } - pub fn new(owner: &JSRef) -> Unrooted { + pub fn new(owner: &JSRef) -> Temporary { reflect_dom_object(~DOMImplementation::new_inherited(owner.unrooted()), owner, DOMImplementationBinding::Wrap) } @@ -50,16 +50,16 @@ impl Reflectable for DOMImplementation { } pub trait DOMImplementationMethods { - fn CreateDocumentType(&self, qname: DOMString, pubid: DOMString, sysid: DOMString) -> Fallible>; + fn CreateDocumentType(&self, qname: DOMString, pubid: DOMString, sysid: DOMString) -> Fallible>; fn CreateDocument(&self, namespace: Option, qname: DOMString, - mut maybe_doctype: Option>) -> Fallible>; - fn CreateHTMLDocument(&self, title: Option) -> Unrooted; + mut maybe_doctype: Option>) -> Fallible>; + fn CreateHTMLDocument(&self, title: Option) -> Temporary; } // http://dom.spec.whatwg.org/#domimplementation impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { // http://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype - fn CreateDocumentType(&self, qname: DOMString, pubid: DOMString, sysid: DOMString) -> Fallible> { + fn CreateDocumentType(&self, qname: DOMString, pubid: DOMString, sysid: DOMString) -> Fallible> { let roots = RootCollection::new(); match xml_name_type(qname) { // Step 1. @@ -77,7 +77,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { // http://dom.spec.whatwg.org/#dom-domimplementation-createdocument fn CreateDocument(&self, namespace: Option, qname: DOMString, - mut maybe_doctype: Option>) -> Fallible> { + mut maybe_doctype: Option>) -> Fallible> { let roots = RootCollection::new(); let win = self.owner.root(&roots); @@ -117,11 +117,11 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { // FIXME: https://github.com/mozilla/servo/issues/1522 // Step 7. - Ok(Unrooted::new_rooted(&*doc)) + Ok(Temporary::new_rooted(&*doc)) } // http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument - fn CreateHTMLDocument(&self, title: Option) -> Unrooted { + fn CreateHTMLDocument(&self, title: Option) -> Temporary { let roots = RootCollection::new(); let owner = self.owner.root(&roots); @@ -170,6 +170,6 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { // FIXME: https://github.com/mozilla/servo/issues/1522 // Step 9. - Unrooted::new_rooted(&*doc) + Temporary::new_rooted(&*doc) } } diff --git a/src/components/script/dom/domparser.rs b/src/components/script/dom/domparser.rs index 9f8785e6fd7..3dc95f57d27 100644 --- a/src/components/script/dom/domparser.rs +++ b/src/components/script/dom/domparser.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::DOMParserBinding; use dom::bindings::codegen::BindingDeclarations::DOMParserBinding::SupportedTypeValues::{Text_html, Text_xml}; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object}; use dom::bindings::error::{Fallible, FailureUnknown}; use dom::document::{Document, HTMLDocument, NonHTMLDocument}; @@ -25,25 +25,25 @@ impl DOMParser { } } - pub fn new(owner: &JSRef) -> Unrooted { + pub fn new(owner: &JSRef) -> Temporary { reflect_dom_object(~DOMParser::new_inherited(owner.unrooted()), owner, DOMParserBinding::Wrap) } - pub fn Constructor(owner: &JSRef) -> Fallible> { + pub fn Constructor(owner: &JSRef) -> Fallible> { Ok(DOMParser::new(owner)) } } pub trait DOMParserMethods { - fn ParseFromString(&self, _s: DOMString, ty: DOMParserBinding::SupportedType) -> Fallible>; + fn ParseFromString(&self, _s: DOMString, ty: DOMParserBinding::SupportedType) -> Fallible>; } impl<'a> DOMParserMethods for JSRef<'a, DOMParser> { fn ParseFromString(&self, _s: DOMString, ty: DOMParserBinding::SupportedType) - -> Fallible> { + -> Fallible> { let roots = RootCollection::new(); let owner = self.owner.root(&roots); match ty { diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index 9e8be904788..fdf9db3e5b0 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -8,7 +8,7 @@ use dom::attr::{Attr, ReplacedAttr, FirstSetAttr, AttrMethods}; use dom::attrlist::AttrList; use dom::bindings::codegen::BindingDeclarations::ElementBinding; use dom::bindings::codegen::InheritTypes::{ElementDerived, NodeCast}; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, UnrootedPushable}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, TemporaryPushable}; use dom::bindings::js::{OptionalAssignable, OptionalRootable, Root}; use dom::bindings::utils::{Reflectable, Reflector}; use dom::bindings::error::{ErrorResult, Fallible, NamespaceError, InvalidCharacter}; @@ -153,7 +153,7 @@ impl Element { } } - pub fn new(local_name: DOMString, namespace: Namespace, prefix: Option, document: &JSRef) -> Unrooted { + pub fn new(local_name: DOMString, namespace: Namespace, prefix: Option, document: &JSRef) -> Temporary { let element = Element::new_inherited(ElementTypeId, local_name, namespace, prefix, document.unrooted()); Node::reflect_node(~element, document, ElementBinding::Wrap) } @@ -206,7 +206,7 @@ impl<'a> ElementHelpers for JSRef<'a, Element> { } pub trait AttributeHandlers { - fn get_attribute(&self, namespace: Namespace, name: &str) -> Option>; + fn get_attribute(&self, namespace: Namespace, name: &str) -> Option>; fn set_attr(&mut self, name: DOMString, value: DOMString) -> ErrorResult; fn set_attribute(&mut self, namespace: Namespace, name: DOMString, value: DOMString) -> ErrorResult; @@ -227,16 +227,16 @@ pub trait AttributeHandlers { } impl<'a> AttributeHandlers for JSRef<'a, Element> { - fn get_attribute(&self, namespace: Namespace, name: &str) -> Option> { + fn get_attribute(&self, namespace: Namespace, name: &str) -> Option> { let roots = RootCollection::new(); if self.html_element_in_html_document() { self.get().attrs.iter().map(|attr| attr.root(&roots)).find(|attr| { name.to_ascii_lower() == attr.local_name && attr.namespace == namespace - }).map(|x| Unrooted::new_rooted(&*x)) + }).map(|x| Temporary::new_rooted(&*x)) } else { self.get().attrs.iter().map(|attr| attr.root(&roots)).find(|attr| { name == attr.local_name && attr.namespace == namespace - }).map(|x| Unrooted::new_rooted(&*x)) + }).map(|x| Temporary::new_rooted(&*x)) } } @@ -394,7 +394,7 @@ pub trait ElementMethods { fn SetId(&mut self, id: DOMString); fn ClassName(&self) -> DOMString; fn SetClassName(&mut self, class: DOMString); - fn Attributes(&mut self) -> Unrooted; + fn Attributes(&mut self) -> Temporary; fn GetAttribute(&self, name: DOMString) -> Option; fn GetAttributeNS(&self, namespace: Option, local_name: DOMString) -> Option; fn SetAttribute(&mut self, name: DOMString, value: DOMString) -> ErrorResult; @@ -403,14 +403,14 @@ pub trait ElementMethods { fn RemoveAttributeNS(&mut self, namespace: Option, localname: DOMString) -> ErrorResult; fn HasAttribute(&self, name: DOMString) -> bool; fn HasAttributeNS(&self, namespace: Option, local_name: DOMString) -> bool; - fn GetElementsByTagName(&self, localname: DOMString) -> Unrooted; - fn GetElementsByTagNameNS(&self, maybe_ns: Option, localname: DOMString) -> Unrooted; - fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted; - fn GetClientRects(&self) -> Unrooted; - fn GetBoundingClientRect(&self) -> Unrooted; + fn GetElementsByTagName(&self, localname: DOMString) -> Temporary; + fn GetElementsByTagNameNS(&self, maybe_ns: Option, localname: DOMString) -> Temporary; + fn GetElementsByClassName(&self, classes: DOMString) -> Temporary; + fn GetClientRects(&self) -> Temporary; + fn GetBoundingClientRect(&self) -> Temporary; fn GetInnerHTML(&self) -> Fallible; fn GetOuterHTML(&self) -> Fallible; - fn Children(&self) -> Unrooted; + fn Children(&self) -> Temporary; } impl<'a> ElementMethods for JSRef<'a, Element> { @@ -461,11 +461,11 @@ impl<'a> ElementMethods for JSRef<'a, Element> { } // http://dom.spec.whatwg.org/#dom-element-attributes - fn Attributes(&mut self) -> Unrooted { + fn Attributes(&mut self) -> Temporary { let roots = RootCollection::new(); match self.attr_list { None => (), - Some(ref list) => return Unrooted::new(list.clone()), + Some(ref list) => return Temporary::new(list.clone()), } let doc = { @@ -475,7 +475,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { let window = doc.deref().window.root(&roots); let list = AttrList::new(&*window, self); self.attr_list.assign(Some(list)); - Unrooted::new(self.attr_list.get_ref().clone()) + Temporary::new(self.attr_list.get_ref().clone()) } // http://dom.spec.whatwg.org/#dom-element-getattribute @@ -623,14 +623,14 @@ impl<'a> ElementMethods for JSRef<'a, Element> { self.GetAttributeNS(namespace, local_name).is_some() } - fn GetElementsByTagName(&self, localname: DOMString) -> Unrooted { + fn GetElementsByTagName(&self, localname: DOMString) -> Temporary { let roots = RootCollection::new(); let window = window_from_node(self).root(&roots); HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(self), localname) } fn GetElementsByTagNameNS(&self, maybe_ns: Option, - localname: DOMString) -> Unrooted { + localname: DOMString) -> Temporary { let roots = RootCollection::new(); let namespace = match maybe_ns { Some(namespace) => Namespace::from_str(namespace), @@ -640,14 +640,14 @@ impl<'a> ElementMethods for JSRef<'a, Element> { HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(self), localname, namespace) } - fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted { + fn GetElementsByClassName(&self, classes: DOMString) -> Temporary { let roots = RootCollection::new(); let window = window_from_node(self).root(&roots); HTMLCollection::by_class_name(&*window, NodeCast::from_ref(self), classes) } // http://dev.w3.org/csswg/cssom-view/#dom-element-getclientrects - fn GetClientRects(&self) -> Unrooted { + fn GetClientRects(&self) -> Temporary { let roots = RootCollection::new(); let win = window_from_node(self).root(&roots); let node: &JSRef = NodeCast::from_ref(self); @@ -665,7 +665,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { } // http://dev.w3.org/csswg/cssom-view/#dom-element-getboundingclientrect - fn GetBoundingClientRect(&self) -> Unrooted { + fn GetBoundingClientRect(&self) -> Temporary { let roots = RootCollection::new(); let win = window_from_node(self).root(&roots); let node: &JSRef = NodeCast::from_ref(self); @@ -689,7 +689,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(self), true, false))) } - fn Children(&self) -> Unrooted { + fn Children(&self) -> Temporary { let roots = RootCollection::new(); let window = window_from_node(self).root(&roots); HTMLCollection::children(&*window, NodeCast::from_ref(self)) diff --git a/src/components/script/dom/event.rs b/src/components/script/dom/event.rs index 08fdc818ed6..3b3254c0f0c 100644 --- a/src/components/script/dom/event.rs +++ b/src/components/script/dom/event.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::EventBinding; use dom::bindings::codegen::BindingDeclarations::EventBinding::EventConstants; -use dom::bindings::js::{JS, JSRef, Unrooted, RootCollection}; +use dom::bindings::js::{JS, JSRef, Temporary, RootCollection}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::Fallible; use dom::eventtarget::EventTarget; @@ -80,7 +80,7 @@ impl Event { } } - pub fn new(window: &JSRef) -> Unrooted { + pub fn new(window: &JSRef) -> Temporary { reflect_dom_object(~Event::new_inherited(HTMLEventTypeId), window, EventBinding::Wrap) @@ -88,19 +88,19 @@ impl Event { pub fn Constructor(global: &JSRef, type_: DOMString, - init: &EventBinding::EventInit) -> Fallible> { + init: &EventBinding::EventInit) -> Fallible> { let roots = RootCollection::new(); let mut ev = Event::new(global).root(&roots); ev.InitEvent(type_, init.bubbles, init.cancelable); - Ok(Unrooted::new_rooted(&*ev)) + Ok(Temporary::new_rooted(&*ev)) } } pub trait EventMethods { fn EventPhase(&self) -> u16; fn Type(&self) -> DOMString; - fn GetTarget(&self) -> Option>; - fn GetCurrentTarget(&self) -> Option>; + fn GetTarget(&self) -> Option>; + fn GetCurrentTarget(&self) -> Option>; fn DefaultPrevented(&self) -> bool; fn PreventDefault(&mut self); fn StopPropagation(&mut self); @@ -121,12 +121,12 @@ impl<'a> EventMethods for JSRef<'a, Event> { self.type_.clone() } - fn GetTarget(&self) -> Option> { - self.target.as_ref().map(|target| Unrooted::new(target.clone())) + fn GetTarget(&self) -> Option> { + self.target.as_ref().map(|target| Temporary::new(target.clone())) } - fn GetCurrentTarget(&self) -> Option> { - self.current_target.as_ref().map(|target| Unrooted::new(target.clone())) + fn GetCurrentTarget(&self) -> Option> { + self.current_target.as_ref().map(|target| Temporary::new(target.clone())) } fn DefaultPrevented(&self) -> bool { diff --git a/src/components/script/dom/formdata.rs b/src/components/script/dom/formdata.rs index 88be3e4314e..8cd1eebb028 100644 --- a/src/components/script/dom/formdata.rs +++ b/src/components/script/dom/formdata.rs @@ -5,7 +5,7 @@ use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::{Fallible}; use dom::bindings::codegen::BindingDeclarations::FormDataBinding; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::blob::Blob; use dom::htmlformelement::HTMLFormElement; use dom::window::Window; @@ -37,11 +37,11 @@ impl FormData { } } - pub fn new(form: Option>, window: &JSRef) -> Unrooted { + pub fn new(form: Option>, window: &JSRef) -> Temporary { reflect_dom_object(~FormData::new_inherited(form, window.unrooted()), window, FormDataBinding::Wrap) } - pub fn Constructor(window: &JSRef, form: Option>) -> Fallible> { + pub fn Constructor(window: &JSRef, form: Option>) -> Fallible> { Ok(FormData::new(form, window)) } } diff --git a/src/components/script/dom/htmlanchorelement.rs b/src/components/script/dom/htmlanchorelement.rs index 22e7846269c..1757de35ecf 100644 --- a/src/components/script/dom/htmlanchorelement.rs +++ b/src/components/script/dom/htmlanchorelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLAnchorElementBinding; use dom::bindings::codegen::InheritTypes::HTMLAnchorElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLAnchorElementTypeId; @@ -34,7 +34,7 @@ impl HTMLAnchorElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLAnchorElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLAnchorElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlappletelement.rs b/src/components/script/dom/htmlappletelement.rs index bcf7481d4d7..5500f6568aa 100644 --- a/src/components/script/dom/htmlappletelement.rs +++ b/src/components/script/dom/htmlappletelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLAppletElementBinding; use dom::bindings::codegen::InheritTypes::HTMLAppletElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLAppletElementTypeId; @@ -34,7 +34,7 @@ impl HTMLAppletElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLAppletElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLAppletElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlareaelement.rs b/src/components/script/dom/htmlareaelement.rs index d22e8a45a67..e6678299abf 100644 --- a/src/components/script/dom/htmlareaelement.rs +++ b/src/components/script/dom/htmlareaelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLAreaElementBinding; use dom::bindings::codegen::InheritTypes::HTMLAreaElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLAreaElementTypeId; @@ -34,7 +34,7 @@ impl HTMLAreaElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLAreaElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLAreaElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlaudioelement.rs b/src/components/script/dom/htmlaudioelement.rs index 7e3826dd4c6..3b1a7cb3a98 100644 --- a/src/components/script/dom/htmlaudioelement.rs +++ b/src/components/script/dom/htmlaudioelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLAudioElementBinding; use dom::bindings::codegen::InheritTypes::HTMLAudioElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLAudioElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,7 +33,7 @@ impl HTMLAudioElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLAudioElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLAudioElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlbaseelement.rs b/src/components/script/dom/htmlbaseelement.rs index 83cdf3607ac..1105f862881 100644 --- a/src/components/script/dom/htmlbaseelement.rs +++ b/src/components/script/dom/htmlbaseelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLBaseElementBinding; use dom::bindings::codegen::InheritTypes::HTMLBaseElementDerived; use dom::bindings::error::ErrorResult; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLBaseElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -34,7 +34,7 @@ impl HTMLBaseElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLBaseElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLBaseElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlbodyelement.rs b/src/components/script/dom/htmlbodyelement.rs index cb59f0c6fb4..d070c7b5a12 100644 --- a/src/components/script/dom/htmlbodyelement.rs +++ b/src/components/script/dom/htmlbodyelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLBodyElementBinding; use dom::bindings::codegen::InheritTypes::HTMLBodyElementDerived; use dom::bindings::error::ErrorResult; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLBodyElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -34,7 +34,7 @@ impl HTMLBodyElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLBodyElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLBodyElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlbrelement.rs b/src/components/script/dom/htmlbrelement.rs index 5b06b1467ea..2bf59a4f966 100644 --- a/src/components/script/dom/htmlbrelement.rs +++ b/src/components/script/dom/htmlbrelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLBRElementBinding; use dom::bindings::codegen::InheritTypes::HTMLBRElementDerived; use dom::bindings::error::ErrorResult; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLBRElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -34,7 +34,7 @@ impl HTMLBRElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLBRElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLBRElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlbuttonelement.rs b/src/components/script/dom/htmlbuttonelement.rs index f37d9926032..7458c7df50b 100644 --- a/src/components/script/dom/htmlbuttonelement.rs +++ b/src/components/script/dom/htmlbuttonelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLButtonElementBinding; use dom::bindings::codegen::InheritTypes::HTMLButtonElementDerived; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLButtonElementTypeId; @@ -36,7 +36,7 @@ impl HTMLButtonElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLButtonElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLButtonElementBinding::Wrap) } @@ -47,7 +47,7 @@ pub trait HTMLButtonElementMethods { fn SetAutofocus(&mut self, _autofocus: bool) -> ErrorResult; fn Disabled(&self) -> bool; fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult; - fn GetForm(&self) -> Option>; + fn GetForm(&self) -> Option>; fn FormAction(&self) -> DOMString; fn SetFormAction(&mut self, _formaction: DOMString) -> ErrorResult; fn FormEnctype(&self) -> DOMString; @@ -66,7 +66,7 @@ pub trait HTMLButtonElementMethods { fn SetValue(&mut self, _value: DOMString) -> ErrorResult; fn WillValidate(&self) -> bool; fn SetWillValidate(&mut self, _will_validate: bool); - fn Validity(&self) -> Unrooted; + fn Validity(&self) -> Temporary; fn SetValidity(&mut self, _validity: JS); fn ValidationMessage(&self) -> DOMString; fn SetValidationMessage(&mut self, _message: DOMString) -> ErrorResult; @@ -91,7 +91,7 @@ impl<'a> HTMLButtonElementMethods for JSRef<'a, HTMLButtonElement> { Ok(()) } - fn GetForm(&self) -> Option> { + fn GetForm(&self) -> Option> { None } @@ -166,7 +166,7 @@ impl<'a> HTMLButtonElementMethods for JSRef<'a, HTMLButtonElement> { fn SetWillValidate(&mut self, _will_validate: bool) { } - fn Validity(&self) -> Unrooted { + fn Validity(&self) -> Temporary { let roots = RootCollection::new(); let window = window_from_node(self).root(&roots); ValidityState::new(&*window) diff --git a/src/components/script/dom/htmlcanvaselement.rs b/src/components/script/dom/htmlcanvaselement.rs index 32af35a06b7..068cee1bbd8 100644 --- a/src/components/script/dom/htmlcanvaselement.rs +++ b/src/components/script/dom/htmlcanvaselement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLCanvasElementBinding; use dom::bindings::codegen::InheritTypes::HTMLCanvasElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::{ErrorResult}; use dom::document::Document; use dom::element::HTMLCanvasElementTypeId; @@ -34,7 +34,7 @@ impl HTMLCanvasElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLCanvasElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLCanvasElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlcollection.rs b/src/components/script/dom/htmlcollection.rs index 77ddb563805..3be0a84a2a2 100644 --- a/src/components/script/dom/htmlcollection.rs +++ b/src/components/script/dom/htmlcollection.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast}; use dom::bindings::codegen::BindingDeclarations::HTMLCollectionBinding; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::element::{Element, AttributeHandlers}; use dom::node::{Node, NodeHelpers}; @@ -46,19 +46,19 @@ impl HTMLCollection { } } - pub fn new(window: &JSRef, collection: CollectionTypeId) -> Unrooted { + pub fn new(window: &JSRef, collection: CollectionTypeId) -> Temporary { reflect_dom_object(~HTMLCollection::new_inherited(window.unrooted(), collection), window, HTMLCollectionBinding::Wrap) } } impl HTMLCollection { - pub fn create(window: &JSRef, root: &JSRef, filter: ~CollectionFilter) -> Unrooted { + pub fn create(window: &JSRef, root: &JSRef, filter: ~CollectionFilter) -> Temporary { HTMLCollection::new(window, Live(root.unrooted(), filter)) } pub fn by_tag_name(window: &JSRef, root: &JSRef, tag: DOMString) - -> Unrooted { + -> Temporary { struct TagNameFilter { tag: DOMString } @@ -74,7 +74,7 @@ impl HTMLCollection { } pub fn by_tag_name_ns(window: &JSRef, root: &JSRef, tag: DOMString, - namespace: Namespace) -> Unrooted { + namespace: Namespace) -> Temporary { struct TagNameNSFilter { tag: DOMString, namespace: Namespace @@ -92,7 +92,7 @@ impl HTMLCollection { } pub fn by_class_name(window: &JSRef, root: &JSRef, classes: DOMString) - -> Unrooted { + -> Temporary { struct ClassNameFilter { classes: Vec } @@ -107,7 +107,7 @@ impl HTMLCollection { HTMLCollection::create(window, root, ~filter) } - pub fn children(window: &JSRef, root: &JSRef) -> Unrooted { + pub fn children(window: &JSRef, root: &JSRef) -> Temporary { struct ElementChildFilter; impl CollectionFilter for ElementChildFilter { fn filter(&self, elem: &JSRef, root: &JSRef) -> bool { @@ -120,10 +120,10 @@ impl HTMLCollection { pub trait HTMLCollectionMethods { fn Length(&self) -> u32; - fn Item(&self, index: u32) -> Option>; - fn NamedItem(&self, key: DOMString) -> Option>; - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option>; - fn NamedGetter(&self, maybe_name: Option, found: &mut bool) -> Option>; + fn Item(&self, index: u32) -> Option>; + fn NamedItem(&self, key: DOMString) -> Option>; + fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option>; + fn NamedGetter(&self, maybe_name: Option, found: &mut bool) -> Option>; } impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> { @@ -144,13 +144,13 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> { } // http://dom.spec.whatwg.org/#dom-htmlcollection-item - fn Item(&self, index: u32) -> Option> { + fn Item(&self, index: u32) -> Option> { let roots = RootCollection::new(); match self.collection { Static(ref elems) => elems .as_slice() .get(index as uint) - .map(|elem| Unrooted::new(elem.clone())), + .map(|elem| Temporary::new(elem.clone())), Live(ref root, ref filter) => { let root = root.root(&roots); root.deref().traverse_preorder(&roots) @@ -161,13 +161,13 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> { }) .nth(index as uint) .clone() - .map(|elem| Unrooted::new_rooted(&elem)) + .map(|elem| Temporary::new_rooted(&elem)) } } } // http://dom.spec.whatwg.org/#dom-htmlcollection-nameditem - fn NamedItem(&self, key: DOMString) -> Option> { + fn NamedItem(&self, key: DOMString) -> Option> { let roots = RootCollection::new(); // Step 1. @@ -182,7 +182,7 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> { .find(|elem| { elem.get_string_attribute("name") == key || elem.get_string_attribute("id") == key }) - .map(|maybe_elem| Unrooted::new_rooted(&*maybe_elem)), + .map(|maybe_elem| Temporary::new_rooted(&*maybe_elem)), Live(ref root, ref filter) => { let root = root.root(&roots); root.deref().traverse_preorder(&roots) @@ -194,18 +194,18 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> { .find(|elem| { elem.get_string_attribute("name") == key || elem.get_string_attribute("id") == key }) - .map(|maybe_elem| Unrooted::new_rooted(&maybe_elem)) + .map(|maybe_elem| Temporary::new_rooted(&maybe_elem)) } } } - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { + fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { let maybe_elem = self.Item(index); *found = maybe_elem.is_some(); maybe_elem } - fn NamedGetter(&self, maybe_name: Option, found: &mut bool) -> Option> { + fn NamedGetter(&self, maybe_name: Option, found: &mut bool) -> Option> { match maybe_name { Some(name) => { let maybe_elem = self.NamedItem(name); diff --git a/src/components/script/dom/htmldataelement.rs b/src/components/script/dom/htmldataelement.rs index 4e412665595..dcac09e2f5b 100644 --- a/src/components/script/dom/htmldataelement.rs +++ b/src/components/script/dom/htmldataelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDataElementBinding; use dom::bindings::codegen::InheritTypes::HTMLDataElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLDataElementTypeId; @@ -34,7 +34,7 @@ impl HTMLDataElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLDataElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLDataElementBinding::Wrap) } diff --git a/src/components/script/dom/htmldatalistelement.rs b/src/components/script/dom/htmldatalistelement.rs index ae5dbfbef9e..398920bdc61 100644 --- a/src/components/script/dom/htmldatalistelement.rs +++ b/src/components/script/dom/htmldatalistelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDataListElementBinding; use dom::bindings::codegen::InheritTypes::{HTMLDataListElementDerived, NodeCast}; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; use dom::document::Document; use dom::element::{Element, HTMLDataListElementTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -34,18 +34,18 @@ impl HTMLDataListElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLDataListElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLDataListElementBinding::Wrap) } } pub trait HTMLDataListElementMethods { - fn Options(&self) -> Unrooted; + fn Options(&self) -> Temporary; } impl<'a> HTMLDataListElementMethods for JSRef<'a, HTMLDataListElement> { - fn Options(&self) -> Unrooted { + fn Options(&self) -> Temporary { struct HTMLDataListOptionsFilter; impl CollectionFilter for HTMLDataListOptionsFilter { fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { diff --git a/src/components/script/dom/htmldirectoryelement.rs b/src/components/script/dom/htmldirectoryelement.rs index cc7dd99920b..8cde736766f 100644 --- a/src/components/script/dom/htmldirectoryelement.rs +++ b/src/components/script/dom/htmldirectoryelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDirectoryElementBinding; use dom::bindings::codegen::InheritTypes::HTMLDirectoryElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLDirectoryElementTypeId; @@ -34,7 +34,7 @@ impl HTMLDirectoryElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLDirectoryElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLDirectoryElementBinding::Wrap) } diff --git a/src/components/script/dom/htmldivelement.rs b/src/components/script/dom/htmldivelement.rs index d50b95c72cd..2047530985b 100644 --- a/src/components/script/dom/htmldivelement.rs +++ b/src/components/script/dom/htmldivelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDivElementBinding; use dom::bindings::codegen::InheritTypes::HTMLDivElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLDivElementTypeId; @@ -34,7 +34,7 @@ impl HTMLDivElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLDivElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLDivElementBinding::Wrap) } diff --git a/src/components/script/dom/htmldlistelement.rs b/src/components/script/dom/htmldlistelement.rs index 838c694a33c..dc7ae6066fe 100644 --- a/src/components/script/dom/htmldlistelement.rs +++ b/src/components/script/dom/htmldlistelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDListElementBinding; use dom::bindings::codegen::InheritTypes::HTMLDListElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLDListElementTypeId; @@ -34,7 +34,7 @@ impl HTMLDListElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLDListElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLDListElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlelement.rs b/src/components/script/dom/htmlelement.rs index c7596688cdb..87b00f2eb90 100644 --- a/src/components/script/dom/htmlelement.rs +++ b/src/components/script/dom/htmlelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLElementBinding; use dom::bindings::codegen::InheritTypes::ElementCast; use dom::bindings::codegen::InheritTypes::HTMLElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::{ErrorResult, Fallible}; use dom::document::Document; use dom::element::{Element, ElementTypeId, HTMLElementTypeId}; @@ -39,7 +39,7 @@ impl HTMLElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLElement::new_inherited(HTMLElementTypeId, localName, document.unrooted()); Node::reflect_node(~element, document, HTMLElementBinding::Wrap) } @@ -71,7 +71,7 @@ pub trait HTMLElementMethods { fn IsContentEditable(&self) -> bool; fn Spellcheck(&self) -> bool; fn SetSpellcheck(&self, _val: bool) -> ErrorResult; - fn GetOffsetParent(&self) -> Option>; + fn GetOffsetParent(&self) -> Option>; fn OffsetTop(&self) -> i32; fn OffsetLeft(&self) -> i32; fn OffsetWidth(&self) -> i32; @@ -176,7 +176,7 @@ impl<'a> HTMLElementMethods for JSRef<'a, HTMLElement> { Ok(()) } - fn GetOffsetParent(&self) -> Option> { + fn GetOffsetParent(&self) -> Option> { None } diff --git a/src/components/script/dom/htmlembedelement.rs b/src/components/script/dom/htmlembedelement.rs index 715f113987e..334c7320295 100644 --- a/src/components/script/dom/htmlembedelement.rs +++ b/src/components/script/dom/htmlembedelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLEmbedElementBinding; use dom::bindings::codegen::InheritTypes::HTMLEmbedElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLEmbedElementTypeId; @@ -34,7 +34,7 @@ impl HTMLEmbedElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLEmbedElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLEmbedElementBinding::Wrap) } @@ -53,7 +53,7 @@ pub trait HTMLEmbedElementMethods { fn SetAlign(&mut self, _type: DOMString) -> ErrorResult; fn Name(&self) -> DOMString; fn SetName(&mut self, _type: DOMString) -> ErrorResult; - fn GetSVGDocument(&self) -> Option>; + fn GetSVGDocument(&self) -> Option>; } impl<'a> HTMLEmbedElementMethods for JSRef<'a, HTMLEmbedElement> { @@ -105,7 +105,7 @@ impl<'a> HTMLEmbedElementMethods for JSRef<'a, HTMLEmbedElement> { Ok(()) } - fn GetSVGDocument(&self) -> Option> { + fn GetSVGDocument(&self) -> Option> { None } } diff --git a/src/components/script/dom/htmlfieldsetelement.rs b/src/components/script/dom/htmlfieldsetelement.rs index 8da6d36b803..f3872235f27 100644 --- a/src/components/script/dom/htmlfieldsetelement.rs +++ b/src/components/script/dom/htmlfieldsetelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFieldSetElementBinding; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLFieldSetElementDerived, NodeCast}; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLFieldSetElementTypeId}; @@ -37,7 +37,7 @@ impl HTMLFieldSetElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLFieldSetElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLFieldSetElementBinding::Wrap) } @@ -46,13 +46,13 @@ impl HTMLFieldSetElement { pub trait HTMLFieldSetElementMethods { fn Disabled(&self) -> bool; fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult; - fn GetForm(&self) -> Option>; + fn GetForm(&self) -> Option>; fn Name(&self) -> DOMString; fn SetName(&mut self, _name: DOMString) -> ErrorResult; fn Type(&self) -> DOMString; - fn Elements(&self) -> Unrooted; + fn Elements(&self) -> Temporary; fn WillValidate(&self) -> bool; - fn Validity(&self) -> Unrooted; + fn Validity(&self) -> Temporary; fn ValidationMessage(&self) -> DOMString; fn CheckValidity(&self) -> bool; fn SetCustomValidity(&mut self, _error: DOMString); @@ -67,7 +67,7 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> { Ok(()) } - fn GetForm(&self) -> Option> { + fn GetForm(&self) -> Option> { None } @@ -84,7 +84,7 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> { } // http://www.whatwg.org/html/#dom-fieldset-elements - fn Elements(&self) -> Unrooted { + fn Elements(&self) -> Temporary { struct ElementsFilter; impl CollectionFilter for ElementsFilter { fn filter(&self, elem: &JSRef, root: &JSRef) -> bool { @@ -105,7 +105,7 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> { false } - fn Validity(&self) -> Unrooted { + fn Validity(&self) -> Temporary { let roots = RootCollection::new(); let window = window_from_node(self).root(&roots); ValidityState::new(&*window) diff --git a/src/components/script/dom/htmlfontelement.rs b/src/components/script/dom/htmlfontelement.rs index eca6b946b23..5d6ececb57d 100644 --- a/src/components/script/dom/htmlfontelement.rs +++ b/src/components/script/dom/htmlfontelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFontElementBinding; use dom::bindings::codegen::InheritTypes::HTMLFontElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLFontElementTypeId; @@ -34,7 +34,7 @@ impl HTMLFontElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLFontElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLFontElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlformelement.rs b/src/components/script/dom/htmlformelement.rs index d69cbcf3a48..c7773bdf68a 100644 --- a/src/components/script/dom/htmlformelement.rs +++ b/src/components/script/dom/htmlformelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFormElementBinding; use dom::bindings::codegen::InheritTypes::HTMLFormElementDerived; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLFormElementTypeId}; @@ -35,7 +35,7 @@ impl HTMLFormElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLFormElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLFormElementBinding::Wrap) } @@ -60,12 +60,12 @@ pub trait HTMLFormElementMethods { fn SetNoValidate(&mut self, _no_validate: bool) -> ErrorResult; fn Target(&self) -> DOMString; fn SetTarget(&mut self, _target: DOMString) -> ErrorResult; - fn Elements(&self) -> Unrooted; + fn Elements(&self) -> Temporary; fn Length(&self) -> i32; fn Submit(&self) -> ErrorResult; fn Reset(&self); fn CheckValidity(&self) -> bool; - fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Unrooted; + fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Temporary; } impl<'a> HTMLFormElementMethods for JSRef<'a, HTMLFormElement> { @@ -141,7 +141,7 @@ impl<'a> HTMLFormElementMethods for JSRef<'a, HTMLFormElement> { Ok(()) } - fn Elements(&self) -> Unrooted { + fn Elements(&self) -> Temporary { // FIXME: https://github.com/mozilla/servo/issues/1844 let roots = RootCollection::new(); let window = window_from_node(self).root(&roots); @@ -163,7 +163,7 @@ impl<'a> HTMLFormElementMethods for JSRef<'a, HTMLFormElement> { false } - fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Unrooted { + fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Temporary { fail!("Not implemented.") } } diff --git a/src/components/script/dom/htmlframeelement.rs b/src/components/script/dom/htmlframeelement.rs index 5dd705b494f..2f3aa886bcf 100644 --- a/src/components/script/dom/htmlframeelement.rs +++ b/src/components/script/dom/htmlframeelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFrameElementBinding; use dom::bindings::codegen::InheritTypes::HTMLFrameElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLFrameElementTypeId; @@ -35,7 +35,7 @@ impl HTMLFrameElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLFrameElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLFrameElementBinding::Wrap) } @@ -54,8 +54,8 @@ pub trait HTMLFrameElementMethods { fn SetLongDesc(&mut self, _longdesc: DOMString) -> ErrorResult; fn NoResize(&self) -> bool; fn SetNoResize(&mut self, _no_resize: bool) -> ErrorResult; - fn GetContentDocument(&self) -> Option>; - fn GetContentWindow(&self) -> Option>; + fn GetContentDocument(&self) -> Option>; + fn GetContentWindow(&self) -> Option>; fn MarginHeight(&self) -> DOMString; fn SetMarginHeight(&mut self, _height: DOMString) -> ErrorResult; fn MarginWidth(&self) -> DOMString; @@ -111,11 +111,11 @@ impl<'a> HTMLFrameElementMethods for JSRef<'a, HTMLFrameElement> { Ok(()) } - fn GetContentDocument(&self) -> Option> { + fn GetContentDocument(&self) -> Option> { None } - fn GetContentWindow(&self) -> Option> { + fn GetContentWindow(&self) -> Option> { None } diff --git a/src/components/script/dom/htmlframesetelement.rs b/src/components/script/dom/htmlframesetelement.rs index 1e58cba197a..32860c79562 100644 --- a/src/components/script/dom/htmlframesetelement.rs +++ b/src/components/script/dom/htmlframesetelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFrameSetElementBinding; use dom::bindings::codegen::InheritTypes::HTMLFrameSetElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLFrameSetElementTypeId; @@ -34,7 +34,7 @@ impl HTMLFrameSetElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLFrameSetElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLFrameSetElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlheadelement.rs b/src/components/script/dom/htmlheadelement.rs index 440a95310f6..1cfb2d4ea6e 100644 --- a/src/components/script/dom/htmlheadelement.rs +++ b/src/components/script/dom/htmlheadelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLHeadElementBinding; use dom::bindings::codegen::InheritTypes::HTMLHeadElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLHeadElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,7 +33,7 @@ impl HTMLHeadElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLHeadElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLHeadElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlheadingelement.rs b/src/components/script/dom/htmlheadingelement.rs index f05ef59a211..98142aaaa6a 100644 --- a/src/components/script/dom/htmlheadingelement.rs +++ b/src/components/script/dom/htmlheadingelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLHeadingElementBinding; use dom::bindings::codegen::InheritTypes::HTMLHeadingElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLHeadingElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -45,7 +45,7 @@ impl HTMLHeadingElement { } } - pub fn new(localName: DOMString, document: &JSRef, level: HeadingLevel) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef, level: HeadingLevel) -> Temporary { let element = HTMLHeadingElement::new_inherited(localName, document.unrooted(), level); Node::reflect_node(~element, document, HTMLHeadingElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlhrelement.rs b/src/components/script/dom/htmlhrelement.rs index 2ad58999b61..9031566d4d8 100644 --- a/src/components/script/dom/htmlhrelement.rs +++ b/src/components/script/dom/htmlhrelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLHRElementBinding; use dom::bindings::codegen::InheritTypes::HTMLHRElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLHRElementTypeId; @@ -34,7 +34,7 @@ impl HTMLHRElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLHRElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLHRElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlhtmlelement.rs b/src/components/script/dom/htmlhtmlelement.rs index e30968f91f4..5a11183e80c 100644 --- a/src/components/script/dom/htmlhtmlelement.rs +++ b/src/components/script/dom/htmlhtmlelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLHtmlElementBinding; use dom::bindings::codegen::InheritTypes::HTMLHtmlElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLHtmlElementTypeId; @@ -34,7 +34,7 @@ impl HTMLHtmlElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLHtmlElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLHtmlElementBinding::Wrap) } diff --git a/src/components/script/dom/htmliframeelement.rs b/src/components/script/dom/htmliframeelement.rs index aa6fc3ceaf3..18a47de9ee7 100644 --- a/src/components/script/dom/htmliframeelement.rs +++ b/src/components/script/dom/htmliframeelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLIFrameElementBinding; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLIFrameElementDerived, HTMLElementCast}; use dom::bindings::error::ErrorResult; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::trace::Untraceable; use dom::document::Document; use dom::element::{HTMLIFrameElementTypeId, Element}; @@ -79,7 +79,7 @@ impl HTMLIFrameElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLIFrameElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLIFrameElementBinding::Wrap) } @@ -100,8 +100,8 @@ pub trait HTMLIFrameElementMethods { fn SetWidth(&mut self, _width: DOMString) -> ErrorResult; fn Height(&self) -> DOMString; fn SetHeight(&mut self, _height: DOMString) -> ErrorResult; - fn GetContentDocument(&self) -> Option>; - fn GetContentWindow(&self) -> Option>; + fn GetContentDocument(&self) -> Option>; + fn GetContentWindow(&self) -> Option>; fn Align(&self) -> DOMString; fn SetAlign(&mut self, _align: DOMString) -> ErrorResult; fn Scrolling(&self) -> DOMString; @@ -114,7 +114,7 @@ pub trait HTMLIFrameElementMethods { fn SetMarginHeight(&mut self, _marginheight: DOMString) -> ErrorResult; fn MarginWidth(&self) -> DOMString; fn SetMarginWidth(&mut self, _marginwidth: DOMString) -> ErrorResult; - fn GetSVGDocument(&self) -> Option>; + fn GetSVGDocument(&self) -> Option>; } impl<'a> HTMLIFrameElementMethods for JSRef<'a, HTMLIFrameElement> { @@ -176,11 +176,11 @@ impl<'a> HTMLIFrameElementMethods for JSRef<'a, HTMLIFrameElement> { Ok(()) } - fn GetContentDocument(&self) -> Option> { + fn GetContentDocument(&self) -> Option> { None } - fn GetContentWindow(&self) -> Option> { + fn GetContentWindow(&self) -> Option> { None } @@ -232,7 +232,7 @@ impl<'a> HTMLIFrameElementMethods for JSRef<'a, HTMLIFrameElement> { Ok(()) } - fn GetSVGDocument(&self) -> Option> { + fn GetSVGDocument(&self) -> Option> { None } } diff --git a/src/components/script/dom/htmlimageelement.rs b/src/components/script/dom/htmlimageelement.rs index 423f49a8f14..956a923f7c0 100644 --- a/src/components/script/dom/htmlimageelement.rs +++ b/src/components/script/dom/htmlimageelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLImageElementBinding; use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast, HTMLElementCast, HTMLImageElementDerived}; use dom::bindings::error::ErrorResult; -use dom::bindings::js::{JS, JSRef, Unrooted, RootCollection}; +use dom::bindings::js::{JS, JSRef, Temporary, RootCollection}; use dom::bindings::trace::Untraceable; use dom::document::Document; use dom::element::{Element, HTMLImageElementTypeId}; @@ -76,7 +76,7 @@ impl HTMLImageElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLImageElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLImageElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlinputelement.rs b/src/components/script/dom/htmlinputelement.rs index f56578c6cdd..a50e73137ae 100644 --- a/src/components/script/dom/htmlinputelement.rs +++ b/src/components/script/dom/htmlinputelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLInputElementBinding; use dom::bindings::codegen::InheritTypes::HTMLInputElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::{ErrorResult, Fallible}; use dom::document::Document; use dom::element::HTMLInputElementTypeId; @@ -34,7 +34,7 @@ impl HTMLInputElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLInputElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLInputElementBinding::Wrap) } diff --git a/src/components/script/dom/htmllabelelement.rs b/src/components/script/dom/htmllabelelement.rs index c11132a7e9b..f994d73331b 100644 --- a/src/components/script/dom/htmllabelelement.rs +++ b/src/components/script/dom/htmllabelelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLLabelElementBinding; use dom::bindings::codegen::InheritTypes::HTMLLabelElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLLabelElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,7 +33,7 @@ impl HTMLLabelElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLLabelElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLLabelElementBinding::Wrap) } diff --git a/src/components/script/dom/htmllegendelement.rs b/src/components/script/dom/htmllegendelement.rs index 22ddb92aca5..20af8e0bcf5 100644 --- a/src/components/script/dom/htmllegendelement.rs +++ b/src/components/script/dom/htmllegendelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLLegendElementBinding; use dom::bindings::codegen::InheritTypes::HTMLLegendElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLLegendElementTypeId; @@ -34,7 +34,7 @@ impl HTMLLegendElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLLegendElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLLegendElementBinding::Wrap) } diff --git a/src/components/script/dom/htmllielement.rs b/src/components/script/dom/htmllielement.rs index 97dee3e3f25..33f46ddebc2 100644 --- a/src/components/script/dom/htmllielement.rs +++ b/src/components/script/dom/htmllielement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLLIElementBinding; use dom::bindings::codegen::InheritTypes::HTMLLIElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLLIElementTypeId; @@ -34,7 +34,7 @@ impl HTMLLIElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLLIElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLLIElementBinding::Wrap) } diff --git a/src/components/script/dom/htmllinkelement.rs b/src/components/script/dom/htmllinkelement.rs index f40bd112585..df96b58d19f 100644 --- a/src/components/script/dom/htmllinkelement.rs +++ b/src/components/script/dom/htmllinkelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLLinkElementBinding; use dom::bindings::codegen::InheritTypes::HTMLLinkElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLLinkElementTypeId; @@ -34,7 +34,7 @@ impl HTMLLinkElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLLinkElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLLinkElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlmainelement.rs b/src/components/script/dom/htmlmainelement.rs index 4024f1ee7fa..ffd5c6cb523 100644 --- a/src/components/script/dom/htmlmainelement.rs +++ b/src/components/script/dom/htmlmainelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLMainElementBinding; use dom::bindings::codegen::InheritTypes::HTMLMainElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLMainElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,7 +33,7 @@ impl HTMLMainElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLMainElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLMainElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlmapelement.rs b/src/components/script/dom/htmlmapelement.rs index 7c6e4b59151..681056a6be6 100644 --- a/src/components/script/dom/htmlmapelement.rs +++ b/src/components/script/dom/htmlmapelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLMapElementBinding; use dom::bindings::codegen::InheritTypes::HTMLMapElementDerived; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLMapElementTypeId; @@ -35,7 +35,7 @@ impl HTMLMapElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLMapElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLMapElementBinding::Wrap) } @@ -44,7 +44,7 @@ impl HTMLMapElement { pub trait HTMLMapElementMethods { fn Name(&self) -> DOMString; fn SetName(&mut self, _name: DOMString) -> ErrorResult; - fn Areas(&self) -> Unrooted; + fn Areas(&self) -> Temporary; } impl<'a> HTMLMapElementMethods for JSRef<'a, HTMLMapElement> { @@ -56,7 +56,7 @@ impl<'a> HTMLMapElementMethods for JSRef<'a, HTMLMapElement> { Ok(()) } - fn Areas(&self) -> Unrooted { + fn Areas(&self) -> Temporary { let roots = RootCollection::new(); // FIXME: https://github.com/mozilla/servo/issues/1845 let window = window_from_node(self).root(&roots); diff --git a/src/components/script/dom/htmlmetaelement.rs b/src/components/script/dom/htmlmetaelement.rs index 89520346b53..cb9e6d603c1 100644 --- a/src/components/script/dom/htmlmetaelement.rs +++ b/src/components/script/dom/htmlmetaelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLMetaElementBinding; use dom::bindings::codegen::InheritTypes::HTMLMetaElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLMetaElementTypeId; @@ -34,7 +34,7 @@ impl HTMLMetaElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLMetaElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLMetaElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlmeterelement.rs b/src/components/script/dom/htmlmeterelement.rs index 685d96f7a0b..7e4c7f42f9f 100644 --- a/src/components/script/dom/htmlmeterelement.rs +++ b/src/components/script/dom/htmlmeterelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLMeterElementBinding; use dom::bindings::codegen::InheritTypes::HTMLMeterElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLMeterElementTypeId; @@ -34,7 +34,7 @@ impl HTMLMeterElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLMeterElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLMeterElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlmodelement.rs b/src/components/script/dom/htmlmodelement.rs index 6a9b33106a2..5e77c3c8636 100644 --- a/src/components/script/dom/htmlmodelement.rs +++ b/src/components/script/dom/htmlmodelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLModElementBinding; use dom::bindings::codegen::InheritTypes::HTMLModElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLModElementTypeId; @@ -34,7 +34,7 @@ impl HTMLModElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLModElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLModElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlobjectelement.rs b/src/components/script/dom/htmlobjectelement.rs index 085bd492b11..18f8acce6b2 100644 --- a/src/components/script/dom/htmlobjectelement.rs +++ b/src/components/script/dom/htmlobjectelement.rs @@ -6,7 +6,7 @@ use dom::attr::AttrMethods; use dom::bindings::codegen::BindingDeclarations::HTMLObjectElementBinding; use dom::bindings::codegen::InheritTypes::HTMLObjectElementDerived; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast}; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLObjectElementTypeId}; @@ -48,7 +48,7 @@ impl HTMLObjectElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLObjectElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLObjectElementBinding::Wrap) } @@ -89,15 +89,15 @@ pub trait HTMLObjectElementMethods { fn SetName(&mut self, _name: DOMString) -> ErrorResult; fn UseMap(&self) -> DOMString; fn SetUseMap(&mut self, _use_map: DOMString) -> ErrorResult; - fn GetForm(&self) -> Option>; + fn GetForm(&self) -> Option>; fn Width(&self) -> DOMString; fn SetWidth(&mut self, _width: DOMString) -> ErrorResult; fn Height(&self) -> DOMString; fn SetHeight(&mut self, _height: DOMString) -> ErrorResult; - fn GetContentDocument(&self) -> Option>; - fn GetContentWindow(&self) -> Option>; + fn GetContentDocument(&self) -> Option>; + fn GetContentWindow(&self) -> Option>; fn WillValidate(&self) -> bool; - fn Validity(&self) -> Unrooted; + fn Validity(&self) -> Temporary; fn ValidationMessage(&self) -> DOMString; fn CheckValidity(&self) -> bool; fn SetCustomValidity(&mut self, _error: DOMString); @@ -121,7 +121,7 @@ pub trait HTMLObjectElementMethods { fn SetCodeType(&mut self, _codetype: DOMString) -> ErrorResult; fn Border(&self) -> DOMString; fn SetBorder(&mut self, _border: DOMString) -> ErrorResult; - fn GetSVGDocument(&self) -> Option>; + fn GetSVGDocument(&self) -> Option>; } impl<'a> HTMLObjectElementMethods for JSRef<'a, HTMLObjectElement> { @@ -157,7 +157,7 @@ impl<'a> HTMLObjectElementMethods for JSRef<'a, HTMLObjectElement> { Ok(()) } - fn GetForm(&self) -> Option> { + fn GetForm(&self) -> Option> { None } @@ -177,11 +177,11 @@ impl<'a> HTMLObjectElementMethods for JSRef<'a, HTMLObjectElement> { Ok(()) } - fn GetContentDocument(&self) -> Option> { + fn GetContentDocument(&self) -> Option> { None } - fn GetContentWindow(&self) -> Option> { + fn GetContentWindow(&self) -> Option> { None } @@ -189,7 +189,7 @@ impl<'a> HTMLObjectElementMethods for JSRef<'a, HTMLObjectElement> { false } - fn Validity(&self) -> Unrooted { + fn Validity(&self) -> Temporary { let roots = RootCollection::new(); let window = window_from_node(self).root(&roots); ValidityState::new(&*window) @@ -286,7 +286,7 @@ impl<'a> HTMLObjectElementMethods for JSRef<'a, HTMLObjectElement> { Ok(()) } - fn GetSVGDocument(&self) -> Option> { + fn GetSVGDocument(&self) -> Option> { None } } diff --git a/src/components/script/dom/htmlolistelement.rs b/src/components/script/dom/htmlolistelement.rs index a7191eb4f31..6b4133513b9 100644 --- a/src/components/script/dom/htmlolistelement.rs +++ b/src/components/script/dom/htmlolistelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLOListElementBinding; use dom::bindings::codegen::InheritTypes::HTMLOListElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLOListElementTypeId; @@ -34,7 +34,7 @@ impl HTMLOListElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLOListElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLOListElementBinding::Wrap) } diff --git a/src/components/script/dom/htmloptgroupelement.rs b/src/components/script/dom/htmloptgroupelement.rs index 05f4cb5ef03..74c0bde0156 100644 --- a/src/components/script/dom/htmloptgroupelement.rs +++ b/src/components/script/dom/htmloptgroupelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLOptGroupElementBinding; use dom::bindings::codegen::InheritTypes::HTMLOptGroupElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLOptGroupElementTypeId; @@ -34,7 +34,7 @@ impl HTMLOptGroupElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLOptGroupElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLOptGroupElementBinding::Wrap) } diff --git a/src/components/script/dom/htmloptionelement.rs b/src/components/script/dom/htmloptionelement.rs index e9793fc1690..dc0c6c291d8 100644 --- a/src/components/script/dom/htmloptionelement.rs +++ b/src/components/script/dom/htmloptionelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLOptionElementBinding; use dom::bindings::codegen::InheritTypes::HTMLOptionElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLOptionElementTypeId; @@ -35,7 +35,7 @@ impl HTMLOptionElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLOptionElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLOptionElementBinding::Wrap) } @@ -44,7 +44,7 @@ impl HTMLOptionElement { pub trait HTMLOptionElementMethods { fn Disabled(&self) -> bool; fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult; - fn GetForm(&self) -> Option>; + fn GetForm(&self) -> Option>; fn Label(&self) -> DOMString; fn SetLabel(&mut self, _label: DOMString) -> ErrorResult; fn DefaultSelected(&self) -> bool; @@ -67,7 +67,7 @@ impl<'a> HTMLOptionElementMethods for JSRef<'a, HTMLOptionElement> { Ok(()) } - fn GetForm(&self) -> Option> { + fn GetForm(&self) -> Option> { None } diff --git a/src/components/script/dom/htmloutputelement.rs b/src/components/script/dom/htmloutputelement.rs index 605bb2eeab2..5bed0a4fb49 100644 --- a/src/components/script/dom/htmloutputelement.rs +++ b/src/components/script/dom/htmloutputelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLOutputElementBinding; use dom::bindings::codegen::InheritTypes::HTMLOutputElementDerived; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLOutputElementTypeId; @@ -36,14 +36,14 @@ impl HTMLOutputElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLOutputElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLOutputElementBinding::Wrap) } } pub trait HTMLOutputElementMethods { - fn GetForm(&self) -> Option>; + fn GetForm(&self) -> Option>; fn Name(&self) -> DOMString; fn SetName(&mut self, _name: DOMString) -> ErrorResult; fn Type(&self) -> DOMString; @@ -53,7 +53,7 @@ pub trait HTMLOutputElementMethods { fn SetValue(&mut self, _value: DOMString) -> ErrorResult; fn WillValidate(&self) -> bool; fn SetWillValidate(&mut self, _will_validate: bool); - fn Validity(&self) -> Unrooted; + fn Validity(&self) -> Temporary; fn SetValidity(&mut self, _validity: JS); fn ValidationMessage(&self) -> DOMString; fn SetValidationMessage(&mut self, _message: DOMString) -> ErrorResult; @@ -62,7 +62,7 @@ pub trait HTMLOutputElementMethods { } impl<'a> HTMLOutputElementMethods for JSRef<'a, HTMLOutputElement> { - fn GetForm(&self) -> Option> { + fn GetForm(&self) -> Option> { None } @@ -101,7 +101,7 @@ impl<'a> HTMLOutputElementMethods for JSRef<'a, HTMLOutputElement> { fn SetWillValidate(&mut self, _will_validate: bool) { } - fn Validity(&self) -> Unrooted { + fn Validity(&self) -> Temporary { let roots = RootCollection::new(); let window = window_from_node(self).root(&roots); ValidityState::new(&*window) diff --git a/src/components/script/dom/htmlparagraphelement.rs b/src/components/script/dom/htmlparagraphelement.rs index 90e3282c915..9bb6160d300 100644 --- a/src/components/script/dom/htmlparagraphelement.rs +++ b/src/components/script/dom/htmlparagraphelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLParagraphElementBinding; use dom::bindings::codegen::InheritTypes::HTMLParagraphElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLParagraphElementTypeId; @@ -34,7 +34,7 @@ impl HTMLParagraphElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLParagraphElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLParagraphElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlparamelement.rs b/src/components/script/dom/htmlparamelement.rs index 41f45b31d17..c5a727c12a5 100644 --- a/src/components/script/dom/htmlparamelement.rs +++ b/src/components/script/dom/htmlparamelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLParamElementBinding; use dom::bindings::codegen::InheritTypes::HTMLParamElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLParamElementTypeId; @@ -34,7 +34,7 @@ impl HTMLParamElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLParamElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLParamElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlpreelement.rs b/src/components/script/dom/htmlpreelement.rs index 34eb9923a52..b43b18c3028 100644 --- a/src/components/script/dom/htmlpreelement.rs +++ b/src/components/script/dom/htmlpreelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLPreElementBinding; use dom::bindings::codegen::InheritTypes::HTMLPreElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLPreElementTypeId; @@ -34,7 +34,7 @@ impl HTMLPreElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLPreElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLPreElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlprogresselement.rs b/src/components/script/dom/htmlprogresselement.rs index 891df6918fe..800bd7df9ff 100644 --- a/src/components/script/dom/htmlprogresselement.rs +++ b/src/components/script/dom/htmlprogresselement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLProgressElementBinding; use dom::bindings::codegen::InheritTypes::HTMLProgressElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::{ErrorResult, Fallible}; use dom::document::Document; use dom::element::HTMLProgressElementTypeId; @@ -34,7 +34,7 @@ impl HTMLProgressElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLProgressElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLProgressElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlquoteelement.rs b/src/components/script/dom/htmlquoteelement.rs index db7edcbede4..a2c50a8082d 100644 --- a/src/components/script/dom/htmlquoteelement.rs +++ b/src/components/script/dom/htmlquoteelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLQuoteElementBinding; use dom::bindings::codegen::InheritTypes::HTMLQuoteElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLQuoteElementTypeId; @@ -34,7 +34,7 @@ impl HTMLQuoteElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLQuoteElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLQuoteElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlscriptelement.rs b/src/components/script/dom/htmlscriptelement.rs index 4d7780d49f7..b392fbb95d2 100644 --- a/src/components/script/dom/htmlscriptelement.rs +++ b/src/components/script/dom/htmlscriptelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLScriptElementBinding; use dom::bindings::codegen::InheritTypes::HTMLScriptElementDerived; use dom::bindings::codegen::InheritTypes::ElementCast; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{HTMLScriptElementTypeId, Element, AttributeHandlers}; @@ -35,7 +35,7 @@ impl HTMLScriptElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLScriptElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLScriptElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlselectelement.rs b/src/components/script/dom/htmlselectelement.rs index ed99506f01d..8c349315849 100644 --- a/src/components/script/dom/htmlselectelement.rs +++ b/src/components/script/dom/htmlselectelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLSelectElementBinding; use dom::bindings::codegen::InheritTypes::HTMLSelectElementDerived; use dom::bindings::codegen::UnionTypes::{HTMLElementOrLong, HTMLOptionElementOrHTMLOptGroupElement}; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLSelectElementTypeId}; @@ -38,7 +38,7 @@ impl HTMLSelectElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLSelectElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLSelectElementBinding::Wrap) } @@ -49,7 +49,7 @@ pub trait HTMLSelectElementMethods { fn SetAutofocus(&mut self, _autofocus: bool) -> ErrorResult; fn Disabled(&self) -> bool; fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult; - fn GetForm(&self) -> Option>; + fn GetForm(&self) -> Option>; fn Multiple(&self) -> bool; fn SetMultiple(&mut self, _multiple: bool) -> ErrorResult; fn Name(&self) -> DOMString; @@ -61,9 +61,9 @@ pub trait HTMLSelectElementMethods { fn Type(&self) -> DOMString; fn Length(&self) -> u32; fn SetLength(&mut self, _length: u32) -> ErrorResult; - fn Item(&self, _index: u32) -> Option>; - fn NamedItem(&self, _name: DOMString) -> Option>; - fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option>; + fn Item(&self, _index: u32) -> Option>; + fn NamedItem(&self, _name: DOMString) -> Option>; + fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option>; fn IndexedSetter(&mut self, _index: u32, _option: Option>) -> ErrorResult; fn Remove_(&self); fn Remove(&self, _index: i32); @@ -73,7 +73,7 @@ pub trait HTMLSelectElementMethods { fn SetValue(&mut self, _value: DOMString); fn WillValidate(&self) -> bool; fn SetWillValidate(&mut self, _will_validate: bool); - fn Validity(&self) -> Unrooted; + fn Validity(&self) -> Temporary; fn SetValidity(&mut self, _validity: JS); fn ValidationMessage(&self) -> DOMString; fn SetValidationMessage(&mut self, _message: DOMString) -> ErrorResult; @@ -99,7 +99,7 @@ impl<'a> HTMLSelectElementMethods for JSRef<'a, HTMLSelectElement> { Ok(()) } - fn GetForm(&self) -> Option> { + fn GetForm(&self) -> Option> { None } @@ -147,15 +147,15 @@ impl<'a> HTMLSelectElementMethods for JSRef<'a, HTMLSelectElement> { Ok(()) } - fn Item(&self, _index: u32) -> Option> { + fn Item(&self, _index: u32) -> Option> { None } - fn NamedItem(&self, _name: DOMString) -> Option> { + fn NamedItem(&self, _name: DOMString) -> Option> { None } - fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option> { + fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option> { None } @@ -191,7 +191,7 @@ impl<'a> HTMLSelectElementMethods for JSRef<'a, HTMLSelectElement> { fn SetWillValidate(&mut self, _will_validate: bool) { } - fn Validity(&self) -> Unrooted { + fn Validity(&self) -> Temporary { let roots = RootCollection::new(); let window = window_from_node(self).root(&roots); ValidityState::new(&*window) diff --git a/src/components/script/dom/htmlsourceelement.rs b/src/components/script/dom/htmlsourceelement.rs index 76d7cb28bab..41586e55401 100644 --- a/src/components/script/dom/htmlsourceelement.rs +++ b/src/components/script/dom/htmlsourceelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLSourceElementBinding; use dom::bindings::codegen::InheritTypes::HTMLSourceElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLSourceElementTypeId; @@ -34,7 +34,7 @@ impl HTMLSourceElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLSourceElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLSourceElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlspanelement.rs b/src/components/script/dom/htmlspanelement.rs index dac10e30b68..79beef28cab 100644 --- a/src/components/script/dom/htmlspanelement.rs +++ b/src/components/script/dom/htmlspanelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLSpanElementBinding; use dom::bindings::codegen::InheritTypes::HTMLSpanElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLSpanElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,7 +33,7 @@ impl HTMLSpanElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLSpanElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLSpanElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlstyleelement.rs b/src/components/script/dom/htmlstyleelement.rs index 94255fe92a9..1ee1408e9ef 100644 --- a/src/components/script/dom/htmlstyleelement.rs +++ b/src/components/script/dom/htmlstyleelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLStyleElementBinding; use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLStyleElementDerived, NodeCast}; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLStyleElementTypeId; @@ -37,7 +37,7 @@ impl HTMLStyleElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLStyleElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLStyleElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltablecaptionelement.rs b/src/components/script/dom/htmltablecaptionelement.rs index 45f3d6ec079..cc99c839e80 100644 --- a/src/components/script/dom/htmltablecaptionelement.rs +++ b/src/components/script/dom/htmltablecaptionelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableCaptionElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableCaptionElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableCaptionElementTypeId; @@ -34,7 +34,7 @@ impl HTMLTableCaptionElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLTableCaptionElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableCaptionElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltablecolelement.rs b/src/components/script/dom/htmltablecolelement.rs index 97c85275ee9..e387e5ad2cc 100644 --- a/src/components/script/dom/htmltablecolelement.rs +++ b/src/components/script/dom/htmltablecolelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableColElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableColElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableColElementTypeId; @@ -34,7 +34,7 @@ impl HTMLTableColElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLTableColElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableColElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltabledatacellelement.rs b/src/components/script/dom/htmltabledatacellelement.rs index 359e2837744..d9c0f208bff 100644 --- a/src/components/script/dom/htmltabledatacellelement.rs +++ b/src/components/script/dom/htmltabledatacellelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableDataCellElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableDataCellElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLTableDataCellElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,7 +33,7 @@ impl HTMLTableDataCellElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLTableDataCellElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableDataCellElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltableelement.rs b/src/components/script/dom/htmltableelement.rs index 6451e2d7276..bebf407b73a 100644 --- a/src/components/script/dom/htmltableelement.rs +++ b/src/components/script/dom/htmltableelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableElementTypeId; @@ -34,7 +34,7 @@ impl HTMLTableElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLTableElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltableheadercellelement.rs b/src/components/script/dom/htmltableheadercellelement.rs index ce1dc6a8241..beb9c5e2f97 100644 --- a/src/components/script/dom/htmltableheadercellelement.rs +++ b/src/components/script/dom/htmltableheadercellelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableHeaderCellElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableHeaderCellElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLTableHeaderCellElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,7 +33,7 @@ impl HTMLTableHeaderCellElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLTableHeaderCellElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableHeaderCellElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltablerowelement.rs b/src/components/script/dom/htmltablerowelement.rs index d7d05516798..0d949741b4c 100644 --- a/src/components/script/dom/htmltablerowelement.rs +++ b/src/components/script/dom/htmltablerowelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableRowElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableRowElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableRowElementTypeId; @@ -34,7 +34,7 @@ impl HTMLTableRowElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLTableRowElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableRowElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltablesectionelement.rs b/src/components/script/dom/htmltablesectionelement.rs index 62dd52e9758..5eefa98722a 100644 --- a/src/components/script/dom/htmltablesectionelement.rs +++ b/src/components/script/dom/htmltablesectionelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableSectionElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableSectionElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableSectionElementTypeId; @@ -34,7 +34,7 @@ impl HTMLTableSectionElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLTableSectionElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTableSectionElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltemplateelement.rs b/src/components/script/dom/htmltemplateelement.rs index 245ce104439..8e3b8d115ed 100644 --- a/src/components/script/dom/htmltemplateelement.rs +++ b/src/components/script/dom/htmltemplateelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTemplateElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTemplateElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLTemplateElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,7 +33,7 @@ impl HTMLTemplateElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLTemplateElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTemplateElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltextareaelement.rs b/src/components/script/dom/htmltextareaelement.rs index 2005a6384e4..7e221cbbd3e 100644 --- a/src/components/script/dom/htmltextareaelement.rs +++ b/src/components/script/dom/htmltextareaelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTextAreaElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTextAreaElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::{ErrorResult, Fallible}; use dom::document::Document; use dom::element::HTMLTextAreaElementTypeId; @@ -34,7 +34,7 @@ impl HTMLTextAreaElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLTextAreaElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTextAreaElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltimeelement.rs b/src/components/script/dom/htmltimeelement.rs index dd2a9b28f97..15e8101561f 100644 --- a/src/components/script/dom/htmltimeelement.rs +++ b/src/components/script/dom/htmltimeelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTimeElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTimeElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTimeElementTypeId; @@ -34,7 +34,7 @@ impl HTMLTimeElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLTimeElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTimeElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltitleelement.rs b/src/components/script/dom/htmltitleelement.rs index c78b26ee4cb..5f7016bc96c 100644 --- a/src/components/script/dom/htmltitleelement.rs +++ b/src/components/script/dom/htmltitleelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTitleElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTitleElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTitleElementTypeId; @@ -34,7 +34,7 @@ impl HTMLTitleElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLTitleElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTitleElementBinding::Wrap) } diff --git a/src/components/script/dom/htmltrackelement.rs b/src/components/script/dom/htmltrackelement.rs index db25ab17130..b2b2b077c78 100644 --- a/src/components/script/dom/htmltrackelement.rs +++ b/src/components/script/dom/htmltrackelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTrackElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTrackElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTrackElementTypeId; @@ -34,7 +34,7 @@ impl HTMLTrackElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLTrackElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLTrackElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlulistelement.rs b/src/components/script/dom/htmlulistelement.rs index bed085157ce..5d5bd0b61da 100644 --- a/src/components/script/dom/htmlulistelement.rs +++ b/src/components/script/dom/htmlulistelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLUListElementBinding; use dom::bindings::codegen::InheritTypes::HTMLUListElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLUListElementTypeId; @@ -34,7 +34,7 @@ impl HTMLUListElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLUListElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLUListElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlunknownelement.rs b/src/components/script/dom/htmlunknownelement.rs index da14d35b69f..2fbf2906c3d 100644 --- a/src/components/script/dom/htmlunknownelement.rs +++ b/src/components/script/dom/htmlunknownelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLUnknownElementBinding; use dom::bindings::codegen::InheritTypes::HTMLUnknownElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLUnknownElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -33,7 +33,7 @@ impl HTMLUnknownElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLUnknownElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLUnknownElementBinding::Wrap) } diff --git a/src/components/script/dom/htmlvideoelement.rs b/src/components/script/dom/htmlvideoelement.rs index 60e9d6a09cf..68925daacee 100644 --- a/src/components/script/dom/htmlvideoelement.rs +++ b/src/components/script/dom/htmlvideoelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLVideoElementBinding; use dom::bindings::codegen::InheritTypes::HTMLVideoElementDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLVideoElementTypeId; @@ -34,7 +34,7 @@ impl HTMLVideoElement { } } - pub fn new(localName: DOMString, document: &JSRef) -> Unrooted { + pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLVideoElement::new_inherited(localName, document.unrooted()); Node::reflect_node(~element, document, HTMLVideoElementBinding::Wrap) } diff --git a/src/components/script/dom/location.rs b/src/components/script/dom/location.rs index 4a28e1c449d..72769bc0a37 100644 --- a/src/components/script/dom/location.rs +++ b/src/components/script/dom/location.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::LocationBinding; -use dom::bindings::js::{JSRef, Unrooted}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::Fallible; use dom::window::Window; @@ -29,7 +29,7 @@ impl Location { } } - pub fn new(window: &JSRef, page: Rc) -> Unrooted { + pub fn new(window: &JSRef, page: Rc) -> Temporary { reflect_dom_object(~Location::new_inherited(page), window, LocationBinding::Wrap) diff --git a/src/components/script/dom/mouseevent.rs b/src/components/script/dom/mouseevent.rs index fbfc9cf783d..ce46cd47680 100644 --- a/src/components/script/dom/mouseevent.rs +++ b/src/components/script/dom/mouseevent.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::MouseEventBinding; use dom::bindings::codegen::InheritTypes::{UIEventCast, MouseEventDerived}; -use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Temporary}; use dom::bindings::error::Fallible; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::event::{Event, MouseEventTypeId}; @@ -51,7 +51,7 @@ impl MouseEvent { } } - pub fn new(window: &JSRef) -> Unrooted { + pub fn new(window: &JSRef) -> Temporary { reflect_dom_object(~MouseEvent::new_inherited(), window, MouseEventBinding::Wrap) @@ -59,7 +59,7 @@ impl MouseEvent { pub fn Constructor(owner: &JSRef, type_: DOMString, - init: &MouseEventBinding::MouseEventInit) -> Fallible> { + init: &MouseEventBinding::MouseEventInit) -> Fallible> { let roots = RootCollection::new(); let mut ev = MouseEvent::new(owner).root(&roots); let view = init.view.as_ref().map(|view| view.root(&roots)); @@ -69,7 +69,7 @@ impl MouseEvent { init.clientX, init.clientY, init.ctrlKey, init.altKey, init.shiftKey, init.metaKey, init.button, related_target.root_ref()); - Ok(Unrooted::new_rooted(&*ev)) + Ok(Temporary::new_rooted(&*ev)) } } @@ -84,7 +84,7 @@ pub trait MouseEventMethods { fn MetaKey(&self) -> bool; fn Button(&self) -> u16; fn Buttons(&self)-> u16; - fn GetRelatedTarget(&self) -> Option>; + fn GetRelatedTarget(&self) -> Option>; fn GetModifierState(&self, _keyArg: DOMString) -> bool; fn InitMouseEvent(&mut self, typeArg: DOMString, @@ -146,8 +146,8 @@ impl<'a> MouseEventMethods for JSRef<'a, MouseEvent> { 0 } - fn GetRelatedTarget(&self) -> Option> { - self.related_target.clone().map(|target| Unrooted::new(target)) + fn GetRelatedTarget(&self) -> Option> { + self.related_target.clone().map(|target| Temporary::new(target)) } fn GetModifierState(&self, _keyArg: DOMString) -> bool { diff --git a/src/components/script/dom/navigator.rs b/src/components/script/dom/navigator.rs index 9e54bffb0c1..2e31fbe8cbb 100644 --- a/src/components/script/dom/navigator.rs +++ b/src/components/script/dom/navigator.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::NavigatorBinding; -use dom::bindings::js::{JSRef, Unrooted}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::Fallible; use dom::window::Window; @@ -21,7 +21,7 @@ impl Navigator { } } - pub fn new(window: &JSRef) -> Unrooted { + pub fn new(window: &JSRef) -> Temporary { reflect_dom_object(~Navigator::new_inherited(), window, NavigatorBinding::Wrap) diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 99daa05e1a5..07b9ecd111d 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -10,8 +10,8 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, TextCast, NodeCast, Elem use dom::bindings::codegen::InheritTypes::{CharacterDataCast, NodeBase, NodeDerived}; use dom::bindings::codegen::InheritTypes::{ProcessingInstructionCast, EventTargetCast}; use dom::bindings::codegen::BindingDeclarations::NodeBinding::NodeConstants; -use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Unrooted, Root}; -use dom::bindings::js::{OptionalAssignable, UnrootedPushable, OptionalRootedRootable}; +use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Temporary, Root}; +use dom::bindings::js::{OptionalAssignable, TemporaryPushable, OptionalRootedRootable}; use dom::bindings::js::{ResultRootable, OptionalRootable}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::{ErrorResult, Fallible, NotFound, HierarchyRequest}; @@ -403,13 +403,13 @@ pub trait NodeHelpers { fn type_id(&self) -> NodeTypeId; - fn parent_node(&self) -> Option>; - fn first_child(&self) -> Option>; - fn last_child(&self) -> Option>; - fn prev_sibling(&self) -> Option>; - fn next_sibling(&self) -> Option>; + fn parent_node(&self) -> Option>; + fn first_child(&self) -> Option>; + fn last_child(&self) -> Option>; + fn prev_sibling(&self) -> Option>; + fn next_sibling(&self) -> Option>; - fn owner_doc(&self) -> Unrooted; + fn owner_doc(&self) -> Temporary; fn set_owner_doc(&mut self, document: &JSRef); fn wait_until_safe_to_modify_dom(&self); @@ -473,26 +473,26 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { self.get().type_id } - fn parent_node(&self) -> Option> { - self.get().parent_node.clone().map(|node| Unrooted::new(node)) + fn parent_node(&self) -> Option> { + self.get().parent_node.clone().map(|node| Temporary::new(node)) } - fn first_child(&self) -> Option> { - self.get().first_child.clone().map(|node| Unrooted::new(node)) + fn first_child(&self) -> Option> { + self.get().first_child.clone().map(|node| Temporary::new(node)) } - fn last_child(&self) -> Option> { - self.get().last_child.clone().map(|node| Unrooted::new(node)) + fn last_child(&self) -> Option> { + self.get().last_child.clone().map(|node| Temporary::new(node)) } /// Returns the previous sibling of this node. Fails if this node is borrowed mutably. - fn prev_sibling(&self) -> Option> { - self.get().prev_sibling.clone().map(|node| Unrooted::new(node)) + fn prev_sibling(&self) -> Option> { + self.get().prev_sibling.clone().map(|node| Temporary::new(node)) } /// Returns the next sibling of this node. Fails if this node is borrowed mutably. - fn next_sibling(&self) -> Option> { - self.get().next_sibling.clone().map(|node| Unrooted::new(node)) + fn next_sibling(&self) -> Option> { + self.get().next_sibling.clone().map(|node| Temporary::new(node)) } #[inline] @@ -581,7 +581,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { fn is_parent_of(&self, child: &JSRef) -> bool { match child.parent_node() { - Some(ref parent) if *parent == Unrooted::new_rooted(self) => true, + Some(ref parent) if *parent == Temporary::new_rooted(self) => true, _ => false } } @@ -618,8 +618,8 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { } } - fn owner_doc(&self) -> Unrooted { - Unrooted::new(self.owner_doc.get_ref().clone()) + fn owner_doc(&self) -> Temporary { + Temporary::new(self.owner_doc.get_ref().clone()) } fn set_owner_doc(&mut self, document: &JSRef) { @@ -656,7 +656,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { /// If the given untrusted node address represents a valid DOM node in the given runtime, /// returns it. pub fn from_untrusted_node_address(runtime: *JSRuntime, candidate: UntrustedNodeAddress) - -> Unrooted { + -> Temporary { unsafe { let candidate: uintptr_t = cast::transmute(candidate); let object: *JSObject = jsfriendapi::bindgen::JS_GetAddressableObject(runtime, @@ -665,7 +665,7 @@ pub fn from_untrusted_node_address(runtime: *JSRuntime, candidate: UntrustedNode fail!("Attempted to create a `JS` from an invalid pointer!") } let boxed_node: *mut Node = utils::unwrap(object); - Unrooted::new(JS::from_raw(boxed_node)) + Temporary::new(JS::from_raw(boxed_node)) } } @@ -913,13 +913,13 @@ impl Node { (node: ~N, document: &JSRef, wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~N) -> JS) - -> Unrooted { + -> Temporary { let roots = RootCollection::new(); assert!(node.reflector().get_jsobject().is_null()); let window = document.get().window.root(&roots); let node = reflect_dom_object(node, &window.root_ref(), wrap_fn).root(&roots); assert!(node.reflector().get_jsobject().is_not_null()); - Unrooted::new_rooted(&*node) + Temporary::new_rooted(&*node) } pub fn new_inherited(type_id: NodeTypeId, doc: JS) -> Node { @@ -977,7 +977,7 @@ impl Node { // http://dom.spec.whatwg.org/#concept-node-pre-insert fn pre_insert(node: &mut JSRef, parent: &mut JSRef, child: Option>) - -> Fallible> { + -> Fallible> { let roots = RootCollection::new(); // Step 1. match parent.type_id() { @@ -1110,7 +1110,7 @@ impl Node { Node::insert(node, parent, referenceChild, Unsuppressed); // Step 11. - return Ok(Unrooted::new_rooted(node)) + return Ok(Temporary::new_rooted(node)) } // http://dom.spec.whatwg.org/#concept-node-insert @@ -1203,10 +1203,10 @@ impl Node { } // http://dom.spec.whatwg.org/#concept-node-pre-remove - fn pre_remove(child: &mut JSRef, parent: &mut JSRef) -> Fallible> { + fn pre_remove(child: &mut JSRef, parent: &mut JSRef) -> Fallible> { // Step 1. match child.parent_node() { - Some(ref node) if *node != Unrooted::new_rooted(parent) => return Err(NotFound), + Some(ref node) if *node != Temporary::new_rooted(parent) => return Err(NotFound), _ => () } @@ -1214,12 +1214,12 @@ impl Node { Node::remove(child, parent, Unsuppressed); // Step 3. - Ok(Unrooted::new_rooted(child)) + Ok(Temporary::new_rooted(child)) } // http://dom.spec.whatwg.org/#concept-node-remove fn remove(node: &mut JSRef, parent: &mut JSRef, suppress_observers: SuppressObserver) { - assert!(node.parent_node().map_or(false, |node_parent| node_parent == Unrooted::new_rooted(parent))); + assert!(node.parent_node().map_or(false, |node_parent| node_parent == Temporary::new_rooted(parent))); // Step 1-5: ranges. // Step 6-7: mutation observers. @@ -1236,7 +1236,7 @@ impl Node { // http://dom.spec.whatwg.org/#concept-node-clone pub fn clone(node: &JSRef, maybe_doc: Option<&JSRef>, - clone_children: CloneChildrenFlag) -> Unrooted { + clone_children: CloneChildrenFlag) -> Temporary { let roots = RootCollection::new(); // Step 1. @@ -1349,7 +1349,7 @@ impl Node { } // Step 7. - Unrooted::new_rooted(&*copy) + Temporary::new_rooted(&*copy) } /// Sends layout data, if any, back to the script task to be destroyed. @@ -1372,25 +1372,25 @@ pub trait NodeMethods { fn NodeType(&self) -> u16; fn NodeName(&self) -> DOMString; fn GetBaseURI(&self) -> Option; - fn GetOwnerDocument(&self) -> Option>; - fn GetParentNode(&self) -> Option>; - fn GetParentElement(&self) -> Option>; + fn GetOwnerDocument(&self) -> Option>; + fn GetParentNode(&self) -> Option>; + fn GetParentElement(&self) -> Option>; fn HasChildNodes(&self) -> bool; - fn ChildNodes(&mut self) -> Unrooted; - fn GetFirstChild(&self) -> Option>; - fn GetLastChild(&self) -> Option>; - fn GetPreviousSibling(&self) -> Option>; - fn GetNextSibling(&self) -> Option>; + fn ChildNodes(&mut self) -> Temporary; + fn GetFirstChild(&self) -> Option>; + fn GetLastChild(&self) -> Option>; + fn GetPreviousSibling(&self) -> Option>; + fn GetNextSibling(&self) -> Option>; fn GetNodeValue(&self) -> Option; fn SetNodeValue(&mut self, val: Option) -> ErrorResult; fn GetTextContent(&self) -> Option; fn SetTextContent(&mut self, value: Option) -> ErrorResult; - fn InsertBefore(&mut self, node: &mut JSRef, child: Option>) -> Fallible>; - fn AppendChild(&mut self, node: &mut JSRef) -> Fallible>; - fn ReplaceChild(&mut self, node: &mut JSRef, child: &mut JSRef) -> Fallible>; - fn RemoveChild(&mut self, node: &mut JSRef) -> Fallible>; + fn InsertBefore(&mut self, node: &mut JSRef, child: Option>) -> Fallible>; + fn AppendChild(&mut self, node: &mut JSRef) -> Fallible>; + fn ReplaceChild(&mut self, node: &mut JSRef, child: &mut JSRef) -> Fallible>; + fn RemoveChild(&mut self, node: &mut JSRef) -> Fallible>; fn Normalize(&mut self); - fn CloneNode(&self, deep: bool) -> Unrooted; + fn CloneNode(&self, deep: bool) -> Temporary; fn IsEqualNode(&self, maybe_node: Option>) -> bool; fn CompareDocumentPosition(&self, other: &JSRef) -> u16; fn Contains(&self, maybe_other: Option>) -> bool; @@ -1443,7 +1443,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-ownerdocument - fn GetOwnerDocument(&self) -> Option> { + fn GetOwnerDocument(&self) -> Option> { match self.type_id { ElementNodeTypeId(..) | CommentNodeTypeId | @@ -1456,18 +1456,18 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-parentnode - fn GetParentNode(&self) -> Option> { - self.parent_node.clone().map(|node| Unrooted::new(node)) + fn GetParentNode(&self) -> Option> { + self.parent_node.clone().map(|node| Temporary::new(node)) } // http://dom.spec.whatwg.org/#dom-node-parentelement - fn GetParentElement(&self) -> Option> { + fn GetParentElement(&self) -> Option> { let roots = RootCollection::new(); self.parent_node.clone() .and_then(|parent| { let parent = parent.root(&roots); ElementCast::to_ref(&*parent).map(|elem| { - Unrooted::new_rooted(elem) + Temporary::new_rooted(elem) }) }) } @@ -1478,38 +1478,38 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-childnodes - fn ChildNodes(&mut self) -> Unrooted { + fn ChildNodes(&mut self) -> Temporary { let roots = RootCollection::new(); match self.child_list { None => (), - Some(ref list) => return Unrooted::new(list.clone()), + Some(ref list) => return Temporary::new(list.clone()), } let doc = self.owner_doc().root(&roots); let window = doc.deref().window.root(&roots); let child_list = NodeList::new_child_list(&*window, self); self.child_list.assign(Some(child_list)); - Unrooted::new(self.child_list.get_ref().clone()) + Temporary::new(self.child_list.get_ref().clone()) } // http://dom.spec.whatwg.org/#dom-node-firstchild - fn GetFirstChild(&self) -> Option> { - self.first_child.clone().map(|node| Unrooted::new(node)) + fn GetFirstChild(&self) -> Option> { + self.first_child.clone().map(|node| Temporary::new(node)) } // http://dom.spec.whatwg.org/#dom-node-lastchild - fn GetLastChild(&self) -> Option> { - self.last_child.clone().map(|node| Unrooted::new(node)) + fn GetLastChild(&self) -> Option> { + self.last_child.clone().map(|node| Temporary::new(node)) } // http://dom.spec.whatwg.org/#dom-node-previoussibling - fn GetPreviousSibling(&self) -> Option> { - self.prev_sibling.clone().map(|node| Unrooted::new(node)) + fn GetPreviousSibling(&self) -> Option> { + self.prev_sibling.clone().map(|node| Temporary::new(node)) } // http://dom.spec.whatwg.org/#dom-node-nextsibling - fn GetNextSibling(&self) -> Option> { - self.next_sibling.clone().map(|node| Unrooted::new(node)) + fn GetNextSibling(&self) -> Option> { + self.next_sibling.clone().map(|node| Temporary::new(node)) } // http://dom.spec.whatwg.org/#dom-node-nodevalue @@ -1608,17 +1608,17 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-insertbefore - fn InsertBefore(&mut self, node: &mut JSRef, child: Option>) -> Fallible> { + fn InsertBefore(&mut self, node: &mut JSRef, child: Option>) -> Fallible> { Node::pre_insert(node, self, child) } // http://dom.spec.whatwg.org/#dom-node-appendchild - fn AppendChild(&mut self, node: &mut JSRef) -> Fallible> { + fn AppendChild(&mut self, node: &mut JSRef) -> Fallible> { Node::pre_insert(node, self, None) } // http://dom.spec.whatwg.org/#concept-node-replace - fn ReplaceChild(&mut self, node: &mut JSRef, child: &mut JSRef) -> Fallible> { + fn ReplaceChild(&mut self, node: &mut JSRef, child: &mut JSRef) -> Fallible> { let roots = RootCollection::new(); // Step 1. @@ -1710,7 +1710,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { // Ok if not caught by previous error checks. if node.unrooted() == child.unrooted() { - return Ok(Unrooted::new_rooted(child)); + return Ok(Temporary::new_rooted(child)); } // Step 7-8. @@ -1744,12 +1744,12 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // Step 15. - Ok(Unrooted::new_rooted(child)) + Ok(Temporary::new_rooted(child)) } // http://dom.spec.whatwg.org/#dom-node-removechild fn RemoveChild(&mut self, node: &mut JSRef) - -> Fallible> { + -> Fallible> { Node::pre_remove(node, self) } @@ -1782,7 +1782,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-clonenode - fn CloneNode(&self, deep: bool) -> Unrooted { + fn CloneNode(&self, deep: bool) -> Temporary { match deep { true => Node::clone(self, None, CloneChildren), false => Node::clone(self, None, DoNotCloneChildren) @@ -1959,15 +1959,15 @@ impl Reflectable for Node { } } -pub fn document_from_node(derived: &JSRef) -> Unrooted { +pub fn document_from_node(derived: &JSRef) -> Temporary { let node: &JSRef = NodeCast::from_ref(derived); node.owner_doc() } -pub fn window_from_node(derived: &JSRef) -> Unrooted { +pub fn window_from_node(derived: &JSRef) -> Temporary { let roots = RootCollection::new(); let document = document_from_node(derived).root(&roots); - Unrooted::new(document.deref().window.clone()) + Temporary::new(document.deref().window.clone()) } impl<'a> VirtualMethods for JSRef<'a, Node> { diff --git a/src/components/script/dom/nodelist.rs b/src/components/script/dom/nodelist.rs index a874a068b65..7157c7ec061 100644 --- a/src/components/script/dom/nodelist.rs +++ b/src/components/script/dom/nodelist.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::NodeListBinding; -use dom::bindings::js::{JS, JSRef, Unrooted, RootCollection}; +use dom::bindings::js::{JS, JSRef, Temporary, RootCollection}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::node::{Node, NodeHelpers}; use dom::window::Window; @@ -32,24 +32,24 @@ impl NodeList { } pub fn new(window: &JSRef, - list_type: NodeListType) -> Unrooted { + list_type: NodeListType) -> Temporary { reflect_dom_object(~NodeList::new_inherited(window.unrooted(), list_type), window, NodeListBinding::Wrap) } - pub fn new_simple_list(window: &JSRef, elements: Vec>) -> Unrooted { + pub fn new_simple_list(window: &JSRef, elements: Vec>) -> Temporary { NodeList::new(window, Simple(elements.iter().map(|element| element.unrooted()).collect())) } - pub fn new_child_list(window: &JSRef, node: &JSRef) -> Unrooted { + pub fn new_child_list(window: &JSRef, node: &JSRef) -> Temporary { NodeList::new(window, Children(node.unrooted())) } } pub trait NodeListMethods { fn Length(&self) -> u32; - fn Item(&self, index: u32) -> Option>; - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option>; + fn Item(&self, index: u32) -> Option>; + fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option>; } impl<'a> NodeListMethods for JSRef<'a, NodeList> { @@ -64,20 +64,20 @@ impl<'a> NodeListMethods for JSRef<'a, NodeList> { } } - fn Item(&self, index: u32) -> Option> { + fn Item(&self, index: u32) -> Option> { let roots = RootCollection::new(); match self.list_type { _ if index >= self.Length() => None, - Simple(ref elems) => Some(Unrooted::new(elems.get(index as uint).clone())), + Simple(ref elems) => Some(Temporary::new(elems.get(index as uint).clone())), Children(ref node) => { let node = node.root(&roots); node.deref().children().nth(index as uint) - .map(|child| Unrooted::new_rooted(&child)) + .map(|child| Temporary::new_rooted(&child)) } } } - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { + fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { let item = self.Item(index); *found = item.is_some(); item diff --git a/src/components/script/dom/processinginstruction.rs b/src/components/script/dom/processinginstruction.rs index ee88cb51bf6..9a00333fd93 100644 --- a/src/components/script/dom/processinginstruction.rs +++ b/src/components/script/dom/processinginstruction.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::ProcessingInstructionBinding; use dom::bindings::codegen::InheritTypes::ProcessingInstructionDerived; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::characterdata::CharacterData; use dom::document::Document; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -35,7 +35,7 @@ impl ProcessingInstruction { } } - pub fn new(target: DOMString, data: DOMString, document: &JSRef) -> Unrooted { + pub fn new(target: DOMString, data: DOMString, document: &JSRef) -> Temporary { let node = ProcessingInstruction::new_inherited(target, data, document.unrooted()); Node::reflect_node(~node, document, ProcessingInstructionBinding::Wrap) } diff --git a/src/components/script/dom/testbinding.rs b/src/components/script/dom/testbinding.rs index 3ad4f8fa202..2c012c1b911 100644 --- a/src/components/script/dom/testbinding.rs +++ b/src/components/script/dom/testbinding.rs @@ -2,7 +2,7 @@ * 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, RootCollection, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; use dom::bindings::codegen::BindingDeclarations::TestBindingBinding; use dom::bindings::codegen::UnionTypes::HTMLElementOrLong; use self::TestBindingBinding::TestEnum; @@ -51,7 +51,7 @@ pub trait TestBindingMethods { fn SetByteStringAttribute(&self, _: ByteString); fn EnumAttribute(&self) -> TestEnum; fn SetEnumAttribute(&self, _: TestEnum); - fn InterfaceAttribute(&self) -> Unrooted; + fn InterfaceAttribute(&self) -> Temporary; fn SetInterfaceAttribute(&self, _: &JSRef); fn AnyAttribute(&self, _: *JSContext) -> JSVal; fn SetAnyAttribute(&self, _: *JSContext, _: JSVal); @@ -83,7 +83,7 @@ pub trait TestBindingMethods { fn GetStringAttributeNullable(&self) -> Option; fn SetStringAttributeNullable(&self, _: Option); fn GetEnumAttributeNullable(&self) -> Option; - fn GetInterfaceAttributeNullable(&self) -> Option>; + fn GetInterfaceAttributeNullable(&self) -> Option>; fn SetInterfaceAttributeNullable(&self, _: Option>); fn PassBoolean(&self, _: bool); @@ -231,7 +231,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> { fn SetByteStringAttribute(&self, _: ByteString) {} fn EnumAttribute(&self) -> TestEnum { _empty } fn SetEnumAttribute(&self, _: TestEnum) {} - fn InterfaceAttribute(&self) -> Unrooted { + fn InterfaceAttribute(&self) -> Temporary { let roots = RootCollection::new(); let window = self.window.root(&roots); Blob::new(&*window) @@ -267,7 +267,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> { fn GetStringAttributeNullable(&self) -> Option { Some(~"") } fn SetStringAttributeNullable(&self, _: Option) {} fn GetEnumAttributeNullable(&self) -> Option { Some(_empty) } - fn GetInterfaceAttributeNullable(&self) -> Option> { + fn GetInterfaceAttributeNullable(&self) -> Option> { let roots = RootCollection::new(); let window = self.window.root(&roots); Some(Blob::new(&(*window))) diff --git a/src/components/script/dom/text.rs b/src/components/script/dom/text.rs index 570c1412833..be62565f965 100644 --- a/src/components/script/dom/text.rs +++ b/src/components/script/dom/text.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::TextBinding; use dom::bindings::codegen::InheritTypes::TextDerived; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; use dom::bindings::error::Fallible; use dom::characterdata::CharacterData; use dom::document::Document; @@ -35,12 +35,12 @@ impl Text { } } - pub fn new(text: DOMString, document: &JSRef) -> Unrooted { + pub fn new(text: DOMString, document: &JSRef) -> Temporary { let node = Text::new_inherited(text, document.unrooted()); Node::reflect_node(~node, document, TextBinding::Wrap) } - pub fn Constructor(owner: &JSRef, text: DOMString) -> Fallible> { + pub fn Constructor(owner: &JSRef, text: DOMString) -> Fallible> { let roots = RootCollection::new(); let document = owner.Document().root(&roots); Ok(Text::new(text.clone(), &*document)) @@ -48,12 +48,12 @@ impl Text { } pub trait TextMethods { - fn SplitText(&self, _offset: u32) -> Fallible>; + fn SplitText(&self, _offset: u32) -> Fallible>; fn GetWholeText(&self) -> Fallible; } impl<'a> TextMethods for JSRef<'a, Text> { - fn SplitText(&self, _offset: u32) -> Fallible> { + fn SplitText(&self, _offset: u32) -> Fallible> { fail!("unimplemented") } diff --git a/src/components/script/dom/uievent.rs b/src/components/script/dom/uievent.rs index cb1365181e5..03140504400 100644 --- a/src/components/script/dom/uievent.rs +++ b/src/components/script/dom/uievent.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::UIEventBinding; use dom::bindings::codegen::InheritTypes::{EventCast, UIEventDerived}; -use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Unrooted}; +use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Temporary}; use dom::bindings::error::Fallible; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::event::{Event, EventMethods, EventTypeId, UIEventTypeId}; @@ -36,7 +36,7 @@ impl UIEvent { } } - pub fn new(window: &JSRef) -> Unrooted { + pub fn new(window: &JSRef) -> Temporary { reflect_dom_object(~UIEvent::new_inherited(UIEventTypeId), window, UIEventBinding::Wrap) @@ -44,25 +44,25 @@ impl UIEvent { pub fn Constructor(owner: &JSRef, type_: DOMString, - init: &UIEventBinding::UIEventInit) -> Fallible> { + init: &UIEventBinding::UIEventInit) -> Fallible> { let roots = RootCollection::new(); let mut ev = UIEvent::new(owner).root(&roots); let view = init.view.as_ref().map(|view| view.root(&roots)); ev.InitUIEvent(type_, init.parent.bubbles, init.parent.cancelable, view.root_ref(), init.detail); - Ok(Unrooted::new_rooted(&*ev)) + Ok(Temporary::new_rooted(&*ev)) } } pub trait UIEventMethods { - fn GetView(&self) -> Option>; + fn GetView(&self) -> Option>; fn Detail(&self) -> i32; fn LayerX(&self) -> i32; fn LayerY(&self) -> i32; fn PageX(&self) -> i32; fn PageY(&self) -> i32; fn Which(&self) -> u32; - fn GetRangeParent(&self) -> Option>; + fn GetRangeParent(&self) -> Option>; fn RangeOffset(&self) -> i32; fn CancelBubble(&self) -> bool; fn SetCancelBubble(&mut self, _val: bool); @@ -76,8 +76,8 @@ pub trait UIEventMethods { } impl<'a> UIEventMethods for JSRef<'a, UIEvent> { - fn GetView(&self) -> Option> { - self.view.clone().map(|view| Unrooted::new(view)) + fn GetView(&self) -> Option> { + self.view.clone().map(|view| Temporary::new(view)) } fn Detail(&self) -> i32 { @@ -123,7 +123,7 @@ impl<'a> UIEventMethods for JSRef<'a, UIEvent> { 0 } - fn GetRangeParent(&self) -> Option> { + fn GetRangeParent(&self) -> Option> { //TODO None } diff --git a/src/components/script/dom/validitystate.rs b/src/components/script/dom/validitystate.rs index d4d829f842b..f60e646b3ff 100644 --- a/src/components/script/dom/validitystate.rs +++ b/src/components/script/dom/validitystate.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::ValidityStateBinding; -use dom::bindings::js::{JS, JSRef, Unrooted}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::window::Window; @@ -23,7 +23,7 @@ impl ValidityState { } } - pub fn new(window: &JSRef) -> Unrooted { + pub fn new(window: &JSRef) -> Temporary { reflect_dom_object(~ValidityState::new_inherited(window.unrooted()), window, ValidityStateBinding::Wrap) diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index 04108330cb8..d3ef0769431 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::WindowBinding; -use dom::bindings::js::{JS, JSRef, Unrooted, OptionalAssignable}; +use dom::bindings::js::{JS, JSRef, Temporary, OptionalAssignable}; use dom::bindings::trace::{Traceable, Untraceable}; use dom::bindings::utils::{Reflectable, Reflector}; use dom::browsercontext::BrowserContext; @@ -108,7 +108,7 @@ pub struct TimerData { pub trait WindowMethods { fn Alert(&self, s: DOMString); fn Close(&self); - fn Document(&self) -> Unrooted; + fn Document(&self) -> Temporary; fn Name(&self) -> DOMString; fn SetName(&self, _name: DOMString); fn Status(&self) -> DOMString; @@ -117,10 +117,10 @@ pub trait WindowMethods { fn Stop(&self); fn Focus(&self); fn Blur(&self); - fn GetFrameElement(&self) -> Option>; - fn Location(&mut self) -> Unrooted; - fn Console(&mut self) -> Unrooted; - fn Navigator(&mut self) -> Unrooted; + fn GetFrameElement(&self) -> Option>; + fn Location(&mut self) -> Temporary; + fn Console(&mut self) -> Temporary; + fn Navigator(&mut self) -> Temporary; fn Confirm(&self, _message: DOMString) -> bool; fn Prompt(&self, _message: DOMString, _default: DOMString) -> Option; fn Print(&self); @@ -129,8 +129,8 @@ pub trait WindowMethods { fn ClearTimeout(&mut self, handle: i32); fn SetInterval(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32; fn ClearInterval(&mut self, handle: i32); - fn Window(&self) -> Unrooted; - fn Self(&self) -> Unrooted; + fn Window(&self) -> Temporary; + fn Self(&self) -> Temporary; } impl<'a> WindowMethods for JSRef<'a, Window> { @@ -144,9 +144,9 @@ impl<'a> WindowMethods for JSRef<'a, Window> { chan.send(ExitWindowMsg(self.page.id.clone())); } - fn Document(&self) -> Unrooted { + fn Document(&self) -> Temporary { let frame = self.page().frame(); - Unrooted::new(frame.get_ref().document.clone()) + Temporary::new(frame.get_ref().document.clone()) } fn Name(&self) -> DOMString { @@ -176,33 +176,33 @@ impl<'a> WindowMethods for JSRef<'a, Window> { fn Blur(&self) { } - fn GetFrameElement(&self) -> Option> { + fn GetFrameElement(&self) -> Option> { None } - fn Location(&mut self) -> Unrooted { + fn Location(&mut self) -> Temporary { if self.location.is_none() { let page = self.deref().page.clone(); let location = Location::new(self, page); self.location.assign(Some(location)); } - Unrooted::new(self.location.get_ref().clone()) + Temporary::new(self.location.get_ref().clone()) } - fn Console(&mut self) -> Unrooted { + fn Console(&mut self) -> Temporary { if self.console.is_none() { let console = Console::new(self); self.console.assign(Some(console)); } - Unrooted::new(self.console.get_ref().clone()) + Temporary::new(self.console.get_ref().clone()) } - fn Navigator(&mut self) -> Unrooted { + fn Navigator(&mut self) -> Temporary { if self.navigator.is_none() { let navigator = Navigator::new(self); self.navigator.assign(Some(navigator)); } - Unrooted::new(self.navigator.get_ref().clone()) + Temporary::new(self.navigator.get_ref().clone()) } fn Confirm(&self, _message: DOMString) -> bool { @@ -241,11 +241,11 @@ impl<'a> WindowMethods for JSRef<'a, Window> { self.ClearTimeout(handle); } - fn Window(&self) -> Unrooted { - Unrooted::new_rooted(self) + fn Window(&self) -> Temporary { + Temporary::new_rooted(self) } - fn Self(&self) -> Unrooted { + fn Self(&self) -> Temporary { self.Window() } } @@ -342,7 +342,7 @@ impl Window { script_chan: ScriptChan, compositor: ~ScriptListener, image_cache_task: ImageCacheTask) - -> Unrooted { + -> Temporary { let win = ~Window { eventtarget: EventTarget::new_inherited(WindowTypeId), script_chan: script_chan, @@ -357,6 +357,6 @@ impl Window { browser_context: None, }; - Unrooted::new(WindowBinding::Wrap(cx, win)) + Temporary::new(WindowBinding::Wrap(cx, win)) } } diff --git a/src/components/script/dom/xmlhttprequest.rs b/src/components/script/dom/xmlhttprequest.rs index a0ffa15c772..7e949a4b2b9 100644 --- a/src/components/script/dom/xmlhttprequest.rs +++ b/src/components/script/dom/xmlhttprequest.rs @@ -10,7 +10,7 @@ use dom::bindings::codegen::InheritTypes::XMLHttpRequestDerived; use dom::document::Document; use dom::eventtarget::{EventTarget, XMLHttpRequestTargetTypeId}; use dom::bindings::error::Fallible; -use dom::bindings::js::{JS, JSRef, Unrooted, OptionalAssignable}; +use dom::bindings::js::{JS, JSRef, Temporary, OptionalAssignable}; use js::jsapi::JSContext; use js::jsval::{JSVal, NullValue}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; @@ -58,12 +58,12 @@ impl XMLHttpRequest { xhr.upload.assign(Some(XMLHttpRequestUpload::new(owner))); xhr } - pub fn new(window: &JSRef) -> Unrooted { + pub fn new(window: &JSRef) -> Temporary { reflect_dom_object(~XMLHttpRequest::new_inherited(window), window, XMLHttpRequestBinding::Wrap) } - pub fn Constructor(owner: &JSRef) -> Fallible> { + pub fn Constructor(owner: &JSRef) -> Fallible> { Ok(XMLHttpRequest::new(owner)) } } @@ -78,7 +78,7 @@ pub trait XMLHttpRequestMethods { fn SetTimeout(&mut self, timeout: u32); fn WithCredentials(&self) -> bool; fn SetWithCredentials(&mut self, with_credentials: bool); - fn Upload(&self) -> Unrooted; + fn Upload(&self) -> Temporary; fn Send(&self, _data: Option); fn Abort(&self); fn ResponseURL(&self) -> DOMString; @@ -91,7 +91,7 @@ pub trait XMLHttpRequestMethods { fn SetResponseType(&mut self, response_type: XMLHttpRequestResponseType); fn Response(&self, _cx: *JSContext) -> JSVal; fn ResponseText(&self) -> DOMString; - fn GetResponseXML(&self) -> Option>; + fn GetResponseXML(&self) -> Option>; } impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { @@ -120,8 +120,8 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { fn SetWithCredentials(&mut self, with_credentials: bool) { self.with_credentials = with_credentials } - fn Upload(&self) -> Unrooted { - Unrooted::new(self.upload.get_ref().clone()) + fn Upload(&self) -> Temporary { + Temporary::new(self.upload.get_ref().clone()) } fn Send(&self, _data: Option) { @@ -159,8 +159,8 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { fn ResponseText(&self) -> DOMString { self.response_text.clone() } - fn GetResponseXML(&self) -> Option> { - self.response_xml.clone().map(|response| Unrooted::new(response)) + fn GetResponseXML(&self) -> Option> { + self.response_xml.clone().map(|response| Temporary::new(response)) } } diff --git a/src/components/script/dom/xmlhttprequestupload.rs b/src/components/script/dom/xmlhttprequestupload.rs index c2332d84ee0..6f373ab0a65 100644 --- a/src/components/script/dom/xmlhttprequestupload.rs +++ b/src/components/script/dom/xmlhttprequestupload.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::XMLHttpRequestUploadDerived; use dom::bindings::codegen::BindingDeclarations::XMLHttpRequestUploadBinding; -use dom::bindings::js::{Unrooted, JSRef}; +use dom::bindings::js::{Temporary, JSRef}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::eventtarget::{EventTarget, XMLHttpRequestTargetTypeId}; use dom::window::Window; @@ -22,7 +22,7 @@ impl XMLHttpRequestUpload { eventtarget:XMLHttpRequestEventTarget::new_inherited(XMLHttpRequestUploadTypeId) } } - pub fn new(window: &JSRef) -> Unrooted { + pub fn new(window: &JSRef) -> Temporary { reflect_dom_object(~XMLHttpRequestUpload::new_inherited(), window, XMLHttpRequestUploadBinding::Wrap) diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 9326ed6cb15..a0490c1621f 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -5,7 +5,7 @@ use dom::attr::AttrMethods; use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, TextCast, ElementCast}; use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalRootable, Root}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalRootable, Root}; use dom::bindings::utils::Reflectable; use dom::document::{Document, DocumentHelpers}; use dom::element::{AttributeHandlers, HTMLLinkElementTypeId, HTMLIFrameElementTypeId}; @@ -87,10 +87,10 @@ impl<'a, T: NodeBase+Reflectable> NodeWrapping for JSRef<'a, T> { } unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr, - roots: Option<&RootCollection>) -> Unrooted { + roots: Option<&RootCollection>) -> Temporary { let js = JS::from_raw(cast::transmute(n)); let _ = roots.map(|roots| roots.unroot_raw(js.reflector().get_jsobject())); - Unrooted::new(js) + Temporary::new(js) } /** @@ -165,7 +165,7 @@ fn js_script_listener(to_parent: Sender, // Silly macros to handle constructing DOM nodes. This produces bad code and should be optimized // via atomization (issue #85). -pub fn build_element_from_tag(tag: DOMString, document: &JSRef) -> Unrooted { +pub fn build_element_from_tag(tag: DOMString, document: &JSRef) -> Temporary { // TODO (Issue #85): use atoms handle_element!(document, tag, "a", HTMLAnchorElement); handle_element!(document, tag, "applet", HTMLAppletElement); diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index e319ef18837..c945f8c3451 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -8,7 +8,7 @@ use dom::attr::AttrMethods; use dom::bindings::codegen::RegisterBindings; use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, ElementCast, EventCast}; -use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalAssignable}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalAssignable}; use dom::bindings::js::OptionalRootable; use dom::bindings::trace::{Traceable, Untraceable}; use dom::bindings::utils::{Reflectable, GlobalStaticData, wrap_for_same_compartment}; @@ -407,7 +407,7 @@ impl Page { } } - fn find_fragment_node(&self, fragid: ~str) -> Option> { + fn find_fragment_node(&self, fragid: ~str) -> Option> { let roots = RootCollection::new(); let document = self.frame().get_ref().document.root(&roots); match document.deref().GetElementById(fragid.to_owned()) { @@ -421,7 +421,7 @@ impl Page { elem.get_attribute(Null, "name").root(&roots).map_or(false, |attr| { attr.get().value_ref() == fragid }) - }).map(|node| Unrooted::new_rooted(ElementCast::to_ref(&node).unwrap())) + }).map(|node| Temporary::new_rooted(ElementCast::to_ref(&node).unwrap())) } } } @@ -1050,7 +1050,7 @@ impl ScriptTask { None => {} } - frame.as_ref().map(|frame| Unrooted::new(frame.window.clone())) + frame.as_ref().map(|frame| Temporary::new(frame.window.clone())) }; match window.root(&roots) { From a09a4bd297d48c2702e1e15a901b1fdec32dda83 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 17 Apr 2014 20:28:01 -0400 Subject: [PATCH 10/16] Root Temporary values for the duration of their lifetime. --- src/components/script/dom/bindings/js.rs | 30 ++++++++++++++------- src/components/script/dom/bindings/utils.rs | 11 +++++--- src/components/script/dom/window.rs | 4 +-- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs index 031987181c2..9b61482e41a 100644 --- a/src/components/script/dom/bindings/js.rs +++ b/src/components/script/dom/bindings/js.rs @@ -2,20 +2,20 @@ * 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::utils::{Reflector, Reflectable}; +use dom::bindings::utils::{Reflector, Reflectable, cx_for_dom_object}; use dom::window::Window; -use js::jsapi::{JSObject, JSContext}; +use js::jsapi::{JSObject, JSContext, JS_AddObjectRoot, JS_RemoveObjectRoot}; use layout_interface::TrustedNodeAddress; use std::cast; use std::cell::RefCell; -/// A type that represents a JS-owned value that may or may not be rooted. -/// Importantly, it requires rooting in order to interact with the value in any way. +/// A type that represents a JS-owned value that is rooted for the lifetime of this value. +/// Importantly, it requires explicit rooting in order to interact with the inner value. /// Can be assigned into JS-owned member fields (ie. JS types) safely via the /// `JS::assign` method or `OptionalAssignable::assign` (for Option> fields). pub struct Temporary { - inner: JS + inner: JS, } impl Eq for Temporary { @@ -24,19 +24,31 @@ impl Eq for Temporary { } } +#[unsafe_destructor] +impl Drop for Temporary { + fn drop(&mut self) { + let cx = cx_for_dom_object(&self.inner); + unsafe { + JS_RemoveObjectRoot(cx, self.inner.reflector().rootable()); + } + } +} + impl Temporary { /// Create a new Temporary value from a JS-owned value. pub fn new(inner: JS) -> Temporary { + let cx = cx_for_dom_object(&inner); + unsafe { + JS_AddObjectRoot(cx, inner.reflector().rootable()); + } Temporary { - inner: inner + inner: inner, } } /// Create a new Temporary value from a rooted value. pub fn new_rooted<'a>(root: &JSRef<'a, T>) -> Temporary { - Temporary { - inner: root.unrooted() - } + Temporary::new(root.unrooted()) } /// Root this unrooted value. diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index cbccb90197a..96982ebb6e2 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -412,6 +412,10 @@ impl Reflector { self.object = object; } + pub fn rootable(&self) -> **JSObject { + &self.object as **JSObject + } + pub fn new() -> Reflector { Reflector { object: ptr::null(), @@ -616,14 +620,13 @@ pub extern fn outerize_global(_cx: *JSContext, obj: JSHandleObject) -> *JSObject } /// Returns the global object of the realm that the given JS object was created in. -pub fn global_object_for_js_object(obj: *JSObject) -> Temporary { +pub fn global_object_for_js_object(obj: *JSObject) -> JS { unsafe { let global = GetGlobalForObjectCrossCompartment(obj); let clasp = JS_GetClass(global); assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0); - Temporary::new( - FromJSValConvertible::from_jsval(ptr::null(), ObjectOrNullValue(global), ()) - .ok().expect("found DOM global that doesn't unwrap to Window")) + FromJSValConvertible::from_jsval(ptr::null(), ObjectOrNullValue(global), ()) + .ok().expect("found DOM global that doesn't unwrap to Window") } } diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index d3ef0769431..3908db73326 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -342,7 +342,7 @@ impl Window { script_chan: ScriptChan, compositor: ~ScriptListener, image_cache_task: ImageCacheTask) - -> Temporary { + -> JS { let win = ~Window { eventtarget: EventTarget::new_inherited(WindowTypeId), script_chan: script_chan, @@ -357,6 +357,6 @@ impl Window { browser_context: None, }; - Temporary::new(WindowBinding::Wrap(cx, win)) + WindowBinding::Wrap(cx, win) } } From aaf0a6119414072b34e3ef2109827eaf2f2a3156 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 17 Apr 2014 23:13:34 -0400 Subject: [PATCH 11/16] Store per-ScriptTask RootCollection in TLS and use that in favour of per-frame collections. --- src/components/script/dom/bindings/js.rs | 11 +++++++++-- src/components/script/script_task.rs | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs index 9b61482e41a..1efd25dc72c 100644 --- a/src/components/script/dom/bindings/js.rs +++ b/src/components/script/dom/bindings/js.rs @@ -6,9 +6,11 @@ use dom::bindings::utils::{Reflector, Reflectable, cx_for_dom_object}; use dom::window::Window; use js::jsapi::{JSObject, JSContext, JS_AddObjectRoot, JS_RemoveObjectRoot}; use layout_interface::TrustedNodeAddress; +use script_task::StackRoots; use std::cast; use std::cell::RefCell; +use std::local_data; /// A type that represents a JS-owned value that is rooted for the lifetime of this value. /// Importantly, it requires explicit rooting in order to interact with the inner value. @@ -52,8 +54,13 @@ impl Temporary { } /// Root this unrooted value. - pub fn root<'a, 'b>(self, collection: &'a RootCollection) -> Root<'a, 'b, T> { - collection.new_root(&self.inner) + pub fn root<'a, 'b>(self, _collection: &'a RootCollection) -> Root<'a, 'b, T> { + local_data::get(StackRoots, |opt| { + let collection = opt.unwrap(); + unsafe { + (**collection).new_root(&self.inner) + } + }) } unsafe fn inner(&self) -> JS { diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index c945f8c3451..2bfe058cc65 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -55,6 +55,7 @@ use servo_util::namespace::Null; use std::cast; use std::cell::{RefCell, Ref, RefMut}; use std::comm::{channel, Sender, Receiver, Empty, Disconnected, Data}; +use std::local_data; use std::mem::replace; use std::ptr; use std::rc::Rc; @@ -63,6 +64,8 @@ use url::Url; use serialize::{Encoder, Encodable}; +local_data_key!(pub StackRoots: *RootCollection) + /// Messages used to control the script task. pub enum ScriptMsg { /// Loads a new URL on the specified pipeline. @@ -510,6 +513,21 @@ pub struct JSPageInfo { pub js_context: Untraceable>, } +struct StackRootTLS; + +impl StackRootTLS { + fn new(roots: &RootCollection) -> StackRootTLS { + local_data::set(StackRoots, roots as *RootCollection); + StackRootTLS + } +} + +impl Drop for StackRootTLS { + fn drop(&mut self) { + let _ = local_data::pop(StackRoots); + } +} + /// Information for an entire page. Pages are top-level browsing contexts and can contain multiple /// frames. /// @@ -653,6 +671,9 @@ impl ScriptTask { /// Handle incoming control messages. fn handle_msgs(&self) -> bool { + let roots = RootCollection::new(); + let _stack_roots_tls = StackRootTLS::new(&roots); + // Handle pending resize events. // Gather them first to avoid a double mut borrow on self. let mut resizes = vec!(); From 7b3e6d1f2125faf598919722b72cc56197d0102c Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 17 Apr 2014 23:26:42 -0400 Subject: [PATCH 12/16] Remove all root collections. --- src/components/script/dom/attr.rs | 5 +- src/components/script/dom/attrlist.rs | 8 +- .../dom/bindings/codegen/CodegenRust.py | 38 ++- src/components/script/dom/bindings/js.rs | 29 ++- src/components/script/dom/bindings/utils.rs | 8 +- src/components/script/dom/blob.rs | 5 +- src/components/script/dom/browsercontext.rs | 8 +- src/components/script/dom/comment.rs | 5 +- src/components/script/dom/document.rs | 101 +++----- src/components/script/dom/documentfragment.rs | 8 +- .../script/dom/domimplementation.rs | 31 ++- src/components/script/dom/domparser.rs | 5 +- src/components/script/dom/element.rs | 85 +++---- src/components/script/dom/event.rs | 5 +- src/components/script/dom/eventdispatcher.rs | 5 +- .../script/dom/htmlbuttonelement.rs | 5 +- src/components/script/dom/htmlcollection.rs | 19 +- .../script/dom/htmldatalistelement.rs | 5 +- .../script/dom/htmlfieldsetelement.rs | 8 +- src/components/script/dom/htmlformelement.rs | 5 +- src/components/script/dom/htmlimageelement.rs | 10 +- src/components/script/dom/htmlmapelement.rs | 5 +- .../script/dom/htmlobjectelement.rs | 13 +- .../script/dom/htmloutputelement.rs | 5 +- .../script/dom/htmlselectelement.rs | 5 +- src/components/script/dom/htmlserializer.rs | 10 +- src/components/script/dom/htmlstyleelement.rs | 5 +- src/components/script/dom/mouseevent.rs | 9 +- src/components/script/dom/node.rs | 218 +++++++----------- src/components/script/dom/nodelist.rs | 8 +- src/components/script/dom/testbinding.rs | 8 +- src/components/script/dom/text.rs | 5 +- src/components/script/dom/uievent.rs | 7 +- .../script/html/hubbub_html_parser.rs | 47 ++-- src/components/script/script_task.rs | 61 ++--- 35 files changed, 329 insertions(+), 475 deletions(-) diff --git a/src/components/script/dom/attr.rs b/src/components/script/dom/attr.rs index fe4ea856cff..76bf3ff1ede 100644 --- a/src/components/script/dom/attr.rs +++ b/src/components/script/dom/attr.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::AttrBinding; use dom::bindings::codegen::InheritTypes::NodeCast; -use dom::bindings::js::{JS, JSRef, Temporary, RootCollection}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::element::Element; use dom::node::Node; @@ -65,8 +65,7 @@ impl Attr { } pub fn set_value(&mut self, set_type: AttrSettingType, value: DOMString) { - let roots = RootCollection::new(); - let owner = self.owner.root(&roots); + let owner = self.owner.root(); let node: &JSRef = NodeCast::from_ref(&*owner); let namespace_is_null = self.namespace == namespace::Null; diff --git a/src/components/script/dom/attrlist.rs b/src/components/script/dom/attrlist.rs index 7bc7f18bdfa..70db8f59971 100644 --- a/src/components/script/dom/attrlist.rs +++ b/src/components/script/dom/attrlist.rs @@ -4,7 +4,7 @@ use dom::attr::Attr; use dom::bindings::codegen::BindingDeclarations::AttrListBinding; -use dom::bindings::js::{JS, JSRef, Temporary, RootCollection}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::element::Element; use dom::window::Window; @@ -39,13 +39,11 @@ pub trait AttrListMethods { impl<'a> AttrListMethods for JSRef<'a, AttrList> { fn Length(&self) -> u32 { - let roots = RootCollection::new(); - self.owner.root(&roots).attrs.len() as u32 + self.owner.root().attrs.len() as u32 } fn Item(&self, index: u32) -> Option> { - let roots = RootCollection::new(); - self.owner.root(&roots).attrs.as_slice().get(index as uint).map(|x| Temporary::new(x.clone())) + self.owner.root().attrs.as_slice().get(index as uint).map(|x| Temporary::new(x.clone())) } fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index b7df283d2b8..8472686e536 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -903,10 +903,10 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements, if type and 'JS<' in type: if dealWithOptional or 'Option<' in type: rootBody = """let ${simpleDeclName} = ${declName}.as_ref().map(|inner| { - inner.root(&roots) //second root code + inner.root() //second root code });""" else: - rootBody = "let ${simpleDeclName} = ${declName}.root(&roots); //third root code" + rootBody = "let ${simpleDeclName} = ${declName}.root(); //third root code" result.append(CGGeneric(string.Template(rootBody).substitute(replacements))) result.append(CGGeneric("")) @@ -1799,7 +1799,7 @@ class CGAbstractMethod(CGThing): def _returnType(self): return (" -> %s" % self.returnType) if self.returnType != "void" else "" def _unsafe_open(self): - return "\n unsafe {\n let roots = RootCollection::new();\n" if self.unsafe else "" + return "\n unsafe {\n" if self.unsafe else "" def _unsafe_close(self): return "\n }\n" if self.unsafe else "" @@ -2247,7 +2247,7 @@ class CGCallGenerator(CGThing): self.cgRoot.append(CGGeneric("result = result_fallible.unwrap();")) if typeRetValNeedsRooting(returnType): - self.cgRoot.append(CGGeneric("let result = result.root(&roots);")) + self.cgRoot.append(CGGeneric("let result = result.root();")) def define(self): return self.cgRoot.define() @@ -2498,7 +2498,7 @@ class CGSpecializedMethod(CGAbstractExternMethod): self.descriptor, self.method), pre=extraPre + " let this = JS::from_raw(this);\n" + - " let mut this = this.root(&roots);\n").define() + " let mut this = this.root();\n").define() class CGGenericGetter(CGAbstractBindingMethod): """ @@ -2552,7 +2552,7 @@ class CGSpecializedGetter(CGAbstractExternMethod): self.descriptor, self.attr)), pre=extraPre + " let this = JS::from_raw(this);\n" + - " let mut this = this.root(&roots);\n").define() + " let mut this = this.root();\n").define() class CGGenericSetter(CGAbstractBindingMethod): """ @@ -2606,7 +2606,7 @@ class CGSpecializedSetter(CGAbstractExternMethod): self.descriptor, self.attr)), pre=extraPre + " let this = JS::from_raw(this);\n" + - " let mut this = this.root(&roots);\n").define() + " let mut this = this.root();\n").define() class CGMemberJITInfo(CGThing): @@ -3531,7 +3531,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): " let index = index.unwrap();\n" + " let this = UnwrapProxy(proxy);\n" + " let this = JS::from_raw(this);\n" + - " let mut this = this.root(&roots);\n" + + " let mut this = this.root();\n" + CGIndenter(CGProxyIndexedGetter(self.descriptor, templateValues)).define() + "\n" + "}\n") @@ -3578,7 +3578,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): " let name = Some(jsid_to_str(cx, id));\n" + " let this = UnwrapProxy(proxy);\n" + " let this = JS::from_raw(this);\n" + - " let mut this = this.root(&roots);\n" + + " let mut this = this.root();\n" + CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() + "\n" + "}\n") else: @@ -3623,7 +3623,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod): " let index = index.unwrap();\n" + " let this = UnwrapProxy(proxy);\n" + " let this = JS::from_raw(this);\n" + - " let mut this = this.root(&roots);\n" + + " let mut this = this.root();\n" + CGIndenter(CGProxyIndexedSetter(self.descriptor)).define() + " return 1;\n" + "}\n") @@ -3641,7 +3641,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod): " let name = Some(jsid_to_str(cx, id));\n" + " let this = UnwrapProxy(proxy);\n" + " let this = JS::from_raw(this);\n" + - " let mut this = this.root(&roots);\n" + + " let mut this = this.root();\n" + CGIndenter(CGProxyNamedSetter(self.descriptor)).define() + "\n" + "}\n") elif self.descriptor.operations['NamedGetter']: @@ -3649,7 +3649,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod): " let name = Some(jsid_to_str(cx, id));\n" + " let this = UnwrapProxy(proxy);\n" + " let this = JS::from_raw(this);\n" + - " let mut this = this.root(&roots);\n" + + " let mut this = this.root();\n" + CGIndenter(CGProxyNamedGetter(self.descriptor)).define() + " if (found) {\n" " return 0;\n" + @@ -3676,7 +3676,7 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod): " let index = index.unwrap();\n" + " let this = UnwrapProxy(proxy);\n" + " let this = JS::from_raw(this);\n" + - " let mut this = this.root(&roots);\n" + + " let mut this = this.root();\n" + CGIndenter(CGProxyIndexedGetter(self.descriptor)).define() + "\n" + " *bp = found as JSBool;\n" + " return 1;\n" + @@ -3690,7 +3690,7 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod): " let name = Some(jsid_to_str(cx, id));\n" + " let this = UnwrapProxy(proxy);\n" + " let this = JS::from_raw(this);\n" + - " let mut this = this.root(&roots);\n" + + " let mut this = this.root();\n" + CGIndenter(CGProxyNamedGetter(self.descriptor)).define() + "\n" + " *bp = found as JSBool;\n" " return 1;\n" @@ -3744,7 +3744,7 @@ if expando.is_not_null() { " let index = index.unwrap();\n" + " let this = UnwrapProxy(proxy);\n" + " let this = JS::from_raw(this);\n" + - " let mut this = this.root(&roots);\n" + + " let mut this = this.root();\n" + CGIndenter(CGProxyIndexedGetter(self.descriptor, templateValues)).define()) getIndexedOrExpando += """ // Even if we don't have this index, we don't forward the @@ -3762,7 +3762,7 @@ if expando.is_not_null() { " let name = Some(jsid_to_str(cx, id));\n" + " let this = UnwrapProxy(proxy);\n" + " let this = JS::from_raw(this);\n" + - " let mut this = this.root(&roots);\n" + + " let mut this = this.root();\n" + CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() + "}\n") % (self.descriptor.concreteType) else: @@ -3879,9 +3879,8 @@ class CGClassConstructHook(CGAbstractExternMethod): def generate_code(self): preamble = """ - let roots = RootCollection::new(); let global = global_object_for_js_object(JS_CALLEE(cx, &*vp).to_object()); - let global = global.root(&roots); + let global = global.root(); let obj = global.reflector().get_jsobject(); """ nativeName = MakeNativeName(self._ctor.identifier.name) @@ -4123,7 +4122,6 @@ class CGDictionary(CGThing): return string.Template( "impl ${selfName} {\n" " pub fn new(cx: *JSContext, val: JSVal) -> Result<${selfName}, ()> {\n" - " let roots = RootCollection::new();\n" # XXXjdm need to root dict members outside of Init " let object = if val.is_null_or_undefined() {\n" " ptr::null()\n" " } else if val.is_object() {\n" @@ -4323,7 +4321,7 @@ class CGBindingRoot(CGThing): 'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}', 'dom::types::*', 'dom::bindings', - 'dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Temporary, OptionalRootable}', + 'dom::bindings::js::{JS, JSRef, RootedReference, Temporary, OptionalRootable}', 'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}', 'dom::bindings::utils::{ConstantSpec, cx_for_dom_object, Default}', 'dom::bindings::utils::{dom_object_slot, DOM_OBJECT_SLOT, DOMClass}', diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs index 1efd25dc72c..1ee1b8da51d 100644 --- a/src/components/script/dom/bindings/js.rs +++ b/src/components/script/dom/bindings/js.rs @@ -54,7 +54,7 @@ impl Temporary { } /// Root this unrooted value. - pub fn root<'a, 'b>(self, _collection: &'a RootCollection) -> Root<'a, 'b, T> { + pub fn root<'a, 'b>(self) -> Root<'a, 'b, T> { local_data::get(StackRoots, |opt| { let collection = opt.unwrap(); unsafe { @@ -119,8 +119,13 @@ impl JS { } /// Root this JS-owned value to prevent its collection as garbage. - pub fn root<'a, 'b>(&self, collection: &'a RootCollection) -> Root<'a, 'b, T> { - collection.new_root(self) + pub fn root<'a, 'b>(&self) -> Root<'a, 'b, T> { + local_data::get(StackRoots, |opt| { + let collection = opt.unwrap(); + unsafe { + (**collection).new_root(self) + } + }) } } @@ -214,32 +219,32 @@ impl, U: Reflectable> OptionalAssignable for Option> { } pub trait OptionalRootable { - fn root<'a, 'b>(self, roots: &'a RootCollection) -> Option>; + fn root<'a, 'b>(self) -> Option>; } impl OptionalRootable for Option> { - fn root<'a, 'b>(self, roots: &'a RootCollection) -> Option> { - self.map(|inner| inner.root(roots)) + fn root<'a, 'b>(self) -> Option> { + self.map(|inner| inner.root()) } } pub trait OptionalRootedRootable { - fn root<'a, 'b>(&self, roots: &'a RootCollection) -> Option>; + fn root<'a, 'b>(&self) -> Option>; } impl OptionalRootedRootable for Option> { - fn root<'a, 'b>(&self, roots: &'a RootCollection) -> Option> { - self.as_ref().map(|inner| inner.root(roots)) + fn root<'a, 'b>(&self) -> Option> { + self.as_ref().map(|inner| inner.root()) } } pub trait ResultRootable { - fn root<'a, 'b>(self, roots: &'a RootCollection) -> Result, U>; + fn root<'a, 'b>(self) -> Result, U>; } impl ResultRootable for Result, U> { - fn root<'a, 'b>(self, roots: &'a RootCollection) -> Result, U> { - self.map(|inner| inner.root(roots)) + fn root<'a, 'b>(self) -> Result, U> { + self.map(|inner| inner.root()) } } diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index 96982ebb6e2..7c74a8b8085 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -5,7 +5,7 @@ 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, RootCollection, Temporary, Root}; +use dom::bindings::js::{JS, JSRef, Temporary, Root}; use dom::bindings::trace::Untraceable; use dom::browsercontext; use dom::window; @@ -606,7 +606,6 @@ pub extern fn wrap_for_same_compartment(cx: *JSContext, obj: *JSObject) -> *JSOb pub extern fn outerize_global(_cx: *JSContext, obj: JSHandleObject) -> *JSObject { unsafe { - let roots = RootCollection::new(); debug!("outerizing"); let obj = *obj.unnamed; let win: Root = @@ -614,7 +613,7 @@ pub extern fn outerize_global(_cx: *JSContext, obj: JSHandleObject) -> *JSObject IDLInterface::get_prototype_id(None::), IDLInterface::get_prototype_depth(None::)) .unwrap() - .root(&roots); + .root(); win.deref().browser_context.get_ref().window_proxy() } } @@ -631,8 +630,7 @@ pub fn global_object_for_js_object(obj: *JSObject) -> JS { } fn cx_for_dom_reflector(obj: *JSObject) -> *JSContext { - let roots = RootCollection::new(); - let win = global_object_for_js_object(obj).root(&roots); + let win = global_object_for_js_object(obj).root(); let js_info = win.get().page().js_info(); match *js_info { Some(ref info) => info.js_context.deref().deref().ptr, diff --git a/src/components/script/dom/blob.rs b/src/components/script/dom/blob.rs index 10cc93ef089..9df9287bc9f 100644 --- a/src/components/script/dom/blob.rs +++ b/src/components/script/dom/blob.rs @@ -2,7 +2,7 @@ * 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, RootCollection, Temporary}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::Fallible; use dom::bindings::codegen::BindingDeclarations::BlobBinding; @@ -51,8 +51,7 @@ impl<'a> BlobMethods for JSRef<'a, Blob> { } fn Slice(&self, _start: Option, _end: Option, _contentType: Option) -> Temporary { - let roots = RootCollection::new(); - let window = self.window.root(&roots); + let window = self.window.root(); Blob::new(&window.root_ref()) } diff --git a/src/components/script/dom/browsercontext.rs b/src/components/script/dom/browsercontext.rs index 5b0be5ccf0c..fea7dc9a8a7 100644 --- a/src/components/script/dom/browsercontext.rs +++ b/src/components/script/dom/browsercontext.rs @@ -2,7 +2,7 @@ * 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, RootCollection}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::trace::Traceable; use dom::bindings::utils::Reflectable; use dom::document::Document; @@ -37,8 +37,7 @@ impl BrowserContext { } pub fn active_window(&self) -> Temporary { - let roots = RootCollection::new(); - let doc = self.active_document().root(&roots); + let doc = self.active_document().root(); Temporary::new(doc.deref().window.clone()) } @@ -48,8 +47,7 @@ impl BrowserContext { } pub fn create_window_proxy(&self) -> *JSObject { - let roots = RootCollection::new(); - let win = self.active_window().root(&roots); + let win = self.active_window().root(); let page = win.get().page(); let js_info = page.js_info(); diff --git a/src/components/script/dom/comment.rs b/src/components/script/dom/comment.rs index 33bb395488c..5d2fce2d212 100644 --- a/src/components/script/dom/comment.rs +++ b/src/components/script/dom/comment.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::CommentDerived; use dom::bindings::codegen::BindingDeclarations::CommentBinding; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::Fallible; use dom::characterdata::CharacterData; use dom::document::Document; @@ -41,8 +41,7 @@ impl Comment { } pub fn Constructor(owner: &JSRef, data: DOMString) -> Fallible> { - let roots = RootCollection::new(); - let document = owner.Document().root(&roots); + let document = owner.Document().root(); Ok(Comment::new(data, &*document)) } } diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index 09a2a2c2ffa..6ba18526127 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::InheritTypes::{DocumentDerived, EventCast, HTMLEleme use dom::bindings::codegen::InheritTypes::{HTMLHeadElementCast, TextCast, ElementCast}; use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, HTMLHtmlElementCast, NodeCast}; use dom::bindings::codegen::BindingDeclarations::DocumentBinding; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalAssignable}; +use dom::bindings::js::{JS, JSRef, Temporary, OptionalAssignable}; use dom::bindings::js::OptionalRootable; use dom::bindings::trace::Untraceable; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; @@ -110,13 +110,11 @@ impl<'a> DocumentHelpers for JSRef<'a, Document> { } fn damage_and_reflow(&self, damage: DocumentDamageLevel) { - let roots = RootCollection::new(); - self.window.root(&roots).damage_and_reflow(damage); + self.window.root().damage_and_reflow(damage); } fn wait_until_safe_to_modify_dom(&self) { - let roots = RootCollection::new(); - self.window.root(&roots).wait_until_safe_to_modify_dom(); + self.window.root().wait_until_safe_to_modify_dom(); } @@ -124,13 +122,12 @@ impl<'a> DocumentHelpers for JSRef<'a, Document> { fn unregister_named_element(&mut self, to_unregister: &JSRef, id: DOMString) { - let roots = RootCollection::new(); let mut is_empty = false; match self.idmap.find_mut(&id) { None => {}, Some(elements) => { let position = elements.iter() - .map(|elem| elem.root(&roots)) + .map(|elem| elem.root()) .position(|element| &*element == to_unregister) .expect("This element should be in registered."); elements.remove(position); @@ -146,7 +143,6 @@ impl<'a> DocumentHelpers for JSRef<'a, Document> { fn register_named_element(&mut self, element: &JSRef, id: DOMString) { - let roots = RootCollection::new(); assert!({ let node: &JSRef = NodeCast::from_ref(element); node.is_in_doc() @@ -154,13 +150,13 @@ impl<'a> DocumentHelpers for JSRef<'a, Document> { // FIXME https://github.com/mozilla/rust/issues/13195 // Use mangle() when it exists again. - let root = self.GetDocumentElement().expect("The element is in the document, so there must be a document element.").root(&roots); + let root = self.GetDocumentElement().expect("The element is in the document, so there must be a document element.").root(); match self.idmap.find_mut(&id) { Some(elements) => { let new_node: &JSRef = NodeCast::from_ref(element); let mut head : uint = 0u; let root: &JSRef = NodeCast::from_ref(&*root); - for node in root.traverse_preorder(&roots) { + for node in root.traverse_preorder() { let elem: Option<&JSRef> = ElementCast::to_ref(&node); match elem { Some(elem) => { @@ -188,9 +184,8 @@ impl Document { window: &JSRef, wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~Document) -> JS) -> Temporary { - let roots = RootCollection::new(); assert!(document.reflector().get_jsobject().is_null()); - let mut raw_doc = reflect_dom_object(document, window, wrap_fn).root(&roots); + let mut raw_doc = reflect_dom_object(document, window, wrap_fn).root(); assert!(raw_doc.reflector().get_jsobject().is_not_null()); let mut doc_alias = raw_doc.clone(); @@ -257,15 +252,14 @@ trait PrivateDocumentHelpers { impl<'a> PrivateDocumentHelpers for JSRef<'a, Document> { fn createNodeList(&self, callback: |node: &JSRef| -> bool) -> Temporary { - let roots = RootCollection::new(); - let window = self.window.root(&roots); + let window = self.window.root(); let mut nodes = vec!(); - match self.GetDocumentElement().root(&roots) { + match self.GetDocumentElement().root() { None => {}, Some(root) => { let root: &JSRef = NodeCast::from_ref(&*root); - for child in root.traverse_preorder(&roots) { + for child in root.traverse_preorder() { if callback(&child) { nodes.push(child); } @@ -277,8 +271,7 @@ impl<'a> PrivateDocumentHelpers for JSRef<'a, Document> { } fn get_html_element(&self) -> Option> { - let roots = RootCollection::new(); - self.GetDocumentElement().root(&roots).filtered(|root| { + self.GetDocumentElement().root().filtered(|root| { root.node.type_id == ElementNodeTypeId(HTMLHtmlElementTypeId) }).map(|elem| { Temporary::new_rooted(HTMLHtmlElementCast::to_ref(&*elem).unwrap()) @@ -330,8 +323,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://dom.spec.whatwg.org/#dom-document-implementation fn Implementation(&mut self) -> Temporary { if self.implementation.is_none() { - let roots = RootCollection::new(); - let window = self.window.root(&roots); + let window = self.window.root(); self.implementation.assign(Some(DOMImplementation::new(&*window))); } Temporary::new(self.implementation.get_ref().clone()) @@ -384,15 +376,13 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://dom.spec.whatwg.org/#dom-document-getelementsbytagname fn GetElementsByTagName(&self, tag_name: DOMString) -> Temporary { - let roots = RootCollection::new(); - let window = self.window.root(&roots); + let window = self.window.root(); HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(self), tag_name) } // http://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens fn GetElementsByTagNameNS(&self, maybe_ns: Option, tag_name: DOMString) -> Temporary { - let roots = RootCollection::new(); - let window = self.window.root(&roots); + let window = self.window.root(); let namespace = match maybe_ns { Some(namespace) => Namespace::from_str(namespace), @@ -403,8 +393,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://dom.spec.whatwg.org/#dom-document-getelementsbyclassname fn GetElementsByClassName(&self, classes: DOMString) -> Temporary { - let roots = RootCollection::new(); - let window = self.window.root(&roots); + let window = self.window.root(); HTMLCollection::by_class_name(&*window, NodeCast::from_ref(self), classes) } @@ -538,8 +527,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://dom.spec.whatwg.org/#dom-document-createevent fn CreateEvent(&self, interface: DOMString) -> Fallible> { - let roots = RootCollection::new(); - let window = self.window.root(&roots); + let window = self.window.root(); match interface.to_ascii_lower().as_slice() { // FIXME: Implement CustomEvent (http://dom.spec.whatwg.org/#customevent) @@ -553,10 +541,9 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://www.whatwg.org/specs/web-apps/current-work/#document.title fn Title(&self) -> DOMString { let mut title = ~""; - let roots = RootCollection::new(); - self.GetDocumentElement().root(&roots).map(|root| { + self.GetDocumentElement().root().map(|root| { let root: &JSRef = NodeCast::from_ref(&*root); - root.traverse_preorder(&roots) + root.traverse_preorder() .find(|node| node.type_id() == ElementNodeTypeId(HTMLTitleElementTypeId)) .map(|title_elem| { for child in title_elem.children() { @@ -574,11 +561,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://www.whatwg.org/specs/web-apps/current-work/#document.title fn SetTitle(&self, title: DOMString) -> ErrorResult { - let roots = RootCollection::new(); - self.GetDocumentElement().root(&roots).map(|root| { + self.GetDocumentElement().root().map(|root| { let root: &JSRef = NodeCast::from_ref(&*root); - let mut head_node = root.traverse_preorder(&roots).find(|child| { + let mut head_node = root.traverse_preorder().find(|child| { child.get().type_id == ElementNodeTypeId(HTMLHeadElementTypeId) }); head_node.as_mut().map(|head| { @@ -591,15 +577,15 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { for mut title_child in title_node.children() { assert!(title_node.RemoveChild(&mut title_child).is_ok()); } - let mut new_text = self.CreateTextNode(title.clone()).root(&roots); + let mut new_text = self.CreateTextNode(title.clone()).root(); assert!(title_node.AppendChild(NodeCast::from_mut_ref(&mut *new_text)).is_ok()); }, None => { - let mut new_title = HTMLTitleElement::new(~"title", self).root(&roots); + let mut new_title = HTMLTitleElement::new(~"title", self).root(); let new_title: &mut JSRef = NodeCast::from_mut_ref(&mut *new_title); - let mut new_text = self.CreateTextNode(title.clone()).root(&roots); + let mut new_text = self.CreateTextNode(title.clone()).root(); assert!(new_title.AppendChild(NodeCast::from_mut_ref(&mut *new_text)).is_ok()); assert!(head.AppendChild(&mut *new_title).is_ok()); @@ -612,9 +598,8 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-head fn GetHead(&self) -> Option> { - let roots = RootCollection::new(); self.get_html_element().and_then(|root| { - let root = root.root(&roots); + let root = root.root(); let node: &JSRef = NodeCast::from_ref(&*root); node.children().find(|child| { child.type_id() == ElementNodeTypeId(HTMLHeadElementTypeId) @@ -626,9 +611,8 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body fn GetBody(&self) -> Option> { - let roots = RootCollection::new(); self.get_html_element().and_then(|root| { - let root = root.root(&roots); + let root = root.root(); let node: &JSRef = NodeCast::from_ref(&*root); node.children().find(|child| { match child.type_id() { @@ -644,7 +628,6 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body fn SetBody(&self, new_body: Option>) -> ErrorResult { - let roots = RootCollection::new(); // Step 1. match new_body { @@ -659,14 +642,14 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // Step 2. - let mut old_body = self.GetBody().root(&roots); + let mut old_body = self.GetBody().root(); //FIXME: covariant lifetime workaround. do not judge. if old_body.as_ref().map(|body| body.deref()) == new_body.as_ref().map(|a| &*a) { return Ok(()); } // Step 3. - match self.get_html_element().root(&roots) { + match self.get_html_element().root() { // Step 4. None => return Err(HierarchyRequest), Some(ref mut root) => { @@ -689,7 +672,6 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-getelementsbyname fn GetElementsByName(&self, name: DOMString) -> Temporary { - let roots = RootCollection::new(); self.createNodeList(|node| { if !node.is_element() { @@ -697,15 +679,14 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } let element: &JSRef = ElementCast::to_ref(node).unwrap(); - element.get_attribute(Null, "name").root(&roots).map_or(false, |mut attr| { + element.get_attribute(Null, "name").root().map_or(false, |mut attr| { attr.value_ref() == name }) }) } fn Images(&self) -> Temporary { - let roots = RootCollection::new(); - let window = self.window.root(&roots); + let window = self.window.root(); // FIXME: https://github.com/mozilla/servo/issues/1847 struct ImagesFilter; @@ -719,8 +700,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } fn Embeds(&self) -> Temporary { - let roots = RootCollection::new(); - let window = self.window.root(&roots); + let window = self.window.root(); // FIXME: https://github.com/mozilla/servo/issues/1847 struct EmbedsFilter; @@ -739,8 +719,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } fn Links(&self) -> Temporary { - let roots = RootCollection::new(); - let window = self.window.root(&roots); + let window = self.window.root(); // FIXME: https://github.com/mozilla/servo/issues/1847 struct LinksFilter; @@ -755,8 +734,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } fn Forms(&self) -> Temporary { - let roots = RootCollection::new(); - let window = self.window.root(&roots); + let window = self.window.root(); // FIXME: https://github.com/mozilla/servo/issues/1847 struct FormsFilter; @@ -770,8 +748,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } fn Scripts(&self) -> Temporary { - let roots = RootCollection::new(); - let window = self.window.root(&roots); + let window = self.window.root(); // FIXME: https://github.com/mozilla/servo/issues/1847 struct ScriptsFilter; @@ -785,8 +762,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } fn Anchors(&self) -> Temporary { - let roots = RootCollection::new(); - let window = self.window.root(&roots); + let window = self.window.root(); // FIXME: https://github.com/mozilla/servo/issues/1847 struct AnchorsFilter; @@ -800,8 +776,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } fn Applets(&self) -> Temporary { - let roots = RootCollection::new(); - let window = self.window.root(&roots); + let window = self.window.root(); // FIXME: This should be return OBJECT elements containing applets. struct AppletsFilter; @@ -815,14 +790,12 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } fn Location(&mut self) -> Temporary { - let roots = RootCollection::new(); - let mut window = self.window.root(&roots); + let mut window = self.window.root(); window.Location() } fn Children(&self) -> Temporary { - let roots = RootCollection::new(); - let window = self.window.root(&roots); + let window = self.window.root(); HTMLCollection::children(&*window, NodeCast::from_ref(self)) } } diff --git a/src/components/script/dom/documentfragment.rs b/src/components/script/dom/documentfragment.rs index 1dfd92c6f66..b6287696300 100644 --- a/src/components/script/dom/documentfragment.rs +++ b/src/components/script/dom/documentfragment.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::{DocumentFragmentDerived, NodeCast}; use dom::bindings::codegen::BindingDeclarations::DocumentFragmentBinding; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::Fallible; use dom::document::Document; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -40,9 +40,8 @@ impl DocumentFragment { } pub fn Constructor(owner: &JSRef) -> Fallible> { - let roots = RootCollection::new(); let document = owner.Document(); - let document = document.root(&roots); + let document = document.root(); Ok(DocumentFragment::new(&document.root_ref())) } @@ -54,8 +53,7 @@ pub trait DocumentFragmentMethods { impl<'a> DocumentFragmentMethods for JSRef<'a, DocumentFragment> { fn Children(&self) -> Temporary { - let roots = RootCollection::new(); - let window = window_from_node(self).root(&roots); + let window = window_from_node(self).root(); HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(self)) } } diff --git a/src/components/script/dom/domimplementation.rs b/src/components/script/dom/domimplementation.rs index 4346e6044c4..231c1e4ac99 100644 --- a/src/components/script/dom/domimplementation.rs +++ b/src/components/script/dom/domimplementation.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::DOMImplementationBinding; use dom::bindings::codegen::InheritTypes::NodeCast; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalRootable}; +use dom::bindings::js::{JS, JSRef, 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}; @@ -60,7 +60,6 @@ pub trait DOMImplementationMethods { impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { // http://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype fn CreateDocumentType(&self, qname: DOMString, pubid: DOMString, sysid: DOMString) -> Fallible> { - let roots = RootCollection::new(); match xml_name_type(qname) { // Step 1. InvalidXMLName => Err(InvalidCharacter), @@ -68,8 +67,8 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { Name => Err(NamespaceError), // Step 3. QName => { - let owner = self.owner.root(&roots); - let document = owner.deref().Document().root(&roots); + let owner = self.owner.root(); + let document = owner.deref().Document().root(); Ok(DocumentType::new(qname, Some(pubid), Some(sysid), &*document)) } } @@ -78,11 +77,10 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { // http://dom.spec.whatwg.org/#dom-domimplementation-createdocument fn CreateDocument(&self, namespace: Option, qname: DOMString, mut maybe_doctype: Option>) -> Fallible> { - let roots = RootCollection::new(); - let win = self.owner.root(&roots); + let win = self.owner.root(); // Step 1. - let mut doc = Document::new(&win.root_ref(), None, NonHTMLDocument, None).root(&roots); + let mut doc = Document::new(&win.root_ref(), None, NonHTMLDocument, None).root(); // Step 2-3. let mut maybe_elem = if qname.is_empty() { None @@ -105,7 +103,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { } // Step 5. - match maybe_elem.root(&roots) { + match maybe_elem.root() { None => (), Some(mut elem) => { assert!(doc_node.AppendChild(NodeCast::from_mut_ref(&mut *elem)).is_ok()) @@ -122,28 +120,27 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { // http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument fn CreateHTMLDocument(&self, title: Option) -> Temporary { - let roots = RootCollection::new(); - let owner = self.owner.root(&roots); + let owner = self.owner.root(); // Step 1-2. - let mut doc = Document::new(&owner.root_ref(), None, HTMLDocument, None).root(&roots); + let mut doc = Document::new(&owner.root_ref(), None, HTMLDocument, None).root(); let mut doc_alias = doc.clone(); let doc_node: &mut JSRef = NodeCast::from_mut_ref(&mut doc_alias); { // Step 3. - let mut doc_type = DocumentType::new(~"html", None, None, &*doc).root(&roots); + let mut doc_type = DocumentType::new(~"html", None, None, &*doc).root(); assert!(doc_node.AppendChild(NodeCast::from_mut_ref(&mut *doc_type)).is_ok()); } { // Step 4. - let mut doc_html = NodeCast::from_unrooted(HTMLHtmlElement::new(~"html", &*doc)).root(&roots); + let mut doc_html = NodeCast::from_unrooted(HTMLHtmlElement::new(~"html", &*doc)).root(); assert!(doc_node.AppendChild(&mut *doc_html).is_ok()); { // Step 5. - let mut doc_head = NodeCast::from_unrooted(HTMLHeadElement::new(~"head", &*doc)).root(&roots); + let mut doc_head = NodeCast::from_unrooted(HTMLHeadElement::new(~"head", &*doc)).root(); assert!(doc_html.AppendChild(&mut *doc_head).is_ok()); // Step 6. @@ -151,18 +148,18 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { None => (), Some(title_str) => { // Step 6.1. - let mut doc_title = NodeCast::from_unrooted(HTMLTitleElement::new(~"title", &*doc)).root(&roots); + let mut doc_title = NodeCast::from_unrooted(HTMLTitleElement::new(~"title", &*doc)).root(); assert!(doc_head.AppendChild(&mut *doc_title).is_ok()); // Step 6.2. - let mut title_text = Text::new(title_str, &*doc).root(&roots); + let mut title_text = Text::new(title_str, &*doc).root(); assert!(doc_title.AppendChild(NodeCast::from_mut_ref(&mut *title_text)).is_ok()); } } } // Step 7. - let mut doc_body = HTMLBodyElement::new(~"body", &*doc).root(&roots); + let mut doc_body = HTMLBodyElement::new(~"body", &*doc).root(); assert!(doc_html.AppendChild(NodeCast::from_mut_ref(&mut *doc_body)).is_ok()); } diff --git a/src/components/script/dom/domparser.rs b/src/components/script/dom/domparser.rs index 3dc95f57d27..41424d24c0d 100644 --- a/src/components/script/dom/domparser.rs +++ b/src/components/script/dom/domparser.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::DOMParserBinding; use dom::bindings::codegen::BindingDeclarations::DOMParserBinding::SupportedTypeValues::{Text_html, Text_xml}; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; +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}; @@ -44,8 +44,7 @@ impl<'a> DOMParserMethods for JSRef<'a, DOMParser> { _s: DOMString, ty: DOMParserBinding::SupportedType) -> Fallible> { - let roots = RootCollection::new(); - let owner = self.owner.root(&roots); + let owner = self.owner.root(); match ty { Text_html => { Ok(Document::new(&owner.root_ref(), None, HTMLDocument, Some(~"text/html"))) diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index fdf9db3e5b0..f316b1765f6 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -8,7 +8,7 @@ use dom::attr::{Attr, ReplacedAttr, FirstSetAttr, AttrMethods}; use dom::attrlist::AttrList; use dom::bindings::codegen::BindingDeclarations::ElementBinding; use dom::bindings::codegen::InheritTypes::{ElementDerived, NodeCast}; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, TemporaryPushable}; +use dom::bindings::js::{JS, JSRef, Temporary, TemporaryPushable}; use dom::bindings::js::{OptionalAssignable, OptionalRootable, Root}; use dom::bindings::utils::{Reflectable, Reflector}; use dom::bindings::error::{ErrorResult, Fallible, NamespaceError, InvalidCharacter}; @@ -198,10 +198,9 @@ pub trait ElementHelpers { impl<'a> ElementHelpers for JSRef<'a, Element> { fn html_element_in_html_document(&self) -> bool { - let roots = RootCollection::new(); let is_html = self.namespace == namespace::HTML; let node: &JSRef = NodeCast::from_ref(self); - is_html && node.owner_doc().root(&roots).is_html_document + is_html && node.owner_doc().root().is_html_document } } @@ -228,13 +227,12 @@ pub trait AttributeHandlers { impl<'a> AttributeHandlers for JSRef<'a, Element> { fn get_attribute(&self, namespace: Namespace, name: &str) -> Option> { - let roots = RootCollection::new(); if self.html_element_in_html_document() { - self.get().attrs.iter().map(|attr| attr.root(&roots)).find(|attr| { + self.get().attrs.iter().map(|attr| attr.root()).find(|attr| { name.to_ascii_lower() == attr.local_name && attr.namespace == namespace }).map(|x| Temporary::new_rooted(&*x)) } else { - self.get().attrs.iter().map(|attr| attr.root(&roots)).find(|attr| { + self.get().attrs.iter().map(|attr| attr.root()).find(|attr| { name == attr.local_name && attr.namespace == namespace }).map(|x| Temporary::new_rooted(&*x)) } @@ -275,14 +273,13 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString, name: DOMString, namespace: Namespace, prefix: Option, cb: |&JSRef| -> bool) { - let roots = RootCollection::new(); let idx = self.get().attrs.iter() - .map(|attr| attr.root(&roots)) + .map(|attr| attr.root()) .position(|attr| cb(&*attr)); let (idx, set_type) = match idx { Some(idx) => (idx, ReplacedAttr), None => { - let window = window_from_node(self).root(&roots); + let window = window_from_node(self).root(); let attr = Attr::new(&*window, local_name.clone(), value.clone(), name, namespace.clone(), prefix, self); self.get_mut().attrs.push_unrooted(attr); @@ -290,14 +287,13 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } }; - self.get_mut().attrs.get(idx).root(&roots).set_value(set_type, value); + self.get_mut().attrs.get(idx).root().set_value(set_type, value); } fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult { - let roots = RootCollection::new(); let (_, local_name) = get_attribute_parts(name.clone()); - let idx = self.get().attrs.iter().map(|attr| attr.root(&roots)).position(|attr| { + let idx = self.get().attrs.iter().map(|attr| attr.root()).position(|attr| { attr.local_name == local_name }); @@ -310,7 +306,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } if namespace == namespace::Null { - let removed_raw_value = self.get().attrs.get(idx).root(&roots).Value(); + let removed_raw_value = self.get().attrs.get(idx).root().Value(); vtable_for(NodeCast::from_ref(self)).before_remove_attr(local_name.clone(), removed_raw_value); } @@ -322,14 +318,13 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } fn notify_attribute_changed(&self, local_name: DOMString) { - let roots = RootCollection::new(); let node: &JSRef = NodeCast::from_ref(self); if node.is_in_doc() { let damage = match local_name.as_slice() { "style" | "id" | "class" => MatchSelectorsDocumentDamage, _ => ContentChangedDocumentDamage }; - let document = node.owner_doc().root(&roots); + let document = node.owner_doc().root(); document.deref().damage_and_reflow(damage); } } @@ -349,10 +344,9 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } fn get_string_attribute(&self, name: &str) -> DOMString { - let roots = RootCollection::new(); match self.get_attribute(Null, name) { Some(x) => { - let x = x.root(&roots); + let x = x.root(); x.deref().Value() } None => ~"" @@ -462,7 +456,6 @@ impl<'a> ElementMethods for JSRef<'a, Element> { // http://dom.spec.whatwg.org/#dom-element-attributes fn Attributes(&mut self) -> Temporary { - let roots = RootCollection::new(); match self.attr_list { None => (), Some(ref list) => return Temporary::new(list.clone()), @@ -470,9 +463,9 @@ impl<'a> ElementMethods for JSRef<'a, Element> { let doc = { let node: &JSRef = NodeCast::from_ref(self); - node.owner_doc() - }.root(&roots); - let window = doc.deref().window.root(&roots); + node.owner_doc().root() + }; + let window = doc.deref().window.root(); let list = AttrList::new(&*window, self); self.attr_list.assign(Some(list)); Temporary::new(self.attr_list.get_ref().clone()) @@ -480,13 +473,12 @@ impl<'a> ElementMethods for JSRef<'a, Element> { // http://dom.spec.whatwg.org/#dom-element-getattribute fn GetAttribute(&self, name: DOMString) -> Option { - let roots = RootCollection::new(); let name = if self.html_element_in_html_document() { name.to_ascii_lower() } else { name }; - self.get_attribute(Null, name).root(&roots) + self.get_attribute(Null, name).root() .map(|s| s.deref().Value()) } @@ -494,9 +486,8 @@ impl<'a> ElementMethods for JSRef<'a, Element> { fn GetAttributeNS(&self, namespace: Option, local_name: DOMString) -> Option { - let roots = RootCollection::new(); let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace)); - self.get_attribute(namespace, local_name).root(&roots) + self.get_attribute(namespace, local_name).root() .map(|attr| attr.deref().Value()) } @@ -624,32 +615,28 @@ impl<'a> ElementMethods for JSRef<'a, Element> { } fn GetElementsByTagName(&self, localname: DOMString) -> Temporary { - let roots = RootCollection::new(); - let window = window_from_node(self).root(&roots); + let window = window_from_node(self).root(); HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(self), localname) } fn GetElementsByTagNameNS(&self, maybe_ns: Option, localname: DOMString) -> Temporary { - let roots = RootCollection::new(); let namespace = match maybe_ns { Some(namespace) => Namespace::from_str(namespace), None => Null }; - let window = window_from_node(self).root(&roots); + let window = window_from_node(self).root(); HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(self), localname, namespace) } fn GetElementsByClassName(&self, classes: DOMString) -> Temporary { - let roots = RootCollection::new(); - let window = window_from_node(self).root(&roots); + let window = window_from_node(self).root(); HTMLCollection::by_class_name(&*window, NodeCast::from_ref(self), classes) } // http://dev.w3.org/csswg/cssom-view/#dom-element-getclientrects fn GetClientRects(&self) -> Temporary { - let roots = RootCollection::new(); - let win = window_from_node(self).root(&roots); + let win = window_from_node(self).root(); let node: &JSRef = NodeCast::from_ref(self); let rects = node.get_content_boxes(); let rects: ~[Root] = rects.iter().map(|r| { @@ -658,7 +645,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { r.origin.y, r.origin.y + r.size.height, r.origin.x, - r.origin.x + r.size.width).root(&roots) + r.origin.x + r.size.width).root() }).collect(); ClientRectList::new(&*win, rects.iter().map(|rect| rect.deref().clone()).collect()) @@ -666,8 +653,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { // http://dev.w3.org/csswg/cssom-view/#dom-element-getboundingclientrect fn GetBoundingClientRect(&self) -> Temporary { - let roots = RootCollection::new(); - let win = window_from_node(self).root(&roots); + let win = window_from_node(self).root(); let node: &JSRef = NodeCast::from_ref(self); let rect = node.get_bounding_content_box(); ClientRect::new( @@ -680,18 +666,15 @@ impl<'a> ElementMethods for JSRef<'a, Element> { fn GetInnerHTML(&self) -> Fallible { //XXX TODO: XML case - let roots = RootCollection::new(); - Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(self), false, false))) + Ok(serialize(&mut NodeIterator::new(NodeCast::from_ref(self), false, false))) } fn GetOuterHTML(&self) -> Fallible { - let roots = RootCollection::new(); - Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(self), true, false))) + Ok(serialize(&mut NodeIterator::new(NodeCast::from_ref(self), true, false))) } fn Children(&self) -> Temporary { - let roots = RootCollection::new(); - let window = window_from_node(self).root(&roots); + let window = window_from_node(self).root(); HTMLCollection::children(&*window, NodeCast::from_ref(self)) } } @@ -716,7 +699,6 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { } fn after_set_attr(&mut self, name: DOMString, value: DOMString) { - let roots = RootCollection::new(); match self.super_type() { Some(ref mut s) => s.after_set_attr(name.clone(), value.clone()), _ => (), @@ -724,14 +706,14 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { match name.as_slice() { "style" => { - let doc = document_from_node(self).root(&roots); + let doc = document_from_node(self).root(); let base_url = doc.deref().url().clone(); self.get_mut().style_attribute = Some(style::parse_style_attribute(value, &base_url)) } "id" => { let node: &JSRef = NodeCast::from_ref(self); if node.is_in_doc() { - let mut doc = document_from_node(self).root(&roots); + let mut doc = document_from_node(self).root(); doc.register_named_element(self, value.clone()); } } @@ -742,7 +724,6 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { } fn before_remove_attr(&mut self, name: DOMString, value: DOMString) { - let roots = RootCollection::new(); match self.super_type() { Some(ref mut s) => s.before_remove_attr(name.clone(), value.clone()), _ => (), @@ -755,7 +736,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { "id" => { let node: &JSRef = NodeCast::from_ref(self); if node.is_in_doc() { - let mut doc = document_from_node(self).root(&roots); + let mut doc = document_from_node(self).root(); doc.unregister_named_element(self, value); } } @@ -766,15 +747,14 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { } fn bind_to_tree(&mut self) { - let roots = RootCollection::new(); match self.super_type() { Some(ref mut s) => s.bind_to_tree(), _ => (), } - match self.get_attribute(Null, "id").root(&roots) { + match self.get_attribute(Null, "id").root() { Some(attr) => { - let mut doc = document_from_node(self).root(&roots); + let mut doc = document_from_node(self).root(); doc.register_named_element(self, attr.deref().Value()); } _ => () @@ -782,15 +762,14 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { } fn unbind_from_tree(&mut self) { - let roots = RootCollection::new(); match self.super_type() { Some(ref mut s) => s.unbind_from_tree(), _ => (), } - match self.get_attribute(Null, "id").root(&roots) { + match self.get_attribute(Null, "id").root() { Some(attr) => { - let mut doc = document_from_node(self).root(&roots); + let mut doc = document_from_node(self).root(); doc.unregister_named_element(self, attr.deref().Value()); } _ => () diff --git a/src/components/script/dom/event.rs b/src/components/script/dom/event.rs index 3b3254c0f0c..9ce0cd4f981 100644 --- a/src/components/script/dom/event.rs +++ b/src/components/script/dom/event.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::EventBinding; use dom::bindings::codegen::BindingDeclarations::EventBinding::EventConstants; -use dom::bindings::js::{JS, JSRef, Temporary, RootCollection}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::Fallible; use dom::eventtarget::EventTarget; @@ -89,8 +89,7 @@ impl Event { pub fn Constructor(global: &JSRef, type_: DOMString, init: &EventBinding::EventInit) -> Fallible> { - let roots = RootCollection::new(); - let mut ev = Event::new(global).root(&roots); + let mut ev = Event::new(global).root(); ev.InitEvent(type_, init.bubbles, init.cancelable); Ok(Temporary::new_rooted(&*ev)) } diff --git a/src/components/script/dom/eventdispatcher.rs b/src/components/script/dom/eventdispatcher.rs index 1e0097bbdc4..b4e6b4644cf 100644 --- a/src/components/script/dom/eventdispatcher.rs +++ b/src/components/script/dom/eventdispatcher.rs @@ -4,7 +4,7 @@ use dom::bindings::callback::ReportExceptions; use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, NodeDerived}; -use dom::bindings::js::{JSRef, OptionalAssignable, RootCollection, Root}; +use dom::bindings::js::{JSRef, OptionalAssignable, Root}; use dom::eventtarget::{Capturing, Bubbling, EventTarget}; use dom::event::{Event, PhaseAtTarget, PhaseNone, PhaseBubbling, PhaseCapturing, EventMethods}; use dom::node::{Node, NodeHelpers}; @@ -13,7 +13,6 @@ use dom::node::{Node, NodeHelpers}; pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>, pseudo_target: Option>, event: &mut JSRef) -> bool { - let roots = RootCollection::new(); assert!(!event.get().dispatching); { @@ -32,7 +31,7 @@ pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>, let target_node: &JSRef = NodeCast::to_ref(target).unwrap(); target_node.ancestors().map(|ancestor| { let ancestor_target: &JSRef = EventTargetCast::from_ref(&ancestor); - ancestor_target.unrooted().root(&roots) + ancestor_target.unrooted().root() }).collect() } else { vec!() diff --git a/src/components/script/dom/htmlbuttonelement.rs b/src/components/script/dom/htmlbuttonelement.rs index 7458c7df50b..1474c9cb563 100644 --- a/src/components/script/dom/htmlbuttonelement.rs +++ b/src/components/script/dom/htmlbuttonelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLButtonElementBinding; use dom::bindings::codegen::InheritTypes::HTMLButtonElementDerived; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLButtonElementTypeId; @@ -167,8 +167,7 @@ impl<'a> HTMLButtonElementMethods for JSRef<'a, HTMLButtonElement> { } fn Validity(&self) -> Temporary { - let roots = RootCollection::new(); - let window = window_from_node(self).root(&roots); + let window = window_from_node(self).root(); ValidityState::new(&*window) } diff --git a/src/components/script/dom/htmlcollection.rs b/src/components/script/dom/htmlcollection.rs index 3be0a84a2a2..0047247ffad 100644 --- a/src/components/script/dom/htmlcollection.rs +++ b/src/components/script/dom/htmlcollection.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast}; use dom::bindings::codegen::BindingDeclarations::HTMLCollectionBinding; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::element::{Element, AttributeHandlers}; use dom::node::{Node, NodeHelpers}; @@ -129,12 +129,11 @@ pub trait HTMLCollectionMethods { impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> { // http://dom.spec.whatwg.org/#dom-htmlcollection-length fn Length(&self) -> u32 { - let roots = RootCollection::new(); match self.collection { Static(ref elems) => elems.len() as u32, Live(ref root, ref filter) => { - let root = root.root(&roots); - root.deref().traverse_preorder(&roots) + let root = root.root(); + root.deref().traverse_preorder() .count(|child| { let elem: Option<&JSRef> = ElementCast::to_ref(&child); elem.map_or(false, |elem| filter.filter(elem, &*root)) @@ -145,15 +144,14 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> { // http://dom.spec.whatwg.org/#dom-htmlcollection-item fn Item(&self, index: u32) -> Option> { - let roots = RootCollection::new(); match self.collection { Static(ref elems) => elems .as_slice() .get(index as uint) .map(|elem| Temporary::new(elem.clone())), Live(ref root, ref filter) => { - let root = root.root(&roots); - root.deref().traverse_preorder(&roots) + let root = root.root(); + root.deref().traverse_preorder() .filter_map(|node| { let elem: Option<&JSRef> = ElementCast::to_ref(&node); elem.filtered(|&elem| filter.filter(elem, &*root)) @@ -168,7 +166,6 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> { // http://dom.spec.whatwg.org/#dom-htmlcollection-nameditem fn NamedItem(&self, key: DOMString) -> Option> { - let roots = RootCollection::new(); // Step 1. if key.is_empty() { @@ -178,14 +175,14 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> { // Step 2. match self.collection { Static(ref elems) => elems.iter() - .map(|elem| elem.root(&roots)) + .map(|elem| elem.root()) .find(|elem| { elem.get_string_attribute("name") == key || elem.get_string_attribute("id") == key }) .map(|maybe_elem| Temporary::new_rooted(&*maybe_elem)), Live(ref root, ref filter) => { - let root = root.root(&roots); - root.deref().traverse_preorder(&roots) + let root = root.root(); + root.deref().traverse_preorder() .filter_map(|node| { let elem: Option<&JSRef> = ElementCast::to_ref(&node); elem.filtered(|&elem| filter.filter(elem, &*root)) diff --git a/src/components/script/dom/htmldatalistelement.rs b/src/components/script/dom/htmldatalistelement.rs index 398920bdc61..caaad975c0e 100644 --- a/src/components/script/dom/htmldatalistelement.rs +++ b/src/components/script/dom/htmldatalistelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDataListElementBinding; use dom::bindings::codegen::InheritTypes::{HTMLDataListElementDerived, NodeCast}; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::document::Document; use dom::element::{Element, HTMLDataListElementTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -52,10 +52,9 @@ impl<'a> HTMLDataListElementMethods for JSRef<'a, HTMLDataListElement> { elem.get().local_name == ~"option" } } - let roots = RootCollection::new(); let node: &JSRef = NodeCast::from_ref(self); let filter = ~HTMLDataListOptionsFilter; - let window = window_from_node(node).root(&roots); + let window = window_from_node(node).root(); HTMLCollection::create(&*window, node, filter) } } diff --git a/src/components/script/dom/htmlfieldsetelement.rs b/src/components/script/dom/htmlfieldsetelement.rs index f3872235f27..0b32c0b916a 100644 --- a/src/components/script/dom/htmlfieldsetelement.rs +++ b/src/components/script/dom/htmlfieldsetelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFieldSetElementBinding; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLFieldSetElementDerived, NodeCast}; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLFieldSetElementTypeId}; @@ -94,10 +94,9 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> { elem != root && tag_names.iter().any(|&tag_name| tag_name == elem.get().local_name) } } - let roots = RootCollection::new(); let node: &JSRef = NodeCast::from_ref(self); let filter = ~ElementsFilter; - let window = window_from_node(node).root(&roots); + let window = window_from_node(node).root(); HTMLCollection::create(&*window, node, filter) } @@ -106,8 +105,7 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> { } fn Validity(&self) -> Temporary { - let roots = RootCollection::new(); - let window = window_from_node(self).root(&roots); + let window = window_from_node(self).root(); ValidityState::new(&*window) } diff --git a/src/components/script/dom/htmlformelement.rs b/src/components/script/dom/htmlformelement.rs index c7773bdf68a..9cba31363ab 100644 --- a/src/components/script/dom/htmlformelement.rs +++ b/src/components/script/dom/htmlformelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFormElementBinding; use dom::bindings::codegen::InheritTypes::HTMLFormElementDerived; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLFormElementTypeId}; @@ -143,8 +143,7 @@ impl<'a> HTMLFormElementMethods for JSRef<'a, HTMLFormElement> { fn Elements(&self) -> Temporary { // FIXME: https://github.com/mozilla/servo/issues/1844 - let roots = RootCollection::new(); - let window = window_from_node(self).root(&roots); + let window = window_from_node(self).root(); HTMLCollection::new(&*window, Static(vec!())) } diff --git a/src/components/script/dom/htmlimageelement.rs b/src/components/script/dom/htmlimageelement.rs index 956a923f7c0..af31c043d11 100644 --- a/src/components/script/dom/htmlimageelement.rs +++ b/src/components/script/dom/htmlimageelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLImageElementBinding; use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast, HTMLElementCast, HTMLImageElementDerived}; use dom::bindings::error::ErrorResult; -use dom::bindings::js::{JS, JSRef, Temporary, RootCollection}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::trace::Untraceable; use dom::document::Document; use dom::element::{Element, HTMLImageElementTypeId}; @@ -43,11 +43,10 @@ impl<'a> PrivateHTMLImageElementHelpers for JSRef<'a, HTMLImageElement> { /// Makes the local `image` member match the status of the `src` attribute and starts /// prefetching the image. This method must be called after `src` is changed. fn update_image(&mut self, value: Option, url: Option) { - let roots = RootCollection::new(); let self_alias = self.clone(); let node_alias: &JSRef = NodeCast::from_ref(&self_alias); - let document = node_alias.owner_doc().root(&roots); - let window = document.deref().window.root(&roots); + let document = node_alias.owner_doc().root(); + let window = document.deref().window.root(); let image_cache = &window.image_cache_task; match value { None => { @@ -275,14 +274,13 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> { } fn after_set_attr(&mut self, name: DOMString, value: DOMString) { - let roots = RootCollection::new(); match self.super_type() { Some(ref mut s) => s.after_set_attr(name.clone(), value.clone()), _ => (), } if "src" == name { - let window = window_from_node(self).root(&roots); + let window = window_from_node(self).root(); let url = Some(window.get().get_url()); self.update_image(Some(value), url); } diff --git a/src/components/script/dom/htmlmapelement.rs b/src/components/script/dom/htmlmapelement.rs index 681056a6be6..a6bd9d39ed0 100644 --- a/src/components/script/dom/htmlmapelement.rs +++ b/src/components/script/dom/htmlmapelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLMapElementBinding; use dom::bindings::codegen::InheritTypes::HTMLMapElementDerived; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLMapElementTypeId; @@ -57,9 +57,8 @@ impl<'a> HTMLMapElementMethods for JSRef<'a, HTMLMapElement> { } fn Areas(&self) -> Temporary { - let roots = RootCollection::new(); // FIXME: https://github.com/mozilla/servo/issues/1845 - let window = window_from_node(self).root(&roots); + let window = window_from_node(self).root(); HTMLCollection::new(&*window, Static(vec!())) } } diff --git a/src/components/script/dom/htmlobjectelement.rs b/src/components/script/dom/htmlobjectelement.rs index 18f8acce6b2..c560486c565 100644 --- a/src/components/script/dom/htmlobjectelement.rs +++ b/src/components/script/dom/htmlobjectelement.rs @@ -6,7 +6,7 @@ use dom::attr::AttrMethods; use dom::bindings::codegen::BindingDeclarations::HTMLObjectElementBinding; use dom::bindings::codegen::InheritTypes::HTMLObjectElementDerived; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast}; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLObjectElementTypeId}; @@ -62,12 +62,11 @@ impl<'a> ProcessDataURL for JSRef<'a, HTMLObjectElement> { // Makes the local `data` member match the status of the `data` attribute and starts /// prefetching the image. This method must be called after `data` is changed. fn process_data_url(&mut self, image_cache: ImageCacheTask, url: Option) { - let roots = RootCollection::new(); let elem: &JSRef = ElementCast::from_ref(self); // TODO: support other values - match (elem.get_attribute(Null, "type").map(|x| x.root(&roots).Value()), - elem.get_attribute(Null, "data").map(|x| x.root(&roots).Value())) { + match (elem.get_attribute(Null, "type").map(|x| x.root().Value()), + elem.get_attribute(Null, "data").map(|x| x.root().Value())) { (None, Some(uri)) => { if is_image_data(uri) { let data_url = parse_url(uri, url); @@ -190,8 +189,7 @@ impl<'a> HTMLObjectElementMethods for JSRef<'a, HTMLObjectElement> { } fn Validity(&self) -> Temporary { - let roots = RootCollection::new(); - let window = window_from_node(self).root(&roots); + let window = window_from_node(self).root(); ValidityState::new(&*window) } @@ -298,14 +296,13 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLObjectElement> { } fn after_set_attr(&mut self, name: DOMString, value: DOMString) { - let roots = RootCollection::new(); match self.super_type() { Some(ref mut s) => s.after_set_attr(name.clone(), value), _ => (), } if "data" == name { - let window = window_from_node(self).root(&roots); + let window = window_from_node(self).root(); let url = Some(window.get().get_url()); self.process_data_url(window.get().image_cache_task.clone(), url); } diff --git a/src/components/script/dom/htmloutputelement.rs b/src/components/script/dom/htmloutputelement.rs index 5bed0a4fb49..91a77daa8e5 100644 --- a/src/components/script/dom/htmloutputelement.rs +++ b/src/components/script/dom/htmloutputelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLOutputElementBinding; use dom::bindings::codegen::InheritTypes::HTMLOutputElementDerived; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLOutputElementTypeId; @@ -102,8 +102,7 @@ impl<'a> HTMLOutputElementMethods for JSRef<'a, HTMLOutputElement> { } fn Validity(&self) -> Temporary { - let roots = RootCollection::new(); - let window = window_from_node(self).root(&roots); + let window = window_from_node(self).root(); ValidityState::new(&*window) } diff --git a/src/components/script/dom/htmlselectelement.rs b/src/components/script/dom/htmlselectelement.rs index 8c349315849..54d3c7cf86f 100644 --- a/src/components/script/dom/htmlselectelement.rs +++ b/src/components/script/dom/htmlselectelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLSelectElementBinding; use dom::bindings::codegen::InheritTypes::HTMLSelectElementDerived; use dom::bindings::codegen::UnionTypes::{HTMLElementOrLong, HTMLOptionElementOrHTMLOptGroupElement}; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLSelectElementTypeId}; @@ -192,8 +192,7 @@ impl<'a> HTMLSelectElementMethods for JSRef<'a, HTMLSelectElement> { } fn Validity(&self) -> Temporary { - let roots = RootCollection::new(); - let window = window_from_node(self).root(&roots); + let window = window_from_node(self).root(); ValidityState::new(&*window) } diff --git a/src/components/script/dom/htmlserializer.rs b/src/components/script/dom/htmlserializer.rs index 55c1ba03d9e..9f2bdf3e40b 100644 --- a/src/components/script/dom/htmlserializer.rs +++ b/src/components/script/dom/htmlserializer.rs @@ -7,7 +7,7 @@ use dom::attr::Attr; use dom::bindings::codegen::InheritTypes::{ElementCast, TextCast, CommentCast, NodeCast}; use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, CharacterDataCast}; use dom::bindings::codegen::InheritTypes::ProcessingInstructionCast; -use dom::bindings::js::{JSRef, RootCollection}; +use dom::bindings::js::JSRef; use dom::characterdata::CharacterData; use dom::comment::Comment; use dom::documenttype::DocumentType; @@ -70,9 +70,8 @@ fn serialize_comment(comment: &JSRef) -> ~str { } fn serialize_text(text: &JSRef) -> ~str { - let roots = RootCollection::new(); let text_node: &JSRef = NodeCast::from_ref(text); - match text_node.parent_node().map(|node| node.root(&roots)) { + match text_node.parent_node().map(|node| node.root()) { Some(ref parent) if parent.is_element() => { let elem: &JSRef = ElementCast::to_ref(&**parent).unwrap(); match elem.get().local_name.as_slice() { @@ -97,17 +96,16 @@ fn serialize_doctype(doctype: &JSRef) -> ~str { } fn serialize_elem(elem: &JSRef, open_elements: &mut Vec<~str>) -> ~str { - let roots = RootCollection::new(); let mut rv = ~"<" + elem.get().local_name; for attr in elem.get().attrs.iter() { - let attr = attr.root(&roots); + let attr = attr.root(); rv.push_str(serialize_attr(&*attr)); }; rv.push_str(">"); match elem.get().local_name.as_slice() { "pre" | "listing" | "textarea" if elem.get().namespace == namespace::HTML => { let node: &JSRef = NodeCast::from_ref(elem); - match node.first_child().map(|child| child.root(&roots)) { + match node.first_child().map(|child| child.root()) { Some(ref child) if child.is_text() => { let text: &JSRef = CharacterDataCast::to_ref(&**child).unwrap(); if text.get().data.len() > 0 && text.get().data[0] == 0x0A as u8 { diff --git a/src/components/script/dom/htmlstyleelement.rs b/src/components/script/dom/htmlstyleelement.rs index 1ee1408e9ef..025375efb73 100644 --- a/src/components/script/dom/htmlstyleelement.rs +++ b/src/components/script/dom/htmlstyleelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLStyleElementBinding; use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLStyleElementDerived, NodeCast}; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLStyleElementTypeId; @@ -93,9 +93,8 @@ pub trait StyleElementHelpers { impl<'a> StyleElementHelpers for JSRef<'a, HTMLStyleElement> { fn parse_own_css(&self) { - let roots = RootCollection::new(); let node: &JSRef = NodeCast::from_ref(self); - let win = window_from_node(node).root(&roots); + let win = window_from_node(node).root(); let url = win.get().page().get_url(); let data = node.GetTextContent().expect("Element.textContent must be a string"); diff --git a/src/components/script/dom/mouseevent.rs b/src/components/script/dom/mouseevent.rs index ce46cd47680..f35c088675c 100644 --- a/src/components/script/dom/mouseevent.rs +++ b/src/components/script/dom/mouseevent.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::MouseEventBinding; use dom::bindings::codegen::InheritTypes::{UIEventCast, MouseEventDerived}; -use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Temporary}; +use dom::bindings::js::{JS, JSRef, RootedReference, Temporary}; use dom::bindings::error::Fallible; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::event::{Event, MouseEventTypeId}; @@ -60,10 +60,9 @@ impl MouseEvent { pub fn Constructor(owner: &JSRef, type_: DOMString, init: &MouseEventBinding::MouseEventInit) -> Fallible> { - let roots = RootCollection::new(); - let mut ev = MouseEvent::new(owner).root(&roots); - let view = init.view.as_ref().map(|view| view.root(&roots)); - let related_target = init.relatedTarget.as_ref().map(|relatedTarget| relatedTarget.root(&roots)); + let mut ev = MouseEvent::new(owner).root(); + let view = init.view.as_ref().map(|view| view.root()); + let related_target = init.relatedTarget.as_ref().map(|relatedTarget| relatedTarget.root()); ev.InitMouseEvent(type_, init.bubbles, init.cancelable, view.root_ref(), init.detail, init.screenX, init.screenY, init.clientX, init.clientY, init.ctrlKey, diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 07b9ecd111d..772d1fbcc39 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -10,7 +10,7 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, TextCast, NodeCast, Elem use dom::bindings::codegen::InheritTypes::{CharacterDataCast, NodeBase, NodeDerived}; use dom::bindings::codegen::InheritTypes::{ProcessingInstructionCast, EventTargetCast}; use dom::bindings::codegen::BindingDeclarations::NodeBinding::NodeConstants; -use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Temporary, Root}; +use dom::bindings::js::{JS, JSRef, RootedReference, Temporary, Root}; use dom::bindings::js::{OptionalAssignable, TemporaryPushable, OptionalRootedRootable}; use dom::bindings::js::{ResultRootable, OptionalRootable}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; @@ -240,29 +240,26 @@ trait PrivateNodeHelpers { impl<'a> PrivateNodeHelpers for JSRef<'a, Node> { // http://dom.spec.whatwg.org/#node-is-inserted fn node_inserted(&self) { - let roots = RootCollection::new(); assert!(self.parent_node().is_some()); - let document = document_from_node(self).root(&roots); + let document = document_from_node(self).root(); if self.is_in_doc() { - for node in self.traverse_preorder(&roots) { + for node in self.traverse_preorder() { vtable_for(&node).bind_to_tree(); } } - self.parent_node().root(&roots) - .map(|parent| vtable_for(&*parent).child_inserted(self)); + self.parent_node().root().map(|parent| vtable_for(&*parent).child_inserted(self)); document.deref().content_changed(); } // http://dom.spec.whatwg.org/#node-is-removed fn node_removed(&self) { - let roots = RootCollection::new(); assert!(self.parent_node().is_none()); - let document = document_from_node(self).root(&roots); + let document = document_from_node(self).root(); - for node in self.traverse_preorder(&roots) { + for node in self.traverse_preorder() { // XXX how about if the node wasn't in the tree in the first place? vtable_for(&node).unbind_from_tree(); } @@ -278,7 +275,6 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> { /// /// Fails unless `new_child` is disconnected from the tree. fn add_child(&mut self, new_child: &mut JSRef, mut before: Option>) { - let roots = RootCollection::new(); assert!(new_child.parent_node().is_none()); assert!(new_child.prev_sibling().is_none()); assert!(new_child.next_sibling().is_none()); @@ -286,14 +282,13 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> { Some(ref mut before) => { // XXX Should assert that parent is self. assert!(before.parent_node().is_some()); - match before.prev_sibling() { + match before.prev_sibling().root() { None => { // XXX Should assert that before is the first child of // self. self.set_first_child(Some(new_child.clone())); }, - Some(prev_sibling) => { - let mut prev_sibling = prev_sibling.root(&roots); + Some(mut prev_sibling) => { prev_sibling.set_next_sibling(Some(new_child.clone())); new_child.set_prev_sibling(Some((*prev_sibling).clone())); }, @@ -302,7 +297,7 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> { new_child.set_next_sibling(Some(before.clone())); }, None => { - match self.last_child().map(|child| child.root(&roots)) { + match self.last_child().root() { None => self.set_first_child(Some(new_child.clone())), Some(mut last_child) => { assert!(last_child.next_sibling().is_none()); @@ -322,27 +317,26 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> { /// /// Fails unless `child` is a child of this node. (FIXME: This is not yet checked.) fn remove_child(&mut self, child: &mut JSRef) { - let roots = RootCollection::new(); assert!(child.parent_node.is_some()); - match child.prev_sibling.root(&roots) { + match child.prev_sibling.root() { None => { - let next_sibling = child.next_sibling.as_ref().map(|next| next.root(&roots)); + let next_sibling = child.next_sibling.root(); self.set_first_child(next_sibling.root_ref()); } Some(ref mut prev_sibling) => { - let next_sibling = child.next_sibling.as_ref().map(|next| next.root(&roots)); + let next_sibling = child.next_sibling.root(); prev_sibling.set_next_sibling(next_sibling.root_ref()); } } - match child.next_sibling.root(&roots) { + match child.next_sibling.root() { None => { - let prev_sibling = child.prev_sibling.as_ref().map(|prev| prev.root(&roots)); + let prev_sibling = child.prev_sibling.root(); self.set_last_child(prev_sibling.root_ref()); } Some(ref mut next_sibling) => { - let prev_sibling = child.prev_sibling.as_ref().map(|prev| prev.root(&roots)); + let prev_sibling = child.prev_sibling.root(); next_sibling.set_prev_sibling(prev_sibling.root_ref()); } } @@ -357,36 +351,31 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> { // fn set_parent_node(&mut self, new_parent_node: Option>) { - let roots = RootCollection::new(); - let doc = self.owner_doc().root(&roots); + let doc = self.owner_doc().root(); doc.deref().wait_until_safe_to_modify_dom(); self.parent_node.assign(new_parent_node); } fn set_first_child(&mut self, new_first_child: Option>) { - let roots = RootCollection::new(); - let doc = self.owner_doc().root(&roots); + let doc = self.owner_doc().root(); doc.deref().wait_until_safe_to_modify_dom(); self.first_child.assign(new_first_child); } fn set_last_child(&mut self, new_last_child: Option>) { - let roots = RootCollection::new(); - let doc = self.owner_doc().root(&roots); + let doc = self.owner_doc().root(); doc.deref().wait_until_safe_to_modify_dom(); self.last_child.assign(new_last_child); } fn set_prev_sibling(&mut self, new_prev_sibling: Option>) { - let roots = RootCollection::new(); - let doc = self.owner_doc().root(&roots); + let doc = self.owner_doc().root(); doc.deref().wait_until_safe_to_modify_dom(); self.prev_sibling.assign(new_prev_sibling); } fn set_next_sibling(&mut self, new_next_sibling: Option>) { - let roots = RootCollection::new(); - let doc = self.owner_doc().root(&roots); + let doc = self.owner_doc().root(); doc.deref().wait_until_safe_to_modify_dom(); self.next_sibling.assign(new_next_sibling); } @@ -427,8 +416,8 @@ pub trait NodeHelpers { fn dump_indent(&self, indent: uint); fn debug_str(&self) -> ~str; - fn traverse_preorder<'a>(&self, roots: &'a RootCollection) -> TreeIterator<'a>; - fn sequential_traverse_postorder<'a>(&self, roots: &'a RootCollection) -> TreeIterator<'a>; + fn traverse_preorder<'a>(&self) -> TreeIterator<'a>; + fn sequential_traverse_postorder<'a>(&self) -> TreeIterator<'a>; fn inclusively_following_siblings(&self) -> AbstractNodeChildrenIterator; fn to_trusted_node_address(&self) -> TrustedNodeAddress; @@ -546,24 +535,22 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { } /// Iterates over this node and all its descendants, in preorder. - fn traverse_preorder<'a>(&self, roots: &'a RootCollection) -> TreeIterator<'a> { + fn traverse_preorder<'a>(&self) -> TreeIterator<'a> { let mut nodes = vec!(); - gather_abstract_nodes(self, roots, &mut nodes, false); + gather_abstract_nodes(self, &mut nodes, false); TreeIterator::new(nodes) } /// Iterates over this node and all its descendants, in postorder. - fn sequential_traverse_postorder<'a>(&self, roots: &'a RootCollection) -> TreeIterator<'a> { + fn sequential_traverse_postorder<'a>(&self) -> TreeIterator<'a> { let mut nodes = vec!(); - gather_abstract_nodes(self, roots, &mut nodes, true); + gather_abstract_nodes(self, &mut nodes, true); TreeIterator::new(nodes) } fn inclusively_following_siblings(&self) -> AbstractNodeChildrenIterator { - let roots = RootCollection::new(); AbstractNodeChildrenIterator { - current_node: Some((*self.unrooted().root(&roots)).clone()), - roots: roots, + current_node: Some((*self.unrooted().root()).clone()), } } @@ -572,10 +559,8 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { } fn following_siblings(&self) -> AbstractNodeChildrenIterator { - let roots = RootCollection::new(); AbstractNodeChildrenIterator { - current_node: self.next_sibling().map(|node| (*node.root(&roots)).clone()), - roots: roots, + current_node: self.next_sibling().map(|node| (*node.root()).clone()), } } @@ -591,8 +576,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { } fn get_bounding_content_box(&self) -> Rect { - let roots = RootCollection::new(); - let window = window_from_node(self).root(&roots); + let window = window_from_node(self).root(); let page = window.get().page(); let (chan, port) = channel(); let addr = self.to_trusted_node_address(); @@ -601,8 +585,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { } fn get_content_boxes(&self) -> Vec> { - let roots = RootCollection::new(); - let window = window_from_node(self).root(&roots); + let window = window_from_node(self).root(); let page = window.get().page(); let (chan, port) = channel(); let addr = self.to_trusted_node_address(); @@ -611,10 +594,8 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { } fn ancestors(&self) -> AncestorIterator { - let roots = RootCollection::new(); AncestorIterator { - current: self.parent_node.clone().map(|node| (*node.root(&roots)).clone()), - roots: roots, + current: self.parent_node.clone().map(|node| (*node.root()).clone()), } } @@ -627,10 +608,8 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { } fn children(&self) -> AbstractNodeChildrenIterator { - let roots = RootCollection::new(); AbstractNodeChildrenIterator { - current_node: self.first_child.clone().map(|node| (*node.root(&roots)).clone()), - roots: roots, + current_node: self.first_child.clone().map(|node| (*node.root()).clone()), } } @@ -646,8 +625,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { } fn wait_until_safe_to_modify_dom(&self) { - let roots = RootCollection::new(); - let document = self.owner_doc().root(&roots); + let document = self.owner_doc().root(); document.deref().wait_until_safe_to_modify_dom(); } @@ -743,14 +721,13 @@ pub type ChildElementIterator<'a, 'b> = Map<'a, JSRef<'b, Node>, pub struct AbstractNodeChildrenIterator<'a> { current_node: Option>, - roots: RootCollection, } impl<'a> Iterator> for AbstractNodeChildrenIterator<'a> { fn next(&mut self) -> Option> { let node = self.current_node.clone(); self.current_node = node.clone().and_then(|node| { - node.next_sibling().map(|node| (*node.root(&self.roots)).clone()) + node.next_sibling().map(|node| (*node.root()).clone()) }); node } @@ -758,7 +735,6 @@ impl<'a> Iterator> for AbstractNodeChildrenIterator<'a> { pub struct AncestorIterator<'a> { current: Option>, - roots: RootCollection, } impl<'a> Iterator> for AncestorIterator<'a> { @@ -769,7 +745,7 @@ impl<'a> Iterator> for AncestorIterator<'a> { // FIXME: Do we need two clones here? let x = self.current.get_ref().clone(); - self.current = x.parent_node().map(|node| (*node.root(&self.roots)).clone()); + self.current = x.parent_node().map(|node| (*node.root()).clone()); Some(x) } } @@ -802,8 +778,7 @@ impl<'a> Iterator> for TreeIterator<'a> { } } -pub struct NodeIterator<'a> { - roots: &'a RootCollection, +pub struct NodeIterator { pub start_node: JS, pub current_node: Option>, pub depth: uint, @@ -811,13 +786,11 @@ pub struct NodeIterator<'a> { include_descendants_of_void: bool } -impl<'a> NodeIterator<'a> { - pub fn new<'a, 'b>(roots: &'a RootCollection, - start_node: &JSRef<'b, Node>, - include_start: bool, - include_descendants_of_void: bool) -> NodeIterator<'a> { +impl NodeIterator { + pub fn new<'a>(start_node: &JSRef<'a, Node>, + include_start: bool, + include_descendants_of_void: bool) -> NodeIterator { NodeIterator { - roots: roots, start_node: start_node.unrooted(), current_node: None, depth: 0, @@ -832,22 +805,22 @@ impl<'a> NodeIterator<'a> { if elem.get().is_void() { None } else { - node.first_child().map(|child| (*child.root(self.roots)).clone()) + node.first_child().map(|child| (*child.root()).clone()) } } else { - node.first_child().map(|child| (*child.root(self.roots)).clone()) + node.first_child().map(|child| (*child.root()).clone()) } } } -impl<'a, 'b> Iterator> for NodeIterator<'a> { +impl<'a> Iterator> for NodeIterator { fn next(&mut self) -> Option> { - self.current_node = match self.current_node.as_ref().map(|node| node.root(self.roots)) { + self.current_node = match self.current_node.as_ref().map(|node| node.root()) { None => { if self.include_start { Some(self.start_node.clone()) } else { - self.next_child(&*self.start_node.root(self.roots)) + self.next_child(&*self.start_node.root()) .map(|child| child.unrooted()) } }, @@ -859,21 +832,21 @@ impl<'a, 'b> Iterator> for NodeIterator<'a> { }, None if node.deref().unrooted() == self.start_node => None, None => { - match node.deref().next_sibling().root(self.roots) { + match node.deref().next_sibling().root() { Some(sibling) => Some(sibling.deref().unrooted()), None => { let mut candidate = node.deref().clone(); while candidate.next_sibling().is_none() { candidate = (*candidate.parent_node() .expect("Got to root without reaching start node") - .root(self.roots)).clone(); + .root()).clone(); self.depth -= 1; if candidate.unrooted() == self.start_node { break; } } if candidate.unrooted() != self.start_node { - candidate.next_sibling().map(|node| node.root(self.roots).unrooted()) + candidate.next_sibling().map(|node| node.root().unrooted()) } else { None } @@ -883,19 +856,19 @@ impl<'a, 'b> Iterator> for NodeIterator<'a> { } } }; - self.current_node.clone().map(|node| (*node.root(self.roots)).clone()) + self.current_node.clone().map(|node| (*node.root()).clone()) } } -fn gather_abstract_nodes<'a>(cur: &JSRef, roots: &'a RootCollection, refs: &mut Vec>, postorder: bool) { +fn gather_abstract_nodes<'a>(cur: &JSRef, refs: &mut Vec>, postorder: bool) { if !postorder { - refs.push((*cur.unrooted().root(roots)).clone()); + refs.push((*cur.unrooted().root()).clone()); } for kid in cur.children() { - gather_abstract_nodes(&kid, roots, refs, postorder) + gather_abstract_nodes(&kid, refs, postorder) } if postorder { - refs.push((*cur.unrooted().root(roots)).clone()); + refs.push((*cur.unrooted().root()).clone()); } } @@ -914,17 +887,15 @@ impl Node { document: &JSRef, wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~N) -> JS) -> Temporary { - let roots = RootCollection::new(); assert!(node.reflector().get_jsobject().is_null()); - let window = document.get().window.root(&roots); - let node = reflect_dom_object(node, &window.root_ref(), wrap_fn).root(&roots); + let window = document.get().window.root(); + let node = reflect_dom_object(node, &window.root_ref(), wrap_fn).root(); assert!(node.reflector().get_jsobject().is_not_null()); Temporary::new_rooted(&*node) } pub fn new_inherited(type_id: NodeTypeId, doc: JS) -> Node { - let roots = RootCollection::new(); - let doc = doc.root(&roots); + let doc = doc.root(); Node::new_(type_id, Some(doc.root_ref())) } @@ -954,9 +925,8 @@ impl Node { // http://dom.spec.whatwg.org/#concept-node-adopt pub fn adopt(node: &mut JSRef, document: &JSRef) { - let roots = RootCollection::new(); // Step 1. - match node.parent_node().root(&roots) { + match node.parent_node().root() { Some(mut parent) => { Node::remove(node, &mut *parent, Unsuppressed); } @@ -964,9 +934,9 @@ impl Node { } // Step 2. - let node_doc = document_from_node(node).root(&roots); + let node_doc = document_from_node(node).root(); if &*node_doc != document { - for mut descendant in node.traverse_preorder(&roots) { + for mut descendant in node.traverse_preorder() { descendant.set_owner_doc(document); } } @@ -978,7 +948,6 @@ impl Node { // http://dom.spec.whatwg.org/#concept-node-pre-insert fn pre_insert(node: &mut JSRef, parent: &mut JSRef, child: Option>) -> Fallible> { - let roots = RootCollection::new(); // Step 1. match parent.type_id() { DocumentNodeTypeId | @@ -1001,13 +970,13 @@ impl Node { // Step 4-5. match node.type_id() { TextNodeTypeId => { - match node.parent_node().root(&roots) { + match node.parent_node().root() { Some(ref parent) if parent.is_document() => return Err(HierarchyRequest), _ => () } } DoctypeNodeTypeId => { - match node.parent_node().root(&roots) { + match node.parent_node().root() { Some(ref parent) if !parent.is_document() => return Err(HierarchyRequest), _ => () } @@ -1098,12 +1067,12 @@ impl Node { // Step 7-8. let referenceChild = match child { - Some(ref child) if child == node => node.next_sibling().map(|node| (*node.root(&roots)).clone()), + Some(ref child) if child == node => node.next_sibling().map(|node| (*node.root()).clone()), _ => child }; // Step 9. - let document = document_from_node(parent).root(&roots); + let document = document_from_node(parent).root(); Node::adopt(node, &*document); // Step 10. @@ -1157,12 +1126,11 @@ impl Node { // http://dom.spec.whatwg.org/#concept-node-replace-all fn replace_all(mut node: Option>, parent: &mut JSRef) { - let roots = RootCollection::new(); // Step 1. match node { Some(ref mut node) => { - let document = document_from_node(parent).root(&roots); + let document = document_from_node(parent).root(); Node::adopt(node, &*document); } None => (), @@ -1237,12 +1205,11 @@ impl Node { // http://dom.spec.whatwg.org/#concept-node-clone pub fn clone(node: &JSRef, maybe_doc: Option<&JSRef>, clone_children: CloneChildrenFlag) -> Temporary { - let roots = RootCollection::new(); // Step 1. let mut document = match maybe_doc { - Some(doc) => doc.unrooted().root(&roots), - None => node.owner_doc().root(&roots) + Some(doc) => doc.unrooted().root(), + None => node.owner_doc().root() }; // Step 2. @@ -1272,7 +1239,7 @@ impl Node { true => HTMLDocument, false => NonHTMLDocument }; - let window = document.window.root(&roots); + let window = document.window.root(); let document = Document::new(&*window, Some(document.url().clone()), is_html_doc, None); NodeCast::from_unrooted(document) @@ -1296,16 +1263,16 @@ impl Node { pi.characterdata.data.clone(), &*document); NodeCast::from_unrooted(pi) }, - }.root(&roots); + }.root(); // Step 3. let document = if copy.is_document() { let doc: &JSRef = DocumentCast::to_ref(&*copy).unwrap(); - doc.unrooted().root(&roots) + doc.unrooted().root() } else { - document.unrooted().root(&roots) + document.unrooted().root() }; - assert!(&*copy.owner_doc().root(&roots) == &*document); + assert!(&*copy.owner_doc().root() == &*document); // Step 4 (some data already copied in step 2). match node.get().type_id { @@ -1326,8 +1293,8 @@ impl Node { let copy_elem = copy_elem.get_mut(); // FIXME: https://github.com/mozilla/servo/issues/1737 copy_elem.namespace = node_elem.namespace.clone(); - let window = document.get().window.root(&roots); - for attr in node_elem.attrs.iter().map(|attr| attr.root(&roots)) { + let window = document.get().window.root(); + for attr in node_elem.attrs.iter().map(|attr| attr.root()) { copy_elem.attrs.push_unrooted( Attr::new(&*window, attr.deref().local_name.clone(), attr.deref().value.clone(), @@ -1343,7 +1310,7 @@ impl Node { // Step 6. if clone_children == CloneChildren { for ref child in node.children() { - let mut child_copy = Node::clone(&*child, Some(&*document), clone_children).root(&roots); + let mut child_copy = Node::clone(&*child, Some(&*document), clone_children).root(); let _inserted_node = Node::pre_insert(&mut *child_copy, &mut *copy, None); } } @@ -1462,10 +1429,9 @@ impl<'a> NodeMethods for JSRef<'a, Node> { // http://dom.spec.whatwg.org/#dom-node-parentelement fn GetParentElement(&self) -> Option> { - let roots = RootCollection::new(); self.parent_node.clone() .and_then(|parent| { - let parent = parent.root(&roots); + let parent = parent.root(); ElementCast::to_ref(&*parent).map(|elem| { Temporary::new_rooted(elem) }) @@ -1479,14 +1445,13 @@ impl<'a> NodeMethods for JSRef<'a, Node> { // http://dom.spec.whatwg.org/#dom-node-childnodes fn ChildNodes(&mut self) -> Temporary { - let roots = RootCollection::new(); match self.child_list { None => (), Some(ref list) => return Temporary::new(list.clone()), } - let doc = self.owner_doc().root(&roots); - let window = doc.deref().window.root(&roots); + let doc = self.owner_doc().root(); + let window = doc.deref().window.root(); let child_list = NodeList::new_child_list(&*window, self); self.child_list.assign(Some(child_list)); Temporary::new(self.child_list.get_ref().clone()) @@ -1542,12 +1507,11 @@ impl<'a> NodeMethods for JSRef<'a, Node> { // http://dom.spec.whatwg.org/#dom-node-textcontent fn GetTextContent(&self) -> Option { - let roots = RootCollection::new(); match self.type_id { DocumentFragmentNodeTypeId | ElementNodeTypeId(..) => { let mut content = ~""; - for node in self.traverse_preorder(&roots) { + for node in self.traverse_preorder() { if node.is_text() { let text: &JSRef = TextCast::to_ref(&node).unwrap(); content.push_str(text.get().characterdata.data.as_slice()); @@ -1571,7 +1535,6 @@ impl<'a> NodeMethods for JSRef<'a, Node> { // http://dom.spec.whatwg.org/#dom-node-textcontent fn SetTextContent(&mut self, value: Option) -> ErrorResult { - let roots = RootCollection::new(); let value = null_str_as_empty(&value); match self.type_id { DocumentFragmentNodeTypeId | @@ -1580,9 +1543,9 @@ impl<'a> NodeMethods for JSRef<'a, Node> { let node = if value.len() == 0 { None } else { - let document = self.owner_doc().root(&roots); + let document = self.owner_doc().root(); Some(NodeCast::from_unrooted(document.deref().CreateTextNode(value))) - }.root(&roots); + }.root(); // Step 3. Node::replace_all(node.root_ref(), self); @@ -1598,7 +1561,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // Notify the document that the content of this node is different - let document = self.owner_doc().root(&roots); + let document = self.owner_doc().root(); document.deref().content_changed(); } DoctypeNodeTypeId | @@ -1619,7 +1582,6 @@ impl<'a> NodeMethods for JSRef<'a, Node> { // http://dom.spec.whatwg.org/#concept-node-replace fn ReplaceChild(&mut self, node: &mut JSRef, child: &mut JSRef) -> Fallible> { - let roots = RootCollection::new(); // Step 1. match self.type_id() { @@ -1714,14 +1676,14 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // Step 7-8. - let next_sibling = child.next_sibling().map(|node| (*node.root(&roots)).clone()); + let next_sibling = child.next_sibling().map(|node| (*node.root()).clone()); let reference_child = match next_sibling { - Some(ref sibling) if sibling == node => node.next_sibling().map(|node| (*node.root(&roots)).clone()), + Some(ref sibling) if sibling == node => node.next_sibling().map(|node| (*node.root()).clone()), _ => next_sibling }; // Step 9. - let document = document_from_node(self).root(&roots); + let document = document_from_node(self).root(); Node::adopt(node, &*document); { @@ -1755,7 +1717,6 @@ impl<'a> NodeMethods for JSRef<'a, Node> { // http://dom.spec.whatwg.org/#dom-node-normalize fn Normalize(&mut self) { - let roots = RootCollection::new(); let mut prev_text = None; for mut child in self.children() { if child.is_text() { @@ -1818,12 +1779,11 @@ impl<'a> NodeMethods for JSRef<'a, Node> { characterdata.get().data == other_characterdata.get().data } fn is_equal_element_attrs(node: &JSRef, other: &JSRef) -> bool { - let roots = RootCollection::new(); let element: &JSRef = ElementCast::to_ref(node).unwrap(); let other_element: &JSRef = ElementCast::to_ref(other).unwrap(); assert!(element.get().attrs.len() == other_element.get().attrs.len()); - element.get().attrs.iter().map(|attr| attr.root(&roots)).all(|attr| { - other_element.get().attrs.iter().map(|attr| attr.root(&roots)).any(|other_attr| { + element.get().attrs.iter().map(|attr| attr.root()).all(|attr| { + other_element.get().attrs.iter().map(|attr| attr.root()).any(|other_attr| { (attr.namespace == other_attr.namespace) && (attr.local_name == other_attr.local_name) && (attr.value == other_attr.value) @@ -1868,7 +1828,6 @@ impl<'a> NodeMethods for JSRef<'a, Node> { // http://dom.spec.whatwg.org/#dom-node-comparedocumentposition fn CompareDocumentPosition(&self, other: &JSRef) -> u16 { - let roots = RootCollection::new(); if self == other { // step 2. 0 @@ -1907,7 +1866,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { NodeConstants::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC; } - for child in lastself.traverse_preorder(&roots) { + for child in lastself.traverse_preorder() { if &child == other { // step 6. return NodeConstants::DOCUMENT_POSITION_PRECEDING; @@ -1965,8 +1924,7 @@ pub fn document_from_node(derived: &JSRef) -> Temporary(derived: &JSRef) -> Temporary { - let roots = RootCollection::new(); - let document = document_from_node(derived).root(&roots); + let document = document_from_node(derived).root(); Temporary::new(document.deref().window.clone()) } diff --git a/src/components/script/dom/nodelist.rs b/src/components/script/dom/nodelist.rs index 7157c7ec061..5c02eca8d08 100644 --- a/src/components/script/dom/nodelist.rs +++ b/src/components/script/dom/nodelist.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::NodeListBinding; -use dom::bindings::js::{JS, JSRef, Temporary, RootCollection}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::node::{Node, NodeHelpers}; use dom::window::Window; @@ -54,23 +54,21 @@ pub trait NodeListMethods { impl<'a> NodeListMethods for JSRef<'a, NodeList> { fn Length(&self) -> u32 { - let roots = RootCollection::new(); match self.list_type { Simple(ref elems) => elems.len() as u32, Children(ref node) => { - let node = node.root(&roots); + let node = node.root(); node.deref().children().len() as u32 } } } fn Item(&self, index: u32) -> Option> { - let roots = RootCollection::new(); match self.list_type { _ if index >= self.Length() => None, Simple(ref elems) => Some(Temporary::new(elems.get(index as uint).clone())), Children(ref node) => { - let node = node.root(&roots); + let node = node.root(); node.deref().children().nth(index as uint) .map(|child| Temporary::new_rooted(&child)) } diff --git a/src/components/script/dom/testbinding.rs b/src/components/script/dom/testbinding.rs index 2c012c1b911..cade75c1f95 100644 --- a/src/components/script/dom/testbinding.rs +++ b/src/components/script/dom/testbinding.rs @@ -2,7 +2,7 @@ * 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, RootCollection, Temporary}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::codegen::BindingDeclarations::TestBindingBinding; use dom::bindings::codegen::UnionTypes::HTMLElementOrLong; use self::TestBindingBinding::TestEnum; @@ -232,8 +232,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> { fn EnumAttribute(&self) -> TestEnum { _empty } fn SetEnumAttribute(&self, _: TestEnum) {} fn InterfaceAttribute(&self) -> Temporary { - let roots = RootCollection::new(); - let window = self.window.root(&roots); + let window = self.window.root(); Blob::new(&*window) } fn SetInterfaceAttribute(&self, _: &JSRef) {} @@ -268,8 +267,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> { fn SetStringAttributeNullable(&self, _: Option) {} fn GetEnumAttributeNullable(&self) -> Option { Some(_empty) } fn GetInterfaceAttributeNullable(&self) -> Option> { - let roots = RootCollection::new(); - let window = self.window.root(&roots); + let window = self.window.root(); Some(Blob::new(&(*window))) } fn SetInterfaceAttributeNullable(&self, _: Option>) {} diff --git a/src/components/script/dom/text.rs b/src/components/script/dom/text.rs index be62565f965..d286c7f5361 100644 --- a/src/components/script/dom/text.rs +++ b/src/components/script/dom/text.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::TextBinding; use dom::bindings::codegen::InheritTypes::TextDerived; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary}; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::error::Fallible; use dom::characterdata::CharacterData; use dom::document::Document; @@ -41,8 +41,7 @@ impl Text { } pub fn Constructor(owner: &JSRef, text: DOMString) -> Fallible> { - let roots = RootCollection::new(); - let document = owner.Document().root(&roots); + let document = owner.Document().root(); Ok(Text::new(text.clone(), &*document)) } } diff --git a/src/components/script/dom/uievent.rs b/src/components/script/dom/uievent.rs index 03140504400..90e4daa872b 100644 --- a/src/components/script/dom/uievent.rs +++ b/src/components/script/dom/uievent.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::UIEventBinding; use dom::bindings::codegen::InheritTypes::{EventCast, UIEventDerived}; -use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Temporary}; +use dom::bindings::js::{JS, JSRef, RootedReference, Temporary}; use dom::bindings::error::Fallible; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::event::{Event, EventMethods, EventTypeId, UIEventTypeId}; @@ -45,9 +45,8 @@ impl UIEvent { pub fn Constructor(owner: &JSRef, type_: DOMString, init: &UIEventBinding::UIEventInit) -> Fallible> { - let roots = RootCollection::new(); - let mut ev = UIEvent::new(owner).root(&roots); - let view = init.view.as_ref().map(|view| view.root(&roots)); + let mut ev = UIEvent::new(owner).root(); + let view = init.view.as_ref().map(|view| view.root()); ev.InitUIEvent(type_, init.parent.bubbles, init.parent.cancelable, view.root_ref(), init.detail); Ok(Temporary::new_rooted(&*ev)) diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index a0490c1621f..452f1c8640b 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -5,7 +5,7 @@ use dom::attr::AttrMethods; use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, TextCast, ElementCast}; use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalRootable, Root}; +use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootable, Root}; use dom::bindings::utils::Reflectable; use dom::document::{Document, DocumentHelpers}; use dom::element::{AttributeHandlers, HTMLLinkElementTypeId, HTMLIFrameElementTypeId}; @@ -76,21 +76,17 @@ pub struct HtmlParserResult { } trait NodeWrapping { - unsafe fn to_hubbub_node(&self, roots: &RootCollection) -> hubbub::NodeDataPtr; + unsafe fn to_hubbub_node(&self) -> hubbub::NodeDataPtr; } impl<'a, T: NodeBase+Reflectable> NodeWrapping for JSRef<'a, T> { - unsafe fn to_hubbub_node(&self, roots: &RootCollection) -> hubbub::NodeDataPtr { - roots.root_raw(self.reflector().get_jsobject()); + unsafe fn to_hubbub_node(&self) -> hubbub::NodeDataPtr { cast::transmute(self.get()) } } -unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr, - roots: Option<&RootCollection>) -> Temporary { - let js = JS::from_raw(cast::transmute(n)); - let _ = roots.map(|roots| roots.unroot_raw(js.reflector().get_jsobject())); - Temporary::new(js) +unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr) -> Temporary { + Temporary::new(JS::from_raw(cast::transmute(n))) } /** @@ -297,9 +293,8 @@ pub fn parse_html(page: &Page, let mut parser = hubbub::Parser("UTF-8", false); debug!("created parser"); - let roots = RootCollection::new(); - parser.set_document_node(unsafe { document.to_hubbub_node(&roots) }); + parser.set_document_node(unsafe { document.to_hubbub_node() }); parser.enable_scripting(true); parser.enable_styling(true); @@ -315,9 +310,9 @@ pub fn parse_html(page: &Page, // NOTE: tmp vars are workaround for lifetime issues. Both required. let tmp_borrow = doc_cell.borrow(); let tmp = &*tmp_borrow; - let comment = Comment::new(data, *tmp).root(&roots); + let comment = Comment::new(data, *tmp).root(); let comment: &JSRef = NodeCast::from_ref(&*comment); - unsafe { comment.to_hubbub_node(&roots) } + unsafe { comment.to_hubbub_node() } }, create_doctype: |doctype: ~hubbub::Doctype| { debug!("create doctype"); @@ -328,9 +323,9 @@ pub fn parse_html(page: &Page, // NOTE: tmp vars are workaround for lifetime issues. Both required. let tmp_borrow = doc_cell.borrow(); let tmp = &*tmp_borrow; - let doctype_node = DocumentType::new(name, public_id, system_id, *tmp).root(&roots); + let doctype_node = DocumentType::new(name, public_id, system_id, *tmp).root(); unsafe { - doctype_node.deref().to_hubbub_node(&roots) + doctype_node.deref().to_hubbub_node() } }, create_element: |tag: ~hubbub::Tag| { @@ -338,7 +333,7 @@ pub fn parse_html(page: &Page, // NOTE: tmp vars are workaround for lifetime issues. Both required. let tmp_borrow = doc_cell.borrow(); let tmp = &*tmp_borrow; - let mut element = build_element_from_tag(tag.name.clone(), *tmp).root(&roots); + let mut element = build_element_from_tag(tag.name.clone(), *tmp).root(); debug!("-- attach attrs"); for attr in tag.attributes.iter() { @@ -351,15 +346,15 @@ pub fn parse_html(page: &Page, //FIXME: workaround for https://github.com/mozilla/rust/issues/13246; // we get unrooting order failures if these are inside the match. let rel = { - let rel = element.get_attribute(Null, "rel").root(&roots); + let rel = element.get_attribute(Null, "rel").root(); rel.map(|a| a.deref().Value()) }; let href = { - let href= element.get_attribute(Null, "href").root(&roots); + let href= element.get_attribute(Null, "href").root(); href.map(|a| a.deref().Value()) }; let src_opt = { - let src_opt = element.get_attribute(Null, "src").root(&roots); + let src_opt = element.get_attribute(Null, "src").root(); src_opt.map(|a| a.deref().Value()) }; @@ -410,23 +405,23 @@ pub fn parse_html(page: &Page, _ => {} } - unsafe { element.to_hubbub_node(&roots) } + unsafe { element.to_hubbub_node() } }, create_text: |data: ~str| { debug!("create text"); // NOTE: tmp vars are workaround for lifetime issues. Both required. let tmp_borrow = doc_cell.borrow(); let tmp = &*tmp_borrow; - let text = Text::new(data, *tmp).root(&roots); - unsafe { text.deref().to_hubbub_node(&roots) } + let text = Text::new(data, *tmp).root(); + unsafe { text.deref().to_hubbub_node() } }, ref_node: |_| {}, unref_node: |_| {}, append_child: |parent: hubbub::NodeDataPtr, child: hubbub::NodeDataPtr| { unsafe { debug!("append child {:x} {:x}", parent, child); - let mut child = from_hubbub_node(child, Some(&roots)).root(&roots); - let mut parent: Root = from_hubbub_node(parent, None).root(&roots); + let mut child = from_hubbub_node(child).root(); + let mut parent: Root = from_hubbub_node(parent).root(); assert!(parent.AppendChild(&mut *child).is_ok()); } child @@ -478,8 +473,8 @@ pub fn parse_html(page: &Page, }, complete_script: |script| { unsafe { - let script: &JSRef = &*from_hubbub_node(script, None).root(&roots); - match script.get_attribute(Null, "src").root(&roots) { + let script: &JSRef = &*from_hubbub_node(script).root(); + match script.get_attribute(Null, "src").root() { Some(src) => { debug!("found script: {:s}", src.deref().Value()); let new_url = parse_url(src.get().value_ref(), Some(url3.clone())); diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index 2bfe058cc65..fe609cfc467 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -278,12 +278,11 @@ impl Page { /// Adds the given damage. pub fn damage(&self, level: DocumentDamageLevel) { - let roots = RootCollection::new(); let root = match *self.frame() { None => return, - Some(ref frame) => frame.document.root(&roots).GetDocumentElement() + Some(ref frame) => frame.document.root().GetDocumentElement() }; - match root.root(&roots) { + match root.root() { None => {}, Some(root) => { let root: &JSRef = NodeCast::from_ref(&*root); @@ -358,16 +357,15 @@ impl Page { goal: ReflowGoal, script_chan: ScriptChan, compositor: &ScriptListener) { - let roots = RootCollection::new(); let root = match *self.frame() { None => return, Some(ref frame) => { - frame.document.root(&roots).GetDocumentElement() + frame.document.root().GetDocumentElement() } }; - match root.root(&roots) { + match root.root() { None => {}, Some(root) => { debug!("script: performing reflow for goal {:?}", goal); @@ -411,17 +409,16 @@ impl Page { } fn find_fragment_node(&self, fragid: ~str) -> Option> { - let roots = RootCollection::new(); - let document = self.frame().get_ref().document.root(&roots); + let document = self.frame().get_ref().document.root(); match document.deref().GetElementById(fragid.to_owned()) { Some(node) => Some(node), None => { let doc_node: &JSRef = NodeCast::from_ref(&*document); - let mut anchors = doc_node.traverse_preorder(&roots) + let mut anchors = doc_node.traverse_preorder() .filter(|node| node.is_anchor_element()); anchors.find(|node| { let elem: &JSRef = ElementCast::to_ref(node).unwrap(); - elem.get_attribute(Null, "name").root(&roots).map_or(false, |attr| { + elem.get_attribute(Null, "name").root().map_or(false, |attr| { attr.get().value_ref() == fragid }) }).map(|node| Temporary::new_rooted(ElementCast::to_ref(&node).unwrap())) @@ -450,10 +447,9 @@ impl Page { } pub fn hit_test(&self, point: &Point2D) -> Option { - let roots = RootCollection::new(); let frame = self.frame(); - let document = frame.get_ref().document.root(&roots); - let root = document.deref().GetDocumentElement().root(&roots); + let document = frame.get_ref().document.root(); + let root = document.deref().GetDocumentElement().root(); if root.is_none() { return None; } @@ -473,10 +469,9 @@ impl Page { } pub fn get_nodes_under_mouse(&self, point: &Point2D) -> Option> { - let roots = RootCollection::new(); let frame = self.frame(); - let document = frame.get_ref().document.root(&roots); - let root = document.deref().GetDocumentElement().root(&roots); + let document = frame.get_ref().document.root(); + let root = document.deref().GetDocumentElement().root(); if root.is_none() { return None; } @@ -763,13 +758,12 @@ impl ScriptTask { /// Handles a timer that fired. fn handle_fire_timer_msg(&self, id: PipelineId, timer_id: TimerId) { - let roots = RootCollection::new(); let mut page_tree = self.page_tree.borrow_mut(); let page = page_tree.find(id).expect("ScriptTask: received fire timer msg for a pipeline ID not associated with this script task. This is a bug.").page(); let frame = page.frame(); - let mut window = frame.get_ref().window.root(&roots); + let mut window = frame.get_ref().window.root(); let is_interval; match window.get().active_timers.find(&timer_id) { @@ -880,7 +874,6 @@ impl ScriptTask { fn load(&self, pipeline_id: PipelineId, url: Url) { debug!("ScriptTask: loading {:?} on page {:?}", url, pipeline_id); - let roots = RootCollection::new(); let mut page_tree = self.page_tree.borrow_mut(); let page_tree = page_tree.find(pipeline_id).expect("ScriptTask: received a load @@ -907,9 +900,9 @@ impl ScriptTask { page_tree.page.clone(), self.chan.clone(), self.compositor.dup(), - self.image_cache_task.clone()).root(&roots); + self.image_cache_task.clone()).root(); page.initialize_js_info(cx.clone(), window.reflector().get_jsobject()); - let mut document = Document::new(&*window, Some(url.clone()), HTMLDocument, None).root(&roots); + let mut document = Document::new(&*window, Some(url.clone()), HTMLDocument, None).root(); window.get_mut().init_browser_context(&*document); { @@ -1010,7 +1003,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 mut event = Event::new(&*window).root(&roots); + let mut event = Event::new(&*window).root(); event.InitEvent(~"load", false, false); let doctarget: &JSRef = EventTargetCast::from_ref(&*document); let wintarget: &JSRef = EventTargetCast::from_ref(&*window); @@ -1048,7 +1041,6 @@ impl ScriptTask { match event { ResizeEvent(new_width, new_height) => { - let roots = RootCollection::new(); debug!("script got resize event: {:u}, {:u}", new_width, new_height); let window = { @@ -1066,7 +1058,7 @@ impl ScriptTask { } let mut fragment_node = page.fragment_node.deref().borrow_mut(); - match fragment_node.take().map(|node| node.root(&roots)) { + match fragment_node.take().map(|node| node.root()) { Some(node) => self.scroll_fragment_point(pipeline_id, &*node), None => {} } @@ -1074,11 +1066,11 @@ impl ScriptTask { frame.as_ref().map(|frame| Temporary::new(frame.window.clone())) }; - match window.root(&roots) { + match window.root() { Some(mut window) => { // http://dev.w3.org/csswg/cssom-view/#resizing-viewports // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-resize - let mut uievent = UIEvent::new(&*window).root(&roots); + let mut uievent = UIEvent::new(&*window).root(); uievent.InitUIEvent(~"resize", false, false, Some((*window).clone()), 0i32); let event: &mut JSRef = EventCast::from_mut_ref(&mut *uievent); @@ -1104,7 +1096,6 @@ impl ScriptTask { } ClickEvent(_button, point) => { - let roots = RootCollection::new(); debug!("ClickEvent: clicked at {:?}", point); let mut page_tree = self.page_tree.borrow_mut(); let page = get_page(&mut *page_tree, pipeline_id); @@ -1113,14 +1104,14 @@ impl ScriptTask { debug!("node address is {:?}", node_address); let mut node = node::from_untrusted_node_address(self.js_runtime.deref().ptr, - node_address).root(&roots); + node_address).root(); debug!("clicked on {:s}", node.deref().debug_str()); // Traverse node generations until a node that is an element is // found. while !node.deref().is_element() { match node.deref().parent_node() { - Some(parent) => node = parent.root(&roots), + Some(parent) => node = parent.root(), None => break, } } @@ -1139,7 +1130,6 @@ impl ScriptTask { MouseDownEvent(..) => {} MouseUpEvent(..) => {} MouseMoveEvent(point) => { - let roots = RootCollection::new(); let mut page_tree = self.page_tree.borrow_mut(); let page = get_page(&mut *page_tree, pipeline_id); match page.get_nodes_under_mouse(&point) { @@ -1152,7 +1142,7 @@ impl ScriptTask { match *mouse_over_targets { Some(ref mut mouse_over_targets) => { for node in mouse_over_targets.mut_iter() { - let mut node = node.root(&roots); + let mut node = node.root(); node.set_hover_state(false); } } @@ -1162,12 +1152,12 @@ impl ScriptTask { for node_address in node_address.iter() { let mut node = node::from_untrusted_node_address( - self.js_runtime.deref().ptr, *node_address).root(&roots); + self.js_runtime.deref().ptr, *node_address).root(); // Traverse node generations until a node that is an element is // found. while !node.is_element() { match node.parent_node() { - Some(parent) => node = parent.root(&roots), + Some(parent) => node = parent.root(), None => break, } } @@ -1211,10 +1201,9 @@ impl ScriptTask { } fn load_url_from_element(&self, page: &Page, element: &JSRef) { - let roots = RootCollection::new(); // if the node's element is "a," load url from href attr let attr = element.get_attribute(Null, "href"); - for href in attr.root(&roots).iter() { + for href in attr.root().iter() { debug!("ScriptTask: clicked on link to {:s}", href.Value()); let click_frag = href.get().value_ref().starts_with("#"); let base_url = Some(page.get_url()); @@ -1222,7 +1211,7 @@ impl ScriptTask { let url = parse_url(href.get().value_ref(), base_url); if click_frag { - match page.find_fragment_node(url.fragment.unwrap()).root(&roots) { + match page.find_fragment_node(url.fragment.unwrap()).root() { Some(node) => self.scroll_fragment_point(page.id, &*node), None => {} } From 0f2d0b1dc3d98ef109627dda061c5a54ff06a91d Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Fri, 18 Apr 2014 00:12:52 -0400 Subject: [PATCH 13/16] Address review comments. --- src/components/script/dom/attrlist.rs | 10 +- .../dom/bindings/codegen/CodegenRust.py | 22 +---- .../dom/bindings/codegen/Configuration.py | 1 + src/components/script/dom/bindings/js.rs | 97 ++++++++++++------- src/components/script/dom/bindings/utils.rs | 3 + src/components/script/dom/blob.rs | 6 +- src/components/script/dom/characterdata.rs | 4 +- src/components/script/dom/clientrect.rs | 6 +- src/components/script/dom/clientrectlist.rs | 6 +- src/components/script/dom/comment.rs | 6 +- src/components/script/dom/document.rs | 34 ++++--- src/components/script/dom/documentfragment.rs | 6 +- src/components/script/dom/documenttype.rs | 6 +- .../script/dom/domimplementation.rs | 10 +- src/components/script/dom/domparser.rs | 6 +- src/components/script/dom/element.rs | 12 +-- src/components/script/dom/event.rs | 2 +- src/components/script/dom/eventdispatcher.rs | 2 +- src/components/script/dom/formdata.rs | 6 +- .../script/dom/htmlanchorelement.rs | 6 +- .../script/dom/htmlappletelement.rs | 6 +- src/components/script/dom/htmlareaelement.rs | 6 +- src/components/script/dom/htmlaudioelement.rs | 6 +- src/components/script/dom/htmlbaseelement.rs | 6 +- src/components/script/dom/htmlbodyelement.rs | 6 +- src/components/script/dom/htmlbrelement.rs | 6 +- .../script/dom/htmlbuttonelement.rs | 10 +- .../script/dom/htmlcanvaselement.rs | 6 +- src/components/script/dom/htmlcollection.rs | 12 +-- src/components/script/dom/htmldataelement.rs | 6 +- .../script/dom/htmldatalistelement.rs | 6 +- .../script/dom/htmldirectoryelement.rs | 6 +- src/components/script/dom/htmldivelement.rs | 6 +- src/components/script/dom/htmldlistelement.rs | 6 +- src/components/script/dom/htmlelement.rs | 6 +- src/components/script/dom/htmlembedelement.rs | 6 +- .../script/dom/htmlfieldsetelement.rs | 6 +- src/components/script/dom/htmlfontelement.rs | 6 +- src/components/script/dom/htmlformelement.rs | 6 +- src/components/script/dom/htmlframeelement.rs | 6 +- .../script/dom/htmlframesetelement.rs | 6 +- src/components/script/dom/htmlheadelement.rs | 6 +- .../script/dom/htmlheadingelement.rs | 6 +- src/components/script/dom/htmlhrelement.rs | 6 +- src/components/script/dom/htmlhtmlelement.rs | 6 +- .../script/dom/htmliframeelement.rs | 6 +- src/components/script/dom/htmlimageelement.rs | 4 +- src/components/script/dom/htmlinputelement.rs | 6 +- src/components/script/dom/htmllabelelement.rs | 6 +- .../script/dom/htmllegendelement.rs | 6 +- src/components/script/dom/htmllielement.rs | 6 +- src/components/script/dom/htmllinkelement.rs | 6 +- src/components/script/dom/htmlmainelement.rs | 6 +- src/components/script/dom/htmlmapelement.rs | 6 +- src/components/script/dom/htmlmediaelement.rs | 4 +- src/components/script/dom/htmlmetaelement.rs | 6 +- src/components/script/dom/htmlmeterelement.rs | 6 +- src/components/script/dom/htmlmodelement.rs | 6 +- .../script/dom/htmlobjectelement.rs | 6 +- src/components/script/dom/htmlolistelement.rs | 6 +- .../script/dom/htmloptgroupelement.rs | 6 +- .../script/dom/htmloptionelement.rs | 6 +- .../script/dom/htmloutputelement.rs | 10 +- .../script/dom/htmlparagraphelement.rs | 6 +- src/components/script/dom/htmlparamelement.rs | 6 +- src/components/script/dom/htmlpreelement.rs | 6 +- .../script/dom/htmlprogresselement.rs | 6 +- src/components/script/dom/htmlquoteelement.rs | 6 +- .../script/dom/htmlscriptelement.rs | 6 +- .../script/dom/htmlselectelement.rs | 10 +- .../script/dom/htmlsourceelement.rs | 6 +- src/components/script/dom/htmlspanelement.rs | 6 +- src/components/script/dom/htmlstyleelement.rs | 6 +- .../script/dom/htmltablecaptionelement.rs | 6 +- .../script/dom/htmltablecellelement.rs | 4 +- .../script/dom/htmltablecolelement.rs | 6 +- .../script/dom/htmltabledatacellelement.rs | 6 +- src/components/script/dom/htmltableelement.rs | 6 +- .../script/dom/htmltableheadercellelement.rs | 6 +- .../script/dom/htmltablerowelement.rs | 6 +- .../script/dom/htmltablesectionelement.rs | 6 +- .../script/dom/htmltemplateelement.rs | 6 +- .../script/dom/htmltextareaelement.rs | 6 +- src/components/script/dom/htmltimeelement.rs | 6 +- src/components/script/dom/htmltitleelement.rs | 6 +- src/components/script/dom/htmltrackelement.rs | 6 +- src/components/script/dom/htmlulistelement.rs | 6 +- .../script/dom/htmlunknownelement.rs | 6 +- src/components/script/dom/htmlvideoelement.rs | 6 +- src/components/script/dom/mouseevent.rs | 6 +- src/components/script/dom/node.rs | 41 ++++---- src/components/script/dom/nodelist.rs | 8 +- .../script/dom/processinginstruction.rs | 6 +- src/components/script/dom/text.rs | 6 +- src/components/script/dom/uievent.rs | 6 +- src/components/script/dom/validitystate.rs | 6 +- src/components/script/dom/window.rs | 4 +- src/components/script/dom/xmlhttprequest.rs | 2 +- src/components/script/script_task.rs | 6 +- 99 files changed, 388 insertions(+), 380 deletions(-) diff --git a/src/components/script/dom/attrlist.rs b/src/components/script/dom/attrlist.rs index 70db8f59971..e707a42b13f 100644 --- a/src/components/script/dom/attrlist.rs +++ b/src/components/script/dom/attrlist.rs @@ -17,16 +17,16 @@ pub struct AttrList { } impl AttrList { - pub fn new_inherited(window: JS, elem: JS) -> AttrList { + pub fn new_inherited(window: &JSRef, elem: &JSRef) -> AttrList { AttrList { reflector_: Reflector::new(), - window: window, - owner: elem + window: window.unrooted(), + owner: elem.unrooted(), } } pub fn new(window: &JSRef, elem: &JSRef) -> Temporary { - reflect_dom_object(~AttrList::new_inherited(window.unrooted(), elem.unrooted()), + reflect_dom_object(~AttrList::new_inherited(window, elem), window, AttrListBinding::Wrap) } } @@ -37,7 +37,7 @@ pub trait AttrListMethods { fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option>; } -impl<'a> AttrListMethods for JSRef<'a, AttrList> { +impl<'a> AttrListMethods for JSRef<'a, AttrList> { fn Length(&self) -> u32 { self.owner.root().attrs.len() as u32 } diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 8472686e536..1aa46c6a44a 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -558,15 +558,6 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, else: assert(defaultValue is None) - #if type.isGeckoInterface() and not type.unroll().inner.isCallback(): - # if type.nullable() or isOptional: - # - # else: - # - # templateBody = CGList([CGGeneric(templateBody), - # CGGeneric("\n"), - # CGGeneric(rootBody)]).define() - return templateBody assert not (isEnforceRange and isClamp) # These are mutually exclusive @@ -901,12 +892,7 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements, type = declType.define() if declType else None if type and 'JS<' in type: - if dealWithOptional or 'Option<' in type: - rootBody = """let ${simpleDeclName} = ${declName}.as_ref().map(|inner| { - inner.root() //second root code -});""" - else: - rootBody = "let ${simpleDeclName} = ${declName}.root(); //third root code" + rootBody = "let ${simpleDeclName} = ${declName}.root();" result.append(CGGeneric(string.Template(rootBody).substitute(replacements))) result.append(CGGeneric("")) @@ -1725,8 +1711,6 @@ class Argument(): A class for outputting the type and name of an argument """ def __init__(self, argType, name, default=None, mutable=False): - if argType and 'JS<' in argType: - argType = argType.replace('JS<', 'JSRef<') self.argType = argType self.name = name self.default = default @@ -4321,7 +4305,7 @@ class CGBindingRoot(CGThing): 'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}', 'dom::types::*', 'dom::bindings', - 'dom::bindings::js::{JS, JSRef, RootedReference, Temporary, OptionalRootable}', + 'dom::bindings::js::{JS, JSRef, RootedReference, Temporary, OptionalRootable, OptionalRootedRootable}', 'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}', 'dom::bindings::utils::{ConstantSpec, cx_for_dom_object, Default}', 'dom::bindings::utils::{dom_object_slot, DOM_OBJECT_SLOT, DOMClass}', @@ -4603,7 +4587,7 @@ class CGNativeMember(ClassMethod): else: typeDecl = "%s" descriptor = self.descriptorProvider.getDescriptor(iface.identifier.name) - return (typeDecl % descriptor.nativeType, + return (typeDecl % descriptor.argumentType, False, False) if type.isSpiderMonkeyInterface(): diff --git a/src/components/script/dom/bindings/codegen/Configuration.py b/src/components/script/dom/bindings/codegen/Configuration.py index 0ff1754a562..c5b9ebb1044 100644 --- a/src/components/script/dom/bindings/codegen/Configuration.py +++ b/src/components/script/dom/bindings/codegen/Configuration.py @@ -134,6 +134,7 @@ class Descriptor(DescriptorProvider): nativeTypeDefault = 'JS<%s>' % ifaceName self.returnType = "Temporary<%s>" % ifaceName + self.argumentType = "JSRef<%s>" % ifaceName self.nativeType = desc.get('nativeType', nativeTypeDefault) self.concreteType = desc.get('concreteType', ifaceName) self.createGlobal = desc.get('createGlobal', False) diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs index 1ee1b8da51d..37694e3beb1 100644 --- a/src/components/script/dom/bindings/js.rs +++ b/src/components/script/dom/bindings/js.rs @@ -2,6 +2,43 @@ * 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 DOM is made up of Rust types whose lifetime is entirely controlled by the whims of +/// the SpiderMonkey garbage collector. The types in this module are designed to ensure +/// that any interactions with said Rust types only occur on values that will remain alive +/// the entire time. +/// +/// Here is a brief overview of the important types: +/// - JSRef: a freely-copyable reference to a rooted value. +/// - JS: a pointer to JS-owned memory that can automatically be traced by the GC when +/// encountered as a field of a Rust structure. +/// - Temporary: a value that will remain rooted for the duration of its lifetime. +/// +/// The rule of thumb is as follows: +/// - All methods return Temporary, to ensure the value remains alive until it is stored +/// somewhere that is reachable by the GC. +/// - All functions take &JSRef arguments, to ensure that they will remain uncollected for +/// the duration of their usage. +/// - All types contain JS fields and derive the Encodable trait, to ensure that they are +/// transitively marked as reachable by the GC if the enclosing value is reachable. +/// - All methods for type T are implemented for JSRef, to ensure that the self value +/// will not be collected for the duration of the method call. +/// +/// Both Temporary and JS do not allow access to their inner value without explicitly +/// creating a stack-based root via the `root` method. This returns a Root, which causes +/// the JS-owned value to be uncollectable for the duration of the Root type's lifetime. +/// A JSRef can be obtained from a Root either by dereferencing the Root (`*rooted`) +/// or explicitly calling the `root_ref` method. These JSRef values are not allowed to +/// outlive their originating Root, to ensure that all interactions with the enclosed value +/// only occur when said value is uncollectable, and will cause static lifetime errors if +/// misused. +/// +/// Other miscellaneous helper traits: +/// - OptionalRootable and OptionalRootedRootable: make rooting Option values easy via a `root` method +/// - ResultRootable: make rooting successful Result values easy +/// - TemporaryPushable: allows mutating vectors of JS with new elements of JSRef/Temporary +/// - OptionalSettable: allows assigning Option values of JSRef/Temporary to fields of Option> +/// - RootedReference: makes obtaining an Option> from an Option> easy + use dom::bindings::utils::{Reflector, Reflectable, cx_for_dom_object}; use dom::window::Window; use js::jsapi::{JSObject, JSContext, JS_AddObjectRoot, JS_RemoveObjectRoot}; @@ -15,7 +52,7 @@ use std::local_data; /// A type that represents a JS-owned value that is rooted for the lifetime of this value. /// Importantly, it requires explicit rooting in order to interact with the inner value. /// Can be assigned into JS-owned member fields (ie. JS types) safely via the -/// `JS::assign` method or `OptionalAssignable::assign` (for Option> fields). +/// `JS::assign` method or `OptionalSettable::assign` (for Option> fields). pub struct Temporary { inner: JS, } @@ -49,7 +86,7 @@ impl Temporary { } /// Create a new Temporary value from a rooted value. - pub fn new_rooted<'a>(root: &JSRef<'a, T>) -> Temporary { + pub fn from_rooted<'a>(root: &JSRef<'a, T>) -> Temporary { Temporary::new(root.unrooted()) } @@ -182,39 +219,38 @@ impl<'a, 'b, T: Reflectable> RootedReference for Option> { } } -// This trait should never be public; it allows access to unrooted values, and is thus -// easy to misuse. +/// Trait that allows extracting a JS value from a variety of rooting-related containers, +/// which in general is an unsafe operation since they can outlive the rooted lifetime of the +/// original value. /*definitely not public*/ trait Assignable { - fn get_js(&self) -> JS; + unsafe fn get_js(&self) -> JS; } impl Assignable for JS { - fn get_js(&self) -> JS { + unsafe fn get_js(&self) -> JS { self.clone() } } impl<'a, T> Assignable for JSRef<'a, T> { - fn get_js(&self) -> JS { + unsafe fn get_js(&self) -> JS { self.unrooted() } } -// Assignable should not be exposed publically, since it's used to -// extract unrooted values in a safe way WHEN USED CORRECTLY. impl Assignable for Temporary { - fn get_js(&self) -> JS { - unsafe { self.inner() } + unsafe fn get_js(&self) -> JS { + self.inner() } } -pub trait OptionalAssignable { +pub trait OptionalSettable { fn assign(&mut self, val: Option); } -impl, U: Reflectable> OptionalAssignable for Option> { +impl, U: Reflectable> OptionalSettable for Option> { fn assign(&mut self, val: Option) { - *self = val.map(|val| val.get_js()); + *self = val.map(|val| unsafe { val.get_js() }); } } @@ -252,12 +288,17 @@ impl ResultRootable for Result, U> { /// under the assumption that said lists are reachable via the GC graph, and therefore the /// new values are transitively rooted for the lifetime of their new owner. pub trait TemporaryPushable { - fn push_unrooted(&mut self, val: Temporary); + fn push_unrooted(&mut self, val: &T); + fn insert_unrooted(&mut self, index: uint, val: &T); } -impl TemporaryPushable for Vec> { - fn push_unrooted(&mut self, val: Temporary) { - unsafe { self.push(val.inner()) }; +impl, U: Reflectable> TemporaryPushable for Vec> { + fn push_unrooted(&mut self, val: &T) { + self.push(unsafe { val.get_js() }); + } + + fn insert_unrooted(&mut self, index: uint, val: &T) { + self.insert(index, unsafe { val.get_js() }); } } @@ -277,26 +318,16 @@ impl RootCollection { Root::new(self, unrooted) } - fn root<'a, 'b, T: Reflectable>(&self, unrooted: &Root<'a, 'b, T>) { - self.root_raw(unrooted.js_ptr); - } - - /// Root a raw JS pointer. - pub fn root_raw(&self, unrooted: *JSObject) { + fn root<'a, 'b, T: Reflectable>(&self, untracked: &Root<'a, 'b, T>) { let mut roots = self.roots.borrow_mut(); - roots.push(unrooted); - debug!(" rooting {:?}", unrooted); + roots.push(untracked.js_ptr); + debug!(" rooting {:?}", untracked.js_ptr); } fn unroot<'a, 'b, T: Reflectable>(&self, rooted: &Root<'a, 'b, T>) { - self.unroot_raw(rooted.js_ptr); - } - - /// Unroot a raw JS pointer. Must occur in reverse order to its rooting. - pub fn unroot_raw(&self, rooted: *JSObject) { let mut roots = self.roots.borrow_mut(); - debug!("unrooting {:?} (expecting {:?}", roots.last().unwrap(), rooted); - assert!(*roots.last().unwrap() == rooted); + debug!("unrooting {:?} (expecting {:?}", roots.last().unwrap(), rooted.js_ptr); + assert!(*roots.last().unwrap() == rooted.js_ptr); roots.pop().unwrap(); } } diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index 7c74a8b8085..28f75073da2 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -412,6 +412,9 @@ impl Reflector { self.object = object; } + /// Return a pointer to the memory location at which the JS reflector object is stored. + /// Used by Temporary values to root the reflector, as required by the JSAPI rooting + /// APIs. pub fn rootable(&self) -> **JSObject { &self.object as **JSObject } diff --git a/src/components/script/dom/blob.rs b/src/components/script/dom/blob.rs index 9df9287bc9f..ff5958478b6 100644 --- a/src/components/script/dom/blob.rs +++ b/src/components/script/dom/blob.rs @@ -16,15 +16,15 @@ pub struct Blob { } impl Blob { - pub fn new_inherited(window: JS) -> Blob { + pub fn new_inherited(window: &JSRef) -> Blob { Blob { reflector_: Reflector::new(), - window: window + window: window.unrooted() } } pub fn new(window: &JSRef) -> Temporary { - reflect_dom_object(~Blob::new_inherited(window.unrooted()), + reflect_dom_object(~Blob::new_inherited(window), window, BlobBinding::Wrap) } diff --git a/src/components/script/dom/characterdata.rs b/src/components/script/dom/characterdata.rs index 44962eea8a9..2a41e1fee3b 100644 --- a/src/components/script/dom/characterdata.rs +++ b/src/components/script/dom/characterdata.rs @@ -5,7 +5,7 @@ //! DOM bindings for `CharacterData`. use dom::bindings::codegen::InheritTypes::CharacterDataDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::JSRef; use dom::bindings::error::{Fallible, ErrorResult, IndexSize}; use dom::bindings::utils::{Reflectable, Reflector}; use dom::document::Document; @@ -31,7 +31,7 @@ impl CharacterDataDerived for EventTarget { } impl CharacterData { - pub fn new_inherited(id: NodeTypeId, data: DOMString, document: JS) -> CharacterData { + pub fn new_inherited(id: NodeTypeId, data: DOMString, document: &JSRef) -> CharacterData { CharacterData { node: Node::new_inherited(id, document), data: data diff --git a/src/components/script/dom/clientrect.rs b/src/components/script/dom/clientrect.rs index ad48fe15d86..316269bfc56 100644 --- a/src/components/script/dom/clientrect.rs +++ b/src/components/script/dom/clientrect.rs @@ -19,7 +19,7 @@ pub struct ClientRect { } impl ClientRect { - pub fn new_inherited(window: JS, + pub fn new_inherited(window: &JSRef, top: Au, bottom: Au, left: Au, right: Au) -> ClientRect { ClientRect { @@ -28,14 +28,14 @@ impl ClientRect { left: left.to_nearest_px() as f32, right: right.to_nearest_px() as f32, reflector_: Reflector::new(), - window: window, + window: window.unrooted(), } } pub fn new(window: &JSRef, top: Au, bottom: Au, left: Au, right: Au) -> Temporary { - let rect = ClientRect::new_inherited(window.unrooted(), top, bottom, left, right); + let rect = ClientRect::new_inherited(window, top, bottom, left, right); reflect_dom_object(~rect, window, ClientRectBinding::Wrap) } } diff --git a/src/components/script/dom/clientrectlist.rs b/src/components/script/dom/clientrectlist.rs index 2a7c609c958..d48cfadf2d7 100644 --- a/src/components/script/dom/clientrectlist.rs +++ b/src/components/script/dom/clientrectlist.rs @@ -16,18 +16,18 @@ pub struct ClientRectList { } impl ClientRectList { - pub fn new_inherited(window: JS, + pub fn new_inherited(window: &JSRef, rects: Vec>) -> ClientRectList { ClientRectList { reflector_: Reflector::new(), rects: rects.iter().map(|rect| rect.unrooted()).collect(), - window: window, + window: window.unrooted(), } } pub fn new(window: &JSRef, rects: Vec>) -> Temporary { - reflect_dom_object(~ClientRectList::new_inherited(window.unrooted(), rects), + reflect_dom_object(~ClientRectList::new_inherited(window, rects), window, ClientRectListBinding::Wrap) } } diff --git a/src/components/script/dom/comment.rs b/src/components/script/dom/comment.rs index 5d2fce2d212..0e314324e57 100644 --- a/src/components/script/dom/comment.rs +++ b/src/components/script/dom/comment.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::CommentDerived; use dom::bindings::codegen::BindingDeclarations::CommentBinding; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::Fallible; use dom::characterdata::CharacterData; use dom::document::Document; @@ -29,14 +29,14 @@ impl CommentDerived for EventTarget { } impl Comment { - pub fn new_inherited(text: DOMString, document: JS) -> Comment { + pub fn new_inherited(text: DOMString, document: &JSRef) -> Comment { Comment { characterdata: CharacterData::new_inherited(CommentNodeTypeId, text, document) } } pub fn new(text: DOMString, document: &JSRef) -> Temporary { - let node = Comment::new_inherited(text, document.unrooted()); + let node = Comment::new_inherited(text, document); Node::reflect_node(~node, document, CommentBinding::Wrap) } diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index 6ba18526127..d858f470fee 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::InheritTypes::{DocumentDerived, EventCast, HTMLEleme use dom::bindings::codegen::InheritTypes::{HTMLHeadElementCast, TextCast, ElementCast}; use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, HTMLHtmlElementCast, NodeCast}; use dom::bindings::codegen::BindingDeclarations::DocumentBinding; -use dom::bindings::js::{JS, JSRef, Temporary, OptionalAssignable}; +use dom::bindings::js::{JS, JSRef, Temporary, OptionalSettable, TemporaryPushable}; use dom::bindings::js::OptionalRootable; use dom::bindings::trace::Untraceable; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; @@ -160,7 +160,7 @@ impl<'a> DocumentHelpers for JSRef<'a, Document> { let elem: Option<&JSRef> = ElementCast::to_ref(&node); match elem { Some(elem) => { - if elements.get(head) == &elem.unrooted() { + if &*elements.get(head).root() == elem { head = head + 1; } if new_node == &node || head == elements.len() { @@ -170,19 +170,21 @@ impl<'a> DocumentHelpers for JSRef<'a, Document> { None => {} } } - elements.insert(head, element.unrooted()); + elements.insert_unrooted(head, element); return; }, None => (), } - self.idmap.insert(id, vec!(element.unrooted())); + let mut elements = vec!(); + elements.push_unrooted(element); + self.idmap.insert(id, elements); } } impl Document { pub fn reflect_document(document: ~Document, - window: &JSRef, - wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~Document) -> JS) + window: &JSRef, + wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~Document) -> JS) -> Temporary { assert!(document.reflector().get_jsobject().is_null()); let mut raw_doc = reflect_dom_object(document, window, wrap_fn).root(); @@ -191,10 +193,10 @@ impl Document { let mut doc_alias = raw_doc.clone(); let node: &mut JSRef = NodeCast::from_mut_ref(&mut doc_alias); node.set_owner_doc(&*raw_doc); - Temporary::new_rooted(&*raw_doc) + Temporary::from_rooted(&*raw_doc) } - pub fn new_inherited(window: JS, + pub fn new_inherited(window: &JSRef, url: Option, is_html_document: IsHTMLDocument, content_type: Option) -> Document { @@ -203,7 +205,7 @@ impl Document { Document { node: Node::new_without_doc(DocumentNodeTypeId), reflector_: Reflector::new(), - window: window, + window: window.unrooted(), idmap: HashMap::new(), implementation: None, content_type: match content_type { @@ -230,7 +232,7 @@ impl Document { } pub fn new(window: &JSRef, url: Option, doctype: IsHTMLDocument, content_type: Option) -> Temporary { - let document = Document::new_inherited(window.unrooted(), url, doctype, content_type); + let document = Document::new_inherited(window, url, doctype, content_type); Document::reflect_document(~document, window, DocumentBinding::Wrap) } } @@ -274,7 +276,7 @@ impl<'a> PrivateDocumentHelpers for JSRef<'a, Document> { self.GetDocumentElement().root().filtered(|root| { root.node.type_id == ElementNodeTypeId(HTMLHtmlElementTypeId) }).map(|elem| { - Temporary::new_rooted(HTMLHtmlElementCast::to_ref(&*elem).unwrap()) + Temporary::from_rooted(HTMLHtmlElementCast::to_ref(&*elem).unwrap()) }) } } @@ -364,14 +366,14 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { child.is_doctype() }).map(|node| { let doctype: &JSRef = DocumentTypeCast::to_ref(&node).unwrap(); - Temporary::new(doctype.unrooted()) + Temporary::from_rooted(doctype) }) } // http://dom.spec.whatwg.org/#dom-document-documentelement fn GetDocumentElement(&self) -> Option> { let node: &JSRef = NodeCast::from_ref(self); - node.child_elements().next().map(|elem| Temporary::new_rooted(&elem)) + node.child_elements().next().map(|elem| Temporary::from_rooted(&elem)) } // http://dom.spec.whatwg.org/#dom-document-getelementsbytagname @@ -522,7 +524,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { Node::adopt(node, self); // Step 3. - Ok(Temporary::new_rooted(node)) + Ok(Temporary::from_rooted(node)) } // http://dom.spec.whatwg.org/#dom-document-createevent @@ -604,7 +606,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { node.children().find(|child| { child.type_id() == ElementNodeTypeId(HTMLHeadElementTypeId) }).map(|node| { - Temporary::new_rooted(HTMLHeadElementCast::to_ref(&node).unwrap()) + Temporary::from_rooted(HTMLHeadElementCast::to_ref(&node).unwrap()) }) }) } @@ -621,7 +623,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { _ => false } }).map(|node| { - Temporary::new_rooted(HTMLElementCast::to_ref(&node).unwrap()) + Temporary::from_rooted(HTMLElementCast::to_ref(&node).unwrap()) }) }) } diff --git a/src/components/script/dom/documentfragment.rs b/src/components/script/dom/documentfragment.rs index b6287696300..25f2c3c1d69 100644 --- a/src/components/script/dom/documentfragment.rs +++ b/src/components/script/dom/documentfragment.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::{DocumentFragmentDerived, NodeCast}; use dom::bindings::codegen::BindingDeclarations::DocumentFragmentBinding; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::Fallible; use dom::document::Document; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -28,14 +28,14 @@ impl DocumentFragmentDerived for EventTarget { impl DocumentFragment { /// Creates a new DocumentFragment. - pub fn new_inherited(document: JS) -> DocumentFragment { + pub fn new_inherited(document: &JSRef) -> DocumentFragment { DocumentFragment { node: Node::new_inherited(DocumentFragmentNodeTypeId, document), } } pub fn new(document: &JSRef) -> Temporary { - let node = DocumentFragment::new_inherited(document.unrooted()); + let node = DocumentFragment::new_inherited(document); Node::reflect_node(~node, document, DocumentFragmentBinding::Wrap) } diff --git a/src/components/script/dom/documenttype.rs b/src/components/script/dom/documenttype.rs index 9e0c61e3723..a5118e791da 100644 --- a/src/components/script/dom/documenttype.rs +++ b/src/components/script/dom/documenttype.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::DocumentTypeDerived; use dom::bindings::codegen::BindingDeclarations::DocumentTypeBinding; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::node::{Node, DoctypeNodeTypeId}; @@ -32,7 +32,7 @@ impl DocumentType { pub fn new_inherited(name: DOMString, public_id: Option, system_id: Option, - document: JS) + document: &JSRef) -> DocumentType { DocumentType { node: Node::new_inherited(DoctypeNodeTypeId, document), @@ -50,7 +50,7 @@ impl DocumentType { let documenttype = DocumentType::new_inherited(name, public_id, system_id, - document.unrooted()); + document); Node::reflect_node(~documenttype, document, DocumentTypeBinding::Wrap) } } diff --git a/src/components/script/dom/domimplementation.rs b/src/components/script/dom/domimplementation.rs index 231c1e4ac99..53cb09fba16 100644 --- a/src/components/script/dom/domimplementation.rs +++ b/src/components/script/dom/domimplementation.rs @@ -26,15 +26,15 @@ pub struct DOMImplementation { } impl DOMImplementation { - pub fn new_inherited(owner: JS) -> DOMImplementation { + pub fn new_inherited(owner: &JSRef) -> DOMImplementation { DOMImplementation { - owner: owner, + owner: owner.unrooted(), reflector_: Reflector::new(), } } pub fn new(owner: &JSRef) -> Temporary { - reflect_dom_object(~DOMImplementation::new_inherited(owner.unrooted()), owner, + reflect_dom_object(~DOMImplementation::new_inherited(owner), owner, DOMImplementationBinding::Wrap) } } @@ -115,7 +115,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { // FIXME: https://github.com/mozilla/servo/issues/1522 // Step 7. - Ok(Temporary::new_rooted(&*doc)) + Ok(Temporary::from_rooted(&*doc)) } // http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument @@ -167,6 +167,6 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { // FIXME: https://github.com/mozilla/servo/issues/1522 // Step 9. - Temporary::new_rooted(&*doc) + Temporary::from_rooted(&*doc) } } diff --git a/src/components/script/dom/domparser.rs b/src/components/script/dom/domparser.rs index 41424d24c0d..035d29cf17d 100644 --- a/src/components/script/dom/domparser.rs +++ b/src/components/script/dom/domparser.rs @@ -18,15 +18,15 @@ pub struct DOMParser { } impl DOMParser { - pub fn new_inherited(owner: JS) -> DOMParser { + pub fn new_inherited(owner: &JSRef) -> DOMParser { DOMParser { - owner: owner, + owner: owner.unrooted(), reflector_: Reflector::new() } } pub fn new(owner: &JSRef) -> Temporary { - reflect_dom_object(~DOMParser::new_inherited(owner.unrooted()), owner, + reflect_dom_object(~DOMParser::new_inherited(owner), owner, DOMParserBinding::Wrap) } diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index f316b1765f6..0e5795a69a0 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -9,7 +9,7 @@ use dom::attrlist::AttrList; use dom::bindings::codegen::BindingDeclarations::ElementBinding; use dom::bindings::codegen::InheritTypes::{ElementDerived, NodeCast}; use dom::bindings::js::{JS, JSRef, Temporary, TemporaryPushable}; -use dom::bindings::js::{OptionalAssignable, OptionalRootable, Root}; +use dom::bindings::js::{OptionalSettable, OptionalRootable, Root}; use dom::bindings::utils::{Reflectable, Reflector}; use dom::bindings::error::{ErrorResult, Fallible, NamespaceError, InvalidCharacter}; use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type}; @@ -141,7 +141,7 @@ pub enum ElementTypeId { // impl Element { - pub fn new_inherited(type_id: ElementTypeId, local_name: DOMString, namespace: Namespace, prefix: Option, document: JS) -> Element { + pub fn new_inherited(type_id: ElementTypeId, local_name: DOMString, namespace: Namespace, prefix: Option, document: &JSRef) -> Element { Element { node: Node::new_inherited(ElementNodeTypeId(type_id), document), local_name: local_name, @@ -154,7 +154,7 @@ impl Element { } pub fn new(local_name: DOMString, namespace: Namespace, prefix: Option, document: &JSRef) -> Temporary { - let element = Element::new_inherited(ElementTypeId, local_name, namespace, prefix, document.unrooted()); + let element = Element::new_inherited(ElementTypeId, local_name, namespace, prefix, document); Node::reflect_node(~element, document, ElementBinding::Wrap) } } @@ -230,11 +230,11 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { if self.html_element_in_html_document() { self.get().attrs.iter().map(|attr| attr.root()).find(|attr| { name.to_ascii_lower() == attr.local_name && attr.namespace == namespace - }).map(|x| Temporary::new_rooted(&*x)) + }).map(|x| Temporary::from_rooted(&*x)) } else { self.get().attrs.iter().map(|attr| attr.root()).find(|attr| { name == attr.local_name && attr.namespace == namespace - }).map(|x| Temporary::new_rooted(&*x)) + }).map(|x| Temporary::from_rooted(&*x)) } } @@ -282,7 +282,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { let window = window_from_node(self).root(); let attr = Attr::new(&*window, local_name.clone(), value.clone(), name, namespace.clone(), prefix, self); - self.get_mut().attrs.push_unrooted(attr); + self.get_mut().attrs.push_unrooted(&attr); (self.get().attrs.len() - 1, FirstSetAttr) } }; diff --git a/src/components/script/dom/event.rs b/src/components/script/dom/event.rs index 9ce0cd4f981..3d6055a1408 100644 --- a/src/components/script/dom/event.rs +++ b/src/components/script/dom/event.rs @@ -91,7 +91,7 @@ impl Event { init: &EventBinding::EventInit) -> Fallible> { let mut ev = Event::new(global).root(); ev.InitEvent(type_, init.bubbles, init.cancelable); - Ok(Temporary::new_rooted(&*ev)) + Ok(Temporary::from_rooted(&*ev)) } } diff --git a/src/components/script/dom/eventdispatcher.rs b/src/components/script/dom/eventdispatcher.rs index b4e6b4644cf..d15a26d6cc1 100644 --- a/src/components/script/dom/eventdispatcher.rs +++ b/src/components/script/dom/eventdispatcher.rs @@ -4,7 +4,7 @@ use dom::bindings::callback::ReportExceptions; use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, NodeDerived}; -use dom::bindings::js::{JSRef, OptionalAssignable, Root}; +use dom::bindings::js::{JSRef, OptionalSettable, Root}; use dom::eventtarget::{Capturing, Bubbling, EventTarget}; use dom::event::{Event, PhaseAtTarget, PhaseNone, PhaseBubbling, PhaseCapturing, EventMethods}; use dom::node::{Node, NodeHelpers}; diff --git a/src/components/script/dom/formdata.rs b/src/components/script/dom/formdata.rs index 8cd1eebb028..33dae4b97c2 100644 --- a/src/components/script/dom/formdata.rs +++ b/src/components/script/dom/formdata.rs @@ -28,17 +28,17 @@ pub struct FormData { } impl FormData { - pub fn new_inherited(form: Option>, window: JS) -> FormData { + pub fn new_inherited(form: Option>, window: &JSRef) -> FormData { FormData { data: HashMap::new(), reflector_: Reflector::new(), - window: window, + window: window.unrooted(), form: form.map(|form| form.unrooted()) } } pub fn new(form: Option>, window: &JSRef) -> Temporary { - reflect_dom_object(~FormData::new_inherited(form, window.unrooted()), window, FormDataBinding::Wrap) + reflect_dom_object(~FormData::new_inherited(form, window), window, FormDataBinding::Wrap) } pub fn Constructor(window: &JSRef, form: Option>) -> Fallible> { diff --git a/src/components/script/dom/htmlanchorelement.rs b/src/components/script/dom/htmlanchorelement.rs index 1757de35ecf..6b90e96053a 100644 --- a/src/components/script/dom/htmlanchorelement.rs +++ b/src/components/script/dom/htmlanchorelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLAnchorElementBinding; use dom::bindings::codegen::InheritTypes::HTMLAnchorElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLAnchorElementTypeId; @@ -28,14 +28,14 @@ impl HTMLAnchorElementDerived for EventTarget { } impl HTMLAnchorElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLAnchorElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLAnchorElement { HTMLAnchorElement { htmlelement: HTMLElement::new_inherited(HTMLAnchorElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLAnchorElement::new_inherited(localName, document.unrooted()); + let element = HTMLAnchorElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLAnchorElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlappletelement.rs b/src/components/script/dom/htmlappletelement.rs index 5500f6568aa..385750d0a16 100644 --- a/src/components/script/dom/htmlappletelement.rs +++ b/src/components/script/dom/htmlappletelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLAppletElementBinding; use dom::bindings::codegen::InheritTypes::HTMLAppletElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLAppletElementTypeId; @@ -28,14 +28,14 @@ impl HTMLAppletElementDerived for EventTarget { } impl HTMLAppletElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLAppletElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLAppletElement { HTMLAppletElement { htmlelement: HTMLElement::new_inherited(HTMLAppletElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLAppletElement::new_inherited(localName, document.unrooted()); + let element = HTMLAppletElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLAppletElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlareaelement.rs b/src/components/script/dom/htmlareaelement.rs index e6678299abf..e09549b7a5e 100644 --- a/src/components/script/dom/htmlareaelement.rs +++ b/src/components/script/dom/htmlareaelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLAreaElementBinding; use dom::bindings::codegen::InheritTypes::HTMLAreaElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLAreaElementTypeId; @@ -28,14 +28,14 @@ impl HTMLAreaElementDerived for EventTarget { } impl HTMLAreaElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLAreaElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLAreaElement { HTMLAreaElement { htmlelement: HTMLElement::new_inherited(HTMLAreaElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLAreaElement::new_inherited(localName, document.unrooted()); + let element = HTMLAreaElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLAreaElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlaudioelement.rs b/src/components/script/dom/htmlaudioelement.rs index 3b1a7cb3a98..9cc697454d1 100644 --- a/src/components/script/dom/htmlaudioelement.rs +++ b/src/components/script/dom/htmlaudioelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLAudioElementBinding; use dom::bindings::codegen::InheritTypes::HTMLAudioElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLAudioElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -27,14 +27,14 @@ impl HTMLAudioElementDerived for EventTarget { } impl HTMLAudioElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLAudioElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLAudioElement { HTMLAudioElement { htmlmediaelement: HTMLMediaElement::new_inherited(HTMLAudioElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLAudioElement::new_inherited(localName, document.unrooted()); + let element = HTMLAudioElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLAudioElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlbaseelement.rs b/src/components/script/dom/htmlbaseelement.rs index 1105f862881..69a15849fef 100644 --- a/src/components/script/dom/htmlbaseelement.rs +++ b/src/components/script/dom/htmlbaseelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLBaseElementBinding; use dom::bindings::codegen::InheritTypes::HTMLBaseElementDerived; use dom::bindings::error::ErrorResult; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLBaseElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -28,14 +28,14 @@ impl HTMLBaseElementDerived for EventTarget { } impl HTMLBaseElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLBaseElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLBaseElement { HTMLBaseElement { htmlelement: HTMLElement::new_inherited(HTMLBaseElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLBaseElement::new_inherited(localName, document.unrooted()); + let element = HTMLBaseElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLBaseElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlbodyelement.rs b/src/components/script/dom/htmlbodyelement.rs index d070c7b5a12..d1ba59c847c 100644 --- a/src/components/script/dom/htmlbodyelement.rs +++ b/src/components/script/dom/htmlbodyelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLBodyElementBinding; use dom::bindings::codegen::InheritTypes::HTMLBodyElementDerived; use dom::bindings::error::ErrorResult; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLBodyElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -28,14 +28,14 @@ impl HTMLBodyElementDerived for EventTarget { } impl HTMLBodyElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLBodyElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLBodyElement { HTMLBodyElement { htmlelement: HTMLElement::new_inherited(HTMLBodyElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLBodyElement::new_inherited(localName, document.unrooted()); + let element = HTMLBodyElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLBodyElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlbrelement.rs b/src/components/script/dom/htmlbrelement.rs index 2bf59a4f966..eee904135e1 100644 --- a/src/components/script/dom/htmlbrelement.rs +++ b/src/components/script/dom/htmlbrelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLBRElementBinding; use dom::bindings::codegen::InheritTypes::HTMLBRElementDerived; use dom::bindings::error::ErrorResult; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLBRElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -28,14 +28,14 @@ impl HTMLBRElementDerived for EventTarget { } impl HTMLBRElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLBRElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLBRElement { HTMLBRElement { htmlelement: HTMLElement::new_inherited(HTMLBRElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLBRElement::new_inherited(localName, document.unrooted()); + let element = HTMLBRElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLBRElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlbuttonelement.rs b/src/components/script/dom/htmlbuttonelement.rs index 1474c9cb563..c920f999cf1 100644 --- a/src/components/script/dom/htmlbuttonelement.rs +++ b/src/components/script/dom/htmlbuttonelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLButtonElementBinding; use dom::bindings::codegen::InheritTypes::HTMLButtonElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLButtonElementTypeId; @@ -30,14 +30,14 @@ impl HTMLButtonElementDerived for EventTarget { } impl HTMLButtonElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLButtonElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLButtonElement { HTMLButtonElement { htmlelement: HTMLElement::new_inherited(HTMLButtonElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLButtonElement::new_inherited(localName, document.unrooted()); + let element = HTMLButtonElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLButtonElementBinding::Wrap) } } @@ -67,7 +67,6 @@ pub trait HTMLButtonElementMethods { fn WillValidate(&self) -> bool; fn SetWillValidate(&mut self, _will_validate: bool); fn Validity(&self) -> Temporary; - fn SetValidity(&mut self, _validity: JS); fn ValidationMessage(&self) -> DOMString; fn SetValidationMessage(&mut self, _message: DOMString) -> ErrorResult; fn CheckValidity(&self) -> bool; @@ -171,9 +170,6 @@ impl<'a> HTMLButtonElementMethods for JSRef<'a, HTMLButtonElement> { ValidityState::new(&*window) } - fn SetValidity(&mut self, _validity: JS) { - } - fn ValidationMessage(&self) -> DOMString { ~"" } diff --git a/src/components/script/dom/htmlcanvaselement.rs b/src/components/script/dom/htmlcanvaselement.rs index 068cee1bbd8..1aba464556a 100644 --- a/src/components/script/dom/htmlcanvaselement.rs +++ b/src/components/script/dom/htmlcanvaselement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLCanvasElementBinding; use dom::bindings::codegen::InheritTypes::HTMLCanvasElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::{ErrorResult}; use dom::document::Document; use dom::element::HTMLCanvasElementTypeId; @@ -28,14 +28,14 @@ impl HTMLCanvasElementDerived for EventTarget { } impl HTMLCanvasElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLCanvasElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLCanvasElement { HTMLCanvasElement { htmlelement: HTMLElement::new_inherited(HTMLCanvasElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLCanvasElement::new_inherited(localName, document.unrooted()); + let element = HTMLCanvasElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLCanvasElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlcollection.rs b/src/components/script/dom/htmlcollection.rs index 0047247ffad..6d0a0c78edf 100644 --- a/src/components/script/dom/htmlcollection.rs +++ b/src/components/script/dom/htmlcollection.rs @@ -38,16 +38,16 @@ pub struct HTMLCollection { } impl HTMLCollection { - pub fn new_inherited(window: JS, collection: CollectionTypeId) -> HTMLCollection { + pub fn new_inherited(window: &JSRef, collection: CollectionTypeId) -> HTMLCollection { HTMLCollection { collection: collection, reflector_: Reflector::new(), - window: window, + window: window.unrooted(), } } pub fn new(window: &JSRef, collection: CollectionTypeId) -> Temporary { - reflect_dom_object(~HTMLCollection::new_inherited(window.unrooted(), collection), + reflect_dom_object(~HTMLCollection::new_inherited(window, collection), window, HTMLCollectionBinding::Wrap) } } @@ -159,7 +159,7 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> { }) .nth(index as uint) .clone() - .map(|elem| Temporary::new_rooted(&elem)) + .map(|elem| Temporary::from_rooted(&elem)) } } } @@ -179,7 +179,7 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> { .find(|elem| { elem.get_string_attribute("name") == key || elem.get_string_attribute("id") == key }) - .map(|maybe_elem| Temporary::new_rooted(&*maybe_elem)), + .map(|maybe_elem| Temporary::from_rooted(&*maybe_elem)), Live(ref root, ref filter) => { let root = root.root(); root.deref().traverse_preorder() @@ -191,7 +191,7 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> { .find(|elem| { elem.get_string_attribute("name") == key || elem.get_string_attribute("id") == key }) - .map(|maybe_elem| Temporary::new_rooted(&maybe_elem)) + .map(|maybe_elem| Temporary::from_rooted(&maybe_elem)) } } } diff --git a/src/components/script/dom/htmldataelement.rs b/src/components/script/dom/htmldataelement.rs index dcac09e2f5b..b2812ef92ad 100644 --- a/src/components/script/dom/htmldataelement.rs +++ b/src/components/script/dom/htmldataelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDataElementBinding; use dom::bindings::codegen::InheritTypes::HTMLDataElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLDataElementTypeId; @@ -28,14 +28,14 @@ impl HTMLDataElementDerived for EventTarget { } impl HTMLDataElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLDataElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLDataElement { HTMLDataElement { htmlelement: HTMLElement::new_inherited(HTMLDataElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLDataElement::new_inherited(localName, document.unrooted()); + let element = HTMLDataElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLDataElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmldatalistelement.rs b/src/components/script/dom/htmldatalistelement.rs index caaad975c0e..756e497cdea 100644 --- a/src/components/script/dom/htmldatalistelement.rs +++ b/src/components/script/dom/htmldatalistelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDataListElementBinding; use dom::bindings::codegen::InheritTypes::{HTMLDataListElementDerived, NodeCast}; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; use dom::element::{Element, HTMLDataListElementTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -28,14 +28,14 @@ impl HTMLDataListElementDerived for EventTarget { } impl HTMLDataListElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLDataListElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLDataListElement { HTMLDataListElement { htmlelement: HTMLElement::new_inherited(HTMLDataListElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLDataListElement::new_inherited(localName, document.unrooted()); + let element = HTMLDataListElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLDataListElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmldirectoryelement.rs b/src/components/script/dom/htmldirectoryelement.rs index 8cde736766f..7c275b29529 100644 --- a/src/components/script/dom/htmldirectoryelement.rs +++ b/src/components/script/dom/htmldirectoryelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDirectoryElementBinding; use dom::bindings::codegen::InheritTypes::HTMLDirectoryElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLDirectoryElementTypeId; @@ -28,14 +28,14 @@ impl HTMLDirectoryElementDerived for EventTarget { } impl HTMLDirectoryElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLDirectoryElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLDirectoryElement { HTMLDirectoryElement { htmlelement: HTMLElement::new_inherited(HTMLDirectoryElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLDirectoryElement::new_inherited(localName, document.unrooted()); + let element = HTMLDirectoryElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLDirectoryElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmldivelement.rs b/src/components/script/dom/htmldivelement.rs index 2047530985b..f4b3ead4323 100644 --- a/src/components/script/dom/htmldivelement.rs +++ b/src/components/script/dom/htmldivelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDivElementBinding; use dom::bindings::codegen::InheritTypes::HTMLDivElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLDivElementTypeId; @@ -28,14 +28,14 @@ impl HTMLDivElementDerived for EventTarget { } impl HTMLDivElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLDivElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLDivElement { HTMLDivElement { htmlelement: HTMLElement::new_inherited(HTMLDivElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLDivElement::new_inherited(localName, document.unrooted()); + let element = HTMLDivElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLDivElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmldlistelement.rs b/src/components/script/dom/htmldlistelement.rs index dc7ae6066fe..db57d180049 100644 --- a/src/components/script/dom/htmldlistelement.rs +++ b/src/components/script/dom/htmldlistelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLDListElementBinding; use dom::bindings::codegen::InheritTypes::HTMLDListElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLDListElementTypeId; @@ -28,14 +28,14 @@ impl HTMLDListElementDerived for EventTarget { } impl HTMLDListElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLDListElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLDListElement { HTMLDListElement { htmlelement: HTMLElement::new_inherited(HTMLDListElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLDListElement::new_inherited(localName, document.unrooted()); + let element = HTMLDListElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLDListElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlelement.rs b/src/components/script/dom/htmlelement.rs index 87b00f2eb90..d5de75d3c09 100644 --- a/src/components/script/dom/htmlelement.rs +++ b/src/components/script/dom/htmlelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLElementBinding; use dom::bindings::codegen::InheritTypes::ElementCast; use dom::bindings::codegen::InheritTypes::HTMLElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::{ErrorResult, Fallible}; use dom::document::Document; use dom::element::{Element, ElementTypeId, HTMLElementTypeId}; @@ -33,14 +33,14 @@ impl HTMLElementDerived for EventTarget { } impl HTMLElement { - pub fn new_inherited(type_id: ElementTypeId, tag_name: DOMString, document: JS) -> HTMLElement { + pub fn new_inherited(type_id: ElementTypeId, tag_name: DOMString, document: &JSRef) -> HTMLElement { HTMLElement { element: Element::new_inherited(type_id, tag_name, namespace::HTML, None, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLElement::new_inherited(HTMLElementTypeId, localName, document.unrooted()); + let element = HTMLElement::new_inherited(HTMLElementTypeId, localName, document); Node::reflect_node(~element, document, HTMLElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlembedelement.rs b/src/components/script/dom/htmlembedelement.rs index 334c7320295..8582bb86164 100644 --- a/src/components/script/dom/htmlembedelement.rs +++ b/src/components/script/dom/htmlembedelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLEmbedElementBinding; use dom::bindings::codegen::InheritTypes::HTMLEmbedElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLEmbedElementTypeId; @@ -28,14 +28,14 @@ impl HTMLEmbedElementDerived for EventTarget { } impl HTMLEmbedElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLEmbedElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLEmbedElement { HTMLEmbedElement { htmlelement: HTMLElement::new_inherited(HTMLEmbedElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLEmbedElement::new_inherited(localName, document.unrooted()); + let element = HTMLEmbedElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLEmbedElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlfieldsetelement.rs b/src/components/script/dom/htmlfieldsetelement.rs index 0b32c0b916a..7cb91d98ba1 100644 --- a/src/components/script/dom/htmlfieldsetelement.rs +++ b/src/components/script/dom/htmlfieldsetelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFieldSetElementBinding; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLFieldSetElementDerived, NodeCast}; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLFieldSetElementTypeId}; @@ -31,14 +31,14 @@ impl HTMLFieldSetElementDerived for EventTarget { } impl HTMLFieldSetElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLFieldSetElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLFieldSetElement { HTMLFieldSetElement { htmlelement: HTMLElement::new_inherited(HTMLFieldSetElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLFieldSetElement::new_inherited(localName, document.unrooted()); + let element = HTMLFieldSetElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLFieldSetElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlfontelement.rs b/src/components/script/dom/htmlfontelement.rs index 5d6ececb57d..c006124bfba 100644 --- a/src/components/script/dom/htmlfontelement.rs +++ b/src/components/script/dom/htmlfontelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFontElementBinding; use dom::bindings::codegen::InheritTypes::HTMLFontElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLFontElementTypeId; @@ -28,14 +28,14 @@ impl HTMLFontElementDerived for EventTarget { } impl HTMLFontElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLFontElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLFontElement { HTMLFontElement { htmlelement: HTMLElement::new_inherited(HTMLFontElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLFontElement::new_inherited(localName, document.unrooted()); + let element = HTMLFontElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLFontElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlformelement.rs b/src/components/script/dom/htmlformelement.rs index 9cba31363ab..8c3fd60d3c1 100644 --- a/src/components/script/dom/htmlformelement.rs +++ b/src/components/script/dom/htmlformelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFormElementBinding; use dom::bindings::codegen::InheritTypes::HTMLFormElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLFormElementTypeId}; @@ -29,14 +29,14 @@ impl HTMLFormElementDerived for EventTarget { } impl HTMLFormElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLFormElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLFormElement { HTMLFormElement { htmlelement: HTMLElement::new_inherited(HTMLFormElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLFormElement::new_inherited(localName, document.unrooted()); + let element = HTMLFormElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLFormElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlframeelement.rs b/src/components/script/dom/htmlframeelement.rs index 2f3aa886bcf..985f02114bc 100644 --- a/src/components/script/dom/htmlframeelement.rs +++ b/src/components/script/dom/htmlframeelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFrameElementBinding; use dom::bindings::codegen::InheritTypes::HTMLFrameElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLFrameElementTypeId; @@ -29,14 +29,14 @@ impl HTMLFrameElementDerived for EventTarget { } impl HTMLFrameElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLFrameElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLFrameElement { HTMLFrameElement { htmlelement: HTMLElement::new_inherited(HTMLFrameElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLFrameElement::new_inherited(localName, document.unrooted()); + let element = HTMLFrameElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLFrameElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlframesetelement.rs b/src/components/script/dom/htmlframesetelement.rs index 32860c79562..cbb3f868b98 100644 --- a/src/components/script/dom/htmlframesetelement.rs +++ b/src/components/script/dom/htmlframesetelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFrameSetElementBinding; use dom::bindings::codegen::InheritTypes::HTMLFrameSetElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLFrameSetElementTypeId; @@ -28,14 +28,14 @@ impl HTMLFrameSetElementDerived for EventTarget { } impl HTMLFrameSetElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLFrameSetElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLFrameSetElement { HTMLFrameSetElement { htmlelement: HTMLElement::new_inherited(HTMLFrameSetElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLFrameSetElement::new_inherited(localName, document.unrooted()); + let element = HTMLFrameSetElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLFrameSetElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlheadelement.rs b/src/components/script/dom/htmlheadelement.rs index 1cfb2d4ea6e..542312c9dfe 100644 --- a/src/components/script/dom/htmlheadelement.rs +++ b/src/components/script/dom/htmlheadelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLHeadElementBinding; use dom::bindings::codegen::InheritTypes::HTMLHeadElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLHeadElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -27,14 +27,14 @@ impl HTMLHeadElementDerived for EventTarget { } impl HTMLHeadElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLHeadElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLHeadElement { HTMLHeadElement { htmlelement: HTMLElement::new_inherited(HTMLHeadElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLHeadElement::new_inherited(localName, document.unrooted()); + let element = HTMLHeadElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLHeadElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlheadingelement.rs b/src/components/script/dom/htmlheadingelement.rs index 98142aaaa6a..e1a2c8051ce 100644 --- a/src/components/script/dom/htmlheadingelement.rs +++ b/src/components/script/dom/htmlheadingelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLHeadingElementBinding; use dom::bindings::codegen::InheritTypes::HTMLHeadingElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLHeadingElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -38,7 +38,7 @@ impl HTMLHeadingElementDerived for EventTarget { } impl HTMLHeadingElement { - pub fn new_inherited(localName: DOMString, document: JS, level: HeadingLevel) -> HTMLHeadingElement { + pub fn new_inherited(localName: DOMString, document: &JSRef, level: HeadingLevel) -> HTMLHeadingElement { HTMLHeadingElement { htmlelement: HTMLElement::new_inherited(HTMLHeadingElementTypeId, localName, document), level: level, @@ -46,7 +46,7 @@ impl HTMLHeadingElement { } pub fn new(localName: DOMString, document: &JSRef, level: HeadingLevel) -> Temporary { - let element = HTMLHeadingElement::new_inherited(localName, document.unrooted(), level); + let element = HTMLHeadingElement::new_inherited(localName, document, level); Node::reflect_node(~element, document, HTMLHeadingElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlhrelement.rs b/src/components/script/dom/htmlhrelement.rs index 9031566d4d8..4ee1d645da6 100644 --- a/src/components/script/dom/htmlhrelement.rs +++ b/src/components/script/dom/htmlhrelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLHRElementBinding; use dom::bindings::codegen::InheritTypes::HTMLHRElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLHRElementTypeId; @@ -28,14 +28,14 @@ impl HTMLHRElementDerived for EventTarget { } impl HTMLHRElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLHRElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLHRElement { HTMLHRElement { htmlelement: HTMLElement::new_inherited(HTMLHRElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLHRElement::new_inherited(localName, document.unrooted()); + let element = HTMLHRElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLHRElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlhtmlelement.rs b/src/components/script/dom/htmlhtmlelement.rs index 5a11183e80c..de57df51216 100644 --- a/src/components/script/dom/htmlhtmlelement.rs +++ b/src/components/script/dom/htmlhtmlelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLHtmlElementBinding; use dom::bindings::codegen::InheritTypes::HTMLHtmlElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLHtmlElementTypeId; @@ -28,14 +28,14 @@ impl HTMLHtmlElementDerived for EventTarget { } impl HTMLHtmlElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLHtmlElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLHtmlElement { HTMLHtmlElement { htmlelement: HTMLElement::new_inherited(HTMLHtmlElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLHtmlElement::new_inherited(localName, document.unrooted()); + let element = HTMLHtmlElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLHtmlElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmliframeelement.rs b/src/components/script/dom/htmliframeelement.rs index 18a47de9ee7..acb1a5c1da6 100644 --- a/src/components/script/dom/htmliframeelement.rs +++ b/src/components/script/dom/htmliframeelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLIFrameElementBinding; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLIFrameElementDerived, HTMLElementCast}; use dom::bindings::error::ErrorResult; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::trace::Untraceable; use dom::document::Document; use dom::element::{HTMLIFrameElementTypeId, Element}; @@ -70,7 +70,7 @@ impl<'a> HTMLIFrameElementHelpers for JSRef<'a, HTMLIFrameElement> { } impl HTMLIFrameElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLIFrameElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLIFrameElement { HTMLIFrameElement { htmlelement: HTMLElement::new_inherited(HTMLIFrameElementTypeId, localName, document), frame: Untraceable::new(None), @@ -80,7 +80,7 @@ impl HTMLIFrameElement { } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLIFrameElement::new_inherited(localName, document.unrooted()); + let element = HTMLIFrameElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLIFrameElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlimageelement.rs b/src/components/script/dom/htmlimageelement.rs index af31c043d11..6013e74334f 100644 --- a/src/components/script/dom/htmlimageelement.rs +++ b/src/components/script/dom/htmlimageelement.rs @@ -68,7 +68,7 @@ impl<'a> PrivateHTMLImageElementHelpers for JSRef<'a, HTMLImageElement> { } impl HTMLImageElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLImageElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLImageElement { HTMLImageElement { htmlelement: HTMLElement::new_inherited(HTMLImageElementTypeId, localName, document), image: Untraceable::new(None), @@ -76,7 +76,7 @@ impl HTMLImageElement { } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLImageElement::new_inherited(localName, document.unrooted()); + let element = HTMLImageElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLImageElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlinputelement.rs b/src/components/script/dom/htmlinputelement.rs index a50e73137ae..3b38421e1ce 100644 --- a/src/components/script/dom/htmlinputelement.rs +++ b/src/components/script/dom/htmlinputelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLInputElementBinding; use dom::bindings::codegen::InheritTypes::HTMLInputElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::{ErrorResult, Fallible}; use dom::document::Document; use dom::element::HTMLInputElementTypeId; @@ -28,14 +28,14 @@ impl HTMLInputElementDerived for EventTarget { } impl HTMLInputElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLInputElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLInputElement { HTMLInputElement { htmlelement: HTMLElement::new_inherited(HTMLInputElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLInputElement::new_inherited(localName, document.unrooted()); + let element = HTMLInputElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLInputElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmllabelelement.rs b/src/components/script/dom/htmllabelelement.rs index f994d73331b..fb70e46c8b0 100644 --- a/src/components/script/dom/htmllabelelement.rs +++ b/src/components/script/dom/htmllabelelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLLabelElementBinding; use dom::bindings::codegen::InheritTypes::HTMLLabelElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLLabelElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -27,14 +27,14 @@ impl HTMLLabelElementDerived for EventTarget { } impl HTMLLabelElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLLabelElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLLabelElement { HTMLLabelElement { htmlelement: HTMLElement::new_inherited(HTMLLabelElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLLabelElement::new_inherited(localName, document.unrooted()); + let element = HTMLLabelElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLLabelElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmllegendelement.rs b/src/components/script/dom/htmllegendelement.rs index 20af8e0bcf5..65896fae79c 100644 --- a/src/components/script/dom/htmllegendelement.rs +++ b/src/components/script/dom/htmllegendelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLLegendElementBinding; use dom::bindings::codegen::InheritTypes::HTMLLegendElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLLegendElementTypeId; @@ -28,14 +28,14 @@ impl HTMLLegendElementDerived for EventTarget { } impl HTMLLegendElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLLegendElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLLegendElement { HTMLLegendElement { htmlelement: HTMLElement::new_inherited(HTMLLegendElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLLegendElement::new_inherited(localName, document.unrooted()); + let element = HTMLLegendElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLLegendElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmllielement.rs b/src/components/script/dom/htmllielement.rs index 33f46ddebc2..7eba5d678ed 100644 --- a/src/components/script/dom/htmllielement.rs +++ b/src/components/script/dom/htmllielement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLLIElementBinding; use dom::bindings::codegen::InheritTypes::HTMLLIElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLLIElementTypeId; @@ -28,14 +28,14 @@ impl HTMLLIElementDerived for EventTarget { } impl HTMLLIElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLLIElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLLIElement { HTMLLIElement { htmlelement: HTMLElement::new_inherited(HTMLLIElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLLIElement::new_inherited(localName, document.unrooted()); + let element = HTMLLIElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLLIElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmllinkelement.rs b/src/components/script/dom/htmllinkelement.rs index df96b58d19f..ff49f250778 100644 --- a/src/components/script/dom/htmllinkelement.rs +++ b/src/components/script/dom/htmllinkelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLLinkElementBinding; use dom::bindings::codegen::InheritTypes::HTMLLinkElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLLinkElementTypeId; @@ -28,14 +28,14 @@ impl HTMLLinkElementDerived for EventTarget { } impl HTMLLinkElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLLinkElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLLinkElement { HTMLLinkElement { htmlelement: HTMLElement::new_inherited(HTMLLinkElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLLinkElement::new_inherited(localName, document.unrooted()); + let element = HTMLLinkElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLLinkElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlmainelement.rs b/src/components/script/dom/htmlmainelement.rs index ffd5c6cb523..3efa0c68fb8 100644 --- a/src/components/script/dom/htmlmainelement.rs +++ b/src/components/script/dom/htmlmainelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLMainElementBinding; use dom::bindings::codegen::InheritTypes::HTMLMainElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLMainElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -27,14 +27,14 @@ impl HTMLMainElementDerived for EventTarget { } impl HTMLMainElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLMainElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLMainElement { HTMLMainElement { htmlelement: HTMLElement::new_inherited(HTMLMainElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLMainElement::new_inherited(localName, document.unrooted()); + let element = HTMLMainElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLMainElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlmapelement.rs b/src/components/script/dom/htmlmapelement.rs index a6bd9d39ed0..08a6e2c5c5d 100644 --- a/src/components/script/dom/htmlmapelement.rs +++ b/src/components/script/dom/htmlmapelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLMapElementBinding; use dom::bindings::codegen::InheritTypes::HTMLMapElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLMapElementTypeId; @@ -29,14 +29,14 @@ impl HTMLMapElementDerived for EventTarget { } impl HTMLMapElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLMapElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLMapElement { HTMLMapElement { htmlelement: HTMLElement::new_inherited(HTMLMapElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLMapElement::new_inherited(localName, document.unrooted()); + let element = HTMLMapElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLMapElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlmediaelement.rs b/src/components/script/dom/htmlmediaelement.rs index 4f68a11f9c0..e2d1c437aa8 100644 --- a/src/components/script/dom/htmlmediaelement.rs +++ b/src/components/script/dom/htmlmediaelement.rs @@ -2,7 +2,7 @@ * 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}; +use dom::bindings::js::{JSRef}; use dom::bindings::codegen::InheritTypes::HTMLMediaElementDerived; use dom::bindings::error::ErrorResult; use dom::document::Document; @@ -28,7 +28,7 @@ impl HTMLMediaElementDerived for EventTarget { } impl HTMLMediaElement { - pub fn new_inherited(type_id: ElementTypeId, tag_name: DOMString, document: JS) -> HTMLMediaElement { + pub fn new_inherited(type_id: ElementTypeId, tag_name: DOMString, document: &JSRef) -> HTMLMediaElement { HTMLMediaElement { htmlelement: HTMLElement::new_inherited(type_id, tag_name, document) } diff --git a/src/components/script/dom/htmlmetaelement.rs b/src/components/script/dom/htmlmetaelement.rs index cb9e6d603c1..0399cd31210 100644 --- a/src/components/script/dom/htmlmetaelement.rs +++ b/src/components/script/dom/htmlmetaelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLMetaElementBinding; use dom::bindings::codegen::InheritTypes::HTMLMetaElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLMetaElementTypeId; @@ -28,14 +28,14 @@ impl HTMLMetaElementDerived for EventTarget { } impl HTMLMetaElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLMetaElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLMetaElement { HTMLMetaElement { htmlelement: HTMLElement::new_inherited(HTMLMetaElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLMetaElement::new_inherited(localName, document.unrooted()); + let element = HTMLMetaElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLMetaElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlmeterelement.rs b/src/components/script/dom/htmlmeterelement.rs index 7e4c7f42f9f..d16a82b79da 100644 --- a/src/components/script/dom/htmlmeterelement.rs +++ b/src/components/script/dom/htmlmeterelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLMeterElementBinding; use dom::bindings::codegen::InheritTypes::HTMLMeterElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLMeterElementTypeId; @@ -28,14 +28,14 @@ impl HTMLMeterElementDerived for EventTarget { } impl HTMLMeterElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLMeterElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLMeterElement { HTMLMeterElement { htmlelement: HTMLElement::new_inherited(HTMLMeterElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLMeterElement::new_inherited(localName, document.unrooted()); + let element = HTMLMeterElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLMeterElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlmodelement.rs b/src/components/script/dom/htmlmodelement.rs index 5e77c3c8636..ed05d72fe62 100644 --- a/src/components/script/dom/htmlmodelement.rs +++ b/src/components/script/dom/htmlmodelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLModElementBinding; use dom::bindings::codegen::InheritTypes::HTMLModElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLModElementTypeId; @@ -28,14 +28,14 @@ impl HTMLModElementDerived for EventTarget { } impl HTMLModElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLModElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLModElement { HTMLModElement { htmlelement: HTMLElement::new_inherited(HTMLModElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLModElement::new_inherited(localName, document.unrooted()); + let element = HTMLModElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLModElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlobjectelement.rs b/src/components/script/dom/htmlobjectelement.rs index c560486c565..473f12aefd7 100644 --- a/src/components/script/dom/htmlobjectelement.rs +++ b/src/components/script/dom/htmlobjectelement.rs @@ -6,7 +6,7 @@ use dom::attr::AttrMethods; use dom::bindings::codegen::BindingDeclarations::HTMLObjectElementBinding; use dom::bindings::codegen::InheritTypes::HTMLObjectElementDerived; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast}; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLObjectElementTypeId}; @@ -42,14 +42,14 @@ impl HTMLObjectElementDerived for EventTarget { } impl HTMLObjectElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLObjectElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLObjectElement { HTMLObjectElement { htmlelement: HTMLElement::new_inherited(HTMLObjectElementTypeId, localName, document), } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLObjectElement::new_inherited(localName, document.unrooted()); + let element = HTMLObjectElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLObjectElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlolistelement.rs b/src/components/script/dom/htmlolistelement.rs index 6b4133513b9..57beee67a5d 100644 --- a/src/components/script/dom/htmlolistelement.rs +++ b/src/components/script/dom/htmlolistelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLOListElementBinding; use dom::bindings::codegen::InheritTypes::HTMLOListElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLOListElementTypeId; @@ -28,14 +28,14 @@ impl HTMLOListElementDerived for EventTarget { } impl HTMLOListElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLOListElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLOListElement { HTMLOListElement { htmlelement: HTMLElement::new_inherited(HTMLOListElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLOListElement::new_inherited(localName, document.unrooted()); + let element = HTMLOListElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLOListElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmloptgroupelement.rs b/src/components/script/dom/htmloptgroupelement.rs index 74c0bde0156..b4eb6e5c619 100644 --- a/src/components/script/dom/htmloptgroupelement.rs +++ b/src/components/script/dom/htmloptgroupelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLOptGroupElementBinding; use dom::bindings::codegen::InheritTypes::HTMLOptGroupElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLOptGroupElementTypeId; @@ -28,14 +28,14 @@ impl HTMLOptGroupElementDerived for EventTarget { } impl HTMLOptGroupElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLOptGroupElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLOptGroupElement { HTMLOptGroupElement { htmlelement: HTMLElement::new_inherited(HTMLOptGroupElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLOptGroupElement::new_inherited(localName, document.unrooted()); + let element = HTMLOptGroupElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLOptGroupElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmloptionelement.rs b/src/components/script/dom/htmloptionelement.rs index dc0c6c291d8..a3f64bb9620 100644 --- a/src/components/script/dom/htmloptionelement.rs +++ b/src/components/script/dom/htmloptionelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLOptionElementBinding; use dom::bindings::codegen::InheritTypes::HTMLOptionElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLOptionElementTypeId; @@ -29,14 +29,14 @@ impl HTMLOptionElementDerived for EventTarget { } impl HTMLOptionElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLOptionElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLOptionElement { HTMLOptionElement { htmlelement: HTMLElement::new_inherited(HTMLOptionElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLOptionElement::new_inherited(localName, document.unrooted()); + let element = HTMLOptionElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLOptionElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmloutputelement.rs b/src/components/script/dom/htmloutputelement.rs index 91a77daa8e5..46f51abcbb4 100644 --- a/src/components/script/dom/htmloutputelement.rs +++ b/src/components/script/dom/htmloutputelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLOutputElementBinding; use dom::bindings::codegen::InheritTypes::HTMLOutputElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLOutputElementTypeId; @@ -30,14 +30,14 @@ impl HTMLOutputElementDerived for EventTarget { } impl HTMLOutputElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLOutputElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLOutputElement { HTMLOutputElement { htmlelement: HTMLElement::new_inherited(HTMLOutputElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLOutputElement::new_inherited(localName, document.unrooted()); + let element = HTMLOutputElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLOutputElementBinding::Wrap) } } @@ -54,7 +54,6 @@ pub trait HTMLOutputElementMethods { fn WillValidate(&self) -> bool; fn SetWillValidate(&mut self, _will_validate: bool); fn Validity(&self) -> Temporary; - fn SetValidity(&mut self, _validity: JS); fn ValidationMessage(&self) -> DOMString; fn SetValidationMessage(&mut self, _message: DOMString) -> ErrorResult; fn CheckValidity(&self) -> bool; @@ -106,9 +105,6 @@ impl<'a> HTMLOutputElementMethods for JSRef<'a, HTMLOutputElement> { ValidityState::new(&*window) } - fn SetValidity(&mut self, _validity: JS) { - } - fn ValidationMessage(&self) -> DOMString { ~"" } diff --git a/src/components/script/dom/htmlparagraphelement.rs b/src/components/script/dom/htmlparagraphelement.rs index 9bb6160d300..cf5e4aefc91 100644 --- a/src/components/script/dom/htmlparagraphelement.rs +++ b/src/components/script/dom/htmlparagraphelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLParagraphElementBinding; use dom::bindings::codegen::InheritTypes::HTMLParagraphElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLParagraphElementTypeId; @@ -28,14 +28,14 @@ impl HTMLParagraphElementDerived for EventTarget { } impl HTMLParagraphElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLParagraphElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLParagraphElement { HTMLParagraphElement { htmlelement: HTMLElement::new_inherited(HTMLParagraphElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLParagraphElement::new_inherited(localName, document.unrooted()); + let element = HTMLParagraphElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLParagraphElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlparamelement.rs b/src/components/script/dom/htmlparamelement.rs index c5a727c12a5..4443dc0cd6b 100644 --- a/src/components/script/dom/htmlparamelement.rs +++ b/src/components/script/dom/htmlparamelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLParamElementBinding; use dom::bindings::codegen::InheritTypes::HTMLParamElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLParamElementTypeId; @@ -28,14 +28,14 @@ impl HTMLParamElementDerived for EventTarget { } impl HTMLParamElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLParamElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLParamElement { HTMLParamElement { htmlelement: HTMLElement::new_inherited(HTMLParamElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLParamElement::new_inherited(localName, document.unrooted()); + let element = HTMLParamElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLParamElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlpreelement.rs b/src/components/script/dom/htmlpreelement.rs index b43b18c3028..2aa6f20c8a0 100644 --- a/src/components/script/dom/htmlpreelement.rs +++ b/src/components/script/dom/htmlpreelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLPreElementBinding; use dom::bindings::codegen::InheritTypes::HTMLPreElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLPreElementTypeId; @@ -28,14 +28,14 @@ impl HTMLPreElementDerived for EventTarget { } impl HTMLPreElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLPreElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLPreElement { HTMLPreElement { htmlelement: HTMLElement::new_inherited(HTMLPreElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLPreElement::new_inherited(localName, document.unrooted()); + let element = HTMLPreElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLPreElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlprogresselement.rs b/src/components/script/dom/htmlprogresselement.rs index 800bd7df9ff..504887a84b6 100644 --- a/src/components/script/dom/htmlprogresselement.rs +++ b/src/components/script/dom/htmlprogresselement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLProgressElementBinding; use dom::bindings::codegen::InheritTypes::HTMLProgressElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::{ErrorResult, Fallible}; use dom::document::Document; use dom::element::HTMLProgressElementTypeId; @@ -28,14 +28,14 @@ impl HTMLProgressElementDerived for EventTarget { } impl HTMLProgressElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLProgressElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLProgressElement { HTMLProgressElement { htmlelement: HTMLElement::new_inherited(HTMLProgressElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLProgressElement::new_inherited(localName, document.unrooted()); + let element = HTMLProgressElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLProgressElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlquoteelement.rs b/src/components/script/dom/htmlquoteelement.rs index a2c50a8082d..910d5ce21e7 100644 --- a/src/components/script/dom/htmlquoteelement.rs +++ b/src/components/script/dom/htmlquoteelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLQuoteElementBinding; use dom::bindings::codegen::InheritTypes::HTMLQuoteElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLQuoteElementTypeId; @@ -28,14 +28,14 @@ impl HTMLQuoteElementDerived for EventTarget { } impl HTMLQuoteElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLQuoteElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLQuoteElement { HTMLQuoteElement { htmlelement: HTMLElement::new_inherited(HTMLQuoteElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLQuoteElement::new_inherited(localName, document.unrooted()); + let element = HTMLQuoteElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLQuoteElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlscriptelement.rs b/src/components/script/dom/htmlscriptelement.rs index b392fbb95d2..522a9244fa6 100644 --- a/src/components/script/dom/htmlscriptelement.rs +++ b/src/components/script/dom/htmlscriptelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLScriptElementBinding; use dom::bindings::codegen::InheritTypes::HTMLScriptElementDerived; use dom::bindings::codegen::InheritTypes::ElementCast; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{HTMLScriptElementTypeId, Element, AttributeHandlers}; @@ -29,14 +29,14 @@ impl HTMLScriptElementDerived for EventTarget { } impl HTMLScriptElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLScriptElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLScriptElement { HTMLScriptElement { htmlelement: HTMLElement::new_inherited(HTMLScriptElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLScriptElement::new_inherited(localName, document.unrooted()); + let element = HTMLScriptElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLScriptElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlselectelement.rs b/src/components/script/dom/htmlselectelement.rs index 54d3c7cf86f..676e2266880 100644 --- a/src/components/script/dom/htmlselectelement.rs +++ b/src/components/script/dom/htmlselectelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLSelectElementBinding; use dom::bindings::codegen::InheritTypes::HTMLSelectElementDerived; use dom::bindings::codegen::UnionTypes::{HTMLElementOrLong, HTMLOptionElementOrHTMLOptGroupElement}; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLSelectElementTypeId}; @@ -32,14 +32,14 @@ impl HTMLSelectElementDerived for EventTarget { } impl HTMLSelectElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLSelectElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLSelectElement { HTMLSelectElement { htmlelement: HTMLElement::new_inherited(HTMLSelectElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLSelectElement::new_inherited(localName, document.unrooted()); + let element = HTMLSelectElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLSelectElementBinding::Wrap) } } @@ -74,7 +74,6 @@ pub trait HTMLSelectElementMethods { fn WillValidate(&self) -> bool; fn SetWillValidate(&mut self, _will_validate: bool); fn Validity(&self) -> Temporary; - fn SetValidity(&mut self, _validity: JS); fn ValidationMessage(&self) -> DOMString; fn SetValidationMessage(&mut self, _message: DOMString) -> ErrorResult; fn CheckValidity(&self) -> bool; @@ -196,9 +195,6 @@ impl<'a> HTMLSelectElementMethods for JSRef<'a, HTMLSelectElement> { ValidityState::new(&*window) } - fn SetValidity(&mut self, _validity: JS) { - } - fn ValidationMessage(&self) -> DOMString { ~"" } diff --git a/src/components/script/dom/htmlsourceelement.rs b/src/components/script/dom/htmlsourceelement.rs index 41586e55401..bc5c70a7ce6 100644 --- a/src/components/script/dom/htmlsourceelement.rs +++ b/src/components/script/dom/htmlsourceelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLSourceElementBinding; use dom::bindings::codegen::InheritTypes::HTMLSourceElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLSourceElementTypeId; @@ -28,14 +28,14 @@ impl HTMLSourceElementDerived for EventTarget { } impl HTMLSourceElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLSourceElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLSourceElement { HTMLSourceElement { htmlelement: HTMLElement::new_inherited(HTMLSourceElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLSourceElement::new_inherited(localName, document.unrooted()); + let element = HTMLSourceElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLSourceElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlspanelement.rs b/src/components/script/dom/htmlspanelement.rs index 79beef28cab..c4ccddeda33 100644 --- a/src/components/script/dom/htmlspanelement.rs +++ b/src/components/script/dom/htmlspanelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLSpanElementBinding; use dom::bindings::codegen::InheritTypes::HTMLSpanElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLSpanElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -27,14 +27,14 @@ impl HTMLSpanElementDerived for EventTarget { } impl HTMLSpanElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLSpanElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLSpanElement { HTMLSpanElement { htmlelement: HTMLElement::new_inherited(HTMLSpanElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLSpanElement::new_inherited(localName, document.unrooted()); + let element = HTMLSpanElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLSpanElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlstyleelement.rs b/src/components/script/dom/htmlstyleelement.rs index 025375efb73..d5fe24aafe3 100644 --- a/src/components/script/dom/htmlstyleelement.rs +++ b/src/components/script/dom/htmlstyleelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLStyleElementBinding; use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLStyleElementDerived, NodeCast}; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLStyleElementTypeId; @@ -31,14 +31,14 @@ impl HTMLStyleElementDerived for EventTarget { } impl HTMLStyleElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLStyleElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLStyleElement { HTMLStyleElement { htmlelement: HTMLElement::new_inherited(HTMLStyleElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLStyleElement::new_inherited(localName, document.unrooted()); + let element = HTMLStyleElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLStyleElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltablecaptionelement.rs b/src/components/script/dom/htmltablecaptionelement.rs index cc99c839e80..6586e4d2703 100644 --- a/src/components/script/dom/htmltablecaptionelement.rs +++ b/src/components/script/dom/htmltablecaptionelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableCaptionElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableCaptionElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableCaptionElementTypeId; @@ -28,14 +28,14 @@ impl HTMLTableCaptionElementDerived for EventTarget { } impl HTMLTableCaptionElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLTableCaptionElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLTableCaptionElement { HTMLTableCaptionElement { htmlelement: HTMLElement::new_inherited(HTMLTableCaptionElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLTableCaptionElement::new_inherited(localName, document.unrooted()); + let element = HTMLTableCaptionElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLTableCaptionElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltablecellelement.rs b/src/components/script/dom/htmltablecellelement.rs index 47010ccbac7..9673551c23e 100644 --- a/src/components/script/dom/htmltablecellelement.rs +++ b/src/components/script/dom/htmltablecellelement.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::InheritTypes::HTMLTableCellElementDerived; -use dom::bindings::js::{JS, JSRef}; +use dom::bindings::js::JSRef; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{ElementTypeId, HTMLTableDataCellElementTypeId, HTMLTableHeaderCellElementTypeId}; @@ -28,7 +28,7 @@ impl HTMLTableCellElementDerived for EventTarget { } impl HTMLTableCellElement { - pub fn new_inherited(type_id: ElementTypeId, tag_name: DOMString, document: JS) -> HTMLTableCellElement { + pub fn new_inherited(type_id: ElementTypeId, tag_name: DOMString, document: &JSRef) -> HTMLTableCellElement { HTMLTableCellElement { htmlelement: HTMLElement::new_inherited(type_id, tag_name, document) } diff --git a/src/components/script/dom/htmltablecolelement.rs b/src/components/script/dom/htmltablecolelement.rs index e387e5ad2cc..cc126ad81e0 100644 --- a/src/components/script/dom/htmltablecolelement.rs +++ b/src/components/script/dom/htmltablecolelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableColElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableColElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableColElementTypeId; @@ -28,14 +28,14 @@ impl HTMLTableColElementDerived for EventTarget { } impl HTMLTableColElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLTableColElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLTableColElement { HTMLTableColElement { htmlelement: HTMLElement::new_inherited(HTMLTableColElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLTableColElement::new_inherited(localName, document.unrooted()); + let element = HTMLTableColElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLTableColElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltabledatacellelement.rs b/src/components/script/dom/htmltabledatacellelement.rs index d9c0f208bff..c62fc8fd191 100644 --- a/src/components/script/dom/htmltabledatacellelement.rs +++ b/src/components/script/dom/htmltabledatacellelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableDataCellElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableDataCellElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLTableDataCellElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -27,14 +27,14 @@ impl HTMLTableDataCellElementDerived for EventTarget { } impl HTMLTableDataCellElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLTableDataCellElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLTableDataCellElement { HTMLTableDataCellElement { htmltablecellelement: HTMLTableCellElement::new_inherited(HTMLTableDataCellElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLTableDataCellElement::new_inherited(localName, document.unrooted()); + let element = HTMLTableDataCellElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLTableDataCellElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltableelement.rs b/src/components/script/dom/htmltableelement.rs index bebf407b73a..f734f9a4ec4 100644 --- a/src/components/script/dom/htmltableelement.rs +++ b/src/components/script/dom/htmltableelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableElementTypeId; @@ -28,14 +28,14 @@ impl HTMLTableElementDerived for EventTarget { } impl HTMLTableElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLTableElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLTableElement { HTMLTableElement { htmlelement: HTMLElement::new_inherited(HTMLTableElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLTableElement::new_inherited(localName, document.unrooted()); + let element = HTMLTableElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLTableElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltableheadercellelement.rs b/src/components/script/dom/htmltableheadercellelement.rs index beb9c5e2f97..1d4245fef5a 100644 --- a/src/components/script/dom/htmltableheadercellelement.rs +++ b/src/components/script/dom/htmltableheadercellelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableHeaderCellElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableHeaderCellElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLTableHeaderCellElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -27,14 +27,14 @@ impl HTMLTableHeaderCellElementDerived for EventTarget { } impl HTMLTableHeaderCellElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLTableHeaderCellElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLTableHeaderCellElement { HTMLTableHeaderCellElement { htmltablecellelement: HTMLTableCellElement::new_inherited(HTMLTableHeaderCellElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLTableHeaderCellElement::new_inherited(localName, document.unrooted()); + let element = HTMLTableHeaderCellElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLTableHeaderCellElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltablerowelement.rs b/src/components/script/dom/htmltablerowelement.rs index 0d949741b4c..35956388968 100644 --- a/src/components/script/dom/htmltablerowelement.rs +++ b/src/components/script/dom/htmltablerowelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableRowElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableRowElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableRowElementTypeId; @@ -28,14 +28,14 @@ impl HTMLTableRowElementDerived for EventTarget { } impl HTMLTableRowElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLTableRowElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLTableRowElement { HTMLTableRowElement { htmlelement: HTMLElement::new_inherited(HTMLTableRowElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLTableRowElement::new_inherited(localName, document.unrooted()); + let element = HTMLTableRowElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLTableRowElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltablesectionelement.rs b/src/components/script/dom/htmltablesectionelement.rs index 5eefa98722a..b22a8ee694f 100644 --- a/src/components/script/dom/htmltablesectionelement.rs +++ b/src/components/script/dom/htmltablesectionelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTableSectionElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTableSectionElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTableSectionElementTypeId; @@ -28,14 +28,14 @@ impl HTMLTableSectionElementDerived for EventTarget { } impl HTMLTableSectionElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLTableSectionElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLTableSectionElement { HTMLTableSectionElement { htmlelement: HTMLElement::new_inherited(HTMLTableSectionElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLTableSectionElement::new_inherited(localName, document.unrooted()); + let element = HTMLTableSectionElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLTableSectionElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltemplateelement.rs b/src/components/script/dom/htmltemplateelement.rs index 8e3b8d115ed..30bf8219d60 100644 --- a/src/components/script/dom/htmltemplateelement.rs +++ b/src/components/script/dom/htmltemplateelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTemplateElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTemplateElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLTemplateElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -27,14 +27,14 @@ impl HTMLTemplateElementDerived for EventTarget { } impl HTMLTemplateElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLTemplateElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLTemplateElement { HTMLTemplateElement { htmlelement: HTMLElement::new_inherited(HTMLTemplateElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLTemplateElement::new_inherited(localName, document.unrooted()); + let element = HTMLTemplateElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLTemplateElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltextareaelement.rs b/src/components/script/dom/htmltextareaelement.rs index 7e221cbbd3e..25a3742bc33 100644 --- a/src/components/script/dom/htmltextareaelement.rs +++ b/src/components/script/dom/htmltextareaelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTextAreaElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTextAreaElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::{ErrorResult, Fallible}; use dom::document::Document; use dom::element::HTMLTextAreaElementTypeId; @@ -28,14 +28,14 @@ impl HTMLTextAreaElementDerived for EventTarget { } impl HTMLTextAreaElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLTextAreaElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLTextAreaElement { HTMLTextAreaElement { htmlelement: HTMLElement::new_inherited(HTMLTextAreaElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLTextAreaElement::new_inherited(localName, document.unrooted()); + let element = HTMLTextAreaElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLTextAreaElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltimeelement.rs b/src/components/script/dom/htmltimeelement.rs index 15e8101561f..63a73d2f63e 100644 --- a/src/components/script/dom/htmltimeelement.rs +++ b/src/components/script/dom/htmltimeelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTimeElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTimeElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTimeElementTypeId; @@ -28,14 +28,14 @@ impl HTMLTimeElementDerived for EventTarget { } impl HTMLTimeElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLTimeElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLTimeElement { HTMLTimeElement { htmlelement: HTMLElement::new_inherited(HTMLTimeElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLTimeElement::new_inherited(localName, document.unrooted()); + let element = HTMLTimeElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLTimeElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltitleelement.rs b/src/components/script/dom/htmltitleelement.rs index 5f7016bc96c..55383c0e62a 100644 --- a/src/components/script/dom/htmltitleelement.rs +++ b/src/components/script/dom/htmltitleelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTitleElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTitleElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTitleElementTypeId; @@ -28,14 +28,14 @@ impl HTMLTitleElementDerived for EventTarget { } impl HTMLTitleElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLTitleElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLTitleElement { HTMLTitleElement { htmlelement: HTMLElement::new_inherited(HTMLTitleElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLTitleElement::new_inherited(localName, document.unrooted()); + let element = HTMLTitleElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLTitleElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmltrackelement.rs b/src/components/script/dom/htmltrackelement.rs index b2b2b077c78..5f0f80708ad 100644 --- a/src/components/script/dom/htmltrackelement.rs +++ b/src/components/script/dom/htmltrackelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLTrackElementBinding; use dom::bindings::codegen::InheritTypes::HTMLTrackElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLTrackElementTypeId; @@ -28,14 +28,14 @@ impl HTMLTrackElementDerived for EventTarget { } impl HTMLTrackElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLTrackElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLTrackElement { HTMLTrackElement { htmlelement: HTMLElement::new_inherited(HTMLTrackElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLTrackElement::new_inherited(localName, document.unrooted()); + let element = HTMLTrackElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLTrackElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlulistelement.rs b/src/components/script/dom/htmlulistelement.rs index 5d5bd0b61da..f91f96a7b90 100644 --- a/src/components/script/dom/htmlulistelement.rs +++ b/src/components/script/dom/htmlulistelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLUListElementBinding; use dom::bindings::codegen::InheritTypes::HTMLUListElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLUListElementTypeId; @@ -28,14 +28,14 @@ impl HTMLUListElementDerived for EventTarget { } impl HTMLUListElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLUListElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLUListElement { HTMLUListElement { htmlelement: HTMLElement::new_inherited(HTMLUListElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLUListElement::new_inherited(localName, document.unrooted()); + let element = HTMLUListElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLUListElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlunknownelement.rs b/src/components/script/dom/htmlunknownelement.rs index 2fbf2906c3d..855b17578e5 100644 --- a/src/components/script/dom/htmlunknownelement.rs +++ b/src/components/script/dom/htmlunknownelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLUnknownElementBinding; use dom::bindings::codegen::InheritTypes::HTMLUnknownElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; use dom::element::HTMLUnknownElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -27,14 +27,14 @@ impl HTMLUnknownElementDerived for EventTarget { } impl HTMLUnknownElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLUnknownElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLUnknownElement { HTMLUnknownElement { htmlelement: HTMLElement::new_inherited(HTMLUnknownElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLUnknownElement::new_inherited(localName, document.unrooted()); + let element = HTMLUnknownElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLUnknownElementBinding::Wrap) } } diff --git a/src/components/script/dom/htmlvideoelement.rs b/src/components/script/dom/htmlvideoelement.rs index 68925daacee..22bdc154bba 100644 --- a/src/components/script/dom/htmlvideoelement.rs +++ b/src/components/script/dom/htmlvideoelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::HTMLVideoElementBinding; use dom::bindings::codegen::InheritTypes::HTMLVideoElementDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLVideoElementTypeId; @@ -28,14 +28,14 @@ impl HTMLVideoElementDerived for EventTarget { } impl HTMLVideoElement { - pub fn new_inherited(localName: DOMString, document: JS) -> HTMLVideoElement { + pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLVideoElement { HTMLVideoElement { htmlmediaelement: HTMLMediaElement::new_inherited(HTMLVideoElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { - let element = HTMLVideoElement::new_inherited(localName, document.unrooted()); + let element = HTMLVideoElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLVideoElementBinding::Wrap) } } diff --git a/src/components/script/dom/mouseevent.rs b/src/components/script/dom/mouseevent.rs index f35c088675c..f813b023961 100644 --- a/src/components/script/dom/mouseevent.rs +++ b/src/components/script/dom/mouseevent.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::MouseEventBinding; use dom::bindings::codegen::InheritTypes::{UIEventCast, MouseEventDerived}; -use dom::bindings::js::{JS, JSRef, RootedReference, Temporary}; +use dom::bindings::js::{JS, JSRef, RootedReference, Temporary, OptionalSettable}; use dom::bindings::error::Fallible; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::event::{Event, MouseEventTypeId}; @@ -68,7 +68,7 @@ impl MouseEvent { init.clientX, init.clientY, init.ctrlKey, init.altKey, init.shiftKey, init.metaKey, init.button, related_target.root_ref()); - Ok(Temporary::new_rooted(&*ev)) + Ok(Temporary::from_rooted(&*ev)) } } @@ -183,7 +183,7 @@ impl<'a> MouseEventMethods for JSRef<'a, MouseEvent> { self.shift_key = shiftKeyArg; self.meta_key = metaKeyArg; self.button = buttonArg; - self.related_target = relatedTargetArg.map(|target| target.unrooted()); + self.related_target.assign(relatedTargetArg); } } diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 772d1fbcc39..a102f916505 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -11,7 +11,7 @@ use dom::bindings::codegen::InheritTypes::{CharacterDataCast, NodeBase, NodeDeri use dom::bindings::codegen::InheritTypes::{ProcessingInstructionCast, EventTargetCast}; use dom::bindings::codegen::BindingDeclarations::NodeBinding::NodeConstants; use dom::bindings::js::{JS, JSRef, RootedReference, Temporary, Root}; -use dom::bindings::js::{OptionalAssignable, TemporaryPushable, OptionalRootedRootable}; +use dom::bindings::js::{OptionalSettable, TemporaryPushable, OptionalRootedRootable}; use dom::bindings::js::{ResultRootable, OptionalRootable}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::{ErrorResult, Fallible, NotFound, HierarchyRequest}; @@ -566,7 +566,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { fn is_parent_of(&self, child: &JSRef) -> bool { match child.parent_node() { - Some(ref parent) if *parent == Temporary::new_rooted(self) => true, + Some(ref parent) if *parent == Temporary::from_rooted(self) => true, _ => false } } @@ -604,7 +604,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { } fn set_owner_doc(&mut self, document: &JSRef) { - self.owner_doc = Some(document.unrooted()); + self.owner_doc.assign(Some(document.clone())); } fn children(&self) -> AbstractNodeChildrenIterator { @@ -891,12 +891,11 @@ impl Node { let window = document.get().window.root(); let node = reflect_dom_object(node, &window.root_ref(), wrap_fn).root(); assert!(node.reflector().get_jsobject().is_not_null()); - Temporary::new_rooted(&*node) + Temporary::from_rooted(&*node) } - pub fn new_inherited(type_id: NodeTypeId, doc: JS) -> Node { - let doc = doc.root(); - Node::new_(type_id, Some(doc.root_ref())) + pub fn new_inherited(type_id: NodeTypeId, doc: &JSRef) -> Node { + Node::new_(type_id, Some(doc.clone())) } pub fn new_without_doc(type_id: NodeTypeId) -> Node { @@ -1079,7 +1078,7 @@ impl Node { Node::insert(node, parent, referenceChild, Unsuppressed); // Step 11. - return Ok(Temporary::new_rooted(node)) + return Ok(Temporary::from_rooted(node)) } // http://dom.spec.whatwg.org/#concept-node-insert @@ -1174,7 +1173,7 @@ impl Node { fn pre_remove(child: &mut JSRef, parent: &mut JSRef) -> Fallible> { // Step 1. match child.parent_node() { - Some(ref node) if *node != Temporary::new_rooted(parent) => return Err(NotFound), + Some(ref node) if *node != Temporary::from_rooted(parent) => return Err(NotFound), _ => () } @@ -1182,12 +1181,12 @@ impl Node { Node::remove(child, parent, Unsuppressed); // Step 3. - Ok(Temporary::new_rooted(child)) + Ok(Temporary::from_rooted(child)) } // http://dom.spec.whatwg.org/#concept-node-remove fn remove(node: &mut JSRef, parent: &mut JSRef, suppress_observers: SuppressObserver) { - assert!(node.parent_node().map_or(false, |node_parent| node_parent == Temporary::new_rooted(parent))); + assert!(node.parent_node().map_or(false, |node_parent| node_parent == Temporary::from_rooted(parent))); // Step 1-5: ranges. // Step 6-7: mutation observers. @@ -1296,10 +1295,10 @@ impl Node { let window = document.get().window.root(); for attr in node_elem.attrs.iter().map(|attr| attr.root()) { copy_elem.attrs.push_unrooted( - Attr::new(&*window, - attr.deref().local_name.clone(), attr.deref().value.clone(), - attr.deref().name.clone(), attr.deref().namespace.clone(), - attr.deref().prefix.clone(), ©_elem_alias)); + &Attr::new(&*window, + attr.deref().local_name.clone(), attr.deref().value.clone(), + attr.deref().name.clone(), attr.deref().namespace.clone(), + attr.deref().prefix.clone(), ©_elem_alias)); } }, _ => () @@ -1316,7 +1315,7 @@ impl Node { } // Step 7. - Temporary::new_rooted(&*copy) + Temporary::from_rooted(&*copy) } /// Sends layout data, if any, back to the script task to be destroyed. @@ -1433,7 +1432,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { .and_then(|parent| { let parent = parent.root(); ElementCast::to_ref(&*parent).map(|elem| { - Temporary::new_rooted(elem) + Temporary::from_rooted(elem) }) }) } @@ -1546,7 +1545,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { let document = self.owner_doc().root(); Some(NodeCast::from_unrooted(document.deref().CreateTextNode(value))) }.root(); - + // Step 3. Node::replace_all(node.root_ref(), self); } @@ -1671,8 +1670,8 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // Ok if not caught by previous error checks. - if node.unrooted() == child.unrooted() { - return Ok(Temporary::new_rooted(child)); + if *node == *child { + return Ok(Temporary::from_rooted(child)); } // Step 7-8. @@ -1706,7 +1705,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // Step 15. - Ok(Temporary::new_rooted(child)) + Ok(Temporary::from_rooted(child)) } // http://dom.spec.whatwg.org/#dom-node-removechild diff --git a/src/components/script/dom/nodelist.rs b/src/components/script/dom/nodelist.rs index 5c02eca8d08..dc050b995ea 100644 --- a/src/components/script/dom/nodelist.rs +++ b/src/components/script/dom/nodelist.rs @@ -22,18 +22,18 @@ pub struct NodeList { } impl NodeList { - pub fn new_inherited(window: JS, + pub fn new_inherited(window: &JSRef, list_type: NodeListType) -> NodeList { NodeList { list_type: list_type, reflector_: Reflector::new(), - window: window + window: window.unrooted() } } pub fn new(window: &JSRef, list_type: NodeListType) -> Temporary { - reflect_dom_object(~NodeList::new_inherited(window.unrooted(), list_type), + reflect_dom_object(~NodeList::new_inherited(window, list_type), window, NodeListBinding::Wrap) } @@ -70,7 +70,7 @@ impl<'a> NodeListMethods for JSRef<'a, NodeList> { Children(ref node) => { let node = node.root(); node.deref().children().nth(index as uint) - .map(|child| Temporary::new_rooted(&child)) + .map(|child| Temporary::from_rooted(&child)) } } } diff --git a/src/components/script/dom/processinginstruction.rs b/src/components/script/dom/processinginstruction.rs index 9a00333fd93..1152a9c20b2 100644 --- a/src/components/script/dom/processinginstruction.rs +++ b/src/components/script/dom/processinginstruction.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::ProcessingInstructionBinding; use dom::bindings::codegen::InheritTypes::ProcessingInstructionDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::characterdata::CharacterData; use dom::document::Document; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; @@ -28,7 +28,7 @@ impl ProcessingInstructionDerived for EventTarget { } impl ProcessingInstruction { - pub fn new_inherited(target: DOMString, data: DOMString, document: JS) -> ProcessingInstruction { + pub fn new_inherited(target: DOMString, data: DOMString, document: &JSRef) -> ProcessingInstruction { ProcessingInstruction { characterdata: CharacterData::new_inherited(ProcessingInstructionNodeTypeId, data, document), target: target @@ -36,7 +36,7 @@ impl ProcessingInstruction { } pub fn new(target: DOMString, data: DOMString, document: &JSRef) -> Temporary { - let node = ProcessingInstruction::new_inherited(target, data, document.unrooted()); + let node = ProcessingInstruction::new_inherited(target, data, document); Node::reflect_node(~node, document, ProcessingInstructionBinding::Wrap) } } diff --git a/src/components/script/dom/text.rs b/src/components/script/dom/text.rs index d286c7f5361..0f331090e37 100644 --- a/src/components/script/dom/text.rs +++ b/src/components/script/dom/text.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::TextBinding; use dom::bindings::codegen::InheritTypes::TextDerived; -use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::Fallible; use dom::characterdata::CharacterData; use dom::document::Document; @@ -29,14 +29,14 @@ impl TextDerived for EventTarget { } impl Text { - pub fn new_inherited(text: DOMString, document: JS) -> Text { + pub fn new_inherited(text: DOMString, document: &JSRef) -> Text { Text { characterdata: CharacterData::new_inherited(TextNodeTypeId, text, document) } } pub fn new(text: DOMString, document: &JSRef) -> Temporary { - let node = Text::new_inherited(text, document.unrooted()); + let node = Text::new_inherited(text, document); Node::reflect_node(~node, document, TextBinding::Wrap) } diff --git a/src/components/script/dom/uievent.rs b/src/components/script/dom/uievent.rs index 90e4daa872b..3da3e509918 100644 --- a/src/components/script/dom/uievent.rs +++ b/src/components/script/dom/uievent.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::BindingDeclarations::UIEventBinding; use dom::bindings::codegen::InheritTypes::{EventCast, UIEventDerived}; -use dom::bindings::js::{JS, JSRef, RootedReference, Temporary}; +use dom::bindings::js::{JS, JSRef, RootedReference, Temporary, OptionalSettable}; use dom::bindings::error::Fallible; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::event::{Event, EventMethods, EventTypeId, UIEventTypeId}; @@ -49,7 +49,7 @@ impl UIEvent { let view = init.view.as_ref().map(|view| view.root()); ev.InitUIEvent(type_, init.parent.bubbles, init.parent.cancelable, view.root_ref(), init.detail); - Ok(Temporary::new_rooted(&*ev)) + Ok(Temporary::from_rooted(&*ev)) } } @@ -93,7 +93,7 @@ impl<'a> UIEventMethods for JSRef<'a, UIEvent> { let event: &mut JSRef = EventCast::from_mut_ref(self); event.InitEvent(type_, can_bubble, cancelable); } - self.view = view.map(|view| view.unrooted()); + self.view.assign(view); self.detail = detail; } diff --git a/src/components/script/dom/validitystate.rs b/src/components/script/dom/validitystate.rs index f60e646b3ff..7069b1572dd 100644 --- a/src/components/script/dom/validitystate.rs +++ b/src/components/script/dom/validitystate.rs @@ -15,16 +15,16 @@ pub struct ValidityState { } impl ValidityState { - pub fn new_inherited(window: JS) -> ValidityState { + pub fn new_inherited(window: &JSRef) -> ValidityState { ValidityState { reflector_: Reflector::new(), - window: window, + window: window.unrooted(), state: 0, } } pub fn new(window: &JSRef) -> Temporary { - reflect_dom_object(~ValidityState::new_inherited(window.unrooted()), + reflect_dom_object(~ValidityState::new_inherited(window), window, ValidityStateBinding::Wrap) } diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index 3908db73326..258a85b1455 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::WindowBinding; -use dom::bindings::js::{JS, JSRef, Temporary, OptionalAssignable}; +use dom::bindings::js::{JS, JSRef, Temporary, OptionalSettable}; use dom::bindings::trace::{Traceable, Untraceable}; use dom::bindings::utils::{Reflectable, Reflector}; use dom::browsercontext::BrowserContext; @@ -242,7 +242,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> { } fn Window(&self) -> Temporary { - Temporary::new_rooted(self) + Temporary::from_rooted(self) } fn Self(&self) -> Temporary { diff --git a/src/components/script/dom/xmlhttprequest.rs b/src/components/script/dom/xmlhttprequest.rs index 7e949a4b2b9..5543f508315 100644 --- a/src/components/script/dom/xmlhttprequest.rs +++ b/src/components/script/dom/xmlhttprequest.rs @@ -10,7 +10,7 @@ use dom::bindings::codegen::InheritTypes::XMLHttpRequestDerived; use dom::document::Document; use dom::eventtarget::{EventTarget, XMLHttpRequestTargetTypeId}; use dom::bindings::error::Fallible; -use dom::bindings::js::{JS, JSRef, Temporary, OptionalAssignable}; +use dom::bindings::js::{JS, JSRef, Temporary, OptionalSettable}; use js::jsapi::JSContext; use js::jsval::{JSVal, NullValue}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index fe609cfc467..1363a1dbc3d 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -8,7 +8,7 @@ use dom::attr::AttrMethods; use dom::bindings::codegen::RegisterBindings; use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, ElementCast, EventCast}; -use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalAssignable}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalSettable}; use dom::bindings::js::OptionalRootable; use dom::bindings::trace::{Traceable, Untraceable}; use dom::bindings::utils::{Reflectable, GlobalStaticData, wrap_for_same_compartment}; @@ -421,7 +421,7 @@ impl Page { elem.get_attribute(Null, "name").root().map_or(false, |attr| { attr.get().value_ref() == fragid }) - }).map(|node| Temporary::new_rooted(ElementCast::to_ref(&node).unwrap())) + }).map(|node| Temporary::from_rooted(ElementCast::to_ref(&node).unwrap())) } } } @@ -907,7 +907,7 @@ impl ScriptTask { { let mut js_info = page.mut_js_info(); - RegisterBindings::Register(&*window, js_info.get_mut_ref()); + RegisterBindings::Register(&window.unrooted(), js_info.get_mut_ref()); } self.compositor.set_ready_state(Loading); From 895e9ee37fb572f7750c02de4fc51060990c51be Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 24 Apr 2014 11:44:53 -0400 Subject: [PATCH 14/16] Make dictionaries contain Root values instead of JS, ensuring that they will not be collected while the dictionary is alive. --- .../script/dom/bindings/codegen/CodegenRust.py | 15 ++++++++++----- .../script/dom/bindings/codegen/Configuration.py | 1 + src/components/script/dom/bindings/js.rs | 6 ++++++ src/components/script/dom/mouseevent.rs | 6 ++---- src/components/script/dom/uievent.rs | 3 +-- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 1aa46c6a44a..8c9eb5d6f8b 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -602,6 +602,8 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, failureCode) return handleOptional(template, declType, isOptional) + descriptorType = descriptor.memberType if isMember else descriptor.nativeType + templateBody = "" if descriptor.interface.isConsequential(): raise TypeError("Consequential interface %s being used as an " @@ -617,11 +619,14 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, descriptor, "(${val}).to_object()")) - declType = CGGeneric(descriptor.nativeType) + declType = CGGeneric(descriptorType) if type.nullable(): templateBody = "Some(%s)" % templateBody declType = CGWrapper(declType, pre="Option<", post=">") + if isMember: + templateBody += ".root()" + templateBody = wrapObjectTemplate(templateBody, isDefinitelyObject, type, failureCode) @@ -4069,7 +4074,7 @@ class CGDictionary(CGThing): def struct(self): d = self.dictionary if d.parent: - inheritance = " pub parent: %s::%s,\n" % (self.makeModuleName(d.parent), + inheritance = " pub parent: %s::%s<'a, 'b>,\n" % (self.makeModuleName(d.parent), self.makeClassName(d.parent)) else: inheritance = "" @@ -4078,7 +4083,7 @@ class CGDictionary(CGThing): for m in self.memberInfo] return (string.Template( - "pub struct ${selfName} {\n" + + "pub struct ${selfName}<'a, 'b> {\n" + "${inheritance}" + "\n".join(memberDecls) + "\n" + "}").substitute( { "selfName": self.makeClassName(d), @@ -4104,7 +4109,7 @@ class CGDictionary(CGThing): memberInits = CGList([memberInit(m) for m in self.memberInfo]) return string.Template( - "impl ${selfName} {\n" + "impl<'a, 'b> ${selfName}<'a, 'b> {\n" " pub fn new(cx: *JSContext, val: JSVal) -> Result<${selfName}, ()> {\n" " let object = if val.is_null_or_undefined() {\n" " ptr::null()\n" @@ -4305,7 +4310,7 @@ class CGBindingRoot(CGThing): 'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}', 'dom::types::*', 'dom::bindings', - 'dom::bindings::js::{JS, JSRef, RootedReference, Temporary, OptionalRootable, OptionalRootedRootable}', + 'dom::bindings::js::{JS, JSRef, Root, RootedReference, Temporary, OptionalRootable, OptionalRootedRootable, ResultRootable}', 'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}', 'dom::bindings::utils::{ConstantSpec, cx_for_dom_object, Default}', 'dom::bindings::utils::{dom_object_slot, DOM_OBJECT_SLOT, DOMClass}', diff --git a/src/components/script/dom/bindings/codegen/Configuration.py b/src/components/script/dom/bindings/codegen/Configuration.py index c5b9ebb1044..dc4daa18b26 100644 --- a/src/components/script/dom/bindings/codegen/Configuration.py +++ b/src/components/script/dom/bindings/codegen/Configuration.py @@ -135,6 +135,7 @@ class Descriptor(DescriptorProvider): self.returnType = "Temporary<%s>" % ifaceName self.argumentType = "JSRef<%s>" % ifaceName + self.memberType = "Root<'a, 'b, %s>" % ifaceName self.nativeType = desc.get('nativeType', nativeTypeDefault) self.concreteType = desc.get('concreteType', ifaceName) self.createGlobal = desc.get('createGlobal', False) diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs index 37694e3beb1..eee20a17e83 100644 --- a/src/components/script/dom/bindings/js.rs +++ b/src/components/script/dom/bindings/js.rs @@ -284,6 +284,12 @@ impl ResultRootable for Result, U> { } } +impl ResultRootable for Result, U> { + fn root<'a, 'b>(self) -> Result, U> { + self.map(|inner| inner.root()) + } +} + /// Provides a facility to push unrooted values onto lists of rooted values. This is safe /// under the assumption that said lists are reachable via the GC graph, and therefore the /// new values are transitively rooted for the lifetime of their new owner. diff --git a/src/components/script/dom/mouseevent.rs b/src/components/script/dom/mouseevent.rs index f813b023961..fbd0abfc4d4 100644 --- a/src/components/script/dom/mouseevent.rs +++ b/src/components/script/dom/mouseevent.rs @@ -61,13 +61,11 @@ impl MouseEvent { type_: DOMString, init: &MouseEventBinding::MouseEventInit) -> Fallible> { let mut ev = MouseEvent::new(owner).root(); - let view = init.view.as_ref().map(|view| view.root()); - let related_target = init.relatedTarget.as_ref().map(|relatedTarget| relatedTarget.root()); - ev.InitMouseEvent(type_, init.bubbles, init.cancelable, view.root_ref(), + ev.InitMouseEvent(type_, init.bubbles, init.cancelable, init.view.root_ref(), init.detail, init.screenX, init.screenY, init.clientX, init.clientY, init.ctrlKey, init.altKey, init.shiftKey, init.metaKey, - init.button, related_target.root_ref()); + init.button, init.relatedTarget.root_ref()); Ok(Temporary::from_rooted(&*ev)) } } diff --git a/src/components/script/dom/uievent.rs b/src/components/script/dom/uievent.rs index 3da3e509918..2af9ca3540d 100644 --- a/src/components/script/dom/uievent.rs +++ b/src/components/script/dom/uievent.rs @@ -46,9 +46,8 @@ impl UIEvent { type_: DOMString, init: &UIEventBinding::UIEventInit) -> Fallible> { let mut ev = UIEvent::new(owner).root(); - let view = init.view.as_ref().map(|view| view.root()); ev.InitUIEvent(type_, init.parent.bubbles, init.parent.cancelable, - view.root_ref(), init.detail); + init.view.root_ref(), init.detail); Ok(Temporary::from_rooted(&*ev)) } } From 46a33b4b38666252245af5dd3a38bb6f57ff8a8e Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 24 Apr 2014 13:01:31 -0400 Subject: [PATCH 15/16] Fix up the virtual method unsoundness. --- src/components/script/dom/attr.rs | 4 +-- src/components/script/dom/element.rs | 5 ++-- src/components/script/dom/node.rs | 13 +++++----- src/components/script/dom/virtualmethods.rs | 28 ++++++++++----------- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/components/script/dom/attr.rs b/src/components/script/dom/attr.rs index 76bf3ff1ede..4822de7eb07 100644 --- a/src/components/script/dom/attr.rs +++ b/src/components/script/dom/attr.rs @@ -65,8 +65,8 @@ impl Attr { } pub fn set_value(&mut self, set_type: AttrSettingType, value: DOMString) { - let owner = self.owner.root(); - let node: &JSRef = NodeCast::from_ref(&*owner); + let mut owner = self.owner.root(); + let node: &mut JSRef = NodeCast::from_mut_ref(&mut *owner); let namespace_is_null = self.namespace == namespace::Null; match set_type { diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index 0e5795a69a0..2ee655f6156 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -301,13 +301,14 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { None => (), Some(idx) => { { - let node: &JSRef = NodeCast::from_ref(self); + let node: &mut JSRef = NodeCast::from_mut_ref(self); node.wait_until_safe_to_modify_dom(); } if namespace == namespace::Null { let removed_raw_value = self.get().attrs.get(idx).root().Value(); - vtable_for(NodeCast::from_ref(self)).before_remove_attr(local_name.clone(), removed_raw_value); + vtable_for(NodeCast::from_mut_ref(self)) + .before_remove_attr(local_name.clone(), removed_raw_value); } self.get_mut().attrs.remove(idx); diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index a102f916505..6a3d0aa14f5 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -244,24 +244,25 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> { let document = document_from_node(self).root(); if self.is_in_doc() { - for node in self.traverse_preorder() { - vtable_for(&node).bind_to_tree(); + for mut node in self.traverse_preorder() { + vtable_for(&mut node).bind_to_tree(); } } - self.parent_node().root().map(|parent| vtable_for(&*parent).child_inserted(self)); + let mut parent = self.parent_node().root(); + parent.as_mut().map(|parent| vtable_for(&mut **parent).child_inserted(self)); document.deref().content_changed(); } - // http://dom.spec.whatwg.org/#node-is-removed + // http://spec.whatwg.org/#node-is-removed fn node_removed(&self) { assert!(self.parent_node().is_none()); let document = document_from_node(self).root(); - for node in self.traverse_preorder() { + for mut node in self.traverse_preorder() { // XXX how about if the node wasn't in the tree in the first place? - vtable_for(&node).unbind_from_tree(); + vtable_for(&mut node).unbind_from_tree(); } document.deref().content_changed(); diff --git a/src/components/script/dom/virtualmethods.rs b/src/components/script/dom/virtualmethods.rs index bf4681fab3b..f67d97985e1 100644 --- a/src/components/script/dom/virtualmethods.rs +++ b/src/components/script/dom/virtualmethods.rs @@ -74,34 +74,34 @@ pub trait VirtualMethods { /// method call on the trait object will invoke the corresponding method on the /// concrete type, propagating up the parent hierarchy unless otherwise /// interrupted. -pub fn vtable_for<'a>(node: &JSRef) -> ~VirtualMethods: { +pub fn vtable_for<'a>(node: &'a mut JSRef) -> &'a mut VirtualMethods: { match node.get().type_id { ElementNodeTypeId(HTMLImageElementTypeId) => { - let element: &JSRef = HTMLImageElementCast::to_ref(node).unwrap(); - ~element.clone() as ~VirtualMethods: + let element: &mut JSRef = HTMLImageElementCast::to_mut_ref(node).unwrap(); + element as &mut VirtualMethods: } ElementNodeTypeId(HTMLIFrameElementTypeId) => { - let element: &JSRef = HTMLIFrameElementCast::to_ref(node).unwrap(); - ~element.clone() as ~VirtualMethods: + let element: &mut JSRef = HTMLIFrameElementCast::to_mut_ref(node).unwrap(); + element as &mut VirtualMethods: } ElementNodeTypeId(HTMLObjectElementTypeId) => { - let element: &JSRef = HTMLObjectElementCast::to_ref(node).unwrap(); - ~element.clone() as ~VirtualMethods: + let element: &mut JSRef = HTMLObjectElementCast::to_mut_ref(node).unwrap(); + element as &mut VirtualMethods: } ElementNodeTypeId(HTMLStyleElementTypeId) => { - let element: &JSRef = HTMLStyleElementCast::to_ref(node).unwrap(); - ~element.clone() as ~VirtualMethods: + let element: &mut JSRef = HTMLStyleElementCast::to_mut_ref(node).unwrap(); + element as &mut VirtualMethods: } ElementNodeTypeId(ElementTypeId) => { - let element: &JSRef = ElementCast::to_ref(node).unwrap(); - ~element.clone() as ~VirtualMethods: + let element: &mut JSRef = ElementCast::to_mut_ref(node).unwrap(); + element as &mut VirtualMethods: } ElementNodeTypeId(_) => { - let element: &JSRef = HTMLElementCast::to_ref(node).unwrap(); - ~element.clone() as ~VirtualMethods: + let element: &mut JSRef = HTMLElementCast::to_mut_ref(node).unwrap(); + element as &mut VirtualMethods: } _ => { - ~node.clone() as ~VirtualMethods: + node as &mut VirtualMethods: } } } From 91278da9dd55582401154e07f9eea34425a332c2 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 24 Apr 2014 13:03:19 -0400 Subject: [PATCH 16/16] Address review comments. --- .../script/dom/bindings/codegen/Bindings.conf | 4 +- .../dom/bindings/codegen/CodegenRust.py | 66 ++++----- .../dom/bindings/codegen/Configuration.py | 9 +- src/components/script/dom/bindings/js.rs | 140 ++++++++++-------- src/components/script/dom/bindings/utils.rs | 8 +- src/components/script/dom/browsercontext.rs | 4 +- src/components/script/dom/document.rs | 33 ++--- src/components/script/dom/documenttype.rs | 1 - src/components/script/dom/domparser.rs | 3 +- src/components/script/dom/element.rs | 42 +++--- src/components/script/dom/event.rs | 6 +- src/components/script/dom/eventdispatcher.rs | 42 +++--- src/components/script/dom/eventtarget.rs | 4 +- src/components/script/dom/formdata.rs | 4 +- src/components/script/dom/htmlbaseelement.rs | 1 - src/components/script/dom/htmlbodyelement.rs | 1 - src/components/script/dom/htmlbrelement.rs | 1 - .../script/dom/htmlbuttonelement.rs | 1 - .../script/dom/htmlcanvaselement.rs | 1 - src/components/script/dom/htmlcollection.rs | 9 +- src/components/script/dom/htmldataelement.rs | 1 - .../script/dom/htmldatalistelement.rs | 3 +- .../script/dom/htmldirectoryelement.rs | 1 - src/components/script/dom/htmldivelement.rs | 1 - src/components/script/dom/htmlelement.rs | 6 +- src/components/script/dom/htmlembedelement.rs | 1 - .../script/dom/htmlfieldsetelement.rs | 3 +- src/components/script/dom/htmlfontelement.rs | 1 - src/components/script/dom/htmlformelement.rs | 1 - src/components/script/dom/htmlframeelement.rs | 1 - .../script/dom/htmlframesetelement.rs | 1 - .../script/dom/htmlheadingelement.rs | 1 - src/components/script/dom/htmlhrelement.rs | 1 - src/components/script/dom/htmlhtmlelement.rs | 1 - .../script/dom/htmliframeelement.rs | 10 +- src/components/script/dom/htmlimageelement.rs | 12 +- src/components/script/dom/htmlinputelement.rs | 1 - src/components/script/dom/htmllabelelement.rs | 1 - .../script/dom/htmllegendelement.rs | 1 - src/components/script/dom/htmllielement.rs | 1 - src/components/script/dom/htmllinkelement.rs | 1 - src/components/script/dom/htmlmediaelement.rs | 2 - src/components/script/dom/htmlmetaelement.rs | 1 - src/components/script/dom/htmlmodelement.rs | 1 - .../script/dom/htmlobjectelement.rs | 10 +- src/components/script/dom/htmlolistelement.rs | 1 - .../script/dom/htmloptgroupelement.rs | 1 - .../script/dom/htmloptionelement.rs | 1 - .../script/dom/htmloutputelement.rs | 1 - .../script/dom/htmlparagraphelement.rs | 1 - src/components/script/dom/htmlparamelement.rs | 1 - src/components/script/dom/htmlpreelement.rs | 1 - .../script/dom/htmlprogresselement.rs | 1 - src/components/script/dom/htmlquoteelement.rs | 1 - .../script/dom/htmlscriptelement.rs | 1 - .../script/dom/htmlselectelement.rs | 1 - src/components/script/dom/htmlserializer.rs | 50 +++---- .../script/dom/htmlsourceelement.rs | 1 - src/components/script/dom/htmlstyleelement.rs | 10 +- .../script/dom/htmltablecaptionelement.rs | 1 - .../script/dom/htmltablecellelement.rs | 2 - .../script/dom/htmltablecolelement.rs | 1 - src/components/script/dom/htmltableelement.rs | 1 - .../script/dom/htmltablerowelement.rs | 1 - .../script/dom/htmltablesectionelement.rs | 1 - .../script/dom/htmltextareaelement.rs | 1 - src/components/script/dom/htmltimeelement.rs | 1 - src/components/script/dom/htmltitleelement.rs | 1 - src/components/script/dom/htmltrackelement.rs | 1 - src/components/script/dom/htmlulistelement.rs | 1 - src/components/script/dom/htmlvideoelement.rs | 1 - src/components/script/dom/location.rs | 1 - src/components/script/dom/navigator.rs | 1 - src/components/script/dom/node.rs | 112 +++++++------- .../script/dom/processinginstruction.rs | 1 - src/components/script/dom/testbinding.rs | 6 +- src/components/script/dom/text.rs | 1 - src/components/script/dom/uievent.rs | 1 - src/components/script/dom/validitystate.rs | 1 - src/components/script/dom/virtualmethods.rs | 6 +- .../script/dom/webidls/TestBinding.webidl | 2 +- .../script/html/hubbub_html_parser.rs | 9 +- src/components/script/script_task.rs | 20 ++- 83 files changed, 316 insertions(+), 374 deletions(-) diff --git a/src/components/script/dom/bindings/codegen/Bindings.conf b/src/components/script/dom/bindings/codegen/Bindings.conf index f3723fb7c9b..c41856ccf86 100644 --- a/src/components/script/dom/bindings/codegen/Bindings.conf +++ b/src/components/script/dom/bindings/codegen/Bindings.conf @@ -58,9 +58,7 @@ DOMInterfaces = { # FIXME: This should be renamed: https://github.com/mozilla/servo/issues/1625 def addHTMLElement(element): - DOMInterfaces[element] = { - 'nativeType': 'JS<%s>' % element, - } + DOMInterfaces[element] = {} addHTMLElement('Comment') addHTMLElement('DocumentFragment') diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 8c9eb5d6f8b..55bfa9eac91 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -281,7 +281,6 @@ class CGMethodCall(CGThing): isDefinitelyObject=True), { "declName" : "arg%d" % distinguishingIndex, - "simpleDeclName" : "arg%d" % distinguishingIndex, "holderName" : ("arg%d" % distinguishingIndex) + "_holder", "val" : distinguishingArg }) @@ -395,6 +394,9 @@ def typeIsSequenceOrHasSequenceMember(type): type.flatMemberTypes) return False +def typeNeedsRooting(type, descriptorProvider): + return type.isGeckoInterface() and descriptorProvider.getDescriptor(type.name).needsRooting + def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, isDefinitelyObject=False, isMember=False, @@ -482,6 +484,8 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, if exceptionCode is None: exceptionCode = "return 0;" + needsRooting = typeNeedsRooting(type, descriptorProvider) + def handleOptional(template, declType, isOptional): if isOptional: template = "Some(%s)" % template @@ -490,7 +494,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, else: initialValue = None - return (template, declType, isOptional, initialValue) + return (template, declType, isOptional, initialValue, needsRooting) # Unfortunately, .capitalize() on a string will lowercase things inside the # string, which we do not want. @@ -751,7 +755,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, "} else {\n" " ${declName} = NULL;\n" "}" % haveCallable, - CGGeneric("JSObject*"), isOptional, None) + CGGeneric("JSObject*"), isOptional, None, needsRooting) if type.isAny(): assert not isEnforceRange and not isClamp @@ -795,7 +799,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, assert not isOptional # This one only happens for return values, and its easy: Just # ignore the jsval. - return ("", None, False, None) + return ("", None, False, None, False) if not type.isPrimitive(): raise TypeError("Need conversion for argument type '%s'" % str(type)) @@ -848,7 +852,7 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements, replace ${argc} and ${index}, where ${index} is the index of this argument (0-based) and ${argc} is the total number of arguments. """ - (templateBody, declType, dealWithOptional, initialValue) = templateTuple + (templateBody, declType, dealWithOptional, initialValue, needsRooting) = templateTuple if dealWithOptional and argcAndIndex is None: raise TypeError("Have to deal with optional things, but don't know how") @@ -895,9 +899,8 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements, # conversion. result.append(CGGeneric("")) - type = declType.define() if declType else None - if type and 'JS<' in type: - rootBody = "let ${simpleDeclName} = ${declName}.root();" + if needsRooting: + rootBody = "let ${declName} = ${declName}.root();" result.append(CGGeneric(string.Template(rootBody).substitute(replacements))) result.append(CGGeneric("")) @@ -942,7 +945,6 @@ class CGArgumentConverter(CGThing): } self.replacementVariables = { "declName" : "arg%d" % index, - "simpleDeclName" : "arg%d" % index, "holderName" : ("arg%d" % index) + "_holder" } self.replacementVariables["val"] = string.Template( @@ -1808,7 +1810,7 @@ def CreateBindingJSObject(descriptor, parent=None): if descriptor.proxy: assert not descriptor.createGlobal handler = """ - let js_info = aScope.get().page().js_info(); + let js_info = aScope.deref().page().js_info(); let handler = js_info.get_ref().dom_static.proxy_handlers.deref().get(&(PrototypeList::id::%s as uint)); """ % descriptor.name create += handler + """ let obj = NewProxyObject(aCx, *handler, @@ -2480,13 +2482,9 @@ class CGSpecializedMethod(CGAbstractExternMethod): def definition_body(self): name = self.method.identifier.name - nativeName = MakeNativeName(name) - extraPre = '' - argsPre = [] - return CGWrapper(CGMethodCall(argsPre, nativeName, self.method.isStatic(), + return CGWrapper(CGMethodCall([], MakeNativeName(name), self.method.isStatic(), self.descriptor, self.method), - pre=extraPre + - " let this = JS::from_raw(this);\n" + + pre=" let this = JS::from_raw(this);\n" + " let mut this = this.root();\n").define() class CGGenericGetter(CGAbstractBindingMethod): @@ -2530,17 +2528,14 @@ class CGSpecializedGetter(CGAbstractExternMethod): def definition_body(self): name = self.attr.identifier.name nativeName = MakeNativeName(name) - extraPre = '' - argsPre = [] infallible = ('infallible' in self.descriptor.getExtendedAttributes(self.attr, getter=True)) if self.attr.type.nullable() or not infallible: nativeName = "Get" + nativeName - return CGWrapper(CGIndenter(CGGetterCall(argsPre, self.attr.type, nativeName, + return CGWrapper(CGIndenter(CGGetterCall([], self.attr.type, nativeName, self.descriptor, self.attr)), - pre=extraPre + - " let this = JS::from_raw(this);\n" + + pre=" let this = JS::from_raw(this);\n" + " let mut this = this.root();\n").define() class CGGenericSetter(CGAbstractBindingMethod): @@ -2588,13 +2583,10 @@ class CGSpecializedSetter(CGAbstractExternMethod): def definition_body(self): name = self.attr.identifier.name - nativeName = "Set" + MakeNativeName(name) - argsPre = [] - extraPre = '' - return CGWrapper(CGIndenter(CGSetterCall(argsPre, self.attr.type, nativeName, + return CGWrapper(CGIndenter(CGSetterCall([], self.attr.type, + "Set" + MakeNativeName(name), self.descriptor, self.attr)), - pre=extraPre + - " let this = JS::from_raw(this);\n" + + pre=" let this = JS::from_raw(this);\n" + " let mut this = this.root();\n").define() @@ -2763,7 +2755,7 @@ def getUnionTypeTemplateVars(type, descriptorProvider): name = type.name typeName = "/*" + type.name + "*/" - (template, _, _, _) = getJSToNativeConversionTemplate( + (template, _, _, _, _) = getJSToNativeConversionTemplate( type, descriptorProvider, failureCode="return Ok(None);", exceptionCode='return Err(());', isDefinitelyObject=True, isOptional=False) @@ -3421,7 +3413,6 @@ class CGProxySpecialOperation(CGPerSignatureCall): treatNullAs=argument.treatNullAs) templateValues = { "declName": argument.identifier.name, - "simpleDeclName": argument.identifier.name, "holderName": argument.identifier.name + "_holder", "val": "(*desc).value", "valPtr": "&(*desc).value" @@ -3868,9 +3859,8 @@ class CGClassConstructHook(CGAbstractExternMethod): def generate_code(self): preamble = """ - let global = global_object_for_js_object(JS_CALLEE(cx, &*vp).to_object()); - let global = global.root(); - let obj = global.reflector().get_jsobject(); + let global = global_object_for_js_object(JS_CALLEE(cx, &*vp).to_object()).root(); + let obj = global.deref().reflector().get_jsobject(); """ nativeName = MakeNativeName(self._ctor.identifier.name) callGenerator = CGMethodCall(["&global.root_ref()"], nativeName, True, @@ -4148,14 +4138,14 @@ class CGDictionary(CGThing): def getMemberType(self, memberInfo): (member, (templateBody, declType, - dealWithOptional, initialValue)) = memberInfo + dealWithOptional, initialValue, _)) = memberInfo if dealWithOptional: declType = CGWrapper(declType, pre="Optional< ", post=" >") return declType.define() def getMemberConversion(self, memberInfo): (member, (templateBody, declType, - dealWithOptional, initialValue)) = memberInfo + dealWithOptional, initialValue, _)) = memberInfo replacements = { "val": "value.unwrap()" } if member.defaultValue: replacements["haveValue"] = "value.is_some()" @@ -4310,7 +4300,9 @@ class CGBindingRoot(CGThing): 'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}', 'dom::types::*', 'dom::bindings', - 'dom::bindings::js::{JS, JSRef, Root, RootedReference, Temporary, OptionalRootable, OptionalRootedRootable, ResultRootable}', + 'dom::bindings::js::{JS, JSRef, Root, RootedReference, Temporary}', + 'dom::bindings::js::{OptionalRootable, OptionalRootedRootable, ResultRootable}', + 'dom::bindings::js::{OptionalRootedReference, OptionalOptionalRootedRootable}', 'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}', 'dom::bindings::utils::{ConstantSpec, cx_for_dom_object, Default}', 'dom::bindings::utils::{dom_object_slot, DOM_OBJECT_SLOT, DOMClass}', @@ -5311,7 +5303,7 @@ class GlobalGenRoots(): cast = [CGGeneric(string.Template('''pub trait ${castTraitName} { #[inline(always)] fn to_ref<'a, 'b, T: ${toBound}+Reflectable>(base: &'a JSRef<'b, T>) -> Option<&'a JSRef<'b, Self>> { - match base.get().${checkFn}() { + match base.deref().${checkFn}() { true => unsafe { Some(base.transmute()) }, false => None } @@ -5319,7 +5311,7 @@ class GlobalGenRoots(): #[inline(always)] fn to_mut_ref<'a, 'b, T: ${toBound}+Reflectable>(base: &'a mut JSRef<'b, T>) -> Option<&'a mut JSRef<'b, Self>> { - match base.get().${checkFn}() { + match base.deref().${checkFn}() { true => unsafe { Some(base.transmute_mut()) }, false => None } diff --git a/src/components/script/dom/bindings/codegen/Configuration.py b/src/components/script/dom/bindings/codegen/Configuration.py index dc4daa18b26..1272867f542 100644 --- a/src/components/script/dom/bindings/codegen/Configuration.py +++ b/src/components/script/dom/bindings/codegen/Configuration.py @@ -128,15 +128,18 @@ class Descriptor(DescriptorProvider): # Read the desc, and fill in the relevant defaults. ifaceName = self.interface.identifier.name + + # Callback types do not use JS smart pointers, so we should not use the + # built-in rooting mechanisms for them. if self.interface.isCallback(): - nativeTypeDefault = "nsIDOM" + ifaceName + self.needsRooting = False else: - nativeTypeDefault = 'JS<%s>' % ifaceName + self.needsRooting = True self.returnType = "Temporary<%s>" % ifaceName self.argumentType = "JSRef<%s>" % ifaceName self.memberType = "Root<'a, 'b, %s>" % ifaceName - self.nativeType = desc.get('nativeType', nativeTypeDefault) + self.nativeType = desc.get('nativeType', 'JS<%s>' % ifaceName) self.concreteType = desc.get('concreteType', ifaceName) self.createGlobal = desc.get('createGlobal', False) self.register = desc.get('register', True) diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs index eee20a17e83..da84c85eeb7 100644 --- a/src/components/script/dom/bindings/js.rs +++ b/src/components/script/dom/bindings/js.rs @@ -40,8 +40,8 @@ /// - RootedReference: makes obtaining an Option> from an Option> easy use dom::bindings::utils::{Reflector, Reflectable, cx_for_dom_object}; -use dom::window::Window; -use js::jsapi::{JSObject, JSContext, JS_AddObjectRoot, JS_RemoveObjectRoot}; +use dom::node::Node; +use js::jsapi::{JSObject, JS_AddObjectRoot, JS_RemoveObjectRoot}; use layout_interface::TrustedNodeAddress; use script_task::StackRoots; @@ -90,7 +90,7 @@ impl Temporary { Temporary::new(root.unrooted()) } - /// Root this unrooted value. + /// Create a stack-bounded root for this value. pub fn root<'a, 'b>(self) -> Root<'a, 'b, T> { local_data::get(StackRoots, |opt| { let collection = opt.unwrap(); @@ -130,15 +130,17 @@ impl Clone for JS { } } -impl JS { - /// Create a new JS-reflected DOM object; returns an Temporary type because the new value - /// is not safe to use until it is rooted. - pub fn new(obj: ~T, - window: &JSRef, - wrap_fn: extern "Rust" fn(*JSContext, &JSRef, ~T) -> JS) -> Temporary { - Temporary::new(wrap_fn(window.get().get_cx(), window, obj)) +impl JS { + /// 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 { + let TrustedNodeAddress(addr) = inner; + JS { + ptr: RefCell::new(addr as *mut Node) + } } +} +impl JS { /// Create a new JS-owned value wrapped from a raw Rust pointer. pub unsafe fn from_raw(raw: *mut T) -> JS { JS { @@ -147,14 +149,6 @@ impl JS { } - /// 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 { - let TrustedNodeAddress(addr) = inner; - JS { - ptr: RefCell::new(addr as *mut T) - } - } - /// Root this JS-owned value to prevent its collection as garbage. pub fn root<'a, 'b>(&self) -> Root<'a, 'b, T> { local_data::get(StackRoots, |opt| { @@ -209,6 +203,8 @@ impl JS { } } + +/// Get an Option> out of an Option> pub trait RootedReference { fn root_ref<'a>(&'a self) -> Option>; } @@ -219,6 +215,17 @@ impl<'a, 'b, T: Reflectable> RootedReference for Option> { } } +/// Get an Option>> out of an Option>> +pub trait OptionalRootedReference { + fn root_ref<'a>(&'a self) -> Option>>; +} + +impl<'a, 'b, T: Reflectable> OptionalRootedReference for Option>> { + fn root_ref<'a>(&'a self) -> Option>> { + self.as_ref().map(|inner| inner.root_ref()) + } +} + /// Trait that allows extracting a JS value from a variety of rooting-related containers, /// which in general is an unsafe operation since they can outlive the rooted lifetime of the /// original value. @@ -244,6 +251,8 @@ impl Assignable for Temporary { } } +/// Assign an optional rootable value (either of JS or Temporary) to an optional +/// field of a DOM type (ie. Option>) pub trait OptionalSettable { fn assign(&mut self, val: Option); } @@ -254,6 +263,7 @@ impl, U: Reflectable> OptionalSettable for Option> { } } +/// Root a rootable Option type (used for Option>) pub trait OptionalRootable { fn root<'a, 'b>(self) -> Option>; } @@ -264,6 +274,18 @@ impl OptionalRootable for Option> { } } +/// Return an unrooted type for storing in optional DOM fields +pub trait OptionalUnrootable { + fn unrooted(&self) -> Option>; +} + +impl<'a, T: Reflectable> OptionalUnrootable for Option> { + fn unrooted(&self) -> Option> { + self.as_ref().map(|inner| inner.unrooted()) + } +} + +/// Root a rootable Option type (used for Option>) pub trait OptionalRootedRootable { fn root<'a, 'b>(&self) -> Option>; } @@ -274,6 +296,19 @@ impl OptionalRootedRootable for Option> { } } +/// Root a rootable Option