mirror of https://github.com/tc39/test262.git
Import tests from Google V8 (Arrow Functions)
These tests are derived from the following files within the Google V8 project: test/mjsunit/harmony/arrow-functions.js
This commit is contained in:
parent
8eb0bd1279
commit
341e31f7d3
|
@ -0,0 +1,13 @@
|
|||
// Copyright (C) Copyright 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: >
|
||||
Arrow functions are like functions, except they throw when using the
|
||||
"new" operator on them.
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof (() => {}), "function");
|
||||
assert.sameValue(Object.getPrototypeOf(() => {}), Function.prototype);
|
||||
assert.throws(TypeError, function() { new (() => {}); });
|
||||
assert.sameValue("prototype" in (() => {}), false);
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) Copyright 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]));
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (C) Copyright 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: >
|
||||
Syntax variations of valid Arrow Functions
|
||||
---*/
|
||||
|
||||
assert.sameValue((() => 1)(), 1);
|
||||
assert.sameValue((a => a + 1)(1), 2);
|
||||
assert.sameValue((() => { return 3; })(), 3);
|
||||
assert.sameValue((a => { return a + 3; })(1), 4);
|
||||
assert.sameValue(((a, b) => a + b)(1, 4), 5);
|
||||
assert.sameValue(((a, b) => { return a + b; })(1, 5), 6);
|
Loading…
Reference in New Issue