mirror of
https://github.com/tc39/test262.git
synced 2025-07-25 15:04:43 +02:00
Update Promise.race tests
This commit is contained in:
parent
c915741594
commit
fb88b47938
@ -1,54 +0,0 @@
|
|||||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
description: >
|
|
||||||
Error retrieving the constructor's `resolve` method (iterator closing)
|
|
||||||
esid: sec-promise.race
|
|
||||||
info: |
|
|
||||||
11. Let result be PerformPromiseRace(iteratorRecord, C, promiseCapability).
|
|
||||||
12. If result is an abrupt completion,
|
|
||||||
a. If iteratorRecord.[[done]] is false, let result be
|
|
||||||
IteratorClose(iterator, result).
|
|
||||||
b. IfAbruptRejectPromise(result, promiseCapability).
|
|
||||||
|
|
||||||
[...]
|
|
||||||
|
|
||||||
25.4.4.3.1 Runtime Semantics: PerformPromiseRace
|
|
||||||
|
|
||||||
1. Repeat
|
|
||||||
[...]
|
|
||||||
h. Let nextPromise be Invoke(C, "resolve", «nextValue»).
|
|
||||||
i. ReturnIfAbrupt(nextPromise).
|
|
||||||
features: [Symbol.iterator]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
var iter = {};
|
|
||||||
|
|
||||||
var returnCount = 0;
|
|
||||||
var nextCount = 0;
|
|
||||||
|
|
||||||
iter[Symbol.iterator] = function() {
|
|
||||||
return {
|
|
||||||
next: function() {
|
|
||||||
nextCount += 1;
|
|
||||||
return {
|
|
||||||
done: false
|
|
||||||
};
|
|
||||||
},
|
|
||||||
return: function() {
|
|
||||||
returnCount += 1;
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
Object.defineProperty(Promise, 'resolve', {
|
|
||||||
get() {
|
|
||||||
throw new Test262Error();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Promise.race(iter);
|
|
||||||
|
|
||||||
assert.sameValue(nextCount, 0);
|
|
||||||
assert.sameValue(returnCount, 1);
|
|
40
test/built-ins/Promise/race/invoke-resolve-get-error.js
Normal file
40
test/built-ins/Promise/race/invoke-resolve-get-error.js
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-promise.race
|
||||||
|
description: >
|
||||||
|
Promise.resolve is retrieved before GetIterator call (abrupt lookup).
|
||||||
|
info: |
|
||||||
|
Promise.race ( iterable )
|
||||||
|
|
||||||
|
[...]
|
||||||
|
3. Let promiseResolve be GetPromiseResolve(C).
|
||||||
|
4. IfAbruptRejectPromise(promiseResolve, promiseCapability).
|
||||||
|
|
||||||
|
GetPromiseResolve ( promiseConstructor )
|
||||||
|
|
||||||
|
[...]
|
||||||
|
2. Let promiseResolve be ? Get(promiseConstructor, "resolve").
|
||||||
|
flags: [async]
|
||||||
|
features: [Symbol.iterator]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const iter = {
|
||||||
|
get [Symbol.iterator]() {
|
||||||
|
throw new Test262Error('unreachable');
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const resolveError = { name: 'MyError' };
|
||||||
|
Object.defineProperty(Promise, 'resolve', {
|
||||||
|
get() {
|
||||||
|
throw resolveError;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
Promise.race(iter).then(() => {
|
||||||
|
throw new Test262Error('The promise should be rejected, but it was resolved');
|
||||||
|
}, (reason) => {
|
||||||
|
assert.sameValue(reason, resolveError);
|
||||||
|
}).then($DONE, $DONE);
|
36
test/built-ins/Promise/race/resolve-non-callable.js
Normal file
36
test/built-ins/Promise/race/resolve-non-callable.js
Normal 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.race
|
||||||
|
description: >
|
||||||
|
Promise.resolve is retrieved before GetIterator call (non-callable).
|
||||||
|
info: |
|
||||||
|
Promise.race ( 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: [Symbol.iterator]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const iter = {
|
||||||
|
get [Symbol.iterator]() {
|
||||||
|
throw new Test262Error("unreachable");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
Promise.resolve = "certainly not callable";
|
||||||
|
|
||||||
|
Promise.race(iter).then(() => {
|
||||||
|
throw new Test262Error("The promise should be rejected, but it was resolved");
|
||||||
|
}, (reason) => {
|
||||||
|
assert(reason instanceof TypeError);
|
||||||
|
}).then($DONE, $DONE);
|
@ -1,47 +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.race
|
|
||||||
info: |
|
|
||||||
[...]
|
|
||||||
5. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C).
|
|
||||||
6. If result is an abrupt completion, then
|
|
||||||
a. If iteratorRecord.[[Done]] is false, let result be
|
|
||||||
IteratorClose(iterator,result).
|
|
||||||
b. IfAbruptRejectPromise(result, promiseCapability).
|
|
||||||
|
|
||||||
|
|
||||||
Runtime Semantics: PerformPromiseRace
|
|
||||||
|
|
||||||
[...]
|
|
||||||
3. Let promiseResolve be ? Get(constructor, "resolve").
|
|
||||||
4. If ! IsCallable(promiseResolve) is false, throw a TypeError exception.
|
|
||||||
[...]
|
|
||||||
|
|
||||||
flags: [async]
|
|
||||||
features: [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.race(iter).then(() => {
|
|
||||||
$DONE('The promise should be rejected, but was resolved');
|
|
||||||
}, (reason) => {
|
|
||||||
assert(reason instanceof TypeError);
|
|
||||||
}).then($DONE, $DONE);
|
|
||||||
|
|
||||||
assert.sameValue(returnCount, 1);
|
|
Loading…
x
Reference in New Issue
Block a user