Add cases for abrupt completions in yield* in async generator - next

Closes #883
This commit is contained in:
Leo Balter 2017-03-27 21:42:06 -04:00
parent 882b3cc0d0
commit 2c6a82e55f
No known key found for this signature in database
GPG Key ID: 2C75F319D398E36B
21 changed files with 1199 additions and 0 deletions

View File

@ -0,0 +1,56 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: Abrupt completion while getting done
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
iii. If generatorKind is async, then set innerResult to
? Await(innerResult).
...
v. Let done be ? IteratorComplete(innerResult).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var reason = {};
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next() {
return {
get done() {
throw reason;
}
};
}
};
}
};
//- body
yield* obj;
throw new Test262Error('abrupt completion closes iter');
//- assertions
iter.next().then(() => {
throw new Test262Error('Promise incorrectly fulfilled.');
}, v => {
assert.sameValue(v, reason, "reject reason");
iter.next().then(({ done, value }) => {
assert.sameValue(done, true, 'the iterator is completed');
assert.sameValue(value, undefined, 'value is undefined');
}).then($DONE, $DONE);
}).catch($DONE);

View File

@ -0,0 +1,48 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: Abrupt completion while calling next
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var reason = {};
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next() {
throw reason;
}
};
}
};
//- body
yield* obj;
throw new Test262Error('abrupt completion closes iter');
//- assertions
iter.next().then(() => {
throw new Test262Error('Promise incorrectly fulfilled.');
}, v => {
assert.sameValue(v, reason, "reject reason");
iter.next().then(({ done, value }) => {
assert.sameValue(done, true, 'the iterator is completed');
assert.sameValue(value, undefined, 'value is undefined');
}).then($DONE, $DONE);
}).catch($DONE);

View File

@ -0,0 +1,58 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: Abrupt completion while getting value
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
iii. If generatorKind is async, then set innerResult to
? Await(innerResult).
...
vi. If done is true, then
1. Return ? IteratorValue(innerResult).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var reason = {};
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next() {
return {
done: true,
get value() {
throw reason;
}
};
}
};
}
};
//- body
yield* obj;
throw new Test262Error('abrupt completion closes iter');
//- assertions
iter.next().then(() => {
throw new Test262Error('Promise incorrectly fulfilled.');
}, v => {
assert.sameValue(v, reason, "reject reason");
iter.next().then(({ done, value }) => {
assert.sameValue(done, true, 'the iterator is completed');
assert.sameValue(value, undefined, 'value is undefined');
}).then($DONE, $DONE);
}).catch($DONE);

View File

@ -0,0 +1,48 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: Abrupt completion while getting next
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var reason = {};
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
get next() {
throw reason;
}
};
}
};
//- body
yield* obj;
throw new Test262Error('abrupt completion closes iter');
//- assertions
iter.next().then(() => {
throw new Test262Error('Promise incorrectly fulfilled.');
}, v => {
assert.sameValue(v, reason, "reject reason");
iter.next().then(({ done, value }) => {
assert.sameValue(done, true, 'the iterator is completed');
assert.sameValue(value, undefined, 'value is undefined');
}).then($DONE, $DONE);
}).catch($DONE);

View File

@ -0,0 +1,68 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: If next() value is not-object, do not access respective then property
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
iii. If generatorKind is async, then set innerResult to
? Await(innerResult).
iv. If Type(innerResult) is not Object, throw a TypeError exception.
...
Await
...
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »).
...
Promise Resolve Functions
...
7. If Type(resolution) is not Object, then
a. Return FulfillPromise(promise, resolution).
8. Let then be Get(resolution, "then").
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
Number.prototype.then = function() {
throw new Test262Error('Number#then should not be used');
};
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next() {
return 42;
}
};
}
};
//- body
yield* obj;
throw new Test262Error('abrupt completion closes iter');
//- assertions
iter.next().then(() => {
throw new Test262Error('Promise incorrectly fulfilled.');
}, v => {
assert.sameValue(v.constructor, TypeError, 'TypeError');
iter.next().then(({ done, value }) => {
assert.sameValue(done, true, 'the iterator is completed');
assert.sameValue(value, undefined, 'value is undefined');
}).then($DONE, $DONE);
}).catch($DONE);

View File

@ -0,0 +1,45 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: Not-callable next value in a yield star position - boolean
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next: true
};
}
};
//- body
yield* obj;
throw new Test262Error('abrupt completion closes iter');
//- assertions
iter.next().then(() => {
throw new Test262Error('Promise incorrectly fulfilled.');
}, v => {
assert.sameValue(v.constructor, TypeError, "TypeError");
iter.next().then(({ done, value }) => {
assert.sameValue(done, true, 'the iterator is completed');
assert.sameValue(value, undefined, 'value is undefined');
}).then($DONE, $DONE);
}).catch($DONE);

View File

@ -0,0 +1,45 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: Not-callable next value in a yield star position - null
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next: null
};
}
};
//- body
yield* obj;
throw new Test262Error('abrupt completion closes iter');
//- assertions
iter.next().then(() => {
throw new Test262Error('Promise incorrectly fulfilled.');
}, v => {
assert.sameValue(v.constructor, TypeError, "TypeError");
iter.next().then(({ done, value }) => {
assert.sameValue(done, true, 'the iterator is completed');
assert.sameValue(value, undefined, 'value is undefined');
}).then($DONE, $DONE);
}).catch($DONE);

View File

@ -0,0 +1,45 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: Not-callable next value in a yield star position - number
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next: 42
};
}
};
//- body
yield* obj;
throw new Test262Error('abrupt completion closes iter');
//- assertions
iter.next().then(() => {
throw new Test262Error('Promise incorrectly fulfilled.');
}, v => {
assert.sameValue(v.constructor, TypeError, "TypeError");
iter.next().then(({ done, value }) => {
assert.sameValue(done, true, 'the iterator is completed');
assert.sameValue(value, undefined, 'value is undefined');
}).then($DONE, $DONE);
}).catch($DONE);

View File

@ -0,0 +1,45 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: Not-callable next value in a yield star position - object
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next: {}
};
}
};
//- body
yield* obj;
throw new Test262Error('abrupt completion closes iter');
//- assertions
iter.next().then(() => {
throw new Test262Error('Promise incorrectly fulfilled.');
}, v => {
assert.sameValue(v.constructor, TypeError, "TypeError");
iter.next().then(({ done, value }) => {
assert.sameValue(done, true, 'the iterator is completed');
assert.sameValue(value, undefined, 'value is undefined');
}).then($DONE, $DONE);
}).catch($DONE);

View File

@ -0,0 +1,45 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: Not-callable next value in a yield star position - string
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next: ''
};
}
};
//- body
yield* obj;
throw new Test262Error('abrupt completion closes iter');
//- assertions
iter.next().then(() => {
throw new Test262Error('Promise incorrectly fulfilled.');
}, v => {
assert.sameValue(v.constructor, TypeError, "TypeError");
iter.next().then(({ done, value }) => {
assert.sameValue(done, true, 'the iterator is completed');
assert.sameValue(value, undefined, 'value is undefined');
}).then($DONE, $DONE);
}).catch($DONE);

View File

@ -0,0 +1,45 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: Not-callable next value in a yield star position - symbol
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next: Symbol('oi')
};
}
};
//- body
yield* obj;
throw new Test262Error('abrupt completion closes iter');
//- assertions
iter.next().then(() => {
throw new Test262Error('Promise incorrectly fulfilled.');
}, v => {
assert.sameValue(v.constructor, TypeError, "TypeError");
iter.next().then(({ done, value }) => {
assert.sameValue(done, true, 'the iterator is completed');
assert.sameValue(value, undefined, 'value is undefined');
}).then($DONE, $DONE);
}).catch($DONE);

View File

@ -0,0 +1,45 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: Not-callable next value in a yield star position - undefined
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next: undefined
};
}
};
//- body
yield* obj;
throw new Test262Error('abrupt completion closes iter');
//- assertions
iter.next().then(() => {
throw new Test262Error('Promise incorrectly fulfilled.');
}, v => {
assert.sameValue(v.constructor, TypeError, "TypeError");
iter.next().then(({ done, value }) => {
assert.sameValue(done, true, 'the iterator is completed');
assert.sameValue(value, undefined, 'value is undefined');
}).then($DONE, $DONE);
}).catch($DONE);

View File

@ -0,0 +1,72 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: Return abrupt after getting next().then
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
iii. If generatorKind is async, then set innerResult to
? Await(innerResult).
...
Await
...
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »).
...
Promise Resolve Functions
...
8. Let then be Get(resolution, "then").
...
10. Get thenAction be then.[[Value]].
...
12. Perform EnqueueJob("PromiseJobs", PromiseResolveThenableJob, « promise,
resolution, thenAction »).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var reason = {};
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next() {
return {
get then() {
throw reason;
}
};
}
};
}
};
//- body
yield* obj;
throw new Test262Error('abrupt completion closes iter');
//- assertions
iter.next().then(() => {
throw new Test262Error('Promise incorrectly fulfilled.');
}, v => {
assert.sameValue(v, reason, 'reject reason');
iter.next().then(({ done, value }) => {
assert.sameValue(done, true, 'the iterator is completed');
assert.sameValue(value, undefined, 'value is undefined');
}).then($DONE, $DONE);
}).catch($DONE);

View File

@ -0,0 +1,66 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: FulfillPromise if next().then is not-callable (boolean)
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
iii. If generatorKind is async, then set innerResult to
? Await(innerResult).
iv. If Type(innerResult) is not Object, throw a TypeError exception.
...
Await
...
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »).
...
Promise Resolve Functions
...
7. If Type(resolution) is not Object, then
a. Return FulfillPromise(promise, resolution).
8. Let then be Get(resolution, "then").
...
11. If IsCallable(thenAction) is false, then
a. Return FulfillPromise(promise, resolution).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next() {
return {
then: true,
value: 42,
done: false
}
}
};
}
};
//- body
yield* obj;
throw new Test262Error('completion closes iter');
//- assertions
iter.next().then(({ value, done }) => {
assert.sameValue(value, 42);
assert.sameValue(done, false);
}).then($DONE, $DONE);

View File

@ -0,0 +1,66 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: FulfillPromise if next().then is not-callable (null)
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
iii. If generatorKind is async, then set innerResult to
? Await(innerResult).
iv. If Type(innerResult) is not Object, throw a TypeError exception.
...
Await
...
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »).
...
Promise Resolve Functions
...
7. If Type(resolution) is not Object, then
a. Return FulfillPromise(promise, resolution).
8. Let then be Get(resolution, "then").
...
11. If IsCallable(thenAction) is false, then
a. Return FulfillPromise(promise, resolution).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next() {
return {
then: null,
value: 42,
done: false
}
}
};
}
};
//- body
yield* obj;
throw new Test262Error('completion closes iter');
//- assertions
iter.next().then(({ value, done }) => {
assert.sameValue(value, 42);
assert.sameValue(done, false);
}).then($DONE, $DONE);

View File

@ -0,0 +1,66 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: FulfillPromise if next().then is not-callable (number)
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
iii. If generatorKind is async, then set innerResult to
? Await(innerResult).
iv. If Type(innerResult) is not Object, throw a TypeError exception.
...
Await
...
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »).
...
Promise Resolve Functions
...
7. If Type(resolution) is not Object, then
a. Return FulfillPromise(promise, resolution).
8. Let then be Get(resolution, "then").
...
11. If IsCallable(thenAction) is false, then
a. Return FulfillPromise(promise, resolution).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next() {
return {
then: 39,
value: 42,
done: false
}
}
};
}
};
//- body
yield* obj;
throw new Test262Error('completion closes iter');
//- assertions
iter.next().then(({ value, done }) => {
assert.sameValue(value, 42);
assert.sameValue(done, false);
}).then($DONE, $DONE);

View File

@ -0,0 +1,66 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: FulfillPromise if next().then is not-callable (object)
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
iii. If generatorKind is async, then set innerResult to
? Await(innerResult).
iv. If Type(innerResult) is not Object, throw a TypeError exception.
...
Await
...
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »).
...
Promise Resolve Functions
...
7. If Type(resolution) is not Object, then
a. Return FulfillPromise(promise, resolution).
8. Let then be Get(resolution, "then").
...
11. If IsCallable(thenAction) is false, then
a. Return FulfillPromise(promise, resolution).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next() {
return {
then: {},
value: 42,
done: false
}
}
};
}
};
//- body
yield* obj;
throw new Test262Error('completion closes iter');
//- assertions
iter.next().then(({ value, done }) => {
assert.sameValue(value, 42);
assert.sameValue(done, false);
}).then($DONE, $DONE);

View File

@ -0,0 +1,66 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: FulfillPromise if next().then is not-callable (string)
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
iii. If generatorKind is async, then set innerResult to
? Await(innerResult).
iv. If Type(innerResult) is not Object, throw a TypeError exception.
...
Await
...
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »).
...
Promise Resolve Functions
...
7. If Type(resolution) is not Object, then
a. Return FulfillPromise(promise, resolution).
8. Let then be Get(resolution, "then").
...
11. If IsCallable(thenAction) is false, then
a. Return FulfillPromise(promise, resolution).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next() {
return {
then: '',
value: 42,
done: false
}
}
};
}
};
//- body
yield* obj;
throw new Test262Error('completion closes iter');
//- assertions
iter.next().then(({ value, done }) => {
assert.sameValue(value, 42);
assert.sameValue(done, false);
}).then($DONE, $DONE);

View File

@ -0,0 +1,66 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: FulfillPromise if next().then is not-callable (symbol)
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
iii. If generatorKind is async, then set innerResult to
? Await(innerResult).
iv. If Type(innerResult) is not Object, throw a TypeError exception.
...
Await
...
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »).
...
Promise Resolve Functions
...
7. If Type(resolution) is not Object, then
a. Return FulfillPromise(promise, resolution).
8. Let then be Get(resolution, "then").
...
11. If IsCallable(thenAction) is false, then
a. Return FulfillPromise(promise, resolution).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next() {
return {
then: Symbol('oi'),
value: 42,
done: false
}
}
};
}
};
//- body
yield* obj;
throw new Test262Error('completion closes iter');
//- assertions
iter.next().then(({ value, done }) => {
assert.sameValue(value, 42);
assert.sameValue(done, false);
}).then($DONE, $DONE);

View File

@ -0,0 +1,66 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: FulfillPromise if next().then is not-callable (undefined)
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
iii. If generatorKind is async, then set innerResult to
? Await(innerResult).
iv. If Type(innerResult) is not Object, throw a TypeError exception.
...
Await
...
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »).
...
Promise Resolve Functions
...
7. If Type(resolution) is not Object, then
a. Return FulfillPromise(promise, resolution).
8. Let then be Get(resolution, "then").
...
11. If IsCallable(thenAction) is false, then
a. Return FulfillPromise(promise, resolution).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next() {
return {
then: undefined,
value: 42,
done: false
}
}
};
}
};
//- body
yield* obj;
throw new Test262Error('completion closes iter');
//- assertions
iter.next().then(({ value, done }) => {
assert.sameValue(value, 42);
assert.sameValue(done, false);
}).then($DONE, $DONE);

View File

@ -0,0 +1,72 @@
// Copyright 2017 Tooru Fujisawa. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: default
desc: Return abrupt after calling next().then
info: |
YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next",
« received.[[Value]] »).
iii. If generatorKind is async, then set innerResult to
? Await(innerResult).
...
Await
...
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »).
...
Promise Resolve Functions
...
8. Let then be Get(resolution, "then").
...
10. Get thenAction be then.[[Value]].
...
12. Perform EnqueueJob("PromiseJobs", PromiseResolveThenableJob, « promise,
resolution, thenAction »).
...
features: [Symbol.asyncIterator]
flags: [async]
---*/
//- setup
var reason = {};
var obj = {
get [Symbol.iterator]() {
throw new Test262Error('it should not get Symbol.iterator');
},
[Symbol.asyncIterator]() {
return {
next() {
return {
then() {
throw reason;
}
};
}
};
}
};
//- body
yield* obj;
throw new Test262Error('abrupt completion closes iter');
//- assertions
iter.next().then(() => {
throw new Test262Error('Promise incorrectly fulfilled.');
}, v => {
assert.sameValue(v, reason, 'reject reason');
iter.next().then(({ done, value }) => {
assert.sameValue(done, true, 'the iterator is completed');
assert.sameValue(value, undefined, 'value is undefined');
}).then($DONE, $DONE);
}).catch($DONE);