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

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

Issue 1415683007: Reland "[es6] Fix Function and GeneratorFunction built-ins subclassing." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@fix-subclass
Patch Set: Improved test 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
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 5 // Flags: --allow-natives-syntax
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__;
16 } 16 }
17 } 17 }
18 18
19 19
20 (function() { 20 (function() {
21 class A extends Function {
22 constructor(...args) {
23 assertTrue(%IsConstructCall());
24 super(...args);
25 this.a = 42;
26 this.d = 4.2;
27 }
28 }
29
30 var o = new A("this.foo = 153;");
31 assertTrue(o instanceof Object);
32 assertTrue(o instanceof Function);
33 assertTrue(o instanceof A);
34 assertEquals("function", typeof o);
35 checkPrototypeChain(o, [A, Function, Object]);
36 assertEquals(42, o.a);
37 assertEquals(4.2, o.d);
38 var oo = new o();
39 assertEquals(153, oo.foo);
40
41 var o1 = new A("return 312;");
42 assertTrue(%HaveSameMap(o, o1));
43 })();
44
45
46 (function() {
21 class A extends Boolean { 47 class A extends Boolean {
22 constructor(...args) { 48 constructor(...args) {
23 assertTrue(%IsConstructCall()); 49 assertTrue(%IsConstructCall());
24 super(...args); 50 super(...args);
25 this.a = 42; 51 this.a = 42;
26 this.d = 4.2; 52 this.d = 4.2;
27 } 53 }
28 } 54 }
29 55
30 var o = new A(true); 56 var o = new A(true);
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 assertEquals(42, o.a); 344 assertEquals(42, o.a);
319 assertEquals(4.2, o.d); 345 assertEquals(4.2, o.d);
320 346
321 var o1 = new A(buffer); 347 var o1 = new A(buffer);
322 assertTrue(%HaveSameMap(o, o1)); 348 assertTrue(%HaveSameMap(o, o1));
323 349
324 })(); 350 })();
325 351
326 352
327 (function() { 353 (function() {
354 // TODO(ishell): remove once GeneratorFunction is available.
355 var GeneratorFunction = (function*() {}).__proto__.constructor;
356 class A extends GeneratorFunction {
357 constructor(...args) {
358 assertTrue(%IsConstructCall());
359 super(...args);
360 this.a = 42;
361 this.d = 4.2;
362 }
363 }
364 var generator_func = new A("var index = 0; while (index < 5) { yield ++index; }");
365 assertTrue(generator_func instanceof Object);
366 assertTrue(generator_func instanceof Function);
367 assertTrue(generator_func instanceof GeneratorFunction);
368 assertTrue(generator_func instanceof A);
369 assertEquals("function", typeof generator_func);
370 checkPrototypeChain(generator_func, [A, GeneratorFunction, Function, Object]);
371 assertEquals(42, generator_func.a);
372 assertEquals(4.2, generator_func.d);
373
374 var o = new generator_func();
375 assertTrue(o instanceof Object);
376 assertTrue(o instanceof generator_func);
377 assertEquals("object", typeof o);
378
379 assertPropertiesEqual({done: false, value: 1}, o.next());
380 assertPropertiesEqual({done: false, value: 2}, o.next());
381 assertPropertiesEqual({done: false, value: 3}, o.next());
382 assertPropertiesEqual({done: false, value: 4}, o.next());
383 assertPropertiesEqual({done: false, value: 5}, o.next());
384 assertPropertiesEqual({done: true, value: undefined}, o.next());
385
386 var generator_func1 = new A("return 0;");
387 assertTrue(%HaveSameMap(generator_func, generator_func1));
388 })();
389
390
391 (function() {
328 class A extends Boolean { 392 class A extends Boolean {
329 constructor() { 393 constructor() {
330 assertTrue(%IsConstructCall()); 394 assertTrue(%IsConstructCall());
331 super(true); 395 super(true);
332 this.a00 = 0 396 this.a00 = 0
333 this.a01 = 0 397 this.a01 = 0
334 this.a02 = 0 398 this.a02 = 0
335 this.a03 = 0 399 this.a03 = 0
336 this.a04 = 0 400 this.a04 = 0
337 this.a05 = 0 401 this.a05 = 0
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 (function() { 491 (function() {
428 class A extends null {} 492 class A extends null {}
429 assertThrows("new A"); 493 assertThrows("new A");
430 })(); 494 })();
431 495
432 496
433 (function() { 497 (function() {
434 class A extends Symbol {} 498 class A extends Symbol {}
435 assertThrows("new A"); 499 assertThrows("new A");
436 })(); 500 })();
OLDNEW
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | test/mjsunit/regress/regress-function-constructor-receiver.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698