Update Promise.allSettled tests

This commit is contained in:
Alexey Shvayka 2020-06-03 17:30:53 +03:00 committed by Rick Waldron
parent cf37b039a8
commit c915741594
4 changed files with 76 additions and 92 deletions

View File

@ -1,48 +0,0 @@
// Copyright (C) 2019 Leo Balter. 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.allsettled
info: |
6. Let result be PerformPromiseAllSettled(iteratorRecord, C, promiseCapability).
7. 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: PerformPromiseAllSettled
6. Repeat
...
i. Let nextPromise be ? Invoke(constructor, "resolve", « nextValue »).
features: [Promise.allSettled, Symbol.iterator]
---*/
var iter = {};
var returnCount = 0;
var nextCount = 0;
iter[Symbol.iterator] = function() {
return {
next() {
nextCount += 1;
return {
done: false
};
},
return() {
returnCount += 1;
return {};
}
};
};
Object.defineProperty(Promise, 'resolve', {
get() {
throw new Test262Error();
}
});
Promise.allSettled(iter);
assert.sameValue(nextCount, 0);
assert.sameValue(returnCount, 1);

View File

@ -0,0 +1,40 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.allsettled
description: >
Promise.resolve is retrieved before GetIterator call (abrupt lookup).
info: |
Promise.allSettled ( iterable )
[...]
3. Let promiseResolve be GetPromiseResolve(C).
4. IfAbruptRejectPromise(promiseResolve, promiseCapability).
GetPromiseResolve ( promiseConstructor )
[...]
2. Let promiseResolve be ? Get(promiseConstructor, "resolve").
flags: [async]
features: [Promise.allSettled, Symbol.iterator]
---*/
const iter = {
get [Symbol.iterator]() {
throw new Test262Error('unreachable');
},
};
const resolveError = { name: 'MyError' };
Object.defineProperty(Promise, 'resolve', {
get() {
throw resolveError;
},
});
Promise.allSettled(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.allsettled
description: >
Promise.resolve is retrieved before GetIterator call (non-callable).
info: |
Promise.allSettled ( 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.allSettled, Symbol.iterator]
---*/
const iter = { 
get [Symbol.iterator]() {
throw new Test262Error("unreachable");
},
};
Promise.resolve = "certainly not callable";
Promise.allSettled(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.allsettled
info: |
5. Let result be PerformPromiseAllSettled(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: PerformPromiseAllSettled
[...]
5. Let promiseResolve be ? Get(constructor, "resolve").
6. If IsCallable(promiseResolve) is false, throw a TypeError exception.
[...]
flags: [async]
features: [Promise.allSettled, 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.allSettled(iter).then(() => {
$DONE('The promise should be rejected, but was resolved');
}, (reason) => {
assert(reason instanceof TypeError);
}).then($DONE, $DONE);
assert.sameValue(returnCount, 1);