Fix unlabelled break (#419)

This commit is contained in:
Herman Venter 2017-04-18 13:57:23 -07:00 committed by GitHub
parent a3a91c738e
commit 90b04fc703
4 changed files with 16 additions and 5 deletions

View File

@ -17,7 +17,7 @@ import { AbruptCompletion, NormalCompletion, PossiblyNormalCompletion, Introspec
import { Reference } from "../environment.js";
import { EmptyValue, StringValue, Value } from "../values/index.js";
import { joinPossiblyNormalCompletions, joinPossiblyNormalCompletionWithAbruptCompletion,
NewDeclarativeEnvironment, BlockDeclarationInstantiation } from "../methods/index.js";
NewDeclarativeEnvironment, BlockDeclarationInstantiation, UpdateEmpty } from "../methods/index.js";
import invariant from "../invariant.js";
// ECMA262 13.2.13
@ -50,7 +50,8 @@ export default function (ast: BabelNodeBlockStatement, strictCode: boolean, env:
invariant(!(res instanceof Reference));
if (!(res instanceof EmptyValue)) {
if (blockValue === undefined || blockValue instanceof Value) {
if (res instanceof AbruptCompletion) throw res;
if (res instanceof AbruptCompletion)
throw UpdateEmpty(realm, res, blockValue || realm.intrinsics.empty);
invariant(res instanceof NormalCompletion || res instanceof Value);
blockValue = res;
} else {

View File

@ -16,7 +16,7 @@ import type { Reference } from "../environment.js";
import { EmptyValue } from "../values/index.js";
import { ToBooleanPartial, GetValue, UpdateEmpty } from "../methods/index.js";
import { LoopContinues, InternalGetResultValue } from "./ForOfStatement.js";
import { AbruptCompletion } from "../completions.js";
import { AbruptCompletion, BreakCompletion } from "../completions.js";
import invariant from "../invariant.js";
import type { BabelNodeDoWhileStatement } from "babel-types";
@ -34,6 +34,11 @@ export default function (ast: BabelNodeDoWhileStatement, strictCode: boolean, en
// b. If LoopContinues(stmt, labelSet) is false, return Completion(UpdateEmpty(stmt, V)).
if (LoopContinues(realm, stmt, labelSet) === false) {
invariant(stmt instanceof AbruptCompletion);
// ECMA262 13.1.7
if (stmt instanceof BreakCompletion) {
if (!stmt.target)
return (UpdateEmpty(realm, stmt, V): any).value;
}
throw UpdateEmpty(realm, stmt, V);
}

View File

@ -12,7 +12,7 @@
import type { LexicalEnvironment, Reference } from "../environment.js";
import type { Realm } from "../realm.js";
import { Value, EmptyValue } from "../values/index.js";
import { AbruptCompletion } from "../completions.js";
import { AbruptCompletion, BreakCompletion } from "../completions.js";
import { BoundNames, NewDeclarativeEnvironment, GetValue, ToBooleanPartial, UpdateEmpty } from "../methods/index.js";
import { LoopContinues, InternalGetResultValue } from "./ForOfStatement.js";
import invariant from "../invariant.js";
@ -79,6 +79,11 @@ function ForBodyEvaluation(realm: Realm, test, increment, stmt, perIterationBind
// c. If LoopContinues(result, labelSet) is false, return Completion(UpdateEmpty(result, V)).
if (!LoopContinues(realm, result, labelSet)) {
invariant(result instanceof AbruptCompletion);
// ECMA262 13.1.7
if (result instanceof BreakCompletion) {
if (!result.target)
return (UpdateEmpty(realm, result, V): any).value;
}
throw UpdateEmpty(realm, result, V);
}

View File

@ -613,7 +613,7 @@ function handleFinished(
// exit status
if (args.timeout === 10) numPassedES5 += 4;
if (!args.filterString && (numPassedES5 < 22638 || numPassedES6 < 7446)) {
if (!args.filterString && (numPassedES5 < 22763 || numPassedES6 < 7456)) {
console.log(chalk.red("Overall failure. Expected more tests to pass!"));
return 1;
} else {