fix empty array case for Promise.all

This commit is contained in:
Leo Horie 2016-06-01 16:22:03 -04:00
parent 9a396c5173
commit c79b4545c2
2 changed files with 8 additions and 1 deletions

View file

@ -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++

View file

@ -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)})