diff --git a/bridge/polyfill/src/console.ts b/bridge/polyfill/src/console.ts index 3af936f989..db09b29b3d 100644 --- a/bridge/polyfill/src/console.ts +++ b/bridge/polyfill/src/console.ts @@ -55,6 +55,13 @@ function formatter(obj: any, limit: number, stack: Array): string { var kind = Object.prototype.toString.call(obj).slice(8, -1); if (kind == 'Object') { prefix = ''; + } else if (kind == 'Array') { + var itemList: any[] = obj.map((item: any) => formatter(item, limit - 1, stack)); + return '[' + itemList.join(', ') + ']'; + } else if (kind == 'Set') { + var itemList: any[] = []; + obj.forEach((item: any) =>itemList.push(formatter(item, limit - 1, stack))); + return 'Set {' + itemList.join(', ') + '}'; } else { prefix = kind + ' '; var primitive; @@ -86,6 +93,10 @@ function formatter(obj: any, limit: number, stack: Array): string { var indent = INDENT.repeat(stackLength); var keys = Object.getOwnPropertyNames(obj); + if (obj instanceof Map) { + keys = Object.keys(obj); + } + var result = prefix + '{'; if (!keys.length) { return result + '}'; @@ -206,6 +217,13 @@ export const console = { log(...args: any) { printer(logger(arguments)); }, + inspect(...args: any) { + var result = []; + for (var i = 0; i < arguments.length; i++) { + result.push(formatter(arguments[i], Number.MAX_VALUE, [])); + } + printer(result.join(SEPARATOR)); + }, info(...args: any) { printer(logger(arguments), 'info'); },