1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var _index = require("./index.js");
|
9 |
|
10 | var _is = require("../methods/is.js");
|
11 |
|
12 | var _singletons = require("../singletons.js");
|
13 |
|
14 | var _invariant = _interopRequireDefault(require("../invariant.js"));
|
15 |
|
16 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | class StringExotic extends _index.ObjectValue {
|
29 | constructor(realm, intrinsicName) {
|
30 | super(realm, realm.intrinsics.StringPrototype, intrinsicName);
|
31 | }
|
32 |
|
33 |
|
34 | $GetOwnProperty(P) {
|
35 |
|
36 |
|
37 | let desc = _singletons.Properties.OrdinaryGetOwnProperty(this.$Realm, this, P);
|
38 |
|
39 |
|
40 | if (desc !== undefined) {
|
41 | _singletons.Properties.ThrowIfMightHaveBeenDeleted(desc.value);
|
42 |
|
43 | return desc;
|
44 | }
|
45 |
|
46 |
|
47 | if (typeof P !== "string" && !(P instanceof _index.StringValue)) return undefined;
|
48 |
|
49 | let index = _singletons.To.CanonicalNumericIndexString(this.$Realm, typeof P === "string" ? new _index.StringValue(this.$Realm, P) : P);
|
50 |
|
51 |
|
52 | if (index === undefined || index === null) return undefined;
|
53 |
|
54 | if ((0, _is.IsInteger)(this.$Realm, index) === false) return undefined;
|
55 |
|
56 | if (1.0 / index === -Infinity) return undefined;
|
57 |
|
58 | let str = this.$StringData;
|
59 | (0, _invariant.default)(str);
|
60 | str = str.throwIfNotConcreteString();
|
61 |
|
62 | let len = str.value.length;
|
63 |
|
64 | if (index < 0 || len <= index) return undefined;
|
65 |
|
66 | let resultStr = new _index.StringValue(this.$Realm, str.value.charAt(index));
|
67 |
|
68 | return {
|
69 | value: resultStr,
|
70 | writable: false,
|
71 | enumerable: true,
|
72 | configurable: false
|
73 | };
|
74 | }
|
75 |
|
76 |
|
77 | $OwnPropertyKeys() {
|
78 |
|
79 | let keys = [];
|
80 |
|
81 | let str = this.$StringData;
|
82 | (0, _invariant.default)(str);
|
83 | str = str.throwIfNotConcreteString();
|
84 |
|
85 | let len = str.value.length;
|
86 |
|
87 | for (let i = 0; i < len; ++i) {
|
88 |
|
89 | keys.push(new _index.StringValue(this.$Realm, _singletons.To.ToString(this.$Realm, new _index.NumberValue(this.$Realm, i))));
|
90 | }
|
91 |
|
92 |
|
93 | let properties = this.getOwnPropertyKeysArray();
|
94 |
|
95 | for (let key of properties.filter(x => (0, _is.IsArrayIndex)(this.$Realm, x)).map(x => parseInt(x, 10)).filter(x => _singletons.To.ToInteger(this.$Realm, x) >= len).sort((x, y) => x - y)) {
|
96 |
|
97 | keys.push(new _index.StringValue(this.$Realm, key + ""));
|
98 | }
|
99 |
|
100 |
|
101 | for (let key of properties.filter(x => !(0, _is.IsArrayIndex)(this.$Realm, x))) {
|
102 |
|
103 | keys.push(new _index.StringValue(this.$Realm, key));
|
104 | }
|
105 |
|
106 |
|
107 | for (let key of this.symbols.keys()) {
|
108 |
|
109 | keys.push(key);
|
110 | }
|
111 |
|
112 |
|
113 | return keys;
|
114 | }
|
115 |
|
116 | }
|
117 |
|
118 | exports.default = StringExotic;
|
119 |
|
\ | No newline at end of file |