mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +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()
|
methods = self.properties.static_methods.variableName()
|
||||||
else:
|
else:
|
||||||
methods = "&[]"
|
methods = "&[]"
|
||||||
return CGGeneric("""\
|
if self.descriptor.interface.hasConstants():
|
||||||
rooted!(in(*cx) let proto = %(proto)s);
|
constants = "sConstants"
|
||||||
|
else:
|
||||||
|
constants = "&[]"
|
||||||
|
id = MakeNativeName(name)
|
||||||
|
return CGGeneric(f"""\
|
||||||
|
rooted!(in(*cx) let proto = {proto});
|
||||||
assert!(!proto.is_null());
|
assert!(!proto.is_null());
|
||||||
rooted!(in(*cx) let mut namespace = ptr::null_mut::<JSObject>());
|
rooted!(in(*cx) let mut namespace = ptr::null_mut::<JSObject>());
|
||||||
create_namespace_object(cx, global, proto.handle(), &NAMESPACE_OBJECT_CLASS,
|
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!(!namespace.is_null());
|
||||||
assert!((*cache)[PrototypeList::Constructor::%(id)s as usize].is_null());
|
assert!((*cache)[PrototypeList::Constructor::{id} as usize].is_null());
|
||||||
(*cache)[PrototypeList::Constructor::%(id)s as usize] = namespace.get();
|
(*cache)[PrototypeList::Constructor::{id} as usize] = namespace.get();
|
||||||
<*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::Constructor::%(id)s as isize),
|
<*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::Constructor::{id} as isize),
|
||||||
ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
namespace.get());
|
namespace.get());
|
||||||
""" % {"id": MakeNativeName(name), "methods": methods, "name": str_to_const_array(name), "proto": proto})
|
""")
|
||||||
if self.descriptor.interface.isCallback():
|
if self.descriptor.interface.isCallback():
|
||||||
assert not self.descriptor.interface.ctor() and self.descriptor.interface.hasConstants()
|
assert not self.descriptor.interface.ctor() and self.descriptor.interface.hasConstants()
|
||||||
return CGGeneric("""\
|
return CGGeneric("""\
|
||||||
|
|
|
@ -9,6 +9,7 @@ use std::ptr;
|
||||||
use js::jsapi::{JSClass, JSFunctionSpec};
|
use js::jsapi::{JSClass, JSFunctionSpec};
|
||||||
use js::rust::{HandleObject, MutableHandleObject};
|
use js::rust::{HandleObject, MutableHandleObject};
|
||||||
|
|
||||||
|
use super::constant::ConstantSpec;
|
||||||
use crate::dom::bindings::guard::Guard;
|
use crate::dom::bindings::guard::Guard;
|
||||||
use crate::dom::bindings::interface::{create_object, define_on_global_object};
|
use crate::dom::bindings::interface::{create_object, define_on_global_object};
|
||||||
use crate::script_runtime::JSContext;
|
use crate::script_runtime::JSContext;
|
||||||
|
@ -40,9 +41,10 @@ pub fn create_namespace_object(
|
||||||
proto: HandleObject,
|
proto: HandleObject,
|
||||||
class: &'static NamespaceObjectClass,
|
class: &'static NamespaceObjectClass,
|
||||||
methods: &[Guard<&'static [JSFunctionSpec]>],
|
methods: &[Guard<&'static [JSFunctionSpec]>],
|
||||||
|
constants: &[Guard<&'static [ConstantSpec]>],
|
||||||
name: &[u8],
|
name: &[u8],
|
||||||
rval: MutableHandleObject,
|
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());
|
define_on_global_object(cx, global, name, rval.handle());
|
||||||
}
|
}
|
||||||
|
|
|
@ -537,6 +537,7 @@ pub mod testbindingmaplike;
|
||||||
pub mod testbindingpairiterable;
|
pub mod testbindingpairiterable;
|
||||||
pub mod testbindingproxy;
|
pub mod testbindingproxy;
|
||||||
pub mod testbindingsetlike;
|
pub mod testbindingsetlike;
|
||||||
|
pub mod testns;
|
||||||
pub mod testrunner;
|
pub mod testrunner;
|
||||||
pub mod testworklet;
|
pub mod testworklet;
|
||||||
pub mod testworkletglobalscope;
|
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"]
|
[Pref="dom.testable_crash.enabled"]
|
||||||
undefined crashHard();
|
undefined crashHard();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[Exposed=(Window,Worker), Pref="dom.testbinding.enabled"]
|
||||||
|
namespace TestNS {
|
||||||
|
const unsigned long ONE = 1;
|
||||||
|
const unsigned long TWO = 0x2;
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
[ns.any.html]
|
||||||
|
type: testharness
|
||||||
|
prefs: [dom.testbinding.enabled:true]
|
||||||
|
|
||||||
|
[ns.any.worker.html]
|
||||||
|
type: testharness
|
||||||
|
prefs: [dom.testbinding.enabled:true]
|
|
@ -13639,6 +13639,31 @@
|
||||||
{}
|
{}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
"ns.any.js": [
|
||||||
|
"05087872b02abdeeb48c21ee9ec037b3a1483c03",
|
||||||
|
[
|
||||||
|
"mozilla/ns.any.html",
|
||||||
|
{
|
||||||
|
"script_metadata": [
|
||||||
|
[
|
||||||
|
"title",
|
||||||
|
"Namespace bindings"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"mozilla/ns.any.worker.html",
|
||||||
|
{
|
||||||
|
"script_metadata": [
|
||||||
|
[
|
||||||
|
"title",
|
||||||
|
"Namespace bindings"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
"out-of-order-stylesheet-loads-and-imports.html": [
|
"out-of-order-stylesheet-loads-and-imports.html": [
|
||||||
"d22ae59c689daf77ccda9fa38979413658778dcb",
|
"d22ae59c689daf77ccda9fa38979413658778dcb",
|
||||||
[
|
[
|
||||||
|
|
7
tests/wpt/mozilla/meta/mozilla/ns.any.js.ini
Normal file
7
tests/wpt/mozilla/meta/mozilla/ns.any.js.ini
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
[ns.any.html]
|
||||||
|
type: testharness
|
||||||
|
prefs: [dom.testbinding.enabled:true]
|
||||||
|
|
||||||
|
[ns.any.worker.html]
|
||||||
|
type: testharness
|
||||||
|
prefs: [dom.testbinding.enabled:true]
|
6
tests/wpt/mozilla/tests/mozilla/ns.any.js
Normal file
6
tests/wpt/mozilla/tests/mozilla/ns.any.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
// META: title=Namespace bindings
|
||||||
|
|
||||||
|
test(function () {
|
||||||
|
assert_equals(TestNS.ONE, 1);
|
||||||
|
assert_equals(TestNS.TWO, 2);
|
||||||
|
}, "Namespace constants");
|
Loading…
Add table
Add a link
Reference in a new issue