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 * Count uncaught exceptions.
14 window.onerror = function() { window.JSErrorCount++; };
16 // Overrides console.error() to count errors.
18 * @param {...*} var_args Message to be logged.
20 console.error = (function() {
21 var orig = console.error;
23 window.JSErrorCount++;
24 return orig.apply(this, arguments);
28 // Overrides console.assert() to count errors.
30 * @param {boolean} condition If false, log a message and stack trace.
31 * @param {...*} var_args Objects to.
33 console.assert = (function() {
34 var orig = console.assert;
35 return function(condition) {
37 window.JSErrorCount++;
38 return orig.apply(this, arguments);
43 * Wraps the function to use it as a callback.
45 * - Capture the stack trace in case of error.
48 * @param {Object} thisObject Object to be used as this.
49 * @return {Function} Wrapped function.
51 Function.prototype.wrap = function(thisObject) {
53 var liveStack = (new Error('Stack trace before async call')).stack;
54 if (thisObject === undefined)
57 return function wrappedCallback() {
59 return func.apply(thisObject, arguments);
61 console.error('Exception happens in callback.', liveStack);
63 window.JSErrorCount++;