fix empty array case for Promise.all
This commit is contained in:
parent
9a396c5173
commit
c79b4545c2
2 changed files with 8 additions and 1 deletions
|
|
@ -72,7 +72,8 @@ if (typeof Promise === "undefined") {
|
|||
Promise.all = function(list) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var total = list.length, count = 0, values = []
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
if (list.length === 0) resolve([])
|
||||
else for (var i = 0; i < list.length; i++) {
|
||||
new function(i) {
|
||||
function consume(value) {
|
||||
count++
|
||||
|
|
|
|||
|
|
@ -530,6 +530,12 @@ o.spec("promise", function() {
|
|||
done()
|
||||
})
|
||||
})
|
||||
o("resolves empty array", function(done) {
|
||||
Promise.all([]).then(function(value) {
|
||||
o(value).deepEquals([])
|
||||
done()
|
||||
})
|
||||
})
|
||||
o("resolves non-promise to itself", function(done) {
|
||||
var a = new Promise(function(resolve, reject) {
|
||||
callAsync(function() {resolve(1)})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue