Skip to content

Commit

Permalink
Get stack traces for errors in most shadowrealm tests
Browse files Browse the repository at this point in the history
This uses the non-standard `stack` property of Error, if it is present, to
provide stack trace information to the caller of shadowRealmEvalAsync().

The stack trace isn't available in shadowrealm-in-serviceworker and
shadowrealm-in-audioworklet contexts, because they implement a fake
dynamic import with ShadowRealm.prototype.evaluate(), which will wrap any
errors from the imported module in a TypeError and clobber any stack info.
We could do it by adding a try/catch around the module text, but that
would mess with line and column numbers; for now, we'll leave it.
  • Loading branch information
ptomato committed Nov 27, 2024
1 parent 81a0b95 commit f3033a7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion resources/testharness-shadowrealm-outer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* Convenience function for evaluating some async code in the ShadowRealm and
* waiting for the result.
*
* In case of error, this function intentionally exposes the stack trace (if it
* is available) to the hosting realm, for debugging purposes.
*
* @param {ShadowRealm} realm - the ShadowRealm to evaluate the code in
* @param {string} asyncBody - the code to evaluate; will be put in the body of
* an async function, and must return a value explicitly if a value is to be
Expand All @@ -15,7 +18,7 @@ globalThis.shadowRealmEvalAsync = function (realm, asyncBody) {
(resolve, reject) => {
(async () => {
${asyncBody}
})().then(resolve, (e) => reject(e.toString()));
})().then(resolve, (e) => reject(e.toString() + "\\n" + (e.stack || "")));
}
`));
};
Expand Down

0 comments on commit f3033a7

Please sign in to comment.