Skip to content

Enforce callback signatures with C++ Concepts #1746

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::AccessorGetter / Setter
  • PropertyDescriptor::FunctionCallable
  • ThreadSafeFunction::BlockingCall / NonBlockingCallCallback
  • TypedThreadSafeFunction::BlockingCall / NonBlockingCallCallback
  • TypedThreadSafeFunction — the CallJs callback

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status
    Need Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions