mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
auto merge of #4781 : Ms2ger/servo/snake-dom, r=jdm
This commit is contained in:
commit
be31f85083
3 changed files with 47 additions and 47 deletions
|
@ -1795,14 +1795,14 @@ class CGAbstractMethod(CGThing):
|
||||||
assert(False) # Override me!
|
assert(False) # Override me!
|
||||||
|
|
||||||
def CreateBindingJSObject(descriptor, parent=None):
|
def CreateBindingJSObject(descriptor, parent=None):
|
||||||
create = "let mut raw: JS<%s> = JS::from_raw(&*aObject);\n" % descriptor.concreteType
|
create = "let mut raw: JS<%s> = JS::from_raw(&*object);\n" % descriptor.concreteType
|
||||||
if descriptor.proxy:
|
if descriptor.proxy:
|
||||||
assert not descriptor.isGlobal()
|
assert not descriptor.isGlobal()
|
||||||
create += """
|
create += """
|
||||||
let handler = RegisterBindings::proxy_handlers[PrototypeList::Proxies::%s as uint];
|
let handler = RegisterBindings::proxy_handlers[PrototypeList::Proxies::%s as uint];
|
||||||
let mut private = PrivateValue(squirrel_away_unique(aObject) as *const libc::c_void);
|
let mut private = PrivateValue(squirrel_away_unique(object) as *const libc::c_void);
|
||||||
let obj = with_compartment(aCx, proto, || {
|
let obj = with_compartment(cx, proto, || {
|
||||||
NewProxyObject(aCx, handler,
|
NewProxyObject(cx, handler,
|
||||||
&private,
|
&private,
|
||||||
proto, %s,
|
proto, %s,
|
||||||
ptr::null_mut(), ptr::null_mut())
|
ptr::null_mut(), ptr::null_mut())
|
||||||
|
@ -1811,16 +1811,16 @@ assert!(!obj.is_null());\
|
||||||
""" % (descriptor.name, parent)
|
""" % (descriptor.name, parent)
|
||||||
else:
|
else:
|
||||||
if descriptor.isGlobal():
|
if descriptor.isGlobal():
|
||||||
create += "let obj = create_dom_global(aCx, &Class.base as *const js::Class as *const JSClass);\n"
|
create += "let obj = create_dom_global(cx, &Class.base as *const js::Class as *const JSClass);\n"
|
||||||
else:
|
else:
|
||||||
create += ("let obj = with_compartment(aCx, proto, || {\n"
|
create += ("let obj = with_compartment(cx, proto, || {\n"
|
||||||
" JS_NewObject(aCx, &Class.base as *const js::Class as *const JSClass, &*proto, &*%s)\n"
|
" JS_NewObject(cx, &Class.base as *const js::Class as *const JSClass, &*proto, &*%s)\n"
|
||||||
"});\n" % parent)
|
"});\n" % parent)
|
||||||
create += """\
|
create += """\
|
||||||
assert!(!obj.is_null());
|
assert!(!obj.is_null());
|
||||||
|
|
||||||
JS_SetReservedSlot(obj, DOM_OBJECT_SLOT as u32,
|
JS_SetReservedSlot(obj, DOM_OBJECT_SLOT as u32,
|
||||||
PrivateValue(squirrel_away_unique(aObject) as *const libc::c_void));"""
|
PrivateValue(squirrel_away_unique(object) as *const libc::c_void));"""
|
||||||
return create
|
return create
|
||||||
|
|
||||||
class CGWrapMethod(CGAbstractMethod):
|
class CGWrapMethod(CGAbstractMethod):
|
||||||
|
@ -1831,22 +1831,22 @@ class CGWrapMethod(CGAbstractMethod):
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
assert not descriptor.interface.isCallback()
|
assert not descriptor.interface.isCallback()
|
||||||
if not descriptor.isGlobal():
|
if not descriptor.isGlobal():
|
||||||
args = [Argument('*mut JSContext', 'aCx'), Argument('GlobalRef', 'aScope'),
|
args = [Argument('*mut JSContext', 'cx'), Argument('GlobalRef', 'scope'),
|
||||||
Argument("Box<%s>" % descriptor.concreteType, 'aObject', mutable=True)]
|
Argument("Box<%s>" % descriptor.concreteType, 'object', mutable=True)]
|
||||||
else:
|
else:
|
||||||
args = [Argument('*mut JSContext', 'aCx'),
|
args = [Argument('*mut JSContext', 'cx'),
|
||||||
Argument("Box<%s>" % descriptor.concreteType, 'aObject', mutable=True)]
|
Argument("Box<%s>" % descriptor.concreteType, 'object', mutable=True)]
|
||||||
retval = 'Temporary<%s>' % descriptor.concreteType
|
retval = 'Temporary<%s>' % descriptor.concreteType
|
||||||
CGAbstractMethod.__init__(self, descriptor, 'Wrap', retval, args, pub=True)
|
CGAbstractMethod.__init__(self, descriptor, 'Wrap', retval, args, pub=True)
|
||||||
|
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
if not self.descriptor.isGlobal():
|
if not self.descriptor.isGlobal():
|
||||||
return CGGeneric("""\
|
return CGGeneric("""\
|
||||||
let scope = aScope.reflector().get_jsobject();
|
let scope = scope.reflector().get_jsobject();
|
||||||
assert!(!scope.is_null());
|
assert!(!scope.is_null());
|
||||||
assert!(((*JS_GetClass(scope)).flags & JSCLASS_IS_GLOBAL) != 0);
|
assert!(((*JS_GetClass(scope)).flags & JSCLASS_IS_GLOBAL) != 0);
|
||||||
|
|
||||||
let proto = with_compartment(aCx, scope, || GetProtoObject(aCx, scope, scope));
|
let proto = with_compartment(cx, scope, || GetProtoObject(cx, scope, scope));
|
||||||
assert!(!proto.is_null());
|
assert!(!proto.is_null());
|
||||||
|
|
||||||
%s
|
%s
|
||||||
|
@ -1857,13 +1857,13 @@ Temporary::new(raw)""" % CreateBindingJSObject(self.descriptor, "scope"))
|
||||||
else:
|
else:
|
||||||
return CGGeneric("""\
|
return CGGeneric("""\
|
||||||
%s
|
%s
|
||||||
with_compartment(aCx, obj, || {
|
with_compartment(cx, obj, || {
|
||||||
let proto = GetProtoObject(aCx, obj, obj);
|
let proto = GetProtoObject(cx, obj, obj);
|
||||||
JS_SetPrototype(aCx, obj, proto);
|
JS_SetPrototype(cx, obj, proto);
|
||||||
|
|
||||||
raw.reflector().set_jsobject(obj);
|
raw.reflector().set_jsobject(obj);
|
||||||
|
|
||||||
RegisterBindings::Register(aCx, obj);
|
RegisterBindings::Register(cx, obj);
|
||||||
});
|
});
|
||||||
|
|
||||||
Temporary::new(raw)""" % CreateBindingJSObject(self.descriptor))
|
Temporary::new(raw)""" % CreateBindingJSObject(self.descriptor))
|
||||||
|
@ -1962,21 +1962,21 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
|
||||||
"""
|
"""
|
||||||
def __init__(self, descriptor, properties):
|
def __init__(self, descriptor, properties):
|
||||||
assert not descriptor.interface.isCallback()
|
assert not descriptor.interface.isCallback()
|
||||||
args = [Argument('*mut JSContext', 'aCx'), Argument('*mut JSObject', 'aGlobal'),
|
args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'global'),
|
||||||
Argument('*mut JSObject', 'aReceiver')]
|
Argument('*mut JSObject', 'receiver')]
|
||||||
CGAbstractMethod.__init__(self, descriptor, 'CreateInterfaceObjects', '*mut JSObject', args)
|
CGAbstractMethod.__init__(self, descriptor, 'CreateInterfaceObjects', '*mut JSObject', args)
|
||||||
self.properties = properties
|
self.properties = properties
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
protoChain = self.descriptor.prototypeChain
|
protoChain = self.descriptor.prototypeChain
|
||||||
if len(protoChain) == 1:
|
if len(protoChain) == 1:
|
||||||
getParentProto = "JS_GetObjectPrototype(aCx, aGlobal)"
|
getParentProto = "JS_GetObjectPrototype(cx, global)"
|
||||||
else:
|
else:
|
||||||
parentProtoName = self.descriptor.prototypeChain[-2]
|
parentProtoName = self.descriptor.prototypeChain[-2]
|
||||||
getParentProto = ("%s::GetProtoObject(aCx, aGlobal, aReceiver)" %
|
getParentProto = ("%s::GetProtoObject(cx, global, receiver)" %
|
||||||
toBindingNamespace(parentProtoName))
|
toBindingNamespace(parentProtoName))
|
||||||
|
|
||||||
getParentProto = ("let parentProto: *mut JSObject = %s;\n"
|
getParentProto = ("let parent_proto: *mut JSObject = %s;\n"
|
||||||
"assert!(!parentProto.is_null());\n") % getParentProto
|
"assert!(!parent_proto.is_null());\n") % getParentProto
|
||||||
|
|
||||||
if self.descriptor.concrete:
|
if self.descriptor.concrete:
|
||||||
if self.descriptor.proxy:
|
if self.descriptor.proxy:
|
||||||
|
@ -2001,7 +2001,7 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
|
||||||
constructor = 'None'
|
constructor = 'None'
|
||||||
|
|
||||||
call = """\
|
call = """\
|
||||||
return do_create_interface_objects(aCx, aGlobal, aReceiver, parentProto,
|
return do_create_interface_objects(cx, global, receiver, parent_proto,
|
||||||
&PrototypeClass, %s,
|
&PrototypeClass, %s,
|
||||||
%s,
|
%s,
|
||||||
&sNativeProperties);""" % (constructor, domClass)
|
&sNativeProperties);""" % (constructor, domClass)
|
||||||
|
@ -2017,32 +2017,32 @@ class CGGetPerInterfaceObject(CGAbstractMethod):
|
||||||
constructor object).
|
constructor object).
|
||||||
"""
|
"""
|
||||||
def __init__(self, descriptor, name, idPrefix="", pub=False):
|
def __init__(self, descriptor, name, idPrefix="", pub=False):
|
||||||
args = [Argument('*mut JSContext', 'aCx'), Argument('*mut JSObject', 'aGlobal'),
|
args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'global'),
|
||||||
Argument('*mut JSObject', 'aReceiver')]
|
Argument('*mut JSObject', 'receiver')]
|
||||||
CGAbstractMethod.__init__(self, descriptor, name,
|
CGAbstractMethod.__init__(self, descriptor, name,
|
||||||
'*mut JSObject', args, pub=pub)
|
'*mut JSObject', args, pub=pub)
|
||||||
self.id = idPrefix + "ID::" + self.descriptor.name
|
self.id = idPrefix + "ID::" + self.descriptor.name
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
return CGGeneric("""
|
return CGGeneric("""
|
||||||
|
|
||||||
/* aGlobal and aReceiver are usually the same, but they can be different
|
/* global and receiver are usually the same, but they can be different
|
||||||
too. For example a sandbox often has an xray wrapper for a window as the
|
too. For example a sandbox often has an xray wrapper for a window as the
|
||||||
prototype of the sandbox's global. In that case aReceiver is the xray
|
prototype of the sandbox's global. In that case receiver is the xray
|
||||||
wrapper and aGlobal is the sandbox's global.
|
wrapper and global is the sandbox's global.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
assert!(((*JS_GetClass(aGlobal)).flags & JSCLASS_DOM_GLOBAL) != 0);
|
assert!(((*JS_GetClass(global)).flags & JSCLASS_DOM_GLOBAL) != 0);
|
||||||
|
|
||||||
/* Check to see whether the interface objects are already installed */
|
/* Check to see whether the interface objects are already installed */
|
||||||
let protoOrIfaceArray = get_proto_or_iface_array(aGlobal);
|
let proto_or_iface_array = get_proto_or_iface_array(global);
|
||||||
let cachedObject: *mut JSObject = *protoOrIfaceArray.offset(%s as int);
|
let cached_object: *mut JSObject = *proto_or_iface_array.offset(%s as int);
|
||||||
if cachedObject.is_null() {
|
if cached_object.is_null() {
|
||||||
let tmp: *mut JSObject = CreateInterfaceObjects(aCx, aGlobal, aReceiver);
|
let tmp: *mut JSObject = CreateInterfaceObjects(cx, global, receiver);
|
||||||
assert!(!tmp.is_null());
|
assert!(!tmp.is_null());
|
||||||
*protoOrIfaceArray.offset(%s as int) = tmp;
|
*proto_or_iface_array.offset(%s as int) = tmp;
|
||||||
tmp
|
tmp
|
||||||
} else {
|
} else {
|
||||||
cachedObject
|
cached_object
|
||||||
}""" % (self.id, self.id))
|
}""" % (self.id, self.id))
|
||||||
|
|
||||||
class CGGetProtoObjectMethod(CGGetPerInterfaceObject):
|
class CGGetProtoObjectMethod(CGGetPerInterfaceObject):
|
||||||
|
|
|
@ -1376,7 +1376,7 @@ impl Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 7-8.
|
// Step 7-8.
|
||||||
let referenceChild = match child {
|
let reference_child = match child {
|
||||||
Some(child) if child.clone() == node => node.next_sibling().map(|node| (*node.root()).clone()),
|
Some(child) if child.clone() == node => node.next_sibling().map(|node| (*node.root()).clone()),
|
||||||
_ => child
|
_ => child
|
||||||
};
|
};
|
||||||
|
@ -1386,7 +1386,7 @@ impl Node {
|
||||||
Node::adopt(node, *document);
|
Node::adopt(node, *document);
|
||||||
|
|
||||||
// Step 10.
|
// Step 10.
|
||||||
Node::insert(node, parent, referenceChild, SuppressObserver::Unsuppressed);
|
Node::insert(node, parent, reference_child, SuppressObserver::Unsuppressed);
|
||||||
|
|
||||||
// Step 11.
|
// Step 11.
|
||||||
return Ok(Temporary::from_rooted(node))
|
return Ok(Temporary::from_rooted(node))
|
||||||
|
@ -1467,10 +1467,10 @@ impl Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2.
|
// Step 2.
|
||||||
let removedNodes: Vec<JSRef<Node>> = parent.children().collect();
|
let removed_nodes: Vec<JSRef<Node>> = parent.children().collect();
|
||||||
|
|
||||||
// Step 3.
|
// Step 3.
|
||||||
let addedNodes = match node {
|
let added_nodes = match node {
|
||||||
None => vec!(),
|
None => vec!(),
|
||||||
Some(node) => match node.type_id() {
|
Some(node) => match node.type_id() {
|
||||||
NodeTypeId::DocumentFragment => node.children().collect(),
|
NodeTypeId::DocumentFragment => node.children().collect(),
|
||||||
|
@ -1493,11 +1493,11 @@ impl Node {
|
||||||
|
|
||||||
// Step 7.
|
// Step 7.
|
||||||
let parent_in_doc = parent.is_in_doc();
|
let parent_in_doc = parent.is_in_doc();
|
||||||
for removedNode in removedNodes.iter() {
|
for removed_node in removed_nodes.iter() {
|
||||||
removedNode.node_removed(parent_in_doc);
|
removed_node.node_removed(parent_in_doc);
|
||||||
}
|
}
|
||||||
for addedNode in addedNodes.iter() {
|
for added_node in added_nodes.iter() {
|
||||||
addedNode.node_inserted();
|
added_node.node_inserted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,10 +57,10 @@ impl Worker {
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://www.whatwg.org/html/#dom-worker
|
// http://www.whatwg.org/html/#dom-worker
|
||||||
pub fn Constructor(global: GlobalRef, scriptURL: DOMString) -> Fallible<Temporary<Worker>> {
|
pub fn Constructor(global: GlobalRef, script_url: DOMString) -> Fallible<Temporary<Worker>> {
|
||||||
// Step 2-4.
|
// Step 2-4.
|
||||||
let worker_url = match UrlParser::new().base_url(&global.get_url())
|
let worker_url = match UrlParser::new().base_url(&global.get_url())
|
||||||
.parse(scriptURL.as_slice()) {
|
.parse(script_url.as_slice()) {
|
||||||
Ok(url) => url,
|
Ok(url) => url,
|
||||||
Err(_) => return Err(Syntax),
|
Err(_) => return Err(Syntax),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue