Commit graph

248 commits

Author SHA1 Message Date
Josh Matthews
7ed6faa56c Update to SpiderMonkey 137.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-05-22 00:48:46 -04:00
Josh Matthews
76ee127af8
Eagerly define interfaces on non-Window globals (#36604)
These changes make us match Gecko's setup for how Window and non-Window
globals are initialized. Since Window globals are much more common than
Worker globals, using lazy interface definitions can be a useful memory
optimization at the expense of increased complexity for property
lookups.

Also adds the MayResolve hook for all globals, which is an optimization
for the JIT to avoid calling resolve hooks unnecessarily.

Testing: Existing test coverage on global interfaces should suffice.

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-04-21 03:32:21 +00:00
Josh Matthews
30390f8c5e
Fix crash when enumerating properties of global object (#36491)
These changes make our implementation of the enumeration hook for
globals [match
Gecko's](https://searchfox.org/mozilla-central/rev/1f65969e57c757146e3e548614b49d3a4168eeb8/dom/base/nsGlobalWindowInner.cpp#3297),
fixing an assertion failure that occurred in the previous
implementation.

Our enumeration hook is supposed to fill a vector with names of
properties on the global object without modifying the global in any way;
instead we were defining all of the missing webidl interfaces. We now do
much less work and crash less.

Testing: New crashtest based on manual testcase.
Fixes: #34686

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-04-17 03:32:53 +00:00
Josh Matthews
b4079b3ff3
Move generated bindings to script_bindings (#36323)
This is the final step of #1799, where the majority of the generated
code for the JS bindings is now compiled as part of the script_bindings
build step. The remaining pieces in script must live there because they
refer to concrete DOM types; all code in script_bindings is generic over
the
[DomTypes](https://doc.servo.org/script/dom/bindings/codegen/DomTypes/trait.DomTypes.html)
trait.

My testing with incremental builds shows me a 12 second reduction in
build times on my 2024 M4 Macbook Pro when modifying code in the script
crate after these changes. Before this PR those changes took 20 seconds
to rebuild Servo, and now they take 8 seconds.

Testing: Existing WPT tests ensure no regressions.
Fixes: #1799

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-04-04 06:45:08 +00:00
Josh Matthews
b445053a7c
More miscellaneous script splitting changes (#36220)
* script: Move HasParent to script_bindings and update imports for InheritTypes.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make principal creation generic over DOM interface.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Move a bunch of proxy-related code to script_bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make some proxy-related code generic over the DOM interface.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Move DomSlice to script_bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Move some utility bindings code to script_bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make enumerating and resolving globals generic over the DOM interface.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make realm helpers generic over the DOM interface.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Move implementations on concrete DOM types to concrete bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make additional codegen helpers generic over the DOM interface.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make iterator creation generic over the DOM interface.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make reporting an exception a generic operation.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Move AsCCharPtrPtr to script_bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Formatting.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Address clippy warnings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-03-30 11:06:30 +00:00
Josh Matthews
c30ad5a30e
Miscellaneous script splitting preparation changes (#36216)
* script: Move num module to script_bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make JS reflector creation generic over DOM trait.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Move bindings-specific lock to script_bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Move DOM proto array code to script_bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Move finalizer implementations to script_bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Move some error routines to script_bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Move some DOM interface conversion routines to script_bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make is_array_like generic over DOM trait.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Use generic interfaces for conditional exposure functions.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Move a bunch of routines used by codegen to script_bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Formatting.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Fix clippy warnings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-03-29 08:11:27 +00:00
Michael Rees
09041e77a0
Fix check in get_array_index_from_id to return early on ASCII char (#36136)
* fix: wrong ascii check in get_array_index_from_id

Signed-off-by: Michael Rees <mrees@noeontheend.com>

* Update WPT expectations

Signed-off-by: Michael Rees <mrees@noeontheend.com>

---------

Signed-off-by: Michael Rees <mrees@noeontheend.com>
2025-03-25 19:27:38 +00:00
Arya Nair
80fc64d063
feat: add CanGc argument in get_dictionary_property (#36156)
* feat: add CanGc argument in get_dictionary_property

Signed-off-by: Arya Nair <aryaajitnair@gmail.com>

* feat: add CanGc argument in get_dictionary_property

Signed-off-by: Arya Nair <aryaajitnair@gmail.com>

---------

Signed-off-by: Arya Nair <aryaajitnair@gmail.com>
2025-03-25 19:24:47 +00:00
Greg Morenz
4ecf0909e5
Use explicit reborrows with mozjs::MutableHandle (#35892)
* Explicitly reborrow MutableHandles

Signed-off-by: Greg Morenz <greg-morenz@droid.cafe>

* Unify jsapi_wrappers

Signed-off-by: Greg Morenz <greg-morenz@droid.cafe>

* Format mozjs changes

Signed-off-by: Greg Morenz <greg-morenz@droid.cafe>

* Update mozjs version

Signed-off-by: Greg Morenz <greg-morenz@droid.cafe>

---------

Signed-off-by: Greg Morenz <greg-morenz@droid.cafe>
2025-03-23 01:23:52 +00:00
Arya Nair
cb56ac8561
feat: add can_gc argument to to_frozen_array (#36043)
* feat: add can_gc argument to to_frozen_array

Signed-off-by: Arya Nair <aryaajitnair@gmail.com>

* fix: linting issues

Signed-off-by: Arya Nair <aryaajitnair@gmail.com>

* feat: add can_gc in binding.conf

Signed-off-by: Arya Nair <aryaajitnair@gmail.com>

* fix: linting issues

Signed-off-by: Arya Nair <aryaajitnair@gmail.com>

---------

Signed-off-by: Arya Nair <aryaajitnair@gmail.com>
2025-03-19 18:03:09 +00:00
Simon Wülker
3d320fa96a
Update rustfmt to the 2024 style edition (#35764)
* Use 2024 style edition

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Reformat all code

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-03-03 11:26:53 +00:00
Yerkebulan Tulibergenov
31b2f81bc6
refactor: add CanGc as argument to exception_to_promise (#35647)
Signed-off-by: Yerkebulan Tulibergenov <yerkebulan@gmail.com>
2025-02-25 13:21:59 +00:00
Auguste Baum
b0b0289014
refactor: propagate CanGc arguments through callers (#35591)
Signed-off-by: Auguste Baum <auguste.apple@gmail.com>
2025-02-23 00:34:51 +00:00
Josh Matthews
a433b20259
script: Make callbacks generic over DOM interfaces. (#35459)
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-02-21 12:17:11 +00:00
Josh Matthews
1192ae32b0
script: Refer to DOM interfaces with generic types in generated bindings. (#35457)
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-02-21 11:10:00 +00:00
Stephen Muss
3c1cce825d
script: make throw_invalid_this and throw_constructor_without_new safe (#35360)
Signed-off-by: Stephen Muss <stephenmuss@gmail.com>
2025-02-07 13:07:50 +00:00
Josh Matthews
c0cef69108
Move more foundational types to script_bindings (#35280)
* script: Move DOMClass to script_bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Move DOMJSClass and get_dom_class to script_bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Move Castable/DerivedFrom/IDLInterface to script_bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-02-04 10:36:30 +00:00
Josh Matthews
c94d909a86
script: Limit public exports. (#34915)
* script: Restrict reexport visibility of DOM types.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Mass pub->pub(crate) conversion.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Hide existing dead code warnings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Formatting.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Fix clippy warnings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Formatting.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Fix unit tests.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Fix clippy.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* More formatting.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-01-10 08:19:19 +00:00
Josh Matthews
3515b83a95
Create two-phase initialization for generated JS engine bindings (#34366)
* script: Generate a runtime initialization for static JS binding information.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Replace dummy static initializers with OnceLock.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Fix clippy warnings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Only initialize statics for DOM interfaces with interface objects.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Remove one unnecessary Box::leak usage.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Tidy.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Hide thread-unsafe OnceLock usage inside of a wrapper type.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Mark ThreadUnsafeOnceLock::get unsafe.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Simplify ThreadUnsafeOnceLock internals.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2024-12-06 07:34:24 +00:00
Josh Matthews
25a0764a37
Use out parameter for generated methods returning JSVal (#34087)
* Make generated bindings that return a WebIDL `any` value use out parameters.

Returning raw JSVal values makes it easier to create GC hazards in code
that calls these methods. Accepting a MutableHandle argument instead
ensures that the values are rooted by the caller.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Update mozjs.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Fix clippy warnings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2024-11-05 08:29:08 +00:00
chickenleaf
900d13fc2f
frozen array in XRInputSourcesChangeEvent, update to_frozen_array doc (#34100)
* frozen array in XRInputSourcesChangeEvent, update 	o_frozen_array doc

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

* simplified changes

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

* added tests

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

---------

Signed-off-by: L Ashwin B <lashwinib@gmail.com>
2024-11-02 14:27:59 +00:00
Martin Robinson
e70507ca40
tidy: Fix rustdoc warnings and add a tidy check for a common URL issue (#33366)
This change fixes all rustdoc errors and also adds a tidy check for a
very common rustdoc URL issue. Eventually rustdoc warnings should likely
cause the build to fail, but this catches those issues sooner in order
to not waste so much developer time.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-09-08 15:04:19 +00:00
Andriy Sultanov
aadc212b95
jsstring_to_str should accept a NonNull argument for the JS string (#33306)
Instead of asserting the raw pointer is not null, force callers to
produce a NonNull pointer.

Signed-off-by: Andriy Sultanov <sultanovandriy@gmail.com>
2024-09-05 03:25:49 +00:00
Koki Saito
db312319ae
fix: Replace callargs_is_constructing with is_constructing method (#33101)
Signed-off-by: Koki Saito <saitoto828@gmail.com>
Co-authored-by: kokisaito <kosaito@indeed.com>
2024-08-18 01:48:39 +00:00
Samson
68f4b359c5
Add exception to rejection logic in generic_call (#32950)
* exception in JS Promise

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* EXCEPTION_TO_REJECTION on generic_call

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* PromiseRejectionEvent should handle promise as object

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* expectations

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2024-08-06 17:12:31 +00:00
Samson
f3bec0aed3
bindings: Convert certain Exceptions into Promise rejections (#32923)
* Impl promise exception to rejection for methods

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Impl promise exception to rejection for getters

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Impl promise exception to rejection for static methods

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Add tests for exception to rejection

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Expectations

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2024-08-03 12:58:37 +00:00
Erik Hennig
5963695664
fix: Memory leak from CreateProxyWindowHandler (#32773)
* fix: Memory leak from CreateProxyWindowHandler

Signed-off-by: ede1998 <online@erik-hennig.me>

* fix: memory leak in WindowProxy

Signed-off-by: ede1998 <online@erik-hennig.me>

* fix: Memory leak in WindowProxyHandler through static

Signed-off-by: ede1998 <online@erik-hennig.me>

---------

Signed-off-by: ede1998 <online@erik-hennig.me>
2024-08-01 21:16:49 +00:00
Rosemary Ajayi
bd287df0d4
fixed various clippy warnings (#31954) 2024-03-31 19:58:37 +00:00
Ekta Siwach
b0196ad373
clippy: Fix a variety of warnings in components/script/dom (#31894) 2024-03-29 14:43:10 +00:00
Oluwatobi Sofela
bae77671f8
clippy: Fix unnecessary_cast warnings in components/script (#31823)
* clippy: Fix unnecessary cast warnings

* clippy: Replace redundant field names with their shorthand alternatives

* clippy: Delete struct pattern dereferencings
2024-03-22 13:48:03 +00:00
Oluwatobi Sofela
694e86ecff
clippy: Fix dereferencing a tuple pattern warnings (#31811) 2024-03-21 17:04:18 +00:00
eri
8c7e9a15e1
Remove repeated imports from generated code (#31711)
* feat: try to deduplicate imports in codegen

* feat: another attempt

* feat: start testing imports

* feat: clean all global imports

* feat: remove shared imports from CGDescriptor

* feat: remove redundant imports from CGDescriptor

* fix: formatting

* fix: remove libc (base level import)

* feat: roll back named path changes

* feat: last changes and tidy

* experiment: move imports into a separate file

* fix: extra parenthesis

* fix: remove repeated allow statement
2024-03-21 13:38:16 +00:00
Taym Haddadi
9d2c102fa0
Use FLoat32Array in GamepadPose (#31106)
* Use FLoat32Array in GamepadPose

Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>

* Remove unused create_typed_array

Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>

---------

Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>
2024-01-19 04:39:09 +00:00
Samson
aad2dccc9c
Strict import formatting (grouping and granularity) (#30325)
* strict imports formatting

* Reformat all imports
2023-09-11 19:16:54 +00:00
Samson
59d134133f
Use MozTools 4 and update mozjs (#30326)
* Update mozjs

* moztools4 in bootstrap

* no autoconf

* tidy

* switch to servo-build-deps

* update mozjs for real

* glue mozjs

* fmt

* move to servo/mozjs
2023-09-11 08:23:05 +00:00
Josh Matthews
56a8237ef4 Throw type error when calling DOM constructor without new. 2023-05-30 10:32:33 -04:00
Josh Matthews
d9600ff50f Support arbitrary protos when wrapping EventTarget objects. 2023-05-28 23:23:12 -04:00
Josh Matthews
f76bb20c2e Format. 2022-11-23 10:04:53 -05:00
Josh Matthews
bd77a4043c Changes for spidermomkey upgrade. 2022-11-23 10:04:50 -05:00
yvt
320965bfb9 refactor(script): move crate::dom::bindings::{utils → principals)::ServoJSPrincipal 2021-07-13 21:45:21 +09:00
yvt
3550270cd0 fix(script): implement the destroy-principals callback correctly 2021-07-12 01:30:02 +09:00
yvt
e786627199 fix(script): apply some of the changes requested in the review comments of #16501 2021-07-12 01:29:41 +09:00
yvt
bfa2026220 feat(script): remove the call to JS_SetWrapObjectCallbacks
We don't make CCWs anymore.
2021-07-11 23:30:40 +09:00
yvt
40fbe6b722 chore(deps): update mozjs
- 798c5b6: Bring `RustJSPrincipals` back
2021-07-11 23:01:21 +09:00
yvt
28c670d6c3 fix: accommodate to the modern age 2021-07-10 18:18:33 +09:00
yvt
01a7de50ab Merge remote-tracking branch 'upstream/master' into feat-cow-infra
`tests/wpt/web-platform-tests/html/browsers/origin/cross-origin-objects/cross-origin-objects.html`
was reverted to the upstream version.
2021-07-10 17:55:42 +09:00
Josh Matthews
5c4939599e Update mozjs. 2021-02-18 09:35:45 -05:00
Sean Joseph
823cca30d6 Added is_platform_obj_static 2020-11-26 18:30:52 -05:00
Josh Matthews
6dc4488bc7 Remove unnecessary generic from private_from_proto_check. 2020-06-04 20:54:36 -04:00
Alan Jeffrey
c611e46381 Remove WebVR 2020-04-08 20:23:41 -05:00