From 15213ec212769837cb2b7e781ffc5bfd598d27ca Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Mon, 19 Mar 2012 11:15:09 -0700 Subject: fix($log): avoid console.log.apply calls in IE In IE window.console.log and friends are functions that don't have apply or call fns. For this reason we have to treat them specially and do our best to log at least something when running in this browser. Closes #805 --- src/service/log.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/service/log.js') diff --git a/src/service/log.js b/src/service/log.js index d338985a..d9d8994d 100644 --- a/src/service/log.js +++ b/src/service/log.js @@ -93,19 +93,23 @@ function $LogProvider(){ } function consoleLog(type) { - var console = $window.console || {}; - var logFn = console[type] || console.log || noop; + var console = $window.console || {}, + logFn = console[type] || console.log || noop; + if (logFn.apply) { return function() { var args = []; - forEach(arguments, function(arg){ + forEach(arguments, function(arg) { args.push(formatError(arg)); }); return logFn.apply(console, args); }; - } else { - // we are IE, in which case there is nothing we can do - return logFn; + } + + // we are IE which either doesn't have window.console => this is noop and we do nothing, + // or we are IE where console.log doesn't have apply so we log at least first 2 args + return function(arg1, arg2) { + logFn(arg1, arg2); } } }]; -- cgit v1.2.3