From cb3cf93a7a892f42d7823fe4df220d44c8ede710 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 25 Oct 2017 17:46:52 +0800 Subject: [PATCH] console.log fix for JavaScriptCore in iOS 8. --- CCDebugger.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/CCDebugger.js b/CCDebugger.js index 66bbca90b3..b7e4ef1a0e 100644 --- a/CCDebugger.js +++ b/CCDebugger.js @@ -96,8 +96,6 @@ cc.DebugMode = Enum({ * @module cc */ -var jsbLog = cc.log || console.log; - /** * !#en Init Debug setting. * !#zh 设置调试模式。 @@ -259,7 +257,14 @@ cc._initDebugSetting = function (mode) { * @param {any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output. */ if (CC_JSB) { - cc.log = jsbLog; + if (scriptEngineType === "JavaScriptCore") { + // console.log has to use `console` as its context for iOS 8~9. Therefore, apply it. + cc.log = function () { + return console.log.apply(console, arguments); + }; + } else { + cc.log = console.log; + } } else if (console.log.bind) { // use bind to avoid pollute call stacks @@ -283,9 +288,16 @@ cc._initDebugSetting = function (mode) { * @param {any} msg - A JavaScript string containing zero or more substitution strings. * @param {any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output. */ - cc.info = CC_JSB ? jsbLog : function () { - (console.info || console.log).apply(console, arguments); - }; + if (CC_JSB) { + cc.info = (scriptEngineType === "JavaScriptCore") ? function () { + (console.info || console.log).apply(console, arguments); + } : (console.info || console.log); + } else { + cc.info = function () { + (console.info || console.log).apply(console, arguments); + }; + } + } cc.warnID = genLogFunc(cc.warn, 'Warning');