Skip to content

feat: add ConstructorTraitTag to allow constructor return overridding - #1670

Draft
legendecas wants to merge 1 commit into
nodejs:mainfrom
legendecas:constructor-traits
Draft

feat: add ConstructorTraitTag to allow constructor return overridding#1670
legendecas wants to merge 1 commit into
nodejs:mainfrom
legendecas:constructor-traits

Conversation

@legendecas

@legendecaslegendecas commented Jun 19, 2025

Copy link
Copy Markdown
Member

Fixes: #1661

  • Add docs.

@codecov-commenter

codecov-commenter commented Jun 19, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.79%. Comparing base (a6213bb) to head (d07f9d7).
⚠️ Report is 30 commits behind head on main.

Files with missing linesPatch %Lines
napi-inl.h40.00%0 Missing and 3 partials ⚠️
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 

☔ View full report in Codecov by Harness.
📢 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.

@legendecaslegendecas changed the title feat: add ConstructorTrait to allow constructor return overriddingfeat: add ConstructorTraitTag to allow constructor return overriddingJun 19, 2025
@legendecas

Copy link
Copy Markdown
MemberAuthor

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.

@greggman

Copy link
Copy Markdown

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

    constmyEvent=newCPPClassThatInheritsFromEvent('nameOfEvent');consttarget=newEventTarget();conste=awaitnewPromise(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

    consttarget=newCPPClassThatInheritsFromEventTarget();constevent=newEvent('foo');conste=awaitnewPromise(resolve=>{target.addEventListener('foo',resolve,{once: true});target.dispatchEvent(event);});assert(e===event);

@legendecaslegendecas moved this from Need Triage to In Progress in Node-API Team ProjectJul 4, 2025
@KevinEady

Copy link
Copy Markdown
Contributor

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?

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

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Wrapping Event in a C++ class so that every where you pass an event it works.

4 participants

@legendecas@codecov-commenter@greggman@KevinEady