From cadc84319a516de6662e1625ba618af59b568b1a Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 27 Aug 2014 12:20:22 +0200 Subject: [PATCH] Introduce the NativePropertyHooks struct. This will be required for the cross-origin wrapper work. --- .../dom/bindings/codegen/CodegenRust.py | 34 +++++++++++++++++-- src/components/script/dom/bindings/utils.rs | 14 +++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 27e7e344dfa..e931335dcd0 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -131,6 +131,34 @@ class CGThing(): """Produce code for a Rust file.""" assert(False) # Override me! + +class CGNativePropertyHooks(CGThing): + """ + Generate a NativePropertyHooks for a given descriptor + """ + def __init__(self, descriptor, properties): + CGThing.__init__(self) + self.descriptor = descriptor + self.properties = properties + + def define(self): + parent = self.descriptor.interface.parent + if parent: + parentHooks = "Some(&::dom::bindings::codegen::Bindings::%sBinding::sNativePropertyHooks)" % parent.identifier.name + else: + parentHooks = "None" + + substitutions = { + "parentHooks": parentHooks + } + + return string.Template( + "pub static sNativePropertyHooks: NativePropertyHooks = NativePropertyHooks {\n" + " native_properties: &sNativeProperties,\n" + " proto_hooks: ${parentHooks},\n" + "};\n").substitute(substitutions) + + class CGMethodCall(CGThing): """ A class to generate selection of a method signature from a set of @@ -1386,7 +1414,8 @@ def DOMClass(descriptor): protoList.extend(['PrototypeList::id::IDCount'] * (descriptor.config.maxProtoChainLength - len(protoList))) prototypeChainString = ', '.join(protoList) return """DOMClass { - interface_chain: [ %s ] + interface_chain: [ %s ], + native_hooks: &sNativePropertyHooks, }""" % prototypeChainString class CGDOMJSClass(CGThing): @@ -4119,6 +4148,7 @@ class CGDescriptor(CGThing): properties = PropertyArrays(descriptor) cgThings.append(CGGeneric(str(properties))) cgThings.append(CGNativeProperties(descriptor, properties)) + cgThings.append(CGNativePropertyHooks(descriptor, properties)) cgThings.append(CGCreateInterfaceObjectsMethod(descriptor, properties)) cgThings.append(CGNamespace.build([descriptor.name + "Constants"], @@ -4499,7 +4529,7 @@ class CGBindingRoot(CGThing): 'dom::bindings::utils::{ThrowingConstructor, unwrap, unwrap_jsmanaged}', 'dom::bindings::utils::VoidVal', 'dom::bindings::utils::get_dictionary_property', - 'dom::bindings::utils::NativeProperties', + 'dom::bindings::utils::{NativeProperties, NativePropertyHooks}', 'dom::bindings::trace::JSTraceable', 'dom::bindings::callback::{CallbackContainer,CallbackInterface,CallbackFunction}', 'dom::bindings::callback::{CallSetup,ExceptionHandling}', diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index 525a6207a09..7e63c8f7f80 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -222,11 +222,23 @@ pub struct ConstantSpec { pub value: ConstantVal } +/// Helper structure for cross-origin wrappers for DOM binding objects. +pub struct NativePropertyHooks { + /// The property arrays for this interface. + pub native_properties: &'static NativeProperties, + + /// The NativePropertyHooks instance for the parent interface, if any. + pub proto_hooks: Option<&'static NativePropertyHooks>, +} + /// The struct that holds inheritance information for DOM object reflectors. pub struct DOMClass { /// A list of interfaces that this object implements, in order of decreasing /// derivedness. - pub interface_chain: [PrototypeList::id::ID, ..MAX_PROTO_CHAIN_LENGTH] + pub interface_chain: [PrototypeList::id::ID, ..MAX_PROTO_CHAIN_LENGTH], + + /// The NativePropertyHooks for the interface associated with this class. + pub native_hooks: &'static NativePropertyHooks, } /// The JSClass used for DOM object reflectors.