Skip to content

Commit 6f421d2

Browse files
committed
handle missing console assert
1 parent 46649d7 commit 6f421d2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

CCDebugger.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,18 @@ cc._initDebugSetting = function (mode) {
313313
//log to console
314314

315315
cc.error = Function.prototype.bind.call(console.error, console);
316-
cc.assert = Function.prototype.bind.call(console.assert, console);
316+
//If console.assert is not support user throw Error msg on wrong condition
317+
if (console.assert) {
318+
cc.assert = Function.prototype.bind.call(console.assert, console);
319+
} else {
320+
cc.assert = function (cond, msg) {
321+
if (!cond && msg) {
322+
for (var i = 2; i < arguments.length; i++)
323+
msg = msg.replace(/(%s)|(%d)/, cc._formatString(arguments[i]));
324+
throw new Error(msg);
325+
}
326+
};
327+
}
317328
if (mode !== ccGame.DEBUG_MODE_ERROR)
318329
cc.warn = Function.prototype.bind.call(console.warn, console);
319330
if (mode === ccGame.DEBUG_MODE_INFO)

0 commit comments

Comments
 (0)