webapi: moveBefore fires connectedCallback without a disconnectedCallback

Fixes the failing subtest of WPT
/dom/nodes/moveBefore/custom-element-move-reactions.html (5/6 -> 6/6):
when a moved custom element defines no connectedMoveCallback, the
fallback is disconnectedCallback + connectedCallback - and either may
be undefined. The error from invoking the missing disconnectedCallback
returned early and skipped connectedCallback entirely.

Both fallback invocations now tolerate a missing method and let the
other one run.

Coverage: /dom/nodes/moveBefore/custom-element-move-reactions.html
5/6 -> 6/6 (fully green).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Francis Bouvier
2026-07-12 16:00:42 +02:00
committed by Karl Seguin
parent d8bc0bacf2
commit cb23ad7cbb

View File

@@ -225,10 +225,11 @@ fn invokeCallbackOnElement(element: *Element, comptime callback_name: [:0]const
// for "move", we call "connectedMoveCallback" if it exists, else we fallback
// to "disconnectedCallback" + "connectedCallback"
if (js_element.has("connectedMoveCallback")) {
js_element.callMethod(void, "connectedMoveCallback", .{}) catch return;
js_element.callMethod(void, "connectedMoveCallback", .{}) catch {};
} else {
js_element.callMethod(void, "disconnectedCallback", .{}) catch return;
js_element.callMethod(void, "connectedCallback", .{}) catch return;
// Either callback may be undefined; the other still runs.
js_element.callMethod(void, "disconnectedCallback", .{}) catch {};
js_element.callMethod(void, "connectedCallback", .{}) catch {};
}
}