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 --harmony-reflect --harmony-regexp-subclass |
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__; |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
597 (function() { | 597 (function() { |
598 class A extends null {} | 598 class A extends null {} |
599 assertThrows("new A"); | 599 assertThrows("new A"); |
600 })(); | 600 })(); |
601 | 601 |
602 | 602 |
603 (function() { | 603 (function() { |
604 class A extends Symbol {} | 604 class A extends Symbol {} |
605 assertThrows("new A"); | 605 assertThrows("new A"); |
606 })(); | 606 })(); |
607 | |
608 | |
609 (function() { | |
610 function f() {} | |
611 | |
612 var p = f.prototype; | |
613 var p2 = {}; | |
614 var o = Reflect.construct( | |
615 Number, [{valueOf() { f.prototype=p2; return 10; }}], f); | |
616 | |
617 assertTrue(o.__proto__ === f.prototype); | |
618 assertTrue(p2 === f.prototype); | |
619 assertFalse(p === o.__proto__); | |
620 assertEquals(10, Number.prototype.valueOf.call(o)); | |
621 })(); | |
622 | |
623 | |
624 (function() { | |
625 function f() {} | |
626 | |
627 var p = f.prototype; | |
628 var p2 = {}; | |
629 var o = Reflect.construct( | |
630 String, [{toString() { f.prototype=p2; return "biep"; }}], f); | |
631 | |
632 assertEquals(o.__proto__, f.prototype); | |
Igor Sheludko
2015/11/19 10:50:03
assertTrue(p2 === f.prototype);
| |
633 assertFalse(p === o.__proto__); | |
634 assertEquals("biep", String.prototype.toString.call(o)); | |
635 })(); | |
636 | |
637 | |
638 (function() { | |
639 function f() {} | |
640 | |
641 var p = f.prototype; | |
642 var p2 = {}; | |
643 var o = Reflect.construct( | |
644 Date, [{valueOf() { f.prototype=p2; return 1447836899614; }}], f); | |
645 | |
646 assertTrue(o.__proto__ === f.prototype); | |
647 assertTrue(p2 === f.prototype); | |
648 assertFalse(p === o.__proto__); | |
649 assertEquals(new Date(1447836899614).toString(), | |
650 Date.prototype.toString.call(o)); | |
651 })(); | |
652 | |
653 | |
654 (function() { | |
655 function f() {} | |
656 | |
657 var p = f.prototype; | |
658 var p2 = {}; | |
659 var o = Reflect.construct( | |
660 Date, [2015, {valueOf() { f.prototype=p2; return 10; }}], f); | |
661 | |
662 assertTrue(o.__proto__ === f.prototype); | |
663 assertTrue(p2 === f.prototype); | |
664 assertFalse(p === o.__proto__); | |
665 assertEquals(new Date(2015, 10).getYear(), Date.prototype.getYear.call(o)); | |
666 assertEquals(new Date(2015, 10).getMonth(), Date.prototype.getMonth.call(o)); | |
667 })(); | |
668 | |
669 | |
670 (function() { | |
671 function f() {} | |
672 | |
673 var p = f.prototype; | |
674 var p2 = {}; | |
675 var o = Reflect.construct( | |
676 DataView, [new ArrayBuffer(100), | |
677 {valueOf(){ f.prototype=p2; return 5; }}], f); | |
678 | |
679 var byteOffset = Object.getOwnPropertyDescriptor( | |
680 DataView.prototype, "byteOffset").get; | |
681 var byteLength = Object.getOwnPropertyDescriptor( | |
682 DataView.prototype, "byteLength").get; | |
683 | |
684 assertTrue(o.__proto__ === f.prototype); | |
685 assertTrue(p2 === f.prototype); | |
686 assertFalse(p === o.__proto__); | |
687 assertEquals(5, byteOffset.call(o)); | |
688 assertEquals(95, byteLength.call(o)); | |
689 })(); | |
690 | |
691 | |
692 (function() { | |
693 function f() {} | |
694 | |
695 var p = f.prototype; | |
696 var p2 = {}; | |
697 var o = Reflect.construct( | |
698 DataView, [new ArrayBuffer(100), | |
699 30, {valueOf() { f.prototype=p2; return 5; }}], f); | |
700 | |
701 var byteOffset = Object.getOwnPropertyDescriptor( | |
702 DataView.prototype, "byteOffset").get; | |
703 var byteLength = Object.getOwnPropertyDescriptor( | |
704 DataView.prototype, "byteLength").get; | |
705 | |
706 assertTrue(o.__proto__ === f.prototype); | |
707 assertTrue(p2 === f.prototype); | |
708 assertFalse(p === o.__proto__); | |
709 assertEquals(30, byteOffset.call(o)); | |
710 assertEquals(5, byteLength.call(o)); | |
711 })(); | |
712 | |
713 | |
714 (function() { | |
715 function f() {} | |
716 | |
717 var p = f.prototype; | |
718 var p2 = {}; | |
719 var p3 = {}; | |
720 | |
721 var log = []; | |
722 | |
723 var pattern = {toString() { | |
724 log.push("tostring"); | |
725 f.prototype = p3; return "biep" }}; | |
726 | |
727 Object.defineProperty(pattern, Symbol.match, { | |
728 get() { log.push("match"); f.prototype = p2; return false; }}); | |
729 | |
730 var o = Reflect.construct(RegExp, [pattern], f); | |
731 assertEquals(["match", "tostring"], log); | |
732 assertEquals(/biep/, o); | |
733 assertTrue(o.__proto__ === p2); | |
734 assertTrue(f.prototype === p3); | |
735 })(); | |
OLD | NEW |