2016-04-18 20:33:21 +02:00
|
|
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
|
|
|
// This code is governed by the BSD license found in the LICENSE file.
|
|
|
|
/*---
|
2016-05-21 00:58:23 +02:00
|
|
|
desc: >
|
2016-04-18 20:33:21 +02:00
|
|
|
IteratorClose throws a TypeError when `return` returns a non-Object value
|
|
|
|
info: |
|
|
|
|
ArrayAssignmentPattern : [ AssignmentElementList ]
|
|
|
|
|
|
|
|
[...]
|
|
|
|
5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator,
|
|
|
|
result).
|
|
|
|
6. Return result.
|
|
|
|
|
|
|
|
7.4.6 IteratorClose( iterator, completion )
|
|
|
|
|
|
|
|
[...]
|
|
|
|
6. Let innerResult be Call(return, iterator, « »).
|
|
|
|
7. If completion.[[type]] is throw, return Completion(completion).
|
|
|
|
8. If innerResult.[[type]] is throw, return Completion(innerResult).
|
|
|
|
9. If Type(innerResult.[[value]]) is not Object, throw a TypeError
|
|
|
|
exception.
|
|
|
|
features: [Symbol.iterator, generators]
|
2016-05-21 00:58:23 +02:00
|
|
|
template: default
|
2016-04-18 20:33:21 +02:00
|
|
|
es6id: 12.14.5.2
|
|
|
|
esid: sec-runtime-semantics-destructuringassignmentevaluation
|
|
|
|
---*/
|
|
|
|
|
2016-05-21 00:58:23 +02:00
|
|
|
//- setup
|
2017-09-16 17:00:54 +02:00
|
|
|
var nextCount = 0;
|
|
|
|
var returnCount = 0;
|
|
|
|
var unreachable = 0;
|
2016-04-18 20:33:21 +02:00
|
|
|
var iterator = {
|
2017-09-16 17:00:54 +02:00
|
|
|
next: function() {
|
|
|
|
nextCount += 1;
|
|
|
|
return {done: false, value: undefined};
|
|
|
|
},
|
2016-04-18 20:33:21 +02:00
|
|
|
return: function() {
|
2017-09-16 17:00:54 +02:00
|
|
|
returnCount += 1;
|
2016-04-18 20:33:21 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
2017-09-16 17:00:54 +02:00
|
|
|
var iterable = {};
|
2016-04-18 20:33:21 +02:00
|
|
|
iterable[Symbol.iterator] = function() {
|
|
|
|
return iterator;
|
|
|
|
};
|
|
|
|
function* g() {
|
2016-05-21 00:58:23 +02:00
|
|
|
//- elems
|
2017-09-16 17:00:54 +02:00
|
|
|
[ {} = yield ]
|
2016-05-21 00:58:23 +02:00
|
|
|
//- vals
|
|
|
|
iterable
|
|
|
|
//- body
|
2016-04-18 20:33:21 +02:00
|
|
|
unreachable += 1;
|
2016-05-21 00:58:23 +02:00
|
|
|
//- teardown
|
2016-04-18 20:33:21 +02:00
|
|
|
}
|
|
|
|
|
2017-09-16 17:00:54 +02:00
|
|
|
var iter = g();
|
2016-04-18 20:33:21 +02:00
|
|
|
iter.next();
|
|
|
|
|
2017-09-16 17:00:54 +02:00
|
|
|
assert.sameValue(nextCount, 1);
|
|
|
|
assert.sameValue(returnCount, 0);
|
2016-04-18 20:33:21 +02:00
|
|
|
assert.throws(TypeError, function() {
|
|
|
|
iter.return();
|
|
|
|
});
|
2017-09-16 17:00:54 +02:00
|
|
|
assert.sameValue(nextCount, 1);
|
|
|
|
assert.sameValue(returnCount, 1);
|
|
|
|
assert.sameValue(unreachable, 0, 'Unreachable statement was not executed');
|