87 lines
2.8 KiB
JavaScript
87 lines
2.8 KiB
JavaScript
"use strict";
|
|
|
|
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 = require("../invariant.js");
|
|
|
|
var _invariant2 = _interopRequireDefault(_invariant);
|
|
|
|
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.
|
|
*/
|
|
|
|
function GetSuperConstructor(realm) {
|
|
// 1. Let envRec be GetThisEnvironment( ).
|
|
var envRec = _singletons.Environment.GetThisEnvironment(realm);
|
|
|
|
// 2. Assert: envRec is a function Environment Record.
|
|
(0, _invariant2.default)(envRec instanceof _environment.FunctionEnvironmentRecord);
|
|
|
|
// 3. Let activeFunction be envRec.[[FunctionObject]].
|
|
var activeFunction = envRec.$FunctionObject;
|
|
|
|
// 4. Let superConstructor be activeFunction.[[GetPrototypeOf]]().
|
|
var 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, _invariant2.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().
|
|
var 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().
|
|
var func = GetSuperConstructor(realm);
|
|
|
|
// 4. ReturnIfAbrupt(func).
|
|
|
|
// 5. Let argList be ArgumentListEvaluation of Arguments.
|
|
var argList = (0, _index2.ArgumentListEvaluation)(realm, strictCode, env, Arguments);
|
|
|
|
// 6. ReturnIfAbrupt(argList).
|
|
|
|
// 7. Let result be Construct(func, argList, newTarget).
|
|
var result = (0, _index2.Construct)(realm, func, argList, newTarget);
|
|
|
|
// 8. ReturnIfAbrupt(result).
|
|
|
|
// 9. Let thisER be GetThisEnvironment( ).
|
|
var thisER = _singletons.Environment.GetThisEnvironment(realm);
|
|
|
|
// 10. Return thisER.BindThisValue(result).
|
|
return thisER.BindThisValue(result);
|
|
}
|
|
//# sourceMappingURL=SuperCall.js.map
|