Index: src/promise.js |
diff --git a/src/promise.js b/src/promise.js |
index 3c8ac676540a2a3e5a3ffe87b78fb91fbbe2040d..60c836c9e6de63c087a318a45dfb181c19e7d217 100644 |
--- a/src/promise.js |
+++ b/src/promise.js |
@@ -35,13 +35,10 @@ function Promise(resolver) { |
throw MakeTypeError('resolver_not_a_function', [resolver]); |
var promise = PromiseInit(this); |
try { |
- %DebugPromiseHandlePrologue(function() { return promise }); |
resolver(function(x) { PromiseResolve(promise, x) }, |
function(r) { PromiseReject(promise, r) }); |
} catch (e) { |
PromiseReject(promise, e); |
- } finally { |
- %DebugPromiseHandleEpilogue(); |
} |
} |
@@ -164,11 +161,6 @@ function PromiseEnqueue(value, tasks) { |
function PromiseHandle(value, handler, deferred) { |
try { |
- %DebugPromiseHandlePrologue( |
- function() { |
- var queue = GET_PRIVATE(deferred.promise, promiseOnReject); |
- return (queue && queue.length == 0) ? deferred.promise : UNDEFINED; |
- }); |
var result = handler(value); |
if (result === deferred.promise) |
throw MakeTypeError('promise_cyclic', [result]); |
@@ -177,13 +169,21 @@ function PromiseHandle(value, handler, deferred) { |
else |
deferred.resolve(result); |
} catch (exception) { |
+ var uncaught = false; |
+ var reject_queue = GET_PRIVATE(deferred.promise, promiseOnReject); |
+ if (reject_queue && reject_queue.length == 0) { |
+ // The deferred promise may get a reject handler attached later. |
+ // For now, we consider the exception to be (for the moment) uncaught. |
+ uncaught = true; |
+ } |
try { |
- %DebugPromiseHandleEpilogue(); // Match the previous prologue. |
- %DebugPromiseHandlePrologue(function() { return deferred.promise }); |
deferred.reject(exception); |
- } catch (e) { } |
- } finally { |
- %DebugPromiseHandleEpilogue(); |
+ } catch (e) { |
+ // The reject handler can only throw for a custom deferred promise. |
+ // We consider the original exception to be uncaught. |
+ uncaught = true; |
+ } |
+ if (uncaught) %DebugPendingExceptionInPromise(exception, deferred.promise); |
} |
} |
@@ -321,6 +321,14 @@ function GetPromiseStatus(promise) { |
return GET_PRIVATE(promise, promiseStatus); |
} |
+function GetPromiseOnResolve(promise) { |
+ return GET_PRIVATE(promise, promiseOnResolve); |
+} |
+ |
+function GetPromiseOnReject(promise) { |
+ return GET_PRIVATE(promise, promiseOnReject); |
+} |
+ |
function GetPromiseValue(promise) { |
return GET_PRIVATE(promise, promiseValue); |
} |