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 | 5 // Flags: --allow-natives-syntax |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 | 9 |
10 function checkPrototypeChain(object, constructors) { | 10 function checkPrototypeChain(object, constructors) { |
11 var proto = object.__proto__; | 11 var proto = object.__proto__; |
12 for (var i = 0; i < constructors.length; i++) { | 12 for (var i = 0; i < constructors.length; i++) { |
13 assertEquals(constructors[i].prototype, proto); | 13 assertEquals(constructors[i].prototype, proto); |
14 assertEquals(constructors[i], proto.constructor); | 14 assertEquals(constructors[i], proto.constructor); |
15 proto = proto.__proto__; | 15 proto = proto.__proto__; |
16 } | 16 } |
17 } | 17 } |
18 | 18 |
19 | 19 |
20 (function() { | 20 (function() { |
| 21 class A extends Object { |
| 22 constructor(...args) { |
| 23 assertTrue(%IsConstructCall()); |
| 24 super(...args); |
| 25 this.a = 42; |
| 26 this.d = 4.2; |
| 27 } |
| 28 } |
| 29 |
| 30 var s = new A("foo"); |
| 31 assertTrue(s instanceof Object); |
| 32 assertTrue(s instanceof A); |
| 33 assertEquals("object", typeof s); |
| 34 checkPrototypeChain(s, [A, Object]); |
| 35 assertEquals(42, s.a); |
| 36 assertEquals(4.2, s.d); |
| 37 |
| 38 var s1 = new A("bar"); |
| 39 assertTrue(%HaveSameMap(s, s1)); |
| 40 |
| 41 |
| 42 var n = new A(153); |
| 43 assertTrue(n instanceof Object); |
| 44 assertTrue(n instanceof A); |
| 45 assertEquals("object", typeof s); |
| 46 checkPrototypeChain(s, [A, Object]); |
| 47 assertEquals(42, n.a); |
| 48 assertEquals(4.2, n.d); |
| 49 |
| 50 var n1 = new A(312); |
| 51 assertTrue(%HaveSameMap(n, n1)); |
| 52 assertTrue(%HaveSameMap(n, s)); |
| 53 |
| 54 |
| 55 var b = new A(true); |
| 56 assertTrue(b instanceof Object); |
| 57 assertTrue(b instanceof A); |
| 58 assertEquals("object", typeof s); |
| 59 checkPrototypeChain(s, [A, Object]); |
| 60 assertEquals(42, b.a); |
| 61 assertEquals(4.2, b.d); |
| 62 |
| 63 var b1 = new A(true); |
| 64 assertTrue(%HaveSameMap(b, b1)); |
| 65 assertTrue(%HaveSameMap(b, s)); |
| 66 })(); |
| 67 |
| 68 |
| 69 (function() { |
21 class A extends Function { | 70 class A extends Function { |
22 constructor(...args) { | 71 constructor(...args) { |
23 assertTrue(%IsConstructCall()); | 72 assertTrue(%IsConstructCall()); |
24 super(...args); | 73 super(...args); |
25 this.a = 42; | 74 this.a = 42; |
26 this.d = 4.2; | 75 this.d = 4.2; |
27 } | 76 } |
28 } | 77 } |
29 | 78 |
30 var o = new A("this.foo = 153;"); | 79 var o = new A("this.foo = 153;"); |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 (function() { | 595 (function() { |
547 class A extends null {} | 596 class A extends null {} |
548 assertThrows("new A"); | 597 assertThrows("new A"); |
549 })(); | 598 })(); |
550 | 599 |
551 | 600 |
552 (function() { | 601 (function() { |
553 class A extends Symbol {} | 602 class A extends Symbol {} |
554 assertThrows("new A"); | 603 assertThrows("new A"); |
555 })(); | 604 })(); |
OLD | NEW |