Truly independent web browser
Tests/LibJS: Replace `finally` environment tests with matrix cases
Tim Ledbetter6738bd0acc13
diff --git a/Tests/LibJS/Runtime/try-return-finally.js b/Tests/LibJS/Runtime/try-return-finally.jsindex 806ae466307..8eeadbff275 100644--- a/Tests/LibJS/Runtime/try-return-finally.js+++ b/Tests/LibJS/Runtime/try-return-finally.js@@ -79,180 +79,6 @@ test("return from async through finally", () => {});});-test("return through a for-of loop restores the environment for finally", () => {- let capturedT;- function f() {- let a = "a";- try {- {- let t = "t";- capturedT = () => t;- for (const x of [1, 2]) {- return () => a;- }- }- } finally {- a = "assigned";- }- }-- const capturedA = f();- expect(capturedA()).toBe("assigned");- expect(capturedT()).toBe("t");-});--test("return through a nested try/finally restores the environment for finally", () => {- let capturedT;- function f() {- let a = "a";- try {- {- let t = "t";- capturedT = () => t;- try {- return () => a;- } finally {- }- }- } finally {- a = "assigned";- }- }-- const capturedA = f();- expect(capturedA()).toBe("assigned");- expect(capturedT()).toBe("t");-});--test("generator return through a for-of loop restores the environment for finally", () => {- let capturedA;- let capturedT;- function* g() {- let a = "a";- capturedA = () => a;- try {- {- let t = "t";- capturedT = () => t;- for (const x of [1, 2]) {- yield 1;- }- }- } finally {- a = "assigned";- }- }-- const generator = g();- generator.next();- generator.return();- expect(capturedA()).toBe("assigned");- expect(capturedT()).toBe("t");-});--test("generator return through an array destructuring restores the environment for finally", () => {- let capturedA;- let capturedT;- function* g() {- let a = "a";- capturedA = () => a;- try {- {- let t = "t";- capturedT = () => t;- let x;- [x = yield] = [undefined];- }- } finally {- a = "assigned";- }- }-- const generator = g();- generator.next();- generator.return();- expect(capturedA()).toBe("assigned");- expect(capturedT()).toBe("t");-});--test("generator return from a class definition restores the environment for finally", () => {- let capturedA;- let capturedT;- function* g() {- let a = "a";- capturedA = () => a;- try {- {- let t = "t";- capturedT = () => t;- class C {- [yield] = 1;- }- }- } finally {- a = "assigned";- }- }-- const generator = g();- generator.next();- generator.return();- expect(capturedA()).toBe("assigned");- expect(capturedT()).toBe("t");-});--test("generator return from a for-of head restores the environment for finally", () => {- let capturedA;- let capturedT;- function* g() {- let a = "a";- capturedA = () => a;- try {- {- let t = "t";- capturedT = () => t;- for (const x of yield) {- const capturedX = () => x;- }- }- } finally {- a = "assigned";- }- }-- const generator = g();- generator.next();- generator.return();- expect(capturedA()).toBe("assigned");- expect(capturedT()).toBe("t");-});--test("generator return from a for-in loop variable default restores the environment for finally", () => {- let capturedA;- let capturedT;- function* g() {- let a = "a";- capturedA = () => a;- try {- {- let t = "t";- capturedT = () => t;- for (const { x = yield } in { p: 1 }) {- const capturedX = () => x;- }- }- } finally {- a = "assigned";- }- }-- const generator = g();- generator.next();- generator.return();- expect(capturedA()).toBe("assigned");- expect(capturedT()).toBe("t");-});-describe("every way out of a scope restores the environment for finally", () => {const yieldExit = { statement: "yield", expression: "yield" };const throwExit = { statement: "thrower()", expression: "thrower()" };@@ -295,6 +121,7 @@ describe("every way out of a scope restores the environment for finally", () =>"a for-of loop body": "for (const x of [1]) { capture(() => x); STATEMENT; }","a for-in loop body": "for (const x in { p: 1 }) { capture(() => x); STATEMENT; }","a catch clause": "try { throw 1; } catch (e) { capture(() => e); STATEMENT; }",+ "a try block with a finally clause": "try { STATEMENT; } finally {}","a switch case": "switch (0) { case 0: let s = 1; capture(() => s); STATEMENT; }","a with statement": "with ({}) { STATEMENT; }","a for-of loop head": "for (const x of [EXPRESSION]) { capture(() => x); }",