Index: test/mjsunit/harmony/promises.js |
diff --git a/test/mjsunit/harmony/promises.js b/test/mjsunit/harmony/promises.js |
index 3aa3fec33bf7b7ac0605d6ac4e4b1b690e207da7..38ccd7fb2bdc27a645efa5e25c1c03b0daaa2446 100644 |
--- a/test/mjsunit/harmony/promises.js |
+++ b/test/mjsunit/harmony/promises.js |
@@ -58,16 +58,32 @@ function assertAsyncDone(iteration) { |
(function() { |
+ assertThrows(function() { Promise(function() {}) }, TypeError) |
+})(); |
+ |
+(function() { |
+ assertTrue(new Promise(function() {}) instanceof Promise) |
+})(); |
+ |
+(function() { |
assertThrows(function() { new Promise(5) }, TypeError) |
})(); |
(function() { |
- assertThrows(function() { new Promise(function() { throw 5 }) }, 5) |
+ assertDoesNotThrow(function() { new Promise(function() { throw 5 }) }) |
+})(); |
+ |
+(function() { |
+ (new Promise(function() { throw 5 })).chain( |
+ assertUnreachable, |
+ function(r) { assertAsync(r === 5, "new-throw") } |
+ ) |
+ assertAsyncRan() |
})(); |
(function() { |
- Promise.resolved(5); |
- Promise.resolved(5).chain(undefined, assertUnreachable).chain( |
+ Promise.resolve(5); |
+ Promise.resolve(5).chain(undefined, assertUnreachable).chain( |
function(x) { assertAsync(x === 5, "resolved/chain-nohandler") }, |
assertUnreachable |
) |
@@ -75,7 +91,7 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- Promise.rejected(5).chain(assertUnreachable, undefined).chain( |
+ Promise.reject(5).chain(assertUnreachable, undefined).chain( |
assertUnreachable, |
function(r) { assertAsync(r === 5, "rejected/chain-nohandler") } |
) |
@@ -83,7 +99,7 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- Promise.resolved(5).then(undefined, assertUnreachable).chain( |
+ Promise.resolve(5).then(undefined, assertUnreachable).chain( |
function(x) { assertAsync(x === 5, "resolved/then-nohandler") }, |
assertUnreachable |
) |
@@ -91,7 +107,7 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- Promise.rejected(5).then(assertUnreachable, undefined).chain( |
+ Promise.reject(5).then(assertUnreachable, undefined).chain( |
assertUnreachable, |
function(r) { assertAsync(r === 5, "rejected/then-nohandler") } |
) |
@@ -99,9 +115,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
+ var p1 = Promise.resolve(5) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
p3.chain( |
function(x) { assertAsync(x === p2, "resolved/chain") }, |
assertUnreachable |
@@ -110,9 +126,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
+ var p1 = Promise.resolve(5) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
p3.then( |
function(x) { assertAsync(x === 5, "resolved/then") }, |
assertUnreachable |
@@ -121,9 +137,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.rejected(5) |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
+ var p1 = Promise.reject(5) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
p3.chain( |
function(x) { assertAsync(x === p2, "rejected/chain") }, |
assertUnreachable |
@@ -132,9 +148,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.rejected(5) |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
+ var p1 = Promise.reject(5) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
p3.then( |
assertUnreachable, |
function(x) { assertAsync(x === 5, "rejected/then") } |
@@ -143,9 +159,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
+ var p1 = Promise.resolve(5) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
p3.chain(function(x) { return x }, assertUnreachable).chain( |
function(x) { assertAsync(x === p1, "resolved/chain/chain") }, |
assertUnreachable |
@@ -154,9 +170,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
+ var p1 = Promise.resolve(5) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
p3.chain(function(x) { return x }, assertUnreachable).then( |
function(x) { assertAsync(x === 5, "resolved/chain/then") }, |
assertUnreachable |
@@ -165,9 +181,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
+ var p1 = Promise.resolve(5) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
p3.chain(function(x) { return 6 }, assertUnreachable).chain( |
function(x) { assertAsync(x === 6, "resolved/chain/chain2") }, |
assertUnreachable |
@@ -176,9 +192,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
+ var p1 = Promise.resolve(5) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
p3.chain(function(x) { return 6 }, assertUnreachable).then( |
function(x) { assertAsync(x === 6, "resolved/chain/then2") }, |
assertUnreachable |
@@ -187,9 +203,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
+ var p1 = Promise.resolve(5) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
p3.then(function(x) { return x + 1 }, assertUnreachable).chain( |
function(x) { assertAsync(x === 6, "resolved/then/chain") }, |
assertUnreachable |
@@ -198,9 +214,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
+ var p1 = Promise.resolve(5) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
p3.then(function(x) { return x + 1 }, assertUnreachable).then( |
function(x) { assertAsync(x === 6, "resolved/then/then") }, |
assertUnreachable |
@@ -209,10 +225,10 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
- p3.then(function(x){ return Promise.resolved(x+1) }, assertUnreachable).chain( |
+ var p1 = Promise.resolve(5) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
+ p3.then(function(x){ return Promise.resolve(x+1) }, assertUnreachable).chain( |
function(x) { assertAsync(x === 6, "resolved/then/chain2") }, |
assertUnreachable |
) |
@@ -220,10 +236,10 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
- p3.then(function(x) { return Promise.resolved(x+1) }, assertUnreachable).then( |
+ var p1 = Promise.resolve(5) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
+ p3.then(function(x) { return Promise.resolve(x+1) }, assertUnreachable).then( |
function(x) { assertAsync(x === 6, "resolved/then/then2") }, |
assertUnreachable |
) |
@@ -231,9 +247,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
+ var p1 = Promise.resolve(5) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
p3.chain(function(x) { throw 6 }, assertUnreachable).chain( |
assertUnreachable, |
function(x) { assertAsync(x === 6, "resolved/chain-throw/chain") } |
@@ -242,9 +258,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
+ var p1 = Promise.resolve(5) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
p3.chain(function(x) { throw 6 }, assertUnreachable).then( |
assertUnreachable, |
function(x) { assertAsync(x === 6, "resolved/chain-throw/then") } |
@@ -253,9 +269,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
+ var p1 = Promise.resolve(5) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
p3.then(function(x) { throw 6 }, assertUnreachable).chain( |
assertUnreachable, |
function(x) { assertAsync(x === 6, "resolved/then-throw/chain") } |
@@ -264,9 +280,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
+ var p1 = Promise.resolve(5) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
p3.then(function(x) { throw 6 }, assertUnreachable).then( |
assertUnreachable, |
function(x) { assertAsync(x === 6, "resolved/then-throw/then") } |
@@ -275,9 +291,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
+ var p1 = Promise.resolve(5) |
var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} |
- var p3 = Promise.resolved(p2) |
+ var p3 = Promise.resolve(p2) |
p3.chain( |
function(x) { assertAsync(x === p2, "resolved/thenable/chain") }, |
assertUnreachable |
@@ -286,9 +302,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
+ var p1 = Promise.resolve(5) |
var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} |
- var p3 = Promise.resolved(p2) |
+ var p3 = Promise.resolve(p2) |
p3.then( |
function(x) { assertAsync(x === 5, "resolved/thenable/then") }, |
assertUnreachable |
@@ -297,9 +313,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.rejected(5) |
+ var p1 = Promise.reject(5) |
var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} |
- var p3 = Promise.resolved(p2) |
+ var p3 = Promise.resolve(p2) |
p3.chain( |
function(x) { assertAsync(x === p2, "rejected/thenable/chain") }, |
assertUnreachable |
@@ -308,9 +324,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.rejected(5) |
+ var p1 = Promise.reject(5) |
var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} |
- var p3 = Promise.resolved(p2) |
+ var p3 = Promise.resolve(p2) |
p3.then( |
assertUnreachable, |
function(x) { assertAsync(x === 5, "rejected/thenable/then") } |
@@ -319,10 +335,10 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var deferred = Promise.deferred() |
+ var deferred = Promise.defer() |
var p1 = deferred.promise |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
p3.chain( |
function(x) { assertAsync(x === p2, "chain/resolve") }, |
assertUnreachable |
@@ -332,10 +348,10 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var deferred = Promise.deferred() |
+ var deferred = Promise.defer() |
var p1 = deferred.promise |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
p3.then( |
function(x) { assertAsync(x === 5, "then/resolve") }, |
assertUnreachable |
@@ -345,10 +361,10 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var deferred = Promise.deferred() |
+ var deferred = Promise.defer() |
var p1 = deferred.promise |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
p3.chain( |
function(x) { assertAsync(x === p2, "chain/reject") }, |
assertUnreachable |
@@ -358,10 +374,10 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var deferred = Promise.deferred() |
+ var deferred = Promise.defer() |
var p1 = deferred.promise |
- var p2 = Promise.resolved(p1) |
- var p3 = Promise.resolved(p2) |
+ var p2 = Promise.resolve(p1) |
+ var p3 = Promise.resolve(p2) |
p3.then( |
assertUnreachable, |
function(x) { assertAsync(x === 5, "then/reject") } |
@@ -371,10 +387,10 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var deferred = Promise.deferred() |
+ var deferred = Promise.defer() |
var p1 = deferred.promise |
var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} |
- var p3 = Promise.resolved(p2) |
+ var p3 = Promise.resolve(p2) |
p3.chain( |
function(x) { assertAsync(x === p2, "chain/resolve/thenable") }, |
assertUnreachable |
@@ -384,10 +400,10 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var deferred = Promise.deferred() |
+ var deferred = Promise.defer() |
var p1 = deferred.promise |
var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} |
- var p3 = Promise.resolved(p2) |
+ var p3 = Promise.resolve(p2) |
p3.then( |
function(x) { assertAsync(x === 5, "then/resolve/thenable") }, |
assertUnreachable |
@@ -397,10 +413,10 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var deferred = Promise.deferred() |
+ var deferred = Promise.defer() |
var p1 = deferred.promise |
var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} |
- var p3 = Promise.resolved(p2) |
+ var p3 = Promise.resolve(p2) |
p3.chain( |
function(x) { assertAsync(x === p2, "chain/reject/thenable") }, |
assertUnreachable |
@@ -410,10 +426,10 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var deferred = Promise.deferred() |
+ var deferred = Promise.defer() |
var p1 = deferred.promise |
var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} |
- var p3 = Promise.resolved(p2) |
+ var p3 = Promise.resolve(p2) |
p3.then( |
assertUnreachable, |
function(x) { assertAsync(x === 5, "then/reject/thenable") } |
@@ -423,9 +439,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
- var p2 = Promise.resolved(p1) |
- var deferred = Promise.deferred() |
+ var p1 = Promise.resolve(5) |
+ var p2 = Promise.resolve(p1) |
+ var deferred = Promise.defer() |
var p3 = deferred.promise |
p3.chain( |
function(x) { assertAsync(x === p2, "chain/resolve2") }, |
@@ -436,9 +452,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
- var p2 = Promise.resolved(p1) |
- var deferred = Promise.deferred() |
+ var p1 = Promise.resolve(5) |
+ var p2 = Promise.resolve(p1) |
+ var deferred = Promise.defer() |
var p3 = deferred.promise |
p3.then( |
function(x) { assertAsync(x === 5, "then/resolve2") }, |
@@ -449,9 +465,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
- var p2 = Promise.resolved(p1) |
- var deferred = Promise.deferred() |
+ var p1 = Promise.resolve(5) |
+ var p2 = Promise.resolve(p1) |
+ var deferred = Promise.defer() |
var p3 = deferred.promise |
p3.chain( |
assertUnreachable, |
@@ -462,9 +478,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
- var p2 = Promise.resolved(p1) |
- var deferred = Promise.deferred() |
+ var p1 = Promise.resolve(5) |
+ var p2 = Promise.resolve(p1) |
+ var deferred = Promise.defer() |
var p3 = deferred.promise |
p3.then( |
assertUnreachable, |
@@ -475,9 +491,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
+ var p1 = Promise.resolve(5) |
var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} |
- var deferred = Promise.deferred() |
+ var deferred = Promise.defer() |
var p3 = deferred.promise |
p3.chain( |
function(x) { assertAsync(x === p2, "chain/resolve/thenable2") }, |
@@ -488,9 +504,9 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(5) |
+ var p1 = Promise.resolve(5) |
var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} |
- var deferred = Promise.deferred() |
+ var deferred = Promise.defer() |
var p3 = deferred.promise |
p3.then( |
function(x) { assertAsync(x === 5, "then/resolve/thenable2") }, |
@@ -501,7 +517,7 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(0) |
+ var p1 = Promise.resolve(0) |
var p2 = p1.chain(function(x) { return p2 }, assertUnreachable) |
p2.chain( |
assertUnreachable, |
@@ -511,7 +527,7 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var p1 = Promise.resolved(0) |
+ var p1 = Promise.resolve(0) |
var p2 = p1.then(function(x) { return p2 }, assertUnreachable) |
p2.chain( |
assertUnreachable, |
@@ -521,7 +537,7 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var deferred = Promise.deferred() |
+ var deferred = Promise.defer() |
var p = deferred.promise |
deferred.resolve(p) |
p.chain( |
@@ -532,7 +548,7 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var deferred = Promise.deferred() |
+ var deferred = Promise.defer() |
var p = deferred.promise |
deferred.resolve(p) |
p.then( |
@@ -543,6 +559,14 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
+ Promise.all({get length() { throw 666 }}).chain( |
+ assertUnreachable, |
+ function(r) { assertAsync(r === 666, "all/no-array") } |
+ ) |
+ assertAsyncRan() |
+})(); |
+ |
+(function() { |
Promise.all([]).chain( |
function(x) { assertAsync(x.length === 0, "all/resolve/empty") }, |
assertUnreachable |
@@ -551,11 +575,11 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var deferred1 = Promise.deferred() |
+ var deferred1 = Promise.defer() |
var p1 = deferred1.promise |
- var deferred2 = Promise.deferred() |
+ var deferred2 = Promise.defer() |
var p2 = deferred2.promise |
- var deferred3 = Promise.deferred() |
+ var deferred3 = Promise.defer() |
var p3 = deferred3.promise |
Promise.all([p1, p2, p3]).chain( |
function(x) { |
@@ -576,10 +600,10 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var deferred = Promise.deferred() |
+ var deferred = Promise.defer() |
var p1 = deferred.promise |
- var p2 = Promise.resolved(2) |
- var p3 = Promise.deferred().promise |
+ var p2 = Promise.resolve(2) |
+ var p3 = Promise.defer().promise |
Promise.all([p1, p2, p3]).chain( |
assertUnreachable, |
assertUnreachable |
@@ -588,11 +612,11 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var deferred1 = Promise.deferred() |
+ var deferred1 = Promise.defer() |
var p1 = deferred1.promise |
- var deferred2 = Promise.deferred() |
+ var deferred2 = Promise.defer() |
var p2 = deferred2.promise |
- var deferred3 = Promise.deferred() |
+ var deferred3 = Promise.defer() |
var p3 = deferred3.promise |
Promise.all([p1, p2, p3]).chain( |
assertUnreachable, |
@@ -605,42 +629,50 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- Promise.one([]).chain( |
+ Promise.race([]).chain( |
assertUnreachable, |
assertUnreachable |
) |
})(); |
(function() { |
- var p1 = Promise.resolved(1) |
- var p2 = Promise.resolved(2) |
- var p3 = Promise.resolved(3) |
- Promise.one([p1, p2, p3]).chain( |
- function(x) { assertAsync(x === 1, "resolved/all") }, |
+ var p1 = Promise.resolve(1) |
+ var p2 = Promise.resolve(2) |
+ var p3 = Promise.resolve(3) |
+ Promise.race([p1, p2, p3]).chain( |
+ function(x) { assertAsync(x === 1, "resolved/one") }, |
assertUnreachable |
) |
assertAsyncRan() |
})(); |
(function() { |
- var p1 = Promise.resolved(1) |
- var p2 = Promise.resolved(2) |
- var p3 = Promise.resolved(3) |
- Promise.one([0, p1, p2, p3]).chain( |
- function(x) { assertAsync(x === 0, "resolved-const/all") }, |
+ var p1 = Promise.resolve(1) |
+ var p2 = Promise.resolve(2) |
+ var p3 = Promise.resolve(3) |
+ Promise.race([0, p1, p2, p3]).chain( |
+ function(x) { assertAsync(x === 0, "resolved-const/one") }, |
assertUnreachable |
) |
assertAsyncRan() |
})(); |
(function() { |
- var deferred1 = Promise.deferred() |
+ Promise.race({get length() { throw 666 }}).chain( |
+ assertUnreachable, |
+ function(r) { assertAsync(r === 666, "one/no-array") } |
+ ) |
+ assertAsyncRan() |
+})(); |
+ |
+(function() { |
+ var deferred1 = Promise.defer() |
var p1 = deferred1.promise |
- var deferred2 = Promise.deferred() |
+ var deferred2 = Promise.defer() |
var p2 = deferred2.promise |
- var deferred3 = Promise.deferred() |
+ var deferred3 = Promise.defer() |
var p3 = deferred3.promise |
- Promise.one([p1, p2, p3]).chain( |
+ Promise.race([p1, p2, p3]).chain( |
function(x) { assertAsync(x === 3, "one/resolve") }, |
assertUnreachable |
) |
@@ -650,11 +682,11 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var deferred = Promise.deferred() |
+ var deferred = Promise.defer() |
var p1 = deferred.promise |
- var p2 = Promise.resolved(2) |
- var p3 = Promise.deferred().promise |
- Promise.one([p1, p2, p3]).chain( |
+ var p2 = Promise.resolve(2) |
+ var p3 = Promise.defer().promise |
+ Promise.race([p1, p2, p3]).chain( |
function(x) { assertAsync(x === 2, "resolved/one") }, |
assertUnreachable |
) |
@@ -663,13 +695,13 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var deferred1 = Promise.deferred() |
+ var deferred1 = Promise.defer() |
var p1 = deferred1.promise |
- var deferred2 = Promise.deferred() |
+ var deferred2 = Promise.defer() |
var p2 = deferred2.promise |
- var deferred3 = Promise.deferred() |
+ var deferred3 = Promise.defer() |
var p3 = deferred3.promise |
- Promise.one([p1, p2, p3]).chain( |
+ Promise.race([p1, p2, p3]).chain( |
function(x) { assertAsync(x === 3, "one/resolve/reject") }, |
assertUnreachable |
) |
@@ -679,13 +711,13 @@ function assertAsyncDone(iteration) { |
})(); |
(function() { |
- var deferred1 = Promise.deferred() |
+ var deferred1 = Promise.defer() |
var p1 = deferred1.promise |
- var deferred2 = Promise.deferred() |
+ var deferred2 = Promise.defer() |
var p2 = deferred2.promise |
- var deferred3 = Promise.deferred() |
+ var deferred3 = Promise.defer() |
var p3 = deferred3.promise |
- Promise.one([p1, p2, p3]).chain( |
+ Promise.race([p1, p2, p3]).chain( |
assertUnreachable, |
function(x) { assertAsync(x === 3, "one/reject/resolve") } |
) |
@@ -698,56 +730,61 @@ function assertAsyncDone(iteration) { |
var log |
function MyPromise(resolver) { |
log += "n" |
- Promise.call(this, |
- function(resolve, reject) { |
- resolver( |
- function(x) { log += "x" + x; resolve(x) }, |
- function(r) { log += "r" + r; reject(r) } |
- ) |
- } |
- ) |
+ var promise = new Promise(function(resolve, reject) { |
+ resolver( |
+ function(x) { log += "x" + x; resolve(x) }, |
+ function(r) { log += "r" + r; reject(r) } |
+ ) |
+ }) |
+ promise.__proto__ = MyPromise.prototype |
+ return promise |
} |
MyPromise.__proto__ = Promise |
- MyPromise.deferred = function() { |
+ MyPromise.defer = function() { |
log += "d" |
- return this.__proto__.deferred.call(this) |
+ return this.__proto__.defer.call(this) |
} |
MyPromise.prototype.__proto__ = Promise.prototype |
MyPromise.prototype.chain = function(resolve, reject) { |
- log += "w" |
+ log += "c" |
return this.__proto__.__proto__.chain.call(this, resolve, reject) |
} |
log = "" |
var p1 = new MyPromise(function(resolve, reject) { resolve(1) }) |
var p2 = new MyPromise(function(resolve, reject) { reject(2) }) |
- var d3 = MyPromise.deferred() |
- assertTrue(d3.promise instanceof MyPromise, "subclass/instance3") |
+ var d3 = MyPromise.defer() |
+ assertTrue(d3.promise instanceof Promise, "subclass/instance") |
+ assertTrue(d3.promise instanceof MyPromise, "subclass/instance-my3") |
assertTrue(log === "nx1nr2dn", "subclass/create") |
log = "" |
- var p4 = MyPromise.resolved(4) |
- var p5 = MyPromise.rejected(5) |
- assertTrue(p4 instanceof MyPromise, "subclass/instance4") |
- assertTrue(p5 instanceof MyPromise, "subclass/instance5") |
+ var p4 = MyPromise.resolve(4) |
+ var p5 = MyPromise.reject(5) |
+ assertTrue(p4 instanceof Promise, "subclass/instance4") |
+ assertTrue(p4 instanceof MyPromise, "subclass/instance-my4") |
+ assertTrue(p5 instanceof Promise, "subclass/instance5") |
+ assertTrue(p5 instanceof MyPromise, "subclass/instance-my5") |
d3.resolve(3) |
assertTrue(log === "nx4nr5x3", "subclass/resolve") |
log = "" |
- var d6 = MyPromise.deferred() |
- d6.promise.chain(function(x) { return new Promise(x) }).chain(function() {}) |
+ var d6 = MyPromise.defer() |
+ d6.promise.chain(function(x) { |
+ return new Promise(function(resolve) { resolve(x) }) |
+ }).chain(function() {}) |
d6.resolve(6) |
- assertTrue(log === "dnwnwnx6", "subclass/chain") |
+ assertTrue(log === "dncncnx6", "subclass/chain") |
log = "" |
- Promise.all([11, Promise.resolved(12), 13, MyPromise.resolved(14), 15, 16]) |
- assertTrue(log === "nx14wn", "subclass/all/arg") |
+ Promise.all([11, Promise.resolve(12), 13, MyPromise.resolve(14), 15, 16]) |
+ assertTrue(log === "nx14cn", "subclass/all/arg") |
log = "" |
- MyPromise.all([21, Promise.resolved(22), 23, MyPromise.resolved(24), 25, 26]) |
- assertTrue(log === "nx24dnnx21wnnx23wnwnnx25wnnx26wn", "subclass/all/self") |
+ MyPromise.all([21, Promise.resolve(22), 23, MyPromise.resolve(24), 25, 26]) |
+ assertTrue(log === "nx24nnx21cnnx23cncnnx25cnnx26cn", "subclass/all/self") |
})(); |