Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Unified Diff: src/promise.js

Issue 249503002: Trigger debug event on not yet caught exception in promises. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: one more test case. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
}
}

Powered by Google App Engine
This is Rietveld 408576698