1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
String.prototype[5] = "five";
String.prototype.foo = "foo";
var lastSetThisValue = null;
class TerribleClass {
get #privateStrict() {
"use strict";
lastSetThisValue = this;
}
get #privateNonStrict() {
lastSetThisValue = this;
}
get 10() {
"use strict";
return this.#privateStrict;
}
get 11() {
return this.#privateNonStrict;
}
set 12(v) {
"use strict";
return this.#privateStrict;
}
set 13(v) {
return this.#privateNonStrict;
}
get strictGetPrivate() {
"use strict";
return this.#privateStrict;
}
get nonStrictGetPrivate() {
return this.#privateNonStrict;
}
set strictSetPrivate(v) {
"use strict";
this.#privateStrict;
}
set nonStrictSetPrivate(v) {
this.#privateNonStrict;
}
}
String.prototype.__proto__ = {
get nonStrictThis() {
return this;
},
get strictThis() {
"use strict";
return this;
},
set setNonStrictThis(v) {
lastSetThisValue = this;
},
set setStrictThis(v) {
"use strict";
lastSetThisValue = this;
},
get 6() {
"use strict";
return this;
},
get 7() {
return this;
},
set 8(v) {
"use strict";
lastSetThisValue = this;
},
set 9(v) {
lastSetThisValue = this;
},
};
String.prototype.__proto__.__proto__ = new TerribleClass();
test("primitive string: numeric indexing", () => {
expect(""[0]).toBeUndefined();
expect("foo"[0]).toBe("f");
expect("foo"[2]).toBe("o");
expect("foo"[3]).toBeUndefined();
expect("foo"[-1]).toBeUndefined();
expect("foo"[1.5]).toBeUndefined();
expect("foo"[5]).toBe("five");
expect(typeof "foo"[6]).toBe("string");
expect("foo"[6]).toBe("foo");
expect(typeof "foo"[7]).toBe("object");
expect("foo"[7] instanceof String).toBeTrue();
expect("foo"[7] !== "foo"[7]).toBeTrue();
expect("foo"[7] !== String.prototype).toBeTrue();
"foo"[8] = "test";
expect(typeof lastSetThisValue).toBe("string");
expect(lastSetThisValue).toBe("foo");
lastSetThisValue = null;
"foo"[9] = "test";
expect(typeof lastSetThisValue).toBe("object");
expect(lastSetThisValue instanceof String).toBeTrue();
expect(lastSetThisValue !== String.prototype);
let oldThisValue = lastSetThisValue;
lastSetThisValue = null;
"foo"[9] = "test";
expect(lastSetThisValue !== oldThisValue).toBeTrue();
lastSetThisValue = null;
expect(() => "foo"[10]).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
expect(() => "foo"[11]).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
expect(() => ("foo"[12] = "wat")).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
expect(() => ("foo"[13] = "wat")).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
});
test("primitive string: string property indexing", () => {
expect(""["0"]).toBeUndefined();
expect("foo"["0"]).toBe("f");
expect("foo"["01"]).toBeUndefined();
expect("foo"[" 1"]).toBeUndefined();
expect("foo"["1 "]).toBeUndefined();
expect("foo"["2"]).toBe("o");
expect("foo"["3"]).toBeUndefined();
expect("foo"["-1"]).toBeUndefined();
expect("foo"["1.5"]).toBeUndefined();
expect("foo"["5"]).toBe("five");
expect(typeof "foo"["6"]).toBe("string");
expect("foo"["6"]).toBe("foo");
expect(typeof "foo"["7"]).toBe("object");
expect("foo"["7"] instanceof String).toBeTrue();
expect("foo"["7"] !== "foo"[7]).toBeTrue();
expect("foo"["7"] !== String.prototope).toBeTrue();
expect(""["length"]).toBe(0);
expect("foo"["length"]).toBe(3);
"foo"["8"] = "test";
expect(typeof lastSetThisValue).toBe("string");
expect(lastSetThisValue).toBe("foo");
lastSetThisValue = null;
"foo"["9"] = "test";
expect(typeof lastSetThisValue).toBe("object");
expect(lastSetThisValue instanceof String).toBeTrue();
expect(lastSetThisValue !== String.prototype);
let oldThisValue = lastSetThisValue;
lastSetThisValue = null;
"foo"["9"] = "test";
expect(lastSetThisValue !== oldThisValue).toBeTrue();
lastSetThisValue = null;
expect(() => "foo"["10"]).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
expect(() => "foo"["11"]).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
expect(() => ("foo"["12"] = "wat")).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
expect(() => ("foo"["13"] = "wat")).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
});
test("primitive string: string property name access", () => {
expect("".length).toBe(0);
expect("foo".length).toBe(3);
expect("foo".bar).toBeUndefined();
expect("foo".foo).toBe("foo");
expect(typeof "foo".strictThis).toBe("string");
expect("foo".strictThis).toBe("foo");
expect(typeof "foo".nonStrictThis).toBe("object");
expect("foo".nonStrictThis !== "foo".nonStrictThis).toBeTrue();
expect("foo".nonStrictThis !== String.prototype).toBeTrue();
expect("foo".nonStrictThis instanceof String).toBeTrue();
let str = new String("foo");
str.setStrictThis = "test";
expect(typeof lastSetThisValue).toBe("object");
expect(lastSetThisValue).toBe(str);
lastSetThisValue = null;
str.setNonStrictThis = "test";
expect(typeof lastSetThisValue).toBe("object");
expect(lastSetThisValue instanceof String).toBeTrue();
expect(lastSetThisValue).toBe(str);
let oldThisValue = lastSetThisValue;
lastSetThisValue = null;
str.setNonStrictThis = "test";
expect(lastSetThisValue === oldThisValue).toBeTrue();
lastSetThisValue = null;
expect(() => "foo".strictGetPrivate).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
expect(() => "foo".nonStrictGetPrivate).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
expect(() => ("foo".strictSetPrivate = "wat")).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
expect(() => ("foo".nonStrictSetPrivate = "wat")).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
});
test("string object: string numeric indexing", () => {
expect(new String("")[0]).toBeUndefined();
expect(new String("foo")[0]).toBe("f");
expect(new String("foo")[2]).toBe("o");
expect(new String("foo")[3]).toBeUndefined();
expect(new String("foo")[-1]).toBeUndefined();
expect(new String("foo")[1.5]).toBeUndefined();
expect(new String("foo")[5]).toBe("five");
expect(typeof new String("foo")[6]).toBe("object");
let str = new String("foo");
expect(str[7]).toBe(str);
expect(typeof "foo"[7]).toBe("object");
expect(str[7] instanceof String).toBeTrue();
expect(str[7]).toBe(str);
expect(str[7] !== String.prototope).toBeTrue();
str["8"] = "test";
expect(typeof lastSetThisValue).toBe("object");
expect(lastSetThisValue).toBe(str);
lastSetThisValue = null;
str["9"] = "test";
expect(typeof lastSetThisValue).toBe("object");
expect(lastSetThisValue instanceof String).toBeTrue();
expect(lastSetThisValue).toBe(str);
let oldThisValue = lastSetThisValue;
lastSetThisValue = null;
str["9"] = "test";
expect(lastSetThisValue === oldThisValue).toBeTrue();
lastSetThisValue = null;
});
test("string object: string property indexing", () => {
expect(new String("")["0"]).toBeUndefined();
expect(new String("foo")["0"]).toBe("f");
expect(new String("foo")["2"]).toBe("o");
expect(new String("foo")["3"]).toBeUndefined();
expect(new String("foo")["-1"]).toBeUndefined();
expect(new String("foo")["1.5"]).toBeUndefined();
expect(new String("foo")["5"]).toBe("five");
expect(typeof new String("foo")["6"]).toBe("object");
let str = new String("foo");
expect(str["7"]).toBe(str);
expect(typeof "foo"["7"]).toBe("object");
expect(str["7"] instanceof String).toBeTrue();
expect(str["7"]).toBe(str);
expect(str["7"] !== String.prototope).toBeTrue();
str["setStrictThis"] = "test";
expect(typeof lastSetThisValue).toBe("object");
expect(lastSetThisValue).toBe(str);
lastSetThisValue = null;
str["setNonStrictThis"] = "test";
expect(typeof lastSetThisValue).toBe("object");
expect(lastSetThisValue instanceof String).toBeTrue();
expect(lastSetThisValue).toBe(str);
let oldThisValue = lastSetThisValue;
lastSetThisValue = null;
str["setNonStrictThis"] = "test";
expect(lastSetThisValue === oldThisValue).toBeTrue();
lastSetThisValue = null;
expect(() => str.strictGetPrivate).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
expect(() => str.nonStrictGetPrivate).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
expect(() => (str.strictSetPrivate = "wat")).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
expect(() => (str.nonStrictSetPrivate = "wat")).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
});
test("string object: string property name access", () => {
expect(new String("").length).toBe(0);
expect(new String("foo").length).toBe(3);
expect(new String("foo").bar).toBeUndefined();
expect(new String("foo").foo).toBe("foo");
expect(typeof new String("foo").strictThis).toBe("object");
let str = new String("foo");
expect(str.strictThis).toBe(str);
expect(typeof str.nonStrictThis).toBe("object");
expect(str.nonStrictThis === str.nonStrictThis).toBeTrue();
expect(str.nonStrictThis !== String.prototype).toBeTrue();
expect(str.nonStrictThis instanceof String).toBeTrue();
expect(new String("foo").nonStrictThis !== new String("foo").nonStrictThis).toBeTrue();
expect(new String("foo").strictThis !== new String("foo").strictThis).toBeTrue();
lastSetThisValue = null;
expect(() => str.strictGetPrivate).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
expect(() => str.nonStrictGetPrivate).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
expect(() => (str.strictSetPrivate = "wat")).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
expect(() => (str.nonStrictSetPrivate = "wat")).toThrow();
expect(lastSetThisValue).toBeNull();
lastSetThisValue = null;
});
|