From e0f6a0d3c6a4ddab2b77b6ab59c817648dcfdb60 Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Wed, 23 Sep 2015 11:26:27 +0300 Subject: [PATCH] console.dump implemented for ios --- console/console.ts | 32 ++++++++------------------------ globals/globals.ts | 11 +++++++---- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/console/console.ts b/console/console.ts index b6aaab996..49833fd7c 100644 --- a/console/console.ts +++ b/console/console.ts @@ -1,5 +1,6 @@ import definition = require("console"); import trace = require("trace"); +import platform = require("platform"); export class Console implements definition.Console { private TAG: string = "JS"; @@ -249,29 +250,6 @@ export class Console implements definition.Console { if (!test) { Array.prototype.shift.apply(arguments); this.error(this.formatParams.apply(this, arguments)); - - // duplicating trace code here because android version shows only 2 frames and if we call trace() - // this would be assert() and trace() which leaves all important stack frames out of our view - - //this._nativeClass.log('=== trace(): JS stack ===') - //if (i.TargetOS.Android == targetOS) { - // var e = new Error('console.trace()'); - // this.log(e.stack); - //} - //else if (i.TargetOS.iOS == targetOS) { - // var callstack = []; - // var currentFunction = arguments.callee.caller; - // while (currentFunction) { - // var fn = currentFunction.toString(); - // var fname = fn.substring(fn.indexOf('function') + 8, fn.indexOf('{')).trim() || 'anonymous'; - // if ('()' === fname) { - // fname = 'anonymous'; - // } - // callstack.push(fname); - // currentFunction = currentFunction.caller; - // this.log(callstack.join('\n')); - // } - //} } } @@ -380,7 +358,13 @@ export class Console implements definition.Console { } public dump(obj: any): void { - this.log(this.createDump(obj)); + var dump = this.createDump(obj); + + if (platform.device.os === platform.platformNames.android) { + this.log(dump); + } else if (platform.device.os === platform.platformNames.ios) { + console.log(dump); + } } public dir = this.dump; diff --git a/globals/globals.ts b/globals/globals.ts index e7ef7b9a9..96d926d16 100644 --- a/globals/globals.ts +++ b/globals/globals.ts @@ -5,7 +5,7 @@ global.moduleMerge = function (sourceExports: any, destExports: any) { destExports[key] = sourceExports[key]; } } - +import platform = require("platform"); import types = require("utils/types"); import timer = require("timer"); import consoleModule = require("console"); @@ -30,9 +30,12 @@ if (typeof global.__decorate !== "function") { } }; -// Temporary workaround for console in iOS. We will use runtime console instead our implementation. -if (types.isUndefined(global.NSObject)) { - global.console = new consoleModule.Console(); +var c = new consoleModule.Console(); + +if (platform.device.os === platform.platformNames.android) { + global.console = c; +} else if (platform.device.os === platform.platformNames.ios) { + global.console.dump = function (args) { c.dump(args); }; } global.XMLHttpRequest = xhr.XMLHttpRequest;