mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Address review comments.
This commit is contained in:
parent
46a33b4b38
commit
91278da9dd
83 changed files with 316 additions and 374 deletions
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -40,8 +40,8 @@
|
|||
/// - RootedReference: makes obtaining an Option<JSRef<T>> from an Option<Root<T>> 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<T: Reflectable> Temporary<T> {
|
|||
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 <T> Clone for JS<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Reflectable> JS<T> {
|
||||
/// 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<Window>,
|
||||
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<Window>, ~T) -> JS<T>) -> Temporary<T> {
|
||||
Temporary::new(wrap_fn(window.get().get_cx(), window, obj))
|
||||
impl JS<Node> {
|
||||
/// Create a new JS-owned value wrapped from an address known to be a Node pointer.
|
||||
pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> JS<Node> {
|
||||
let TrustedNodeAddress(addr) = inner;
|
||||
JS {
|
||||
ptr: RefCell::new(addr as *mut Node)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Reflectable> JS<T> {
|
||||
/// Create a new JS-owned value wrapped from a raw Rust pointer.
|
||||
pub unsafe fn from_raw(raw: *mut T) -> JS<T> {
|
||||
JS {
|
||||
|
@ -147,14 +149,6 @@ impl<T: Reflectable> JS<T> {
|
|||
}
|
||||
|
||||
|
||||
/// 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<T> {
|
||||
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<From, To> JS<From> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Get an Option<JSRef<T>> out of an Option<Root<T>>
|
||||
pub trait RootedReference<T> {
|
||||
fn root_ref<'a>(&'a self) -> Option<JSRef<'a, T>>;
|
||||
}
|
||||
|
@ -219,6 +215,17 @@ impl<'a, 'b, T: Reflectable> RootedReference<T> for Option<Root<'a, 'b, T>> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get an Option<Option<JSRef<T>>> out of an Option<Option<Root<T>>>
|
||||
pub trait OptionalRootedReference<T> {
|
||||
fn root_ref<'a>(&'a self) -> Option<Option<JSRef<'a, T>>>;
|
||||
}
|
||||
|
||||
impl<'a, 'b, T: Reflectable> OptionalRootedReference<T> for Option<Option<Root<'a, 'b, T>>> {
|
||||
fn root_ref<'a>(&'a self) -> Option<Option<JSRef<'a, T>>> {
|
||||
self.as_ref().map(|inner| inner.root_ref())
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait that allows extracting a JS<T> 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<T: Reflectable> Assignable<T> for Temporary<T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Assign an optional rootable value (either of JS<T> or Temporary<T>) to an optional
|
||||
/// field of a DOM type (ie. Option<JS<T>>)
|
||||
pub trait OptionalSettable<T> {
|
||||
fn assign(&mut self, val: Option<T>);
|
||||
}
|
||||
|
@ -254,6 +263,7 @@ impl<T: Assignable<U>, U: Reflectable> OptionalSettable<T> for Option<JS<U>> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Root a rootable Option type (used for Option<Temporary<T>>)
|
||||
pub trait OptionalRootable<T> {
|
||||
fn root<'a, 'b>(self) -> Option<Root<'a, 'b, T>>;
|
||||
}
|
||||
|
@ -264,6 +274,18 @@ impl<T: Reflectable> OptionalRootable<T> for Option<Temporary<T>> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Return an unrooted type for storing in optional DOM fields
|
||||
pub trait OptionalUnrootable<T> {
|
||||
fn unrooted(&self) -> Option<JS<T>>;
|
||||
}
|
||||
|
||||
impl<'a, T: Reflectable> OptionalUnrootable<T> for Option<JSRef<'a, T>> {
|
||||
fn unrooted(&self) -> Option<JS<T>> {
|
||||
self.as_ref().map(|inner| inner.unrooted())
|
||||
}
|
||||
}
|
||||
|
||||
/// Root a rootable Option type (used for Option<JS<T>>)
|
||||
pub trait OptionalRootedRootable<T> {
|
||||
fn root<'a, 'b>(&self) -> Option<Root<'a, 'b, T>>;
|
||||
}
|
||||
|
@ -274,6 +296,19 @@ impl<T: Reflectable> OptionalRootedRootable<T> for Option<JS<T>> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Root a rootable Option<Option> type (used for Option<Option<JS<T>>>)
|
||||
pub trait OptionalOptionalRootedRootable<T> {
|
||||
fn root<'a, 'b>(&self) -> Option<Option<Root<'a, 'b, T>>>;
|
||||
}
|
||||
|
||||
impl<T: Reflectable> OptionalOptionalRootedRootable<T> for Option<Option<JS<T>>> {
|
||||
fn root<'a, 'b>(&self) -> Option<Option<Root<'a, 'b, T>>> {
|
||||
self.as_ref().map(|inner| inner.root())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Root a rootable Result type (any of Temporary<T> or JS<T>)
|
||||
pub trait ResultRootable<T,U> {
|
||||
fn root<'a, 'b>(self) -> Result<Root<'a, 'b, T>, U>;
|
||||
}
|
||||
|
@ -310,26 +345,30 @@ impl<T: Assignable<U>, U: Reflectable> TemporaryPushable<T> for Vec<JS<U>> {
|
|||
|
||||
/// An opaque, LIFO rooting mechanism.
|
||||
pub struct RootCollection {
|
||||
roots: RefCell<~[*JSObject]>,
|
||||
roots: RefCell<Vec<*JSObject>>,
|
||||
}
|
||||
|
||||
impl RootCollection {
|
||||
/// Create an empty collection of roots
|
||||
pub fn new() -> RootCollection {
|
||||
RootCollection {
|
||||
roots: RefCell::new(~[]),
|
||||
roots: RefCell::new(vec!()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new stack-bounded root that will not outlive this collection
|
||||
fn new_root<'a, 'b, T: Reflectable>(&'a self, unrooted: &JS<T>) -> Root<'a, 'b, T> {
|
||||
Root::new(self, unrooted)
|
||||
}
|
||||
|
||||
/// Track a stack-based root to ensure LIFO root ordering
|
||||
fn root<'a, 'b, T: Reflectable>(&self, untracked: &Root<'a, 'b, T>) {
|
||||
let mut roots = self.roots.borrow_mut();
|
||||
roots.push(untracked.js_ptr);
|
||||
debug!(" rooting {:?}", untracked.js_ptr);
|
||||
}
|
||||
|
||||
/// Stop tracking a stack-based root, asserting if LIFO root ordering has been violated
|
||||
fn unroot<'a, 'b, T: Reflectable>(&self, rooted: &Root<'a, 'b, T>) {
|
||||
let mut roots = self.roots.borrow_mut();
|
||||
debug!("unrooting {:?} (expecting {:?}", roots.last().unwrap(), rooted.js_ptr);
|
||||
|
@ -355,6 +394,9 @@ pub struct Root<'a, 'b, T> {
|
|||
}
|
||||
|
||||
impl<'a, 'b, T: Reflectable> Root<'a, 'b, T> {
|
||||
/// Create a new stack-bounded root for the provided JS-owned value.
|
||||
/// It cannot not outlive its associated RootCollection, and it contains a JSRef
|
||||
/// which cannot outlive this new Root.
|
||||
fn new(roots: &'a RootCollection, unrooted: &JS<T>) -> Root<'a, 'b, T> {
|
||||
let root = Root {
|
||||
root_list: roots,
|
||||
|
@ -369,20 +411,8 @@ impl<'a, 'b, T: Reflectable> Root<'a, 'b, T> {
|
|||
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
|
||||
}
|
||||
}
|
||||
|
||||
/// Obtain a safe reference to the wrapped JS owned-value that cannot outlive
|
||||
/// the lifetime of this root.
|
||||
pub fn root_ref<'b>(&'b self) -> JSRef<'b,T> {
|
||||
self.jsref.clone()
|
||||
}
|
||||
|
@ -395,37 +425,33 @@ impl<'a, 'b, T: Reflectable> Drop for Root<'a, 'b, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, T: Reflectable> Reflectable for Root<'a, 'b, 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, 'b, T: Reflectable> Deref<JSRef<'b, T>> for Root<'a, 'b, T> {
|
||||
fn deref<'c>(&'c self) -> &'c JSRef<'b, T> {
|
||||
&'a self.jsref
|
||||
&self.jsref
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, T: Reflectable> DerefMut<JSRef<'b, T>> for Root<'a, 'b, T> {
|
||||
fn deref_mut<'c>(&'c mut self) -> &'c mut JSRef<'b, T> {
|
||||
&'a mut self.jsref
|
||||
&mut self.jsref
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Reflectable> Deref<T> for JSRef<'a, T> {
|
||||
fn deref<'b>(&'b self) -> &'b T {
|
||||
self.get()
|
||||
let borrow = self.ptr.borrow();
|
||||
unsafe {
|
||||
&**borrow
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Reflectable> DerefMut<T> for JSRef<'a, T> {
|
||||
fn deref_mut<'b>(&'b mut self) -> &'b mut T {
|
||||
self.get_mut()
|
||||
let mut borrowed = self.ptr.borrow_mut();
|
||||
unsafe {
|
||||
&mut **borrowed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -451,20 +477,6 @@ impl<'a, T> Eq for JSRef<'a, T> {
|
|||
}
|
||||
|
||||
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)
|
||||
|
@ -484,10 +496,10 @@ impl<'a,T> JSRef<'a,T> {
|
|||
|
||||
impl<'a, T: Reflectable> Reflectable for JSRef<'a, T> {
|
||||
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||
self.get().reflector()
|
||||
self.deref().reflector()
|
||||
}
|
||||
|
||||
fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector {
|
||||
self.get_mut().mut_reflector()
|
||||
self.deref_mut().mut_reflector()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -392,7 +392,7 @@ pub fn reflect_dom_object<T: Reflectable>
|
|||
window: &JSRef<window::Window>,
|
||||
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<window::Window>, ~T) -> JS<T>)
|
||||
-> Temporary<T> {
|
||||
JS::new(obj, window, wrap_fn)
|
||||
Temporary::new(wrap_fn(window.deref().get_cx(), window, obj))
|
||||
}
|
||||
|
||||
#[deriving(Eq)]
|
||||
|
@ -415,8 +415,8 @@ impl Reflector {
|
|||
/// 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
|
||||
pub fn rootable<'a>(&'a self) -> &'a *JSObject {
|
||||
&self.object
|
||||
}
|
||||
|
||||
pub fn new() -> Reflector {
|
||||
|
@ -634,7 +634,7 @@ pub fn global_object_for_js_object(obj: *JSObject) -> JS<window::Window> {
|
|||
|
||||
fn cx_for_dom_reflector(obj: *JSObject) -> *JSContext {
|
||||
let win = global_object_for_js_object(obj).root();
|
||||
let js_info = win.get().page().js_info();
|
||||
let js_info = win.deref().page().js_info();
|
||||
match *js_info {
|
||||
Some(ref info) => info.js_context.deref().deref().ptr,
|
||||
None => fail!("no JS context for DOM global")
|
||||
|
|
|
@ -48,13 +48,13 @@ impl BrowserContext {
|
|||
|
||||
pub fn create_window_proxy(&self) -> *JSObject {
|
||||
let win = self.active_window().root();
|
||||
let page = win.get().page();
|
||||
let page = win.deref().page();
|
||||
let js_info = page.js_info();
|
||||
|
||||
let handler = js_info.get_ref().dom_static.windowproxy_handler;
|
||||
assert!(handler.deref().is_not_null());
|
||||
|
||||
let parent = win.get().reflector().get_jsobject();
|
||||
let parent = win.deref().reflector().get_jsobject();
|
||||
let cx = js_info.get_ref().js_context.deref().deref().ptr;
|
||||
let wrapper = unsafe {
|
||||
WrapperNew(cx, parent, *handler.deref())
|
||||
|
|
|
@ -182,7 +182,7 @@ impl<'a> DocumentHelpers for JSRef<'a, Document> {
|
|||
}
|
||||
|
||||
impl Document {
|
||||
pub fn reflect_document(document: ~Document,
|
||||
pub fn reflect_document(document: ~Document,
|
||||
window: &JSRef<Window>,
|
||||
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<Window>, ~Document) -> JS<Document>)
|
||||
-> Temporary<Document> {
|
||||
|
@ -256,20 +256,22 @@ impl<'a> PrivateDocumentHelpers for JSRef<'a, Document> {
|
|||
fn createNodeList(&self, callback: |node: &JSRef<Node>| -> bool) -> Temporary<NodeList> {
|
||||
let window = self.window.root();
|
||||
|
||||
let mut nodes = vec!();
|
||||
match self.GetDocumentElement().root() {
|
||||
None => {},
|
||||
None => {
|
||||
NodeList::new_simple_list(&*window, vec!())
|
||||
},
|
||||
Some(root) => {
|
||||
let mut nodes = vec!();
|
||||
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
||||
for child in root.traverse_preorder() {
|
||||
if callback(&child) {
|
||||
nodes.push(child);
|
||||
}
|
||||
}
|
||||
NodeList::new_simple_list(&*window, nodes)
|
||||
}
|
||||
}
|
||||
|
||||
NodeList::new_simple_list(&*window, nodes)
|
||||
}
|
||||
|
||||
fn get_html_element(&self) -> Option<Temporary<HTMLHtmlElement>> {
|
||||
|
@ -551,7 +553,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
for child in title_elem.children() {
|
||||
if child.is_text() {
|
||||
let text: &JSRef<Text> = TextCast::to_ref(&child).unwrap();
|
||||
title.push_str(text.get().characterdata.data.as_slice());
|
||||
title.push_str(text.deref().characterdata.data.as_slice());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -563,15 +565,14 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
|
||||
// http://www.whatwg.org/specs/web-apps/current-work/#document.title
|
||||
fn SetTitle(&self, title: DOMString) -> ErrorResult {
|
||||
|
||||
self.GetDocumentElement().root().map(|root| {
|
||||
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
||||
let mut head_node = root.traverse_preorder().find(|child| {
|
||||
child.get().type_id == ElementNodeTypeId(HTMLHeadElementTypeId)
|
||||
child.type_id() == ElementNodeTypeId(HTMLHeadElementTypeId)
|
||||
});
|
||||
head_node.as_mut().map(|head| {
|
||||
let mut title_node = head.children().find(|child| {
|
||||
child.get().type_id == ElementNodeTypeId(HTMLTitleElementTypeId)
|
||||
child.type_id() == ElementNodeTypeId(HTMLTitleElementTypeId)
|
||||
});
|
||||
|
||||
match title_node {
|
||||
|
@ -630,7 +631,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<JSRef<HTMLElement>>) -> ErrorResult {
|
||||
|
||||
// Step 1.
|
||||
match new_body {
|
||||
Some(ref htmlelem) => {
|
||||
|
@ -674,7 +674,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<NodeList> {
|
||||
|
||||
self.createNodeList(|node| {
|
||||
if !node.is_element() {
|
||||
return false;
|
||||
|
@ -694,7 +693,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
struct ImagesFilter;
|
||||
impl CollectionFilter for ImagesFilter {
|
||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||
elem.get().local_name == ~"img"
|
||||
elem.deref().local_name == ~"img"
|
||||
}
|
||||
}
|
||||
let filter = ~ImagesFilter;
|
||||
|
@ -708,7 +707,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
struct EmbedsFilter;
|
||||
impl CollectionFilter for EmbedsFilter {
|
||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||
elem.get().local_name == ~"embed"
|
||||
elem.deref().local_name == ~"embed"
|
||||
}
|
||||
}
|
||||
let filter = ~EmbedsFilter;
|
||||
|
@ -727,7 +726,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
struct LinksFilter;
|
||||
impl CollectionFilter for LinksFilter {
|
||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||
(elem.get().local_name == ~"a" || elem.get().local_name == ~"area") &&
|
||||
(elem.deref().local_name == ~"a" || elem.deref().local_name == ~"area") &&
|
||||
elem.get_attribute(Null, "href").is_some()
|
||||
}
|
||||
}
|
||||
|
@ -742,7 +741,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
struct FormsFilter;
|
||||
impl CollectionFilter for FormsFilter {
|
||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||
elem.get().local_name == ~"form"
|
||||
elem.deref().local_name == ~"form"
|
||||
}
|
||||
}
|
||||
let filter = ~FormsFilter;
|
||||
|
@ -756,7 +755,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
struct ScriptsFilter;
|
||||
impl CollectionFilter for ScriptsFilter {
|
||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||
elem.get().local_name == ~"script"
|
||||
elem.deref().local_name == ~"script"
|
||||
}
|
||||
}
|
||||
let filter = ~ScriptsFilter;
|
||||
|
@ -770,7 +769,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
struct AnchorsFilter;
|
||||
impl CollectionFilter for AnchorsFilter {
|
||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||
elem.get().local_name == ~"a" && elem.get_attribute(Null, "name").is_some()
|
||||
elem.deref().local_name == ~"a" && elem.get_attribute(Null, "name").is_some()
|
||||
}
|
||||
}
|
||||
let filter = ~AnchorsFilter;
|
||||
|
@ -784,7 +783,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
struct AppletsFilter;
|
||||
impl CollectionFilter for AppletsFilter {
|
||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||
elem.get().local_name == ~"applet"
|
||||
elem.deref().local_name == ~"applet"
|
||||
}
|
||||
}
|
||||
let filter = ~AppletsFilter;
|
||||
|
|
|
@ -74,4 +74,3 @@ impl<'a> DocumentTypeMethods for JSRef<'a, DocumentType> {
|
|||
self.system_id.clone()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,8 @@ impl DOMParser {
|
|||
}
|
||||
|
||||
pub trait DOMParserMethods {
|
||||
fn ParseFromString(&self, _s: DOMString, ty: DOMParserBinding::SupportedType) -> Fallible<Temporary<Document>>;
|
||||
fn ParseFromString(&self, _s: DOMString, ty: DOMParserBinding::SupportedType)
|
||||
-> Fallible<Temporary<Document>>;
|
||||
}
|
||||
|
||||
impl<'a> DOMParserMethods for JSRef<'a, DOMParser> {
|
||||
|
|
|
@ -228,11 +228,11 @@ pub trait AttributeHandlers {
|
|||
impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||
fn get_attribute(&self, namespace: Namespace, name: &str) -> Option<Temporary<Attr>> {
|
||||
if self.html_element_in_html_document() {
|
||||
self.get().attrs.iter().map(|attr| attr.root()).find(|attr| {
|
||||
self.deref().attrs.iter().map(|attr| attr.root()).find(|attr| {
|
||||
name.to_ascii_lower() == attr.local_name && attr.namespace == namespace
|
||||
}).map(|x| Temporary::from_rooted(&*x))
|
||||
} else {
|
||||
self.get().attrs.iter().map(|attr| attr.root()).find(|attr| {
|
||||
self.deref().attrs.iter().map(|attr| attr.root()).find(|attr| {
|
||||
name == attr.local_name && attr.namespace == namespace
|
||||
}).map(|x| Temporary::from_rooted(&*x))
|
||||
}
|
||||
|
@ -262,9 +262,9 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
|
||||
let position: |&JSRef<Attr>| -> bool =
|
||||
if self.html_element_in_html_document() {
|
||||
|attr| attr.get().local_name.eq_ignore_ascii_case(local_name)
|
||||
|attr| attr.deref().local_name.eq_ignore_ascii_case(local_name)
|
||||
} else {
|
||||
|attr| attr.get().local_name == local_name
|
||||
|attr| attr.deref().local_name == local_name
|
||||
};
|
||||
self.do_set_attribute(name.clone(), value, name.clone(), namespace::Null, None, position);
|
||||
Ok(())
|
||||
|
@ -273,27 +273,27 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString,
|
||||
name: DOMString, namespace: Namespace,
|
||||
prefix: Option<DOMString>, cb: |&JSRef<Attr>| -> bool) {
|
||||
let idx = self.get().attrs.iter()
|
||||
.map(|attr| attr.root())
|
||||
.position(|attr| cb(&*attr));
|
||||
let idx = self.deref().attrs.iter()
|
||||
.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();
|
||||
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)
|
||||
self.deref_mut().attrs.push_unrooted(&attr);
|
||||
(self.deref().attrs.len() - 1, FirstSetAttr)
|
||||
}
|
||||
};
|
||||
|
||||
self.get_mut().attrs.get(idx).root().set_value(set_type, value);
|
||||
self.deref_mut().attrs.get(idx).root().set_value(set_type, value);
|
||||
}
|
||||
|
||||
fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult {
|
||||
let (_, local_name) = get_attribute_parts(name.clone());
|
||||
|
||||
let idx = self.get().attrs.iter().map(|attr| attr.root()).position(|attr| {
|
||||
let idx = self.deref().attrs.iter().map(|attr| attr.root()).position(|attr| {
|
||||
attr.local_name == local_name
|
||||
});
|
||||
|
||||
|
@ -306,12 +306,12 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
}
|
||||
|
||||
if namespace == namespace::Null {
|
||||
let removed_raw_value = self.get().attrs.get(idx).root().Value();
|
||||
let removed_raw_value = self.deref().attrs.get(idx).root().Value();
|
||||
vtable_for(NodeCast::from_mut_ref(self))
|
||||
.before_remove_attr(local_name.clone(), removed_raw_value);
|
||||
}
|
||||
|
||||
self.get_mut().attrs.remove(idx);
|
||||
self.deref_mut().attrs.remove(idx);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -516,7 +516,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
|
||||
// Step 3-5.
|
||||
self.do_set_attribute(name.clone(), value, name.clone(), namespace::Null, None, |attr| {
|
||||
attr.get().name == name
|
||||
attr.deref().name == name
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
@ -577,8 +577,8 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
|
||||
// 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
|
||||
attr.deref().local_name == local_name &&
|
||||
attr.deref().namespace == namespace
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
@ -694,9 +694,9 @@ pub fn get_attribute_parts(name: DOMString) -> (Option<~str>, ~str) {
|
|||
}
|
||||
|
||||
impl<'a> VirtualMethods for JSRef<'a, Element> {
|
||||
fn super_type(&self) -> Option<~VirtualMethods:> {
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
Some(~node.clone() as ~VirtualMethods:)
|
||||
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:> {
|
||||
let node: &mut JSRef<Node> = NodeCast::from_mut_ref(self);
|
||||
Some(node as &mut VirtualMethods:)
|
||||
}
|
||||
|
||||
fn after_set_attr(&mut self, name: DOMString, value: DOMString) {
|
||||
|
@ -709,7 +709,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
|||
"style" => {
|
||||
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))
|
||||
self.deref_mut().style_attribute = Some(style::parse_style_attribute(value, &base_url))
|
||||
}
|
||||
"id" => {
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
|
@ -732,7 +732,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
|||
|
||||
match name.as_slice() {
|
||||
"style" => {
|
||||
self.get_mut().style_attribute = None
|
||||
self.deref_mut().style_attribute = None
|
||||
}
|
||||
"id" => {
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
|
|
|
@ -160,9 +160,9 @@ impl<'a> EventMethods for JSRef<'a, Event> {
|
|||
}
|
||||
|
||||
fn InitEvent(&mut self,
|
||||
type_: DOMString,
|
||||
bubbles: bool,
|
||||
cancelable: bool) {
|
||||
type_: DOMString,
|
||||
bubbles: bool,
|
||||
cancelable: bool) {
|
||||
self.initialized = true;
|
||||
if self.dispatching {
|
||||
return;
|
||||
|
|
|
@ -13,21 +13,21 @@ use dom::node::{Node, NodeHelpers};
|
|||
pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>,
|
||||
pseudo_target: Option<JSRef<'b, EventTarget>>,
|
||||
event: &mut JSRef<Event>) -> bool {
|
||||
assert!(!event.get().dispatching);
|
||||
assert!(!event.deref().dispatching);
|
||||
|
||||
{
|
||||
let event = event.get_mut();
|
||||
match pseudo_target {
|
||||
Some(pseudo_target) => event.target.assign(Some(pseudo_target)),
|
||||
None => event.target.assign(Some(target.clone())),
|
||||
}
|
||||
let event = event.deref_mut();
|
||||
event.target.assign(Some(match pseudo_target {
|
||||
Some(pseudo_target) => pseudo_target,
|
||||
None => target.clone(),
|
||||
}));
|
||||
event.dispatching = true;
|
||||
}
|
||||
|
||||
let type_ = event.get().type_.clone();
|
||||
let type_ = event.deref().type_.clone();
|
||||
|
||||
//TODO: no chain if not participating in a tree
|
||||
let mut chain: Vec<Root<EventTarget>> = if target.get().is_node() {
|
||||
let mut chain: Vec<Root<EventTarget>> = if target.deref().is_node() {
|
||||
let target_node: &JSRef<Node> = NodeCast::to_ref(target).unwrap();
|
||||
target_node.ancestors().map(|ancestor| {
|
||||
let ancestor_target: &JSRef<EventTarget> = EventTargetCast::from_ref(&ancestor);
|
||||
|
@ -37,7 +37,7 @@ pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>,
|
|||
vec!()
|
||||
};
|
||||
|
||||
event.get_mut().phase = PhaseCapturing;
|
||||
event.deref_mut().phase = PhaseCapturing;
|
||||
|
||||
//FIXME: The "callback this value" should be currentTarget
|
||||
|
||||
|
@ -51,12 +51,12 @@ pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>,
|
|||
// drop the exception on the floor
|
||||
assert!(listener.HandleEvent__(event, ReportExceptions).is_ok());
|
||||
|
||||
if event.get().stop_immediate {
|
||||
if event.deref().stop_immediate {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
event.get().stop_propagation
|
||||
event.deref().stop_propagation
|
||||
}
|
||||
None => false
|
||||
};
|
||||
|
@ -67,20 +67,20 @@ pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>,
|
|||
}
|
||||
|
||||
/* at target */
|
||||
if !event.get().stop_propagation {
|
||||
if !event.deref().stop_propagation {
|
||||
{
|
||||
let event = event.get_mut();
|
||||
let event = event.deref_mut();
|
||||
event.phase = PhaseAtTarget;
|
||||
event.current_target.assign(Some(target.clone()));
|
||||
}
|
||||
|
||||
let opt_listeners = target.get().get_listeners(type_);
|
||||
let opt_listeners = target.deref().get_listeners(type_);
|
||||
for listeners in opt_listeners.iter() {
|
||||
for listener in listeners.iter() {
|
||||
//FIXME: this should have proper error handling, or explicitly drop the
|
||||
// exception on the floor.
|
||||
assert!(listener.HandleEvent__(event, ReportExceptions).is_ok());
|
||||
if event.get().stop_immediate {
|
||||
if event.deref().stop_immediate {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -88,24 +88,24 @@ pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>,
|
|||
}
|
||||
|
||||
/* bubbling */
|
||||
if event.get().bubbles && !event.get().stop_propagation {
|
||||
event.get_mut().phase = PhaseBubbling;
|
||||
if event.deref().bubbles && !event.deref().stop_propagation {
|
||||
event.deref_mut().phase = PhaseBubbling;
|
||||
|
||||
for cur_target in chain.iter() {
|
||||
let stopped = match cur_target.get().get_listeners_for(type_, Bubbling) {
|
||||
let stopped = match cur_target.deref().get_listeners_for(type_, Bubbling) {
|
||||
Some(listeners) => {
|
||||
event.get_mut().current_target.assign(Some(cur_target.deref().clone()));
|
||||
event.deref_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.
|
||||
assert!(listener.HandleEvent__(event, ReportExceptions).is_ok());
|
||||
|
||||
if event.get().stop_immediate {
|
||||
if event.deref().stop_immediate {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
event.get().stop_propagation
|
||||
event.deref().stop_propagation
|
||||
}
|
||||
None => false
|
||||
};
|
||||
|
|
|
@ -76,7 +76,7 @@ impl<'a> EventTargetHelpers for JSRef<'a, EventTarget> {
|
|||
fn dispatch_event_with_target<'b>(&self,
|
||||
target: Option<JSRef<'b, EventTarget>>,
|
||||
event: &mut JSRef<Event>) -> Fallible<bool> {
|
||||
if event.get().dispatching || !event.get().initialized {
|
||||
if event.deref().dispatching || !event.deref().initialized {
|
||||
return Err(InvalidState);
|
||||
}
|
||||
Ok(dispatch_event(self, target, event))
|
||||
|
@ -149,7 +149,7 @@ impl Reflectable for EventTarget {
|
|||
}
|
||||
|
||||
impl<'a> VirtualMethods for JSRef<'a, EventTarget> {
|
||||
fn super_type(&self) -> Option<~VirtualMethods:> {
|
||||
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary, OptionalUnrootable};
|
||||
use dom::blob::Blob;
|
||||
use dom::htmlformelement::HTMLFormElement;
|
||||
use dom::window::Window;
|
||||
|
@ -33,7 +33,7 @@ impl FormData {
|
|||
data: HashMap::new(),
|
||||
reflector_: Reflector::new(),
|
||||
window: window.unrooted(),
|
||||
form: form.map(|form| form.unrooted())
|
||||
form: form.unrooted(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,4 +64,3 @@ impl<'a> HTMLBaseElementMethods for JSRef<'a, HTMLBaseElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -104,4 +104,3 @@ impl<'a> HTMLBodyElementMethods for JSRef<'a, HTMLBodyElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLBRElementMethods for JSRef<'a, HTMLBRElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -185,4 +185,3 @@ impl<'a> HTMLButtonElementMethods for JSRef<'a, HTMLButtonElement> {
|
|||
fn SetCustomValidity(&mut self, _error: DOMString) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,4 +64,3 @@ impl<'a> HTMLCanvasElementMethods for JSRef<'a, HTMLCanvasElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ impl HTMLCollection {
|
|||
}
|
||||
impl CollectionFilter for TagNameFilter {
|
||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||
elem.get().local_name == self.tag
|
||||
elem.deref().local_name == self.tag
|
||||
}
|
||||
}
|
||||
let filter = TagNameFilter {
|
||||
|
@ -81,7 +81,7 @@ impl HTMLCollection {
|
|||
}
|
||||
impl CollectionFilter for TagNameNSFilter {
|
||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||
elem.get().namespace == self.namespace && elem.get().local_name == self.tag
|
||||
elem.deref().namespace == self.namespace && elem.deref().local_name == self.tag
|
||||
}
|
||||
}
|
||||
let filter = TagNameNSFilter {
|
||||
|
@ -155,7 +155,7 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
|
|||
.filter_map(|node| {
|
||||
let elem: Option<&JSRef<Element>> = ElementCast::to_ref(&node);
|
||||
elem.filtered(|&elem| filter.filter(elem, &*root))
|
||||
.and_then(|elem| Some(elem.clone()))
|
||||
.map(|elem| elem.clone())
|
||||
})
|
||||
.nth(index as uint)
|
||||
.clone()
|
||||
|
@ -166,7 +166,6 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
|
|||
|
||||
// http://dom.spec.whatwg.org/#dom-htmlcollection-nameditem
|
||||
fn NamedItem(&self, key: DOMString) -> Option<Temporary<Element>> {
|
||||
|
||||
// Step 1.
|
||||
if key.is_empty() {
|
||||
return None;
|
||||
|
@ -186,7 +185,7 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
|
|||
.filter_map(|node| {
|
||||
let elem: Option<&JSRef<Element>> = ElementCast::to_ref(&node);
|
||||
elem.filtered(|&elem| filter.filter(elem, &*root))
|
||||
.and_then(|elem| Some(elem.clone()))
|
||||
.map(|elem| elem.clone())
|
||||
})
|
||||
.find(|elem| {
|
||||
elem.get_string_attribute("name") == key ||
|
||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLDataElementMethods for JSRef<'a, HTMLDataElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ impl<'a> HTMLDataListElementMethods for JSRef<'a, HTMLDataListElement> {
|
|||
struct HTMLDataListOptionsFilter;
|
||||
impl CollectionFilter for HTMLDataListOptionsFilter {
|
||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||
elem.get().local_name == ~"option"
|
||||
elem.deref().local_name == ~"option"
|
||||
}
|
||||
}
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
|
@ -58,4 +58,3 @@ impl<'a> HTMLDataListElementMethods for JSRef<'a, HTMLDataListElement> {
|
|||
HTMLCollection::create(&*window, node, filter)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLDirectoryElementMethods for JSRef<'a, HTMLDirectoryElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLDivElementMethods for JSRef<'a, HTMLDivElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -198,8 +198,8 @@ impl<'a> HTMLElementMethods for JSRef<'a, HTMLElement> {
|
|||
}
|
||||
|
||||
impl<'a> VirtualMethods for JSRef<'a, HTMLElement> {
|
||||
fn super_type(&self) -> Option<~VirtualMethods:> {
|
||||
let element: &JSRef<Element> = ElementCast::from_ref(self);
|
||||
Some(~element.clone() as ~VirtualMethods:)
|
||||
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:> {
|
||||
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(self);
|
||||
Some(element as &mut VirtualMethods:)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,4 +109,3 @@ impl<'a> HTMLEmbedElementMethods for JSRef<'a, HTMLEmbedElement> {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> {
|
|||
static tag_names: StaticStringVec = &["button", "fieldset", "input",
|
||||
"keygen", "object", "output", "select", "textarea"];
|
||||
let root: &JSRef<Element> = ElementCast::to_ref(root).unwrap();
|
||||
elem != root && tag_names.iter().any(|&tag_name| tag_name == elem.get().local_name)
|
||||
elem != root && tag_names.iter().any(|&tag_name| tag_name == elem.deref().local_name)
|
||||
}
|
||||
}
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
|
@ -120,4 +120,3 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> {
|
|||
fn SetCustomValidity(&mut self, _error: DOMString) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,4 +74,3 @@ impl<'a> HTMLFontElementMethods for JSRef<'a, HTMLFontElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -166,4 +166,3 @@ impl<'a> HTMLFormElementMethods for JSRef<'a, HTMLFormElement> {
|
|||
fail!("Not implemented.")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -135,4 +135,3 @@ impl<'a> HTMLFrameElementMethods for JSRef<'a, HTMLFrameElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,4 +64,3 @@ impl<'a> HTMLFrameSetElementMethods for JSRef<'a, HTMLFrameSetElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,4 +64,3 @@ impl<'a> HTMLHeadingElementMethods for JSRef<'a, HTMLHeadingElement> {
|
|||
fn SetAlign(&mut self, _align: DOMString) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -94,4 +94,3 @@ impl<'a> HTMLHRElementMethods for JSRef<'a, HTMLHRElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLHtmlElementMethods for JSRef<'a, HTMLHtmlElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -238,9 +238,9 @@ impl<'a> HTMLIFrameElementMethods for JSRef<'a, HTMLIFrameElement> {
|
|||
}
|
||||
|
||||
impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> {
|
||||
fn super_type(&self) -> Option<~VirtualMethods:> {
|
||||
let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self);
|
||||
Some(~htmlelement.clone() as ~VirtualMethods:)
|
||||
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:> {
|
||||
let htmlelement: &mut JSRef<HTMLElement> = HTMLElementCast::from_mut_ref(self);
|
||||
Some(htmlelement as &mut VirtualMethods:)
|
||||
}
|
||||
|
||||
fn after_set_attr(&mut self, name: DOMString, value: DOMString) {
|
||||
|
@ -264,7 +264,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> {
|
|||
_ => AllowNothing
|
||||
} as u8;
|
||||
}
|
||||
self.get_mut().sandbox = Some(modes);
|
||||
self.deref_mut().sandbox = Some(modes);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -275,7 +275,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> {
|
|||
}
|
||||
|
||||
if "sandbox" == name {
|
||||
self.get_mut().sandbox = None;
|
||||
self.deref_mut().sandbox = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -218,7 +218,7 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> {
|
|||
|
||||
fn Align(&self) -> DOMString {
|
||||
let element: &JSRef<Element> = ElementCast::from_ref(self);
|
||||
element.get_string_attribute("longdesc")
|
||||
element.get_string_attribute("align")
|
||||
}
|
||||
|
||||
fn SetAlign(&mut self, align: DOMString) {
|
||||
|
@ -268,9 +268,9 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> {
|
|||
}
|
||||
|
||||
impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> {
|
||||
fn super_type(&self) -> Option<~VirtualMethods:> {
|
||||
let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self);
|
||||
Some(~htmlelement.clone() as ~VirtualMethods:)
|
||||
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:> {
|
||||
let htmlelement: &mut JSRef<HTMLElement> = HTMLElementCast::from_mut_ref(self);
|
||||
Some(htmlelement as &mut VirtualMethods:)
|
||||
}
|
||||
|
||||
fn after_set_attr(&mut self, name: DOMString, value: DOMString) {
|
||||
|
@ -281,13 +281,13 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> {
|
|||
|
||||
if "src" == name {
|
||||
let window = window_from_node(self).root();
|
||||
let url = Some(window.get().get_url());
|
||||
let url = Some(window.deref().get_url());
|
||||
self.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()),
|
||||
_ => (),
|
||||
}
|
||||
|
|
|
@ -428,4 +428,3 @@ impl<'a> HTMLInputElementMethods for JSRef<'a, HTMLInputElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,4 +52,3 @@ impl<'a> HTMLLabelElementMethods for JSRef<'a, HTMLLabelElement> {
|
|||
fn SetHtmlFor(&mut self, _html_for: DOMString) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLLegendElementMethods for JSRef<'a, HTMLLegendElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,4 +64,3 @@ impl<'a> HTMLLIElementMethods for JSRef<'a, HTMLLIElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -143,4 +143,3 @@ impl<'a> HTMLLinkElementMethods for JSRef<'a, HTMLLinkElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -207,5 +207,3 @@ impl<'a> HTMLMediaElementMethods for JSRef<'a, HTMLMediaElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -84,4 +84,3 @@ impl<'a> HTMLMetaElementMethods for JSRef<'a, HTMLMetaElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,4 +64,3 @@ impl<'a> HTMLModElementMethods for JSRef<'a, HTMLModElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -290,9 +290,9 @@ impl<'a> HTMLObjectElementMethods for JSRef<'a, HTMLObjectElement> {
|
|||
}
|
||||
|
||||
impl<'a> VirtualMethods for JSRef<'a, HTMLObjectElement> {
|
||||
fn super_type(&self) -> Option<~VirtualMethods:> {
|
||||
let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self);
|
||||
Some(~htmlelement.clone() as ~VirtualMethods:)
|
||||
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:> {
|
||||
let htmlelement: &mut JSRef<HTMLElement> = HTMLElementCast::from_mut_ref(self);
|
||||
Some(htmlelement as &mut VirtualMethods:)
|
||||
}
|
||||
|
||||
fn after_set_attr(&mut self, name: DOMString, value: DOMString) {
|
||||
|
@ -303,8 +303,8 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLObjectElement> {
|
|||
|
||||
if "data" == name {
|
||||
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);
|
||||
let url = Some(window.deref().get_url());
|
||||
self.process_data_url(window.deref().image_cache_task.clone(), url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,4 +84,3 @@ impl<'a> HTMLOListElementMethods for JSRef<'a, HTMLOListElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,4 +64,3 @@ impl<'a> HTMLOptGroupElementMethods for JSRef<'a, HTMLOptGroupElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -115,4 +115,3 @@ impl<'a> HTMLOptionElementMethods for JSRef<'a, HTMLOptionElement> {
|
|||
0
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -120,4 +120,3 @@ impl<'a> HTMLOutputElementMethods for JSRef<'a, HTMLOutputElement> {
|
|||
fn SetCustomValidity(&mut self, _error: DOMString) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLParagraphElementMethods for JSRef<'a, HTMLParagraphElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -84,4 +84,3 @@ impl<'a> HTMLParamElementMethods for JSRef<'a, HTMLParamElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLPreElementMethods for JSRef<'a, HTMLPreElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,4 +74,3 @@ impl<'a> HTMLProgressElementMethods for JSRef<'a, HTMLProgressElement> {
|
|||
Ok(0f64)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLQuoteElementMethods for JSRef<'a, HTMLQuoteElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -136,4 +136,3 @@ impl<'a> HTMLScriptElementMethods for JSRef<'a, HTMLScriptElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -214,4 +214,3 @@ impl<'a> HTMLSelectElementMethods for JSRef<'a, HTMLSelectElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ pub fn serialize(iterator: &mut NodeIterator) -> ~str {
|
|||
}
|
||||
|
||||
fn serialize_comment(comment: &JSRef<Comment>) -> ~str {
|
||||
~"<!--" + comment.get().characterdata.data + "-->"
|
||||
~"<!--" + comment.deref().characterdata.data + "-->"
|
||||
}
|
||||
|
||||
fn serialize_text(text: &JSRef<Text>) -> ~str {
|
||||
|
@ -74,41 +74,41 @@ fn serialize_text(text: &JSRef<Text>) -> ~str {
|
|||
match text_node.parent_node().map(|node| node.root()) {
|
||||
Some(ref parent) if parent.is_element() => {
|
||||
let elem: &JSRef<Element> = ElementCast::to_ref(&**parent).unwrap();
|
||||
match elem.get().local_name.as_slice() {
|
||||
match elem.deref().local_name.as_slice() {
|
||||
"style" | "script" | "xmp" | "iframe" |
|
||||
"noembed" | "noframes" | "plaintext" |
|
||||
"noscript" if elem.get().namespace == namespace::HTML => {
|
||||
text.get().characterdata.data.clone()
|
||||
"noscript" if elem.deref().namespace == namespace::HTML => {
|
||||
text.deref().characterdata.data.clone()
|
||||
},
|
||||
_ => escape(text.get().characterdata.data, false)
|
||||
_ => escape(text.deref().characterdata.data, false)
|
||||
}
|
||||
}
|
||||
_ => escape(text.get().characterdata.data, false)
|
||||
_ => escape(text.deref().characterdata.data, false)
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_processing_instruction(processing_instruction: &JSRef<ProcessingInstruction>) -> ~str {
|
||||
~"<?" + processing_instruction.get().target + " " + processing_instruction.get().characterdata.data + "?>"
|
||||
~"<?" + processing_instruction.deref().target + " " + processing_instruction.deref().characterdata.data + "?>"
|
||||
}
|
||||
|
||||
fn serialize_doctype(doctype: &JSRef<DocumentType>) -> ~str {
|
||||
~"<!DOCTYPE" + doctype.get().name + ">"
|
||||
~"<!DOCTYPE" + doctype.deref().name + ">"
|
||||
}
|
||||
|
||||
fn serialize_elem(elem: &JSRef<Element>, open_elements: &mut Vec<~str>) -> ~str {
|
||||
let mut rv = ~"<" + elem.get().local_name;
|
||||
for attr in elem.get().attrs.iter() {
|
||||
let mut rv = ~"<" + elem.deref().local_name;
|
||||
for attr in elem.deref().attrs.iter() {
|
||||
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 => {
|
||||
match elem.deref().local_name.as_slice() {
|
||||
"pre" | "listing" | "textarea" if elem.deref().namespace == namespace::HTML => {
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(elem);
|
||||
match node.first_child().map(|child| child.root()) {
|
||||
Some(ref child) if child.is_text() => {
|
||||
let text: &JSRef<CharacterData> = CharacterDataCast::to_ref(&**child).unwrap();
|
||||
if text.get().data.len() > 0 && text.get().data[0] == 0x0A as u8 {
|
||||
if text.deref().data.len() > 0 && text.deref().data[0] == 0x0A as u8 {
|
||||
rv.push_str("\x0A");
|
||||
}
|
||||
},
|
||||
|
@ -117,26 +117,26 @@ fn serialize_elem(elem: &JSRef<Element>, open_elements: &mut Vec<~str>) -> ~str
|
|||
},
|
||||
_ => {}
|
||||
}
|
||||
if !elem.get().is_void() {
|
||||
open_elements.push(elem.get().local_name.clone());
|
||||
if !elem.deref().is_void() {
|
||||
open_elements.push(elem.deref().local_name.clone());
|
||||
}
|
||||
rv
|
||||
}
|
||||
|
||||
fn serialize_attr(attr: &JSRef<Attr>) -> ~str {
|
||||
let attr_name = if attr.get().namespace == namespace::XML {
|
||||
~"xml:" + attr.get().local_name.clone()
|
||||
} else if attr.get().namespace == namespace::XMLNS &&
|
||||
attr.get().local_name.as_slice() == "xmlns" {
|
||||
let attr_name = if attr.deref().namespace == namespace::XML {
|
||||
~"xml:" + attr.deref().local_name.clone()
|
||||
} else if attr.deref().namespace == namespace::XMLNS &&
|
||||
attr.deref().local_name.as_slice() == "xmlns" {
|
||||
~"xmlns"
|
||||
} else if attr.get().namespace == namespace::XMLNS {
|
||||
~"xmlns:" + attr.get().local_name.clone()
|
||||
} else if attr.get().namespace == namespace::XLink {
|
||||
~"xlink:" + attr.get().local_name.clone()
|
||||
} else if attr.deref().namespace == namespace::XMLNS {
|
||||
~"xmlns:" + attr.deref().local_name.clone()
|
||||
} else if attr.deref().namespace == namespace::XLink {
|
||||
~"xlink:" + attr.deref().local_name.clone()
|
||||
} else {
|
||||
attr.get().name.clone()
|
||||
attr.deref().name.clone()
|
||||
};
|
||||
~" " + attr_name + "=\"" + escape(attr.get().value, true) + "\""
|
||||
~" " + attr_name + "=\"" + escape(attr.deref().value, true) + "\""
|
||||
}
|
||||
|
||||
fn escape(string: &str, attr_mode: bool) -> ~str {
|
||||
|
|
|
@ -74,4 +74,3 @@ impl<'a> HTMLSourceElementMethods for JSRef<'a, HTMLSourceElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -95,19 +95,19 @@ impl<'a> StyleElementHelpers for JSRef<'a, HTMLStyleElement> {
|
|||
fn parse_own_css(&self) {
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
let win = window_from_node(node).root();
|
||||
let url = win.get().page().get_url();
|
||||
let url = win.deref().page().get_url();
|
||||
|
||||
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;
|
||||
let LayoutChan(ref layout_chan) = *win.deref().page().layout_chan;
|
||||
layout_chan.send(AddStylesheetMsg(sheet));
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> VirtualMethods for JSRef<'a, HTMLStyleElement> {
|
||||
fn super_type(&self) -> Option<~VirtualMethods:> {
|
||||
let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self);
|
||||
Some(~htmlelement.clone() as ~VirtualMethods:)
|
||||
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:> {
|
||||
let htmlelement: &mut JSRef<HTMLElement> = HTMLElementCast::from_mut_ref(self);
|
||||
Some(htmlelement as &mut VirtualMethods:)
|
||||
}
|
||||
|
||||
fn child_inserted(&mut self, child: &JSRef<Node>) {
|
||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLTableCaptionElementMethods for JSRef<'a, HTMLTableCaptionElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -189,5 +189,3 @@ impl<'a> HTMLTableCellElementMethods for JSRef<'a, HTMLTableCellElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -104,4 +104,3 @@ impl<'a> HTMLTableColElementMethods for JSRef<'a, HTMLTableColElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -164,4 +164,3 @@ impl<'a> HTMLTableElementMethods for JSRef<'a, HTMLTableElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -119,4 +119,3 @@ impl<'a> HTMLTableRowElementMethods for JSRef<'a, HTMLTableRowElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -89,4 +89,3 @@ impl<'a> HTMLTableSectionElementMethods for JSRef<'a, HTMLTableSectionElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -244,4 +244,3 @@ impl<'a> HTMLTextAreaElementMethods for JSRef<'a, HTMLTextAreaElement> {
|
|||
fn SetRangeText(&self, _replacement: DOMString) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLTimeElementMethods for JSRef<'a, HTMLTimeElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLTitleElementMethods for JSRef<'a, HTMLTitleElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -99,4 +99,3 @@ impl<'a> HTMLTrackElementMethods for JSRef<'a, HTMLTrackElement> {
|
|||
0
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,4 +64,3 @@ impl<'a> HTMLUListElementMethods for JSRef<'a, HTMLUListElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -84,4 +84,3 @@ impl<'a> HTMLVideoElementMethods for JSRef<'a, HTMLVideoElement> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -161,7 +161,6 @@ impl<'a> LocationMethods for JSRef<'a, Location> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl Reflectable for Location {
|
||||
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||
&self.reflector_
|
||||
|
|
|
@ -113,7 +113,6 @@ impl<'a> NavigatorMethods for JSRef<'a, Navigator> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl Reflectable for Navigator {
|
||||
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||
&self.reflector_
|
||||
|
|
|
@ -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, RootedReference, Temporary, Root};
|
||||
use dom::bindings::js::{JS, JSRef, RootedReference, Temporary, Root, OptionalUnrootable};
|
||||
use dom::bindings::js::{OptionalSettable, TemporaryPushable, OptionalRootedRootable};
|
||||
use dom::bindings::js::{ResultRootable, OptionalRootable};
|
||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||
|
@ -255,7 +255,7 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> {
|
|||
document.deref().content_changed();
|
||||
}
|
||||
|
||||
// http://spec.whatwg.org/#node-is-removed
|
||||
// http://dom.spec.whatwg.org/#node-is-removed
|
||||
fn node_removed(&self) {
|
||||
assert!(self.parent_node().is_none());
|
||||
let document = document_from_node(self).root();
|
||||
|
@ -417,9 +417,9 @@ pub trait NodeHelpers {
|
|||
fn dump_indent(&self, indent: uint);
|
||||
fn debug_str(&self) -> ~str;
|
||||
|
||||
fn traverse_preorder<'a>(&self) -> TreeIterator<'a>;
|
||||
fn sequential_traverse_postorder<'a>(&self) -> TreeIterator<'a>;
|
||||
fn inclusively_following_siblings(&self) -> AbstractNodeChildrenIterator;
|
||||
fn traverse_preorder<'a>(&'a self) -> TreeIterator<'a>;
|
||||
fn sequential_traverse_postorder<'a>(&'a self) -> TreeIterator<'a>;
|
||||
fn inclusively_following_siblings<'a>(&'a self) -> AbstractNodeChildrenIterator<'a>;
|
||||
|
||||
fn to_trusted_node_address(&self) -> TrustedNodeAddress;
|
||||
|
||||
|
@ -455,34 +455,34 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
|||
}
|
||||
|
||||
fn is_in_doc(&self) -> bool {
|
||||
self.get().flags.is_in_doc()
|
||||
self.deref().flags.is_in_doc()
|
||||
}
|
||||
|
||||
/// Returns the type ID of this node. Fails if this node is borrowed mutably.
|
||||
fn type_id(&self) -> NodeTypeId {
|
||||
self.get().type_id
|
||||
self.deref().type_id
|
||||
}
|
||||
|
||||
fn parent_node(&self) -> Option<Temporary<Node>> {
|
||||
self.get().parent_node.clone().map(|node| Temporary::new(node))
|
||||
self.deref().parent_node.clone().map(|node| Temporary::new(node))
|
||||
}
|
||||
|
||||
fn first_child(&self) -> Option<Temporary<Node>> {
|
||||
self.get().first_child.clone().map(|node| Temporary::new(node))
|
||||
self.deref().first_child.clone().map(|node| Temporary::new(node))
|
||||
}
|
||||
|
||||
fn last_child(&self) -> Option<Temporary<Node>> {
|
||||
self.get().last_child.clone().map(|node| Temporary::new(node))
|
||||
self.deref().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<Temporary<Node>> {
|
||||
self.get().prev_sibling.clone().map(|node| Temporary::new(node))
|
||||
self.deref().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<Temporary<Node>> {
|
||||
self.get().next_sibling.clone().map(|node| Temporary::new(node))
|
||||
self.deref().next_sibling.clone().map(|node| Temporary::new(node))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -536,22 +536,22 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
|||
}
|
||||
|
||||
/// Iterates over this node and all its descendants, in preorder.
|
||||
fn traverse_preorder<'a>(&self) -> TreeIterator<'a> {
|
||||
fn traverse_preorder<'a>(&'a self) -> TreeIterator<'a> {
|
||||
let mut nodes = vec!();
|
||||
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) -> TreeIterator<'a> {
|
||||
fn sequential_traverse_postorder<'a>(&'a self) -> TreeIterator<'a> {
|
||||
let mut nodes = vec!();
|
||||
gather_abstract_nodes(self, &mut nodes, true);
|
||||
TreeIterator::new(nodes)
|
||||
}
|
||||
|
||||
fn inclusively_following_siblings(&self) -> AbstractNodeChildrenIterator {
|
||||
fn inclusively_following_siblings<'a>(&'a self) -> AbstractNodeChildrenIterator<'a> {
|
||||
AbstractNodeChildrenIterator {
|
||||
current_node: Some((*self.unrooted().root()).clone()),
|
||||
current_node: Some(self.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -561,7 +561,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
|||
|
||||
fn following_siblings(&self) -> AbstractNodeChildrenIterator {
|
||||
AbstractNodeChildrenIterator {
|
||||
current_node: self.next_sibling().map(|node| (*node.root()).clone()),
|
||||
current_node: self.next_sibling().root().map(|next| next.deref().clone()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -573,12 +573,12 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
|||
}
|
||||
|
||||
fn to_trusted_node_address(&self) -> TrustedNodeAddress {
|
||||
TrustedNodeAddress(self.get() as *Node as *libc::c_void)
|
||||
TrustedNodeAddress(self.deref() as *Node as *libc::c_void)
|
||||
}
|
||||
|
||||
fn get_bounding_content_box(&self) -> Rect<Au> {
|
||||
let window = window_from_node(self).root();
|
||||
let page = window.get().page();
|
||||
let page = window.deref().page();
|
||||
let (chan, port) = channel();
|
||||
let addr = self.to_trusted_node_address();
|
||||
let ContentBoxResponse(rect) = page.query_layout(ContentBoxQuery(addr, chan), port);
|
||||
|
@ -587,7 +587,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
|||
|
||||
fn get_content_boxes(&self) -> Vec<Rect<Au>> {
|
||||
let window = window_from_node(self).root();
|
||||
let page = window.get().page();
|
||||
let page = window.deref().page();
|
||||
let (chan, port) = channel();
|
||||
let addr = self.to_trusted_node_address();
|
||||
let ContentBoxesResponse(rects) = page.query_layout(ContentBoxesQuery(addr, chan), port);
|
||||
|
@ -803,7 +803,7 @@ impl NodeIterator {
|
|||
fn next_child<'b>(&self, node: &JSRef<'b, Node>) -> Option<JSRef<Node>> {
|
||||
if !self.include_descendants_of_void && node.is_element() {
|
||||
let elem: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||
if elem.get().is_void() {
|
||||
if elem.deref().is_void() {
|
||||
None
|
||||
} else {
|
||||
node.first_child().map(|child| (*child.root()).clone())
|
||||
|
@ -861,15 +861,15 @@ impl<'a> Iterator<JSRef<'a, Node>> for NodeIterator {
|
|||
}
|
||||
}
|
||||
|
||||
fn gather_abstract_nodes<'a>(cur: &JSRef<Node>, refs: &mut Vec<JSRef<Node>>, postorder: bool) {
|
||||
fn gather_abstract_nodes<'a>(cur: &JSRef<'a, Node>, refs: &mut Vec<JSRef<'a, Node>>, postorder: bool) {
|
||||
if !postorder {
|
||||
refs.push((*cur.unrooted().root()).clone());
|
||||
refs.push(cur.clone());
|
||||
}
|
||||
for kid in cur.children() {
|
||||
gather_abstract_nodes(&kid, refs, postorder)
|
||||
}
|
||||
if postorder {
|
||||
refs.push((*cur.unrooted().root()).clone());
|
||||
refs.push(cur.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -889,9 +889,9 @@ impl Node {
|
|||
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<Window>, ~N) -> JS<N>)
|
||||
-> Temporary<N> {
|
||||
assert!(node.reflector().get_jsobject().is_null());
|
||||
let window = document.get().window.root();
|
||||
let window = document.deref().window.root();
|
||||
let node = reflect_dom_object(node, &window.root_ref(), wrap_fn).root();
|
||||
assert!(node.reflector().get_jsobject().is_not_null());
|
||||
assert!(node.deref().reflector().get_jsobject().is_not_null());
|
||||
Temporary::from_rooted(&*node)
|
||||
}
|
||||
|
||||
|
@ -914,7 +914,7 @@ impl Node {
|
|||
next_sibling: None,
|
||||
prev_sibling: None,
|
||||
|
||||
owner_doc: doc.map(|doc| doc.unrooted()),
|
||||
owner_doc: doc.unrooted(),
|
||||
child_list: None,
|
||||
|
||||
flags: NodeFlags::new(type_id),
|
||||
|
@ -1110,7 +1110,7 @@ impl Node {
|
|||
// Step 8.
|
||||
for node in nodes.mut_iter() {
|
||||
parent.add_child(node, child.clone());
|
||||
node.get_mut().flags.set_is_in_doc(parent.is_in_doc());
|
||||
node.deref_mut().flags.set_is_in_doc(parent.is_in_doc());
|
||||
}
|
||||
|
||||
// Step 9.
|
||||
|
@ -1193,7 +1193,7 @@ impl Node {
|
|||
// Step 6-7: mutation observers.
|
||||
// Step 8.
|
||||
parent.remove_child(node);
|
||||
node.get_mut().flags.set_is_in_doc(false);
|
||||
node.deref_mut().flags.set_is_in_doc(false);
|
||||
|
||||
// Step 9.
|
||||
match suppress_observers {
|
||||
|
@ -1217,7 +1217,7 @@ impl Node {
|
|||
let mut copy: Root<Node> = match node.type_id() {
|
||||
DoctypeNodeTypeId => {
|
||||
let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(node).unwrap();
|
||||
let doctype = doctype.get();
|
||||
let doctype = doctype.deref();
|
||||
let doctype = DocumentType::new(doctype.name.clone(),
|
||||
Some(doctype.public_id.clone()),
|
||||
Some(doctype.system_id.clone()), &*document);
|
||||
|
@ -1229,7 +1229,7 @@ impl Node {
|
|||
},
|
||||
CommentNodeTypeId => {
|
||||
let comment: &JSRef<Comment> = CommentCast::to_ref(node).unwrap();
|
||||
let comment = comment.get();
|
||||
let comment = comment.deref();
|
||||
let comment = Comment::new(comment.characterdata.data.clone(), &*document);
|
||||
NodeCast::from_unrooted(comment)
|
||||
},
|
||||
|
@ -1246,19 +1246,19 @@ impl Node {
|
|||
},
|
||||
ElementNodeTypeId(..) => {
|
||||
let element: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||
let element = element.get();
|
||||
let element = element.deref();
|
||||
let element = build_element_from_tag(element.local_name.clone(), &*document);
|
||||
NodeCast::from_unrooted(element)
|
||||
},
|
||||
TextNodeTypeId => {
|
||||
let text: &JSRef<Text> = TextCast::to_ref(node).unwrap();
|
||||
let text = text.get();
|
||||
let text = text.deref();
|
||||
let text = Text::new(text.characterdata.data.clone(), &*document);
|
||||
NodeCast::from_unrooted(text)
|
||||
},
|
||||
ProcessingInstructionNodeTypeId => {
|
||||
let pi: &JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(node).unwrap();
|
||||
let pi = pi.get();
|
||||
let pi = pi.deref();
|
||||
let pi = ProcessingInstruction::new(pi.target.clone(),
|
||||
pi.characterdata.data.clone(), &*document);
|
||||
NodeCast::from_unrooted(pi)
|
||||
|
@ -1275,7 +1275,7 @@ impl Node {
|
|||
assert!(&*copy.owner_doc().root() == &*document);
|
||||
|
||||
// Step 4 (some data already copied in step 2).
|
||||
match node.get().type_id {
|
||||
match node.type_id() {
|
||||
DocumentNodeTypeId => {
|
||||
let node_doc: &JSRef<Document> = DocumentCast::to_ref(node).unwrap();
|
||||
let copy_doc: &mut JSRef<Document> = DocumentCast::to_mut_ref(&mut *copy).unwrap();
|
||||
|
@ -1284,16 +1284,16 @@ impl Node {
|
|||
},
|
||||
ElementNodeTypeId(..) => {
|
||||
let node_elem: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||
let node_elem = node_elem.get();
|
||||
let node_elem = node_elem.deref();
|
||||
let copy_elem: &mut JSRef<Element> = 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 = copy_elem.clone();
|
||||
|
||||
let copy_elem = copy_elem.get_mut();
|
||||
let copy_elem = copy_elem.deref_mut();
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1737
|
||||
copy_elem.namespace = node_elem.namespace.clone();
|
||||
let window = document.get().window.root();
|
||||
let window = document.deref().window.root();
|
||||
for attr in node_elem.attrs.iter().map(|attr| attr.root()) {
|
||||
copy_elem.attrs.push_unrooted(
|
||||
&Attr::new(&*window,
|
||||
|
@ -1396,7 +1396,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
CommentNodeTypeId => ~"#comment",
|
||||
DoctypeNodeTypeId => {
|
||||
let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(self).unwrap();
|
||||
doctype.get().name.clone()
|
||||
doctype.deref().name.clone()
|
||||
},
|
||||
DocumentFragmentNodeTypeId => ~"#document-fragment",
|
||||
DocumentNodeTypeId => ~"#document"
|
||||
|
@ -1514,7 +1514,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
for node in self.traverse_preorder() {
|
||||
if node.is_text() {
|
||||
let text: &JSRef<Text> = TextCast::to_ref(&node).unwrap();
|
||||
content.push_str(text.get().characterdata.data.as_slice());
|
||||
content.push_str(text.deref().characterdata.data.as_slice());
|
||||
}
|
||||
}
|
||||
Some(content)
|
||||
|
@ -1557,7 +1557,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
|
||||
{
|
||||
let characterdata: &mut JSRef<CharacterData> = CharacterDataCast::to_mut_ref(self).unwrap();
|
||||
characterdata.get_mut().data = value.clone();
|
||||
characterdata.deref_mut().data = value.clone();
|
||||
}
|
||||
|
||||
// Notify the document that the content of this node is different
|
||||
|
@ -1755,35 +1755,35 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
fn is_equal_doctype(node: &JSRef<Node>, other: &JSRef<Node>) -> bool {
|
||||
let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(node).unwrap();
|
||||
let other_doctype: &JSRef<DocumentType> = 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)
|
||||
(doctype.deref().name == other_doctype.deref().name) &&
|
||||
(doctype.deref().public_id == other_doctype.deref().public_id) &&
|
||||
(doctype.deref().system_id == other_doctype.deref().system_id)
|
||||
}
|
||||
fn is_equal_element(node: &JSRef<Node>, other: &JSRef<Node>) -> bool {
|
||||
let element: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||
let other_element: &JSRef<Element> = 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())
|
||||
(element.deref().namespace == other_element.deref().namespace) &&
|
||||
(element.deref().local_name == other_element.deref().local_name) &&
|
||||
(element.deref().attrs.len() == other_element.deref().attrs.len())
|
||||
}
|
||||
fn is_equal_processinginstruction(node: &JSRef<Node>, other: &JSRef<Node>) -> bool {
|
||||
let pi: &JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(node).unwrap();
|
||||
let other_pi: &JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(other).unwrap();
|
||||
(pi.get().target == other_pi.get().target) &&
|
||||
(pi.get().characterdata.data == other_pi.get().characterdata.data)
|
||||
(pi.deref().target == other_pi.deref().target) &&
|
||||
(pi.deref().characterdata.data == other_pi.deref().characterdata.data)
|
||||
}
|
||||
fn is_equal_characterdata(node: &JSRef<Node>, other: &JSRef<Node>) -> bool {
|
||||
let characterdata: &JSRef<CharacterData> = CharacterDataCast::to_ref(node).unwrap();
|
||||
let other_characterdata: &JSRef<CharacterData> = CharacterDataCast::to_ref(other).unwrap();
|
||||
characterdata.get().data == other_characterdata.get().data
|
||||
characterdata.deref().data == other_characterdata.deref().data
|
||||
}
|
||||
fn is_equal_element_attrs(node: &JSRef<Node>, other: &JSRef<Node>) -> bool {
|
||||
let element: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||
let other_element: &JSRef<Element> = ElementCast::to_ref(other).unwrap();
|
||||
assert!(element.get().attrs.len() == other_element.get().attrs.len());
|
||||
element.get().attrs.iter().map(|attr| attr.root()).all(|attr| {
|
||||
other_element.get().attrs.iter().map(|attr| attr.root()).any(|other_attr| {
|
||||
assert!(element.deref().attrs.len() == other_element.deref().attrs.len());
|
||||
element.deref().attrs.iter().map(|attr| attr.root()).all(|attr| {
|
||||
other_element.deref().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)
|
||||
|
@ -1929,8 +1929,8 @@ pub fn window_from_node<T: NodeBase>(derived: &JSRef<T>) -> Temporary<Window> {
|
|||
}
|
||||
|
||||
impl<'a> VirtualMethods for JSRef<'a, Node> {
|
||||
fn super_type(&self) -> Option<~VirtualMethods:> {
|
||||
let eventtarget: &JSRef<EventTarget> = EventTargetCast::from_ref(self);
|
||||
Some(~eventtarget.clone() as ~VirtualMethods:)
|
||||
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:> {
|
||||
let eventtarget: &mut JSRef<EventTarget> = EventTargetCast::from_mut_ref(self);
|
||||
Some(eventtarget as &mut VirtualMethods:)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,4 +50,3 @@ impl<'a> ProcessingInstructionMethods for JSRef<'a, ProcessingInstruction> {
|
|||
self.target.clone()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ pub trait TestBindingMethods {
|
|||
fn PassOptionalNullableString(&self, _: Option<Option<DOMString>>);
|
||||
fn PassOptionalNullableByteString(&self, _: Option<Option<ByteString>>) {}
|
||||
// fn PassOptionalNullableEnum(&self, _: Option<Option<TestEnum>>);
|
||||
fn PassOptionalNullableInterface(&self, _: Option<Option<JS<Blob>>>);
|
||||
fn PassOptionalNullableInterface(&self, _: Option<Option<JSRef<Blob>>>);
|
||||
fn PassOptionalNullableUnion(&self, _: Option<Option<HTMLElementOrLong>>);
|
||||
|
||||
fn PassOptionalBooleanWithDefault(&self, _: bool);
|
||||
|
@ -268,7 +268,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
|||
fn GetEnumAttributeNullable(&self) -> Option<TestEnum> { Some(_empty) }
|
||||
fn GetInterfaceAttributeNullable(&self) -> Option<Temporary<Blob>> {
|
||||
let window = self.window.root();
|
||||
Some(Blob::new(&(*window)))
|
||||
Some(Blob::new(&*window))
|
||||
}
|
||||
fn SetInterfaceAttributeNullable(&self, _: Option<JSRef<Blob>>) {}
|
||||
|
||||
|
@ -340,7 +340,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
|||
fn PassOptionalNullableString(&self, _: Option<Option<DOMString>>) {}
|
||||
fn PassOptionalNullableByteString(&self, _: Option<Option<ByteString>>) {}
|
||||
// fn PassOptionalNullableEnum(&self, _: Option<Option<TestEnum>>) {}
|
||||
fn PassOptionalNullableInterface(&self, _: Option<Option<JS<Blob>>>) {}
|
||||
fn PassOptionalNullableInterface(&self, _: Option<Option<JSRef<Blob>>>) {}
|
||||
fn PassOptionalNullableUnion(&self, _: Option<Option<HTMLElementOrLong>>) {}
|
||||
|
||||
fn PassOptionalBooleanWithDefault(&self, _: bool) {}
|
||||
|
|
|
@ -60,4 +60,3 @@ impl<'a> TextMethods for JSRef<'a, Text> {
|
|||
Ok(~"")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -146,7 +146,6 @@ impl<'a> UIEventMethods for JSRef<'a, UIEvent> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl Reflectable for UIEvent {
|
||||
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||
self.event.reflector()
|
||||
|
|
|
@ -80,7 +80,6 @@ impl<'a> ValidityStateMethods for JSRef<'a, ValidityState> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl Reflectable for ValidityState {
|
||||
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||
&self.reflector_
|
||||
|
|
|
@ -17,7 +17,7 @@ use dom::htmliframeelement::HTMLIFrameElement;
|
|||
use dom::htmlimageelement::HTMLImageElement;
|
||||
use dom::htmlobjectelement::HTMLObjectElement;
|
||||
use dom::htmlstyleelement::HTMLStyleElement;
|
||||
use dom::node::{Node, ElementNodeTypeId};
|
||||
use dom::node::{Node, NodeHelpers, ElementNodeTypeId};
|
||||
use servo_util::str::DOMString;
|
||||
|
||||
/// Trait to allow DOM nodes to opt-in to overriding (or adding to) common
|
||||
|
@ -25,7 +25,7 @@ use servo_util::str::DOMString;
|
|||
pub trait VirtualMethods {
|
||||
/// Returns self as the superclass of the implementation for this trait,
|
||||
/// if any.
|
||||
fn super_type(&self) -> Option<~VirtualMethods:>;
|
||||
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:>;
|
||||
|
||||
/// Called when changing or adding attributes, after the attribute's value
|
||||
/// has been updated.
|
||||
|
@ -75,7 +75,7 @@ pub trait VirtualMethods {
|
|||
/// concrete type, propagating up the parent hierarchy unless otherwise
|
||||
/// interrupted.
|
||||
pub fn vtable_for<'a>(node: &'a mut JSRef<Node>) -> &'a mut VirtualMethods: {
|
||||
match node.get().type_id {
|
||||
match node.type_id() {
|
||||
ElementNodeTypeId(HTMLImageElementTypeId) => {
|
||||
let element: &mut JSRef<HTMLImageElement> = HTMLImageElementCast::to_mut_ref(node).unwrap();
|
||||
element as &mut VirtualMethods:
|
||||
|
|
|
@ -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); //XXXjdm disabled until later commit
|
||||
void passOptionalNullableInterface(optional Blob? arg);
|
||||
void passOptionalNullableUnion(optional (HTMLElement or long)? arg);
|
||||
|
||||
void passOptionalBooleanWithDefault(optional boolean arg = false);
|
||||
|
|
|
@ -81,7 +81,7 @@ trait NodeWrapping<T> {
|
|||
|
||||
impl<'a, T: NodeBase+Reflectable> NodeWrapping<T> for JSRef<'a, T> {
|
||||
unsafe fn to_hubbub_node(&self) -> hubbub::NodeDataPtr {
|
||||
cast::transmute(self.get())
|
||||
cast::transmute(self.deref())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -293,7 +293,6 @@ 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() });
|
||||
parser.enable_scripting(true);
|
||||
parser.enable_styling(true);
|
||||
|
@ -393,7 +392,7 @@ pub fn parse_html(page: &Page,
|
|||
let SubpageId(id_num) = subpage_id;
|
||||
*next_subpage_id.borrow_mut() = SubpageId(id_num + 1);
|
||||
|
||||
iframe_element.get_mut().size = Some(IFrameSize {
|
||||
iframe_element.deref_mut().size = Some(IFrameSize {
|
||||
pipeline_id: pipeline_id,
|
||||
subpage_id: subpage_id,
|
||||
});
|
||||
|
@ -477,7 +476,7 @@ pub fn parse_html(page: &Page,
|
|||
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()));
|
||||
let new_url = parse_url(src.deref().value_ref(), Some(url3.clone()));
|
||||
js_chan2.send(JSTaskNewFile(new_url));
|
||||
}
|
||||
None => {
|
||||
|
@ -487,7 +486,7 @@ pub fn parse_html(page: &Page,
|
|||
for child in scriptnode.children() {
|
||||
debug!("child = {:?}", child);
|
||||
let text: &JSRef<Text> = TextCast::to_ref(&child).unwrap();
|
||||
data.push(text.get().characterdata.data.to_str()); // FIXME: Bad copy.
|
||||
data.push(text.deref().characterdata.data.to_str()); // FIXME: Bad copy.
|
||||
}
|
||||
|
||||
debug!("script data = {:?}", data);
|
||||
|
|
|
@ -419,7 +419,7 @@ impl Page {
|
|||
anchors.find(|node| {
|
||||
let elem: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||
elem.get_attribute(Null, "name").root().map_or(false, |attr| {
|
||||
attr.get().value_ref() == fragid
|
||||
attr.deref().value_ref() == fragid
|
||||
})
|
||||
}).map(|node| Temporary::from_rooted(ElementCast::to_ref(&node).unwrap()))
|
||||
}
|
||||
|
@ -758,19 +758,18 @@ impl ScriptTask {
|
|||
|
||||
/// Handles a timer that fired.
|
||||
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.root();
|
||||
|
||||
let this_value = window.deref().reflector().get_jsobject();
|
||||
|
||||
let is_interval;
|
||||
match window.get().active_timers.find(&timer_id) {
|
||||
match window.deref().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();
|
||||
|
@ -785,7 +784,7 @@ impl ScriptTask {
|
|||
}
|
||||
|
||||
if !is_interval {
|
||||
window.get_mut().active_timers.remove(&timer_id);
|
||||
window.deref_mut().active_timers.remove(&timer_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -874,7 +873,6 @@ impl ScriptTask {
|
|||
fn load(&self, pipeline_id: PipelineId, url: Url) {
|
||||
debug!("ScriptTask: loading {:?} on page {:?}", url, pipeline_id);
|
||||
|
||||
|
||||
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
|
||||
|
@ -903,7 +901,7 @@ impl ScriptTask {
|
|||
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();
|
||||
window.get_mut().init_browser_context(&*document);
|
||||
window.deref_mut().init_browser_context(&*document);
|
||||
|
||||
{
|
||||
let mut js_info = page.mut_js_info();
|
||||
|
@ -1118,7 +1116,7 @@ impl ScriptTask {
|
|||
|
||||
if node.deref().is_element() {
|
||||
let element: &JSRef<Element> = ElementCast::to_ref(&*node).unwrap();
|
||||
if "a" == element.get().local_name {
|
||||
if "a" == element.deref().local_name {
|
||||
self.load_url_from_element(page, element)
|
||||
}
|
||||
}
|
||||
|
@ -1205,10 +1203,10 @@ impl ScriptTask {
|
|||
let attr = element.get_attribute(Null, "href");
|
||||
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 click_frag = href.deref().value_ref().starts_with("#");
|
||||
let base_url = Some(page.get_url());
|
||||
debug!("ScriptTask: current url is {:?}", base_url);
|
||||
let url = parse_url(href.get().value_ref(), base_url);
|
||||
let url = parse_url(href.deref().value_ref(), base_url);
|
||||
|
||||
if click_frag {
|
||||
match page.find_fragment_node(url.fragment.unwrap()).root() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue