node-addon-api
node-addon-api copied to clipboard
src: restore ability to run under NAPI_EXPERIMENTAL
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_EXPERIMENTALshould be on, and add it to the defines ifNAPI_VERSIONis set toNAPI_VERSION_EXPERIMENTAL, i.e. 2147483647. - When building with
NAPI_EXPERIMENTAL,- render all finalizers asynchronous, and
- expect
napi_cannot_run_jsinstead ofnapi_exception_pending.
I might have been thinking of another change but I thought we had made it opt-in with another define? @legendecas is that right?
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?
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) |
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.
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.