From 6db2334a31e5d36f30e2dbda47bfaa2162f279bf Mon Sep 17 00:00:00 2001 From: doktordirk Date: Wed, 18 May 2016 18:31:48 +0200 Subject: [PATCH] feat(console): moved console fix from logging-console to polyfills --- build/tasks/build.js | 3 ++- src/console.js | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/console.js diff --git a/build/tasks/build.js b/build/tasks/build.js index bef7739..f933cae 100644 --- a/build/tasks/build.js +++ b/build/tasks/build.js @@ -21,7 +21,8 @@ gulp.task('build-index', function(){ 'array.js', 'object.js', 'collections.js', - 'reflect.js' + 'reflect.js', + 'console.js' ].map(function(file){ return paths.root + file; }); diff --git a/src/console.js b/src/console.js new file mode 100644 index 0000000..db0f1be --- /dev/null +++ b/src/console.js @@ -0,0 +1,22 @@ +import {PLATFORM} from 'aurelia-pal'; + +(function(global) { + global.console = global.console || {}; + let con = global.console; + let prop; + let method; + let empty = {}; + let dummy = function() {}; + let properties = 'memory'.split(','); + let methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' + + 'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' + + 'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(','); + while (prop = properties.pop()) if (!con[prop]) con[prop] = empty; + while (method = methods.pop()) if (!con[method]) con[method] = dummy; +})(PLATFORM.global); + +if (PLATFORM.global.console && typeof console.log === 'object') { + ['log', 'info', 'warn', 'error', 'assert', 'dir', 'clear', 'profile', 'profileEnd'].forEach(function(method) { + console[method] = this.bind(console[method], console); + }, Function.prototype.call); +}