Promise.any: additional then + resolve tests

This commit is contained in:
Rick Waldron 2020-03-24 17:22:11 -04:00
parent 1c748507f2
commit d9265df3ab
11 changed files with 457 additions and 1 deletions

View File

@ -0,0 +1,54 @@
// 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: >
Explicit iterator closing in response to error
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]
---*/
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;
}
};
}
};
Promise.resolve = function() {
throw error;
};
Promise.any(iter).then(() => {
$DONE('The promise should be rejected, but was resolved');
}, (reason) => {
assert.sameValue(nextCount, 1);
assert.sameValue(returnCount, 1);
assert.sameValue(reason, error);
}).then($DONE, $DONE);

View File

@ -0,0 +1,33 @@
// 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: Promise rejection in response to error
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]
---*/
let error = new Test262Error();
Promise.resolve = function() {
throw error;
};
Promise.any([1]).then(() => {
$DONE('The promise should be rejected, but was resolved');
}, (reason) => {
assert.sameValue(reason, error);
}).then($DONE, $DONE);

View File

@ -0,0 +1,58 @@
// 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]
---*/
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,36 @@
// 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 (rejecting promise)
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]
---*/
let error = new Test262Error();
Object.defineProperty(Promise, 'resolve', {
get() {
throw error;
}
});
Promise.any([1]).then(() => {
$DONE('The promise should be rejected, but was resolved');
}, (reason) => {
assert.sameValue(reason, error);
}).then($DONE, $DONE);

View File

@ -0,0 +1,55 @@
// 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: >
Gets constructor's `resolve` method once from zero to many invocations.
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
6. Let promiseResolve be ? Get(constructor, "resolve").
7. If ! IsCallable(promiseResolve) is false, throw a TypeError exception.
8. Repeat
...
i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »).
flags: [async]
features: [Promise.any]
---*/
let promises = [
Promise.reject(1),
Promise.reject(1),
Promise.reject(1),
];
let boundPromiseResolve = Promise.resolve.bind(Promise);
let getCount = 0;
let callCount = 0;
Object.defineProperty(Promise, 'resolve', {
configurable: true,
get() {
getCount += 1;
return function(...args) {
callCount += 1;
return boundPromiseResolve(...args);
};
}
});
Promise.any(promises).then(() => {
$DONE('The promise should be rejected, but was resolved');
}, ({errors}) => {
assert.sameValue(getCount, 1);
assert.sameValue(callCount, 3);
assert.sameValue(errors.length, 3);
}).then($DONE, $DONE);

View File

@ -0,0 +1,50 @@
// 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: >
Gets constructor's `resolve` method once from zero to many invocations.
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
6. Let promiseResolve be ? Get(constructor, "resolve").
7. If ! IsCallable(promiseResolve) is false, throw a TypeError exception.
8. Repeat
...
i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »).
flags: [async]
features: [Promise.any]
---*/
let boundPromiseResolve = Promise.resolve.bind(Promise);
let getCount = 0;
let callCount = 0;
Object.defineProperty(Promise, 'resolve', {
configurable: true,
get() {
getCount += 1;
return function(...args) {
callCount += 1;
return boundPromiseResolve(...args);
};
}
});
Promise.any([]).then(() => {
$DONE('The promise should be rejected, but was resolved');
}, ({errors}) => {
assert.sameValue(getCount, 1);
assert.sameValue(callCount, 0);
assert.sameValue(errors.length, 0);
}).then($DONE, $DONE);

View File

@ -1,4 +1,4 @@
// Copyright (C) 2019 Sergey Rubanov. All rights reserved.
// Copyright (C) 2019 Sergey Rubanov, 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---

View File

@ -0,0 +1,51 @@
// 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 thrown when invoking the instance's `then` method (closing 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
r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »).
flags: [async]
features: [Promise.any, Symbol.iterator]
---*/
let error = new Test262Error();
let promise = new Promise(() => {});
let returnCount = 0;
let iter = {
[Symbol.iterator]() {
return {
next() {
return {
done: false,
value: promise
};
},
return() {
returnCount += 1;
return {};
}
};
}
};
promise.then = function() {
throw error;
};
Promise.any(iter).then(() => {
$DONE('The promise should be rejected, but was resolved');
}, (reason) => {
assert.sameValue(returnCount, 1);
assert.sameValue(reason, error);
}).then($DONE, $DONE);

View File

@ -0,0 +1,33 @@
// 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 thrown when invoking the instance's `then` method (rejecting Promise)
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
r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »).
flags: [async]
features: [Promise.any]
---*/
let error = new Test262Error();
let promise = Promise.resolve();
promise.then = function() {
throw error;
};
Promise.any([promise]).then(() => {
$DONE('The promise should be rejected, but was resolved');
}, (reason) => {
assert.sameValue(reason, error);
}).then($DONE, $DONE);

View File

@ -0,0 +1,52 @@
// 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 thrown when accesing the instance's `then` method (closing 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
r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »).
flags: [async]
features: [Promise.any, Symbol.iterator]
---*/
let error = new Test262Error();
let promise = new Promise(() => {});
let returnCount = 0;
let iter = {
[Symbol.iterator]() {
return {
next() {
return {
done: false,
value: promise
};
},
return() {
returnCount += 1;
return {};
}
};
}
};
Object.defineProperty(promise, 'then', {
get() {
throw error;
}
});
Promise.any(iter).then(() => {
$DONE('The promise should be rejected, but was resolved');
}, (reason) => {
assert.sameValue(returnCount, 1);
assert.sameValue(reason, error);
}).then($DONE, $DONE);

View File

@ -0,0 +1,34 @@
// 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 thrown when accessing the instance's `then` method (rejecting Promise)
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
r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »).
flags: [async]
features: [Promise.any]
---*/
let error = new Test262Error();
let promise = new Promise(() => {});
Object.defineProperty(promise, 'then', {
get() {
throw error;
}
});
Promise.any([promise]).then(() => {
$DONE('The promise should be rejected, but was resolved');
}, (reason) => {
assert.sameValue(reason, error);
}).then($DONE, $DONE);