prepack
Version:
Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.
84 lines (64 loc) • 3.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _index = require("../values/index.js");
var _completions = require("../completions.js");
var _invariant = _interopRequireDefault(require("../invariant.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// ECMA262 13.13.14
function LabelledEvaluation(labelSet, ast, strictCode, env, realm) {
// LabelledStatement:LabelIdentifier:LabelledItem
switch (ast.type) {
case "LabeledStatement":
let labeledAst = ast; // 1. Let label be the StringValue of LabelIdentifier.
let label = labeledAst.label.name; // 2. Append label as an element of labelSet.
labelSet.push(label); // 3. Let stmtResult be LabelledEvaluation of LabelledItem with argument labelSet.
let normalCompletionStmtResult;
try {
normalCompletionStmtResult = LabelledEvaluation(labelSet, labeledAst.body, strictCode, env, realm);
} catch (stmtResult) {
// 4. If stmtResult.[[Type]] is break and SameValue(stmtResult.[[Target]], label) is true, then
if (stmtResult instanceof _completions.BreakCompletion && stmtResult.target === label) {
// a. Let stmtResult be NormalCompletion(stmtResult.[[Value]]).
normalCompletionStmtResult = stmtResult.value;
} else if (stmtResult instanceof _completions.JoinedAbruptCompletions || stmtResult instanceof _completions.JoinedNormalAndAbruptCompletions) {
let nc = _completions.Completion.normalizeSelectedCompletions(c => c instanceof _completions.BreakCompletion && c.target === label, stmtResult);
return realm.returnOrThrowCompletion(nc);
} else {
// 5. Return Completion(stmtResult).
throw stmtResult;
}
} // 5. Return Completion(stmtResult).
return normalCompletionStmtResult;
case "VariableDeclaration":
if (ast.kind === "var") {
let r = env.evaluate(ast, strictCode);
(0, _invariant.default)(r instanceof _index.Value);
return r;
}
// fall through to throw
case "FunctionDeclaration":
case "ClassDeclaration":
throw realm.createErrorThrowCompletion(realm.intrinsics.SyntaxError, ast.type + " may not have a label");
default:
let r = env.evaluate(ast, strictCode, labelSet);
(0, _invariant.default)(r instanceof _index.Value);
return r;
}
} // ECMA262 13.13.15
function _default(ast, strictCode, env, realm) {
//1. Let newLabelSet be a new empty List.
let newLabelSet = []; //2. Return LabelledEvaluation of this LabelledStatement with argument newLabelSet.
return LabelledEvaluation(newLabelSet, ast, strictCode, env, realm);
}
//# sourceMappingURL=LabeledStatement.js.map