Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: ui/file_manager/video_player/js/error_util.js

Issue 315103004: Video Player: Supports bound arguments of wrap() util function (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * This variable is checked in SelectFileDialogExtensionBrowserTest. 8 * This variable is checked in SelectFileDialogExtensionBrowserTest.
9 * @type {number} 9 * @type {number}
10 */ 10 */
11 window.JSErrorCount = 0; 11 window.JSErrorCount = 0;
12 12
13 /** 13 /**
14 * Counts uncaught exceptions. 14 * Counts uncaught exceptions.
15 */ 15 */
16 window.onerror = function() { window.JSErrorCount++; }; 16 window.onerror = function() { window.JSErrorCount++; };
17 17
18 /** 18 /**
19 * Wraps the function to use it as a callback. 19 * Wraps the function to use it as a callback.
20 * This does: 20 * This does:
21 * - Capture the stack trace in case of error. 21 * - Capture the stack trace in case of error.
22 * - Bind this object 22 * - Bind this object
23 * 23 *
24 * @param {Object} thisObject Object to be used as this. 24 * @param {Object} thisObject Object to be used as this.
25 * @param {...} var_args Arguments to be bound with the wrapped function.
25 * @return {function} Wrapped function. 26 * @return {function} Wrapped function.
26 */ 27 */
27 Function.prototype.wrap = function(thisObject) { 28 Function.prototype.wrap = function(thisObject, var_args) {
28 var func = this; 29 var func = this;
29 var liveStack = (new Error('Stack trace before async call')).stack; 30 var liveStack = (new Error('Stack trace before async call')).stack;
30 if (thisObject === undefined) 31 if (thisObject === undefined)
31 thisObject = null; 32 thisObject = null;
33 var boundArguments = Array.prototype.slice.call(arguments, 1);
32 34
33 return function wrappedCallback() { 35 return function wrappedCallback(var_args) {
hirono 2014/06/05 08:47:42 The name of wrappedCallback is needed?
yoshiki 2014/06/05 14:28:13 It's useful in backtrace.
34 try { 36 try {
35 return func.apply(thisObject, arguments); 37 var args = boundArguments.concat(Array.prototype.slice.call(arguments));
38 return func.apply(thisObject, args);
36 } catch (e) { 39 } catch (e) {
37 console.error('Exception happens in callback.', liveStack); 40 // Some async funcrtion doesn't handle exception correctly. So outputing
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.name + ': ' + e.message, e.stack);
hirono 2014/06/05 08:47:42 e.stack includes e.name and e.message.
yoshiki 2014/06/05 14:28:13 Done.
44 console.info('Exception above happened in callback.', liveStack);
38 45
39 window.JSErrorCount++; 46 window.JSErrorCount++;
40 throw e; 47 throw e;
41 } 48 }
42 } 49 }
43 }; 50 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698