mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-06 16:19:23 +00:00
LibWeb: Report exceptions when invoking custom element reactions
This commit is contained in:
parent
d8511e39c9
commit
7cacf5ca55
Notes:
github-actions[bot]
2024-12-19 15:26:29 +00:00
Author: https://github.com/tcl3
Commit: 7cacf5ca55
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2739
Reviewed-by: https://github.com/shannonbooth
3 changed files with 96 additions and 6 deletions
|
@ -822,12 +822,8 @@ void invoke_custom_element_reactions(Vector<GC::Root<DOM::Element>>& element_que
|
||||||
},
|
},
|
||||||
[&](DOM::CustomElementCallbackReaction& custom_element_callback_reaction) -> void {
|
[&](DOM::CustomElementCallbackReaction& custom_element_callback_reaction) -> void {
|
||||||
// -> callback reaction
|
// -> callback reaction
|
||||||
// Invoke reaction's callback function with reaction's arguments, and with element as the callback this value.
|
// Invoke reaction's callback function with reaction's arguments and "report", and callback this value set to element.
|
||||||
auto result = WebIDL::invoke_callback(*custom_element_callback_reaction.callback, element.ptr(), custom_element_callback_reaction.arguments);
|
(void)WebIDL::invoke_callback(*custom_element_callback_reaction.callback, element.ptr(), WebIDL::ExceptionBehavior::Report, custom_element_callback_reaction.arguments);
|
||||||
// FIXME: The error from CustomElementCallbackReaction is supposed
|
|
||||||
// to use the new steps for IDL callback error reporting
|
|
||||||
if (result.is_abrupt())
|
|
||||||
HTML::report_exception(result, element->realm());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
Harness status: OK
|
||||||
|
|
||||||
|
Found 5 tests
|
||||||
|
|
||||||
|
4 Pass
|
||||||
|
1 Fail
|
||||||
|
Fail constructor
|
||||||
|
Pass connectedCallback
|
||||||
|
Pass disconnectedCallback
|
||||||
|
Pass attributeChangedCallback
|
||||||
|
Pass adoptedCallback
|
|
@ -0,0 +1,83 @@
|
||||||
|
<!doctype html>
|
||||||
|
<meta charset=utf-8>
|
||||||
|
<title>Exceptions raised in constructors / lifecycle callbacks are reported in their global objects</title>
|
||||||
|
<script src=../resources/testharness.js></script>
|
||||||
|
<script src=../resources/testharnessreport.js></script>
|
||||||
|
<iframe></iframe>
|
||||||
|
<iframe></iframe>
|
||||||
|
<iframe></iframe>
|
||||||
|
<script>
|
||||||
|
setup({ allow_uncaught_exception: true });
|
||||||
|
|
||||||
|
window.onerror = () => { onerrorCalls.push("top"); };
|
||||||
|
frames[0].onerror = () => { onerrorCalls.push("frame0"); };
|
||||||
|
frames[1].onerror = () => { onerrorCalls.push("frame1"); };
|
||||||
|
frames[2].onerror = () => { onerrorCalls.push("frame2"); };
|
||||||
|
|
||||||
|
const sourceThrowError = `throw new parent.frames[2].Error("PASS")`;
|
||||||
|
|
||||||
|
test(t => {
|
||||||
|
window.onerrorCalls = [];
|
||||||
|
|
||||||
|
const XFoo = new frames[1].Function(sourceThrowError);
|
||||||
|
frames[0].customElements.define("x-foo-constructor", XFoo);
|
||||||
|
|
||||||
|
frames[0].document.createElement("x-foo-constructor");
|
||||||
|
assert_array_equals(onerrorCalls, ["frame1"]);
|
||||||
|
}, "constructor");
|
||||||
|
|
||||||
|
test(t => {
|
||||||
|
window.onerrorCalls = [];
|
||||||
|
|
||||||
|
const XFooConnected = class extends frames[0].HTMLElement {};
|
||||||
|
XFooConnected.prototype.connectedCallback = new frames[1].Function(sourceThrowError);
|
||||||
|
frames[0].customElements.define("x-foo-connected", XFooConnected);
|
||||||
|
|
||||||
|
const el = frames[0].document.createElement("x-foo-connected");
|
||||||
|
frames[0].document.body.append(el);
|
||||||
|
|
||||||
|
assert_array_equals(onerrorCalls, ["frame1"]);
|
||||||
|
}, "connectedCallback");
|
||||||
|
|
||||||
|
test(t => {
|
||||||
|
window.onerrorCalls = [];
|
||||||
|
|
||||||
|
const XFooDisconnected = class extends frames[0].HTMLElement {};
|
||||||
|
XFooDisconnected.prototype.disconnectedCallback = new frames[1].Function(sourceThrowError);
|
||||||
|
frames[0].customElements.define("x-foo-disconnected", XFooDisconnected);
|
||||||
|
|
||||||
|
const el = frames[0].document.createElement("x-foo-disconnected");
|
||||||
|
frames[0].document.body.append(el);
|
||||||
|
el.remove();
|
||||||
|
|
||||||
|
assert_array_equals(onerrorCalls, ["frame1"]);
|
||||||
|
}, "disconnectedCallback");
|
||||||
|
|
||||||
|
test(t => {
|
||||||
|
window.onerrorCalls = [];
|
||||||
|
|
||||||
|
const XFooAttributeChanged = class extends frames[0].HTMLElement {};
|
||||||
|
XFooAttributeChanged.observedAttributes = ["foo"];
|
||||||
|
XFooAttributeChanged.prototype.attributeChangedCallback = new frames[1].Function(sourceThrowError);
|
||||||
|
frames[0].customElements.define("x-foo-attribute-changed", XFooAttributeChanged);
|
||||||
|
|
||||||
|
const el = frames[0].document.createElement("x-foo-attribute-changed");
|
||||||
|
frames[0].document.body.append(el);
|
||||||
|
el.setAttribute("foo", "bar");
|
||||||
|
|
||||||
|
assert_array_equals(onerrorCalls, ["frame1"]);
|
||||||
|
}, "attributeChangedCallback");
|
||||||
|
|
||||||
|
test(t => {
|
||||||
|
window.onerrorCalls = [];
|
||||||
|
|
||||||
|
const XFooAdopted = class extends frames[0].HTMLElement {};
|
||||||
|
XFooAdopted.prototype.adoptedCallback = new frames[1].Function(sourceThrowError);
|
||||||
|
frames[0].customElements.define("x-foo-adopted", XFooAdopted);
|
||||||
|
|
||||||
|
const el = frames[0].document.createElement("x-foo-adopted");
|
||||||
|
document.body.append(el);
|
||||||
|
|
||||||
|
assert_array_equals(onerrorCalls, ["frame1"]);
|
||||||
|
}, "adoptedCallback");
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue