mirror of
https://github.com/tc39/test262.git
synced 2025-07-31 01:44:54 +02:00
A subtle aspect of the for-of iteration protocol concerns abrupt completions that do *not* trigger iterator closing. Although this detail is implicit in the current structure of the specification text, some hosts may violate the protocol by closing the iterator because later steps *do* specify that behavior. The V8 engine is one such host--as of this writing, it incorrectly closes the iterator when accessing the `value` property of the iterator result produces an abrupt completion. Add tests verifying that the iterator protocol is not violated in this way for abrupt completions during the semantics of for-of evaluation.
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
|
// This code is governed by the BSD license found in the LICENSE file.
|
|
/*---
|
|
es6id: 13.6.4.13 S5.g
|
|
description: >
|
|
If `nextValue` is an abrupt completion as per IteratorValue (ES6 7.4.4),
|
|
return the completion.
|
|
info: |
|
|
[...]
|
|
5. Repeat
|
|
a. Let nextResult be ? IteratorStep(iterator).
|
|
b. If nextResult is false, return NormalCompletion(V).
|
|
c. Let nextValue be ? IteratorValue(nextResult).
|
|
features: [Symbol.iterator]
|
|
---*/
|
|
|
|
var iterable = {};
|
|
var iterationCount = 0;
|
|
var returnCount = 0;
|
|
|
|
iterable[Symbol.iterator] = function() {
|
|
return {
|
|
next: function() {
|
|
return {
|
|
done: false,
|
|
get value() {
|
|
throw new Test262Error();
|
|
}
|
|
};
|
|
},
|
|
return: function() {
|
|
returnCount += 1;
|
|
return {};
|
|
}
|
|
};
|
|
};
|
|
|
|
assert.throws(Test262Error, function() {
|
|
for (var x of iterable) {
|
|
iterationCount += 1;
|
|
}
|
|
});
|
|
|
|
assert.sameValue(iterationCount, 0, 'The loop body is not evaluated');
|
|
assert.sameValue(returnCount, 0, 'Iterator is not closed.');
|