76 lines
2.7 KiB
JavaScript
76 lines
2.7 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
|
|
exports.default = function (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.
|
|
var strict = strictCode || (0, _strict3.default)(ast.body);
|
|
|
|
// 2. Let name be StringValue of BindingIdentifier.
|
|
var name = void 0;
|
|
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).
|
|
var F = _singletons.Functions.GeneratorFunctionCreate(realm, "normal", ast.params, ast.body, env, strict);
|
|
|
|
// 4. Let prototype be ObjectCreate(%GeneratorPrototype%).
|
|
var 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", {
|
|
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.
|
|
var _strict = strictCode || (0, _strict3.default)(ast.body);
|
|
|
|
// 2. Let name be StringValue of BindingIdentifier.
|
|
var _name = void 0;
|
|
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).
|
|
var _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;
|
|
}
|
|
};
|
|
|
|
var _construct = require("../methods/construct.js");
|
|
|
|
var _singletons = require("../singletons.js");
|
|
|
|
var _index = require("../values/index.js");
|
|
|
|
var _strict2 = require("../utils/strict.js");
|
|
|
|
var _strict3 = _interopRequireDefault(_strict2);
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
//# sourceMappingURL=FunctionDeclaration.js.map
|