chore: added a few more examples based on code review

This commit is contained in:
bcoe 2019-11-18 20:44:34 -08:00
parent 3d0c2037c3
commit 5babea2780
No known key found for this signature in database
GPG Key ID: 84D97FAF3C07DF69
3 changed files with 35 additions and 8 deletions

View File

@ -8,6 +8,7 @@ info: |
IterationStatement
for await (LeftHandSideExpression of AssignmentExpression) Statement
features: [optional-chaining]
flags: [async]
---*/
const obj = {
iterable: {

View File

@ -11,8 +11,18 @@ features: [optional-chaining]
---*/
assert.throws(TypeError, function() {
const obj = undefined;
for (const key of obj?.a) {
str += key;
}
for (const key of {}?.a) ;
});
assert.throws(TypeError, function() {
for (const key of {}?.a) {}
});
const obj = undefined;
assert.throws(TypeError, function() {
for (const key of obj?.a) {}
});
assert.throws(TypeError, function() {
for (const key of obj?.a);
});

View File

@ -16,12 +16,28 @@ const obj = {a: true};
for (count = 0; obj?.a; count++) {
if (count > 0) break;
}
assert.sameValue(1, count);
assert.sameValue(count, 1);
// OptionalExpression in init/test/update.
let count2 = 0;
const obj2 = undefined;
for (obj?.a; obj2?.a; obj?.a) {
count2++;
for (obj?.a; obj2?.a; obj?.a) { count2++; }
assert.sameValue(count2, 0);
for (obj?.a; undefined?.a; obj?.a) { count2++; }
assert.sameValue(count2, 0);
// Short-circuiting
let touched = 0;
const obj3 = {
get a() {
count++;
return undefined; // explicit for clarity
}
};
for (count = 0; true; obj3?.a?.[touched++]) {
if (count > 0) { break; }
}
assert.sameValue(0, count2);
assert.sameValue(count, 1);
assert.sameValue(touched, 0);