napi_type_tag


一个以两个无符号64位整数存储的128位值。它用作UUID,可以对JavaScript对象进行“标记”,以确保它们属于某种类型。这比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;