Skip to content

feat: add support for requiring basic finalizers - #1568

Merged
legendecas merged 2 commits into
nodejs:mainfrom
KevinEady:add-require-basic-finalizers
Sep 19, 2024
Merged

feat: add support for requiring basic finalizers#1568
legendecas merged 2 commits into
nodejs:mainfrom
KevinEady:add-require-basic-finalizers

Conversation

@KevinEady

@KevinEadyKevinEady commented Sep 3, 2024

Copy link
Copy Markdown
Contributor

Introduce NODE_ADDON_API_REQUIRE_BASIC_FINALIZERS preprocessor directive, which adds an always-fail static assertion inside the Wrapper definition (responsible for passing the user's non-basic finalizer through a node_api_post_finalizer call) if this preprocessor directive is defined.

@KevinEady
KevinEadyforce-pushed the add-require-basic-finalizers branch from 4603869 to e21c0f6CompareSeptember 3, 2024 21:39
@codecov-commenter

codecov-commenter commented Sep 3, 2024

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.40%. Comparing base (b4aeecb) to head (23b57cc).
⚠️ Report is 71 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@## main #1568 +/- ##
=======================================
Coverage 64.40% 64.40% =======================================
Files 3 3 Lines 2003 2003 Branches 693 693 =======================================
Hits 1290 1290 Misses 146 146 Partials 567 567 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@KevinEady
KevinEadyforce-pushed the add-require-basic-finalizers branch from e21c0f6 to 7c91a10CompareSeptember 4, 2024 17:34
@KevinEady

Copy link
Copy Markdown
ContributorAuthor

When trying to use a non-basic finalizer with this directive defined, you'll get an error like:

../../../../../napi-inl.h:252:5: error: static assertion failed: NODE_ADDON_API_REQUIRE_BASIC_FINALIZERS defined: Finalizer must be basic.
static_assert(false,
^ ~~~~~

(error taken from the test created in this PR)

@KevinEadyKevinEady mentioned this pull request Sep 5, 2024
Comment threaddoc/finalization.md Outdated
In general, it is best to use basic finalizers whenever possible (eg. when
access to JavaScript is _not_ needed).
access to JavaScript is _not_ needed). To ensure that all finalizers are basic
finalizers at compile-time, define the `NODE_ADDON_API_REQUIRE_BASIC_FINALIZERS`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if we should add a "best practice" target that enables all possible checks in https://github.com/nodejs/node-addon-api/blob/main/node_addon_api.gyp.

Comment threaddoc/finalization.md Outdated

In general, it is best to use basic finalizers whenever possible (eg. when
access to JavaScript is _not_ needed).
access to JavaScript is _not_ needed). To ensure that all finalizers are basic

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this passive voice: The NODE_ADDON_API_REQUIRE_BASIC_FINALIZERS preprocessor directive can be defined to ensure that all finalizers are basic.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 23b57cc

Comment threaddoc/setup.md Outdated
@@ -90,3 +90,13 @@ provide feedback to the user of the runtime error, as it is impossible to pass
the error to JavaScript when the environment is terminating. In order to bypass
this behavior such that the Node process will not terminate, define the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too: "The ... can be defined in order to bypass ... "

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 23b57cc

Comment threadnapi-inl.h Outdated
}

#ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
#if defined(NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change needed?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, this was a leftover of a different implementation. Addressed in 23b57cc

Comment threadnapi-inl.h Outdated
}

#ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
#if defined(NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 23b57cc

@gabrielschulhofgabrielschulhof left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some comments.

@KevinEady
KevinEady marked this pull request as draft September 7, 2024 10:48
- Use passive voice in existing and new docs
- Revert unnecessary change
@KevinEady
KevinEady marked this pull request as ready for review September 9, 2024 15:30
@KevinEady

Copy link
Copy Markdown
ContributorAuthor

LGTM with some comments.

Hi @gabrielschulhof ,

Your changes have been introduced in 23b57cc. PTAL!

@mhdawsonmhdawson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants

@KevinEady@codecov-commenter@gabrielschulhof@legendecas@mhdawson