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

For .. in loops not protected from iterating prototype properties #209

Closed
xoundboy opened this issue Mar 24, 2021 · 14 comments · Fixed by #211
Closed

For .. in loops not protected from iterating prototype properties #209

xoundboy opened this issue Mar 24, 2021 · 14 comments · Fixed by #211
Milestone

Comments

@xoundboy
Copy link

xoundboy commented Mar 24, 2021

I've been testing the library on Samsung and WebOS tvs and discovered that on one 2020 Samsung device execution breaks inside several of the for.. in loops conained in this library due to native prototype properties being iterated as regular array members. I don't know yet exactly why the problem only appears on this TV, however I was easily able to fix it using the hasOwnProperty check. I'm wondering whether I can submit a PR for this change to be merged to master? I have it ready to push. There are quite a few places the check is needed.

@palemieux
Copy link
Contributor

palemieux commented Mar 25, 2021

Is it on all for...in loops, including those over arrays?

Would replacing for...in with for (var i = 0; i < a.length; i++) solve the issue?

@xoundboy
Copy link
Author

Yes it seems to be all for...in loops, including arrays, although I didn't test every instance of for...in in the whole library.

replacing for...in with for (var i = 0; i < a.length; i++) should solve the issue. I'll check today and leave an update later. Thanks

@nigelmegitt
Copy link
Contributor

We've noticed something similar and have a pull request on our BBC fork at bbc#9 to address this issue, which may help.

It's also worth noting that replacing the for ... in loops with indexed-based array iterators should provide a performance improvement too: I haven't got any profiling results that demonstrate this for our real world content, unfortunately.

@xoundboy
Copy link
Author

I was thinking the very same thing about potentially improving performance by avoiding any hasOwnProperty checks which I believe slow things down, although I don't have any data to prove that either, just a hunch :-) Anyway, thanks for your comment. Good to know it's not just me that has this problem. Maybe it would make sense to fix this upstream and then rebase the changes into your fork @nigelmegitt

@nigelmegitt
Copy link
Contributor

@xoundboy yes, for sure where we have improvements it's our intention to push them upstream (or fetch them from upstream if others have already done the same) to minimise the deltas between our fork and the main repo. We have some divergence that's required for us to deal with specifics of our environment.

@nigelmegitt
Copy link
Contributor

potentially improving performance by avoiding any hasOwnProperty

Just for clarity, the performance improvements don't come from this, but from changing to indexed based array iterator for loops rather than for ... in.

I don't know a way to avoid using hasOwnProperty.

@palemieux
Copy link
Contributor

replacing for...in with for (var i = 0; i < a.length; i++) should solve the issue. I'll check today and leave an update later. Thanks

Great. Looking forward to it.

@xoundboy
Copy link
Author

@palemieux I verified that for (var i = 0; i < a.length; i++) solves the problem. Please go ahead and replace the for...in loops, or let me know if you would like me to prepare a PR. Thank you.

@palemieux
Copy link
Contributor

let me know if you would like me to prepare a PR.

That would be great!

@xoundboy
Copy link
Author

OK, I've got a branch ready called issues/0209-guard-against-native-prototype-property-iteration (trying to copy your branch naming scheme). Please grant me access to push to the repo. Thanks. @palemieux

@palemieux
Copy link
Contributor

palemieux commented Mar 26, 2021

Please grant me access to push to the repo. Thanks.

Even better, any chance you might be able to create the branch on a fork of the repo in your github account?

This is the intended Github workflow AFAIK.

@xoundboy
Copy link
Author

@palemieux This is the first time I'm making a PR in Github using this workflow. Thanks for the guidance. Here's the PR: #210 - it includes some whitespace changes which I didn't notice until too late. Let me know if you need me to revert those.

@palemieux
Copy link
Contributor

This is the first time I'm making a PR in Github using this workflow.

Super! Thanks.

Let me know if you need me to revert those.

Not fatal... just distracting. How difficult is it to revert them?

@xoundboy
Copy link
Author

It's a real pain to revert them. I'd really prefer not to if possible :)

palemieux added a commit that referenced this issue Sep 13, 2021
Co-authored-by: Ben Roberts <ben.roberts.extern@joyn.de>
@palemieux palemieux added this to the 1.1.3 Release milestone Sep 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants