Add type tags to `napi-sys`.
Would it be possible to add the following two functions to napi-sys? Added since N-API v8 (in Node v14.8.0, v12.19.0).
napi_status napi_type_tag_object(napi_env env,
napi_value js_object,
const napi_type_tag* type_tag);
napi_status napi_check_object_type_tag(napi_env env,
napi_value js_object,
const napi_type_tag* type_tag,
bool* result);I'm using the napi::sys for some FFI-safe bindings (long story), so if these land in napi::sys that would be enough for me. I can submit a PR for this.
I can also imagine it would be useful to use this in TaggedObject on v8 since it's a bit safer. E.g. the following example segfaults right now:
- Assume a JS script like this:
const { one } = require("objc-module"); const { sum } = require("napi-rs-module"); sum(one(), one()); - The Objective-C library calls
napi_create_external(...)withdata = [NSNumber numberWithInt:1]. This is a tagged pointer [^1], so it doesn't actually point to anything but it also doesn't violate the NAPI contract. - The Rust library segfaults because
napi-rs::JsExternalattempts to read the firstsizeof(TypeId)bytes at the tagged pointer's address.
Granted, this example isn't supposed to "work" anyway, but I think it would be better to have it throw an exception instead of segfault.
Anyway, summarizing: would it be okay if I submit a PR adding these two functions to napi::sys?
[^1]: NB: Apple's tagged pointers in Objective-C are unrelated to type tagging in NAPI.
Source: napi-rs/napi-rs