Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
|
hirono
2014/03/26 02:55:05
nit: 2014
yoshiki
2014/03/26 04:55:52
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 'use strict'; | |
| 6 | |
| 7 /** | |
| 8 * This variable is checked in SelectFileDialogExtensionBrowserTest. | |
| 9 * @type {number} | |
| 10 */ | |
| 11 window.JSErrorCount = 0; | |
| 12 | |
| 13 /** | |
| 14 * Count uncaught exceptions. | |
| 15 */ | |
| 16 window.onerror = function() { window.JSErrorCount++; }; | |
| 17 | |
| 18 /** | |
| 19 * Wrap the function to use it as a callback. | |
|
hirono
2014/03/26 02:55:05
nit: Wraps
yoshiki
2014/03/26 04:55:52
Done.
| |
| 20 * This does: | |
| 21 * - Capture the stack trace in case of error. | |
| 22 * - Bind this object | |
| 23 * | |
| 24 * @param {Object} thisObject Object to be used as this. | |
| 25 * @return {function} Wapped function. | |
| 26 */ | |
| 27 Function.prototype.wrap = function(thisObject) { | |
|
hirono
2014/03/26 02:55:05
Strictly our design guide forbid us to modify prot
yoshiki
2014/03/26 04:55:52
Not "strictly". The guide says "Modifying other bu
hirono
2014/03/26 08:18:31
SGTM.
mtomasz
2014/04/01 19:37:50
Out of curiosity. Why don't we put this code to #1
| |
| 28 var func = this; | |
| 29 var liveStack = (new Error('Stack trace before async call')).stack; | |
| 30 if (thisObject === undefined) | |
| 31 thisObject = null; | |
| 32 | |
| 33 return function wrappedCallback() { | |
| 34 try { | |
| 35 return func.apply(thisObject, arguments); | |
| 36 } catch (e) { | |
| 37 console.error('Exception is happen in callback.', liveStack); | |
|
hirono
2014/03/26 02:55:05
The e.stack is also useful information. Could you
hirono
2014/03/26 02:55:05
nit: Exception happens or Exception is thrown?
yoshiki
2014/03/26 04:55:52
Done.
yoshiki
2014/03/26 04:55:52
The original exception e will be caught by the han
| |
| 38 | |
| 39 window.JSErrorCount++; | |
|
mtomasz
2014/04/01 19:37:50
Aren't we incrementing JSErrorCount twice? #16 and
| |
| 40 throw e; | |
| 41 } | |
| 42 } | |
| 43 }; | |
| OLD | NEW |