-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Apply window.console instead of console, which is no longer defined #3686
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,14 +19,6 @@ let log; | |
*/ | ||
export const logByType = (type, args, stringify = !!IE_VERSION && IE_VERSION < 11) => { | ||
|
||
// If there's no console then don't try to output messages, but they will | ||
// still be stored in `log.history`. | ||
// | ||
// Was setting these once outside of this function, but containing them | ||
// in the function makes it easier to test cases where console doesn't exist | ||
// when the module is executed. | ||
const fn = window.console && window.console[type] || function() {}; | ||
|
||
if (type !== 'log') { | ||
|
||
// add the type to the front of the message when it's not "log" | ||
|
@@ -39,6 +31,19 @@ export const logByType = (type, args, stringify = !!IE_VERSION && IE_VERSION < 1 | |
// add console prefix after adding to history | ||
args.unshift('VIDEOJS:'); | ||
|
||
// If there's no console then don't try to output messages, but they will | ||
// still be stored in `log.history`. | ||
// | ||
// Was setting these once outside of this function, but containing them | ||
// in the function makes it easier to test cases where console doesn't exist | ||
// when the module is executed. | ||
const fn = window.console && window.console[type]; | ||
|
||
// Bail out if there's no console. | ||
if (!fn) { | ||
return; | ||
} | ||
|
||
// IEs previous to 11 log objects uselessly as "[object Object]"; so, JSONify | ||
// objects and arrays for those less-capable browsers. | ||
if (stringify) { | ||
|
@@ -62,7 +67,7 @@ export const logByType = (type, args, stringify = !!IE_VERSION && IE_VERSION < 1 | |
if (!fn.apply) { | ||
fn(args); | ||
} else { | ||
fn[Array.isArray(args) ? 'apply' : 'call'](console, args); | ||
fn[Array.isArray(args) ? 'apply' : 'call'](window.console, args); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume using global console caused issues as well? and what about just calling apply and making args an array be default? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the implied global As to the other change, I think I want to keep this fix pretty minimal. More changes are more opportunities for bugs! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
} | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, we've already stored the arguments in history; so, we can safely bail out if there's nothing to do. This is cheaper than potentially running
JSON.stringify
and calling a no-op.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds like a better idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also has the benefit of avoiding the previous potentiality of having a no-op assigned to
fn
whenconsole
does not exist then hitting line 70 and callingfn.apply(window.console...)
, which could cause an error (not entirely sure).