Merge pull request #228 from bocoup/arrow-functions

14.2 Arrow Function Definitions
This commit is contained in:
Brian Terlson 2015-04-21 09:48:07 -07:00
commit 8980d3f929
67 changed files with 1227 additions and 46 deletions

View File

@ -1,35 +0,0 @@
// Copyright (C) 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
Semantics associated with specific Arrow Function syntactic forms.
includes: [compareArray.js]
---*/
// Empty arrow function returns undefined
var empty = () => {};
assert.sameValue(empty(), undefined);
// Single parameter case needs no parentheses around parameter list
var identity = x => x;
assert.sameValue(identity(empty), empty);
// No need for parentheses even for lower-precedence expression body
var square = x => x * x;
assert.sameValue(square(3), 9);
// Parenthesize the body to return an object literal expression
var key_maker = val => ({key: val});
assert.sameValue(key_maker(empty).key, empty);
// Expression Body implicit return
var evens = [0, 2, 4, 6, 8];
assert(compareArray(evens.map(v => v + 1), [1, 3, 5, 7, 9]));
// Statement body needs braces, must use 'return' explicitly if not void
var fives = [];
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].forEach(v => {
if (v % 5 === 0) fives.push(v);
});
assert(compareArray(fives, [5, 10]));

View File

@ -0,0 +1,29 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowFunction `this` cannot be overridden by thisArg
9.2.4 FunctionInitialize (F, kind, ParameterList, Body, Scope)
...
9. If kind is Arrow, set the [[ThisMode]] internal slot of F to lexical.
...
9.2.1.2 OrdinaryCallBindThis ( F, calleeContext, thisArgument )
1. Let thisMode be the value of Fs [[ThisMode]] internal slot.
2. If thisMode is lexical, return NormalCompletion(undefined).
...
---*/
var calls = 0;
var usurper = {};
[1].forEach(value => {
calls++;
assert.notSameValue(this, usurper);
}, usurper);
assert.sameValue(calls, 1);

View File

@ -0,0 +1,10 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
Empty arrow function returns undefined
---*/
var empty = () => {};
assert.sameValue(empty(), undefined);

View File

@ -0,0 +1,9 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
Expression Body implicit return
---*/
var plusOne = v => v + 1;
assert.sameValue(plusOne(1), 2);

View File

@ -0,0 +1,29 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.16
description: >
Runtime Semantics: Evaluation
arguments
...
4. Let closure be FunctionCreate(Arrow, parameters, ConciseBody, scope, strict).
...
The non-normative note elaborates on the "scope" argument:
An ArrowFunction does not define local bindings for arguments, super, this, or new.target. Any reference to arguments, super, or this within an ArrowFunction must resolve to a binding in a lexically enclosing environment. Typically this will be the Function Environment of an immediately enclosing function. Even though an ArrowFunction may contain references to super, the function object created in step 4 is not made into a method by performing MakeMethod. An ArrowFunction that references super is always contained within a non-ArrowFunction and the necessary state to implement super is accessible via the scope that is captured by the function object of the ArrowFunction.
---*/
function f() {
var args = arguments;
var af = _ => {
return arguments;
};
return args === af();
}
assert(f());

View File

@ -0,0 +1,14 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.16
description: >
Runtime Semantics: Evaluation
flags: [noStrict]
---*/
function f() {
return (arguments) => arguments;
}
assert.sameValue(f(1)(2), 2);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.16
description: >
Runtime Semantics: Evaluation
new.target
...
4. Let closure be FunctionCreate(Arrow, parameters, ConciseBody, scope, strict).
...
The non-normative note elaborates on the "scope" argument:
An ArrowFunction does not define local bindings for arguments, super, this, or new.target. Any reference to arguments, super, or this within an ArrowFunction must resolve to a binding in a lexically enclosing environment. Typically this will be the Function Environment of an immediately enclosing function. Even though an ArrowFunction may contain references to super, the function object created in step 4 is not made into a method by performing MakeMethod. An ArrowFunction that references super is always contained within a non-ArrowFunction and the necessary state to implement super is accessible via the scope that is captured by the function object of the ArrowFunction.
---*/
function F() {
this.af = _ => {
if (new.target) {
return 1;
}
return 2;
};
}
var f = new F();
assert.sameValue(f.af(), 1);

View File

@ -0,0 +1,33 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.16
description: >
Runtime Semantics: Evaluation
new.target
...
4. Let closure be FunctionCreate(Arrow, parameters, ConciseBody, scope, strict).
...
The non-normative note elaborates on the "scope" argument:
An ArrowFunction does not define local bindings for arguments, super, this, or new.target. Any reference to arguments, super, or this within an ArrowFunction must resolve to a binding in a lexically enclosing environment. Typically this will be the Function Environment of an immediately enclosing function. Even though an ArrowFunction may contain references to super, the function object created in step 4 is not made into a method by performing MakeMethod. An ArrowFunction that references super is always contained within a non-ArrowFunction and the necessary state to implement super is accessible via the scope that is captured by the function object of the ArrowFunction.
---*/
var functionInvocationCount = 0;
var newInvocationCount = 0;
function F() {
if ((_ => new.target)() !== undefined) {
newInvocationCount++;
}
functionInvocationCount++;
}
F();
new F();
assert.sameValue(functionInvocationCount, 2);
assert.sameValue(newInvocationCount, 1);

View File

@ -0,0 +1,46 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.3.5.1
description: >
Runtime Semantics: Evaluation
SuperCall : super Arguments
...
7. Let result be Construct(func, argList, newTarget).
...
10. Return thisER.BindThisValue(result)
8.1.1.3.1 BindThisValue(V)
...
3. If envRec.[[thisBindingStatus]] is "initialized", throw a ReferenceError exception.
...
---*/
var count = 0;
class A {
constructor() {
count++;
}
}
class B extends A {
constructor() {
super();
// envRec.[[thisBindingStatus]] is "initialized"
this.af = _ => super();
}
}
var b = new B();
assert.throws(ReferenceError, function() {
b.af();
});
assert.sameValue(count, 2, "The value of `count` is `2`, because S7 of `SuperCall : super Arguments` will call the super constructor.");

View File

@ -0,0 +1,40 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.16
description: >
Runtime Semantics: Evaluation
super
...
4. Let closure be FunctionCreate(Arrow, parameters, ConciseBody, scope, strict).
...
The non-normative note elaborates on the "scope" argument:
An ArrowFunction does not define local bindings for arguments, super, this, or new.target. Any reference to arguments, super, or this within an ArrowFunction must resolve to a binding in a lexically enclosing environment. Typically this will be the Function Environment of an immediately enclosing function. Even though an ArrowFunction may contain references to super, the function object created in step 4 is not made into a method by performing MakeMethod. An ArrowFunction that references super is always contained within a non-ArrowFunction and the necessary state to implement super is accessible via the scope that is captured by the function object of the ArrowFunction.
---*/
var count = 0;
class A {
constructor() {
count++;
}
increment() {
count++;
}
}
class B extends A {
constructor() {
super();
(_ => super.increment())();
}
}
var bar = new B();
assert.sameValue(count, 2);

View File

@ -0,0 +1,38 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.16
description: >
Runtime Semantics: Evaluation
super
...
4. Let closure be FunctionCreate(Arrow, parameters, ConciseBody, scope, strict).
...
The non-normative note elaborates on the "scope" argument:
An ArrowFunction does not define local bindings for arguments, super, this, or new.target. Any reference to arguments, super, or this within an ArrowFunction must resolve to a binding in a lexically enclosing environment. Typically this will be the Function Environment of an immediately enclosing function. Even though an ArrowFunction may contain references to super, the function object created in step 4 is not made into a method by performing MakeMethod. An ArrowFunction that references super is always contained within a non-ArrowFunction and the necessary state to implement super is accessible via the scope that is captured by the function object of the ArrowFunction.
---*/
var count = 0;
class A {
increment() {
count++;
}
}
class B extends A {
incrementer() {
(_ => super.increment())();
}
}
var bar = new B();
bar.incrementer();
assert.sameValue(count, 1);

View File

@ -0,0 +1,35 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.16
description: >
Runtime Semantics: Evaluation
super
...
4. Let closure be FunctionCreate(Arrow, parameters, ConciseBody, scope, strict).
...
The non-normative note elaborates on the "scope" argument:
An ArrowFunction does not define local bindings for arguments, super, this, or new.target. Any reference to arguments, super, or this within an ArrowFunction must resolve to a binding in a lexically enclosing environment. Typically this will be the Function Environment of an immediately enclosing function. Even though an ArrowFunction may contain references to super, the function object created in step 4 is not made into a method by performing MakeMethod. An ArrowFunction that references super is always contained within a non-ArrowFunction and the necessary state to implement super is accessible via the scope that is captured by the function object of the ArrowFunction.
---*/
var count = 0;
class A {
constructor() {
count++;
}
}
class B extends A {
constructor() {
(_ => super())();
}
}
var bar = new B();
assert.sameValue(count, 1);

View File

@ -0,0 +1,31 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.16
description: >
Runtime Semantics: Evaluation
this
...
4. Let closure be FunctionCreate(Arrow, parameters, ConciseBody, scope, strict).
...
The non-normative note elaborates on the "scope" argument:
An ArrowFunction does not define local bindings for arguments, super, this, or new.target. Any reference to arguments, super, or this within an ArrowFunction must resolve to a binding in a lexically enclosing environment. Typically this will be the Function Environment of an immediately enclosing function. Even though an ArrowFunction may contain references to super, the function object created in step 4 is not made into a method by performing MakeMethod. An ArrowFunction that references super is always contained within a non-ArrowFunction and the necessary state to implement super is accessible via the scope that is captured by the function object of the ArrowFunction.
---*/
function F() {
this.af = _ => {
return this;
};
}
var usurper = {};
var f = new F();
assert.sameValue(f.af(), f);
assert.sameValue(f.af.apply(usurper), f);
assert.sameValue(f.af.call(usurper), f);
assert.sameValue(f.af.bind(usurper)(), f);

View File

@ -0,0 +1,10 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
No need for parentheses even for lower-precedence expression body
---*/
var square = x => x * x;
assert.sameValue(square(3), 9);

View File

@ -0,0 +1,20 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.16
description: >
Runtime Semantics: Evaluation
1. If the function code for this ArrowFunction is strict mode code (10.2.1),
let strict be true. Otherwise let strict be false.
...
flags: [noStrict]
---*/
var af = _ => {
foo = 1;
};
af();
assert.sameValue(foo, 1);

View File

@ -0,0 +1,10 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
Parenthesize the body to return an object literal expression
---*/
var keyMaker = val => ({ key: val });
assert.sameValue(keyMaker(1).key, 1);

View File

@ -1,4 +1,4 @@
// Copyright (C) 2014 the V8 project authors. All rights reserved.
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
@ -9,5 +9,4 @@ description: >
assert.sameValue(typeof (() => {}), "function");
assert.sameValue(Object.getPrototypeOf(() => {}), Function.prototype);
assert.throws(TypeError, function() { new (() => {}); });
assert.sameValue("prototype" in (() => {}), false);

View File

@ -0,0 +1,12 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
Statement body needs braces, must use 'return' explicitly if not void
---*/
var plusOne = v => {
v + 1;
};
assert.sameValue(plusOne(1), undefined);

View File

@ -0,0 +1,12 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
Statement body needs braces, must use 'return' explicitly if not void
---*/
var plusOne = v => {
return v + 1;
};
assert.sameValue(plusOne(1), 2);

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.16
description: >
Runtime Semantics: Evaluation
1. If the function code for this ArrowFunction is strict mode code (10.2.1),
let strict be true. Otherwise let strict be false.
...
flags: [onlyStrict]
---*/
assert.throws(ReferenceError, function() {
var af = _ => {
foo = 1;
};
af();
});
assert.sameValue(typeof foo, "undefined");

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
BindingIdentifier[?Yield]
...
Parameter named "arguments", non-strict
flags: [noStrict]
---*/
var af = arguments => arguments;
assert.sameValue(typeof af, "function");
assert.sameValue(af(1), 1);

View File

@ -0,0 +1,16 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowFunction[In, Yield] :
ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In]
LineTerminator not present
ArrowParameters[Yield] : BindingIdentifier
ConciseBody[In] : AssignmentExpression[?In]
---*/
var af = x => x;
assert.sameValue(typeof af, "function");
assert.sameValue(af(1), 1);

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowFunction[In, Yield] :
ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In]
ArrowParameters[Yield] :
BindingIdentifier[?Yield]
...
ConciseBody[In] :
...
{ FunctionBody }
---*/
var af = BindingIdentifier => {
return BindingIdentifier;
};
assert.sameValue(typeof af, "function");
assert.sameValue(af(1), 1);

View File

@ -0,0 +1,18 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
BindingIdentifier[?Yield]
...
Parameter named "eval", non-strict
flags: [noStrict]
---*/
var af = eval => eval;
assert.sameValue(typeof af, "function");
assert.sameValue(af(1), 1);

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowFunction[In, Yield] :
ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In]
LineTerminator between arrow and ConciseBody
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList[?Yield]
ConciseBody[In] : AssignmentExpression[?In]
---*/
var af = x =>
x;
assert.sameValue(typeof af, "function");
assert.sameValue(af(1), 1);

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowFunction[In, Yield] :
ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In]
LineTerminator between arrow and ConciseBody[?In]
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList[?Yield]
ConciseBody[In] : { FunctionBody }
---*/
var af = x =>
{ return x };
assert.sameValue(typeof af, "function");
assert.sameValue(af(1), 1);

View File

@ -0,0 +1,14 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
BindingIdentifier[?Yield]
...
Parameter named "yield", non-strict
flags: [noStrict]
---*/
var af = yield => 1;

View File

@ -0,0 +1,16 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowFunction[In, Yield] :
ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In]
LineTerminator not present
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList[?Yield]
ConciseBody[In] : [lookahead { ] AssignmentExpression[?In]
---*/
var af = (x) => x;
assert.sameValue(typeof af, "function");
assert.sameValue(af(1), 1);

View File

@ -0,0 +1,15 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowFunction[In, Yield] :
ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In]
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList[?Yield]
ConciseBody[In] : { FunctionBody }
---*/
var af = (x) => { return x };
assert.sameValue(typeof af, "function");
assert.sameValue(af(1), 1);

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
Parameter named "arguments", non-strict
flags: [noStrict]
---*/
var af = (arguments) => arguments;
assert.sameValue(typeof af, "function");
assert.sameValue(af(1), 1);

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
Parameter named "eval", non-strict
flags: [noStrict]
---*/
var af = (eval) => eval;
assert.sameValue(typeof af, "function");
assert.sameValue(af(1), 1);

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
Parameter named "yield", non-strict
flags: [noStrict]
---*/
var af = (yield) => 1;
assert.sameValue(typeof af, "function");
assert.sameValue(af(1), 1);

View File

@ -0,0 +1,19 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowFunction[In, Yield] :
ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In]
LineTerminator between arrow and ConciseBody[?In]
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList[?Yield]
ConciseBody[In] : { FunctionBody }
Includes ...rest
---*/
var af = (x, ...y) => { return [x, y.length]; };
assert.sameValue(typeof af, "function");
assert.sameValue(af(1, 1, 1)[0], 1);
assert.sameValue(af(1, 1, 1)[1], 2);

View File

@ -0,0 +1,16 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
---*/
var af = (x = 1) => x;
assert.sameValue(typeof af, "function");
assert.sameValue(af(), 1);
assert.sameValue(af(2), 2);

View File

@ -0,0 +1,16 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
12.14.5
---*/
var af = ({x = 1}) => x;
assert.sameValue(typeof af, "function");
assert.sameValue(af({}), 1);
assert.sameValue(af({x: 2}), 2);

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowFunction[In, Yield] :
ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In]
LineTerminator not present
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList[?Yield]
ConciseBody[In] : [lookahead { ] AssignmentExpression[?In]
---*/
var af = (x) =>
x;
assert.sameValue(typeof af, "function");
assert.sameValue(af(1), 1);

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowFunction[In, Yield] :
ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In]
LineTerminator between arrow and ConciseBody[?In]
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList[?Yield]
ConciseBody[In] : { FunctionBody }
---*/
var af = (x) =>
{ return x };
assert.sameValue(typeof af, "function");
assert.sameValue(af(1), 1);

View File

@ -0,0 +1,18 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowFunction[In, Yield] :
ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In]
LineTerminator between arrow and ConciseBody[?In]
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList[?Yield]
ConciseBody[In] : { FunctionBody }
Includes ...rest
---*/
var af = (...x) => { return x.length; };
assert.sameValue(typeof af, "function");
assert.sameValue(af(1, 1, 1), 3);

View File

@ -0,0 +1,19 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowFunction[In, Yield] :
ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In]
LineTerminator between arrow and ConciseBody[?In]
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList[?Yield]
ConciseBody[In] : { FunctionBody }
Includes ...rest
---*/
var af = (...x) =>
{ return x.length; };
assert.sameValue(typeof af, "function");
assert.sameValue(af(1, 1, 1), 3);

View File

@ -0,0 +1,20 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowParameters[Yield] :
BindingIdentifier[?Yield]
(12.1)
BindingIdentifier[Yield] :
Identifier[~Yield] yield
Identifier :
IdentifierName but not ReservedWord
ReservedWord : FutureReservedWord
negative: SyntaxError
---*/
var af = enum => 1;

View File

@ -0,0 +1,23 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowParameters[Yield] :
BindingIdentifier[?Yield]
(12.1)
BindingIdentifier[Yield] :
Identifier[~Yield] yield
Identifier :
IdentifierName but not ReservedWord
ReservedWord : FutureReservedWord
Strict Mode
negative: SyntaxError
flags: [onlyStrict]
---*/
var af = package => 1;

View File

@ -0,0 +1,20 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowParameters[Yield] :
BindingIdentifier[?Yield]
(12.1)
BindingIdentifier[Yield] :
Identifier[~Yield] yield
Identifier :
IdentifierName but not ReservedWord
ReservedWord : Keyword
negative: SyntaxError
---*/
var af = switch => 1;

View File

@ -0,0 +1,15 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
BindingIdentifier[?Yield]
...
No parameter named "arguments"
negative: SyntaxError
flags: [onlyStrict]
---*/
var af = arguments => 1;

View File

@ -0,0 +1,16 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
BindingIdentifier[?Yield]
...
No parameter named "eval"
negative: SyntaxError
flags: [onlyStrict]
---*/
var af = eval => 1;

View File

@ -0,0 +1,16 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
BindingIdentifier[?Yield]
...
No parameter named "yield"
negative: SyntaxError
flags: [onlyStrict]
---*/
var af = yield => 1;

View File

@ -0,0 +1,12 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowParameters : BindingIdentifier[?Yield]
Includes ...rest
negative: SyntaxError
---*/
var af = ...x => x;

View File

@ -0,0 +1,20 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
CoverParenthesizedExpressionAndArrowParameterList, refined by:
ArrowFormalParameters[Yield, GeneratorParameter] :
( StrictFormalParameters[?Yield, ?GeneratorParameter] )
No parameters named "arguments"
negative: SyntaxError
flags: [onlyStrict]
---*/
var af = (arguments) => 1;

View File

@ -0,0 +1,21 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
CoverParenthesizedExpressionAndArrowParameterList, refined by:
ArrowFormalParameters[Yield, GeneratorParameter] :
( StrictFormalParameters[?Yield, ?GeneratorParameter] )
ArrayBindingPattern
No duplicates
negative: SyntaxError
---*/
var af = (x, [x]) => 1;

View File

@ -0,0 +1,21 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
CoverParenthesizedExpressionAndArrowParameterList, refined by:
ArrowFormalParameters[Yield, GeneratorParameter] :
( StrictFormalParameters[?Yield, ?GeneratorParameter] )
ArrayBindingPattern
No duplicates
negative: SyntaxError
---*/
var af = ([x, x]) => 1;

View File

@ -0,0 +1,23 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
CoverParenthesizedExpressionAndArrowParameterList, refined by:
ArrowFormalParameters[Yield, GeneratorParameter] :
( StrictFormalParameters[?Yield, ?GeneratorParameter] )
ArrayBindingPattern
BindingRestElement
No duplicates
negative: SyntaxError
---*/
var af = ([x], ...x) => 1;

View File

@ -0,0 +1,21 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
CoverParenthesizedExpressionAndArrowParameterList, refined by:
ArrowFormalParameters[Yield, GeneratorParameter] :
( StrictFormalParameters[?Yield, ?GeneratorParameter] )
ObjectBindingPattern
No duplicates
negative: SyntaxError
---*/
var af = (x, {x}) => 1;

View File

@ -0,0 +1,23 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
CoverParenthesizedExpressionAndArrowParameterList, refined by:
ArrowFormalParameters[Yield, GeneratorParameter] :
( StrictFormalParameters[?Yield, ?GeneratorParameter] )
ObjectBindingPattern
BindingPropertyList
No duplicates
negative: SyntaxError
---*/
var af = (x, {y: x}) => 1;

View File

@ -0,0 +1,23 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
CoverParenthesizedExpressionAndArrowParameterList, refined by:
ArrowFormalParameters[Yield, GeneratorParameter] :
( StrictFormalParameters[?Yield, ?GeneratorParameter] )
ObjectBindingPattern
BindingPropertyList
No duplicates
negative: SyntaxError
---*/
var af = ({x}, {y: x}) => 1;

View File

@ -0,0 +1,25 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
CoverParenthesizedExpressionAndArrowParameterList, refined by:
ArrowFormalParameters[Yield, GeneratorParameter] :
( StrictFormalParameters[?Yield, ?GeneratorParameter] )
ObjectBindingPattern
BindingPropertyList
BindingRestElement
No duplicates
negative: SyntaxError
---*/
var af = ({x}, ...x) => 1;

View File

@ -0,0 +1,25 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
CoverParenthesizedExpressionAndArrowParameterList, refined by:
ArrowFormalParameters[Yield, GeneratorParameter] :
( StrictFormalParameters[?Yield, ?GeneratorParameter] )
ObjectBindingPattern
BindingPropertyList
BindingRestElement
No duplicates
negative: SyntaxError
---*/
var af = ({y: x}, ...x) => 1;

View File

@ -0,0 +1,23 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
CoverParenthesizedExpressionAndArrowParameterList, refined by:
ArrowFormalParameters[Yield, GeneratorParameter] :
( StrictFormalParameters[?Yield, ?GeneratorParameter] )
ObjectBindingPattern
BindingPropertyList
No duplicates
negative: SyntaxError
---*/
var af = ({y: x, x}) => 1;

View File

@ -0,0 +1,19 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
CoverParenthesizedExpressionAndArrowParameterList, refined by:
ArrowFormalParameters[Yield, GeneratorParameter] :
( StrictFormalParameters[?Yield, ?GeneratorParameter] )
No duplicates, rest
negative: SyntaxError
---*/
var af = (x, ...x) => 1;

View File

@ -0,0 +1,19 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
CoverParenthesizedExpressionAndArrowParameterList, refined by:
ArrowFormalParameters[Yield, GeneratorParameter] :
( StrictFormalParameters[?Yield, ?GeneratorParameter] )
No duplicates
negative: SyntaxError
---*/
var af = (x, x) => 1;

View File

@ -0,0 +1,20 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
CoverParenthesizedExpressionAndArrowParameterList, refined by:
ArrowFormalParameters[Yield, GeneratorParameter] :
( StrictFormalParameters[?Yield, ?GeneratorParameter] )
No parameters named "eval"
negative: SyntaxError
flags: [onlyStrict]
---*/
var af = (eval) => 1;

View File

@ -0,0 +1,15 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
ArrowParameters[Yield] :
...
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
No parameter named "yield"
negative: SyntaxError
flags: [onlyStrict]
---*/
var af = (yield) => 1;

View File

@ -0,0 +1,12 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowFunction[In, Yield] :
ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In]
negative: SyntaxError
---*/
var af = x
=> x;

View File

@ -0,0 +1,14 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowFunction[In, Yield] :
ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In]
No parens around ArrowParameters
negative: SyntaxError
---*/
var af = x
=> {};

View File

@ -0,0 +1,11 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2
description: >
ArrowFunction[In, Yield] :
ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In]
negative: SyntaxError
---*/
var af = ()
=> {};

View File

@ -0,0 +1,14 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.3.3.1.1
description: >
Runtime Semantics: EvaluateNew(constructProduction, arguments)
...
8. If IsConstructor (constructor) is false, throw a TypeError exception.
...
---*/
assert.throws(TypeError, function() { new (() => {}); });

View File

@ -1,9 +0,0 @@
// Copyright (C) 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.1
description: >
Invalid rest parameter in arrow function parameters
negative: SyntaxError
---*/
var x = ...y => y;