webassembly/objpyproxy: Avoid throwing on implicit symbols access.#17683
webassembly/objpyproxy: Avoid throwing on implicit symbols access.#17683dpgeorge merged 1 commit intomicropython:masterfrom
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]
undefinedBut 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 |
dpgeorge
left a comment
There was a problem hiding this comment.
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 <[email protected]>
|
thanks @dpgeorge , any chance this can make it to npm too? |
Yes, I'll do that soon. |
Summary
This MR fixes #17657 by guarding against implicit unknown symbols accessed directly by specific JS native APIs.
Testing
Added a new
getproxy trap focused test that would throw otherwise with current MicroPython whenObject.prototype.toString.call(pyProxy)happens, returningnulljust like thethencase would for any symbol that is notSymbol.iterator.Trade-offs and Alternatives
The
typeofoperator 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
undefinedwhich could be returned forthencase too but neither of these actually matter as boththenandSymbol.toStringTagor others are implicit viaReflectso that returningnullis still OK, yet if anyone checks strictly againstundefinedthat might fail but it's a very edge/uncommon use case to consider, so that changes in here are minimal.