diff --git a/test/language/expressions/optional-chaining/iteration-statement-for-await-of.js b/test/language/expressions/optional-chaining/iteration-statement-for-await-of.js index e7b9ebde8b..6d414965ab 100644 --- a/test/language/expressions/optional-chaining/iteration-statement-for-await-of.js +++ b/test/language/expressions/optional-chaining/iteration-statement-for-await-of.js @@ -8,6 +8,7 @@ info: | IterationStatement for await (LeftHandSideExpression of AssignmentExpression) Statement features: [optional-chaining] +flags: [async] ---*/ const obj = { iterable: { diff --git a/test/language/expressions/optional-chaining/iteration-statement-for-of-type-error.js b/test/language/expressions/optional-chaining/iteration-statement-for-of-type-error.js index 080d19c3a9..3cd18cd48f 100644 --- a/test/language/expressions/optional-chaining/iteration-statement-for-of-type-error.js +++ b/test/language/expressions/optional-chaining/iteration-statement-for-of-type-error.js @@ -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); }); diff --git a/test/language/expressions/optional-chaining/iteration-statement-for.js b/test/language/expressions/optional-chaining/iteration-statement-for.js index 34e6b8e3e1..c6d78a3181 100644 --- a/test/language/expressions/optional-chaining/iteration-statement-for.js +++ b/test/language/expressions/optional-chaining/iteration-statement-for.js @@ -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);