-
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
Checking instanceof Arrays cross frames (needed for the vjs.Player.prototype.src method) #1218
Conversation
instanceof Array, will not work on arrays created cross frames. Array,isArray is the method to check if an object isArray across frames. IE8 does not suppoort the Array.isArray method, so we have to create a shim to support all browsers.
instanceof Array, will not work on arrays created cross frames. Array,isArray is the method to check if an object isArray across frames. IE8 does not suppoort the Array.isArray method, so we have to create a shim to support all browsers.
* @private | ||
*/ | ||
vjs.obj.isArray = Array.isArray || function(arr) { | ||
return Object.prototype.toString.call(arr) === "[object Array]"; |
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.
You need to use single quotes, which is why the build failed on travis.
Other than that, looks good. Are there any other cases of |
Thanks @gkatsev. |
Nope. Just do another commit to the same branch and this PR will pick it up and re-run the build.
Cool. That's fine. |
vjs.Player.prototype.src uses the instanceof Array method. This will not work for arrays created on another frame, Instead of instanceof we should use Array.isArray, but this is not supported on IE8. So vjs.obj.isArray shim was created for the isArray method.
Great stuff! Thanks @shmulik. We do need to add tests to finish this off, but that shouldn't be too difficult for this. The tests would be added to the test/unit/lib.js file. You can follow how some of the other tests are written to get started. I think we would need at least two assertions here.
Would you be up for doing that? |
Good find.
should we just be using |
no, because if source is |
Except that won't work if the source object is a source element.
Either way, if @shmulik doesn't want to take on the object piece for this specific issue we can create a new issue for. |
Yep, that can be done in a different commit. The component piece, might as well be done here as well :D |
Yeah, the |
Sorry for my late response, I am on a different time zone..... |
Using the instanceof Array method will not work for arrays created on another frame, Instead of instanceof we should use Array.isArray, but this is not supported on IE8. So vjs.obj.isArray shim was created for the isArray method.
I will also do the tests for the isArray, but only for arrays created on the same frame. Is this good enough? |
Adding test for the vjs.obj.isArray method
Added test for the vjs.obj.isArray method.
Added test for the vgs.obj.isArray
What do you say about the following code for the Object trick: vjs.obj.isObject = function(obj) { vjs.obj.isSourceObject = function(src) { |
Yeah, same frame is fine. Steve Heffernan (mobile)
|
We need to think a little more on where and how we'd use the object one because I don't think it's the right fit for that specific instance. Steve Heffernan (mobile)
|
Merged in. Thanks! |
vjs.Player.prototype.src uses the instanceof Array method.
This will not work for arrays created on another frame,
Instead of instanceof we should use Array.isArray, but this is not supported on IE8.
So vjs.obj.isArray shim was created for the isArray method.