mirror of https://github.com/tc39/test262.git
Import tests from Google V8 (Rest Parameters)
These tests are derived from the following files within the Google V8 project: test/mjsunit/harmony/rest-params.js
This commit is contained in:
parent
2b0339683d
commit
c8aabb3664
|
@ -0,0 +1,9 @@
|
|||
// 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;
|
|
@ -0,0 +1,16 @@
|
|||
// 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: >arrow functions
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
var fn = (a, b, ...c) => c;
|
||||
|
||||
assert(compareArray(fn(), []), "`compareArray(fn(), [])` returns `true`");
|
||||
assert(compareArray(fn(1, 2), []), "`compareArray(fn(1, 2), [])` returns `true`");
|
||||
assert(compareArray(fn(1, 2, 3), [3]),"`compareArray(fn(1, 2, 3), [3])` returns `true`");
|
||||
assert(compareArray(fn(1, 2, 3, 4), [3, 4]),"`compareArray(fn(1, 2, 3, 4), [3, 4])` returns `true`");
|
||||
assert(compareArray(fn(1, 2, 3, 4, 5), [3, 4, 5]),"`compareArray(fn(1, 2, 3, 4, 5), [3, 4, 5])` returns `true`");
|
||||
assert(compareArray(((...args) => args)(), []),"`compareArray(((...args) => args)(), [])` returns `true`");
|
||||
assert(compareArray(((...args) => args)(1,2,3), [1,2,3]),"`compareArray(((...args) => args)(1,2,3), [1,2,3])` returns `true`");
|
|
@ -0,0 +1,14 @@
|
|||
// 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.6
|
||||
description: >
|
||||
The ExpectedArgumentCount of a FormalParameterList is the number of
|
||||
FormalParameters to the left of either the rest parameter or the first
|
||||
FormalParameter with an Initializer.
|
||||
---*/
|
||||
function af(...a) {}
|
||||
function bf(a, ...b) {}
|
||||
|
||||
assert.sameValue(af.length, 0, "The value of `af.length` is `0`");
|
||||
assert.sameValue(bf.length, 1, "The value of `bf.length` is `1`");
|
|
@ -0,0 +1,15 @@
|
|||
// 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: >
|
||||
no alias arguments
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
function f(a, ...rest) {
|
||||
arguments[0] = 1;
|
||||
assert.sameValue(a, 3, "The value of `a` is `3`");
|
||||
arguments[1] = 2;
|
||||
assert(compareArray(rest, [4, 5]), "`compareArray(rest, [4, 5])` returns `true`");
|
||||
}
|
||||
f(3, 4, 5);
|
|
@ -0,0 +1,9 @@
|
|||
// 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: >
|
||||
Rest parameter cannot be followed by another named parameter
|
||||
negative: SyntaxError
|
||||
---*/
|
||||
function f(a, ...b, c) {}
|
|
@ -0,0 +1,37 @@
|
|||
// 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: >
|
||||
rest index
|
||||
---*/
|
||||
assert.sameValue(
|
||||
(function(...args) { return args.length; })(1,2,3,4,5),
|
||||
5,
|
||||
"`(function(...args) { return args.length; })(1,2,3,4,5)` returns `5`"
|
||||
);
|
||||
assert.sameValue(
|
||||
(function(a, ...args) { return args.length; })(1,2,3,4,5),
|
||||
4,
|
||||
"`(function(a, ...args) { return args.length; })(1,2,3,4,5)` returns `4`"
|
||||
);
|
||||
assert.sameValue(
|
||||
(function(a, b, ...args) { return args.length; })(1,2,3,4,5),
|
||||
3,
|
||||
"`(function(a, b, ...args) { return args.length; })(1,2,3,4,5)` returns `3`"
|
||||
);
|
||||
assert.sameValue(
|
||||
(function(a, b, c, ...args) { return args.length; })(1,2,3,4,5),
|
||||
2,
|
||||
"`(function(a, b, c, ...args) { return args.length; })(1,2,3,4,5)` returns `2`"
|
||||
);
|
||||
assert.sameValue(
|
||||
(function(a, b, c, d, ...args) { return args.length; })(1,2,3,4,5),
|
||||
1,
|
||||
"`(function(a, b, c, d, ...args) { return args.length; })(1,2,3,4,5)` returns `1`"
|
||||
);
|
||||
assert.sameValue(
|
||||
(function(a, b, c, d, e, ...args) { return args.length; })(1,2,3,4,5),
|
||||
0,
|
||||
"`(function(a, b, c, d, e, ...args) { return args.length; })(1,2,3,4,5)` returns `0`"
|
||||
);
|
|
@ -0,0 +1,15 @@
|
|||
// 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: >
|
||||
Rest parameter and Function.prototype.apply
|
||||
---*/
|
||||
function af(...a) {
|
||||
return a.length;
|
||||
}
|
||||
|
||||
assert.sameValue(af.apply(null, []), 0, "`af.apply(null, [])` returns `0`");
|
||||
assert.sameValue(af.apply(null, [1]), 1, "`af.apply(null, [1])` returns `1`");
|
||||
assert.sameValue(af.apply(null, [1, 2]), 2, "`af.apply(null, [1, 2])` returns `2`");
|
||||
assert.sameValue(af.apply(null, [1, ,2]), 3, "`af.apply(null, [1, ,2])` returns `3`");
|
|
@ -0,0 +1,14 @@
|
|||
// 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: >
|
||||
Rest parameter and Function.prototype.call
|
||||
---*/
|
||||
function af(...a) {
|
||||
return a.length;
|
||||
}
|
||||
|
||||
assert.sameValue(af.call(null), 0, "`af.call(null)` returns `0`");
|
||||
assert.sameValue(af.call(null, 1), 1, "`af.call(null, 1)` returns `1`");
|
||||
assert.sameValue(af.call(null, 1, 2), 2, "`af.call(null, 1, 2)` returns `2`");
|
|
@ -0,0 +1,12 @@
|
|||
// 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: >
|
||||
Rest parameter produces an instance of Array
|
||||
---*/
|
||||
function af(...a) {
|
||||
assert.sameValue(a.constructor, Array, "The value of `a.constructor` is `Array`");
|
||||
assert(Array.isArray(a), "`Array.isArray(a)` returns `true`");
|
||||
}
|
||||
af(1);
|
|
@ -0,0 +1,53 @@
|
|||
// 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: >
|
||||
with new target
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
class Base {
|
||||
constructor(...a) {
|
||||
assert.sameValue(
|
||||
arguments.length,
|
||||
a.length,
|
||||
"The value of `arguments.length` is `a.length`"
|
||||
);
|
||||
this.base = a;
|
||||
var args = [];
|
||||
for (var i = 0; i < arguments.length; ++i) {
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
assert(compareArray(args, a), "`compareArray(args, a)` returns `true`");
|
||||
}
|
||||
}
|
||||
class Child extends Base {
|
||||
constructor(...b) {
|
||||
super(1, 2, 3);
|
||||
assert.sameValue(
|
||||
arguments.length,
|
||||
b.length,
|
||||
"The value of `arguments.length` is `b.length`"
|
||||
);
|
||||
this.child = b;
|
||||
var args = [];
|
||||
for (var i = 0; i < arguments.length; ++i) {
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
assert(compareArray(args, b), "`compareArray(args, b)` returns `true`");
|
||||
}
|
||||
}
|
||||
|
||||
var c = new Child(1, 2, 3);
|
||||
|
||||
assert.sameValue(c.child.length, 3, "The value of `c.child.length` is `3`");
|
||||
assert.sameValue(c.base.length, 3, "The value of `c.base.length` is `3`");
|
||||
|
||||
assert(
|
||||
compareArray(c.child, [1, 2, 3]),
|
||||
"`compareArray(c.child, [1, 2, 3])` returns `true`"
|
||||
);
|
||||
assert(
|
||||
compareArray(c.base, [1, 2, 3]),
|
||||
"`compareArray(c.base, [1, 2, 3])` returns `true`"
|
||||
);
|
Loading…
Reference in New Issue