Skip to content

Commit e0f6a0d

Browse files
author
Vladimir Enchev
committed
console.dump implemented for ios
1 parent d517c68 commit e0f6a0d

File tree

2 files changed

+15
-28
lines changed

2 files changed

+15
-28
lines changed

console/console.ts

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import definition = require("console");
22
import trace = require("trace");
3+
import platform = require("platform");
34

45
export class Console implements definition.Console {
56
private TAG: string = "JS";
@@ -249,29 +250,6 @@ export class Console implements definition.Console {
249250
if (!test) {
250251
Array.prototype.shift.apply(arguments);
251252
this.error(this.formatParams.apply(this, arguments));
252-
253-
// duplicating trace code here because android version shows only 2 frames and if we call trace()
254-
// this would be assert() and trace() which leaves all important stack frames out of our view
255-
256-
//this._nativeClass.log('=== trace(): JS stack ===')
257-
//if (i.TargetOS.Android == targetOS) {
258-
// var e = <any>new Error('console.trace()');
259-
// this.log(e.stack);
260-
//}
261-
//else if (i.TargetOS.iOS == targetOS) {
262-
// var callstack = [];
263-
// var currentFunction = arguments.callee.caller;
264-
// while (currentFunction) {
265-
// var fn = currentFunction.toString();
266-
// var fname = fn.substring(fn.indexOf('function') + 8, fn.indexOf('{')).trim() || 'anonymous';
267-
// if ('()' === fname) {
268-
// fname = 'anonymous';
269-
// }
270-
// callstack.push(fname);
271-
// currentFunction = currentFunction.caller;
272-
// this.log(callstack.join('\n'));
273-
// }
274-
//}
275253
}
276254
}
277255

@@ -380,7 +358,13 @@ export class Console implements definition.Console {
380358
}
381359

382360
public dump(obj: any): void {
383-
this.log(this.createDump(obj));
361+
var dump = this.createDump(obj);
362+
363+
if (platform.device.os === platform.platformNames.android) {
364+
this.log(dump);
365+
} else if (platform.device.os === platform.platformNames.ios) {
366+
console.log(dump);
367+
}
384368
}
385369

386370
public dir = this.dump;

globals/globals.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ global.moduleMerge = function (sourceExports: any, destExports: any) {
55
destExports[key] = sourceExports[key];
66
}
77
}
8-
8+
import platform = require("platform");
99
import types = require("utils/types");
1010
import timer = require("timer");
1111
import consoleModule = require("console");
@@ -30,9 +30,12 @@ if (typeof global.__decorate !== "function") {
3030
}
3131
};
3232

33-
// Temporary workaround for console in iOS. We will use runtime console instead our implementation.
34-
if (types.isUndefined(global.NSObject)) {
35-
global.console = new consoleModule.Console();
33+
var c = new consoleModule.Console();
34+
35+
if (platform.device.os === platform.platformNames.android) {
36+
global.console = c;
37+
} else if (platform.device.os === platform.platformNames.ios) {
38+
global.console.dump = function (args) { c.dump(args); };
3639
}
3740

3841
global.XMLHttpRequest = xhr.XMLHttpRequest;

0 commit comments

Comments
 (0)