-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix findMatchingCatch iterating over argument array prototype chain #21986
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
Conversation
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.
I don't have a good idea for a specific test here - seems like that would require messing around with the prototype chain? But this is shorter and obviously correct, and covered by existing tests for regressions at least, lgtm.
I think this warrants a little more investigation. The only callers of this function are the native |
Of course the change itself looks fine.. I just don't understand how you ran into needing this |
I have a suspicion - give me a few minutes to investigate |
Yeah I figured it out. In an old inherited portion of our codebase, custom properties are added to This is a problem we should be able to solve ourselves by marking them non-enumerable. However, this change would make the code more robust to poor userland behavior ( 🥲 ) - and is arguably more readable/conventional and saves a few bytes. Not sure if there is a reason why the previous implementation decided to iterate over keys instead of values when only values are used. |
Ah yes, that makes sense. It requires some external monkey patching to mess with all array objects. Thanks for clarifying.
The reason for this is that until recently emscripten did not allow |
A bug was introduced in #19760 where when iterating over the arguments passed to findMatchingCatch, it iterates not just over the elements in the array, but all properties in the Array prototype chain (due to the semantics of for..in vs for..of). This can cause exception handling to segfault in ___cxa_can_catch, as it is not being passed a valid pointer in the case of iterating over something like a utility function added to the array prototype without marking it as enumerable.
I discovered this when debugging onnxruntime and discovering that their custom errors (which inherit from
std::exception
) were causing segfaults during exception handling (whereas changing tostd::logic_error
would work fine), and have confirmed this fix resolves that issue. However, I could use guidance on adding a test for this change.