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

Fix exceptions in IE #1786

Merged
merged 9 commits into from
Jun 16, 2018
Merged

Fix exceptions in IE #1786

merged 9 commits into from
Jun 16, 2018

Conversation

johnBartos
Copy link
Collaborator

This PR will...

  • Revert the Array.from changes
  • Avoid throwing an avoidable exception accessing crypto
  • Avoid reassigning window

Why is this Pull Request needed?

  1. The Array.from changes cause IE to fail with an unhandled exception:
2018-06-15 16:29:53.019: "hlsjs fatal error :internalException"
2018-06-15 16:29:53.020: "exception in :demuxerWorker"
2018-06-15 16:29:53.020: "Function.prototype.call: 'this' is not a Function object (blob:D44328A0-4D47-40C3-9929-A44E11920A9B:1)"

These changes are not valuable so they have been reverted.

  1. Makes it a bit easier to debug when the all exceptions flag does not get triggered due to a caught exception.

  2. It is a bad practice to reassign globals.

Are there any points in the code the reviewer needs to double check?

I don't think so. I did a spot check on IE/Edge/Chrome/FF and everything looks fine.

Resolves issues:

Reported via video-dev slack

Checklist

  • changes have been done against master branch, and PR does not conflict
  • no commits have been done in dist folder (we will take care of updating it)
  • new unit / functional tests have been added (whenever applicable)
  • API or design changes are documented in API.md

@johnBartos johnBartos added the Bug label Jun 15, 2018
@johnBartos johnBartos added this to the 0.10.1 milestone Jun 15, 2018
@tjenkinson
Copy link
Member

#1769 could work in place of some of these commits. Understand if we'd rather hold that back for now though and get a new version out

@johnBartos
Copy link
Collaborator Author

@tjenkinson Would like to take a closer look at that one. I think we need to get this in & cut a release asap

@@ -3,7 +3,6 @@
*/

// import Hex from '../utils/hex';
Copy link
Collaborator

Choose a reason for hiding this comment

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

if this import isn't needed we should remove it

sps = sps.concat(makeArrayFromArrayLike(data)); // SPS

// SPS
if (typeof Array.from === 'function') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure what is broken in there, but: why don't you fix the util function (makeArrayFromArrayLike)?

the way you did it here, we will have more code-size if this functionnality is needed somewhere else.

Copy link
Collaborator

Choose a reason for hiding this comment

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

update: see my proposed fix further down

const window = getSelfScope(); // safeguard for code that might run both on worker and main thread

const { performance, crypto } = window;
const global = getSelfScope(); // safeguard for code that might run both on worker and main thread
Copy link
Collaborator

Choose a reason for hiding this comment

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

if this is a problem on IE11, can we add a linter setting that forbids the variable name window? it would be the way to avoid regression in this case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

or this is what no-global-assign does?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah no-global-assign does that

.eslintrc.js Outdated
@@ -83,6 +83,7 @@ module.exports = {
'no-irregular-whitespace': 1,
'no-self-assign': 1,
'new-cap': 1,
'no-undefined': 1
'no-undefined': 1,
'no-global-assign': 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

if this is a critical issue, you shouldn't make it a warning, but an error (2).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah thanks. Will address

@@ -344,7 +349,12 @@ class MP4 {
len = data.byteLength;
pps.push((len >>> 8) & 0xFF);
pps.push((len & 0xFF));
pps = pps.concat(makeArrayFromArrayLike(data));

if (typeof Array.from === 'function') {
Copy link
Collaborator

@tchakabam tchakabam Jun 15, 2018

Choose a reason for hiding this comment

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

like this is actually redundant code really growing the package, isn't it?

it seems more intuitive to rather fix the issue here: https://github.com/video-dev/hls.js/blob/master/src/utils/make-array-from-array-like.js#L1

if the current state doesn't work...I guess you need to change it to something like:

export function makeArrayFromArrayLike(arrayLike) { 
  return (typeof Array.from === 'function' ? Array.from(arrayLike) : Array.prototype.slice.call(arrayLike));
}

and you can use it without changes the exact same way.

IE11 seems to have a bug in exporting native prototype members :)

@tchakabam
Copy link
Collaborator

tchakabam commented Jun 15, 2018

@tjenkinson let's first get this fixed based on the status quo, and after that merge your PR asap.

@@ -3,7 +3,6 @@
*/

// import Hex from '../utils/hex';
import { makeArrayFromArrayLike } from '../utils/make-array-from-array-like';
Copy link
Collaborator

@tchakabam tchakabam Jun 15, 2018

Choose a reason for hiding this comment

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

if you wanted to remove it, we should have deleted the module as well. but imo we should definitely keep it.

@tchakabam
Copy link
Collaborator

@johnBartos it seems you fixed this without completely understanding what the issue was :) i hope my suggestion may help!

@johnBartos
Copy link
Collaborator Author

@tchakabam Ah looks like I reverted the wrong commit. Will fix

@johnBartos
Copy link
Collaborator Author

@tchakabam Fixed. That's what I get for rushing 😅

@tchakabam
Copy link
Collaborator

@johnBartos Awesome work!

Also I need to admit that I found out: This util function was a wrong thing to do in the first place the way it was done. One can't export a call function in general 8| this is something for exampleFirefox also doesn't get right. We could have done it right by setting the Array.from property globally to something implemented by slice where its not defined, as in a proper polyfill.

Sorry, my bad :/

@tchakabam
Copy link
Collaborator

tchakabam commented Jun 15, 2018

or something like this would have worked: export const makeArrayFromArrayLike = typeof Array.from === 'function' ? Array.from : ((arrayLike) => Array.prototype.slice.call(arrayLike));

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.

3 participants