feat: Create ObjectUtils for Object.freeze, Object.defineProperty, ...#967
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
💡 Enable Vercel Agent with $100 free credit for automated AI reviews |
|
let me know if there is anything I can do on my side to quick fix the webgpu module (namespace renaming/global renaming) |
we already do it in native.
|
I think renaming the global would be enough for a monkey-patch, but nevertheless we should stop trying to monkeypatch all the time - going forward properly switching to the actually official release of Nitro makes more sense for both of us - from a maintenance and performance perspective :) |
|
Created a fix for WebGPU: wcandillon/react-native-webgpu#271 |
|
@mrousavy nice! please trust that I not interesting to monkey patch forever, new bindings are high priority now. |
This one PR does 2 things:
1. Return actual error messages when Nitro fails to initialize
It logs & returns the actual error that was thrown when Nitro failed to initialize. This can happen if something is cooked with the
runtime, or when aglobal()property cannot be set (e.g. if it's frozen)So now the error would propagate up to JS instead of just saying the module cannot be found.
2. Add
ObjectUtilsAlso this PR adds
ObjectUtils, a static-class that provides native access to JS methods likeObject.freeze,Object.create,Object.definePropertyand a helper methodObject.defineGlobal.Caching and better performance
ObjectUtilsalso uses caching internally for common JS functions (likeObject.defineProperty), so this should speed things up as well.Object.defineGlobalObject.defineGlobaltakes aKnownGlobalPropertyNameargument which is one of three values:__nitroDispatcher,__nitroJsiCacheorNitroModulesProxy- all three values that Nitro puts into ajsi::Runtime'sglobal. As we add more to global, we also need to add them to the enum. This prevents typos as before it was just loose strings repeated everywhere.Object.defineGlobalalso adds DEBUG checks like freezing the global (prevent it from being written to) and throwing if it already exists. We had an issue where react-native-typegpu from @wcandillon also installed the same globals since he uses an old copy of Nitro, which causes duplicate code in the codebase. This causes undecypherable crashes later on, since we try to downcast our global types to ournitro::margelo::Dispatchertype (or other types), which obviously doesn't work since it is a different type (or more precisely: C++ symbol) - the one from webgpu.