OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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: --harmony | 5 // Flags: --harmony |
6 | 6 |
7 (function TestBasics() { | 7 (function TestBasics() { |
8 var C = class C {} | 8 var C = class C {} |
9 assertEquals(typeof C, 'function'); | 9 assertEquals(typeof C, 'function'); |
10 assertEquals(C.__proto__, Function.prototype); | 10 assertEquals(C.__proto__, Function.prototype); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 167 |
168 | 168 |
169 function assertMethodDescriptor(object, name) { | 169 function assertMethodDescriptor(object, name) { |
170 var descr = Object.getOwnPropertyDescriptor(object, name); | 170 var descr = Object.getOwnPropertyDescriptor(object, name); |
171 assertTrue(descr.configurable); | 171 assertTrue(descr.configurable); |
172 assertTrue(descr.enumerable); | 172 assertTrue(descr.enumerable); |
173 assertTrue(descr.writable); | 173 assertTrue(descr.writable); |
174 assertEquals('function', typeof descr.value); | 174 assertEquals('function', typeof descr.value); |
175 } | 175 } |
176 | 176 |
| 177 |
177 function assertGetterDescriptor(object, name) { | 178 function assertGetterDescriptor(object, name) { |
178 var descr = Object.getOwnPropertyDescriptor(object, name); | 179 var descr = Object.getOwnPropertyDescriptor(object, name); |
179 assertTrue(descr.configurable); | 180 assertTrue(descr.configurable); |
180 assertTrue(descr.enumerable); | 181 assertTrue(descr.enumerable); |
181 assertEquals('function', typeof descr.get); | 182 assertEquals('function', typeof descr.get); |
182 assertEquals(undefined, descr.set); | 183 assertEquals(undefined, descr.set); |
183 } | 184 } |
184 | 185 |
185 | 186 |
186 function assertSetterDescriptor(object, name) { | 187 function assertSetterDescriptor(object, name) { |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 } | 381 } |
381 static staticM() { | 382 static staticM() { |
382 return 2; | 383 return 2; |
383 } | 384 } |
384 } | 385 } |
385 | 386 |
386 assertEquals(1, new C().m()); | 387 assertEquals(1, new C().m()); |
387 assertEquals(2, C.staticM()); | 388 assertEquals(2, C.staticM()); |
388 })(); | 389 })(); |
389 | 390 |
| 391 |
| 392 (function TestConstructableButNoPrototype() { |
| 393 var Base = function() {}.bind(); |
| 394 assertThrows(function() { |
| 395 class C extends Base {} |
| 396 }, TypeError); |
| 397 })(); |
| 398 |
| 399 |
| 400 (function TestPrototypeGetter() { |
| 401 var calls = 0; |
| 402 var Base = function() {}.bind(); |
| 403 Object.defineProperty(Base, 'prototype', { |
| 404 get: function() { |
| 405 calls++; |
| 406 return null; |
| 407 }, |
| 408 configurable: true |
| 409 }); |
| 410 class C extends Base {} |
| 411 assertEquals(1, calls); |
| 412 |
| 413 calls = 0; |
| 414 Object.defineProperty(Base, 'prototype', { |
| 415 get: function() { |
| 416 calls++; |
| 417 return 42; |
| 418 }, |
| 419 configurable: true |
| 420 }); |
| 421 assertThrows(function() { |
| 422 class C extends Base {} |
| 423 }, TypeError); |
| 424 assertEquals(1, calls); |
| 425 })(); |
| 426 |
| 427 |
| 428 (function TestPrototypeSetter() { |
| 429 var Base = function() {}.bind(); |
| 430 Object.defineProperty(Base, 'prototype', { |
| 431 set: function() { |
| 432 assertUnreachable(); |
| 433 } |
| 434 }); |
| 435 assertThrows(function() { |
| 436 class C extends Base {} |
| 437 }, TypeError); |
| 438 })(); |
| 439 |
| 440 |
390 /* TODO(arv): Implement | 441 /* TODO(arv): Implement |
391 (function TestNameBindingInConstructor() { | 442 (function TestNameBindingInConstructor() { |
392 class C { | 443 class C { |
393 constructor() { | 444 constructor() { |
394 assertThrows(function() { | 445 assertThrows(function() { |
395 C = 42; | 446 C = 42; |
396 }, ReferenceError); | 447 }, ReferenceError); |
397 } | 448 } |
398 } | 449 } |
399 new C(); | 450 new C(); |
400 })(); | 451 })(); |
401 */ | 452 */ |
OLD | NEW |