Skip to content

Commit 2c6a82e

Browse files
committed
Add cases for abrupt completions in yield* in async generator - next
Closes tc39#883
1 parent 882b3cc commit 2c6a82e

21 files changed

+1199
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2017 Tooru Fujisawa. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
template: default
6+
desc: Abrupt completion while getting done
7+
info: |
8+
YieldExpression: yield * AssignmentExpression
9+
...
10+
6. Repeat
11+
a. If received.[[Type]] is normal, then
12+
ii. Let innerResult be ? Invoke(iterator, "next",
13+
« received.[[Value]] »).
14+
iii. If generatorKind is async, then set innerResult to
15+
? Await(innerResult).
16+
...
17+
v. Let done be ? IteratorComplete(innerResult).
18+
...
19+
features: [Symbol.asyncIterator]
20+
flags: [async]
21+
---*/
22+
23+
//- setup
24+
var reason = {};
25+
var obj = {
26+
get [Symbol.iterator]() {
27+
throw new Test262Error('it should not get Symbol.iterator');
28+
},
29+
[Symbol.asyncIterator]() {
30+
return {
31+
next() {
32+
return {
33+
get done() {
34+
throw reason;
35+
}
36+
};
37+
}
38+
};
39+
}
40+
};
41+
42+
//- body
43+
yield* obj;
44+
throw new Test262Error('abrupt completion closes iter');
45+
46+
//- assertions
47+
iter.next().then(() => {
48+
throw new Test262Error('Promise incorrectly fulfilled.');
49+
}, v => {
50+
assert.sameValue(v, reason, "reject reason");
51+
52+
iter.next().then(({ done, value }) => {
53+
assert.sameValue(done, true, 'the iterator is completed');
54+
assert.sameValue(value, undefined, 'value is undefined');
55+
}).then($DONE, $DONE);
56+
}).catch($DONE);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2017 Tooru Fujisawa. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
template: default
6+
desc: Abrupt completion while calling next
7+
info: |
8+
YieldExpression: yield * AssignmentExpression
9+
...
10+
6. Repeat
11+
a. If received.[[Type]] is normal, then
12+
ii. Let innerResult be ? Invoke(iterator, "next",
13+
« received.[[Value]] »).
14+
...
15+
features: [Symbol.asyncIterator]
16+
flags: [async]
17+
---*/
18+
19+
//- setup
20+
var reason = {};
21+
var obj = {
22+
get [Symbol.iterator]() {
23+
throw new Test262Error('it should not get Symbol.iterator');
24+
},
25+
[Symbol.asyncIterator]() {
26+
return {
27+
next() {
28+
throw reason;
29+
}
30+
};
31+
}
32+
};
33+
34+
//- body
35+
yield* obj;
36+
throw new Test262Error('abrupt completion closes iter');
37+
38+
//- assertions
39+
iter.next().then(() => {
40+
throw new Test262Error('Promise incorrectly fulfilled.');
41+
}, v => {
42+
assert.sameValue(v, reason, "reject reason");
43+
44+
iter.next().then(({ done, value }) => {
45+
assert.sameValue(done, true, 'the iterator is completed');
46+
assert.sameValue(value, undefined, 'value is undefined');
47+
}).then($DONE, $DONE);
48+
}).catch($DONE);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2017 Tooru Fujisawa. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
template: default
6+
desc: Abrupt completion while getting value
7+
info: |
8+
YieldExpression: yield * AssignmentExpression
9+
...
10+
6. Repeat
11+
a. If received.[[Type]] is normal, then
12+
ii. Let innerResult be ? Invoke(iterator, "next",
13+
« received.[[Value]] »).
14+
iii. If generatorKind is async, then set innerResult to
15+
? Await(innerResult).
16+
...
17+
vi. If done is true, then
18+
1. Return ? IteratorValue(innerResult).
19+
...
20+
features: [Symbol.asyncIterator]
21+
flags: [async]
22+
---*/
23+
24+
//- setup
25+
var reason = {};
26+
var obj = {
27+
get [Symbol.iterator]() {
28+
throw new Test262Error('it should not get Symbol.iterator');
29+
},
30+
[Symbol.asyncIterator]() {
31+
return {
32+
next() {
33+
return {
34+
done: true,
35+
get value() {
36+
throw reason;
37+
}
38+
};
39+
}
40+
};
41+
}
42+
};
43+
44+
//- body
45+
yield* obj;
46+
throw new Test262Error('abrupt completion closes iter');
47+
48+
//- assertions
49+
iter.next().then(() => {
50+
throw new Test262Error('Promise incorrectly fulfilled.');
51+
}, v => {
52+
assert.sameValue(v, reason, "reject reason");
53+
54+
iter.next().then(({ done, value }) => {
55+
assert.sameValue(done, true, 'the iterator is completed');
56+
assert.sameValue(value, undefined, 'value is undefined');
57+
}).then($DONE, $DONE);
58+
}).catch($DONE);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2017 Tooru Fujisawa. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
template: default
6+
desc: Abrupt completion while getting next
7+
info: |
8+
YieldExpression: yield * AssignmentExpression
9+
...
10+
6. Repeat
11+
a. If received.[[Type]] is normal, then
12+
ii. Let innerResult be ? Invoke(iterator, "next",
13+
« received.[[Value]] »).
14+
...
15+
features: [Symbol.asyncIterator]
16+
flags: [async]
17+
---*/
18+
19+
//- setup
20+
var reason = {};
21+
var obj = {
22+
get [Symbol.iterator]() {
23+
throw new Test262Error('it should not get Symbol.iterator');
24+
},
25+
[Symbol.asyncIterator]() {
26+
return {
27+
get next() {
28+
throw reason;
29+
}
30+
};
31+
}
32+
};
33+
34+
//- body
35+
yield* obj;
36+
throw new Test262Error('abrupt completion closes iter');
37+
38+
//- assertions
39+
iter.next().then(() => {
40+
throw new Test262Error('Promise incorrectly fulfilled.');
41+
}, v => {
42+
assert.sameValue(v, reason, "reject reason");
43+
44+
iter.next().then(({ done, value }) => {
45+
assert.sameValue(done, true, 'the iterator is completed');
46+
assert.sameValue(value, undefined, 'value is undefined');
47+
}).then($DONE, $DONE);
48+
}).catch($DONE);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2017 Tooru Fujisawa. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
template: default
6+
desc: If next() value is not-object, do not access respective then property
7+
info: |
8+
YieldExpression: yield * AssignmentExpression
9+
...
10+
6. Repeat
11+
a. If received.[[Type]] is normal, then
12+
ii. Let innerResult be ? Invoke(iterator, "next",
13+
« received.[[Value]] »).
14+
iii. If generatorKind is async, then set innerResult to
15+
? Await(innerResult).
16+
iv. If Type(innerResult) is not Object, throw a TypeError exception.
17+
...
18+
19+
Await
20+
21+
...
22+
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
23+
3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »).
24+
...
25+
26+
Promise Resolve Functions
27+
28+
...
29+
7. If Type(resolution) is not Object, then
30+
a. Return FulfillPromise(promise, resolution).
31+
8. Let then be Get(resolution, "then").
32+
...
33+
features: [Symbol.asyncIterator]
34+
flags: [async]
35+
---*/
36+
37+
//- setup
38+
Number.prototype.then = function() {
39+
throw new Test262Error('Number#then should not be used');
40+
};
41+
var obj = {
42+
get [Symbol.iterator]() {
43+
throw new Test262Error('it should not get Symbol.iterator');
44+
},
45+
[Symbol.asyncIterator]() {
46+
return {
47+
next() {
48+
return 42;
49+
}
50+
};
51+
}
52+
};
53+
54+
//- body
55+
yield* obj;
56+
throw new Test262Error('abrupt completion closes iter');
57+
58+
//- assertions
59+
iter.next().then(() => {
60+
throw new Test262Error('Promise incorrectly fulfilled.');
61+
}, v => {
62+
assert.sameValue(v.constructor, TypeError, 'TypeError');
63+
64+
iter.next().then(({ done, value }) => {
65+
assert.sameValue(done, true, 'the iterator is completed');
66+
assert.sameValue(value, undefined, 'value is undefined');
67+
}).then($DONE, $DONE);
68+
}).catch($DONE);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2017 Tooru Fujisawa. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
template: default
6+
desc: Not-callable next value in a yield star position - boolean
7+
info: |
8+
YieldExpression: yield * AssignmentExpression
9+
...
10+
6. Repeat
11+
a. If received.[[Type]] is normal, then
12+
ii. Let innerResult be ? Invoke(iterator, "next",
13+
« received.[[Value]] »).
14+
...
15+
features: [Symbol.asyncIterator]
16+
flags: [async]
17+
---*/
18+
19+
//- setup
20+
var obj = {
21+
get [Symbol.iterator]() {
22+
throw new Test262Error('it should not get Symbol.iterator');
23+
},
24+
[Symbol.asyncIterator]() {
25+
return {
26+
next: true
27+
};
28+
}
29+
};
30+
31+
//- body
32+
yield* obj;
33+
throw new Test262Error('abrupt completion closes iter');
34+
35+
//- assertions
36+
iter.next().then(() => {
37+
throw new Test262Error('Promise incorrectly fulfilled.');
38+
}, v => {
39+
assert.sameValue(v.constructor, TypeError, "TypeError");
40+
41+
iter.next().then(({ done, value }) => {
42+
assert.sameValue(done, true, 'the iterator is completed');
43+
assert.sameValue(value, undefined, 'value is undefined');
44+
}).then($DONE, $DONE);
45+
}).catch($DONE);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2017 Tooru Fujisawa. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
template: default
6+
desc: Not-callable next value in a yield star position - null
7+
info: |
8+
YieldExpression: yield * AssignmentExpression
9+
...
10+
6. Repeat
11+
a. If received.[[Type]] is normal, then
12+
ii. Let innerResult be ? Invoke(iterator, "next",
13+
« received.[[Value]] »).
14+
...
15+
features: [Symbol.asyncIterator]
16+
flags: [async]
17+
---*/
18+
19+
//- setup
20+
var obj = {
21+
get [Symbol.iterator]() {
22+
throw new Test262Error('it should not get Symbol.iterator');
23+
},
24+
[Symbol.asyncIterator]() {
25+
return {
26+
next: null
27+
};
28+
}
29+
};
30+
31+
//- body
32+
yield* obj;
33+
throw new Test262Error('abrupt completion closes iter');
34+
35+
//- assertions
36+
iter.next().then(() => {
37+
throw new Test262Error('Promise incorrectly fulfilled.');
38+
}, v => {
39+
assert.sameValue(v.constructor, TypeError, "TypeError");
40+
41+
iter.next().then(({ done, value }) => {
42+
assert.sameValue(done, true, 'the iterator is completed');
43+
assert.sameValue(value, undefined, 'value is undefined');
44+
}).then($DONE, $DONE);
45+
}).catch($DONE);

0 commit comments

Comments
 (0)