prepack
Version:
Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.
79 lines (53 loc) • 3.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = SuperProperty;
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 MakeSuperPropertyReference(realm, propertyKey, strict) {
// 1. Let env be GetThisEnvironment( ).
let env = _singletons.Environment.GetThisEnvironment(realm);
(0, _invariant.default)(env instanceof _environment.FunctionEnvironmentRecord); // 2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
if (!env.HasSuperBinding()) {
throw realm.createErrorThrowCompletion(realm.intrinsics.ReferenceError, "env does not have super binding");
} // 3. Let actualThis be env.GetThisBinding().
let actualThis = env.GetThisBinding(); // 4. ReturnIfAbrupt(actualThis).
// 5. Let baseValue be env.GetSuperBase().
let baseValue = env.GetSuperBase(); // 6. Let bv be RequireObjectCoercible(baseValue).
let bv = (0, _index2.RequireObjectCoercible)(realm, baseValue); // 7. ReturnIfAbrupt(bv).
// 8. Return a value of type Reference that is a Super Reference whose base value is bv, whose referenced name is propertyKey, whose thisValue is actualThis, and whose strict reference flag is strict.
return new _environment.Reference(bv, propertyKey, strict, actualThis);
} // ECMA262 12.3.5.1
function SuperProperty(ast, strictCode, env, realm) {
// SuperProperty : super [ Expression ]
if (ast.computed === true) {
// 1. Let propertyNameReference be the result of evaluating Expression.
let propertyNameReference = env.evaluate(ast.property, strictCode); // 2. Let propertyNameValue be GetValue(propertyNameReference).
let propertyNameValue = _singletons.Environment.GetValue(realm, propertyNameReference); // 3. Let propertyKey be ToPropertyKey(propertyNameValue).
let propertyKey = _singletons.To.ToPropertyKeyPartial(realm, propertyNameValue); // 4. ReturnIfAbrupt(propertyKey).
// 5. If the code matched by the syntactic production that is being evaluated is strict mode code, let strict be true, else let strict be false.
let strict = strictCode; // 6. Return MakeSuperPropertyReference(propertyKey, strict).
return MakeSuperPropertyReference(realm, propertyKey, strict);
} else {
// SuperProperty : super . IdentifierName
// 1. Let propertyKey be StringValue of IdentifierName.
let propertyKey = new _index.StringValue(realm, ast.property.name); // 2. If the code matched by the syntactic production that is being evaluated is strict mode code, let strict be true, else let strict be false.
let strict = strictCode; // 3. Return MakeSuperPropertyReference(propertyKey, strict).
return MakeSuperPropertyReference(realm, propertyKey, strict);
}
}
//# sourceMappingURL=SuperProperty.js.map