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) {
|
Promise.all = function(list) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
var total = list.length, count = 0, values = []
|
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) {
|
new function(i) {
|
||||||
function consume(value) {
|
function consume(value) {
|
||||||
count++
|
count++
|
||||||
|
|
|
||||||
|
|
@ -530,6 +530,12 @@ o.spec("promise", function() {
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
o("resolves empty array", function(done) {
|
||||||
|
Promise.all([]).then(function(value) {
|
||||||
|
o(value).deepEquals([])
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
o("resolves non-promise to itself", function(done) {
|
o("resolves non-promise to itself", function(done) {
|
||||||
var a = new Promise(function(resolve, reject) {
|
var a = new Promise(function(resolve, reject) {
|
||||||
callAsync(function() {resolve(1)})
|
callAsync(function() {resolve(1)})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue