aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2016-01-29 01:10:26 +0100
committerAnthony Ramine <n.oxyde@gmail.com>2016-02-25 15:56:47 +0100
commit1559f5a39fab451d83ad40ef960d9a3e5cd9f453 (patch)
tree0228ec739ce6cc78dc72f4cd00d2ad4389b44191 /components/script/dom/bindings/codegen
parentca979e115b087cf627baf2be8d54ea47b1f773a1 (diff)
downloadservo-1559f5a39fab451d83ad40ef960d9a3e5cd9f453.tar.gz
servo-1559f5a39fab451d83ad40ef960d9a3e5cd9f453.zip
Lazily define interface objects on globals (fixes #6419)
Diffstat (limited to 'components/script/dom/bindings/codegen')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py48
-rw-r--r--components/script/dom/bindings/codegen/GlobalGen.py1
2 files changed, 39 insertions, 10 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 6ae07873dca..c969d3f04db 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -1779,10 +1779,10 @@ class CGDOMJSClass(CGThing):
}
if self.descriptor.isGlobal():
assert not self.descriptor.weakReferenceable
- args["enumerateHook"] = "Some(js::jsapi::JS_EnumerateStandardClasses)"
+ args["enumerateHook"] = "Some(enumerate_global)"
args["flags"] = "JSCLASS_IS_GLOBAL | JSCLASS_DOM_GLOBAL"
args["slots"] = "JSCLASS_GLOBAL_SLOT_COUNT + 1"
- args["resolveHook"] = "Some(js::jsapi::JS_ResolveStandardClass)"
+ args["resolveHook"] = "Some(resolve_global)"
args["traceHook"] = "js::jsapi::JS_GlobalObjectTraceHook"
elif self.descriptor.weakReferenceable:
args["slots"] = "2"
@@ -2280,11 +2280,8 @@ JS_SetPrototype(cx, obj.handle(), proto.handle());
%(copyUnforgeable)s
(*raw).init_reflector(obj.ptr);
-let ret = Root::from_ref(&*raw);
-
-RegisterBindings::Register(cx, obj.handle());
-
-ret""" % {'copyUnforgeable': unforgeable, 'createObject': create})
+Root::from_ref(&*raw)\
+""" % {'copyUnforgeable': unforgeable, 'createObject': create})
class CGIDLInterface(CGThing):
@@ -5447,12 +5444,12 @@ class CGBindingRoot(CGThing):
'dom::bindings::utils::{DOMClass, DOMJSClass}',
'dom::bindings::utils::{DOM_PROTO_UNFORGEABLE_HOLDER_SLOT, JSCLASS_DOM_GLOBAL}',
'dom::bindings::utils::{ProtoOrIfaceArray, create_dom_global}',
- 'dom::bindings::utils::{finalize_global, find_enum_string_index, generic_getter}',
- 'dom::bindings::utils::{generic_lenient_getter, generic_lenient_setter}',
+ 'dom::bindings::utils::{enumerate_global, finalize_global, find_enum_string_index}',
+ 'dom::bindings::utils::{generic_getter, generic_lenient_getter, generic_lenient_setter}',
'dom::bindings::utils::{generic_method, generic_setter, get_array_index_from_id}',
'dom::bindings::utils::{get_dictionary_property, get_property_on_prototype}',
'dom::bindings::utils::{get_proto_or_iface_array, has_property_on_prototype}',
- 'dom::bindings::utils::{is_platform_object, set_dictionary_property}',
+ 'dom::bindings::utils::{is_platform_object, resolve_global, set_dictionary_property}',
'dom::bindings::utils::{throwing_constructor, trace_global}',
'dom::bindings::trace::{JSTraceable, RootedTraceable}',
'dom::bindings::callback::{CallbackContainer,CallbackInterface,CallbackFunction}',
@@ -6096,6 +6093,37 @@ class GlobalGenRoots():
"""
@staticmethod
+ def InterfaceObjectMap(config):
+ mods = [
+ "dom::bindings::codegen",
+ "js::jsapi::{HandleObject, JSContext}",
+ "phf",
+ ]
+ imports = CGList([CGGeneric("use %s;" % mod) for mod in mods], "\n")
+
+ pairs = []
+ for d in config.getDescriptors(hasInterfaceObject=True):
+ binding = toBindingNamespace(d.name)
+ pairs.append((d.name, binding))
+ for ctor in d.interface.namedConstructors:
+ pairs.append((ctor.identifier.name, binding))
+ pairs.sort(key=operator.itemgetter(0))
+ mappings = [
+ CGGeneric('b"%s" => codegen::Bindings::%s::DefineDOMInterface as fn(_, _),' % pair)
+ for pair in pairs
+ ]
+ mapType = "phf::Map<&'static [u8], fn(*mut JSContext, HandleObject)>"
+ phf = CGWrapper(
+ CGIndenter(CGList(mappings, "\n")),
+ pre="pub static MAP: %s = phf_map! {\n" % mapType,
+ post="\n};\n")
+
+ return CGList([
+ CGGeneric(AUTOGENERATED_WARNING_COMMENT),
+ CGList([imports, phf], "\n\n")
+ ])
+
+ @staticmethod
def PrototypeList(config):
# Prototype ID enum.
interfaces = config.getDescriptors(isCallback=False)
diff --git a/components/script/dom/bindings/codegen/GlobalGen.py b/components/script/dom/bindings/codegen/GlobalGen.py
index f4210331e0e..72a2faa71e4 100644
--- a/components/script/dom/bindings/codegen/GlobalGen.py
+++ b/components/script/dom/bindings/codegen/GlobalGen.py
@@ -62,6 +62,7 @@ def main():
to_generate = [
('PrototypeList', 'PrototypeList.rs'),
('RegisterBindings', 'RegisterBindings.rs'),
+ ('InterfaceObjectMap', 'InterfaceObjectMap.rs'),
('InterfaceTypes', 'InterfaceTypes.rs'),
('InheritTypes', 'InheritTypes.rs'),
('Bindings', os.path.join('Bindings', 'mod.rs')),