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-sloppy | 5 // Flags: --harmony-sloppy |
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 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 | 618 |
619 (function TestDefaultConstructorNoCrash() { | 619 (function TestDefaultConstructorNoCrash() { |
620 // Regression test for https://code.google.com/p/v8/issues/detail?id=3661 | 620 // Regression test for https://code.google.com/p/v8/issues/detail?id=3661 |
621 class C {} | 621 class C {} |
622 assertThrows(function () {C();}, TypeError); | 622 assertThrows(function () {C();}, TypeError); |
623 assertThrows(function () {C(1);}, TypeError); | 623 assertThrows(function () {C(1);}, TypeError); |
624 assertTrue(new C() instanceof C); | 624 assertTrue(new C() instanceof C); |
625 assertTrue(new C(1) instanceof C); | 625 assertTrue(new C(1) instanceof C); |
626 })(); | 626 })(); |
627 | 627 |
628 (function TestConstructorCall(){ | |
629 var realmIndex = Realm.create(); | |
630 var otherTypeError = Realm.eval(realmIndex, "TypeError"); | |
631 var A = Realm.eval(realmIndex, '"use strict"; class A {}'); | |
632 var instance = new A(); | |
633 var constructor = instance.constructor; | |
634 var otherTypeError = Realm.eval(realmIndex, 'TypeError'); | |
635 if (otherTypeError === TypeError) { | |
636 throw Error('Should not happen!'); | |
637 } | |
638 | |
639 // ES6 9.2.1[[Call]] throws a TypeError in the caller context/Realm when the | |
640 // called function is a classConstructor | |
641 assertThrows(function() { Realm.eval(realmIndex, "A()") }, otherTypeError); | |
642 assertThrows(function() { instance.constructor() }, TypeError); | |
643 assertThrows(function() { A() }, TypeError); | |
644 | |
645 // ES6 9.3.1 call() first activates the callee context before invoking the | |
646 // method. The TypeError from the constructor is thus thrown in the other | |
647 // Realm. | |
648 assertThrows(function() { Realm.eval(realmIndex, "A.call()") }, | |
649 otherTypeError); | |
650 assertThrows(function() { constructor.call() }, otherTypeError); | |
651 assertThrows(function() { A.call() }, otherTypeError); | |
652 })(); | |
653 | 628 |
654 (function TestDefaultConstructor() { | 629 (function TestDefaultConstructor() { |
655 var calls = 0; | 630 var calls = 0; |
656 class Base { | 631 class Base { |
657 constructor() { | 632 constructor() { |
658 calls++; | 633 calls++; |
659 } | 634 } |
660 } | 635 } |
661 class Derived extends Base {} | 636 class Derived extends Base {} |
662 var object = new Derived; | 637 var object = new Derived; |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 testClassRestrictedProperties(ClassWithDefaultConstructor); | 939 testClassRestrictedProperties(ClassWithDefaultConstructor); |
965 testClassRestrictedProperties(Class); | 940 testClassRestrictedProperties(Class); |
966 testClassRestrictedProperties(DerivedClassWithDefaultConstructor); | 941 testClassRestrictedProperties(DerivedClassWithDefaultConstructor); |
967 testClassRestrictedProperties(DerivedClass); | 942 testClassRestrictedProperties(DerivedClass); |
968 testClassRestrictedProperties(class { method() {} }); | 943 testClassRestrictedProperties(class { method() {} }); |
969 testClassRestrictedProperties(class { constructor() {} method() {} }); | 944 testClassRestrictedProperties(class { constructor() {} method() {} }); |
970 testClassRestrictedProperties(class extends Class { }); | 945 testClassRestrictedProperties(class extends Class { }); |
971 testClassRestrictedProperties( | 946 testClassRestrictedProperties( |
972 class extends Class { constructor() { super(); } }); | 947 class extends Class { constructor() { super(); } }); |
973 })(); | 948 })(); |
OLD | NEW |