Files
asciidisco.com/build/node_modules/prepack/lib/evaluators/CatchClause.js
2023-08-01 13:49:46 +02:00

82 lines
2.8 KiB
JavaScript

"use strict";
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.
var oldEnv = realm.getRunningContext().lexicalEnvironment;
// 2. Let catchEnv be NewDeclarativeEnvironment(oldEnv).
var catchEnv = _singletons.Environment.NewDeclarativeEnvironment(realm, oldEnv);
// 3. Let catchEnvRec be catchEnv's EnvironmentRecord.
var catchEnvRec = catchEnv.environmentRecord;
// 4. For each element argName of the BoundNames of CatchParameter, do
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = _singletons.Environment.BoundNames(realm, ast.param)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var argName = _step.value;
// a. Perform ! catchEnvRec.CreateMutableBinding(argName, false).
catchEnvRec.CreateMutableBinding(argName, false);
}
// 5. Set the running execution context's LexicalEnvironment to catchEnv.
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
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.
var 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