-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
webassembly/objpyproxy: Avoid throwing on implicit symbols access. #17683
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
e68d2fd
to
d4503a4
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #17683 +/- ##
=======================================
Coverage 98.44% 98.44%
=======================================
Files 171 171
Lines 22208 22208
=======================================
Hits 21863 21863
Misses 345 345 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
I also thought this might be better, since it matches the JS side, eg: $ node
> {'0':1}[Symbol.toStringTag]
undefined But I guess |
if I change $ node
> ({'0':1}.then)
undefined |
d4503a4
to
7b5e364
Compare
@dpgeorge in latest push we have:
anything else I should change? edit ... well, I could just |
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.
This looks good now, thanks for updating!
|
This commit improves get handling by guarding against implicit unknown symbols accessed directly by specific JS native APIs. Fixes issue micropython#17657. Signed-off-by: Andrea Giammarchi <andrea.giammarchi@gmail.com>
thanks @dpgeorge , any chance this can make it to npm too? |
Yes, I'll do that soon. |
Now published to npmjs: https://www.npmjs.com/package/@micropython/micropython-webassembly-pyscript/v/1.26.0-preview-386 |
Summary
This MR fixes #17657 by guarding against implicit unknown symbols accessed directly by specific JS native APIs.
Testing
Added a new
get
proxy trap focused test that would throw otherwise with current MicroPython whenObject.prototype.toString.call(pyProxy)
happens, returningnull
just like thethen
case would for any symbol that is notSymbol.iterator
.Trade-offs and Alternatives
The
typeof
operator is the fastest check JS offers for primitive types so there are not many side-effects or trafe-offs in here, just better runtime handling of unexpected symbol access that both 3rd party libraries or native JS APIs would regularly perform.The only alternative approach is to return
undefined
which could be returned forthen
case too but neither of these actually matter as boththen
andSymbol.toStringTag
or others are implicit viaReflect
so that returningnull
is still OK, yet if anyone checks strictly againstundefined
that might fail but it's a very edge/uncommon use case to consider, so that changes in here are minimal.