aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py46
-rw-r--r--components/script/dom/bindings/interface.rs24
2 files changed, 51 insertions, 19 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 8fc5ca34dee..9651d815c9b 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -2498,7 +2498,7 @@ class CGWrapGlobalMethod(CGAbstractMethod):
"""
Class that generates the FooBinding::Wrap function for global interfaces.
"""
- def __init__(self, descriptor):
+ def __init__(self, descriptor, properties):
assert not descriptor.interface.isCallback()
assert descriptor.isGlobal()
args = [Argument('*mut JSContext', 'cx'),
@@ -2506,9 +2506,22 @@ class CGWrapGlobalMethod(CGAbstractMethod):
retval = 'Root<%s>' % descriptor.concreteType
CGAbstractMethod.__init__(self, descriptor, 'Wrap', retval, args,
pub=True, unsafe=True)
+ self.properties = properties
def definition_body(self):
- unforgeable = CopyUnforgeablePropertiesToInstance(self.descriptor)
+ values = {
+ "unforgeable": CopyUnforgeablePropertiesToInstance(self.descriptor)
+ }
+
+ pairs = [
+ ("define_guarded_properties", self.properties.attrs),
+ ("define_guarded_methods", self.properties.methods),
+ ("define_guarded_constants", self.properties.consts)
+ ]
+ members = ["%s(cx, obj.handle(), %s);" % (function, array.variableName())
+ for (function, array) in pairs if array.length() > 0]
+ values["members"] = "\n".join(members)
+
return CGGeneric("""\
let raw = Box::into_raw(object);
let _rt = RootedTraceable::new(&*raw);
@@ -2529,10 +2542,12 @@ rooted!(in(cx) let mut proto = ptr::null_mut());
GetProtoObject(cx, obj.handle(), proto.handle_mut());
JS_SplicePrototype(cx, obj.handle(), proto.handle());
-%(copyUnforgeable)s
+%(members)s
+
+%(unforgeable)s
Root::from_ref(&*raw)\
-""" % {'copyUnforgeable': unforgeable})
+""" % values)
class CGIDLInterface(CGThing):
@@ -2676,6 +2691,18 @@ assert!(!prototype_proto.is_null());""" % getPrototypeProto)]
else:
properties[arrayName] = "&[]"
+ if self.descriptor.isGlobal():
+ assert not self.haveUnscopables
+ proto_properties = {
+ "attrs": "&[]",
+ "consts": "&[]",
+ "id": name,
+ "methods": "&[]",
+ "unscopables": "&[]",
+ }
+ else:
+ proto_properties = properties
+
code.append(CGGeneric("""
rooted!(in(cx) let mut prototype = ptr::null_mut());
create_interface_prototype_object(cx,
@@ -2692,7 +2719,7 @@ assert!((*cache)[PrototypeList::ID::%(id)s as usize].is_null());
<*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::ID::%(id)s as isize),
ptr::null_mut(),
prototype.get());
-""" % properties))
+""" % proto_properties))
if self.descriptor.interface.hasInterfaceObject():
properties["name"] = str_to_const_array(name)
@@ -5299,8 +5326,8 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'dom::bindings::interface::{NonCallbackInterfaceObjectClass, NonNullJSNative}',
'dom::bindings::interface::{create_callback_interface_object, create_global_object}',
'dom::bindings::interface::{create_interface_prototype_object, create_named_constructors}',
- 'dom::bindings::interface::{create_noncallback_interface_object, define_guarded_methods}',
- 'dom::bindings::interface::{define_guarded_properties, is_exposed_in}',
+ 'dom::bindings::interface::{create_noncallback_interface_object, define_guarded_constants}',
+ 'dom::bindings::interface::{define_guarded_methods, define_guarded_properties, is_exposed_in}',
'dom::bindings::interface::ConstantVal::{IntVal, UintVal}',
'dom::bindings::iterable::{IteratorType, Iterable}',
'dom::bindings::js::{JS, Root, RootedReference}',
@@ -5450,6 +5477,8 @@ class CGDescriptor(CGThing):
if descriptor.proxy:
cgThings.append(CGDefineProxyHandler(descriptor))
+ properties = PropertyArrays(descriptor)
+
if descriptor.concrete:
if descriptor.proxy:
# cgThings.append(CGProxyIsProxy(descriptor))
@@ -5480,7 +5509,7 @@ class CGDescriptor(CGThing):
pass
if descriptor.isGlobal():
- cgThings.append(CGWrapGlobalMethod(descriptor))
+ cgThings.append(CGWrapGlobalMethod(descriptor, properties))
else:
cgThings.append(CGWrapMethod(descriptor))
reexports.append('Wrap')
@@ -5505,7 +5534,6 @@ class CGDescriptor(CGThing):
if descriptor.weakReferenceable:
cgThings.append(CGWeakReferenceableTrait(descriptor))
- properties = PropertyArrays(descriptor)
cgThings.append(CGGeneric(str(properties)))
cgThings.append(CGCreateInterfaceObjectsMethod(descriptor, properties, haveUnscopables))
diff --git a/components/script/dom/bindings/interface.rs b/components/script/dom/bindings/interface.rs
index d92510754d5..1e21c3db651 100644
--- a/components/script/dom/bindings/interface.rs
+++ b/components/script/dom/bindings/interface.rs
@@ -257,11 +257,7 @@ pub unsafe fn create_callback_interface_object(
assert!(!constants.is_empty());
rval.set(JS_NewObject(cx, ptr::null()));
assert!(!rval.ptr.is_null());
- for guard in constants {
- if let Some(specs) = guard.expose(cx, rval.handle()) {
- define_constants(cx, rval.handle(), specs);
- }
- }
+ define_guarded_constants(cx, rval.handle(), constants);
define_name(cx, rval.handle(), name);
define_on_global_object(cx, global, name, rval.handle());
}
@@ -421,11 +417,7 @@ unsafe fn create_object(
assert!(!rval.ptr.is_null());
define_guarded_methods(cx, rval.handle(), methods);
define_guarded_properties(cx, rval.handle(), properties);
- for guard in constants {
- if let Some(specs) = guard.expose(cx, rval.handle()) {
- define_constants(cx, rval.handle(), specs);
- }
- }
+ define_guarded_constants(cx, rval.handle(), constants);
}
unsafe fn create_unscopable_object(
@@ -444,6 +436,18 @@ unsafe fn create_unscopable_object(
}
}
+/// Conditionally define constants on an object.
+pub unsafe fn define_guarded_constants(
+ cx: *mut JSContext,
+ obj: HandleObject,
+ constants: &[Guard<&[ConstantSpec]>]) {
+ for guard in constants {
+ if let Some(specs) = guard.expose(cx, obj) {
+ define_constants(cx, obj, specs);
+ }
+ }
+}
+
/// Conditionally define methods on an object.
pub unsafe fn define_guarded_methods(
cx: *mut JSContext,