Chromium Code Reviews| Index: src/promise.js |
| diff --git a/src/promise.js b/src/promise.js |
| index 27890a7626b37d12af837e73627617d6a94da4f2..e2209dcd32ae22ec5b2a769aab72725e0df61efe 100644 |
| --- a/src/promise.js |
| +++ b/src/promise.js |
| @@ -182,6 +182,7 @@ function PromiseEnqueue(value, tasks) { |
| %SetMicrotaskPending(true); |
| } |
| + |
|
rossberg
2014/04/24 14:33:47
nit: spurious new line
Yang
2014/04/24 14:44:53
Done.
|
| function PromiseHandle(value, handler, deferred) { |
| try { |
| var result = handler(value); |
| @@ -191,9 +192,29 @@ function PromiseHandle(value, handler, deferred) { |
| %_CallFunction(result, deferred.resolve, deferred.reject, PromiseChain); |
| else |
| deferred.resolve(result); |
| - } catch(e) { |
| - // TODO(rossberg): perhaps log uncaught exceptions below. |
| - try { deferred.reject(e) } catch(e) {} |
| + } catch (exception) { |
| + var uncaught = false; |
| + if (!IS_SPEC_FUNCTION(deferred.reject)) { |
|
rossberg
2014/04/24 14:33:47
Why do you have to test this case? It will throw i
Yang
2014/04/24 14:44:53
Yeah, it will throw, with a TypeError 'undefined i
rossberg
2014/04/24 14:56:51
That may be so, but that's equally true for other
|
| + // There is no reject handler defined in the custom deferred promise. |
| + // Therefore the exception cannot be caught. |
| + uncaught = true; |
| + } else { |
| + 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 { |
| + deferred.reject(exception); |
| + } catch (inner_exception) { |
| + // The reject handler can only throw for a custom deferred promise. |
| + // The resulting exception is considered to be uncaught. |
| + uncaught = true; |
| + exception = inner_exception; |
| + } |
| + } |
| + if (uncaught) %DebugPendingExceptionInPromise(exception, deferred.promise); |
| } |
| } |