mirror of
https://github.com/servo/servo.git
synced 2025-08-10 07:55:33 +01:00
Stringify unknown JavaScript objects in global exception handlers
When turning DOM exceptions into `ErrorInfo` always try to stringify the JavaScript value, even if it's an object that isn't a `DOMException` or native exception. This means that exceptions that extend the `Error` prototype are now stringified. The result is that test output for WPT global assertion failures is more useful. For instance for the test include-frames-from-child-same-origin-grandchild.sub.html: Before: ``` uncaught exception: unknown (can't convert to string) ``` After: ``` uncaught exception: Error: assert_equals: expected 4 but got 3 ```
This commit is contained in:
parent
633f14df11
commit
e68ebd2617
3 changed files with 81 additions and 30 deletions
|
@ -13746,6 +13746,13 @@
|
|||
{}
|
||||
]
|
||||
],
|
||||
"global_exception_stringification.html": [
|
||||
"b1c6cb6c390cca290085eea61ba4bf2f34aa4475",
|
||||
[
|
||||
null,
|
||||
{}
|
||||
]
|
||||
],
|
||||
"globals": {
|
||||
"entry.html": [
|
||||
"f963385342adbd92e4858a507c88155b4ed4371f",
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<!-- doctype html -->
|
||||
<!DOCTYPE html>
|
||||
<meta charset=utf-8>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
|
||||
<body>
|
||||
<div id="testOutput"></div>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
setup({ 'allow_uncaught_exception': true });
|
||||
promise_test(async t => {
|
||||
function CustomError(message) {
|
||||
this.message = message;
|
||||
}
|
||||
CustomError.prototype = Object.create(Error.prototype);
|
||||
|
||||
let message = null;
|
||||
let waitForError = new Promise(resolve => {
|
||||
window.onerror = (errorMessage) => {
|
||||
message = errorMessage;
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
throw new CustomError("An exceptional exception.");
|
||||
}, 0);
|
||||
|
||||
await waitForError;
|
||||
assert_equals(message, "uncaught exception: Error: An exceptional exception.");
|
||||
}, "Exception is stringified properly.");
|
||||
</script>
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue