mrousavy / nitro

🔥 Insanely fast native C++, Swift or Kotlin modules with a statically compiled binding layer to JSI
https://nitro.margelo.com
MIT License
642 stars 22 forks source link

fix: Perform safer checks for `toContain(..)` in example, and add `NitroModules.hasNativeState(value)` #324

Closed mrousavy closed 1 week ago

mrousavy commented 1 week ago

Adds a new API to NitroModules: NitroModules.hasNativeState(value).

With this API, we guard the toString() call of a HybridObject in release builds because we relied on an error being thrown, which turns into an assert (crash) in release. To avoid relying on an error being thrown, we instead now somewhat safely check if we can stringify an object by checking if it has toString() or inherits from it - and then we check if it has NativeState. It is a fair assumption that toString() from prototype only works if we have NativeState, at least in the Nitro world.

vercel[bot] commented 1 week ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **nitro-docs** | ⬜️ Skipped ([Inspect](https://vercel.com/margelo/nitro-docs/C4uz82gr5Sj75YrfyEfbDbaBVcs6)) | | | Nov 12, 2024 5:05pm |