Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: test/mjsunit/es6/classes-subclass-builtins.js

Issue 1773653002: [strong] Remove all remainders of strong mode (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Oversight Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/test-parsing.cc ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 --harmony-reflect --harmony-regexp-subclass 5 // Flags: --allow-natives-syntax --harmony-reflect --harmony-regexp-subclass
6 // Flags: --expose-gc --strong-mode 6 // Flags: --expose-gc
7 7
8 "use strict"; 8 "use strict";
9 9
10 10
11 function checkPrototypeChain(object, constructors) { 11 function checkPrototypeChain(object, constructors) {
12 var proto = object.__proto__; 12 var proto = object.__proto__;
13 for (var i = 0; i < constructors.length; i++) { 13 for (var i = 0; i < constructors.length; i++) {
14 assertEquals(constructors[i].prototype, proto); 14 assertEquals(constructors[i].prototype, proto);
15 assertEquals(constructors[i], proto.constructor); 15 assertEquals(constructors[i], proto.constructor);
16 proto = proto.__proto__; 16 proto = proto.__proto__;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 this.o = {foo:153}; 83 this.o = {foo:153};
84 } 84 }
85 } 85 }
86 var sloppy_func = new A(""); 86 var sloppy_func = new A("");
87 var strict_func = new A("'use strict';"); 87 var strict_func = new A("'use strict';");
88 assertNull(sloppy_func.caller); 88 assertNull(sloppy_func.caller);
89 assertThrows("strict_f.caller"); 89 assertThrows("strict_f.caller");
90 assertNull(Object.getOwnPropertyDescriptor(sloppy_func, "caller").value); 90 assertNull(Object.getOwnPropertyDescriptor(sloppy_func, "caller").value);
91 assertEquals(undefined, Object.getOwnPropertyDescriptor(strict_func, "caller") ); 91 assertEquals(undefined, Object.getOwnPropertyDescriptor(strict_func, "caller") );
92 92
93 function CheckFunction(func, is_strong) { 93 function CheckFunction(func) {
94 assertEquals("function", typeof func); 94 assertEquals("function", typeof func);
95 assertTrue(func instanceof Object); 95 assertTrue(func instanceof Object);
96 assertTrue(func instanceof Function); 96 assertTrue(func instanceof Function);
97 assertTrue(func instanceof A); 97 assertTrue(func instanceof A);
98 checkPrototypeChain(func, [A, Function, Object]); 98 checkPrototypeChain(func, [A, Function, Object]);
99 if (!is_strong) { 99 assertEquals(42, func.a);
100 assertEquals(42, func.a); 100 assertEquals(4.2, func.d);
101 assertEquals(4.2, func.d); 101 assertEquals(153, func.o.foo);
102 assertEquals(153, func.o.foo); 102 assertTrue(undefined !== func.prototype);
103 assertTrue(undefined !== func.prototype); 103 func.prototype.bar = "func.bar";
104 func.prototype.bar = "func.bar"; 104 var obj = new func();
105 var obj = new func(); 105 assertTrue(obj instanceof Object);
106 assertTrue(obj instanceof Object); 106 assertTrue(obj instanceof func);
107 assertTrue(obj instanceof func); 107 assertEquals("object", typeof obj);
108 assertEquals("object", typeof obj); 108 assertEquals(113, obj.foo);
109 assertEquals(113, obj.foo); 109 assertEquals("func.bar", obj.bar);
110 assertEquals("func.bar", obj.bar); 110 delete func.prototype.bar;
111 delete func.prototype.bar;
112 }
113 } 111 }
114 112
115 var source = "this.foo = 113;"; 113 var source = "this.foo = 113;";
116 114
117 // Sloppy function 115 // Sloppy function
118 var sloppy_func = new A(source); 116 var sloppy_func = new A(source);
119 assertTrue(undefined !== sloppy_func.prototype); 117 assertTrue(undefined !== sloppy_func.prototype);
120 CheckFunction(sloppy_func, false); 118 CheckFunction(sloppy_func, false);
121 119
122 var sloppy_func1 = new A("return 312;"); 120 var sloppy_func1 = new A("return 312;");
123 assertTrue(%HaveSameMap(sloppy_func, sloppy_func1)); 121 assertTrue(%HaveSameMap(sloppy_func, sloppy_func1));
124 122
125 // Strict function 123 // Strict function
126 var strict_func = new A("'use strict'; " + source); 124 var strict_func = new A("'use strict'; " + source);
127 assertFalse(%HaveSameMap(strict_func, sloppy_func)); 125 assertFalse(%HaveSameMap(strict_func, sloppy_func));
128 CheckFunction(strict_func, false); 126 CheckFunction(strict_func, false);
129 127
130 var strict_func1 = new A("'use strict'; return 312;"); 128 var strict_func1 = new A("'use strict'; return 312;");
131 assertTrue(%HaveSameMap(strict_func, strict_func1)); 129 assertTrue(%HaveSameMap(strict_func, strict_func1));
132 130
133 // Strong function
134 var strong_func = new A("'use strong'; " + source);
135 assertFalse(%HaveSameMap(strong_func, sloppy_func));
136 assertFalse(%HaveSameMap(strong_func, strict_func));
137 CheckFunction(strong_func, true);
138
139 var strong_func1 = new A("'use strong'; return 312;");
140 assertTrue(%HaveSameMap(strong_func, strong_func1));
141
142 gc(); 131 gc();
143 })(); 132 })();
144 133
145 134
146 (function() { 135 (function() {
147 class A extends Boolean { 136 class A extends Boolean {
148 constructor(...args) { 137 constructor(...args) {
149 assertFalse(new.target === undefined); 138 assertFalse(new.target === undefined);
150 super(...args); 139 super(...args);
151 this.a = 42; 140 this.a = 42;
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 gc(); 569 gc();
581 })(); 570 })();
582 571
583 572
584 (function() { 573 (function() {
585 var GeneratorFunction = (function*() {}).constructor; 574 var GeneratorFunction = (function*() {}).constructor;
586 class A extends GeneratorFunction { 575 class A extends GeneratorFunction {
587 constructor(...args) { 576 constructor(...args) {
588 assertFalse(new.target === undefined); 577 assertFalse(new.target === undefined);
589 super(...args); 578 super(...args);
590 // Strong functions are not extensible, so don't add fields.
591 if (args[args.length - 1].indexOf("use strong") >= 0) {
592 assertThrows(()=>{ this.a = 10; }, TypeError);
593 return;
594 }
595 this.a = 42; 579 this.a = 42;
596 this.d = 4.2; 580 this.d = 4.2;
597 this.o = {foo:153}; 581 this.o = {foo:153};
598 } 582 }
599 } 583 }
600 var sloppy_func = new A("yield 153;"); 584 var sloppy_func = new A("yield 153;");
601 var strict_func = new A("'use strict'; yield 153;"); 585 var strict_func = new A("'use strict'; yield 153;");
602 // Unfortunately the difference is not observable from outside. 586 // Unfortunately the difference is not observable from outside.
603 assertThrows("sloppy_func.caller"); 587 assertThrows("sloppy_func.caller");
604 assertThrows("strict_f.caller"); 588 assertThrows("strict_f.caller");
605 assertEquals(undefined, Object.getOwnPropertyDescriptor(sloppy_func, "caller") ); 589 assertEquals(undefined, Object.getOwnPropertyDescriptor(sloppy_func, "caller") );
606 assertEquals(undefined, Object.getOwnPropertyDescriptor(strict_func, "caller") ); 590 assertEquals(undefined, Object.getOwnPropertyDescriptor(strict_func, "caller") );
607 591
608 function CheckFunction(func, is_strong) { 592 function CheckFunction(func) {
609 assertEquals("function", typeof func); 593 assertEquals("function", typeof func);
610 assertTrue(func instanceof Object); 594 assertTrue(func instanceof Object);
611 assertTrue(func instanceof Function); 595 assertTrue(func instanceof Function);
612 assertTrue(func instanceof GeneratorFunction); 596 assertTrue(func instanceof GeneratorFunction);
613 assertTrue(func instanceof A); 597 assertTrue(func instanceof A);
614 checkPrototypeChain(func, [A, GeneratorFunction, Function, Object]); 598 checkPrototypeChain(func, [A, GeneratorFunction, Function, Object]);
615 if (!is_strong) {
616 assertEquals(42, func.a);
617 assertEquals(4.2, func.d);
618 assertEquals(153, func.o.foo);
619 599
620 assertTrue(undefined !== func.prototype); 600 assertEquals(42, func.a);
621 func.prototype.bar = "func.bar"; 601 assertEquals(4.2, func.d);
622 var obj = func(); // Generator object. 602 assertEquals(153, func.o.foo);
623 assertTrue(obj instanceof Object);
624 assertTrue(obj instanceof func);
625 assertEquals("object", typeof obj);
626 assertEquals("func.bar", obj.bar);
627 delete func.prototype.bar;
628 603
629 assertPropertiesEqual({done: false, value: 1}, obj.next()); 604 assertTrue(undefined !== func.prototype);
630 assertPropertiesEqual({done: false, value: 1}, obj.next()); 605 func.prototype.bar = "func.bar";
631 assertPropertiesEqual({done: false, value: 2}, obj.next()); 606 var obj = func(); // Generator object.
632 assertPropertiesEqual({done: false, value: 3}, obj.next()); 607 assertTrue(obj instanceof Object);
633 assertPropertiesEqual({done: false, value: 5}, obj.next()); 608 assertTrue(obj instanceof func);
634 assertPropertiesEqual({done: false, value: 8}, obj.next()); 609 assertEquals("object", typeof obj);
635 assertPropertiesEqual({done: true, value: undefined}, obj.next()); 610 assertEquals("func.bar", obj.bar);
636 } 611 delete func.prototype.bar;
612
613 assertPropertiesEqual({done: false, value: 1}, obj.next());
614 assertPropertiesEqual({done: false, value: 1}, obj.next());
615 assertPropertiesEqual({done: false, value: 2}, obj.next());
616 assertPropertiesEqual({done: false, value: 3}, obj.next());
617 assertPropertiesEqual({done: false, value: 5}, obj.next());
618 assertPropertiesEqual({done: false, value: 8}, obj.next());
619 assertPropertiesEqual({done: true, value: undefined}, obj.next());
637 } 620 }
638 621
639 var source = "yield 1; yield 1; yield 2; yield 3; yield 5; yield 8;"; 622 var source = "yield 1; yield 1; yield 2; yield 3; yield 5; yield 8;";
640 623
641 // Sloppy generator function 624 // Sloppy generator function
642 var sloppy_func = new A(source); 625 var sloppy_func = new A(source);
643 assertTrue(undefined !== sloppy_func.prototype); 626 assertTrue(undefined !== sloppy_func.prototype);
644 CheckFunction(sloppy_func, false); 627 CheckFunction(sloppy_func, false);
645 628
646 var sloppy_func1 = new A("yield 312;"); 629 var sloppy_func1 = new A("yield 312;");
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 916
934 Object.defineProperty(pattern, Symbol.match, { 917 Object.defineProperty(pattern, Symbol.match, {
935 get() { log.push("match"); f.prototype = p2; return false; }}); 918 get() { log.push("match"); f.prototype = p2; return false; }});
936 919
937 var o = Reflect.construct(RegExp, [pattern], f); 920 var o = Reflect.construct(RegExp, [pattern], f);
938 assertEquals(["match", "tostring"], log); 921 assertEquals(["match", "tostring"], log);
939 assertEquals(/biep/, o); 922 assertEquals(/biep/, o);
940 assertTrue(o.__proto__ === p2); 923 assertTrue(o.__proto__ === p2);
941 assertTrue(f.prototype === p3); 924 assertTrue(f.prototype === p3);
942 })(); 925 })();
OLDNEW
« no previous file with comments | « test/cctest/test-parsing.cc ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698