diff options
author | Samson <16504129+sagudev@users.noreply.github.com> | 2023-10-04 13:29:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-04 11:29:54 +0000 |
commit | 8436002383fc17a0572e02aa5a1409505bb10e91 (patch) | |
tree | 4090d4eb0c7490d24a429475bd3807b2208978fb | |
parent | a31e2ea57627bf5cdf8de81c6646d4f2fe25092b (diff) | |
download | servo-8436002383fc17a0572e02aa5a1409505bb10e91.tar.gz servo-8436002383fc17a0572e02aa5a1409505bb10e91.zip |
Support Namespace const in webidl (#30492)
* Add TestNS with const
* Implement namespace const in codegen
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 19 | ||||
-rw-r--r-- | components/script/dom/bindings/namespace.rs | 4 | ||||
-rw-r--r-- | components/script/dom/mod.rs | 1 | ||||
-rw-r--r-- | components/script/dom/testns.rs | 7 | ||||
-rw-r--r-- | components/script/dom/webidls/TestBinding.webidl | 6 | ||||
-rw-r--r-- | tests/wpt/mozilla/meta-legacy-layout/mozilla/ns.any.js.ini | 7 | ||||
-rw-r--r-- | tests/wpt/mozilla/meta/MANIFEST.json | 25 | ||||
-rw-r--r-- | tests/wpt/mozilla/meta/mozilla/ns.any.js.ini | 7 | ||||
-rw-r--r-- | tests/wpt/mozilla/tests/mozilla/ns.any.js | 6 |
9 files changed, 74 insertions, 8 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index eff03384447..471c152040b 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -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("""\ diff --git a/components/script/dom/bindings/namespace.rs b/components/script/dom/bindings/namespace.rs index e6c730907a5..d60deefdd89 100644 --- a/components/script/dom/bindings/namespace.rs +++ b/components/script/dom/bindings/namespace.rs @@ -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()); } diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index 2d11d7bf955..681f8e0ef4b 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -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; diff --git a/components/script/dom/testns.rs b/components/script/dom/testns.rs new file mode 100644 index 00000000000..e6a3574449b --- /dev/null +++ b/components/script/dom/testns.rs @@ -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(()); diff --git a/components/script/dom/webidls/TestBinding.webidl b/components/script/dom/webidls/TestBinding.webidl index 7b105f238ab..4552a6e002a 100644 --- a/components/script/dom/webidls/TestBinding.webidl +++ b/components/script/dom/webidls/TestBinding.webidl @@ -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; +}; diff --git a/tests/wpt/mozilla/meta-legacy-layout/mozilla/ns.any.js.ini b/tests/wpt/mozilla/meta-legacy-layout/mozilla/ns.any.js.ini new file mode 100644 index 00000000000..1028c1162dd --- /dev/null +++ b/tests/wpt/mozilla/meta-legacy-layout/mozilla/ns.any.js.ini @@ -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] diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index db7900cf84b..348218ec20a 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -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": [ "d22ae59c689daf77ccda9fa38979413658778dcb", [ diff --git a/tests/wpt/mozilla/meta/mozilla/ns.any.js.ini b/tests/wpt/mozilla/meta/mozilla/ns.any.js.ini new file mode 100644 index 00000000000..1028c1162dd --- /dev/null +++ b/tests/wpt/mozilla/meta/mozilla/ns.any.js.ini @@ -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] diff --git a/tests/wpt/mozilla/tests/mozilla/ns.any.js b/tests/wpt/mozilla/tests/mozilla/ns.any.js new file mode 100644 index 00000000000..05087872b02 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/ns.any.js @@ -0,0 +1,6 @@ +// META: title=Namespace bindings + +test(function () { + assert_equals(TestNS.ONE, 1); + assert_equals(TestNS.TWO, 2); +}, "Namespace constants"); |