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

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

Issue 1510753005: Fix Function subclassing. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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
« src/objects.cc ('K') | « src/transitions-inl.h ('k') | no next file » | 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 6 // Flags: --expose-gc --strong-mode
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 gc(); 72 gc();
73 })(); 73 })();
74 74
75 75
76 (function() { 76 (function() {
77 class A extends Function { 77 class A extends Function {
78 constructor(...args) { 78 constructor(...args) {
79 assertFalse(new.target === undefined); 79 assertFalse(new.target === undefined);
80 super(...args); 80 super(...args);
81 // Strong functions are not extensible, so don't add fields.
82 if (args[args.length - 1].indexOf("use strong") >= 0) return;
81 this.a = 42; 83 this.a = 42;
82 this.d = 4.2; 84 this.d = 4.2;
83 this.o = {foo:153}; 85 this.o = {foo:153};
84 } 86 }
85 } 87 }
88 var sloppy_func = new A("");
89 var strict_func = new A("'use strict';");
90 assertNull(sloppy_func.caller);
91 assertThrows("strict_f.caller");
92 assertNull(Object.getOwnPropertyDescriptor(sloppy_func, "caller").value);
93 assertEquals(undefined, Object.getOwnPropertyDescriptor(strict_func, "caller") );
86 94
87 var o = new A("this.foo = 113;"); 95 var sloppy_func = new A("this.foo = 113;");
88 assertTrue(o instanceof Object); 96 assertTrue(undefined !== sloppy_func.prototype);
89 assertTrue(o instanceof Function); 97 sloppy_func.prototype.bar = 377;
90 assertTrue(o instanceof A); 98 assertTrue(sloppy_func instanceof Object);
91 assertEquals("function", typeof o); 99 assertTrue(sloppy_func instanceof Function);
92 checkPrototypeChain(o, [A, Function, Object]); 100 assertTrue(sloppy_func instanceof A);
93 assertEquals(42, o.a); 101 assertEquals("function", typeof sloppy_func);
94 assertEquals(4.2, o.d); 102 checkPrototypeChain(sloppy_func, [A, Function, Object]);
95 assertEquals(153, o.o.foo); 103 assertEquals(42, sloppy_func.a);
96 var oo = new o(); 104 assertEquals(4.2, sloppy_func.d);
105 assertEquals(153, sloppy_func.o.foo);
106 var oo = new sloppy_func();
97 assertEquals(113, oo.foo); 107 assertEquals(113, oo.foo);
108 assertEquals(377, oo.bar);
98 109
99 var o1 = new A("return 312;"); 110 var sloppy_func1 = new A("return 312;");
100 assertTrue(%HaveSameMap(o, o1)); 111 assertTrue(%HaveSameMap(sloppy_func, sloppy_func1));
112
113
114 var strict_func = new A("'use strict'; this.foo = 113;");
115 assertFalse(%HaveSameMap(strict_func, sloppy_func));
116
117 var strict_func1 = new A("'use strict'; return 312;");
118 assertTrue(%HaveSameMap(strict_func, strict_func1));
119
120
121 var strong_func = new A("'use strong'; this.foo = 113");
122 assertFalse(%HaveSameMap(strong_func, sloppy_func));
123 assertFalse(%HaveSameMap(strong_func, strict_func));
124
125 var strong_func1 = new A("'use strong'; return 312;");
126 assertTrue(%HaveSameMap(strong_func, strong_func1));
101 127
102 gc(); 128 gc();
103 })(); 129 })();
104 130
105 131
106 (function() { 132 (function() {
107 class A extends Boolean { 133 class A extends Boolean {
108 constructor(...args) { 134 constructor(...args) {
109 assertFalse(new.target === undefined); 135 assertFalse(new.target === undefined);
110 super(...args); 136 super(...args);
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 847
822 Object.defineProperty(pattern, Symbol.match, { 848 Object.defineProperty(pattern, Symbol.match, {
823 get() { log.push("match"); f.prototype = p2; return false; }}); 849 get() { log.push("match"); f.prototype = p2; return false; }});
824 850
825 var o = Reflect.construct(RegExp, [pattern], f); 851 var o = Reflect.construct(RegExp, [pattern], f);
826 assertEquals(["match", "tostring"], log); 852 assertEquals(["match", "tostring"], log);
827 assertEquals(/biep/, o); 853 assertEquals(/biep/, o);
828 assertTrue(o.__proto__ === p2); 854 assertTrue(o.__proto__ === p2);
829 assertTrue(f.prototype === p3); 855 assertTrue(f.prototype === p3);
830 })(); 856 })();
OLDNEW
« src/objects.cc ('K') | « src/transitions-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698