aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2016-01-23 23:32:51 +0100
committerAnthony Ramine <n.oxyde@gmail.com>2016-02-25 15:15:44 +0100
commitca979e115b087cf627baf2be8d54ea47b1f773a1 (patch)
tree7dcfe3f4380a468f766ec2291dc162530bd2d061 /components/script/dom/bindings/codegen
parent2c4d5da86685537b550f05a6a142c6543320ab0f (diff)
downloadservo-ca979e115b087cf627baf2be8d54ea47b1f773a1.tar.gz
servo-ca979e115b087cf627baf2be8d54ea47b1f773a1.zip
Cache legacy callback interface objects in proto_or_icache_array
We need them to be cached to not instantiate them multiple times with lazy initialisation.
Diffstat (limited to 'components/script/dom/bindings/codegen')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py32
-rw-r--r--components/script/dom/bindings/codegen/Configuration.py4
2 files changed, 24 insertions, 12 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 99d60e379b6..6ae07873dca 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -2379,9 +2379,8 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
properties should be a PropertyArrays instance.
"""
def __init__(self, descriptor, properties):
- args = [Argument('*mut JSContext', 'cx'), Argument('HandleObject', 'global')]
- if not descriptor.interface.isCallback():
- args.append(Argument('*mut ProtoOrIfaceArray', 'cache'))
+ args = [Argument('*mut JSContext', 'cx'), Argument('HandleObject', 'global'),
+ Argument('*mut ProtoOrIfaceArray', 'cache')]
CGAbstractMethod.__init__(self, descriptor, 'CreateInterfaceObjects', 'void', args,
unsafe=True)
self.properties = properties
@@ -2391,7 +2390,14 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
if self.descriptor.interface.isCallback():
assert not self.descriptor.interface.ctor() and self.descriptor.interface.hasConstants()
return CGGeneric("""\
-create_callback_interface_object(cx, global, sConstants, %s);""" % str_to_const_array(name))
+let mut interface = RootedObject::new(cx, ptr::null_mut());
+create_callback_interface_object(cx, global, sConstants, %(name)s, interface.handle_mut());
+assert!(!interface.ptr.is_null());
+(*cache)[PrototypeList::Constructor::%(id)s as usize] = interface.ptr;
+if <*mut JSObject>::needs_post_barrier(interface.ptr) {
+ <*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::Constructor::%(id)s as isize));
+}
+""" % {"id": name, "name": str_to_const_array(name)})
if len(self.descriptor.prototypeChain) == 1:
if self.descriptor.interface.getExtendedAttribute("ExceptionClass"):
@@ -2672,14 +2678,14 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod):
def definition_body(self):
if self.descriptor.interface.isCallback():
- code = "CreateInterfaceObjects(cx, global);"
+ function = "GetConstructorObject"
else:
- code = """\
+ function = "GetProtoObject"
+ return CGGeneric("""\
+assert!(!global.get().is_null());
let mut proto = RootedObject::new(cx, ptr::null_mut());
-GetProtoObject(cx, global, proto.handle_mut());
-assert!(!proto.ptr.is_null());
-"""
- return CGGeneric("assert!(!global.get().is_null());\n" + code)
+%s(cx, global, proto.handle_mut());
+assert!(!proto.ptr.is_null());""" % function)
def needCx(returnType, arguments, considerTypes):
@@ -4956,7 +4962,8 @@ class CGDescriptor(CGThing):
cgThings = []
if not descriptor.interface.isCallback():
cgThings.append(CGGetProtoObjectMethod(descriptor))
- if descriptor.interface.hasInterfaceObject() and descriptor.hasDescendants():
+ if (descriptor.interface.hasInterfaceObject() and
+ descriptor.shouldHaveGetConstructorObjectMethod()):
cgThings.append(CGGetConstructorObjectMethod(descriptor))
for m in descriptor.interface.members:
@@ -6093,7 +6100,8 @@ class GlobalGenRoots():
# Prototype ID enum.
interfaces = config.getDescriptors(isCallback=False)
protos = [d.name for d in interfaces]
- constructors = [d.name for d in interfaces if d.hasDescendants()]
+ constructors = [d.name for d in config.getDescriptors(hasInterfaceObject=True)
+ if d.shouldHaveGetConstructorObjectMethod()]
proxies = [d.name for d in config.getDescriptors(proxy=True)]
return CGList([
diff --git a/components/script/dom/bindings/codegen/Configuration.py b/components/script/dom/bindings/codegen/Configuration.py
index 762998b91ac..c634665c410 100644
--- a/components/script/dom/bindings/codegen/Configuration.py
+++ b/components/script/dom/bindings/codegen/Configuration.py
@@ -345,6 +345,10 @@ class Descriptor(DescriptorProvider):
return (self.interface.getUserData("hasConcreteDescendant", False) or
self.interface.getUserData("hasProxyDescendant", False))
+ def shouldHaveGetConstructorObjectMethod(self):
+ assert self.interface.hasInterfaceObject()
+ return self.interface.isCallback() or self.hasDescendants()
+
def isGlobal(self):
"""
Returns true if this is the primary interface for a global object