From 46649d72f73898c39abfd8b5c09f87bbb2ab8d92 Mon Sep 17 00:00:00 2001 From: Nilesh Suthar Date: Thu, 19 May 2016 22:42:16 +0530 Subject: [PATCH 1/2] Show line number in console statements --- CCDebugger.js | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/CCDebugger.js b/CCDebugger.js index b52b21367b..ef5f01289c 100644 --- a/CCDebugger.js +++ b/CCDebugger.js @@ -312,24 +312,12 @@ cc._initDebugSetting = function (mode) { } else if(console && console.log.apply){//console is null when user doesn't open dev tool on IE9 //log to console - cc.error = function(){ - return console.error.apply(console, arguments); - }; - cc.assert = function (cond, msg) { - if (!cond && msg) { - for (var i = 2; i < arguments.length; i++) - msg = msg.replace(/(%s)|(%d)/, cc._formatString(arguments[i])); - throw new Error(msg); - } - }; - if(mode !== ccGame.DEBUG_MODE_ERROR) - cc.warn = function(){ - return console.warn.apply(console, arguments); - }; - if(mode === ccGame.DEBUG_MODE_INFO) - cc.log = function(){ - return console.log.apply(console, arguments); - }; + cc.error = Function.prototype.bind.call(console.error, console); + cc.assert = Function.prototype.bind.call(console.assert, console); + if (mode !== ccGame.DEBUG_MODE_ERROR) + cc.warn = Function.prototype.bind.call(console.warn, console); + if (mode === ccGame.DEBUG_MODE_INFO) + cc.log = Function.prototype.bind.call(console.log, console); } }; -//+++++++++++++++++++++++++something about log end+++++++++++++++++++++++++++++ \ No newline at end of file +//+++++++++++++++++++++++++something about log end+++++++++++++++++++++++++++++ From 6f421d28d1d836e822f143ba0a6dd3c0beb111a2 Mon Sep 17 00:00:00 2001 From: Nilesh Suthar Date: Thu, 26 May 2016 17:56:50 +0530 Subject: [PATCH 2/2] handle missing console assert --- CCDebugger.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CCDebugger.js b/CCDebugger.js index ef5f01289c..da0b8e28d3 100644 --- a/CCDebugger.js +++ b/CCDebugger.js @@ -313,7 +313,18 @@ cc._initDebugSetting = function (mode) { //log to console cc.error = Function.prototype.bind.call(console.error, console); - cc.assert = Function.prototype.bind.call(console.assert, console); + //If console.assert is not support user throw Error msg on wrong condition + if (console.assert) { + cc.assert = Function.prototype.bind.call(console.assert, console); + } else { + cc.assert = function (cond, msg) { + if (!cond && msg) { + for (var i = 2; i < arguments.length; i++) + msg = msg.replace(/(%s)|(%d)/, cc._formatString(arguments[i])); + throw new Error(msg); + } + }; + } if (mode !== ccGame.DEBUG_MODE_ERROR) cc.warn = Function.prototype.bind.call(console.warn, console); if (mode === ccGame.DEBUG_MODE_INFO)