123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679 |
- test("Nested try/catch/finally with continue", () => {
- const executionOrder = [];
- function callFromUpdateBlock(i) {
- expect(i).toBe(2);
- executionOrder.push(4);
- }
- function callFromTestBlock(i) {
- expect(i).toBe(2);
- executionOrder.push(5);
- return false;
- }
- try {
- const foo = 0;
- expect(foo).toBe(0);
- for (let i = 1; i >= 2 ? callFromTestBlock(i) : true; ++i, callFromUpdateBlock(i)) {
- const bar = 2;
- expect(foo).toBe(0);
- expect(i).toBe(1);
- expect(bar).toBe(2);
- try {
- const baz = 3;
- expect(foo).toBe(0);
- expect(i).toBe(1);
- expect(bar).toBe(2);
- expect(baz).toBe(3);
- try {
- const serenity = 4;
- expect(foo).toBe(0);
- expect(i).toBe(1);
- expect(bar).toBe(2);
- expect(baz).toBe(3);
- expect(serenity).toBe(4);
- try {
- const whf = 5;
- expect(foo).toBe(0);
- expect(i).toBe(1);
- expect(bar).toBe(2);
- expect(baz).toBe(3);
- expect(serenity).toBe(4);
- expect(whf).toBe(5);
- continue;
- } finally {
- const innerFinally1 = 6;
- expect(() => {
- whf;
- }).toThrowWithMessage(ReferenceError, "'whf' is not defined");
- expect(foo).toBe(0);
- expect(i).toBe(1);
- expect(bar).toBe(2);
- expect(baz).toBe(3);
- expect(serenity).toBe(4);
- expect(innerFinally1).toBe(6);
- executionOrder.push(1);
- }
- expect().fail("Running code after most inner try in for loop");
- } finally {
- const innerFinally2 = 7;
- expect(() => {
- serenity;
- }).toThrowWithMessage(ReferenceError, "'serenity' is not defined");
- expect(() => {
- whf;
- }).toThrowWithMessage(ReferenceError, "'whf' is not defined");
- expect(() => {
- innerFinally1;
- }).toThrowWithMessage(ReferenceError, "'innerFinally1' is not defined");
- expect(foo).toBe(0);
- expect(i).toBe(1);
- expect(bar).toBe(2);
- expect(baz).toBe(3);
- expect(innerFinally2).toBe(7);
- executionOrder.push(2);
- }
- expect().fail("Running code from after the middle try in for loop");
- } finally {
- const innerFinally3 = 8;
- expect(() => {
- baz;
- }).toThrowWithMessage(ReferenceError, "'baz' is not defined");
- expect(() => {
- serenity;
- }).toThrowWithMessage(ReferenceError, "'serenity' is not defined");
- expect(() => {
- whf;
- }).toThrowWithMessage(ReferenceError, "'whf' is not defined");
- expect(() => {
- innerFinally1;
- }).toThrowWithMessage(ReferenceError, "'innerFinally1' is not defined");
- expect(() => {
- innerFinally2;
- }).toThrowWithMessage(ReferenceError, "'innerFinally2' is not defined");
- expect(foo).toBe(0);
- expect(i).toBe(1);
- expect(bar).toBe(2);
- expect(innerFinally3).toBe(8);
- executionOrder.push(3);
- }
- expect().fail("Running code from after the outer try in for loop");
- }
- executionOrder.push(6);
- expect(() => {
- i;
- }).toThrowWithMessage(ReferenceError, "'i' is not defined");
- expect(() => {
- bar;
- }).toThrowWithMessage(ReferenceError, "'bar' is not defined");
- expect(() => {
- baz;
- }).toThrowWithMessage(ReferenceError, "'baz' is not defined");
- expect(() => {
- serenity;
- }).toThrowWithMessage(ReferenceError, "'serenity' is not defined");
- expect(() => {
- whf;
- }).toThrowWithMessage(ReferenceError, "'whf' is not defined");
- expect(() => {
- innerFinally1;
- }).toThrowWithMessage(ReferenceError, "'innerFinally1' is not defined");
- expect(() => {
- innerFinally2;
- }).toThrowWithMessage(ReferenceError, "'innerFinally2' is not defined");
- expect(() => {
- innerFinally3;
- }).toThrowWithMessage(ReferenceError, "'innerFinally3' is not defined");
- expect(foo).toBe(0);
- } finally {
- const innerFinally4 = 9;
- expect(() => {
- foo;
- }).toThrowWithMessage(ReferenceError, "'foo' is not defined");
- expect(() => {
- i;
- }).toThrowWithMessage(ReferenceError, "'i' is not defined");
- expect(() => {
- bar;
- }).toThrowWithMessage(ReferenceError, "'bar' is not defined");
- expect(() => {
- baz;
- }).toThrowWithMessage(ReferenceError, "'baz' is not defined");
- expect(() => {
- serenity;
- }).toThrowWithMessage(ReferenceError, "'serenity' is not defined");
- expect(() => {
- whf;
- }).toThrowWithMessage(ReferenceError, "'whf' is not defined");
- expect(() => {
- innerFinally1;
- }).toThrowWithMessage(ReferenceError, "'innerFinally1' is not defined");
- expect(() => {
- innerFinally2;
- }).toThrowWithMessage(ReferenceError, "'innerFinally2' is not defined");
- expect(() => {
- innerFinally3;
- }).toThrowWithMessage(ReferenceError, "'innerFinally3' is not defined");
- expect(innerFinally4).toBe(9);
- executionOrder.push(7);
- }
- expect(() => {
- foo;
- }).toThrowWithMessage(ReferenceError, "'foo' is not defined");
- expect(() => {
- i;
- }).toThrowWithMessage(ReferenceError, "'i' is not defined");
- expect(() => {
- bar;
- }).toThrowWithMessage(ReferenceError, "'bar' is not defined");
- expect(() => {
- baz;
- }).toThrowWithMessage(ReferenceError, "'baz' is not defined");
- expect(() => {
- serenity;
- }).toThrowWithMessage(ReferenceError, "'serenity' is not defined");
- expect(() => {
- whf;
- }).toThrowWithMessage(ReferenceError, "'whf' is not defined");
- expect(() => {
- innerFinally1;
- }).toThrowWithMessage(ReferenceError, "'innerFinally1' is not defined");
- expect(() => {
- innerFinally2;
- }).toThrowWithMessage(ReferenceError, "'innerFinally2' is not defined");
- expect(() => {
- innerFinally3;
- }).toThrowWithMessage(ReferenceError, "'innerFinally3' is not defined");
- expect(() => {
- innerFinally4;
- }).toThrowWithMessage(ReferenceError, "'innerFinally4' is not defined");
- expect(executionOrder).toEqual([1, 2, 3, 4, 5, 6, 7]);
- });
- test("Nested try/catch/finally with labelled continue", () => {
- const executionOrder = [];
- function callFromUpdateBlock(j) {
- expect(j).toBe(2);
- executionOrder.push(5);
- }
- function callFromTestBlock(j) {
- expect(j).toBe(2);
- executionOrder.push(6);
- return false;
- }
- try {
- const foo = 0;
- expect(foo).toBe(0);
- outer: for (let j = 1; j >= 2 ? callFromTestBlock(j) : true; ++j, callFromUpdateBlock(j)) {
- const bar = 2;
- expect(foo).toBe(0);
- expect(j).toBe(1);
- expect(bar).toBe(2);
- try {
- const baz = 3;
- expect(foo).toBe(0);
- expect(j).toBe(1);
- expect(bar).toBe(2);
- expect(baz).toBe(3);
- for (const i = 4; ; expect().fail("Jumped to inner for loop update block")) {
- const serenity = 5;
- expect(foo).toBe(0);
- expect(j).toBe(1);
- expect(bar).toBe(2);
- expect(baz).toBe(3);
- expect(i).toBe(4);
- expect(serenity).toBe(5);
- try {
- const whf = 6;
- expect(foo).toBe(0);
- expect(j).toBe(1);
- expect(bar).toBe(2);
- expect(baz).toBe(3);
- expect(i).toBe(4);
- expect(serenity).toBe(5);
- expect(whf).toBe(6);
- try {
- const beforeContinueTry = 7;
- expect(foo).toBe(0);
- expect(j).toBe(1);
- expect(bar).toBe(2);
- expect(baz).toBe(3);
- expect(i).toBe(4);
- expect(serenity).toBe(5);
- expect(whf).toBe(6);
- expect(beforeContinueTry).toBe(7);
- try {
- const continueTry = 8;
- expect(foo).toBe(0);
- expect(j).toBe(1);
- expect(bar).toBe(2);
- expect(baz).toBe(3);
- expect(i).toBe(4);
- expect(serenity).toBe(5);
- expect(whf).toBe(6);
- expect(beforeContinueTry).toBe(7);
- expect(continueTry).toBe(8);
- continue outer;
- } finally {
- const innerFinally1 = 9;
- expect(() => {
- continueTry;
- }).toThrowWithMessage(
- ReferenceError,
- "'continueTry' is not defined"
- );
- expect(foo).toBe(0);
- expect(j).toBe(1);
- expect(bar).toBe(2);
- expect(baz).toBe(3);
- expect(i).toBe(4);
- expect(serenity).toBe(5);
- expect(whf).toBe(6);
- expect(beforeContinueTry).toBe(7);
- expect(innerFinally1).toBe(9);
- executionOrder.push(1);
- }
- expect().fail("Running code after most inner try");
- } finally {
- const innerFinally2 = 10;
- expect(() => {
- beforeContinueTry;
- }).toThrowWithMessage(
- ReferenceError,
- "'beforeContinueTry' is not defined"
- );
- expect(() => {
- continueTry;
- }).toThrowWithMessage(ReferenceError, "'continueTry' is not defined");
- expect(() => {
- innerFinally1;
- }).toThrowWithMessage(ReferenceError, "'innerFinally1' is not defined");
- expect(foo).toBe(0);
- expect(j).toBe(1);
- expect(bar).toBe(2);
- expect(baz).toBe(3);
- expect(i).toBe(4);
- expect(serenity).toBe(5);
- expect(whf).toBe(6);
- expect(innerFinally2).toBe(10);
- executionOrder.push(2);
- }
- expect().fail("Running code after second to most inner try");
- } finally {
- const innerFinally3 = 11;
- expect(() => {
- whf;
- }).toThrowWithMessage(ReferenceError, "'whf' is not defined");
- expect(() => {
- beforeContinueTry;
- }).toThrowWithMessage(ReferenceError, "'beforeContinueTry' is not defined");
- expect(() => {
- continueTry;
- }).toThrowWithMessage(ReferenceError, "'continueTry' is not defined");
- expect(() => {
- innerFinally1;
- }).toThrowWithMessage(ReferenceError, "'innerFinally1' is not defined");
- expect(() => {
- innerFinally2;
- }).toThrowWithMessage(ReferenceError, "'innerFinally2' is not defined");
- expect(foo).toBe(0);
- expect(j).toBe(1);
- expect(bar).toBe(2);
- expect(baz).toBe(3);
- expect(i).toBe(4);
- expect(serenity).toBe(5);
- expect(innerFinally3).toBe(11);
- executionOrder.push(3);
- }
- expect().fail("Running code after third to most inner try");
- }
- expect().fail("Running code after inner for loop");
- } finally {
- const innerFinally4 = 12;
- expect(() => {
- baz;
- }).toThrowWithMessage(ReferenceError, "'baz' is not defined");
- expect(() => {
- i;
- }).toThrowWithMessage(ReferenceError, "'i' is not defined");
- expect(() => {
- serenity;
- }).toThrowWithMessage(ReferenceError, "'serenity' is not defined");
- expect(() => {
- whf;
- }).toThrowWithMessage(ReferenceError, "'whf' is not defined");
- expect(() => {
- beforeContinueTry;
- }).toThrowWithMessage(ReferenceError, "'beforeContinueTry' is not defined");
- expect(() => {
- continueTry;
- }).toThrowWithMessage(ReferenceError, "'continueTry' is not defined");
- expect(() => {
- innerFinally1;
- }).toThrowWithMessage(ReferenceError, "'innerFinally1' is not defined");
- expect(() => {
- innerFinally2;
- }).toThrowWithMessage(ReferenceError, "'innerFinally2' is not defined");
- expect(() => {
- innerFinally3;
- }).toThrowWithMessage(ReferenceError, "'innerFinally3' is not defined");
- expect(foo).toBe(0);
- expect(j).toBe(1);
- expect(bar).toBe(2);
- expect(innerFinally4).toBe(12);
- executionOrder.push(4);
- }
- expect().fail("Running code after try in outer for loop");
- }
- expect(() => {
- j;
- }).toThrowWithMessage(ReferenceError, "'j' is not defined");
- expect(() => {
- bar;
- }).toThrowWithMessage(ReferenceError, "'bar' is not defined");
- expect(() => {
- baz;
- }).toThrowWithMessage(ReferenceError, "'baz' is not defined");
- expect(() => {
- i;
- }).toThrowWithMessage(ReferenceError, "'i' is not defined");
- expect(() => {
- serenity;
- }).toThrowWithMessage(ReferenceError, "'serenity' is not defined");
- expect(() => {
- whf;
- }).toThrowWithMessage(ReferenceError, "'whf' is not defined");
- expect(() => {
- beforeContinueTry;
- }).toThrowWithMessage(ReferenceError, "'beforeContinueTry' is not defined");
- expect(() => {
- continueTry;
- }).toThrowWithMessage(ReferenceError, "'continueTry' is not defined");
- expect(() => {
- innerFinally1;
- }).toThrowWithMessage(ReferenceError, "'innerFinally1' is not defined");
- expect(() => {
- innerFinally2;
- }).toThrowWithMessage(ReferenceError, "'innerFinally2' is not defined");
- expect(() => {
- innerFinally3;
- }).toThrowWithMessage(ReferenceError, "'innerFinally3' is not defined");
- expect(() => {
- innerFinally4;
- }).toThrowWithMessage(ReferenceError, "'innerFinally4' is not defined");
- expect(foo).toBe(0);
- executionOrder.push(7);
- } finally {
- const innerFinally5 = 13;
- expect(() => {
- foo;
- }).toThrowWithMessage(ReferenceError, "'foo' is not defined");
- expect(() => {
- j;
- }).toThrowWithMessage(ReferenceError, "'j' is not defined");
- expect(() => {
- bar;
- }).toThrowWithMessage(ReferenceError, "'bar' is not defined");
- expect(() => {
- baz;
- }).toThrowWithMessage(ReferenceError, "'baz' is not defined");
- expect(() => {
- i;
- }).toThrowWithMessage(ReferenceError, "'i' is not defined");
- expect(() => {
- serenity;
- }).toThrowWithMessage(ReferenceError, "'serenity' is not defined");
- expect(() => {
- whf;
- }).toThrowWithMessage(ReferenceError, "'whf' is not defined");
- expect(() => {
- beforeContinueTry;
- }).toThrowWithMessage(ReferenceError, "'beforeContinueTry' is not defined");
- expect(() => {
- continueTry;
- }).toThrowWithMessage(ReferenceError, "'continueTry' is not defined");
- expect(() => {
- innerFinally1;
- }).toThrowWithMessage(ReferenceError, "'innerFinally1' is not defined");
- expect(() => {
- innerFinally2;
- }).toThrowWithMessage(ReferenceError, "'innerFinally2' is not defined");
- expect(() => {
- innerFinally3;
- }).toThrowWithMessage(ReferenceError, "'innerFinally3' is not defined");
- expect(() => {
- innerFinally4;
- }).toThrowWithMessage(ReferenceError, "'innerFinally4' is not defined");
- expect(innerFinally5).toBe(13);
- executionOrder.push(8);
- }
- expect(() => {
- foo;
- }).toThrowWithMessage(ReferenceError, "'foo' is not defined");
- expect(() => {
- j;
- }).toThrowWithMessage(ReferenceError, "'j' is not defined");
- expect(() => {
- bar;
- }).toThrowWithMessage(ReferenceError, "'bar' is not defined");
- expect(() => {
- baz;
- }).toThrowWithMessage(ReferenceError, "'baz' is not defined");
- expect(() => {
- i;
- }).toThrowWithMessage(ReferenceError, "'i' is not defined");
- expect(() => {
- serenity;
- }).toThrowWithMessage(ReferenceError, "'serenity' is not defined");
- expect(() => {
- whf;
- }).toThrowWithMessage(ReferenceError, "'whf' is not defined");
- expect(() => {
- beforeContinueTry;
- }).toThrowWithMessage(ReferenceError, "'beforeContinueTry' is not defined");
- expect(() => {
- continueTry;
- }).toThrowWithMessage(ReferenceError, "'continueTry' is not defined");
- expect(() => {
- innerFinally1;
- }).toThrowWithMessage(ReferenceError, "'innerFinally1' is not defined");
- expect(() => {
- innerFinally2;
- }).toThrowWithMessage(ReferenceError, "'innerFinally2' is not defined");
- expect(() => {
- innerFinally3;
- }).toThrowWithMessage(ReferenceError, "'innerFinally3' is not defined");
- expect(() => {
- innerFinally4;
- }).toThrowWithMessage(ReferenceError, "'innerFinally4' is not defined");
- expect(() => {
- innerFinally5;
- }).toThrowWithMessage(ReferenceError, "'innerFinally5' is not defined");
- expect(executionOrder).toEqual([1, 2, 3, 4, 5, 6, 7, 8]);
- });
- test("labelled continue in finally overrides labelled continue in try", () => {
- const executionOrder = [];
- function callFromUpdateBlock(i) {
- expect(i).toBe(2);
- executionOrder.push(3);
- }
- function callFromTestBlock(i) {
- expect(i).toBe(2);
- executionOrder.push(4);
- return false;
- }
- outer: for (let i = 1; i >= 2 ? callFromTestBlock(i) : true; ++i, callFromUpdateBlock(i)) {
- inner: for (const j = 2; ; expect().fail("Jumped to inner for loop update block")) {
- try {
- executionOrder.push(1);
- continue inner;
- } finally {
- executionOrder.push(2);
- continue outer;
- }
- expect().fail("Running code after try block");
- }
- expect().fail("Running code after inner for loop");
- }
- expect(executionOrder).toEqual([1, 2, 3, 4]);
- });
|