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

226 lines
12 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("../values/index.js");
var _is = require("../methods/is.js");
var _singletons = require("../singletons.js");
var _invariant = require("../invariant");
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 StringExotic = function (_ObjectValue) {
_inherits(StringExotic, _ObjectValue);
function StringExotic(realm, intrinsicName) {
_classCallCheck(this, StringExotic);
return _possibleConstructorReturn(this, (StringExotic.__proto__ || Object.getPrototypeOf(StringExotic)).call(this, realm, realm.intrinsics.StringPrototype, intrinsicName));
}
// ECMA262 9.4.3.1
_createClass(StringExotic, [{
key: "$GetOwnProperty",
value: function $GetOwnProperty(P) {
// 1. Assert: IsPropertyKey(P) is true.
// 2. Let desc be OrdinaryGetOwnProperty(S, P).
var desc = _singletons.Properties.OrdinaryGetOwnProperty(this.$Realm, this, P);
// 3. If desc is not undefined, return desc.
if (desc !== undefined) {
_singletons.Properties.ThrowIfMightHaveBeenDeleted(desc.value);
return desc;
}
// 4. If Type(P) is not String, return undefined.
if (typeof P !== "string" && !(P instanceof _index.StringValue)) return undefined;
// 5. Let index be ! CanonicalNumericIndexString(P).
var index = _singletons.To.CanonicalNumericIndexString(this.$Realm, typeof P === "string" ? new _index.StringValue(this.$Realm, P) : P);
// 6. If index is undefined, return undefined.
if (index === undefined || index === null) return undefined;
// 7. If IsInteger(index) is false, return undefined.
if ((0, _is.IsInteger)(this.$Realm, index) === false) return undefined;
// 8. If index = -0, return undefined.
if (1.0 / index === -Infinity) return undefined;
// 9. Let str be the String value of S.[[StringData]].
var str = this.$StringData;
(0, _invariant2.default)(str);
str = str.throwIfNotConcreteString();
// 10. Let len be the number of elements in str.
var len = str.value.length;
// 11. If index < 0 or len ≤ index, return undefined.
if (index < 0 || len <= index) return undefined;
// 12. Let resultStr be a String value of length 1, containing one code unit from str, specifically the code unit at index index.
var resultStr = new _index.StringValue(this.$Realm, str.value.charAt(index));
// 13. Return a PropertyDescriptor{[[Value]]: resultStr, [[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false}.
return {
value: resultStr,
writable: false,
enumerable: true,
configurable: false
};
}
// ECMA262 9.4.3.2
}, {
key: "$OwnPropertyKeys",
value: function $OwnPropertyKeys() {
var _this2 = this;
// 1. Let keys be a new empty List.
var keys = [];
// 2. Let str be the String value of O.[[StringData]].
var str = this.$StringData;
(0, _invariant2.default)(str);
str = str.throwIfNotConcreteString();
// 3. Let len be the number of elements in str.
var len = str.value.length;
// 4. For each integer i starting with 0 such that i < len, in ascending order,
for (var i = 0; i < len; ++i) {
// a. Add ! ToString(i) as the last element of keys.
keys.push(new _index.StringValue(this.$Realm, _singletons.To.ToString(this.$Realm, new _index.NumberValue(this.$Realm, i))));
}
// 5. For each own property key P of O such that P is an integer index and ToInteger(P) ≥ len, in ascending numeric index order,
var properties = this.getOwnPropertyKeysArray();
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = properties.filter(function (x) {
return (0, _is.IsArrayIndex)(_this2.$Realm, x);
}).map(function (x) {
return parseInt(x, 10);
}).filter(function (x) {
return _singletons.To.ToInteger(_this2.$Realm, x) >= len;
}).sort(function (x, y) {
return x - y;
})[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var key = _step.value;
// i. Add P as the last element of keys.
keys.push(new _index.StringValue(this.$Realm, key + ""));
}
// 6. For each own property key P of O such that Type(P) is String and P is not an integer index, in ascending chronological order of property creation,
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = properties.filter(function (x) {
return !(0, _is.IsArrayIndex)(_this2.$Realm, x);
})[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _key = _step2.value;
// i. Add P as the last element of keys.
keys.push(new _index.StringValue(this.$Realm, _key));
}
// 7. For each own property key P of O such that Type(P) is Symbol, in ascending chronological order of property creation,
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = this.symbols.keys()[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var _key2 = _step3.value;
// i. Add P as the last element of keys.
keys.push(_key2);
}
// 12. Return keys.
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
return keys;
}
}]);
return StringExotic;
}(_index.ObjectValue);
exports.default = StringExotic;
//# sourceMappingURL=StringExotic.js.map