Skip to content

Enforce callback signatures with C++ Concepts #1746

Open

Description

@legendecas

#1738 documented the required signature of the templated finalizer callback parameters as inline comment hints.

These are human-only annotations. The compiler does not enforce them, so a mismatched callable fails deep inside the template instantiation with an unhelpful error.

Once C++20 is the minimum supported standard, we should replace these hints with C++ Concepts that constrain the Finalizer/FinalizerType template parameters. This gives compiler-enforced contracts and clear diagnostics at the call site.

Finalizer candidates:

  • BasicEnv::PostFinalizer
  • Object::AddFinalizer
  • External::New
  • Buffer::New / Buffer::NewOrCopy
  • ThreadSafeFunction::New
  • TypedThreadSafeFunction::New

Callback candidates:

  • Function::New — the JS callback (Callable)
  • PropertyDescriptor::Accessor — Getter / Setter
  • PropertyDescriptor::Function — Callable
  • ThreadSafeFunction::BlockingCall / NonBlockingCall — Callback
  • TypedThreadSafeFunction::BlockingCall / NonBlockingCall — Callback
  • TypedThreadSafeFunction — the CallJs callback

Activity

  1. moved this from Need Triage to Todo in Node-API Team Projecton Sep 4, 2026
  2. github-actions commented on Nov 9, 2026

    @github-actions
    Contributor

    This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions