Update Promise.any tests

This commit is contained in:
Alexey Shvayka 2020-06-03 17:39:31 +03:00 committed by Rick Waldron
parent fb88b47938
commit 290ceba31f
4 changed files with 76 additions and 101 deletions

View File

@ -1,57 +0,0 @@
// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Error retrieving the constructor's `resolve` method not opening iterator
esid: sec-promise.any
info: |
5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability).
6. If result is an abrupt completion, then
a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result).
b. IfAbruptRejectPromise(result, promiseCapability).
Runtime Semantics: PerformPromiseAny
8. Repeat
...
i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »).
flags: [async]
features: [Promise.any, Symbol.iterator, computed-property-names, Symbol, arrow-function]
---*/
let error = new Test262Error();
let nextCount = 0;
let returnCount = 0;
let iter = {
[Symbol.iterator]() {
return {
next() {
nextCount += 1;
return {
value: null,
done: false
};
},
return() {
returnCount += 1;
}
};
}
};
Object.defineProperty(Promise, 'resolve', {
get() {
throw error;
}
});
Promise.any(iter).then(() => {
$DONE('The promise should be rejected, but was resolved');
}, (reason) => {
assert.sameValue(nextCount, 0);
assert.sameValue(returnCount, 1);
assert.sameValue(reason, error);
}).then($DONE, $DONE);

View File

@ -0,0 +1,40 @@
// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.any
description: >
Promise.resolve is retrieved before GetIterator call (abrupt lookup).
info: |
Promise.any ( iterable )
[...]
3. Let promiseResolve be GetPromiseResolve(C).
4. IfAbruptRejectPromise(promiseResolve, promiseCapability).
GetPromiseResolve ( promiseConstructor )
[...]
2. Let promiseResolve be ? Get(promiseConstructor, "resolve").
flags: [async]
features: [Promise.any, Symbol.iterator]
---*/
const iter = {
get [Symbol.iterator]() {
throw new Test262Error('unreachable');
},
};
const resolveError = { name: 'MyError' };
Object.defineProperty(Promise, 'resolve', {
get() {
throw resolveError;
},
});
Promise.any(iter).then(() => {
throw new Test262Error('The promise should be rejected, but it was resolved');
}, (reason) => {
assert.sameValue(reason, resolveError);
}).then($DONE, $DONE);

View File

@ -0,0 +1,36 @@
// Copyright (C) 2020 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.any
description: >
Promise.resolve is retrieved before GetIterator call (non-callable).
info: |
Promise.any ( iterable )
[...]
3. Let promiseResolve be GetPromiseResolve(C).
4. IfAbruptRejectPromise(promiseResolve, promiseCapability).
GetPromiseResolve ( promiseConstructor )
[...]
2. Let promiseResolve be ? Get(promiseConstructor, "resolve").
3. If IsCallable(promiseResolve) is false, throw a TypeError exception.
flags: [async]
features: [Promise.any, Symbol.iterator]
---*/
const iter = { 
get [Symbol.iterator]() {
throw new Test262Error("unreachable");
},
};
Promise.resolve = "certainly not callable";
Promise.any(iter).then(() => {
throw new Test262Error("The promise should be rejected, but it was resolved");
}, (reason) => {
assert(reason instanceof TypeError);
}).then($DONE, $DONE);

View File

@ -1,44 +0,0 @@
// Copyright (C) 2020 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Explicit iterator closing if Promise.resolve is not callable
esid: sec-promise.any
info: |
5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability).
6. If result is an abrupt completion, then
a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result).
b. IfAbruptRejectPromise(result, promiseCapability).
Runtime Semantics: PerformPromiseAny
[...]
5. Let promiseResolve be ? Get(constructor, "resolve").
6. If ! IsCallable(promiseResolve) is false, throw a TypeError exception.
[...]
flags: [async]
features: [Promise.any, Symbol.iterator, computed-property-names, arrow-function]
---*/
let returnCount = 0;
const iter = { 
[Symbol.iterator]: function() {
return {
return: function() {
++returnCount;
}
};
}
}
Promise.resolve = "certainly not callable";
Promise.any(iter).then(() => {
$DONE('The promise should be rejected, but was resolved');
}, (reason) => {
assert(reason instanceof TypeError);
}).then($DONE, $DONE);
assert.sameValue(returnCount, 1);