feat: add ConstructorTraitTag to allow constructor return overridding
Fixes: https://github.com/nodejs/node-addon-api/issues/1661
- [ ] Add docs.
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.
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.
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 targetconst 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 functionalityconst 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);
This does not work for
InstanceMethodbecause 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?