Index: test/mjsunit/es6/promises.js |
diff --git a/test/mjsunit/es6/promises.js b/test/mjsunit/es6/promises.js |
index 341242f8d9df11c3def63ac6f393f0747bca818a..478f216eb1ca2bea6f38634e3be3385870f0b5fc 100644 |
--- a/test/mjsunit/es6/promises.js |
+++ b/test/mjsunit/es6/promises.js |
@@ -93,13 +93,30 @@ function assertAsync(b, s) { |
--asyncAssertsExpected |
} |
+function assertLater(f, name) { |
+ assertFalse(f()); // should not be true synchronously |
+ ++asyncAssertsExpected; |
+ var iterations = 0; |
+ function runAssertion() { |
+ if (f()) { |
+ print(name, "succeeded"); |
+ --asyncAssertsExpected; |
+ } else if (iterations++ < 10) { |
+ %EnqueueMicrotask(runAssertion); |
+ } else { |
+ %AbortJS(name + " FAILED!"); |
+ } |
+ } |
+ %EnqueueMicrotask(runAssertion); |
+} |
+ |
function assertAsyncDone(iteration) { |
var iteration = iteration || 0; |
%EnqueueMicrotask(function() { |
if (asyncAssertsExpected === 0) |
assertAsync(true, "all") |
else if (iteration > 10) // Shouldn't take more. |
- assertAsync(false, "all") |
+ assertAsync(false, "all... " + asyncAssertsExpected) |
else |
assertAsyncDone(iteration + 1) |
}); |
@@ -216,6 +233,7 @@ function assertAsyncDone(iteration) { |
assertAsyncRan() |
})(); |
+/* TODO(caitp): remove tests once PromiseChain is removed, per bug 3237 |
(function() { |
var p1 = Promise.accept(5) |
var p2 = Promise.accept(p1) |
@@ -225,7 +243,7 @@ function assertAsyncDone(iteration) { |
assertUnreachable |
) |
assertAsyncRan() |
-})(); |
+})();*/ |
(function() { |
var p1 = Promise.accept(5) |
@@ -520,6 +538,7 @@ function assertAsyncDone(iteration) { |
assertAsyncRan() |
})(); |
+/* TODO(caitp): remove tests once PromiseChain is removed, per bug v8:3237 |
(function() { |
var p1 = Promise.accept(5) |
var p2 = Promise.accept(p1) |
@@ -531,7 +550,7 @@ function assertAsyncDone(iteration) { |
) |
deferred.resolve(p2) |
assertAsyncRan() |
-})(); |
+})(); */ |
(function() { |
var p1 = Promise.accept(5) |
@@ -572,6 +591,7 @@ function assertAsyncDone(iteration) { |
assertAsyncRan() |
})(); |
+/* TODO(caitp): remove tests once PromiseChain is removed, per bug v8:3237 |
(function() { |
var p1 = Promise.accept(5) |
var p2 = {then: function(onResolve, onReject) { onResolve(p1) }} |
@@ -583,7 +603,7 @@ function assertAsyncDone(iteration) { |
) |
deferred.resolve(p2) |
assertAsyncRan() |
-})(); |
+})(); */ |
(function() { |
var p1 = Promise.accept(5) |
@@ -618,6 +638,7 @@ function assertAsyncDone(iteration) { |
assertAsyncRan() |
})(); |
+/* TODO(caitp): remove tests once PromiseChain is removed, per bug v8:3237 |
(function() { |
var deferred = Promise.defer() |
var p = deferred.promise |
@@ -627,8 +648,9 @@ function assertAsyncDone(iteration) { |
assertUnreachable |
) |
assertAsyncRan() |
-})(); |
+})();*/ |
+/* TODO(caitp): remove tests once PromiseChain is removed, per bug v8:3237 |
(function() { |
var deferred = Promise.defer() |
var p = deferred.promise |
@@ -638,7 +660,7 @@ function assertAsyncDone(iteration) { |
function(r) { assertAsync(r instanceof TypeError, "cyclic/deferred/then") } |
) |
assertAsyncRan() |
-})(); |
+})();*/ |
(function() { |
Promise.all([]).chain( |
@@ -1059,4 +1081,39 @@ function assertAsyncDone(iteration) { |
"subclass/resolve/descendant with transplanted own constructor"); |
}()); |
+(function() { |
+ var thenCalled = false; |
+ |
+ var resolve; |
+ var promise = new Promise(function(res) { resolve = res; }); |
+ resolve({ then() { thenCalled = true; throw new Error(); } }); |
+ assertLater(function() { return thenCalled; }, "resolve-with-thenable"); |
+}); |
+ |
+(function() { |
+ var calledWith; |
+ |
+ var resolve; |
+ var p1 = (new Promise(function(res) { resolve = res; })); |
+ var p2 = p1.then(function(v) { |
+ return { |
+ then(resolve, reject) { resolve({ then() { calledWith = v }}); } |
+ }; |
+ }); |
+ |
+ resolve({ then(resolve) { resolve(2); } }); |
+ assertLater(function() { return calledWith === 2; }, |
+ "resolve-with-thenable2"); |
+})(); |
+ |
+(function() { |
+ var p = Promise.resolve(); |
+ var callCount = 0; |
+ defineProperty(p, "constructor", { |
+ get: function() { ++callCount; return Promise; } |
+ }); |
+ p.then(); |
+ assertEquals(1, callCount); |
+})(); |
+ |
assertAsyncDone() |