prepack
Version:
Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.
75 lines (49 loc) • 2.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = SuperCall;
var _environment = require("../environment.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 */
function GetSuperConstructor(realm) {
// 1. Let envRec be GetThisEnvironment( ).
let envRec = _singletons.Environment.GetThisEnvironment(realm); // 2. Assert: envRec is a function Environment Record.
(0, _invariant.default)(envRec instanceof _environment.FunctionEnvironmentRecord); // 3. Let activeFunction be envRec.[[FunctionObject]].
let activeFunction = envRec.$FunctionObject; // 4. Let superConstructor be activeFunction.[[GetPrototypeOf]]().
let superConstructor = activeFunction.$GetPrototypeOf(); // 5. ReturnIfAbrupt(superConstructor).
// 6. If IsConstructor(superConstructor) is false, throw a TypeError exception.
if (!(0, _index2.IsConstructor)(realm, superConstructor)) {
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "super called outside of constructor");
}
(0, _invariant.default)(superConstructor instanceof _index.ObjectValue); // 7. Return superConstructor.
return superConstructor;
} // ECMA262 12.3.5.1
function SuperCall(Arguments, strictCode, env, realm) {
// 1. Let newTarget be GetNewTarget().
let newTarget = (0, _index2.GetNewTarget)(realm); // 2. If newTarget is undefined, throw a ReferenceError exception.
if (newTarget instanceof _index.UndefinedValue) {
throw realm.createErrorThrowCompletion(realm.intrinsics.ReferenceError, "newTarget is undefined");
} // 3. Let func be GetSuperConstructor().
let func = GetSuperConstructor(realm); // 4. ReturnIfAbrupt(func).
// 5. Let argList be ArgumentListEvaluation of Arguments.
let argList = (0, _index2.ArgumentListEvaluation)(realm, strictCode, env, Arguments); // 6. ReturnIfAbrupt(argList).
// 7. Let result be Construct(func, argList, newTarget).
let result = (0, _index2.Construct)(realm, func, argList, newTarget).throwIfNotConcreteObject(); // 8. ReturnIfAbrupt(result).
// 9. Let thisER be GetThisEnvironment( ).
let thisER = _singletons.Environment.GetThisEnvironment(realm); // 10. Return thisER.BindThisValue(result).
return thisER.BindThisValue(result);
}
//# sourceMappingURL=SuperCall.js.map