diff --git a/src/compiler/factory/emitHelpers.ts b/src/compiler/factory/emitHelpers.ts index 365dc03925d07..436695b1538ab 100644 --- a/src/compiler/factory/emitHelpers.ts +++ b/src/compiler/factory/emitHelpers.ts @@ -1417,6 +1417,10 @@ export const addDisposableResourceHelper: UnscopedEmitHelper = { }; /** + * The `s` variable represents two boolean flags from the `DisposeResources` algorithm: + * - `needsAwait` (`1`) — Indicates that an `await using` for a `null` or `undefined` resource was encountered. + * - `hasAwaited` (`2`) — Indicates that the algorithm has performed an Await. + * * @internal */ export const disposeResourcesHelper: UnscopedEmitHelper = { @@ -1430,17 +1434,22 @@ export const disposeResourcesHelper: UnscopedEmitHelper = { env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/src/testRunner/unittests/evaluation/usingDeclarations.ts b/src/testRunner/unittests/evaluation/usingDeclarations.ts index d7c3bd26a47b5..f244e27844b0d 100644 --- a/src/testRunner/unittests/evaluation/usingDeclarations.ts +++ b/src/testRunner/unittests/evaluation/usingDeclarations.ts @@ -1810,4 +1810,50 @@ describe("unittests:: evaluation:: usingDeclarations", () => { "exit", ]); }); + + it("deterministic collapse of Await", async () => { + const { main, output } = evaluator.evaluateTypeScript( + ` + export const output: any[] = []; + + let asyncId = 0; + function increment() { asyncId++; } + + export async function main() { + // increment asyncId at the top of each turn of the microtask queue + let pending = Promise.resolve(); + for (let i = 0; i < 10; i++) { + pending = pending.then(increment); + } + + { + using sync1 = { [Symbol.dispose]() { output.push(asyncId); } }; // asyncId: 2 + await using async1 = null, async2 = null; + using sync2 = { [Symbol.dispose]() { output.push(asyncId); } }; // asyncId: 1 + await using async3 = null, async4 = null; + output.push(asyncId); // asyncId: 0 + } + + output.push(asyncId); // asyncId: Ideally, 2, but ends up being 4 due to delays imposed by 'await' + + await pending; // wait for the remaining 'increment' frames to complete. + } + + `, + { target: ts.ScriptTarget.ES2018 }, + ); + + await main(); + + assert.deepEqual(output, [ + 0, + 1, + 2, + + // This really should be 2, but our transpile introduces an extra `await` by necessity to observe the + // result of __disposeResources. The process of adopting the result ends up taking two turns of the + // microtask queue. + 4, + ]); + }); }); diff --git a/tests/baselines/reference/awaitUsingDeclarations.1(target=es2015).js b/tests/baselines/reference/awaitUsingDeclarations.1(target=es2015).js index c2271c2f2bab1..60d690d76bda0 100644 --- a/tests/baselines/reference/awaitUsingDeclarations.1(target=es2015).js +++ b/tests/baselines/reference/awaitUsingDeclarations.1(target=es2015).js @@ -137,17 +137,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarations.1(target=es2017).js b/tests/baselines/reference/awaitUsingDeclarations.1(target=es2017).js index cccc573e759c2..31b8b0bdf0b82 100644 --- a/tests/baselines/reference/awaitUsingDeclarations.1(target=es2017).js +++ b/tests/baselines/reference/awaitUsingDeclarations.1(target=es2017).js @@ -128,17 +128,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarations.1(target=es2022).js b/tests/baselines/reference/awaitUsingDeclarations.1(target=es2022).js index 182dbc52e3a99..9c660646ccf39 100644 --- a/tests/baselines/reference/awaitUsingDeclarations.1(target=es2022).js +++ b/tests/baselines/reference/awaitUsingDeclarations.1(target=es2022).js @@ -128,17 +128,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarations.1(target=es5).js b/tests/baselines/reference/awaitUsingDeclarations.1(target=es5).js index de5e85a705f10..a34ff4098232c 100644 --- a/tests/baselines/reference/awaitUsingDeclarations.1(target=es5).js +++ b/tests/baselines/reference/awaitUsingDeclarations.1(target=es5).js @@ -164,17 +164,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarations.2(target=es2015).js b/tests/baselines/reference/awaitUsingDeclarations.2(target=es2015).js index 7fe2694730aa5..092e3e5657c41 100644 --- a/tests/baselines/reference/awaitUsingDeclarations.2(target=es2015).js +++ b/tests/baselines/reference/awaitUsingDeclarations.2(target=es2015).js @@ -46,17 +46,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarations.2(target=es2017).js b/tests/baselines/reference/awaitUsingDeclarations.2(target=es2017).js index 99d27d1f62b16..4560efec1fc8a 100644 --- a/tests/baselines/reference/awaitUsingDeclarations.2(target=es2017).js +++ b/tests/baselines/reference/awaitUsingDeclarations.2(target=es2017).js @@ -37,17 +37,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarations.2(target=es2022).js b/tests/baselines/reference/awaitUsingDeclarations.2(target=es2022).js index 99d27d1f62b16..4560efec1fc8a 100644 --- a/tests/baselines/reference/awaitUsingDeclarations.2(target=es2022).js +++ b/tests/baselines/reference/awaitUsingDeclarations.2(target=es2022).js @@ -37,17 +37,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarations.2(target=es5).js b/tests/baselines/reference/awaitUsingDeclarations.2(target=es5).js index a6620ca372225..80fa7d99ba97b 100644 --- a/tests/baselines/reference/awaitUsingDeclarations.2(target=es5).js +++ b/tests/baselines/reference/awaitUsingDeclarations.2(target=es5).js @@ -73,17 +73,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarations.3(target=es2015).js b/tests/baselines/reference/awaitUsingDeclarations.3(target=es2015).js index 5262fd883d987..025ee0a304ccd 100644 --- a/tests/baselines/reference/awaitUsingDeclarations.3(target=es2015).js +++ b/tests/baselines/reference/awaitUsingDeclarations.3(target=es2015).js @@ -48,17 +48,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarations.3(target=es2017).js b/tests/baselines/reference/awaitUsingDeclarations.3(target=es2017).js index e64bb7a3097b6..369461561d9d9 100644 --- a/tests/baselines/reference/awaitUsingDeclarations.3(target=es2017).js +++ b/tests/baselines/reference/awaitUsingDeclarations.3(target=es2017).js @@ -39,17 +39,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarations.3(target=es2022).js b/tests/baselines/reference/awaitUsingDeclarations.3(target=es2022).js index e64bb7a3097b6..369461561d9d9 100644 --- a/tests/baselines/reference/awaitUsingDeclarations.3(target=es2022).js +++ b/tests/baselines/reference/awaitUsingDeclarations.3(target=es2022).js @@ -39,17 +39,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarations.3(target=es5).js b/tests/baselines/reference/awaitUsingDeclarations.3(target=es5).js index 19b2bab799223..57e87730665f5 100644 --- a/tests/baselines/reference/awaitUsingDeclarations.3(target=es5).js +++ b/tests/baselines/reference/awaitUsingDeclarations.3(target=es5).js @@ -75,17 +75,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarationsInFor(target=es2015).js b/tests/baselines/reference/awaitUsingDeclarationsInFor(target=es2015).js index 2870194227ef9..f1c9be674ccf5 100644 --- a/tests/baselines/reference/awaitUsingDeclarationsInFor(target=es2015).js +++ b/tests/baselines/reference/awaitUsingDeclarationsInFor(target=es2015).js @@ -47,17 +47,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarationsInFor(target=es2017).js b/tests/baselines/reference/awaitUsingDeclarationsInFor(target=es2017).js index 221ed3291d271..b430e2684b316 100644 --- a/tests/baselines/reference/awaitUsingDeclarationsInFor(target=es2017).js +++ b/tests/baselines/reference/awaitUsingDeclarationsInFor(target=es2017).js @@ -38,17 +38,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarationsInFor(target=es2022).js b/tests/baselines/reference/awaitUsingDeclarationsInFor(target=es2022).js index 221ed3291d271..b430e2684b316 100644 --- a/tests/baselines/reference/awaitUsingDeclarationsInFor(target=es2022).js +++ b/tests/baselines/reference/awaitUsingDeclarationsInFor(target=es2022).js @@ -38,17 +38,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarationsInFor(target=es5).js b/tests/baselines/reference/awaitUsingDeclarationsInFor(target=es5).js index 3d9c377e54741..f01f673a98836 100644 --- a/tests/baselines/reference/awaitUsingDeclarationsInFor(target=es5).js +++ b/tests/baselines/reference/awaitUsingDeclarationsInFor(target=es5).js @@ -74,17 +74,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es2015).js b/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es2015).js index ef9b9c4303a42..aa6dd826bd543 100644 --- a/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es2015).js +++ b/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es2015).js @@ -44,17 +44,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es2017).js b/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es2017).js index 21630d7de18b3..18c95ea8e4fca 100644 --- a/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es2017).js +++ b/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es2017).js @@ -35,17 +35,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es2022).js b/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es2022).js index 1275289cf78e7..ac74f897e702a 100644 --- a/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es2022).js +++ b/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es2022).js @@ -35,17 +35,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es5).js b/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es5).js index ecb8a463300ce..2e401a484063b 100644 --- a/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es5).js +++ b/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es5).js @@ -71,17 +71,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf.3(target=es5).js b/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf.3(target=es5).js index 2a13612d602c6..abe97e09c15d0 100644 --- a/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf.3(target=es5).js +++ b/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf.3(target=es5).js @@ -78,17 +78,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarationsInForOf.1(target=es2015).js b/tests/baselines/reference/awaitUsingDeclarationsInForOf.1(target=es2015).js index 7c33128a23a5a..9ea879d8b742e 100644 --- a/tests/baselines/reference/awaitUsingDeclarationsInForOf.1(target=es2015).js +++ b/tests/baselines/reference/awaitUsingDeclarationsInForOf.1(target=es2015).js @@ -45,17 +45,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarationsInForOf.1(target=es2017).js b/tests/baselines/reference/awaitUsingDeclarationsInForOf.1(target=es2017).js index 74c7a2fd7c596..4d81c8b1f5f5f 100644 --- a/tests/baselines/reference/awaitUsingDeclarationsInForOf.1(target=es2017).js +++ b/tests/baselines/reference/awaitUsingDeclarationsInForOf.1(target=es2017).js @@ -36,17 +36,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarationsInForOf.1(target=es2022).js b/tests/baselines/reference/awaitUsingDeclarationsInForOf.1(target=es2022).js index 74c7a2fd7c596..4d81c8b1f5f5f 100644 --- a/tests/baselines/reference/awaitUsingDeclarationsInForOf.1(target=es2022).js +++ b/tests/baselines/reference/awaitUsingDeclarationsInForOf.1(target=es2022).js @@ -36,17 +36,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarationsInForOf.1(target=es5).js b/tests/baselines/reference/awaitUsingDeclarationsInForOf.1(target=es5).js index bc8e91348c200..3dab903ba3c89 100644 --- a/tests/baselines/reference/awaitUsingDeclarationsInForOf.1(target=es5).js +++ b/tests/baselines/reference/awaitUsingDeclarationsInForOf.1(target=es5).js @@ -72,17 +72,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/awaitUsingDeclarationsInForOf.5(target=es5).js b/tests/baselines/reference/awaitUsingDeclarationsInForOf.5(target=es5).js index a5bccb513f76c..1b0ea1fd6307e 100644 --- a/tests/baselines/reference/awaitUsingDeclarationsInForOf.5(target=es5).js +++ b/tests/baselines/reference/awaitUsingDeclarationsInForOf.5(target=es5).js @@ -78,17 +78,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/transpile/declarationBasicSyntax.js b/tests/baselines/reference/transpile/declarationBasicSyntax.js index 4fe0087ee9c36..dd7a762bf285b 100644 --- a/tests/baselines/reference/transpile/declarationBasicSyntax.js +++ b/tests/baselines/reference/transpile/declarationBasicSyntax.js @@ -70,17 +70,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarations.1(target=es2015).js b/tests/baselines/reference/usingDeclarations.1(target=es2015).js index aeb42a3939556..a32dd5c254fb5 100644 --- a/tests/baselines/reference/usingDeclarations.1(target=es2015).js +++ b/tests/baselines/reference/usingDeclarations.1(target=es2015).js @@ -191,17 +191,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarations.1(target=es2017).js b/tests/baselines/reference/usingDeclarations.1(target=es2017).js index 5fa00020c0554..afc9c8a3d9d92 100644 --- a/tests/baselines/reference/usingDeclarations.1(target=es2017).js +++ b/tests/baselines/reference/usingDeclarations.1(target=es2017).js @@ -182,17 +182,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarations.1(target=es2022).js b/tests/baselines/reference/usingDeclarations.1(target=es2022).js index ab239e373c5f5..9b121b2c5cd92 100644 --- a/tests/baselines/reference/usingDeclarations.1(target=es2022).js +++ b/tests/baselines/reference/usingDeclarations.1(target=es2022).js @@ -182,17 +182,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarations.1(target=es5).js b/tests/baselines/reference/usingDeclarations.1(target=es5).js index 1b8a2b4e196c7..96d3e7e0311e7 100644 --- a/tests/baselines/reference/usingDeclarations.1(target=es5).js +++ b/tests/baselines/reference/usingDeclarations.1(target=es5).js @@ -233,17 +233,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarations.11.js b/tests/baselines/reference/usingDeclarations.11.js index 64728b2aae96a..19959e6d995e1 100644 --- a/tests/baselines/reference/usingDeclarations.11.js +++ b/tests/baselines/reference/usingDeclarations.11.js @@ -80,17 +80,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarations.12(usedefineforclassfields=false).js b/tests/baselines/reference/usingDeclarations.12(usedefineforclassfields=false).js index e8b19e3ab9d46..22c0ba099c55b 100644 --- a/tests/baselines/reference/usingDeclarations.12(usedefineforclassfields=false).js +++ b/tests/baselines/reference/usingDeclarations.12(usedefineforclassfields=false).js @@ -42,17 +42,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarations.12(usedefineforclassfields=true).js b/tests/baselines/reference/usingDeclarations.12(usedefineforclassfields=true).js index 0d91a0de73e34..c72699637b0f7 100644 --- a/tests/baselines/reference/usingDeclarations.12(usedefineforclassfields=true).js +++ b/tests/baselines/reference/usingDeclarations.12(usedefineforclassfields=true).js @@ -42,17 +42,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarations.2(target=es2015).js b/tests/baselines/reference/usingDeclarations.2(target=es2015).js index 2fa2402b5d140..be422ae02bf10 100644 --- a/tests/baselines/reference/usingDeclarations.2(target=es2015).js +++ b/tests/baselines/reference/usingDeclarations.2(target=es2015).js @@ -36,17 +36,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarations.2(target=es2017).js b/tests/baselines/reference/usingDeclarations.2(target=es2017).js index 2fa2402b5d140..be422ae02bf10 100644 --- a/tests/baselines/reference/usingDeclarations.2(target=es2017).js +++ b/tests/baselines/reference/usingDeclarations.2(target=es2017).js @@ -36,17 +36,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarations.2(target=es2022).js b/tests/baselines/reference/usingDeclarations.2(target=es2022).js index 2fa2402b5d140..be422ae02bf10 100644 --- a/tests/baselines/reference/usingDeclarations.2(target=es2022).js +++ b/tests/baselines/reference/usingDeclarations.2(target=es2022).js @@ -36,17 +36,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarations.2(target=es5).js b/tests/baselines/reference/usingDeclarations.2(target=es5).js index bea0c8e0ce45d..d82b0795e32c4 100644 --- a/tests/baselines/reference/usingDeclarations.2(target=es5).js +++ b/tests/baselines/reference/usingDeclarations.2(target=es5).js @@ -36,17 +36,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarations.3(target=es2015).js b/tests/baselines/reference/usingDeclarations.3(target=es2015).js index 88ed00e44cca4..4810e74d865e6 100644 --- a/tests/baselines/reference/usingDeclarations.3(target=es2015).js +++ b/tests/baselines/reference/usingDeclarations.3(target=es2015).js @@ -38,17 +38,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarations.3(target=es2017).js b/tests/baselines/reference/usingDeclarations.3(target=es2017).js index 88ed00e44cca4..4810e74d865e6 100644 --- a/tests/baselines/reference/usingDeclarations.3(target=es2017).js +++ b/tests/baselines/reference/usingDeclarations.3(target=es2017).js @@ -38,17 +38,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarations.3(target=es2022).js b/tests/baselines/reference/usingDeclarations.3(target=es2022).js index 88ed00e44cca4..4810e74d865e6 100644 --- a/tests/baselines/reference/usingDeclarations.3(target=es2022).js +++ b/tests/baselines/reference/usingDeclarations.3(target=es2022).js @@ -38,17 +38,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarations.3(target=es5).js b/tests/baselines/reference/usingDeclarations.3(target=es5).js index 69c01f121e53e..301be428010f7 100644 --- a/tests/baselines/reference/usingDeclarations.3(target=es5).js +++ b/tests/baselines/reference/usingDeclarations.3(target=es5).js @@ -38,17 +38,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarationsInFor(target=es2015).js b/tests/baselines/reference/usingDeclarationsInFor(target=es2015).js index b42621bb77a54..a6ec32ec0c235 100644 --- a/tests/baselines/reference/usingDeclarationsInFor(target=es2015).js +++ b/tests/baselines/reference/usingDeclarationsInFor(target=es2015).js @@ -34,17 +34,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarationsInFor(target=es2017).js b/tests/baselines/reference/usingDeclarationsInFor(target=es2017).js index b42621bb77a54..a6ec32ec0c235 100644 --- a/tests/baselines/reference/usingDeclarationsInFor(target=es2017).js +++ b/tests/baselines/reference/usingDeclarationsInFor(target=es2017).js @@ -34,17 +34,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarationsInFor(target=es2022).js b/tests/baselines/reference/usingDeclarationsInFor(target=es2022).js index b42621bb77a54..a6ec32ec0c235 100644 --- a/tests/baselines/reference/usingDeclarationsInFor(target=es2022).js +++ b/tests/baselines/reference/usingDeclarationsInFor(target=es2022).js @@ -34,17 +34,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarationsInFor(target=es5).js b/tests/baselines/reference/usingDeclarationsInFor(target=es5).js index 2e97a49005d13..d6589a1779afc 100644 --- a/tests/baselines/reference/usingDeclarationsInFor(target=es5).js +++ b/tests/baselines/reference/usingDeclarationsInFor(target=es5).js @@ -34,17 +34,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es2015).js b/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es2015).js index a52b7731b855e..52a0d20d1efc6 100644 --- a/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es2015).js +++ b/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es2015).js @@ -45,17 +45,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es2017).js b/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es2017).js index 4d6cb74eaa726..9d4fa33d6ef25 100644 --- a/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es2017).js +++ b/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es2017).js @@ -36,17 +36,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es2022).js b/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es2022).js index 7ffc7a4827445..353ac015ec2ee 100644 --- a/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es2022).js +++ b/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es2022).js @@ -36,17 +36,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es5).js b/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es5).js index 053246ff90370..73e60e2988694 100644 --- a/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es5).js +++ b/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es5).js @@ -72,17 +72,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarationsInForOf.1(target=es2015).js b/tests/baselines/reference/usingDeclarationsInForOf.1(target=es2015).js index a3d8f5f7c49c6..3ae4724bd550a 100644 --- a/tests/baselines/reference/usingDeclarationsInForOf.1(target=es2015).js +++ b/tests/baselines/reference/usingDeclarationsInForOf.1(target=es2015).js @@ -34,17 +34,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarationsInForOf.1(target=es2017).js b/tests/baselines/reference/usingDeclarationsInForOf.1(target=es2017).js index a3d8f5f7c49c6..3ae4724bd550a 100644 --- a/tests/baselines/reference/usingDeclarationsInForOf.1(target=es2017).js +++ b/tests/baselines/reference/usingDeclarationsInForOf.1(target=es2017).js @@ -34,17 +34,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarationsInForOf.1(target=es2022).js b/tests/baselines/reference/usingDeclarationsInForOf.1(target=es2022).js index a3d8f5f7c49c6..3ae4724bd550a 100644 --- a/tests/baselines/reference/usingDeclarationsInForOf.1(target=es2022).js +++ b/tests/baselines/reference/usingDeclarationsInForOf.1(target=es2022).js @@ -34,17 +34,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarationsInForOf.1(target=es5).js b/tests/baselines/reference/usingDeclarationsInForOf.1(target=es5).js index dcad7b6146ec7..caec071966fdd 100644 --- a/tests/baselines/reference/usingDeclarationsInForOf.1(target=es5).js +++ b/tests/baselines/reference/usingDeclarationsInForOf.1(target=es5).js @@ -34,17 +34,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next(); diff --git a/tests/baselines/reference/usingDeclarationsNamedEvaluationDecoratorsAndClassFields.js b/tests/baselines/reference/usingDeclarationsNamedEvaluationDecoratorsAndClassFields.js index d7c6b9cc58b09..700a42f901acd 100644 --- a/tests/baselines/reference/usingDeclarationsNamedEvaluationDecoratorsAndClassFields.js +++ b/tests/baselines/reference/usingDeclarationsNamedEvaluationDecoratorsAndClassFields.js @@ -91,17 +91,22 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; env.hasError = true; } + var r, s = 0; function next() { - while (env.stack.length) { - var rec = env.stack.pop(); + while (r = env.stack.pop()) { try { - var result = rec.dispose && rec.dispose.call(rec.value); - if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; } catch (e) { fail(e); } } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); if (env.hasError) throw env.error; } return next();