Skip to content

N-API: Implement stricter wrapping

Use a stronger criterion to identify objects in the prototype chain that store pointers to native data that were added by previous calls to napi_wrap().

Whereas the old criterion for identifying napi_wrap()-injected prototype chain objects was to consider an object with an internal field count of 1 to be such an object, the new criterion is to consider an object with an internal field count of 2 such that the second field holds a v8::External which itself contains a pointer to a global static string unique to N-API to be a napi_wrap()-injected prototype chain object.

This greatly reduces the possibility of returning a pointer that was not previously added with napi_wrap(), and it allows us to recognize that an object has already undergone napi_wrap() and we can thus replace the old v8::External with the new one such that, when the old one will be garbage- collected, any finalize callback for its native pointer will also be called.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

Merge request reports

Loading