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