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.
8 * This variable is checked in SelectFileDialogExtensionBrowserTest.
11 window.JSErrorCount = 0;
14 * Counts uncaught exceptions.
16 window.onerror = function() { window.JSErrorCount++; };
19 * Wraps the function to use it as a callback.
21 * - Capture the stack trace in case of error.
24 * @param {Object} thisObject Object to be used as this.
25 * @param {...} var_args Arguments to be bound with the wrapped function.
26 * @return {function} Wrapped function.
28 Function.prototype.wrap = function(thisObject, var_args) {
30 var liveStack = (new Error('Stack trace before async call')).stack;
31 if (thisObject === undefined)
33 var boundArguments = Array.prototype.slice.call(arguments, 1);
35 return function wrappedCallback(var_args) {
37 var args = boundArguments.concat(Array.prototype.slice.call(arguments));
38 return func.apply(thisObject, args);
40 // Some async function doesn't handle exception correctly. So outputting
41 // the exception message and stack trace just in case.
42 // The message will show twice if the caller handles exception correctly.
43 console.error(e.stack);
44 console.info('Exception above happened in callback.', liveStack);
46 window.JSErrorCount++;