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

67 lines
2.5 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (ast, strictCode, env, realm) {
// 1. Let val be the result of evaluating Expression.
var val = env.evaluate(ast.object, strictCode);
// 2. Let obj be ? ToObject(? GetValue(val)).
val = _singletons.Environment.GetValue(realm, val);
if (val instanceof _index.AbstractValue || val instanceof _index.ObjectValue && val.isPartialObject()) {
var loc = ast.object.loc;
var error = new _errors.CompilerDiagnostic("with object must be a known value", loc, "PP0007", "RecoverableError");
if (realm.handleError(error) === "Fail") throw new _errors.FatalError();
}
var obj = _singletons.To.ToObjectPartial(realm, val);
// 3. Let oldEnv be the running execution context's LexicalEnvironment.
var oldEnv = env;
// 4. Let newEnv be NewObjectEnvironment(obj, oldEnv).
var newEnv = _singletons.Environment.NewObjectEnvironment(realm, obj, oldEnv);
// 5. Set the withEnvironment flag of newEnv's EnvironmentRecord to true.
(0, _invariant2.default)(newEnv.environmentRecord instanceof _environment.ObjectEnvironmentRecord);
newEnv.environmentRecord.withEnvironment = true;
// 6. Set the running execution context's LexicalEnvironment to newEnv.
realm.getRunningContext().lexicalEnvironment = newEnv;
try {
// 7. Let C be the result of evaluating Statement.
var C = newEnv.evaluateCompletion(ast.body, strictCode);
(0, _invariant2.default)(C instanceof _index.Value || C instanceof _completions.AbruptCompletion);
// 9. Return Completion(UpdateEmpty(C, undefined)).
var res = (0, _index2.UpdateEmpty)(realm, C, realm.intrinsics.undefined);
if (res instanceof _completions.AbruptCompletion) throw res;
(0, _invariant2.default)(res instanceof _index.Value);
return res;
} finally {
// 8. Set the running execution context's LexicalEnvironment to oldEnv.
realm.getRunningContext().lexicalEnvironment = oldEnv;
realm.onDestroyScope(newEnv);
}
};
var _environment = require("../environment.js");
var _errors = require("../errors.js");
var _completions = require("../completions.js");
var _index = require("../values/index.js");
var _index2 = require("../methods/index.js");
var _singletons = require("../singletons.js");
var _invariant = require("../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//# sourceMappingURL=WithStatement.js.map