node-addon-api icon indicating copy to clipboard operation
node-addon-api copied to clipboard

feat: add ConstructorTraitTag to allow constructor return overridding

Open legendecas opened this issue 6 months ago • 4 comments

Fixes: https://github.com/nodejs/node-addon-api/issues/1661

  • [ ] Add docs.

legendecas avatar Jun 19 '25 15:06 legendecas

Codecov Report

:x: Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 65.79%. Comparing base (a6213bb) to head (d07f9d7). :warning: Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
napi-inl.h 40.00% 0 Missing and 3 partials :warning:
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1670   +/-   ##
=======================================
  Coverage   65.79%   65.79%           
=======================================
  Files           3        3           
  Lines        2146     2149    +3     
  Branches      715      716    +1     
=======================================
+ Hits         1412     1414    +2     
  Misses        162      162           
- Partials      572      573    +1     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov-commenter avatar Jun 19 '25 16:06 codecov-commenter

This does not work for InstanceMethod because there is a branch check enabled at https://github.com/nodejs/node/blob/main/src/js_native_api_v8.cc#L1028.

legendecas avatar Jun 19 '25 17:06 legendecas

Thank you for working on this!

It's not clear from the comments if this is working yet. It sounds like maybe not?

I would suggest adding a few more tests

  • Make a C++ class that inherits from Event, then pass it to a native event target

    const myEvent = new CPPClassThatInheritsFromEvent('nameOfEvent');
    const target = new EventTarget();
    const e = await new Promise(resolve => {
      target.addEventListener('nameOfEvent', resolve, { once: true });
      target.dispatchEvent(myEvent);
    });
    assert(e === myEvent);
    
  • Make a C++ class that inherits from EventTarget. Maybe sure you can use EventTarget's functionality

    const target = new CPPClassThatInheritsFromEventTarget();
    const event = new Event('foo');
    const e = await new Promise(resolve => {
      target.addEventListener('foo', resolve, { once: true });
      target.dispatchEvent(event);
    });
    assert(e === event);
    

greggman avatar Jun 24 '25 18:06 greggman

This does not work for InstanceMethod because there is a branch check enabled at https://github.com/nodejs/node/blob/main/src/js_native_api_v8.cc#L1028.

Hi @legendecas , is there anything we can do to address this branch check? Is it absolutely needed?

KevinEady avatar Sep 26 '25 15:09 KevinEady