Promise.any: coverage updates, R3

This commit is contained in:
Rick Waldron 2020-06-03 12:54:30 -04:00 committed by Leo Balter
parent 9999dff8fd
commit 081afde9c1
3 changed files with 89 additions and 49 deletions

View File

@ -16,37 +16,53 @@ info: |
IfAbruptRejectPromise(result, promiseCapability).
Return Completion(result).
flags: [async]
features: [Promise.any, Symbol.iterator]
---*/
let callCount = 0;
let nextCount = 0;
let returnCount = 0;
let iter = {};
iter[Symbol.iterator] = function() {
return {
next() {
nextCount += 1;
return {
done: true
};
},
return() {
returnCount += 1;
return {};
}
};
let iter = {
[Symbol.iterator]() {
callCount++;
return {
next() {
callCount++
nextCount++;
return {
done: true
};
},
return() {
callCount++;
returnCount++;
return {};
}
};
}
};
let P = function(executor) {
return new Promise(function(resolve) {
executor(resolve, function() {
throw new Test262Error();
function P(executor) {
callCount++;
return new Promise((_, reject) => {
callCount++;
executor(() => {
callCount++;
$ERROR();
}, () => {
callCount++;
reject(new Test262Error('reject throws'));
});
});
};
P.resolve = Promise.resolve;
Promise.any.call(P, iter);
assert.sameValue(nextCount, 1);
assert.sameValue(returnCount, 0);
Promise.any.call(P, iter).then(
() => {
$DONE('The promise should be rejected.');
}, (reason) => {
assert.sameValue(nextCount, 1);
assert.sameValue(returnCount, 0);
assert.sameValue(callCount, 5);
}).then($DONE, $DONE);

View File

@ -16,36 +16,53 @@ info: |
IfAbruptRejectPromise(result, promiseCapability).
Return Completion(result).
flags: [async]
features: [Promise.any, Symbol.iterator]
---*/
let callCount = 0;
let nextCount = 0;
let returnCount = 0;
let iter = {};
iter[Symbol.iterator] = function() {
return {
next() {
nextCount += 1;
return {
done: true
};
},
return() {
returnCount += 1;
return {};
}
};
let iter = {
[Symbol.iterator]() {
callCount++;
return {
next() {
callCount++;
nextCount += 1;
return {
done: true
};
},
return() {
callCount++;
returnCount += 1;
return {};
}
};
}
};
let P = function(executor) {
return new Promise(function(_, reject) {
executor(function() {
function P(executor) {
callCount++;
return new Promise((_, reject) => {
callCount++;
executor(() => {
callCount++;
throw new Test262Error();
}, reject);
}, (...args) => {
callCount++;
reject(...args);
});
});
};
P.resolve = Promise.resolve;
Promise.any.call(P, iter);
assert.sameValue(nextCount, 1);
assert.sameValue(returnCount, 0);
Promise.any.call(P, iter).then(
() => {
$DONE('The promise should be rejected.');
}, (reason) => {
assert.sameValue(nextCount, 1);
assert.sameValue(returnCount, 0);
assert.sameValue(callCount, 5);
}).then($DONE, $DONE);

View File

@ -19,12 +19,19 @@ info: |
features: [Promise.any, Symbol.iterator]
flags: [async]
---*/
let callCount = 0;
let thrown = new Test262Error();
let P = function(executor) {
function P(executor) {
callCount++;
return new Promise((_, reject) => {
callCount++;
executor(() => {
callCount++;
throw thrown;
}, reject);
}, (...args) => {
callCount++;
reject(...args);
});
});
};
P.resolve = Promise.resolve;
@ -36,7 +43,7 @@ Promise.any.call(P, [1])
// The error was not the result of promise
// resolution, so will not be an AggregateError
assert.sameValue(thrown, error);
$DONE();
});
assert.sameValue(callCount, 6);
}).then($DONE, $DONE);