Skip to content
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

fix: Provide helpful error message if this is not bound #157

Merged
merged 2 commits into from
Sep 25, 2024

Conversation

mrousavy
Copy link
Owner

@mrousavy mrousavy commented Sep 25, 2024

When you accidentally destructure the HybridObject in JS, the NativeState gets lost and it cannot properly resolve the prototype anymore (by design):

const math = NitroModules.createHybridObject<Math>('Math')
const { add } = math
     // ^ destructured! `this` is not bound to `math` anymore on `add`

This PR now provides a more helpful error message - the error thrown when trying to call add without a properly bound this now like this:

- Cannot call Math.add(...) - `this` is not bound! Suggestions:
- - Did you accidentally destructure the `HybridObject`? (`const { add } = ...`)
- - Did you call `dispose()` on the `HybridObject` before?
- - Did you accidentally call `add` on the prototype directly?

@mrousavy mrousavy merged commit 377fbd8 into main Sep 25, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant