Repository navigation
script_bindings: Implement ObservableArray - #48506
Conversation
a600c3f to
5b89018
Compare
|
🔨 Triggering try run (#36736114366) for Linux (WPT) |
|
Test results for linux-wpt from try job (#36736114366): Flaky unexpected result (35)
Stable unexpected results that are known to be intermittent (13)
Stable unexpected results (9)
|
|
|
jdm
left a comment
There was a problem hiding this comment.
Looks like the only comments I have are pretty minor. We should look into the test failures, though!
| }; | ||
|
|
||
| pub fn create_proxy_handler(config: *const ObservableArrayProxyHandlerConfig) -> *const c_void { | ||
| unsafe { CreateProxyHandler(&PROXY_TRAPS, config as *const c_void) } |
There was a problem hiding this comment.
Hmm, we may need to make some changes in mozjs to allow us to create a proxy handler that inherits from https://searchfox.org/firefox-main/rev/66b70484481af2e01d4da8bb33f4a756aba77d74/js/public/Wrapper.h#42 . That's what gecko does: https://searchfox.org/firefox-main/rev/66b70484481af2e01d4da8bb33f4a756aba77d74/dom/bindings/ObservableArrayProxyHandler.h#22
There was a problem hiding this comment.
I think doing this as a followup should be ok.
There was a problem hiding this comment.
I am pretty confident that this is the cause of the most recent crash you're looking at. The C++ ForwardingProxyHandler has a getPrototype operation that overrides the one from BaseProxyHandler, and that's the one we want to use.
| isConstructor: None, | ||
| }; | ||
|
|
||
| pub fn create_proxy_handler(config: *const ObservableArrayProxyHandlerConfig) -> *const c_void { |
There was a problem hiding this comment.
This should be unsafe since it accepts a raw pointer.
| } | ||
|
|
||
| /// # Safety | ||
| /// The caller must ensure that the returned pointer is not used after the `JSContext` is deallocated. |
There was a problem hiding this comment.
| /// The caller must ensure that the returned pointer is not used after the `JSContext` is deallocated. | |
| /// handler and owner pointers must outlive the created proxy object. |
| } | ||
|
|
||
| /// # Safety | ||
| /// The caller must ensure that the returned pointer is not used after the `JSContext` is deallocated. |
There was a problem hiding this comment.
| /// The caller must ensure that the returned pointer is not used after the `JSContext` is deallocated. | |
| /// `proxy` must be a valid, non-null pointer. |
| let mut result_ptr = unsafe { *result }; | ||
|
|
||
| if is_length_id(&cx, id) { | ||
| if desc.hasSetter_() || desc.hasGetter_() { |
There was a problem hiding this comment.
| /// 2. Remove the old effective constructed stylesheets from the style set. | ||
| /// 3. Rebuild the effective constructed stylesheet order from `incoming_stylesheets`. | ||
| fn set_adopted_stylesheets( | ||
| _cx: &mut JSContext, |
There was a problem hiding this comment.
| _cx: &mut JSContext, |
| } | ||
| } | ||
|
|
||
| // The set to check for the duplicates when removing the old stylesheets. |
| pub(crate) fn set_adopted_stylesheet_from_jsval( | ||
| /// <https://drafts.csswg.org/cssom/#dom-documentorshadowroot-adoptedstylesheets> | ||
| pub(crate) fn on_set_adopted_stylesheets( | ||
| cx: &mut JSContext, |
There was a problem hiding this comment.
| cx: &mut JSContext, |
| }, | ||
| retval, | ||
| ); | ||
| self.adopted_stylesheets.borrow_mut().as_mut(), |
There was a problem hiding this comment.
| self.adopted_stylesheets.borrow_mut().as_mut(), | |
| self.adopted_stylesheets.safe_borrow_mut(cx).as_mut(), |
| cx, | ||
| &self.adopted_stylesheets, | ||
| val, | ||
| self.adopted_stylesheets.borrow_mut().as_mut(), |
There was a problem hiding this comment.
| self.adopted_stylesheets.borrow_mut().as_mut(), | |
| self.adopted_stylesheets.safe_borrow_mut(cx).as_mut(), |
|
It would be good to see the full backtrace of the crash from /webidl/ecmascript-binding/observable-array-no-leak-of-internals.window.html. |
3c63dfe to
3f61afc
Compare
3f61afc to
2d34a44
Compare
Could you help me figure out the right tools to do this? I've been trying to set up my own debugger but haven't found any clues, and I'm also trying to set up profiling according to these docs, but it looks like servo_tracing isn't available for script_bindings |
|
That backtrace shows a panic in progress. If you set a breakpoint on rust_panic, what's the backtrace look like when the breakpoint is triggered? Does running the test normally show a panic message in the test output? |
|
One thing that can help.in that case is building with |
|
The panic in your first stack does not align with the current tree? I don't see a Also, can you copy/paste instead of doing screenshots? That makes it much easier to check the code referenced in your stacks. Thanks! |
| handler: *const c_void, | ||
| owner: *const c_void, | ||
| ) -> *mut JSObject { | ||
| rooted!(&in(cx) let target = unsafe { NewArrayObject(cx, &HandleValueArray::empty()) }); |
There was a problem hiding this comment.
Oh, I remember now—SpiderMonkey doesn't like calling this particular variant with an empty array. Instead, do this:
|
I made the change above from Stack Trace |
|
I wonder why ProxyTraps in windowproxy need to be singleton here, is that different from ObservableArray implementation? |
|
|
…updated test expectations Signed-off-by: Jerens Lensun <[email protected]>
a5110ac to
b5d00a5
Compare
Servo now pins mozjs 0.26.9 (mozjs_sys 153.4.0-1), for the ObservableArray bindings (servo/servo#48506). With the shim still at 0.26.7, Cargo leaves the patch unused and builds Servo against SpiderMonkey's mozjs. The Rust layers and the tests of mozjs are unchanged since 0.26.7; mozjs_sys 153.4 adds a glue function. CreateForwardingProxyHandler makes a handler like CreateProxyHandler's, whose missing traps forward to the target, as in js::ForwardingProxyHandler: ObservableArray proxies have a backing array as target and implement only some traps. Like mozjs, its proxies are in the handler family and have their extra, and they aren't wrappers. The handler kind of CreateProxyHandler, which mozjs now calls BaseProxyHandler, is renamed to match. Validation: `just test` (132 tests, the new forwarding_proxy_handler included: missing traps reach the target for get, has, keys, descriptors, prototype, extensibility and delete, the defineProperty trap runs instead of the target's, and the proxy is in the handler family with its extra and isn't a wrapper; with CreateForwardingProxyHandler making a base handler, the test fails), `just lint` and `cargo fmt --check` pass. Servo's ohos-main sync of 2026-10-29 builds `./mach build --release --js-engine quickjs` against this commit; its QuickJS WPT run covers ObservableArray (`webidl/ecmascript-binding/observable-array-*`, `adoptedStyleSheets`). AI-assisted: Yes (agent session; found the unused patch in the ohos-main sync, wrote and tested the change) Signed-off-by: Jonathan Schwender <[email protected]>
Servo's ObservableArray bindings (servo/servo#48506) set the length of their backing array with JS::SetArrayLength, which was still a stub, so every assignment to `adoptedStyleSheets` panicked. Set `length` with [[Set]] and throw on failure, as SpiderMonkey's SetLengthProperty does. Validation: the `arrays` test now truncates and extends an array with SetArrayLength and checks that a frozen array's length can't be set, with an exception pending; `just test` (133 tests), `just lint` and `cargo fmt --check` pass. Servo's QuickJS build of the ohos-main sync of 2026-10-29 panicked with "`SetArrayLength` is not implemented" in 36 WPT tests, all with `adoptedStyleSheets`; with this commit, a page that assigns and pushes to `document.adoptedStyleSheets` runs. AI-assisted: Yes (agent session; found by the QuickJS WPT run of the ohos-main sync, written and tested by the agent) Signed-off-by: Jonathan Schwender <[email protected]>
Upstream's ObservableArray bindings (servo#48506) pin mozjs 0.26.9 and call `CreateForwardingProxyHandler`, a glue function of mozjs_sys 153.4. The pinned servo-quickjs c38af5c still called itself mozjs 0.26.7, so Cargo left `--js-engine quickjs`'s patch unused and built Servo against SpiderMonkey's mozjs, which failed on the QuickJS-only calls of the stack. servo-quickjs 544db84 is mozjs 0.26.9 and implements the forwarding handler (18891c1), `SetArrayLength` (f1c371c), which every assignment to `adoptedStyleSheets` uses, and IsArray for proxies of arrays (544db84, QuickJS patch Q44), so that `Array.isArray(document.adoptedStyleSheets)` is true, as with SpiderMonkey. e335588 lets the finalizers of ObservableArray owners write to a proxy that the same cycle collection already finalized, where QuickJS's order differs from SpiderMonkey's. Validation: servo-quickjs's `just test` and `just test-asan` (137 tests, a forwarding handler test and tests of the three other fixes that fail without them), `just lint` and `cargo fmt --check` pass; `just test262` passes on the same QuickJS sources. A QuickJS release build of this stack from this pin runs a page that assigns and pushes to `document.adoptedStyleSheets`, sees an array and exits cleanly. Full WPT with `--js-engine quickjs` against 18891c1 (60,788 tests): 36 crashes from `SetArrayLength` and an abort in the document's finalizer, both fixed since; the 216 tests with unexpected results then ran three times with each engine: the only crash left, load-removes-queued-error-event, crashes with SpiderMonkey too, and 6 tests had consistent QuickJS-only results. Three origin-keyed-agent-clusters tests got QuickJS conditions in patch 49; the other three came from `Array.isArray` being false for ObservableArrays and now pass. A second full run against the same tree as 544db84, before it was merged, has no shim abort, and of its 4 unexpected crashes, load-removes-queued-error-event is the known one and the other three were WebDriver harness errors that passed 5 of 5 reruns. From this pin, css/cssom, origin-keyed-agent-clusters and webidl/ecmascript-binding (431 tests) run as expected with QuickJS. An OpenHarmony headless QuickJS build against 18891c1 ran the media set on a DAYU200 as SpiderMonkey does. AI-assisted: Yes (agent session; 2026-10-29 sync -- the agent found the unused patch, the two crashes and the `Array.isArray` gap, wrote the servo-quickjs changes and bumped the pin) Signed-off-by: Jonathan Schwender <[email protected]>
Upstream's ObservableArray bindings (servo#48506) pin mozjs 0.26.9 and call `CreateForwardingProxyHandler`, a glue function of mozjs_sys 153.4. The pinned servo-quickjs c38af5c still called itself mozjs 0.26.7, so Cargo left `--js-engine quickjs`'s patch unused and built Servo against SpiderMonkey's mozjs, which failed on the QuickJS-only calls of the stack. servo-quickjs 544db84 is mozjs 0.26.9 and implements the forwarding handler (18891c1), `SetArrayLength` (f1c371c), which every assignment to `adoptedStyleSheets` uses, and IsArray for proxies of arrays (544db84, QuickJS patch Q44), so that `Array.isArray(document.adoptedStyleSheets)` is true, as with SpiderMonkey. e335588 lets the finalizers of ObservableArray owners write to a proxy that the same cycle collection already finalized, where QuickJS's order differs from SpiderMonkey's. Validation: servo-quickjs's `just test` and `just test-asan` (137 tests, a forwarding handler test and tests of the three other fixes that fail without them), `just lint` and `cargo fmt --check` pass; `just test262` passes on the same QuickJS sources. A QuickJS release build of this stack from this pin runs a page that assigns and pushes to `document.adoptedStyleSheets`, sees an array and exits cleanly. Full WPT with `--js-engine quickjs` against 18891c1 (60,788 tests): 36 crashes from `SetArrayLength` and an abort in the document's finalizer, both fixed since; the 216 tests with unexpected results then ran three times with each engine: the only crash left, load-removes-queued-error-event, crashes with SpiderMonkey too, and 6 tests had consistent QuickJS-only results. Three origin-keyed-agent-clusters tests got QuickJS conditions in patch 49; the other three came from `Array.isArray` being false for ObservableArrays and now pass. A second full run against the same tree as 544db84, before it was merged, has no shim abort, and of its 4 unexpected crashes, load-removes-queued-error-event is the known one and the other three were WebDriver harness errors that passed 5 of 5 reruns. From this pin, css/cssom, origin-keyed-agent-clusters and webidl/ecmascript-binding (431 tests) run as expected with QuickJS. An OpenHarmony headless QuickJS build against 18891c1 ran the media set on a DAYU200 as SpiderMonkey does. AI-assisted: Yes (agent session; 2026-10-29 sync -- the agent found the unused patch, the two crashes and the `Array.isArray` gap, wrote the servo-quickjs changes and bumped the pin) Signed-off-by: Jonathan Schwender <[email protected]>
Upstream's ObservableArray bindings (servo#48506) pin mozjs 0.26.9 and call `CreateForwardingProxyHandler`, a glue function of mozjs_sys 153.4. The pinned servo-quickjs c38af5c still called itself mozjs 0.26.7, so Cargo left `--js-engine quickjs`'s patch unused and built Servo against SpiderMonkey's mozjs, which failed on the QuickJS-only calls of the stack. servo-quickjs 544db84 is mozjs 0.26.9 and implements the forwarding handler (18891c1), `SetArrayLength` (f1c371c), which every assignment to `adoptedStyleSheets` uses, and IsArray for proxies of arrays (544db84, QuickJS patch Q44), so that `Array.isArray(document.adoptedStyleSheets)` is true, as with SpiderMonkey. e335588 lets the finalizers of ObservableArray owners write to a proxy that the same cycle collection already finalized, where QuickJS's order differs from SpiderMonkey's. Validation: servo-quickjs's `just test` and `just test-asan` (137 tests, a forwarding handler test and tests of the three other fixes that fail without them), `just lint` and `cargo fmt --check` pass; `just test262` passes on the same QuickJS sources. A QuickJS release build of this stack from this pin runs a page that assigns and pushes to `document.adoptedStyleSheets`, sees an array and exits cleanly. Full WPT with `--js-engine quickjs` against 18891c1 (60,788 tests): 36 crashes from `SetArrayLength` and an abort in the document's finalizer, both fixed since; the 216 tests with unexpected results then ran three times with each engine: the only crash left, load-removes-queued-error-event, crashes with SpiderMonkey too, and 6 tests had consistent QuickJS-only results. Three origin-keyed-agent-clusters tests got QuickJS conditions in patch 49; the other three came from `Array.isArray` being false for ObservableArrays and now pass. A second full run against the same tree as 544db84, before it was merged, has no shim abort, and of its 4 unexpected crashes, load-removes-queued-error-event is the known one and the other three were WebDriver harness errors that passed 5 of 5 reruns. From this pin, css/cssom, origin-keyed-agent-clusters and webidl/ecmascript-binding (431 tests) run as expected with QuickJS. An OpenHarmony headless QuickJS build against 18891c1 ran the media set on a DAYU200 as SpiderMonkey does. AI-assisted: Yes (agent session; 2026-10-29 sync -- the agent found the unused patch, the two crashes and the `Array.isArray` gap, wrote the servo-quickjs changes and bumped the pin) Signed-off-by: Jonathan Schwender <[email protected]>
…(#830) Currently all proxy handlers must inherit the behaviour of js::BaseProxyHandler or js::Wrapper, but the ObservableArray implementation needs js::ForwardingProxyHandler. This change renames the existing glue class to match the base and adds a new class that inherits from the real ForwardingProxyHandler. Testing: Tested via ObservableArray implementation in Servo. Servo PR: servo/servo#48506 --------- Signed-off-by: Josh Matthews <[email protected]>
Servo now pins mozjs 0.26.9 (mozjs_sys 153.4.0-1), for the ObservableArray bindings (servo/servo#48506). With the shim still at 0.26.7, Cargo leaves the patch unused and builds Servo against SpiderMonkey's mozjs. The Rust layers and the tests of mozjs are unchanged since 0.26.7; mozjs_sys 153.4 adds a glue function. CreateForwardingProxyHandler makes a handler like CreateProxyHandler's, whose missing traps forward to the target, as in js::ForwardingProxyHandler: ObservableArray proxies have a backing array as target and implement only some traps. Like mozjs, its proxies are in the handler family and have their extra, and they aren't wrappers. The handler kind of CreateProxyHandler, which mozjs now calls BaseProxyHandler, is renamed to match. Validation: `just test` (132 tests, the new forwarding_proxy_handler included: missing traps reach the target for get, has, keys, descriptors, prototype, extensibility and delete, the defineProperty trap runs instead of the target's, and the proxy is in the handler family with its extra and isn't a wrapper; with CreateForwardingProxyHandler making a base handler, the test fails), `just lint` and `cargo fmt --check` pass. Servo's ohos-main sync of 2026-10-29 builds `./mach build --release --js-engine quickjs` against this commit; its QuickJS WPT run covers ObservableArray (`webidl/ecmascript-binding/observable-array-*`, `adoptedStyleSheets`). AI-assisted: Yes (agent session; found the unused patch in the ohos-main sync, wrote and tested the change) Signed-off-by: Jonathan Schwender <[email protected]>
Servo's ObservableArray bindings (servo/servo#48506) set the length of their backing array with JS::SetArrayLength, which was still a stub, so every assignment to `adoptedStyleSheets` panicked. Set `length` with [[Set]] and throw on failure, as SpiderMonkey's SetLengthProperty does. Validation: the `arrays` test now truncates and extends an array with SetArrayLength and checks that a frozen array's length can't be set, with an exception pending; `just test` (133 tests), `just lint` and `cargo fmt --check` pass. Servo's QuickJS build of the ohos-main sync of 2026-10-29 panicked with "`SetArrayLength` is not implemented" in 36 WPT tests, all with `adoptedStyleSheets`; with this commit, a page that assigns and pushes to `document.adoptedStyleSheets` runs. AI-assisted: Yes (agent session; found by the QuickJS WPT run of the ohos-main sync, written and tested by the agent) Signed-off-by: Jonathan Schwender <[email protected]>




Resurrecting the implementation of ObservableArray in #46130
Testing:
Fixes #37902
Fixes #38132