mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Support Namespace const in webidl (#30492)
* Add TestNS with const * Implement namespace const in codegen
This commit is contained in:
parent
a31e2ea576
commit
8436002383
9 changed files with 74 additions and 8 deletions
|
@ -3281,19 +3281,24 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
|
|||
methods = self.properties.static_methods.variableName()
|
||||
else:
|
||||
methods = "&[]"
|
||||
return CGGeneric("""\
|
||||
rooted!(in(*cx) let proto = %(proto)s);
|
||||
if self.descriptor.interface.hasConstants():
|
||||
constants = "sConstants"
|
||||
else:
|
||||
constants = "&[]"
|
||||
id = MakeNativeName(name)
|
||||
return CGGeneric(f"""\
|
||||
rooted!(in(*cx) let proto = {proto});
|
||||
assert!(!proto.is_null());
|
||||
rooted!(in(*cx) let mut namespace = ptr::null_mut::<JSObject>());
|
||||
create_namespace_object(cx, global, proto.handle(), &NAMESPACE_OBJECT_CLASS,
|
||||
%(methods)s, %(name)s, namespace.handle_mut());
|
||||
{methods}, {constants}, {str_to_const_array(name)}, namespace.handle_mut());
|
||||
assert!(!namespace.is_null());
|
||||
assert!((*cache)[PrototypeList::Constructor::%(id)s as usize].is_null());
|
||||
(*cache)[PrototypeList::Constructor::%(id)s as usize] = namespace.get();
|
||||
<*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::Constructor::%(id)s as isize),
|
||||
assert!((*cache)[PrototypeList::Constructor::{id} as usize].is_null());
|
||||
(*cache)[PrototypeList::Constructor::{id} as usize] = namespace.get();
|
||||
<*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::Constructor::{id} as isize),
|
||||
ptr::null_mut(),
|
||||
namespace.get());
|
||||
""" % {"id": MakeNativeName(name), "methods": methods, "name": str_to_const_array(name), "proto": proto})
|
||||
""")
|
||||
if self.descriptor.interface.isCallback():
|
||||
assert not self.descriptor.interface.ctor() and self.descriptor.interface.hasConstants()
|
||||
return CGGeneric("""\
|
||||
|
|
|
@ -9,6 +9,7 @@ use std::ptr;
|
|||
use js::jsapi::{JSClass, JSFunctionSpec};
|
||||
use js::rust::{HandleObject, MutableHandleObject};
|
||||
|
||||
use super::constant::ConstantSpec;
|
||||
use crate::dom::bindings::guard::Guard;
|
||||
use crate::dom::bindings::interface::{create_object, define_on_global_object};
|
||||
use crate::script_runtime::JSContext;
|
||||
|
@ -40,9 +41,10 @@ pub fn create_namespace_object(
|
|||
proto: HandleObject,
|
||||
class: &'static NamespaceObjectClass,
|
||||
methods: &[Guard<&'static [JSFunctionSpec]>],
|
||||
constants: &[Guard<&'static [ConstantSpec]>],
|
||||
name: &[u8],
|
||||
rval: MutableHandleObject,
|
||||
) {
|
||||
create_object(cx, global, proto, &class.0, methods, &[], &[], rval);
|
||||
create_object(cx, global, proto, &class.0, methods, &[], constants, rval);
|
||||
define_on_global_object(cx, global, name, rval.handle());
|
||||
}
|
||||
|
|
|
@ -537,6 +537,7 @@ pub mod testbindingmaplike;
|
|||
pub mod testbindingpairiterable;
|
||||
pub mod testbindingproxy;
|
||||
pub mod testbindingsetlike;
|
||||
pub mod testns;
|
||||
pub mod testrunner;
|
||||
pub mod testworklet;
|
||||
pub mod testworkletglobalscope;
|
||||
|
|
7
components/script/dom/testns.rs
Normal file
7
components/script/dom/testns.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// check-tidy: no specs after this line
|
||||
|
||||
pub struct TestNS(());
|
|
@ -599,3 +599,9 @@ partial interface TestBinding {
|
|||
[Pref="dom.testable_crash.enabled"]
|
||||
undefined crashHard();
|
||||
};
|
||||
|
||||
[Exposed=(Window,Worker), Pref="dom.testbinding.enabled"]
|
||||
namespace TestNS {
|
||||
const unsigned long ONE = 1;
|
||||
const unsigned long TWO = 0x2;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue