Files
2023-08-01 13:49:46 +02:00

123 lines
9.1 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _index = require("./index.js");
var _is = require("../methods/is.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 }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* 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.
*/
var ArrayValue = function (_ObjectValue) {
_inherits(ArrayValue, _ObjectValue);
function ArrayValue(realm, intrinsicName) {
_classCallCheck(this, ArrayValue);
return _possibleConstructorReturn(this, (ArrayValue.__proto__ || Object.getPrototypeOf(ArrayValue)).call(this, realm, realm.intrinsics.ArrayPrototype, intrinsicName));
}
_createClass(ArrayValue, [{
key: "getKind",
value: function getKind() {
return "Array";
}
}, {
key: "isSimpleObject",
value: function isSimpleObject() {
return this.$TypedArrayName === undefined;
}
// ECMA262 9.4.2.1
}, {
key: "$DefineOwnProperty",
value: function $DefineOwnProperty(P, Desc) {
var A = this;
// 1. Assert: IsPropertyKey(P) is true.
(0, _invariant2.default)((0, _is.IsPropertyKey)(this.$Realm, P), "expected a property key");
// 2. If P is "length", then
if (P === "length" || P instanceof _index.StringValue && P.value === "length") {
// a. Return ? ArraySetLength(A, Desc).
return _singletons.Properties.ArraySetLength(this.$Realm, A, Desc);
} else if ((0, _is.IsArrayIndex)(this.$Realm, P)) {
// 3. Else if P is an array index, then
// a. Let oldLenDesc be OrdinaryGetOwnProperty(A, "length").
var oldLenDesc = _singletons.Properties.OrdinaryGetOwnProperty(this.$Realm, A, "length");
// b. Assert: oldLenDesc will never be undefined or an accessor descriptor because Array objects are
// created with a length data property that cannot be deleted or reconfigured.
(0, _invariant2.default)(oldLenDesc !== undefined && !(0, _is.IsAccessorDescriptor)(this.$Realm, oldLenDesc), "cannot be undefined or an accessor descriptor");
_singletons.Properties.ThrowIfMightHaveBeenDeleted(oldLenDesc.value);
// c. Let oldLen be oldLenDesc.[[Value]].
var oldLen = oldLenDesc.value;
(0, _invariant2.default)(oldLen instanceof _index.Value);
oldLen = oldLen.throwIfNotConcrete();
(0, _invariant2.default)(oldLen instanceof _index.NumberValue, "expected number value");
oldLen = oldLen.value;
// d. Let index be ! ToUint32(P).
var index = _singletons.To.ToUint32(this.$Realm, typeof P === "string" ? new _index.StringValue(this.$Realm, P) : P);
// e. If index ≥ oldLen and oldLenDesc.[[Writable]] is false, return false.
if (index >= oldLen && oldLenDesc.writable === false) return false;
// f. Let succeeded be ! OrdinaryDefineOwnProperty(A, P, Desc).
var succeeded = _singletons.Properties.OrdinaryDefineOwnProperty(this.$Realm, A, P, Desc);
// g. If succeeded is false, return false.
if (succeeded === false) return false;
// h. If index ≥ oldLen, then
if (index >= oldLen) {
// i. Set oldLenDesc.[[Value]] to index + 1.
oldLenDesc.value = new _index.NumberValue(this.$Realm, index + 1);
// ii. Let succeeded be OrdinaryDefineOwnProperty(A, "length", oldLenDesc).
succeeded = _singletons.Properties.OrdinaryDefineOwnProperty(this.$Realm, A, "length", oldLenDesc);
// iii. Assert: succeeded is true.
(0, _invariant2.default)(succeeded, "expected length definition to succeed");
}
// i. Return true.
return true;
}
// 1. Return OrdinaryDefineOwnProperty(A, P, Desc).
return _singletons.Properties.OrdinaryDefineOwnProperty(this.$Realm, A, P, Desc);
}
}]);
return ArrayValue;
}(_index.ObjectValue);
exports.default = ArrayValue;
//# sourceMappingURL=ArrayValue.js.map