mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 14:04:51 +02:00
Promise.any: coverage updates, R3
This commit is contained in:
parent
9999dff8fd
commit
081afde9c1
@ -16,37 +16,53 @@ info: |
|
|||||||
IfAbruptRejectPromise(result, promiseCapability).
|
IfAbruptRejectPromise(result, promiseCapability).
|
||||||
Return Completion(result).
|
Return Completion(result).
|
||||||
|
|
||||||
|
flags: [async]
|
||||||
features: [Promise.any, Symbol.iterator]
|
features: [Promise.any, Symbol.iterator]
|
||||||
---*/
|
---*/
|
||||||
|
let callCount = 0;
|
||||||
let nextCount = 0;
|
let nextCount = 0;
|
||||||
let returnCount = 0;
|
let returnCount = 0;
|
||||||
let iter = {};
|
let iter = {
|
||||||
iter[Symbol.iterator] = function() {
|
[Symbol.iterator]() {
|
||||||
return {
|
callCount++;
|
||||||
next() {
|
return {
|
||||||
nextCount += 1;
|
next() {
|
||||||
return {
|
callCount++
|
||||||
done: true
|
nextCount++;
|
||||||
};
|
return {
|
||||||
},
|
done: true
|
||||||
return() {
|
};
|
||||||
returnCount += 1;
|
},
|
||||||
return {};
|
return() {
|
||||||
}
|
callCount++;
|
||||||
};
|
returnCount++;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let P = function(executor) {
|
|
||||||
return new Promise(function(resolve) {
|
function P(executor) {
|
||||||
executor(resolve, function() {
|
callCount++;
|
||||||
throw new Test262Error();
|
return new Promise((_, reject) => {
|
||||||
|
callCount++;
|
||||||
|
executor(() => {
|
||||||
|
callCount++;
|
||||||
|
$ERROR();
|
||||||
|
}, () => {
|
||||||
|
callCount++;
|
||||||
|
reject(new Test262Error('reject throws'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
P.resolve = Promise.resolve;
|
P.resolve = Promise.resolve;
|
||||||
|
|
||||||
Promise.any.call(P, iter);
|
Promise.any.call(P, iter).then(
|
||||||
|
() => {
|
||||||
assert.sameValue(nextCount, 1);
|
$DONE('The promise should be rejected.');
|
||||||
assert.sameValue(returnCount, 0);
|
}, (reason) => {
|
||||||
|
assert.sameValue(nextCount, 1);
|
||||||
|
assert.sameValue(returnCount, 0);
|
||||||
|
assert.sameValue(callCount, 5);
|
||||||
|
}).then($DONE, $DONE);
|
||||||
|
@ -16,36 +16,53 @@ info: |
|
|||||||
IfAbruptRejectPromise(result, promiseCapability).
|
IfAbruptRejectPromise(result, promiseCapability).
|
||||||
Return Completion(result).
|
Return Completion(result).
|
||||||
|
|
||||||
|
flags: [async]
|
||||||
features: [Promise.any, Symbol.iterator]
|
features: [Promise.any, Symbol.iterator]
|
||||||
---*/
|
---*/
|
||||||
|
let callCount = 0;
|
||||||
let nextCount = 0;
|
let nextCount = 0;
|
||||||
let returnCount = 0;
|
let returnCount = 0;
|
||||||
let iter = {};
|
let iter = {
|
||||||
iter[Symbol.iterator] = function() {
|
[Symbol.iterator]() {
|
||||||
return {
|
callCount++;
|
||||||
next() {
|
return {
|
||||||
nextCount += 1;
|
next() {
|
||||||
return {
|
callCount++;
|
||||||
done: true
|
nextCount += 1;
|
||||||
};
|
return {
|
||||||
},
|
done: true
|
||||||
return() {
|
};
|
||||||
returnCount += 1;
|
},
|
||||||
return {};
|
return() {
|
||||||
}
|
callCount++;
|
||||||
};
|
returnCount += 1;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let P = function(executor) {
|
|
||||||
return new Promise(function(_, reject) {
|
function P(executor) {
|
||||||
executor(function() {
|
callCount++;
|
||||||
|
return new Promise((_, reject) => {
|
||||||
|
callCount++;
|
||||||
|
executor(() => {
|
||||||
|
callCount++;
|
||||||
throw new Test262Error();
|
throw new Test262Error();
|
||||||
}, reject);
|
}, (...args) => {
|
||||||
|
callCount++;
|
||||||
|
reject(...args);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
P.resolve = Promise.resolve;
|
P.resolve = Promise.resolve;
|
||||||
|
|
||||||
Promise.any.call(P, iter);
|
Promise.any.call(P, iter).then(
|
||||||
|
() => {
|
||||||
assert.sameValue(nextCount, 1);
|
$DONE('The promise should be rejected.');
|
||||||
assert.sameValue(returnCount, 0);
|
}, (reason) => {
|
||||||
|
assert.sameValue(nextCount, 1);
|
||||||
|
assert.sameValue(returnCount, 0);
|
||||||
|
assert.sameValue(callCount, 5);
|
||||||
|
}).then($DONE, $DONE);
|
||||||
|
@ -19,12 +19,19 @@ info: |
|
|||||||
features: [Promise.any, Symbol.iterator]
|
features: [Promise.any, Symbol.iterator]
|
||||||
flags: [async]
|
flags: [async]
|
||||||
---*/
|
---*/
|
||||||
|
let callCount = 0;
|
||||||
let thrown = new Test262Error();
|
let thrown = new Test262Error();
|
||||||
let P = function(executor) {
|
function P(executor) {
|
||||||
|
callCount++;
|
||||||
return new Promise((_, reject) => {
|
return new Promise((_, reject) => {
|
||||||
|
callCount++;
|
||||||
executor(() => {
|
executor(() => {
|
||||||
|
callCount++;
|
||||||
throw thrown;
|
throw thrown;
|
||||||
}, reject);
|
}, (...args) => {
|
||||||
|
callCount++;
|
||||||
|
reject(...args);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
P.resolve = Promise.resolve;
|
P.resolve = Promise.resolve;
|
||||||
@ -36,7 +43,7 @@ Promise.any.call(P, [1])
|
|||||||
// The error was not the result of promise
|
// The error was not the result of promise
|
||||||
// resolution, so will not be an AggregateError
|
// resolution, so will not be an AggregateError
|
||||||
assert.sameValue(thrown, error);
|
assert.sameValue(thrown, error);
|
||||||
$DONE();
|
assert.sameValue(callCount, 6);
|
||||||
});
|
}).then($DONE, $DONE);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user