1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 12:37:45 +00:00

LibJS: Integrate labels into the Interpreter

The interpreter now considers a statement or block's label when
considering whether or not to break. All statements can be labelled.
This commit is contained in:
Matthew Olsson 2020-05-28 13:36:59 -07:00 committed by Andreas Kling
parent 03615a7872
commit d52ea37717
6 changed files with 87 additions and 21 deletions

View file

@ -25,9 +25,13 @@ function bar() {
}
function foo() {
label:
for (var i = 0; i < 4; i++) {
break // semicolon inserted here
continue // semicolon inserted here
break label // semicolon inserted here
continue label // semicolon inserted here
}
var j // semicolon inserted here
@ -39,8 +43,25 @@ function foo() {
1;
var curly/* semicolon inserted here */}
function baz() {
let counter = 0;
let outer;
outer:
for (let i = 0; i < 5; ++i) {
for (let j = 0; j < 5; ++j) {
continue // semicolon inserted here
outer // semicolon inserted here
}
counter++;
}
return counter;
}
try {
assert(foo() === undefined);
assert(baz() === 5);
console.log("PASS");
} catch (e) {

View file

@ -1,12 +1,42 @@
load("test-common.js");
try {
test:
{
test: {
let o = 1;
assert(o === 1);
break test;
assertNotReached();
}
outer: {
{
break outer;
}
assertNotReached();
}
let counter = 0;
outer:
for (a of [1, 2, 3]) {
for (b of [4, 5, 6]) {
if (a === 2 && b === 5)
break outer;
counter++;
}
}
assert(counter === 4);
let counter = 0;
outer:
for (a of [1, 2, 3]) {
for (b of [4, 5, 6]) {
if (b === 6)
continue outer;
counter++;
}
}
assert(counter === 6);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);