mirror of https://github.com/tc39/test262.git
Add test cases for the spread operator
This commit is contained in:
parent
c98b6ed4e6
commit
95b5b13c16
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Spread operator following other arguments when no iteration occurs
|
||||
template: default
|
||||
info: |
|
||||
12.3.6.1 Runtime Semantics: ArgumentListEvaluation
|
||||
|
||||
ArgumentList : ArgumentList , ... AssignmentExpression
|
||||
|
||||
1. Let precedingArgs be the result of evaluating ArgumentList.
|
||||
2. Let spreadRef be the result of evaluating AssignmentExpression.
|
||||
3. Let iterator be GetIterator(GetValue(spreadRef) ).
|
||||
4. ReturnIfAbrupt(iterator).
|
||||
5. Repeat
|
||||
a. Let next be IteratorStep(iterator).
|
||||
b. ReturnIfAbrupt(next).
|
||||
c. If next is false, return precedingArgs.
|
||||
---*/
|
||||
|
||||
//- args
|
||||
1, 2, 3, ...[]
|
||||
//- body
|
||||
assert.sameValue(arguments.length, 3);
|
||||
assert.sameValue(arguments[0], 1);
|
||||
assert.sameValue(arguments[1], 2);
|
||||
assert.sameValue(arguments[2], 3);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Spread operator following other arguments when evaluation throws
|
||||
template: error
|
||||
info: |
|
||||
12.3.6.1 Runtime Semantics: ArgumentListEvaluation
|
||||
|
||||
ArgumentList : ArgumentList , ... AssignmentExpression
|
||||
|
||||
1. Let precedingArgs be the result of evaluating ArgumentList.
|
||||
2. Let spreadRef be the result of evaluating AssignmentExpression.
|
||||
3. Let iterator be GetIterator(GetValue(spreadRef) ).
|
||||
4. ReturnIfAbrupt(iterator).
|
||||
---*/
|
||||
|
||||
//- error
|
||||
Test262Error
|
||||
//- args
|
||||
0, ...function*() { throw new Test262Error(); }()
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: >
|
||||
Spread operator following other arguments when GetIterator fails
|
||||
(@@iterator function return value)
|
||||
template: error
|
||||
features: [Symbol.iterator]
|
||||
info: |
|
||||
12.3.6.1 Runtime Semantics: ArgumentListEvaluation
|
||||
|
||||
ArgumentList : ArgumentList , ... AssignmentExpression
|
||||
|
||||
1. Let precedingArgs be the result of evaluating ArgumentList.
|
||||
2. Let spreadRef be the result of evaluating AssignmentExpression.
|
||||
3. Let iterator be GetIterator(GetValue(spreadRef) ).
|
||||
4. ReturnIfAbrupt(iterator).
|
||||
|
||||
7.4.1 GetIterator ( obj, method )
|
||||
|
||||
[...]
|
||||
2. Let iterator be ? Call(method, obj).
|
||||
3. If Type(iterator) is not Object, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var iter = {};
|
||||
Object.defineProperty(iter, Symbol.iterator, {
|
||||
get: function() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
//- error
|
||||
TypeError
|
||||
//- args
|
||||
0, ...iter
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: >
|
||||
Spread operator following other arguments when GetIterator fails
|
||||
(@@iterator function invocation)
|
||||
template: error
|
||||
features: [Symbol.iterator]
|
||||
info: |
|
||||
12.3.6.1 Runtime Semantics: ArgumentListEvaluation
|
||||
|
||||
ArgumentList : ArgumentList , ... AssignmentExpression
|
||||
|
||||
1. Let precedingArgs be the result of evaluating ArgumentList.
|
||||
2. Let spreadRef be the result of evaluating AssignmentExpression.
|
||||
3. Let iterator be GetIterator(GetValue(spreadRef) ).
|
||||
4. ReturnIfAbrupt(iterator).
|
||||
|
||||
7.4.1 GetIterator ( obj, method )
|
||||
|
||||
[...]
|
||||
3. Let iterator be Call(method,obj).
|
||||
4. ReturnIfAbrupt(iterator).
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var iter = {};
|
||||
iter[Symbol.iterator] = function() {
|
||||
throw new Test262Error();
|
||||
};
|
||||
//- error
|
||||
Test262Error
|
||||
//- args
|
||||
0, ...iter
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: >
|
||||
Spread operator following other arguments when GetIterator fails
|
||||
(@@iterator property access)
|
||||
template: error
|
||||
features: [Symbol.iterator]
|
||||
info: |
|
||||
12.3.6.1 Runtime Semantics: ArgumentListEvaluation
|
||||
|
||||
ArgumentList : ArgumentList , ... AssignmentExpression
|
||||
|
||||
1. Let precedingArgs be the result of evaluating ArgumentList.
|
||||
2. Let spreadRef be the result of evaluating AssignmentExpression.
|
||||
3. Let iterator be GetIterator(GetValue(spreadRef) ).
|
||||
4. ReturnIfAbrupt(iterator).
|
||||
|
||||
7.4.1 GetIterator ( obj, method )
|
||||
|
||||
1. If method was not passed, then
|
||||
a. Let method be ? GetMethod(obj, @@iterator).
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var iter = {};
|
||||
Object.defineProperty(iter, Symbol.iterator, {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
//- error
|
||||
Test262Error
|
||||
//- args
|
||||
0, ...iter
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Spread operator following other arguments when IteratorStep fails
|
||||
template: error
|
||||
features: [Symbol.iterator]
|
||||
info: |
|
||||
12.3.6.1 Runtime Semantics: ArgumentListEvaluation
|
||||
|
||||
ArgumentList : ArgumentList , ... AssignmentExpression
|
||||
|
||||
1. Let precedingArgs be the result of evaluating ArgumentList.
|
||||
2. Let spreadRef be the result of evaluating AssignmentExpression.
|
||||
3. Let iterator be GetIterator(GetValue(spreadRef) ).
|
||||
4. ReturnIfAbrupt(iterator).
|
||||
|
||||
7.4.5 IteratorStep ( iterator )
|
||||
|
||||
1. Let result be IteratorNext(iterator).
|
||||
2. ReturnIfAbrupt(result).
|
||||
|
||||
7.4.2 IteratorNext ( iterator, value )
|
||||
|
||||
1. If value was not passed, then
|
||||
a. Let result be Invoke(iterator, "next", « »).
|
||||
[...]
|
||||
3. ReturnIfAbrupt(result).
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var iter = {};
|
||||
iter[Symbol.iterator] = function() {
|
||||
return {
|
||||
next: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
};
|
||||
//- error
|
||||
Test262Error
|
||||
//- args
|
||||
0, ...iter
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Spread operator following other arguments when IteratorValue fails
|
||||
template: error
|
||||
features: [Symbol.iterator]
|
||||
info: |
|
||||
12.3.6.1 Runtime Semantics: ArgumentListEvaluation
|
||||
|
||||
ArgumentList : ArgumentList , ... AssignmentExpression
|
||||
|
||||
1. Let precedingArgs be the result of evaluating ArgumentList.
|
||||
2. Let spreadRef be the result of evaluating AssignmentExpression.
|
||||
3. Let iterator be GetIterator(GetValue(spreadRef) ).
|
||||
4. ReturnIfAbrupt(iterator).
|
||||
|
||||
7.4.4 IteratorValue ( iterResult )
|
||||
|
||||
1. Assert: Type(iterResult) is Object.
|
||||
2. Return Get(iterResult, "value").
|
||||
|
||||
7.3.1 Get (O, P)
|
||||
|
||||
[...]
|
||||
3. Return O.[[Get]](P, O).
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var iter = {};
|
||||
var poisonedValue = Object.defineProperty({}, 'value', {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
iter[Symbol.iterator] = function() {
|
||||
return {
|
||||
next: function() {
|
||||
return poisonedValue;
|
||||
}
|
||||
};
|
||||
};
|
||||
//- error
|
||||
Test262Error
|
||||
//- args
|
||||
0, ...iter
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Spread operator following other arguments when reference is unresolvable
|
||||
template: error
|
||||
info: |
|
||||
12.3.6.1 Runtime Semantics: ArgumentListEvaluation
|
||||
|
||||
ArgumentList : ArgumentList , ... AssignmentExpression
|
||||
|
||||
1. Let precedingArgs be the result of evaluating ArgumentList.
|
||||
2. Let spreadRef be the result of evaluating AssignmentExpression.
|
||||
3. Let iterator be GetIterator(GetValue(spreadRef) ).
|
||||
4. ReturnIfAbrupt(iterator).
|
||||
|
||||
6.2.3.1 GetValue (V)
|
||||
|
||||
1. ReturnIfAbrupt(V).
|
||||
2. If Type(V) is not Reference, return V.
|
||||
3. Let base be GetBase(V).
|
||||
4. If IsUnresolvableReference(V), throw a ReferenceError exception.
|
||||
---*/
|
||||
|
||||
//- error
|
||||
ReferenceError
|
||||
//- args
|
||||
0, ...unresolvableReference
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Spread operator following other arguments with a valid iterator
|
||||
template: default
|
||||
features: [Symbol.iterator]
|
||||
info: |
|
||||
12.3.6.1 Runtime Semantics: ArgumentListEvaluation
|
||||
|
||||
ArgumentList : ... AssignmentExpression
|
||||
|
||||
1. Let list be an empty List.
|
||||
2. Let spreadRef be the result of evaluating AssignmentExpression.
|
||||
3. Let spreadObj be GetValue(spreadRef).
|
||||
4. Let iterator be GetIterator(spreadObj).
|
||||
5. ReturnIfAbrupt(iterator).
|
||||
6. Repeat
|
||||
a. Let next be IteratorStep(iterator).
|
||||
b. ReturnIfAbrupt(next).
|
||||
c. If next is false, return list.
|
||||
d. Let nextArg be IteratorValue(next).
|
||||
e. ReturnIfAbrupt(nextArg).
|
||||
f. Append nextArg as the last element of list.
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var iter = {};
|
||||
iter[Symbol.iterator] = function() {
|
||||
var nextCount = 3;
|
||||
return {
|
||||
next: function() {
|
||||
nextCount += 1;
|
||||
return { done: nextCount === 6, value: nextCount };
|
||||
}
|
||||
};
|
||||
};
|
||||
//- args
|
||||
1, 2, 3, ...iter
|
||||
//- body
|
||||
assert.sameValue(arguments.length, 5);
|
||||
assert.sameValue(arguments[0], 1);
|
||||
assert.sameValue(arguments[1], 2);
|
||||
assert.sameValue(arguments[2], 3);
|
||||
assert.sameValue(arguments[3], 4);
|
||||
assert.sameValue(arguments[4], 5);
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Spread operator applied to the only argument when no iteration occurs
|
||||
template: default
|
||||
info: |
|
||||
12.3.6.1 Runtime Semantics: ArgumentListEvaluation
|
||||
|
||||
ArgumentList : ... AssignmentExpression
|
||||
|
||||
1. Let list be an empty List.
|
||||
2. Let spreadRef be the result of evaluating AssignmentExpression.
|
||||
3. Let spreadObj be GetValue(spreadRef).
|
||||
4. Let iterator be GetIterator(spreadObj).
|
||||
5. ReturnIfAbrupt(iterator).
|
||||
6. Repeat
|
||||
a. Let next be IteratorStep(iterator).
|
||||
b. ReturnIfAbrupt(next).
|
||||
c. If next is false, return list.
|
||||
[...]
|
||||
---*/
|
||||
|
||||
//- params
|
||||
//- args
|
||||
...[]
|
||||
//- body
|
||||
assert.sameValue(arguments.length, 0);
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: >
|
||||
Spread operator applied to the only argument when GetIterator fails
|
||||
(@@iterator function invocation)
|
||||
template: error
|
||||
features: [Symbol.iterator]
|
||||
info: |
|
||||
12.3.6.1 Runtime Semantics: ArgumentListEvaluation
|
||||
|
||||
ArgumentList : ... AssignmentExpression
|
||||
|
||||
1. Let list be an empty List.
|
||||
2. Let spreadRef be the result of evaluating AssignmentExpression.
|
||||
3. Let spreadObj be GetValue(spreadRef).
|
||||
4. Let iterator be GetIterator(spreadObj).
|
||||
5. ReturnIfAbrupt(iterator).
|
||||
|
||||
7.4.1 GetIterator ( obj, method )
|
||||
|
||||
[...]
|
||||
3. Let iterator be Call(method,obj).
|
||||
4. ReturnIfAbrupt(iterator).
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var iter = {};
|
||||
iter[Symbol.iterator] = function() {
|
||||
throw new Test262Error();
|
||||
};
|
||||
//- error
|
||||
Test262Error
|
||||
//- args
|
||||
...iter
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: >
|
||||
Spread operator applied to the only argument when GetIterator fails
|
||||
(@@iterator property access)
|
||||
template: error
|
||||
features: [Symbol.iterator]
|
||||
info: |
|
||||
12.3.6.1 Runtime Semantics: ArgumentListEvaluation
|
||||
|
||||
ArgumentList : ... AssignmentExpression
|
||||
|
||||
1. Let list be an empty List.
|
||||
2. Let spreadRef be the result of evaluating AssignmentExpression.
|
||||
3. Let spreadObj be GetValue(spreadRef).
|
||||
4. Let iterator be GetIterator(spreadObj).
|
||||
5. ReturnIfAbrupt(iterator).
|
||||
|
||||
7.4.1 GetIterator ( obj, method )
|
||||
|
||||
1. If method was not passed, then
|
||||
a. Let method be ? GetMethod(obj, @@iterator).
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var iter = {};
|
||||
Object.defineProperty(iter, Symbol.iterator, {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
//- error
|
||||
Test262Error
|
||||
//- args
|
||||
...iter
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: >
|
||||
Spread operator applied to the only argument when GetIterator fails
|
||||
(@@iterator function return value)
|
||||
template: error
|
||||
features: [Symbol.iterator]
|
||||
info: |
|
||||
12.3.6.1 Runtime Semantics: ArgumentListEvaluation
|
||||
|
||||
ArgumentList : ... AssignmentExpression
|
||||
|
||||
1. Let list be an empty List.
|
||||
2. Let spreadRef be the result of evaluating AssignmentExpression.
|
||||
3. Let spreadObj be GetValue(spreadRef).
|
||||
4. Let iterator be GetIterator(spreadObj).
|
||||
5. ReturnIfAbrupt(iterator).
|
||||
|
||||
7.4.1 GetIterator ( obj, method )
|
||||
|
||||
[...]
|
||||
2. Let iterator be ? Call(method, obj).
|
||||
3. If Type(iterator) is not Object, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var iter = {};
|
||||
iter[Symbol.iterator] = function() {
|
||||
return null;
|
||||
};
|
||||
//- error
|
||||
TypeError
|
||||
//- args
|
||||
...iter
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Spread operator applied to the only argument when IteratorStep fails
|
||||
template: error
|
||||
features: [Symbol.iterator]
|
||||
info: |
|
||||
12.3.6.1 Runtime Semantics: ArgumentListEvaluation
|
||||
|
||||
ArgumentList : ... AssignmentExpression
|
||||
|
||||
1. Let list be an empty List.
|
||||
2. Let spreadRef be the result of evaluating AssignmentExpression.
|
||||
3. Let spreadObj be GetValue(spreadRef).
|
||||
4. Let iterator be GetIterator(spreadObj).
|
||||
5. ReturnIfAbrupt(iterator).
|
||||
6. Repeat
|
||||
a. Let next be IteratorStep(iterator).
|
||||
b. ReturnIfAbrupt(next).
|
||||
|
||||
7.4.5 IteratorStep ( iterator )
|
||||
|
||||
1. Let result be IteratorNext(iterator).
|
||||
2. ReturnIfAbrupt(result).
|
||||
|
||||
7.4.2 IteratorNext ( iterator, value )
|
||||
|
||||
1. If value was not passed, then
|
||||
a. Let result be Invoke(iterator, "next", « »).
|
||||
[...]
|
||||
3. ReturnIfAbrupt(result).
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var iter = {};
|
||||
iter[Symbol.iterator] = function() {
|
||||
return {
|
||||
next: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
};
|
||||
//- error
|
||||
Test262Error
|
||||
//- args
|
||||
...iter
|
|
@ -0,0 +1,52 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Spread operator applied to the only argument when IteratorValue fails
|
||||
template: error
|
||||
features: [Symbol.iterator]
|
||||
info: |
|
||||
12.3.6.1 Runtime Semantics: ArgumentListEvaluation
|
||||
|
||||
ArgumentList : ... AssignmentExpression
|
||||
|
||||
1. Let list be an empty List.
|
||||
2. Let spreadRef be the result of evaluating AssignmentExpression.
|
||||
3. Let spreadObj be GetValue(spreadRef).
|
||||
4. Let iterator be GetIterator(spreadObj).
|
||||
5. ReturnIfAbrupt(iterator).
|
||||
6. Repeat
|
||||
a. Let next be IteratorStep(iterator).
|
||||
b. ReturnIfAbrupt(next).
|
||||
c. If next is false, return list.
|
||||
d. Let nextArg be IteratorValue(next).
|
||||
e. ReturnIfAbrupt(nextArg).
|
||||
|
||||
7.4.4 IteratorValue ( iterResult )
|
||||
|
||||
1. Assert: Type(iterResult) is Object.
|
||||
2. Return Get(iterResult, "value").
|
||||
|
||||
7.3.1 Get (O, P)
|
||||
|
||||
[...]
|
||||
3. Return O.[[Get]](P, O).
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var iter = {};
|
||||
var poisonedValue = Object.defineProperty({}, 'value', {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
iter[Symbol.iterator] = function() {
|
||||
return {
|
||||
next: function() {
|
||||
return poisonedValue;
|
||||
}
|
||||
};
|
||||
};
|
||||
//- error
|
||||
Test262Error
|
||||
//- args
|
||||
...iter
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Spread operator applied to the only argument when reference is unresolvable
|
||||
template: error
|
||||
info: |
|
||||
12.3.6.1 Runtime Semantics: ArgumentListEvaluation
|
||||
|
||||
ArgumentList : ... AssignmentExpression
|
||||
|
||||
1. Let list be an empty List.
|
||||
2. Let spreadRef be the result of evaluating AssignmentExpression.
|
||||
3. Let spreadObj be GetValue(spreadRef).
|
||||
4. Let iterator be GetIterator(spreadObj).
|
||||
5. ReturnIfAbrupt(iterator).
|
||||
|
||||
6.2.3.1 GetValue (V)
|
||||
|
||||
1. ReturnIfAbrupt(V).
|
||||
2. If Type(V) is not Reference, return V.
|
||||
3. Let base be GetBase(V).
|
||||
4. If IsUnresolvableReference(V), throw a ReferenceError exception.
|
||||
---*/
|
||||
|
||||
//- error
|
||||
ReferenceError
|
||||
//- args
|
||||
...unresolvableReference
|
Loading…
Reference in New Issue