node-addon-api icon indicating copy to clipboard operation
node-addon-api copied to clipboard

src: restore ability to run under NAPI_EXPERIMENTAL

Open gabrielschulhof opened this issue 2 years ago • 2 comments

Since we made the default for Node.js core finalizers synchronous for users running with NAPI_EXPERIMENTAL and introduced env->CheckGCAccess() in Node.js core, we must now defer all finalizers in node-addon-api, because our users likely make non-gc-safe Node-API calls from existing finalizers. To that end,

  • Use the NAPI_VERSION environment variable to detect whether NAPI_EXPERIMENTAL should be on, and add it to the defines if NAPI_VERSION is set to NAPI_VERSION_EXPERIMENTAL, i.e. 2147483647.
  • When building with NAPI_EXPERIMENTAL,
    • render all finalizers asynchronous, and
    • expect napi_cannot_run_js instead of napi_exception_pending.

gabrielschulhof avatar Nov 12 '23 07:11 gabrielschulhof

I might have been thinking of another change but I thought we had made it opt-in with another define? @legendecas is that right?

mhdawson avatar Nov 14 '23 22:11 mhdawson

because our users likely make non-gc-safe Node-API calls from existing finalizers

I'm afraid that I didn't understand this assumption. Is this assumption unique to node-addon-api, not the node-api c layer?

legendecas avatar Nov 15 '23 16:11 legendecas

Core status of needed changes:

branch backport complete released
v22.x ✅ (v22.0.0)
v20.x ✅ (20.13.0)
v18.x (v18.20.3-proposal)

gabrielschulhof avatar May 03 '24 15:05 gabrielschulhof

Hi @gabrielschulhof ,

Looks like this is becoming of more importance. I can take a look at continuing this work? Judging by the latest CI failure, looks like the Napi::External<> object needs to implement a similar approach.

KevinEady avatar May 08 '24 09:05 KevinEady

Codecov Report

Attention: Patch coverage is 94.44444% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 64.89%. Comparing base (23bb42b) to head (a6db742). Report is 2 commits behind head on main.

Files Patch % Lines
napi-inl.h 94.44% 0 Missing and 1 partial :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1409      +/-   ##
==========================================
+ Coverage   64.71%   64.89%   +0.17%     
==========================================
  Files           3        3              
  Lines        1981     1991      +10     
  Branches      687      687              
==========================================
+ Hits         1282     1292      +10     
  Misses        138      138              
  Partials      561      561              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar May 17 '24 14:05 codecov-commenter