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 --strong-mode | 6 // Flags: --expose-gc --strong-mode |
7 | 7 |
8 "use strict"; | 8 "use strict"; |
9 | 9 |
10 | 10 |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 assertEquals(4.2, o.d); | 342 assertEquals(4.2, o.d); |
343 assertEquals(153, o.o.foo); | 343 assertEquals(153, o.o.foo); |
344 | 344 |
345 var o1 = new A(7); | 345 var o1 = new A(7); |
346 assertTrue(%HaveSameMap(o, o1)); | 346 assertTrue(%HaveSameMap(o, o1)); |
347 | 347 |
348 gc(); | 348 gc(); |
349 })(); | 349 })(); |
350 | 350 |
351 | 351 |
352 (function TestArraySubclassing() { | 352 function TestArraySubclassing(array) { |
353 class A extends Array { | 353 class A extends array { |
354 constructor(...args) { | 354 constructor(...args) { |
355 assertFalse(new.target === undefined); | 355 assertFalse(new.target === undefined); |
356 super(...args); | 356 super(...args); |
357 this.a = 42; | 357 this.a = 42; |
358 this.d = 4.2; | 358 this.d = 4.2; |
359 this.o = {foo:153}; | 359 this.o = {foo:153}; |
360 } | 360 } |
361 } | 361 } |
362 | 362 |
363 var o = new Array(13); | 363 var o = new array(13); |
364 assertTrue(o instanceof Object); | 364 assertTrue(o instanceof Object); |
365 assertTrue(o instanceof Array); | 365 assertTrue(o instanceof array); |
366 assertEquals("object", typeof o); | 366 assertEquals("object", typeof o); |
367 checkPrototypeChain(o, [Array, Object]); | 367 checkPrototypeChain(o, [array, Object]); |
368 assertEquals(13, o.length); | 368 assertEquals(13, o.length); |
369 | 369 |
370 var o = new A(10); | 370 var o = new A(10); |
371 assertTrue(o instanceof Object); | 371 assertTrue(o instanceof Object); |
372 assertTrue(o instanceof Array); | 372 assertTrue(o instanceof array); |
373 assertTrue(o instanceof A); | 373 assertTrue(o instanceof A); |
374 assertEquals("object", typeof o); | 374 assertEquals("object", typeof o); |
375 checkPrototypeChain(o, [A, Array, Object]); | 375 checkPrototypeChain(o, [A, array, Object]); |
376 assertEquals(10, o.length); | 376 assertEquals(10, o.length); |
377 assertEquals(42, o.a); | 377 assertEquals(42, o.a); |
378 assertEquals(4.2, o.d); | 378 assertEquals(4.2, o.d); |
379 assertEquals(153, o.o.foo); | 379 assertEquals(153, o.o.foo); |
380 | 380 |
381 var o1 = new A(7); | 381 var o1 = new A(7); |
382 assertTrue(%HaveSameMap(o, o1)); | 382 assertTrue(%HaveSameMap(o, o1)); |
383 })(); | |
384 | |
385 | |
386 var TypedArray = Uint8Array.__proto__; | |
387 | |
388 function TestTypedArraySubclassing(array) { | |
389 class A extends array { | |
390 constructor(...args) { | |
391 assertFalse(new.target === undefined); | |
392 super(...args); | |
393 this.a = 42; | |
394 this.d = 4.2; | |
395 this.o = {foo:153}; | |
396 } | |
397 } | |
398 | |
399 var o = new array(13); | |
400 assertTrue(o instanceof Object); | |
401 assertTrue(o instanceof TypedArray); | |
402 assertTrue(o instanceof array); | |
403 assertEquals("object", typeof o); | |
404 checkPrototypeChain(o, [array, TypedArray, Object]); | |
405 assertEquals(13, o.length); | |
406 | |
407 var o = new A(10); | |
408 assertTrue(o instanceof Object); | |
409 assertTrue(o instanceof TypedArray); | |
410 assertTrue(o instanceof array); | |
411 assertTrue(o instanceof A); | |
412 assertEquals("object", typeof o); | |
413 checkPrototypeChain(o, [A, array, TypedArray, Object]); | |
414 assertEquals(10, o.length); | |
415 assertEquals(42, o.a); | |
416 assertEquals(4.2, o.d); | |
417 assertEquals(153, o.o.foo); | |
418 | |
419 var o1 = new A(7); | |
420 assertTrue(%HaveSameMap(o, o1)); | |
421 } | 383 } |
422 | 384 |
423 | 385 |
424 (function() { | 386 (function() { |
425 TestTypedArraySubclassing(Int8Array); | 387 TestArraySubclassing(Array); |
426 TestTypedArraySubclassing(Uint8Array); | 388 TestArraySubclassing(Int8Array); |
427 TestTypedArraySubclassing(Uint8ClampedArray); | 389 TestArraySubclassing(Uint8Array); |
428 TestTypedArraySubclassing(Int16Array); | 390 TestArraySubclassing(Uint8ClampedArray); |
429 TestTypedArraySubclassing(Uint16Array); | 391 TestArraySubclassing(Int16Array); |
430 TestTypedArraySubclassing(Int32Array); | 392 TestArraySubclassing(Uint16Array); |
431 TestTypedArraySubclassing(Uint32Array); | 393 TestArraySubclassing(Int32Array); |
432 TestTypedArraySubclassing(Float32Array); | 394 TestArraySubclassing(Uint32Array); |
433 TestTypedArraySubclassing(Float64Array); | 395 TestArraySubclassing(Float32Array); |
| 396 TestArraySubclassing(Float64Array); |
434 })(); | 397 })(); |
435 | 398 |
436 | 399 |
437 function TestMapSetSubclassing(container, is_map) { | 400 function TestMapSetSubclassing(container, is_map) { |
438 var keys = [{name: "banana"}, {name: "cow"}, {name: "orange"}, {name: "chicken
"}, {name: "apple"}]; | 401 var keys = [{name: "banana"}, {name: "cow"}, {name: "orange"}, {name: "chicken
"}, {name: "apple"}]; |
439 | 402 |
440 class A extends container { | 403 class A extends container { |
441 constructor(...args) { | 404 constructor(...args) { |
442 assertFalse(new.target === undefined); | 405 assertFalse(new.target === undefined); |
443 super(...args); | 406 super(...args); |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 | 910 |
948 Object.defineProperty(pattern, Symbol.match, { | 911 Object.defineProperty(pattern, Symbol.match, { |
949 get() { log.push("match"); f.prototype = p2; return false; }}); | 912 get() { log.push("match"); f.prototype = p2; return false; }}); |
950 | 913 |
951 var o = Reflect.construct(RegExp, [pattern], f); | 914 var o = Reflect.construct(RegExp, [pattern], f); |
952 assertEquals(["match", "tostring"], log); | 915 assertEquals(["match", "tostring"], log); |
953 assertEquals(/biep/, o); | 916 assertEquals(/biep/, o); |
954 assertTrue(o.__proto__ === p2); | 917 assertTrue(o.__proto__ === p2); |
955 assertTrue(f.prototype === p3); | 918 assertTrue(f.prototype === p3); |
956 })(); | 919 })(); |
OLD | NEW |