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

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

Issue 1427483002: [es6] Better support for built-ins subclassing. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Avoid crashes in case of Function subclassing Created 5 years, 1 month 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/runtime/runtime-object.cc ('K') | « src/x64/builtins-x64.cc ('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
(Empty)
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
3 // found in the LICENSE file.
4
5 // Flags: --allow-natives-syntax
6
7 "use strict";
8
9
10 function checkPrototypeChain(object, constructors) {
11 var proto = object.__proto__;
12 for (var i = 0; i < constructors.length; i++) {
13 assertEquals(constructors[i].prototype, proto);
14 assertEquals(constructors[i], proto.constructor);
15 proto = proto.__proto__;
16 }
17 }
18
19
20 /*
21 // TODO(ishell): BUG: v8:3101, fix this case.
22 (function() {
23 class A extends Object {
24 constructor(v) {
25 assertTrue(%IsConstructCall());
26 super(v);
27 this.a = 42;
28 }
29 }
30
31 var s = new A("foo");
32 assertTrue(s instanceof Object);
33 assertTrue(s instanceof String);
34 assertTrue(s instanceof A);
35 assertEquals("foo", s.valueOf());
36 assertEquals(42, s.a);
37
38 var s1 = new A("bar");
39 assertTrue(%HaveSameMap(s, s1));
40
41
42 var n = new A(153);
43 assertTrue(n instanceof Object);
44 assertTrue(n instanceof Number);
45 assertTrue(n instanceof A);
46 assertEquals(153, n.valueOf());
47 assertEquals(42, n.a);
48
49 var n1 = new A(312);
50 assertTrue(%HaveSameMap(n, n1));
51 assertTrue(%HaveSameMap(n, s));
52
53
54 var b = new A(true);
55 assertTrue(b instanceof Object);
56 assertTrue(b instanceof Boolean);
57 assertTrue(b instanceof A);
58 assertEquals(153, b.valueOf());
59 assertEquals(42, b.a);
60
61 var b1 = new A(true);
62 assertTrue(%HaveSameMap(b, b1));
63 assertTrue(%HaveSameMap(b, s));
64
65 })();
66 //*/
67
68
69 (function() {
70 class A extends String {
71 constructor(v) {
72 assertTrue(%IsConstructCall());
73 super(v);
74 this.a = 42;
75 }
76 }
77
78 var o = new A("foo");
79 assertTrue(o instanceof Object);
80 assertTrue(o instanceof String);
81 assertTrue(o instanceof A);
82 assertEquals("object", typeof o);
83 checkPrototypeChain(o, [A, String]);
84
85 assertEquals("foo", o.valueOf());
86 assertEquals(42, o.a);
87
88 var o1 = new A("bar");
89 assertTrue(%HaveSameMap(o, o1));
90 })();
91
92
93 (function() {
94 class A extends Number {
95 constructor(v) {
96 assertTrue(%IsConstructCall());
97 super(v);
98 this.a = 42;
99 }
100 }
101
102 var o = new A(153);
103 assertTrue(o instanceof Object);
104 assertTrue(o instanceof Number);
105 assertTrue(o instanceof A);
106 assertEquals("object", typeof o);
107 checkPrototypeChain(o, [A, Number]);
108 assertEquals(153, o.valueOf());
109 assertEquals(42, o.a);
110
111 var o1 = new A(312);
112 assertTrue(%HaveSameMap(o, o1));
113 })();
114
115
116 (function() {
117 class A extends Boolean {
118 constructor(v) {
119 assertTrue(%IsConstructCall());
120 super(v);
121 this.a = 42;
122 }
123 }
124
125 var o = new A(true);
126 assertTrue(o instanceof Object);
127 assertTrue(o instanceof Boolean);
128 assertTrue(o instanceof A);
129 assertEquals("object", typeof o);
130 checkPrototypeChain(o, [A, Boolean]);
131 assertTrue(o.valueOf());
132 assertEquals(42, o.a);
133
134 var o1 = new A(false);
135 assertTrue(%HaveSameMap(o, o1));
136 })();
137
138
139 /*
140 // TODO(ishell): BUG: v8:3101, fix this case.
141 (function() {
142 class A extends Function {
143 constructor(v) {
144 assertTrue(%IsConstructCall());
145 super(v);
146 this.a = 42;
147 }
148 }
149
150 var o = new A("return 153;");
151 assertTrue(o instanceof Function);
152 assertTrue(o instanceof A);
153 assertTrue(o instanceof Object);
154 assertEquals("function", typeof o);
155 checkPrototypeChain(o, [A, Function]);
156 assertEquals(42, o.a);
157
158 var o1 = new A("return 312;");
159 assertTrue(%HaveSameMap(o, o1));
160 })();
161 //*/
162
163
164 (function() {
165 class A extends Array {
166 constructor(v) {
167 assertTrue(%IsConstructCall());
168 super(v);
169 this.a = 42;
170 }
171 }
172
173 var o = new A(10);
174 assertTrue(o instanceof Object);
175 assertTrue(o instanceof Array);
176 assertTrue(o instanceof A);
177 assertEquals("object", typeof o);
178 checkPrototypeChain(o, [A, Array]);
179 assertEquals(10, o.length);
180 assertEquals(42, o.a);
181
182 var o1 = new A(7);
183 assertTrue(%HaveSameMap(o, o1));
184 })();
185
186
187 (function() {
188 class A extends Int32Array {
189 constructor(v) {
190 assertTrue(%IsConstructCall());
191 super(v);
192 this.a = 42;
193 }
194 }
195
196 var o = new A(10);
197 assertTrue(o instanceof Object);
198 assertTrue(o instanceof Int32Array);
199 assertTrue(o instanceof A);
200 assertEquals("object", typeof o);
201 checkPrototypeChain(o, [A, Int32Array]);
202 assertEquals(10, o.length);
203 assertEquals(42, o.a);
204
205 var o1 = new A(7);
206 assertTrue(%HaveSameMap(o, o1));
207 })();
208
209
210 (function() {
211 class A extends RegExp {
212 constructor(v) {
213 assertTrue(%IsConstructCall());
214 super(v);
215 this.a = 42;
216 }
217 }
218
219 var o = new A("o..h");
220 assertTrue(o instanceof Object);
221 assertTrue(o instanceof RegExp);
222 assertTrue(o instanceof A);
223 assertEquals("object", typeof o);
224 checkPrototypeChain(o, [A, RegExp]);
225 assertTrue(o.test("ouch"));
226 assertEquals(42, o.a);
227
228 var o1 = new A(7);
229 assertTrue(%HaveSameMap(o, o1));
230 })();
231
232
233 (function() {
234 class A extends Boolean {
235 constructor() {
236 assertTrue(%IsConstructCall());
237 super(true);
238 this.a00 = 0
239 this.a01 = 0
240 this.a02 = 0
241 this.a03 = 0
242 this.a04 = 0
243 this.a05 = 0
244 this.a06 = 0
245 this.a07 = 0
246 this.a08 = 0
247 this.a09 = 0
248 this.a10 = 0
249 this.a11 = 0
250 this.a12 = 0
251 this.a13 = 0
252 this.a14 = 0
253 this.a15 = 0
254 this.a16 = 0
255 this.a17 = 0
256 this.a18 = 0
257 this.a19 = 0
258 }
259 }
260
261 class B extends A {
262 constructor() {
263 assertTrue(%IsConstructCall());
264 super();
265 this.b00 = 0
266 this.b01 = 0
267 this.b02 = 0
268 this.b03 = 0
269 this.b04 = 0
270 this.b05 = 0
271 this.b06 = 0
272 this.b07 = 0
273 this.b08 = 0
274 this.b09 = 0
275 this.b10 = 0
276 this.b11 = 0
277 this.b12 = 0
278 this.b13 = 0
279 this.b14 = 0
280 this.b15 = 0
281 this.b16 = 0
282 this.b17 = 0
283 this.b18 = 0
284 this.b19 = 0
285 }
286 }
287
288 class C extends B {
289 constructor() {
290 assertTrue(%IsConstructCall());
291 super();
292 this.c00 = 0
293 this.c01 = 0
294 this.c02 = 0
295 this.c03 = 0
296 this.c04 = 0
297 this.c05 = 0
298 this.c06 = 0
299 this.c07 = 0
300 this.c08 = 0
301 this.c09 = 0
302 this.c10 = 0
303 this.c11 = 0
304 this.c12 = 0
305 this.c13 = 0
306 this.c14 = 0
307 this.c15 = 0
308 this.c16 = 0
309 this.c17 = 0
310 this.c18 = 0
311 this.c19 = 0
312 }
313 }
314
315 var o = new C();
316 assertTrue(o instanceof Object);
317 assertTrue(o instanceof Boolean);
318 assertTrue(o instanceof A);
319 assertTrue(o instanceof B);
320 assertTrue(o instanceof C);
321 assertEquals("object", typeof o);
322 checkPrototypeChain(o, [C, B, A, Boolean]);
323 })();
324
325
326 (function() {
327 assertThrows("class A extends undefined {}");
328 assertThrows("class B extends NaN {}");
329 assertThrows("class C extends Infinity {}");
330 })();
331
332
333 (function() {
334 class A extends null {}
335 assertThrows("new A");
336 })();
337
338
339 (function() {
340 class A extends Symbol {}
341 assertThrows("new A");
342 })();
OLDNEW
« src/runtime/runtime-object.cc ('K') | « src/x64/builtins-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698