OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --allow-natives-syntax --harmony-reflect --harmony-regexp-subclass | 5 // Flags: --allow-natives-syntax --harmony-reflect --harmony-regexp-subclass |
| 6 // Flags: --expose-gc |
6 | 7 |
7 "use strict"; | 8 "use strict"; |
8 | 9 |
9 | 10 |
10 function checkPrototypeChain(object, constructors) { | 11 function checkPrototypeChain(object, constructors) { |
11 var proto = object.__proto__; | 12 var proto = object.__proto__; |
12 for (var i = 0; i < constructors.length; i++) { | 13 for (var i = 0; i < constructors.length; i++) { |
13 assertEquals(constructors[i].prototype, proto); | 14 assertEquals(constructors[i].prototype, proto); |
14 assertEquals(constructors[i], proto.constructor); | 15 assertEquals(constructors[i], proto.constructor); |
15 proto = proto.__proto__; | 16 proto = proto.__proto__; |
16 } | 17 } |
17 } | 18 } |
18 | 19 |
19 | 20 |
20 (function() { | 21 (function() { |
21 class A extends Object { | 22 class A extends Object { |
22 constructor(...args) { | 23 constructor(...args) { |
23 assertTrue(%IsConstructCall()); | 24 assertTrue(%IsConstructCall()); |
24 super(...args); | 25 super(...args); |
25 this.a = 42; | 26 this.a = 42; |
26 this.d = 4.2; | 27 this.d = 4.2; |
| 28 this.o = {foo:153}; |
27 } | 29 } |
28 } | 30 } |
29 | 31 |
30 var s = new A("foo"); | 32 var s = new A("foo"); |
31 assertTrue(s instanceof Object); | 33 assertTrue(s instanceof Object); |
32 assertTrue(s instanceof A); | 34 assertTrue(s instanceof A); |
33 assertEquals("object", typeof s); | 35 assertEquals("object", typeof s); |
34 checkPrototypeChain(s, [A, Object]); | 36 checkPrototypeChain(s, [A, Object]); |
35 assertEquals(42, s.a); | 37 assertEquals(42, s.a); |
36 assertEquals(4.2, s.d); | 38 assertEquals(4.2, s.d); |
| 39 assertEquals(153, s.o.foo); |
37 | 40 |
38 var s1 = new A("bar"); | 41 var s1 = new A("bar"); |
39 assertTrue(%HaveSameMap(s, s1)); | 42 assertTrue(%HaveSameMap(s, s1)); |
40 | 43 |
41 | 44 |
42 var n = new A(153); | 45 var n = new A(153); |
43 assertTrue(n instanceof Object); | 46 assertTrue(n instanceof Object); |
44 assertTrue(n instanceof A); | 47 assertTrue(n instanceof A); |
45 assertEquals("object", typeof s); | 48 assertEquals("object", typeof s); |
46 checkPrototypeChain(s, [A, Object]); | 49 checkPrototypeChain(s, [A, Object]); |
47 assertEquals(42, n.a); | 50 assertEquals(42, n.a); |
48 assertEquals(4.2, n.d); | 51 assertEquals(4.2, n.d); |
| 52 assertEquals(153, n.o.foo); |
49 | 53 |
50 var n1 = new A(312); | 54 var n1 = new A(312); |
51 assertTrue(%HaveSameMap(n, n1)); | 55 assertTrue(%HaveSameMap(n, n1)); |
52 assertTrue(%HaveSameMap(n, s)); | 56 assertTrue(%HaveSameMap(n, s)); |
53 | 57 |
54 | 58 |
55 var b = new A(true); | 59 var b = new A(true); |
56 assertTrue(b instanceof Object); | 60 assertTrue(b instanceof Object); |
57 assertTrue(b instanceof A); | 61 assertTrue(b instanceof A); |
58 assertEquals("object", typeof s); | 62 assertEquals("object", typeof s); |
59 checkPrototypeChain(s, [A, Object]); | 63 checkPrototypeChain(s, [A, Object]); |
60 assertEquals(42, b.a); | 64 assertEquals(42, b.a); |
61 assertEquals(4.2, b.d); | 65 assertEquals(4.2, b.d); |
| 66 assertEquals(153, b.o.foo); |
62 | 67 |
63 var b1 = new A(true); | 68 var b1 = new A(true); |
64 assertTrue(%HaveSameMap(b, b1)); | 69 assertTrue(%HaveSameMap(b, b1)); |
65 assertTrue(%HaveSameMap(b, s)); | 70 assertTrue(%HaveSameMap(b, s)); |
| 71 |
| 72 gc(); |
66 })(); | 73 })(); |
67 | 74 |
68 | 75 |
69 (function() { | 76 (function() { |
70 class A extends Function { | 77 class A extends Function { |
71 constructor(...args) { | 78 constructor(...args) { |
72 assertTrue(%IsConstructCall()); | 79 assertTrue(%IsConstructCall()); |
73 super(...args); | 80 super(...args); |
74 this.a = 42; | 81 this.a = 42; |
75 this.d = 4.2; | 82 this.d = 4.2; |
| 83 this.o = {foo:153}; |
76 } | 84 } |
77 } | 85 } |
78 | 86 |
79 var o = new A("this.foo = 153;"); | 87 var o = new A("this.foo = 113;"); |
80 assertTrue(o instanceof Object); | 88 assertTrue(o instanceof Object); |
81 assertTrue(o instanceof Function); | 89 assertTrue(o instanceof Function); |
82 assertTrue(o instanceof A); | 90 assertTrue(o instanceof A); |
83 assertEquals("function", typeof o); | 91 assertEquals("function", typeof o); |
84 checkPrototypeChain(o, [A, Function, Object]); | 92 checkPrototypeChain(o, [A, Function, Object]); |
85 assertEquals(42, o.a); | 93 assertEquals(42, o.a); |
86 assertEquals(4.2, o.d); | 94 assertEquals(4.2, o.d); |
| 95 assertEquals(153, o.o.foo); |
87 var oo = new o(); | 96 var oo = new o(); |
88 assertEquals(153, oo.foo); | 97 assertEquals(113, oo.foo); |
89 | 98 |
90 var o1 = new A("return 312;"); | 99 var o1 = new A("return 312;"); |
91 assertTrue(%HaveSameMap(o, o1)); | 100 assertTrue(%HaveSameMap(o, o1)); |
| 101 |
| 102 gc(); |
92 })(); | 103 })(); |
93 | 104 |
94 | 105 |
95 (function() { | 106 (function() { |
96 class A extends Boolean { | 107 class A extends Boolean { |
97 constructor(...args) { | 108 constructor(...args) { |
98 assertTrue(%IsConstructCall()); | 109 assertTrue(%IsConstructCall()); |
99 super(...args); | 110 super(...args); |
100 this.a = 42; | 111 this.a = 42; |
101 this.d = 4.2; | 112 this.d = 4.2; |
| 113 this.o = {foo:153}; |
102 } | 114 } |
103 } | 115 } |
104 | 116 |
105 var o = new A(true); | 117 var o = new A(true); |
106 assertTrue(o instanceof Object); | 118 assertTrue(o instanceof Object); |
107 assertTrue(o instanceof Boolean); | 119 assertTrue(o instanceof Boolean); |
108 assertTrue(o instanceof A); | 120 assertTrue(o instanceof A); |
109 assertEquals("object", typeof o); | 121 assertEquals("object", typeof o); |
110 checkPrototypeChain(o, [A, Boolean]); | 122 checkPrototypeChain(o, [A, Boolean]); |
111 assertTrue(o.valueOf()); | 123 assertTrue(o.valueOf()); |
112 assertEquals(42, o.a); | 124 assertEquals(42, o.a); |
113 assertEquals(4.2, o.d); | 125 assertEquals(4.2, o.d); |
| 126 assertEquals(153, o.o.foo); |
114 | 127 |
115 var o1 = new A(false); | 128 var o1 = new A(false); |
116 assertTrue(%HaveSameMap(o, o1)); | 129 assertTrue(%HaveSameMap(o, o1)); |
| 130 |
| 131 gc(); |
117 })(); | 132 })(); |
118 | 133 |
119 | 134 |
120 function TestErrorSubclassing(error) { | 135 function TestErrorSubclassing(error) { |
121 class A extends error { | 136 class A extends error { |
122 constructor(...args) { | 137 constructor(...args) { |
123 assertTrue(%IsConstructCall()); | 138 assertTrue(%IsConstructCall()); |
124 super(...args); | 139 super(...args); |
125 this.a = 42; | 140 this.a = 42; |
126 this.d = 4.2; | 141 this.d = 4.2; |
| 142 this.o = {foo:153}; |
127 } | 143 } |
128 } | 144 } |
129 | 145 |
130 var o = new A("message"); | 146 var o = new A("message"); |
131 assertTrue(o instanceof Object); | 147 assertTrue(o instanceof Object); |
132 assertTrue(o instanceof error); | 148 assertTrue(o instanceof error); |
133 assertTrue(o instanceof Error); | 149 assertTrue(o instanceof Error); |
134 assertTrue(o instanceof A); | 150 assertTrue(o instanceof A); |
135 assertEquals("object", typeof o); | 151 assertEquals("object", typeof o); |
136 if (error == Error) { | 152 if (error == Error) { |
137 checkPrototypeChain(o, [A, Error, Object]); | 153 checkPrototypeChain(o, [A, Error, Object]); |
138 } else { | 154 } else { |
139 checkPrototypeChain(o, [A, error, Error, Object]); | 155 checkPrototypeChain(o, [A, error, Error, Object]); |
140 } | 156 } |
141 assertEquals("message", o.message); | 157 assertEquals("message", o.message); |
142 assertEquals(error.name + ": message", o.toString()); | 158 assertEquals(error.name + ": message", o.toString()); |
143 assertEquals(42, o.a); | 159 assertEquals(42, o.a); |
144 assertEquals(4.2, o.d); | 160 assertEquals(4.2, o.d); |
| 161 assertEquals(153, o.o.foo); |
145 | 162 |
146 var o1 = new A("achtung!"); | 163 var o1 = new A("achtung!"); |
147 assertTrue(%HaveSameMap(o, o1)); | 164 assertTrue(%HaveSameMap(o, o1)); |
| 165 |
| 166 gc(); |
148 } | 167 } |
149 | 168 |
150 | 169 |
151 (function() { | 170 (function() { |
152 TestErrorSubclassing(Error); | 171 TestErrorSubclassing(Error); |
153 TestErrorSubclassing(EvalError); | 172 TestErrorSubclassing(EvalError); |
154 TestErrorSubclassing(RangeError); | 173 TestErrorSubclassing(RangeError); |
155 TestErrorSubclassing(ReferenceError); | 174 TestErrorSubclassing(ReferenceError); |
156 TestErrorSubclassing(SyntaxError); | 175 TestErrorSubclassing(SyntaxError); |
157 TestErrorSubclassing(TypeError); | 176 TestErrorSubclassing(TypeError); |
158 TestErrorSubclassing(URIError); | 177 TestErrorSubclassing(URIError); |
159 })(); | 178 })(); |
160 | 179 |
161 | 180 |
162 (function() { | 181 (function() { |
163 class A extends Number { | 182 class A extends Number { |
164 constructor(...args) { | 183 constructor(...args) { |
165 assertTrue(%IsConstructCall()); | 184 assertTrue(%IsConstructCall()); |
166 super(...args); | 185 super(...args); |
167 this.a = 42; | 186 this.a = 42; |
168 this.d = 4.2; | 187 this.d = 4.2; |
| 188 this.o = {foo:153}; |
169 } | 189 } |
170 } | 190 } |
171 | 191 |
172 var o = new A(153); | 192 var o = new A(153); |
173 assertTrue(o instanceof Object); | 193 assertTrue(o instanceof Object); |
174 assertTrue(o instanceof Number); | 194 assertTrue(o instanceof Number); |
175 assertTrue(o instanceof A); | 195 assertTrue(o instanceof A); |
176 assertEquals("object", typeof o); | 196 assertEquals("object", typeof o); |
177 checkPrototypeChain(o, [A, Number, Object]); | 197 checkPrototypeChain(o, [A, Number, Object]); |
178 assertEquals(153, o.valueOf()); | 198 assertEquals(153, o.valueOf()); |
179 assertEquals(42, o.a); | 199 assertEquals(42, o.a); |
180 assertEquals(4.2, o.d); | 200 assertEquals(4.2, o.d); |
| 201 assertEquals(153, o.o.foo); |
181 | 202 |
182 var o1 = new A(312); | 203 var o1 = new A(312); |
183 assertTrue(%HaveSameMap(o, o1)); | 204 assertTrue(%HaveSameMap(o, o1)); |
| 205 |
| 206 gc(); |
184 })(); | 207 })(); |
185 | 208 |
186 | 209 |
187 (function() { | 210 (function() { |
188 class A extends Date { | 211 class A extends Date { |
189 constructor(...args) { | 212 constructor(...args) { |
190 assertTrue(%IsConstructCall()); | 213 assertTrue(%IsConstructCall()); |
191 super(...args); | 214 super(...args); |
192 this.a = 42; | 215 this.a = 42; |
193 this.d = 4.2; | 216 this.d = 4.2; |
| 217 this.o = {foo:153}; |
194 } | 218 } |
195 } | 219 } |
196 | 220 |
197 var o = new A(1234567890); | 221 var o = new A(1234567890); |
198 assertTrue(o instanceof Object); | 222 assertTrue(o instanceof Object); |
199 assertTrue(o instanceof Date); | 223 assertTrue(o instanceof Date); |
200 assertTrue(o instanceof A); | 224 assertTrue(o instanceof A); |
201 assertEquals("object", typeof o); | 225 assertEquals("object", typeof o); |
202 checkPrototypeChain(o, [A, Date, Object]); | 226 checkPrototypeChain(o, [A, Date, Object]); |
203 assertEquals(1234567890, o.getTime()); | 227 assertEquals(1234567890, o.getTime()); |
204 assertEquals(42, o.a); | 228 assertEquals(42, o.a); |
205 assertEquals(4.2, o.d); | 229 assertEquals(4.2, o.d); |
| 230 assertEquals(153, o.o.foo); |
206 | 231 |
207 var o1 = new A(2015, 10, 29); | 232 var o1 = new A(2015, 10, 29); |
208 assertEquals(2015, o1.getFullYear()); | 233 assertEquals(2015, o1.getFullYear()); |
209 assertEquals(10, o1.getMonth()); | 234 assertEquals(10, o1.getMonth()); |
210 assertEquals(29, o1.getDate()); | 235 assertEquals(29, o1.getDate()); |
211 assertTrue(%HaveSameMap(o, o1)); | 236 assertTrue(%HaveSameMap(o, o1)); |
| 237 |
| 238 gc(); |
212 })(); | 239 })(); |
213 | 240 |
214 | 241 |
215 (function() { | 242 (function() { |
216 class A extends String { | 243 class A extends String { |
217 constructor(...args) { | 244 constructor(...args) { |
218 assertTrue(%IsConstructCall()); | 245 assertTrue(%IsConstructCall()); |
219 super(...args); | 246 super(...args); |
220 this.a = 42; | 247 this.a = 42; |
221 this.d = 4.2; | 248 this.d = 4.2; |
| 249 this.o = {foo:153}; |
222 } | 250 } |
223 } | 251 } |
224 | 252 |
225 var o = new A("foo"); | 253 var o = new A("foo"); |
226 assertTrue(o instanceof Object); | 254 assertTrue(o instanceof Object); |
227 assertTrue(o instanceof String); | 255 assertTrue(o instanceof String); |
228 assertTrue(o instanceof A); | 256 assertTrue(o instanceof A); |
229 assertEquals("object", typeof o); | 257 assertEquals("object", typeof o); |
230 checkPrototypeChain(o, [A, String, Object]); | 258 checkPrototypeChain(o, [A, String, Object]); |
231 | 259 |
232 assertEquals("foo", o.valueOf()); | 260 assertEquals("foo", o.valueOf()); |
233 assertEquals(42, o.a); | 261 assertEquals(42, o.a); |
234 assertEquals(4.2, o.d); | 262 assertEquals(4.2, o.d); |
| 263 assertEquals(153, o.o.foo); |
235 | 264 |
236 var o1 = new A("bar"); | 265 var o1 = new A("bar"); |
237 assertTrue(%HaveSameMap(o, o1)); | 266 assertTrue(%HaveSameMap(o, o1)); |
| 267 |
| 268 gc(); |
238 })(); | 269 })(); |
239 | 270 |
240 | 271 |
241 (function() { | 272 (function() { |
242 class A extends RegExp { | 273 class A extends RegExp { |
243 constructor(...args) { | 274 constructor(...args) { |
244 assertTrue(%IsConstructCall()); | 275 assertTrue(%IsConstructCall()); |
245 super(...args); | 276 super(...args); |
246 this.a = 42; | 277 this.a = 42; |
247 this.d = 4.2; | 278 this.d = 4.2; |
| 279 this.o = {foo:153}; |
248 } | 280 } |
249 } | 281 } |
250 | 282 |
251 var o = new A("o(..)h", "g"); | 283 var o = new A("o(..)h", "g"); |
252 assertTrue(o instanceof Object); | 284 assertTrue(o instanceof Object); |
253 assertTrue(o instanceof RegExp); | 285 assertTrue(o instanceof RegExp); |
254 assertTrue(o instanceof A); | 286 assertTrue(o instanceof A); |
255 assertEquals("object", typeof o); | 287 assertEquals("object", typeof o); |
256 checkPrototypeChain(o, [A, RegExp, Object]); | 288 checkPrototypeChain(o, [A, RegExp, Object]); |
257 assertTrue(o.test("ouch")); | 289 assertTrue(o.test("ouch")); |
258 assertArrayEquals(["ouch", "uc"], o.exec("boom! ouch! bam!")); | 290 assertArrayEquals(["ouch", "uc"], o.exec("boom! ouch! bam!")); |
259 assertEquals("o(..)h", o.source); | 291 assertEquals("o(..)h", o.source); |
260 assertTrue(o.global); | 292 assertTrue(o.global); |
261 assertFalse(o.ignoreCase); | 293 assertFalse(o.ignoreCase); |
262 assertFalse(o.multiline); | 294 assertFalse(o.multiline); |
263 assertEquals(10, o.lastIndex); | 295 assertEquals(10, o.lastIndex); |
264 assertEquals(42, o.a); | 296 assertEquals(42, o.a); |
265 assertEquals(4.2, o.d); | 297 assertEquals(4.2, o.d); |
| 298 assertEquals(153, o.o.foo); |
266 | 299 |
267 var o1 = new A(7); | 300 var o1 = new A(7); |
268 assertTrue(%HaveSameMap(o, o1)); | 301 assertTrue(%HaveSameMap(o, o1)); |
| 302 |
| 303 gc(); |
269 })(); | 304 })(); |
270 | 305 |
271 | 306 |
272 function TestArraySubclassing(array) { | 307 function TestArraySubclassing(array) { |
273 class A extends array { | 308 class A extends array { |
274 constructor(...args) { | 309 constructor(...args) { |
275 assertTrue(%IsConstructCall()); | 310 assertTrue(%IsConstructCall()); |
276 super(...args); | 311 super(...args); |
277 this.a = 42; | 312 this.a = 42; |
278 this.d = 4.2; | 313 this.d = 4.2; |
| 314 this.o = {foo:153}; |
279 } | 315 } |
280 } | 316 } |
281 | 317 |
282 var o = new array(13); | 318 var o = new array(13); |
283 assertTrue(o instanceof Object); | 319 assertTrue(o instanceof Object); |
284 assertTrue(o instanceof array); | 320 assertTrue(o instanceof array); |
285 assertEquals("object", typeof o); | 321 assertEquals("object", typeof o); |
286 checkPrototypeChain(o, [array, Object]); | 322 checkPrototypeChain(o, [array, Object]); |
287 assertEquals(13, o.length); | 323 assertEquals(13, o.length); |
288 | 324 |
289 var o = new A(10); | 325 var o = new A(10); |
290 assertTrue(o instanceof Object); | 326 assertTrue(o instanceof Object); |
291 assertTrue(o instanceof array); | 327 assertTrue(o instanceof array); |
292 assertTrue(o instanceof A); | 328 assertTrue(o instanceof A); |
293 assertEquals("object", typeof o); | 329 assertEquals("object", typeof o); |
294 checkPrototypeChain(o, [A, array, Object]); | 330 checkPrototypeChain(o, [A, array, Object]); |
295 assertEquals(10, o.length); | 331 assertEquals(10, o.length); |
296 assertEquals(42, o.a); | 332 assertEquals(42, o.a); |
297 assertEquals(4.2, o.d); | 333 assertEquals(4.2, o.d); |
| 334 assertEquals(153, o.o.foo); |
298 | 335 |
299 var o1 = new A(7); | 336 var o1 = new A(7); |
300 assertTrue(%HaveSameMap(o, o1)); | 337 assertTrue(%HaveSameMap(o, o1)); |
301 } | 338 } |
302 | 339 |
303 | 340 |
304 (function() { | 341 (function() { |
305 TestArraySubclassing(Array); | 342 TestArraySubclassing(Array); |
306 TestArraySubclassing(Int8Array); | 343 TestArraySubclassing(Int8Array); |
307 TestArraySubclassing(Uint8Array); | 344 TestArraySubclassing(Uint8Array); |
308 TestArraySubclassing(Uint8ClampedArray); | 345 TestArraySubclassing(Uint8ClampedArray); |
309 TestArraySubclassing(Int16Array); | 346 TestArraySubclassing(Int16Array); |
310 TestArraySubclassing(Uint16Array); | 347 TestArraySubclassing(Uint16Array); |
311 TestArraySubclassing(Int32Array); | 348 TestArraySubclassing(Int32Array); |
312 TestArraySubclassing(Uint32Array); | 349 TestArraySubclassing(Uint32Array); |
313 TestArraySubclassing(Float32Array); | 350 TestArraySubclassing(Float32Array); |
314 TestArraySubclassing(Float64Array); | 351 TestArraySubclassing(Float64Array); |
315 })(); | 352 })(); |
316 | 353 |
317 | 354 |
318 function TestMapSetSubclassing(container, is_map) { | 355 function TestMapSetSubclassing(container, is_map) { |
319 var keys = [{name: "banana"}, {name: "cow"}, {name: "orange"}, {name: "chicken
"}, {name: "apple"}]; | 356 var keys = [{name: "banana"}, {name: "cow"}, {name: "orange"}, {name: "chicken
"}, {name: "apple"}]; |
320 | 357 |
321 class A extends container { | 358 class A extends container { |
322 constructor(...args) { | 359 constructor(...args) { |
323 assertTrue(%IsConstructCall()); | 360 assertTrue(%IsConstructCall()); |
324 super(...args); | 361 super(...args); |
325 this.a = 42; | 362 this.a = 42; |
326 this.d = 4.2; | 363 this.d = 4.2; |
| 364 this.o = {foo:153}; |
327 } | 365 } |
328 } | 366 } |
329 | 367 |
330 var o = new A(); | 368 var o = new A(); |
331 assertTrue(o instanceof Object); | 369 assertTrue(o instanceof Object); |
332 assertTrue(o instanceof container); | 370 assertTrue(o instanceof container); |
333 assertTrue(o instanceof A); | 371 assertTrue(o instanceof A); |
334 assertEquals("object", typeof o); | 372 assertEquals("object", typeof o); |
335 checkPrototypeChain(o, [A, container, Object]); | 373 checkPrototypeChain(o, [A, container, Object]); |
336 | 374 |
(...skipping 14 matching lines...) Expand all Loading... |
351 assertTrue(o.has(keys[4])); | 389 assertTrue(o.has(keys[4])); |
352 if (is_map) { | 390 if (is_map) { |
353 assertEquals(11, o.get(keys[0])); | 391 assertEquals(11, o.get(keys[0])); |
354 assertEquals(undefined, o.get(keys[1])); | 392 assertEquals(undefined, o.get(keys[1])); |
355 assertEquals(33, o.get(keys[2])); | 393 assertEquals(33, o.get(keys[2])); |
356 assertEquals(undefined, o.get(keys[3])); | 394 assertEquals(undefined, o.get(keys[3])); |
357 assertEquals(55, o.get(keys[4])); | 395 assertEquals(55, o.get(keys[4])); |
358 } | 396 } |
359 assertEquals(42, o.a); | 397 assertEquals(42, o.a); |
360 assertEquals(4.2, o.d); | 398 assertEquals(4.2, o.d); |
| 399 assertEquals(153, o.o.foo); |
361 | 400 |
362 var o1 = new A(); | 401 var o1 = new A(); |
363 assertTrue(%HaveSameMap(o, o1)); | 402 assertTrue(%HaveSameMap(o, o1)); |
| 403 |
| 404 gc(); |
364 } | 405 } |
365 | 406 |
366 | 407 |
367 (function() { | 408 (function() { |
368 TestMapSetSubclassing(Map, true); | 409 TestMapSetSubclassing(Map, true); |
369 TestMapSetSubclassing(WeakMap, true); | 410 TestMapSetSubclassing(WeakMap, true); |
370 TestMapSetSubclassing(Set, false); | 411 TestMapSetSubclassing(Set, false); |
371 TestMapSetSubclassing(WeakSet, false); | 412 TestMapSetSubclassing(WeakSet, false); |
372 })(); | 413 })(); |
373 | 414 |
374 | 415 |
375 (function() { | 416 (function() { |
376 class A extends ArrayBuffer { | 417 class A extends ArrayBuffer { |
377 constructor(...args) { | 418 constructor(...args) { |
378 assertTrue(%IsConstructCall()); | 419 assertTrue(%IsConstructCall()); |
379 super(...args); | 420 super(...args); |
380 this.a = 42; | 421 this.a = 42; |
381 this.d = 4.2; | 422 this.d = 4.2; |
| 423 this.o = {foo:153}; |
382 } | 424 } |
383 } | 425 } |
384 | 426 |
385 var o = new A(16); | 427 var o = new A(16); |
386 assertTrue(o instanceof Object); | 428 assertTrue(o instanceof Object); |
387 assertTrue(o instanceof ArrayBuffer); | 429 assertTrue(o instanceof ArrayBuffer); |
388 assertTrue(o instanceof A); | 430 assertTrue(o instanceof A); |
389 assertEquals("object", typeof o); | 431 assertEquals("object", typeof o); |
390 checkPrototypeChain(o, [A, ArrayBuffer, Object]); | 432 checkPrototypeChain(o, [A, ArrayBuffer, Object]); |
391 | 433 |
392 assertEquals(16, o.byteLength); | 434 assertEquals(16, o.byteLength); |
393 assertEquals(42, o.a); | 435 assertEquals(42, o.a); |
394 assertEquals(4.2, o.d); | 436 assertEquals(4.2, o.d); |
| 437 assertEquals(153, o.o.foo); |
395 | 438 |
396 var o1 = new A("bar"); | 439 var o1 = new A("bar"); |
397 assertTrue(%HaveSameMap(o, o1)); | 440 assertTrue(%HaveSameMap(o, o1)); |
398 | 441 |
399 | 442 |
400 class MyInt32Array extends Int32Array { | 443 class MyInt32Array extends Int32Array { |
401 constructor(v, name) { | 444 constructor(v, name) { |
402 super(v); | 445 super(v); |
403 this.name = name; | 446 this.name = name; |
404 } | 447 } |
(...skipping 11 matching lines...) Expand all Loading... |
416 | 459 |
417 int32view[0] = -2; | 460 int32view[0] = -2; |
418 uint32view[1] = 0xffffffff; | 461 uint32view[1] = 0xffffffff; |
419 | 462 |
420 assertEquals("cats", int32view.name); | 463 assertEquals("cats", int32view.name); |
421 assertEquals("dogs", uint32view.name); | 464 assertEquals("dogs", uint32view.name); |
422 assertEquals(-2, int32view[0]); | 465 assertEquals(-2, int32view[0]); |
423 assertEquals(-1, int32view[1]); | 466 assertEquals(-1, int32view[1]); |
424 assertEquals(0xfffffffe, uint32view[0]); | 467 assertEquals(0xfffffffe, uint32view[0]); |
425 assertEquals(0xffffffff, uint32view[1]); | 468 assertEquals(0xffffffff, uint32view[1]); |
| 469 |
| 470 gc(); |
426 })(); | 471 })(); |
427 | 472 |
428 | 473 |
429 (function() { | 474 (function() { |
430 class A extends DataView { | 475 class A extends DataView { |
431 constructor(...args) { | 476 constructor(...args) { |
432 assertTrue(%IsConstructCall()); | 477 assertTrue(%IsConstructCall()); |
433 super(...args); | 478 super(...args); |
434 this.a = 42; | 479 this.a = 42; |
435 this.d = 4.2; | 480 this.d = 4.2; |
| 481 this.o = {foo:153}; |
436 } | 482 } |
437 } | 483 } |
438 | 484 |
439 var buffer = new ArrayBuffer(16); | 485 var buffer = new ArrayBuffer(16); |
440 var o = new A(buffer); | 486 var o = new A(buffer); |
441 assertTrue(o instanceof Object); | 487 assertTrue(o instanceof Object); |
442 assertTrue(o instanceof DataView); | 488 assertTrue(o instanceof DataView); |
443 assertTrue(o instanceof A); | 489 assertTrue(o instanceof A); |
444 assertEquals("object", typeof o); | 490 assertEquals("object", typeof o); |
445 checkPrototypeChain(o, [A, DataView, Object]); | 491 checkPrototypeChain(o, [A, DataView, Object]); |
446 | 492 |
447 o.setUint32(0, 0xcafebabe, false); | 493 o.setUint32(0, 0xcafebabe, false); |
448 assertEquals(0xcafebabe, o.getUint32(0, false)); | 494 assertEquals(0xcafebabe, o.getUint32(0, false)); |
449 assertEquals(0xbebafeca, o.getUint32(0, true)); | 495 assertEquals(0xbebafeca, o.getUint32(0, true)); |
450 assertEquals(42, o.a); | 496 assertEquals(42, o.a); |
451 assertEquals(4.2, o.d); | 497 assertEquals(4.2, o.d); |
| 498 assertEquals(153, o.o.foo); |
452 | 499 |
453 var o1 = new A(buffer); | 500 var o1 = new A(buffer); |
454 assertTrue(%HaveSameMap(o, o1)); | 501 assertTrue(%HaveSameMap(o, o1)); |
455 | 502 |
| 503 gc(); |
456 })(); | 504 })(); |
457 | 505 |
458 | 506 |
459 (function() { | 507 (function() { |
460 // TODO(ishell): remove once GeneratorFunction is available. | 508 // TODO(ishell): remove once GeneratorFunction is available. |
461 var GeneratorFunction = (function*() {}).__proto__.constructor; | 509 var GeneratorFunction = (function*() {}).__proto__.constructor; |
462 class A extends GeneratorFunction { | 510 class A extends GeneratorFunction { |
463 constructor(...args) { | 511 constructor(...args) { |
464 assertTrue(%IsConstructCall()); | 512 assertTrue(%IsConstructCall()); |
465 super(...args); | 513 super(...args); |
466 this.a = 42; | 514 this.a = 42; |
467 this.d = 4.2; | 515 this.d = 4.2; |
| 516 this.o = {foo:153}; |
468 } | 517 } |
469 } | 518 } |
470 var generator_func = new A("var index = 0; while (index < 5) { yield ++index;
}"); | 519 var generator_func = new A("var index = 0; while (index < 5) { yield ++index;
}"); |
471 assertTrue(generator_func instanceof Object); | 520 assertTrue(generator_func instanceof Object); |
472 assertTrue(generator_func instanceof Function); | 521 assertTrue(generator_func instanceof Function); |
473 assertTrue(generator_func instanceof GeneratorFunction); | 522 assertTrue(generator_func instanceof GeneratorFunction); |
474 assertTrue(generator_func instanceof A); | 523 assertTrue(generator_func instanceof A); |
475 assertEquals("function", typeof generator_func); | 524 assertEquals("function", typeof generator_func); |
476 checkPrototypeChain(generator_func, [A, GeneratorFunction, Function, Object]); | 525 checkPrototypeChain(generator_func, [A, GeneratorFunction, Function, Object]); |
477 assertEquals(42, generator_func.a); | 526 assertEquals(42, generator_func.a); |
478 assertEquals(4.2, generator_func.d); | 527 assertEquals(4.2, generator_func.d); |
| 528 assertEquals(153, generator_func.o.foo); |
479 | 529 |
480 var o = new generator_func(); | 530 var o = new generator_func(); |
481 assertTrue(o instanceof Object); | 531 assertTrue(o instanceof Object); |
482 assertTrue(o instanceof generator_func); | 532 assertTrue(o instanceof generator_func); |
483 assertEquals("object", typeof o); | 533 assertEquals("object", typeof o); |
484 | 534 |
485 assertPropertiesEqual({done: false, value: 1}, o.next()); | 535 assertPropertiesEqual({done: false, value: 1}, o.next()); |
486 assertPropertiesEqual({done: false, value: 2}, o.next()); | 536 assertPropertiesEqual({done: false, value: 2}, o.next()); |
487 assertPropertiesEqual({done: false, value: 3}, o.next()); | 537 assertPropertiesEqual({done: false, value: 3}, o.next()); |
488 assertPropertiesEqual({done: false, value: 4}, o.next()); | 538 assertPropertiesEqual({done: false, value: 4}, o.next()); |
489 assertPropertiesEqual({done: false, value: 5}, o.next()); | 539 assertPropertiesEqual({done: false, value: 5}, o.next()); |
490 assertPropertiesEqual({done: true, value: undefined}, o.next()); | 540 assertPropertiesEqual({done: true, value: undefined}, o.next()); |
491 | 541 |
492 var generator_func1 = new A("return 0;"); | 542 var generator_func1 = new A("return 0;"); |
493 assertTrue(%HaveSameMap(generator_func, generator_func1)); | 543 assertTrue(%HaveSameMap(generator_func, generator_func1)); |
| 544 |
| 545 gc(); |
494 })(); | 546 })(); |
495 | 547 |
496 | 548 |
497 (function() { | 549 (function() { |
498 class A extends Boolean { | 550 class A extends Boolean { |
499 constructor() { | 551 constructor() { |
500 assertTrue(%IsConstructCall()); | 552 assertTrue(%IsConstructCall()); |
501 super(true); | 553 super(true); |
502 this.a00 = 0 | 554 this.a00 = 0 |
503 this.a01 = 0 | 555 this.a01 = 0 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 } | 629 } |
578 | 630 |
579 var o = new C(); | 631 var o = new C(); |
580 assertTrue(o instanceof Object); | 632 assertTrue(o instanceof Object); |
581 assertTrue(o instanceof Boolean); | 633 assertTrue(o instanceof Boolean); |
582 assertTrue(o instanceof A); | 634 assertTrue(o instanceof A); |
583 assertTrue(o instanceof B); | 635 assertTrue(o instanceof B); |
584 assertTrue(o instanceof C); | 636 assertTrue(o instanceof C); |
585 assertEquals("object", typeof o); | 637 assertEquals("object", typeof o); |
586 checkPrototypeChain(o, [C, B, A, Boolean, Object]); | 638 checkPrototypeChain(o, [C, B, A, Boolean, Object]); |
| 639 |
| 640 gc(); |
587 })(); | 641 })(); |
588 | 642 |
589 | 643 |
590 (function() { | 644 (function() { |
591 assertThrows("class A extends undefined {}"); | 645 assertThrows("class A extends undefined {}"); |
592 assertThrows("class B extends NaN {}"); | 646 assertThrows("class B extends NaN {}"); |
593 assertThrows("class C extends Infinity {}"); | 647 assertThrows("class C extends Infinity {}"); |
594 })(); | 648 })(); |
595 | 649 |
596 | 650 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 | 781 |
728 Object.defineProperty(pattern, Symbol.match, { | 782 Object.defineProperty(pattern, Symbol.match, { |
729 get() { log.push("match"); f.prototype = p2; return false; }}); | 783 get() { log.push("match"); f.prototype = p2; return false; }}); |
730 | 784 |
731 var o = Reflect.construct(RegExp, [pattern], f); | 785 var o = Reflect.construct(RegExp, [pattern], f); |
732 assertEquals(["match", "tostring"], log); | 786 assertEquals(["match", "tostring"], log); |
733 assertEquals(/biep/, o); | 787 assertEquals(/biep/, o); |
734 assertTrue(o.__proto__ === p2); | 788 assertTrue(o.__proto__ === p2); |
735 assertTrue(f.prototype === p3); | 789 assertTrue(f.prototype === p3); |
736 })(); | 790 })(); |
OLD | NEW |