Skip to content

Commit

Permalink
Removed console polyfills/shims
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sauer committed Nov 29, 2017
1 parent 78e0b66 commit a85fcb2
Showing 1 changed file with 6 additions and 40 deletions.
46 changes: 6 additions & 40 deletions packages/ember-console/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,3 @@
import { context } from 'ember-environment';

function K() {}

function consoleMethod(name) {
let consoleObj;
if (context.imports.console) {
consoleObj = context.imports.console;
} else if (typeof console !== 'undefined') { // eslint-disable-line no-undef
consoleObj = console; // eslint-disable-line no-undef
}

let method = typeof consoleObj === 'object' ? consoleObj[name] : null;

if (typeof method !== 'function') {
return;
}

return method.bind(consoleObj);
}

function assertPolyfill(test, message) {
if (!test) {
try {
// attempt to preserve the stack
throw new Error(`assertion failed: ${message}`);
} catch (error) {
setTimeout(() => {
throw error;
}, 0);
}
}
}

/**
Inside Ember-Metal, simply uses the methods from `imports.console`.
Override this to provide more robust logging functionality.
Expand All @@ -56,7 +22,7 @@ export default {
@param {*} arguments
@public
*/
log: consoleMethod('log') || K,
log: console.log, // eslint-disable-line no-console, no-undef

/**
Prints the arguments to the console with a warning icon.
Expand All @@ -72,7 +38,7 @@ export default {
@param {*} arguments
@public
*/
warn: consoleMethod('warn') || K,
warn: console.warn, // eslint-disable-line no-console, no-undef

/**
Prints the arguments to the console with an error icon, red text and a stack trace.
Expand All @@ -88,7 +54,7 @@ export default {
@param {*} arguments
@public
*/
error: consoleMethod('error') || K,
error: console.error, // eslint-disable-line no-console, no-undef

/**
Logs the arguments to the console.
Expand All @@ -105,7 +71,7 @@ export default {
@param {*} arguments
@public
*/
info: consoleMethod('info') || K,
info: console.info, // eslint-disable-line no-console, no-undef

/**
Logs the arguments to the console in blue text.
Expand All @@ -122,7 +88,7 @@ export default {
@param {*} arguments
@public
*/
debug: consoleMethod('debug') || consoleMethod('info') || K,
debug: console.debug || console.info, // eslint-disable-line no-console, no-undef

/**
If the value passed into `Ember.Logger.assert` is not truthy it will throw an error with a stack trace.
Expand All @@ -139,5 +105,5 @@ export default {
@param {String} message Assertion message on failed
@public
*/
assert: consoleMethod('assert') || assertPolyfill
assert: console.assert // eslint-disable-line no-console, no-undef
};

0 comments on commit a85fcb2

Please sign in to comment.