prepack
Version:
Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.
87 lines (57 loc) • 3.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _construct = require("../methods/construct.js");
var _singletons = require("../singletons.js");
var _index = require("../values/index.js");
var _strict = _interopRequireDefault(require("../utils/strict.js"));
var _descriptors = require("../descriptors.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 14.1.20
function _default(ast, strictCode, env, realm) {
if (ast.generator) {
// 1. If the function code for GeneratorDeclaration is strict mode code, let strict be true. Otherwise let strict be false.
let strict = strictCode || (0, _strict.default)(ast.body); // 2. Let name be StringValue of BindingIdentifier.
let name;
if (ast.id) {
name = new _index.StringValue(realm, ast.id.name);
} else {
name = new _index.StringValue(realm, "default");
} // 3. Let F be GeneratorFunctionCreate(Normal, FormalParameters, GeneratorBody, scope, strict).
let F = _singletons.Functions.GeneratorFunctionCreate(realm, "normal", ast.params, ast.body, env, strict); // 4. Let prototype be ObjectCreate(%GeneratorPrototype%).
let prototype = _singletons.Create.ObjectCreate(realm, realm.intrinsics.GeneratorPrototype); // 5. Perform DefinePropertyOrThrow(F, "prototype", PropertyDescriptor{[[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false}).
_singletons.Properties.DefinePropertyOrThrow(realm, F, "prototype", new _descriptors.PropertyDescriptor({
value: prototype,
writable: true,
configurable: false
})); // 6. Perform SetFunctionName(F, name).
_singletons.Functions.SetFunctionName(realm, F, name); // 7 .Return F.
return F;
} else {
// 1. If the function code for FunctionDeclaration is strict mode code, let strict be true. Otherwise let strict be false.
let strict = strictCode || (0, _strict.default)(ast.body); // 2. Let name be StringValue of BindingIdentifier.
let name;
if (ast.id) {
name = new _index.StringValue(realm, ast.id.name);
} else {
name = new _index.StringValue(realm, "default");
} // 3. Let F be FunctionCreate(Normal, FormalParameters, FunctionBody, scope, strict).
let F = _singletons.Functions.FunctionCreate(realm, "normal", ast.params, ast.body, env, strict);
if (ast.id && ast.id.name) F.__originalName = ast.id.name; // 4. Perform MakeConstructor(F).
(0, _construct.MakeConstructor)(realm, F); // 5. Perform SetFunctionName(F, name).
_singletons.Functions.SetFunctionName(realm, F, name); // 6. Return F.
return F;
}
}
//# sourceMappingURL=FunctionDeclaration.js.map