mirror of https://github.com/tc39/test262.git
Update Promise.all tests
This commit is contained in:
parent
081afde9c1
commit
cf37b039a8
|
@ -1,57 +0,0 @@
|
||||||
// Copyright (C) 2015 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 before iterator being used.
|
|
||||||
esid: sec-performpromiseall
|
|
||||||
info: |
|
|
||||||
11. Let result be PerformPromiseAll(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).
|
|
||||||
|
|
||||||
...
|
|
||||||
|
|
||||||
Runtime Semantics: PerformPromiseAll
|
|
||||||
|
|
||||||
...
|
|
||||||
1. Let promiseResolve be ? Get(constructor, `"resolve"`).
|
|
||||||
...
|
|
||||||
1. Repeat,
|
|
||||||
1. Let next be IteratorStep(iteratorRecord).
|
|
||||||
...
|
|
||||||
1. Let nextPromise be ? Call(promiseResolve, constructor, < nextValue >).
|
|
||||||
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.all(iter);
|
|
||||||
|
|
||||||
assert.sameValue(nextCount, 0);
|
|
||||||
assert.sameValue(returnCount, 1);
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-promise.all
|
||||||
|
description: >
|
||||||
|
Promise.resolve is retrieved before GetIterator call (abrupt lookup).
|
||||||
|
info: |
|
||||||
|
Promise.all ( 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.all(iter).then(() => {
|
||||||
|
throw new Test262Error('The promise should be rejected, but it was resolved');
|
||||||
|
}, (reason) => {
|
||||||
|
assert.sameValue(reason, resolveError);
|
||||||
|
}).then($DONE, $DONE);
|
|
@ -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.all
|
||||||
|
description: >
|
||||||
|
Promise.resolve is retrieved before GetIterator call (non-callable).
|
||||||
|
info: |
|
||||||
|
Promise.all ( 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.all(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.all
|
|
||||||
info: |
|
|
||||||
5. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability).
|
|
||||||
6. If result is an abrupt completion,
|
|
||||||
a. If iteratorRecord.[[Done]] is false, let result be
|
|
||||||
IteratorClose(iterator, result).
|
|
||||||
b. IfAbruptRejectPromise(result, promiseCapability).
|
|
||||||
|
|
||||||
[...]
|
|
||||||
|
|
||||||
Runtime Semantics: PerformPromiseAll
|
|
||||||
|
|
||||||
[...]
|
|
||||||
5. Let promiseResolve be ? Get(constructor, "resolve").
|
|
||||||
6. 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.all(iter).then(() => {
|
|
||||||
$DONE('The promise should be rejected, but was resolved');
|
|
||||||
}, (reason) => {
|
|
||||||
assert(reason instanceof TypeError);
|
|
||||||
}).then($DONE, $DONE);
|
|
||||||
|
|
||||||
assert.sameValue(returnCount, 1);
|
|
Loading…
Reference in New Issue