prepack
Version:
Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.
60 lines (43 loc) • 2.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (ast, strictCode, env, realm, thrownValue) {
(0, _invariant2.default)(thrownValue instanceof _completions.ThrowCompletion, "Metadata isn't a throw completion");
// 1. Let oldEnv be the running execution context's LexicalEnvironment.
let oldEnv = realm.getRunningContext().lexicalEnvironment;
// 2. Let catchEnv be NewDeclarativeEnvironment(oldEnv).
let catchEnv = _singletons.Environment.NewDeclarativeEnvironment(realm, oldEnv);
// 3. Let catchEnvRec be catchEnv's EnvironmentRecord.
let catchEnvRec = catchEnv.environmentRecord;
// 4. For each element argName of the BoundNames of CatchParameter, do
for (let argName of _singletons.Environment.BoundNames(realm, ast.param)) {
// a. Perform ! catchEnvRec.CreateMutableBinding(argName, false).
catchEnvRec.CreateMutableBinding(argName, false);
}
// 5. Set the running execution context's LexicalEnvironment to catchEnv.
realm.getRunningContext().lexicalEnvironment = catchEnv;
try {
// 6. Let status be the result of performing BindingInitialization for CatchParameter passing thrownValue and catchEnv as arguments.
_singletons.Environment.BindingInitialization(realm, ast.param, thrownValue.value, strictCode, catchEnv);
// 7. If status is an abrupt completion, then
// a. Set the running execution context's LexicalEnvironment to oldEnv.
// b. Return Completion(status).
// 8. Let B be the result of evaluating Block.
let B = catchEnv.evaluate(ast.body, strictCode);
(0, _invariant2.default)(B instanceof _index.Value);
// 10. Return Completion(B).
return B;
} finally {
// 9. Set the running execution context's LexicalEnvironment to oldEnv.
realm.getRunningContext().lexicalEnvironment = oldEnv;
realm.onDestroyScope(catchEnv);
}
};
var _index = require("../values/index.js");
var _completions = require("../completions.js");
var _invariant = require("../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _singletons = require("../singletons.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//# sourceMappingURL=CatchClause.js.map