Chromium Code Reviews| OLD | NEW |
|---|---|
| (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: --harmony-classes --harmony-new-target --harmony-reflect | |
| 6 // Flags: --harmony-rest-parameters | |
| 7 | |
| 8 'use strict'; | |
| 9 | |
| 10 | |
| 11 (function TestBasics() { | |
| 12 class Base {} | |
| 13 class Derived extends Base { | |
| 14 constructor(expected) { | |
| 15 super(); | |
| 16 assertEquals(expected, new.target); | |
| 17 } | |
| 18 } | |
| 19 new Derived(Derived); | |
| 20 | |
| 21 class Derived2 extends Derived {} | |
| 22 new Derived2(Derived2); | |
| 23 })(); | |
| 24 | |
| 25 | |
| 26 (function TestFunctionCall() { | |
| 27 function f(expected) { | |
| 28 assertEquals(expected, new.target); | |
| 29 } | |
| 30 | |
| 31 f(undefined); | |
| 32 f(); | |
| 33 | |
| 34 f(undefined, 'extra'); | |
|
arv (Not doing code reviews)
2015/06/18 22:17:59
This one fails. `expected` ends up as the 'extra'.
| |
| 35 | |
| 36 f.call({}, undefined); | |
| 37 f.apply({}, [undefined]); | |
| 38 })(); | |
| 39 | |
| 40 | |
| 41 (function TestFunctionRest() { | |
| 42 function f(...rest) { | |
| 43 assertEquals(rest[0], new.target); | |
| 44 } | |
| 45 | |
| 46 new f(f); | |
|
arv (Not doing code reviews)
2015/06/18 22:17:59
This one fails.
| |
| 47 new f(f, 'extra'); | |
| 48 | |
| 49 f(undefined); | |
| 50 f(undefined, 'extra'); | |
| 51 })(); | |
| 52 | |
| 53 | |
| 54 (function TestReflectConstruct() { | |
| 55 function f(expected) { | |
| 56 assertEquals(expected, new.target); | |
| 57 } | |
| 58 | |
| 59 Reflect.construct(f, [f]); | |
| 60 Reflect.construct(f, [f], f); | |
| 61 Reflect.construct(f, [f, 'extra']); | |
| 62 Reflect.construct(f, [f, 'extra'], f); | |
| 63 })(); | |
| 64 | |
| 65 | |
| 66 (function TestExtendsFunction() { | |
| 67 function Base() { | |
| 68 assertEquals(Derived, new.target); | |
| 69 } | |
| 70 | |
| 71 class Derived extends Base { | |
| 72 constructor() { | |
| 73 super(); | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 new Derived(); | |
|
arv (Not doing code reviews)
2015/06/18 22:17:59
This one fails too...
| |
| 78 })(); | |
| 79 | |
| 80 | |
| 81 (function TestExtendsFunctionDefaultConstructor() { | |
| 82 function Base() { | |
| 83 assertEquals(Derived, new.target); | |
| 84 } | |
| 85 | |
| 86 class Derived extends Base {} | |
| 87 | |
| 88 new Derived(); | |
| 89 })(); | |
| OLD | NEW |