napi_type_tag
存储为两个无符号 64 位整数的 128 位值。它作为一个 UUID,JavaScript 对象可以用它来 "tagged" 以确保它们是某种类型。这是比 napi_instanceof
更强的检查,因为如果对象的原型被操纵,后者会报告误报。类型标记与 napi_wrap
一起使用时最有用,因为它确保从封装对象中检索的指针可以安全地转换为与先前应用于 JavaScript 对象的类型标记相对应的原生类型。
¥A 128-bit value stored as two unsigned 64-bit integers. It serves as a UUID
with which JavaScript objects can be "tagged" in order to ensure that they are
of a certain type. This is a stronger check than napi_instanceof
, because
the latter can report a false positive if the object's prototype has been
manipulated. Type-tagging is most useful in conjunction with napi_wrap
because it ensures that the pointer retrieved from a wrapped object can be
safely cast to the native type corresponding to the type tag that had been
previously applied to the JavaScript object.
typedef struct {
uint64_t lower;
uint64_t upper;
} napi_type_tag;