Skip to content
Snippets Groups Projects
Commit 03f0f569 authored by Rick Waldron's avatar Rick Waldron Committed by Leo Balter
Browse files

Promise.all/race with non-iterable or invalid return from Symbol.iterator. (#1496)

Fixes gh-1490
parent 50dd1fbd
No related branches found
No related tags found
No related merge requests found
// Copyright (C) 2018 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.race
description: >
Reject when argument's Symbol.iterator returns null
info: |
...
Let iteratorRecord be GetIterator(iterable).
IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
#sec-getiterator
GetIterator ( obj [ , hint [ , method ] ] )
...
Let iterator be ? Call(method, obj).
If Type(iterator) is not Object, throw a TypeError exception.
...
features: [Symbol.iterator]
flags: [async]
---*/
try {
Promise.race({
[Symbol.iterator]() {
return null;
}
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
// Copyright (C) 2018 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.race
description: >
Reject when argument's Symbol.iterator returns a number
info: |
...
Let iteratorRecord be GetIterator(iterable).
IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
#sec-getiterator
GetIterator ( obj [ , hint [ , method ] ] )
...
Let iterator be ? Call(method, obj).
If Type(iterator) is not Object, throw a TypeError exception.
...
features: [Symbol.iterator]
flags: [async]
---*/
try {
Promise.race({
[Symbol.iterator]() {
return 1;
}
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
// Copyright (C) 2018 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.race
description: >
Reject when argument's Symbol.iterator returns a string
info: |
...
Let iteratorRecord be GetIterator(iterable).
IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
#sec-getiterator
GetIterator ( obj [ , hint [ , method ] ] )
...
Let iterator be ? Call(method, obj).
If Type(iterator) is not Object, throw a TypeError exception.
...
features: [Symbol.iterator]
flags: [async]
---*/
try {
Promise.race({
[Symbol.iterator]() {
return "";
}
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
// Copyright (C) 2018 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.race
description: >
Reject when argument's Symbol.iterator returns a symbol
info: |
...
Let iteratorRecord be GetIterator(iterable).
IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
#sec-getiterator
GetIterator ( obj [ , hint [ , method ] ] )
...
Let iterator be ? Call(method, obj).
If Type(iterator) is not Object, throw a TypeError exception.
...
features: [Symbol.iterator]
flags: [async]
---*/
try {
Promise.race({
[Symbol.iterator]() {
return Symbol();
}
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
// Copyright (C) 2018 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.race
description: >
Reject when argument's Symbol.iterator returns true
info: |
...
Let iteratorRecord be GetIterator(iterable).
IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
#sec-getiterator
GetIterator ( obj [ , hint [ , method ] ] )
...
Let iterator be ? Call(method, obj).
If Type(iterator) is not Object, throw a TypeError exception.
...
features: [Symbol.iterator]
flags: [async]
---*/
try {
Promise.race({
[Symbol.iterator]() {
return true;
}
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
// Copyright (C) 2018 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.race
description: >
Reject when argument's Symbol.iterator returns undefined
info: |
...
Let iteratorRecord be GetIterator(iterable).
IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
#sec-getiterator
GetIterator ( obj [ , hint [ , method ] ] )
...
Let iterator be ? Call(method, obj).
If Type(iterator) is not Object, throw a TypeError exception.
...
features: [Symbol.iterator]
flags: [async]
---*/
try {
Promise.race({
[Symbol.iterator]() {
return undefined;
}
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
......@@ -46,7 +46,7 @@ iterStepThrows[Symbol.iterator] = function() {
};
Promise.race(iterStepThrows).then(function() {
$ERROR('The promise should be rejected.');
$DONE('The promise should be rejected.');
}, function(reason) {
assert.sameValue(reason, error);
}).then($DONE, $DONE);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment