aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/CodegenRust.py
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2016-04-23 14:02:55 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2016-04-25 11:44:59 +0200
commit4c2ca7a8c9244746ac168942651b0df6b6476626 (patch)
treee2d181c9dd1cf1c799ad69ad76aafe4c2996e354 /components/script/dom/bindings/codegen/CodegenRust.py
parenta45f117838d542ceb8f3557321dc410d4fbab3e5 (diff)
downloadservo-4c2ca7a8c9244746ac168942651b0df6b6476626.tar.gz
servo-4c2ca7a8c9244746ac168942651b0df6b6476626.zip
Refactor the `call` hook on non-callback interface objects (fixes #10744)
It's now set through the intermediate InterfaceConstructorBehavior structure, which lets us improve the abstraction around NonCallbackInterfaceObjectClass a bit better. When the interface's constructor is supposed to always throw, the error for calling `Foo()` without new is "Illegal constructor.". when the interface actually defines an interface, the error is instead "This constructor needs to be called with `new`.".
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 7a463e6dd7b..1ef2e0a4eb9 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -1897,20 +1897,23 @@ class CGInterfaceObjectJSClass(CGThing):
def define(self):
if self.descriptor.interface.ctor():
- constructor = CONSTRUCT_HOOK_NAME
+ constructorBehavior = "InterfaceConstructorBehavior::call(%s)" % CONSTRUCT_HOOK_NAME
else:
- constructor = "throwing_constructor"
+ constructorBehavior = "InterfaceConstructorBehavior::throw()"
name = self.descriptor.interface.identifier.name
args = {
- "constructor": constructor,
+ "constructorBehavior": constructorBehavior,
"id": name,
"representation": str_to_const_array("function %s() {\\n [native code]\\n}" % name),
"depth": self.descriptor.prototypeDepth
}
return """\
static InterfaceObjectClass: NonCallbackInterfaceObjectClass = unsafe {
- NonCallbackInterfaceObjectClass::new(%(constructor)s, %(representation)s,
- PrototypeList::ID::%(id)s, %(depth)s)
+ NonCallbackInterfaceObjectClass::new(
+ %(constructorBehavior)s,
+ %(representation)s,
+ PrototypeList::ID::%(id)s,
+ %(depth)s)
};
""" % args
@@ -2450,10 +2453,8 @@ if <*mut JSObject>::needs_post_barrier(prototype.ptr) {
if self.descriptor.interface.hasInterfaceObject():
properties["name"] = str_to_const_array(name)
if self.descriptor.interface.ctor():
- properties["constructor"] = CONSTRUCT_HOOK_NAME
properties["length"] = methodLength(self.descriptor.interface.ctor())
else:
- properties["constructor"] = "throwing_constructor"
properties["length"] = 0
if self.descriptor.interface.parent:
parentName = toBindingNamespace(self.descriptor.getParentName())
@@ -5401,9 +5402,9 @@ class CGBindingRoot(CGThing):
'js::rust::{GCMethods, define_methods, define_properties}',
'dom::bindings',
'dom::bindings::global::{GlobalRef, global_root_from_object, global_root_from_reflector}',
- 'dom::bindings::interface::{NonCallbackInterfaceObjectClass, create_callback_interface_object}',
- 'dom::bindings::interface::{create_interface_prototype_object, create_named_constructors}',
- 'dom::bindings::interface::{create_noncallback_interface_object}',
+ 'dom::bindings::interface::{InterfaceConstructorBehavior, NonCallbackInterfaceObjectClass}',
+ 'dom::bindings::interface::{create_callback_interface_object, create_interface_prototype_object}',
+ 'dom::bindings::interface::{create_named_constructors, create_noncallback_interface_object}',
'dom::bindings::interface::{ConstantSpec, NonNullJSNative}',
'dom::bindings::interface::ConstantVal::{IntVal, UintVal}',
'dom::bindings::js::{JS, Root, RootedReference}',
@@ -5417,8 +5418,7 @@ class CGBindingRoot(CGThing):
'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, resolve_global, set_dictionary_property}',
- 'dom::bindings::utils::{throwing_constructor, trace_global}',
+ 'dom::bindings::utils::{is_platform_object, resolve_global, set_dictionary_property, trace_global}',
'dom::bindings::trace::{JSTraceable, RootedTraceable}',
'dom::bindings::callback::{CallbackContainer,CallbackInterface,CallbackFunction}',
'dom::bindings::callback::{CallSetup,ExceptionHandling}',