Add iter-arg tests

This commit is contained in:
chicoxyzzy 2019-11-28 00:07:46 +03:00 committed by Rick Waldron
parent 094ddc7f75
commit 9567abd85a
8 changed files with 332 additions and 0 deletions

View File

@ -0,0 +1,36 @@
// Copyright (C) 2019 Sergey Rubanov. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.any
description: >
Reject when argument is `false`
info: |
Promise.any ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. 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: [Promise.any, Symbol.iterator]
flags: [async]
---*/
try {
Promise.any(false).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}

View File

@ -0,0 +1,36 @@
// Copyright (C) 2019 Sergey Rubanov. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.any
description: >
Reject when argument is `null`
info: |
Promise.any ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. 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: [Promise.any, Symbol.iterator]
flags: [async]
---*/
try {
Promise.any(null).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}

View File

@ -0,0 +1,36 @@
// Copyright (C) 2019 Sergey Rubanov. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.any
description: >
Reject when argument is a number
info: |
Promise.any ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. 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: [Promise.any, Symbol.iterator]
flags: [async]
---*/
try {
Promise.any(1).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}

View File

@ -0,0 +1,42 @@
// Copyright (C) 2019 Sergey Rubanov. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.any
description: >
Reject with abrupt completion from GetIterator
info: |
Promise.any ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
#sec-getiterator
GetIterator ( obj [ , hint [ , method ] ] )
...
Let iterator be ? Call(method, obj).
...
features: [Promise.any, Symbol.iterator]
flags: [async]
---*/
var poison = [];
var error = new Test262Error();
Object.defineProperty(poison, Symbol.iterator, {
get() {
throw error;
}
});
try {
Promise.any(poison).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(err) {
assert.sameValue(err, error);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}

View File

@ -0,0 +1,35 @@
// Copyright (C) 2019 Sergey Rubanov. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.any
description: >
Resolve when argument is a string
info: |
Promise.any ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. 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: [Promise.any, Symbol.iterator]
flags: [async]
---*/
try {
Promise.any('').then(function(v) {
assert.sameValue(v.length, 0);
}, function() {
$DONE('The promise should be resolved, but was rejected');
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be resolved, but threw an exception: ${error.message}`);
}

View File

@ -0,0 +1,49 @@
// Copyright (C) 2019 Sergey Rubanov. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.any
description: >
Reject when argument is a symbol
info: |
Promise.any ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.any, Symbol.iterator]
flags: [async]
---*/
try {
Promise.any(Symbol()).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}

View File

@ -0,0 +1,49 @@
// Copyright (C) 2019 Sergey Rubanov. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.any
description: >
Reject when argument is `true`
info: |
Promise.any ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.any, Symbol.iterator]
flags: [async]
---*/
try {
Promise.any(true).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}

View File

@ -0,0 +1,49 @@
// Copyright (C) 2019 Sergey Rubanov. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.any
description: >
Reject when argument is `undefined`
info: |
Promise.any ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.any, Symbol.iterator]
flags: [async]
---*/
try {
Promise.any(undefined).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}