forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for Promise.all|race resolve lookup
- Loading branch information
Showing
4 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
test/built-ins/Promise/all/invoke-resolve-get-once-multiple-calls.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (C) 2019 Leo Balter. 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.all | ||
info: | | ||
Runtime Semantics: PerformPromiseAll | ||
1. Let promiseResolve be ? Get(constructor, `"resolve"`). | ||
1. If IsCallable(promiseResolve) is false, throw a TypeError exception. | ||
... | ||
1. Repeat, | ||
... | ||
1. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). | ||
---*/ | ||
|
||
var p1 = Promise.resolve(1); | ||
var p2 = Promise.resolve(1); | ||
var p3 = Promise.reject(1); | ||
var p4 = Promise.resolve(1); | ||
var resolve = Promise.resolve; | ||
var getCount = 0; | ||
var callCount = 0; | ||
|
||
Object.defineProperty(Promise, 'resolve', { | ||
configurable: true, | ||
get() { | ||
getCount += 1; | ||
return function() { | ||
callCount += 1; | ||
return resolve.apply(Promise, arguments); | ||
}; | ||
} | ||
}); | ||
|
||
Promise.all([p1, p2, p3, p4]); | ||
|
||
assert.sameValue( | ||
getCount, 1, 'Got `resolve` only once for each iterated value' | ||
); | ||
assert.sameValue( | ||
callCount, 4, '`resolve` invoked once for each iterated value' | ||
); |
42 changes: 42 additions & 0 deletions
42
test/built-ins/Promise/all/invoke-resolve-get-once-no-calls.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2019 Leo Balter. 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.allsettled | ||
info: | | ||
Runtime Semantics: PerformPromiseAll | ||
1. Let promiseResolve be ? Get(constructor, `"resolve"`). | ||
1. If IsCallable(promiseResolve) is false, throw a TypeError exception. | ||
... | ||
1. Repeat, | ||
... | ||
1. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). | ||
features: [Promise.allSettled] | ||
---*/ | ||
|
||
var resolve = Promise.resolve; | ||
var getCount = 0; | ||
var callCount = 0; | ||
|
||
Object.defineProperty(Promise, 'resolve', { | ||
configurable: true, | ||
get() { | ||
getCount += 1; | ||
return function() { | ||
callCount += 1; | ||
return resolve.apply(Promise, arguments); | ||
}; | ||
} | ||
}); | ||
|
||
Promise.all([]); | ||
|
||
assert.sameValue( | ||
getCount, 1, 'Got `resolve` only once for each iterated value' | ||
); | ||
assert.sameValue( | ||
callCount, 0, '`resolve` not called for empty iterator' | ||
); |
45 changes: 45 additions & 0 deletions
45
test/built-ins/Promise/race/invoke-resolve-get-once-multiple-calls.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (C) 2019 Leo Balter. 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.race | ||
info: | | ||
Runtime Semantics: PerformPromiseRace | ||
1. Let promiseResolve be ? Get(constructor, `"resolve"`). | ||
1. If IsCallable(promiseResolve) is false, throw a TypeError exception. | ||
... | ||
1. Repeat, | ||
... | ||
1. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). | ||
---*/ | ||
|
||
var p1 = Promise.resolve(1); | ||
var p2 = Promise.resolve(1); | ||
var p3 = Promise.reject(1); | ||
var p4 = Promise.resolve(1); | ||
var resolve = Promise.resolve; | ||
var getCount = 0; | ||
var callCount = 0; | ||
|
||
Object.defineProperty(Promise, 'resolve', { | ||
configurable: true, | ||
get() { | ||
getCount += 1; | ||
return function() { | ||
callCount += 1; | ||
return resolve.apply(Promise, arguments); | ||
}; | ||
} | ||
}); | ||
|
||
Promise.race([p1, p2, p3, p4]); | ||
|
||
assert.sameValue( | ||
getCount, 1, 'Got `resolve` only once for each iterated value' | ||
); | ||
assert.sameValue( | ||
callCount, 4, '`resolve` invoked once for each iterated value' | ||
); |
41 changes: 41 additions & 0 deletions
41
test/built-ins/Promise/race/invoke-resolve-get-once-no-calls.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (C) 2019 Leo Balter. 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.race | ||
info: | | ||
Runtime Semantics: PerformPromiseRace | ||
1. Let promiseResolve be ? Get(constructor, `"resolve"`). | ||
1. If IsCallable(promiseResolve) is false, throw a TypeError exception. | ||
... | ||
1. Repeat, | ||
... | ||
1. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). | ||
---*/ | ||
|
||
var resolve = Promise.resolve; | ||
var getCount = 0; | ||
var callCount = 0; | ||
|
||
Object.defineProperty(Promise, 'resolve', { | ||
configurable: true, | ||
get() { | ||
getCount += 1; | ||
return function() { | ||
callCount += 1; | ||
return resolve.apply(Promise, arguments); | ||
}; | ||
} | ||
}); | ||
|
||
Promise.race([]); | ||
|
||
assert.sameValue( | ||
getCount, 1, 'Got `resolve` only once for each iterated value' | ||
); | ||
assert.sameValue( | ||
callCount, 0, '`resolve` not called for empty iterator' | ||
); |