Index: chrome/browser/resources/sync_internals/chrome_sync.js |
diff --git a/chrome/browser/resources/sync_internals/chrome_sync.js b/chrome/browser/resources/sync_internals/chrome_sync.js |
index c8dbcc676832ae7d6c56c9e3b63fd2f5a834fe55..3e5d21fe797b9e91a109c2cdb1e70ae81312ecdd 100644 |
--- a/chrome/browser/resources/sync_internals/chrome_sync.js |
+++ b/chrome/browser/resources/sync_internals/chrome_sync.js |
@@ -40,14 +40,20 @@ Event.prototype.findListener_ = function(listener) { |
return -1; |
}; |
-// Fires the event. Called by the actual event callback. |
+// Fires the event. Called by the actual event callback. Any |
+// exceptions thrown by a listener are caught and logged. |
Event.prototype.dispatch_ = function() { |
var args = Array.prototype.slice.call(arguments); |
for (var i = 0; i < this.listeners_.length; i++) { |
try { |
this.listeners_[i].apply(null, args); |
} catch (e) { |
- console.error(e); |
+ if (e instanceof Error) { |
+ // Non-standard, but useful. |
+ console.error(e.stack); |
+ } else { |
+ console.error(e); |
+ } |
} |
} |
}; |
@@ -90,12 +96,10 @@ AsyncFunction.prototype.call = function() { |
// Handle a reply, assuming that messages are processed in FIFO order. |
AsyncFunction.prototype.handleReply = function() { |
var args = Array.prototype.slice.call(arguments); |
+ // Remove the callback before we call it since the callback may |
+ // throw. |
var callback = this.callbacks_.shift(); |
- try { |
- callback.apply(null, args); |
- } catch (e) { |
- console.error(e); |
- } |
+ callback.apply(null, args); |
} |
// Sync service functions. |