mirror of https://github.com/tc39/test262.git
chore: added a few more examples based on code review
This commit is contained in:
parent
3d0c2037c3
commit
5babea2780
|
@ -8,6 +8,7 @@ info: |
|
||||||
IterationStatement
|
IterationStatement
|
||||||
for await (LeftHandSideExpression of AssignmentExpression) Statement
|
for await (LeftHandSideExpression of AssignmentExpression) Statement
|
||||||
features: [optional-chaining]
|
features: [optional-chaining]
|
||||||
|
flags: [async]
|
||||||
---*/
|
---*/
|
||||||
const obj = {
|
const obj = {
|
||||||
iterable: {
|
iterable: {
|
||||||
|
|
|
@ -11,8 +11,18 @@ features: [optional-chaining]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
const obj = undefined;
|
for (const key of {}?.a) ;
|
||||||
for (const key of obj?.a) {
|
});
|
||||||
str += key;
|
|
||||||
}
|
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);
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,12 +16,28 @@ const obj = {a: true};
|
||||||
for (count = 0; obj?.a; count++) {
|
for (count = 0; obj?.a; count++) {
|
||||||
if (count > 0) break;
|
if (count > 0) break;
|
||||||
}
|
}
|
||||||
assert.sameValue(1, count);
|
assert.sameValue(count, 1);
|
||||||
|
|
||||||
// OptionalExpression in init/test/update.
|
// OptionalExpression in init/test/update.
|
||||||
let count2 = 0;
|
let count2 = 0;
|
||||||
const obj2 = undefined;
|
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);
|
||||||
|
|
Loading…
Reference in New Issue