Chromium Code Reviews| Index: test/mjsunit/harmony/new-target.js |
| diff --git a/test/mjsunit/harmony/new-target.js b/test/mjsunit/harmony/new-target.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..99c2de0fccf0395c319e08d91d3d60bc589a02dc |
| --- /dev/null |
| +++ b/test/mjsunit/harmony/new-target.js |
| @@ -0,0 +1,89 @@ |
| +// Copyright 2015 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Flags: --harmony-classes --harmony-new-target --harmony-reflect |
| +// Flags: --harmony-rest-parameters |
| + |
| +'use strict'; |
| + |
| + |
| +(function TestBasics() { |
| + class Base {} |
| + class Derived extends Base { |
| + constructor(expected) { |
| + super(); |
| + assertEquals(expected, new.target); |
| + } |
| + } |
| + new Derived(Derived); |
| + |
| + class Derived2 extends Derived {} |
| + new Derived2(Derived2); |
| +})(); |
| + |
| + |
| +(function TestFunctionCall() { |
| + function f(expected) { |
| + assertEquals(expected, new.target); |
| + } |
| + |
| + f(undefined); |
| + f(); |
| + |
| + f(undefined, 'extra'); |
|
arv (Not doing code reviews)
2015/06/18 22:17:59
This one fails. `expected` ends up as the 'extra'.
|
| + |
| + f.call({}, undefined); |
| + f.apply({}, [undefined]); |
| +})(); |
| + |
| + |
| +(function TestFunctionRest() { |
| + function f(...rest) { |
| + assertEquals(rest[0], new.target); |
| + } |
| + |
| + new f(f); |
|
arv (Not doing code reviews)
2015/06/18 22:17:59
This one fails.
|
| + new f(f, 'extra'); |
| + |
| + f(undefined); |
| + f(undefined, 'extra'); |
| +})(); |
| + |
| + |
| +(function TestReflectConstruct() { |
| + function f(expected) { |
| + assertEquals(expected, new.target); |
| + } |
| + |
| + Reflect.construct(f, [f]); |
| + Reflect.construct(f, [f], f); |
| + Reflect.construct(f, [f, 'extra']); |
| + Reflect.construct(f, [f, 'extra'], f); |
| +})(); |
| + |
| + |
| +(function TestExtendsFunction() { |
| + function Base() { |
| + assertEquals(Derived, new.target); |
| + } |
| + |
| + class Derived extends Base { |
| + constructor() { |
| + super(); |
| + } |
| + } |
| + |
| + new Derived(); |
|
arv (Not doing code reviews)
2015/06/18 22:17:59
This one fails too...
|
| +})(); |
| + |
| + |
| +(function TestExtendsFunctionDefaultConstructor() { |
| + function Base() { |
| + assertEquals(Derived, new.target); |
| + } |
| + |
| + class Derived extends Base {} |
| + |
| + new Derived(); |
| +})(); |