1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 * This variable is checked in SelectFileDialogExtensionBrowserTest.
9 window.JSErrorCount = 0;
12 * Counts uncaught exceptions.
14 window.onerror = function() { window.JSErrorCount++; };
17 * Wraps the function to use it as a callback.
19 * - Capture the stack trace in case of error.
22 * @param {Object=} opt_thisObject Object to be used as this.
23 * @param {...} var_args Arguments to be bound with the wrapped function.
24 * @return {function(...)} Wrapped function.
26 Function.prototype.wrap = function(opt_thisObject, var_args) {
28 var liveStack = (new Error('Stack trace before async call')).stack;
29 var thisObject = opt_thisObject || null;
30 var boundArguments = Array.prototype.slice.call(arguments, 1);
32 return function wrappedCallback(var_args) {
34 var args = boundArguments.concat(Array.prototype.slice.call(arguments));
35 return func.apply(thisObject, args);
37 // Some async function doesn't handle exception correctly. So outputting
38 // the exception message and stack trace just in case.
39 // The message will show twice if the caller handles exception correctly.
40 console.error(e.stack);
41 console.info('Exception above happened in callback.', liveStack);
43 window.JSErrorCount++;