prepack
Version:
Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.
52 lines (39 loc) • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _index = require("../values/index.js");
var _singletons = require("../singletons.js");
/**
* 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.2.13
function _default(ast, strictCode, env, realm) {
// 1. Let oldEnv be the running execution context's LexicalEnvironment.
let oldEnv = realm.getRunningContext().lexicalEnvironment; // 2. Let blockEnv be NewDeclarativeEnvironment(oldEnv).
let blockEnv = _singletons.Environment.NewDeclarativeEnvironment(realm, oldEnv); // 3. Perform BlockDeclarationInstantiation(StatementList, blockEnv).
_singletons.Environment.BlockDeclarationInstantiation(realm, strictCode, ast.body, blockEnv); // 4. Set the running execution context's LexicalEnvironment to blockEnv.
realm.getRunningContext().lexicalEnvironment = blockEnv;
try {
// 5. Let blockValue be the result of evaluating StatementList.
let blockValue;
if (ast.directives) {
for (let directive of ast.directives) {
blockValue = new _index.StringValue(realm, directive.value.value);
}
}
return _singletons.Functions.EvaluateStatements(ast.body, blockValue, strictCode, blockEnv, realm);
} finally {
// 6. Set the running execution context's LexicalEnvironment to oldEnv.
realm.getRunningContext().lexicalEnvironment = oldEnv;
realm.onDestroyScope(blockEnv);
}
}
//# sourceMappingURL=BlockStatement.js.map