Skip to content

Missing napi_type_tag_object? #1260

Description

@audetto

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.

Activity

  1. KevinEady commented on Jan 2, 2023

    @KevinEady
    Contributor

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

  2. self-assigned this
    on Jan 2, 2023
  3. audetto commented on Jan 2, 2023

    @audetto
    Author

    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.

  4. mhdawson commented on Jan 27, 2023

    @mhdawson
    Member

    PR to add landed, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions