feat: add support for nogc types via BasicEnv #1514
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1514 +/- ##
==========================================
- Coverage 64.69% 64.40% -0.30%
==========================================
Files 3 3
Lines 1997 2003 +6
Branches 687 693 +6
==========================================
- Hits 1292 1290 -2
- Misses 144 146 +2
- Partials 561 567 +6 ☔ View full report in Codecov by Sentry. |
| fail-fast: false | ||
| matrix: | ||
| node-version: [ 18.x, 20.x, 21.x, 22.x ] | ||
| api_version: |
There was a problem hiding this comment.
Should we add checks for the standard/experimental to ci-win.yml too?
There was a problem hiding this comment.
Good thought... I pretty much copied Gabriel's CI file. I'll comment on his PR to verify, since mine would end up being overwritten when i rebase to master after his is merged.
|
Agreed we should do a release to get out the previous fixe that @gabrielschulhof made and then put this out in a SemVer major. |
674fa28 to
83af80c
Compare
|
Hi team, Using some SFINAE magic, I was able to determine at compile time how to associate the finalizer -- either directly or with This means no changes were needed to any existing tests, and I created a new test in |
fc5dc94 to
321fe1f
Compare
There was a problem hiding this comment.
Looks good!
I think the Gc vs. NoGc nomenclature is a bit confusing. Unfortunately, we established this in core. I think maybe we should go with DuringGc and OutsideGc. For env, we'd have DuringGcEnv and Env, since Env is already established, but for the finalizer type names I think we can go with DuringGc and OutsideGc for clarity.
| if (isExperimental) { | ||
| assert.strictEqual(binding.finalizer_order.Test.isNogcFinalizerCalled, true, 'Expected nogc finalizer to be called [before ticking]'); | ||
| assert.strictEqual(binding.finalizer_order.Test.isGcFinalizerCalled, false, 'Expected gc finalizer to not be called [before ticking]'); | ||
| assert.strictEqual(isCallbackCalled, false, 'Expected callback not be called [before ticking]'); |
There was a problem hiding this comment.
| assert.strictEqual(isCallbackCalled, false, 'Expected callback not be called [before ticking]'); | |
| assert.strictEqual(isCallbackCalled, false, 'Expected callback to not be called [before ticking]'); |
| napi_property_attributes attributes = napi_default); | ||
| static Napi::Value OnCalledAsFunction(const Napi::CallbackInfo& callbackInfo); | ||
| virtual void Finalize(Napi::Env env); | ||
| virtual void Finalize(NogcEnv env); |
There was a problem hiding this comment.
| virtual void Finalize(NogcEnv env); | |
| virtual void Finalize(Napi::NogcEnv env); |
|
I tested this with const { makeSync, makeAsync } = require('bindings')('test_sync_fini')
const doAsync = process.argv[2] === 'async'
;(function test(iter = 0) {
for (let i = 0; i < 1000000; i++) {
const id = `${iter}:${i}`
if (doAsync) {
makeAsync(id)
} else {
makeSync(id)
}
}
setTimeout(test, 0, iter + 1)
})()Here's a video of the output. Guess which column is async 🙂 Screen.Recording.2024-06-24.at.8.46.57.AM.mov |
Napi::NogcEnvclass, taking the place ofNapi::Envin finalizer callbacks.void Napi::NogcEnv::AddPostFinalizer()and overloads.Closes: #1508
TODO: