prepack
Version:
Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.
75 lines (53 loc) • 2.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
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 = _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.
*/
/* strict-local */
// ECMA262 13.11.7
function _default(ast, strictCode, env, realm) {
// 1. Let val be the result of evaluating Expression.
let 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()) {
let loc = ast.object.loc;
let error = new _errors.CompilerDiagnostic("with object must be a known value", loc, "PP0007", "RecoverableError");
if (realm.handleError(error) === "Fail") throw new _errors.FatalError();
}
let obj = _singletons.To.ToObject(realm, val); // 3. Let oldEnv be the running execution context's LexicalEnvironment.
let oldEnv = env; // 4. Let newEnv be NewObjectEnvironment(obj, oldEnv).
let newEnv = _singletons.Environment.NewObjectEnvironment(realm, obj, oldEnv); // 5. Set the withEnvironment flag of newEnv's EnvironmentRecord to true.
(0, _invariant.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.
let C = newEnv.evaluateCompletion(ast.body, strictCode);
(0, _invariant.default)(C instanceof _index.Value || C instanceof _completions.AbruptCompletion); // 9. Return Completion(UpdateEmpty(C, undefined)).
let res = (0, _index2.UpdateEmpty)(realm, C, realm.intrinsics.undefined);
if (res instanceof _completions.AbruptCompletion) throw res;
(0, _invariant.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);
}
}
//# sourceMappingURL=WithStatement.js.map