Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed console polyfills/shims #15881

Merged
merged 1 commit into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = {
'clearTimeout': true,
'setInterval': true,
'clearInterval': true,
'console': true,

'Symbol': true,
'WeakMap': true,
Expand Down
48 changes: 8 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() { return console.log(...arguments);}, // eslint-disable-line no-console

/**
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() { return console.warn(...arguments);}, // eslint-disable-line no-console

/**
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() { return console.error(...arguments);}, // eslint-disable-line no-console

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

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

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