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

Apply window.console instead of console, which is no longer defined #3686

Merged
merged 2 commits into from Oct 18, 2016

Conversation

misteroneill
Copy link
Member

@misteroneill misteroneill commented Oct 14, 2016

Description

This fixes the potential for a completely broken player under the following conditions:

  • IE < 10
  • console is closed, so undefined
  • Call videojs.log or one of its methods

Specific Changes proposed

No longer attempts to apply(console, args) because console is no longer defined as a local variable after e85c1c0 so the browser looks up the scope until it reaches the global scope and, in IE9, because there is no console unless it's open... throws a "console is undefined" error.

Requirements Checklist

  • Feature implemented / Bug fixed
  • Reviewed by Two Core Contributors

@misteroneill misteroneill added patch needs: LGTM Needs an additional approval labels Oct 14, 2016
@forbesjo
Copy link
Contributor

Looks good to me

@gkatsev
Copy link
Member

gkatsev commented Oct 14, 2016

This doesn't seem right to me. The log methods expect to the called on the console object, so, if you apply null there, it's not getting called on console and may not work.

@misteroneill
Copy link
Member Author

You're right. Firefox doesn't like it. I'm gonna go back to what I was doing in my other PR.

// Bail out if there's no console.
if (!fn) {
return;
}
Copy link
Member Author

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.

Copy link
Contributor

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

Copy link
Member Author

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 when console does not exist then hitting line 70 and calling fn.apply(window.console...), which could cause an error (not entirely sure).

@misteroneill misteroneill changed the title Apply null instead of console, which is no longer defined Apply window.console instead of console, which is no longer defined Oct 14, 2016
// Bail out if there's no console.
if (!fn) {
return;
}
Copy link
Contributor

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

@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the implied global console combined with the noop (which had apply()) was causing the problem in the first place.

As to the other change, I think I want to keep this fix pretty minimal. More changes are more opportunities for bugs!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@misteroneill misteroneill added this to the 5.12 milestone Oct 17, 2016
@gkatsev gkatsev merged commit e932061 into videojs:master Oct 18, 2016
@misteroneill misteroneill deleted the fix-log branch October 18, 2016 20:36
@gkatsev gkatsev removed the needs: LGTM Needs an additional approval label Dec 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants