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 | 5 |
6 (function testConstructClassStrict() { | 6 (function testConstructClassStrict() { |
7 "use strict"; | 7 "use strict"; |
8 class Base { | 8 class Base { |
9 constructor(...args) { | 9 constructor(...args) { |
10 this.baseArgs = args; | 10 this.baseArgs = args; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 assertEquals([1, 2, 3], c.baseArgs); | 81 assertEquals([1, 2, 3], c.baseArgs); |
82 assertEquals([1, 2, 3], c.childArgs); | 82 assertEquals([1, 2, 3], c.childArgs); |
83 | 83 |
84 c = new Child2(...[1, 2, 3]); | 84 c = new Child2(...[1, 2, 3]); |
85 assertInstanceof(c, Child2); | 85 assertInstanceof(c, Child2); |
86 assertInstanceof(c, Base); | 86 assertInstanceof(c, Base); |
87 assertEquals(["extra", 1, 2, 3], c.method()); | 87 assertEquals(["extra", 1, 2, 3], c.method()); |
88 assertEquals(["extra", 1, 2, 3], c.baseArgs); | 88 assertEquals(["extra", 1, 2, 3], c.baseArgs); |
89 assertEquals([1, 2, 3], c.childArgs); | 89 assertEquals([1, 2, 3], c.childArgs); |
90 })(); | 90 })(); |
| 91 |
| 92 (function testArgumentsObjectStrict() { |
| 93 "use strict"; |
| 94 class Base { |
| 95 constructor(...args) { |
| 96 this.baseArgs = args; |
| 97 } |
| 98 method() { return this.baseArgs; } |
| 99 } |
| 100 |
| 101 class Child extends Base { |
| 102 constructor() { |
| 103 super(...arguments); |
| 104 this.childArgs = arguments; |
| 105 } |
| 106 } |
| 107 |
| 108 class Child2 extends Base { |
| 109 constructor() { |
| 110 super("extra", ...arguments); |
| 111 this.childArgs = arguments; |
| 112 } |
| 113 } |
| 114 |
| 115 var c = new Child(...[1, 2, 3]); |
| 116 assertInstanceof(c, Child); |
| 117 assertInstanceof(c, Base); |
| 118 assertEquals([1, 2, 3], c.method()); |
| 119 assertEquals([1, 2, 3], c.baseArgs); |
| 120 assertFalse(Array.__proto__ === c.childArgs.__proto__); |
| 121 assertEquals([1, 2, 3], Array.prototype.slice.call(c.childArgs)); |
| 122 |
| 123 c = new Child2(...[1, 2, 3]); |
| 124 assertInstanceof(c, Child2); |
| 125 assertInstanceof(c, Base); |
| 126 assertEquals(["extra", 1, 2, 3], c.method()); |
| 127 assertEquals(["extra", 1, 2, 3], c.baseArgs); |
| 128 assertFalse(Array.__proto__ === c.childArgs.__proto__); |
| 129 assertEquals([1, 2, 3], Array.prototype.slice.call(c.childArgs)); |
| 130 })(); |
| 131 |
| 132 (function testArgumentsObjectSloppy() { |
| 133 class Base { |
| 134 constructor(...args) { |
| 135 this.baseArgs = args; |
| 136 } |
| 137 method() { return this.baseArgs; } |
| 138 } |
| 139 |
| 140 class Child extends Base { |
| 141 constructor() { |
| 142 super(...arguments); |
| 143 this.childArgs = arguments; |
| 144 } |
| 145 } |
| 146 |
| 147 class Child2 extends Base { |
| 148 constructor() { |
| 149 super("extra", ...arguments); |
| 150 this.childArgs = arguments; |
| 151 } |
| 152 } |
| 153 |
| 154 var c = new Child(...[1, 2, 3]); |
| 155 assertInstanceof(c, Child); |
| 156 assertInstanceof(c, Base); |
| 157 assertEquals([1, 2, 3], c.method()); |
| 158 assertEquals([1, 2, 3], c.baseArgs); |
| 159 assertFalse(Array.__proto__ === c.childArgs.__proto__); |
| 160 assertEquals([1, 2, 3], Array.prototype.slice.call(c.childArgs)); |
| 161 |
| 162 c = new Child2(...[1, 2, 3]); |
| 163 assertInstanceof(c, Child2); |
| 164 assertInstanceof(c, Base); |
| 165 assertEquals(["extra", 1, 2, 3], c.method()); |
| 166 assertEquals(["extra", 1, 2, 3], c.baseArgs); |
| 167 assertFalse(Array.__proto__ === c.childArgs.__proto__); |
| 168 assertEquals([1, 2, 3], Array.prototype.slice.call(c.childArgs)); |
| 169 })(); |
OLD | NEW |