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

Missing napi_type_tag_object? #1260

Closed
audetto opened this issue Jan 1, 2023 · 3 comments
Closed

Missing napi_type_tag_object? #1260

audetto opened this issue Jan 1, 2023 · 3 comments
Assignees

Comments

@audetto
Copy link

audetto commented Jan 1, 2023

Should the raw api napi_type_tag_object be exposed?

I use External<T> but there is no way to know if the external is of the right type, and a reinterpret_cast will cause seg fault for any javascript error passing an external for another?

I guess I can call it directly on the napi_value. I was just wondering.

@KevinEady
Copy link
Contributor

Yes, this appears to be a missing wrapper in node-addon-api. I can take a look at implementing this.

@KevinEady KevinEady self-assigned this Jan 2, 2023
@audetto
Copy link
Author

audetto commented Jan 2, 2023

Thanks.
It took me a while to understand the semantics of the various casts and since this is C++ I imagined that they were "safe".

Maybe a line added here:

https://github.com/nodejs/node-addon-api/blob/77350eee98957f471a355a4cf12f6ee05262fa5b/doc/external.md

that there is absolutely no safety and one must do whatever it takes to ensure the cast is sound.
(I use tagging, but maybe there are better ways).

And As<External<T>> will not fail if one uses the wrong T.

@mhdawson
Copy link
Member

PR to add landed, closing.

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 a pull request may close this issue.

3 participants