fix(ext/fetch): Connect async error stack with user code (#13899)

This commit is contained in:
Nayeem Rahman 2022-03-22 17:08:33 +00:00 committed by GitHub
parent f81334d5bd
commit d2c099ce34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 2 deletions

View file

@ -409,8 +409,13 @@
* @param {RequestInit} init
*/
function fetch(input, init = {}) {
// There is an async dispatch later that causes a stack trace disconnect.
// We reconnect it by assigning the result of that dispatch to `opPromise`,
// awaiting `opPromise` in an inner function also named `fetch()` and
// returning the result from that.
let opPromise = undefined;
// 1.
return new Promise((resolve, reject) => {
const result = new Promise((resolve, reject) => {
const prefix = "Failed to call 'fetch'";
webidl.requiredArguments(arguments.length, 1, { prefix });
// 2.
@ -441,7 +446,7 @@
}
// 12.
PromisePrototypeCatch(
opPromise = PromisePrototypeCatch(
PromisePrototypeThen(
mainFetch(request, false, requestObject.signal),
(response) => {
@ -479,6 +484,14 @@
},
);
});
if (opPromise) {
PromisePrototypeCatch(result, () => {});
return (async function fetch() {
await opPromise;
return result;
})();
}
return result;
}
function abortFetch(request, responseObject, error) {