Skip to content

src: deduplicate/consolidate multiple sources - #67496

Closed
jasnell wants to merge 11 commits into
nodejs:mainfrom
jasnell:consolidate-cpp-duplicates-2
Closed

jasnell wants to merge 11 commits into
nodejs:mainfrom
jasnell:consolidate-cpp-duplicates-2

Conversation

@jasnell

@jasnell jasnell commented Nov 15, 2026

Copy link
Copy Markdown
Member

See individual commits. Deduplicate/consolidate multiple bits.

@nodejs-github-bot

nodejs-github-bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/ffi
  • @nodejs/gyp
  • @nodejs/inspector
  • @nodejs/loaders
  • @nodejs/node-api
  • @nodejs/security-wg
  • @nodejs/vm

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Nov 15, 2026
@jasnell
jasnell requested review from addaleax and mcollina November 15, 2026 19:01
@codecov

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.54325% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.51%. Comparing base (7ed1ca0) to head (9eb547c).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/stream_base.cc 34.78% 11 Missing and 4 partials ⚠️
src/util.cc 92.85% 8 Missing ⚠️
src/module_wrap.cc 45.45% 3 Missing and 3 partials ⚠️
src/js_native_api_v8.cc 85.00% 0 Missing and 3 partials ⚠️
src/permission/permission.cc 50.00% 2 Missing and 1 partial ⚠️
src/node_ffi.cc 95.23% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #67496    +/-   ##
========================================
  Coverage   90.51%   90.51%            
========================================
  Files         805      805            
  Lines      285878   285644   -234     
  Branches    55200    55145    -55     
========================================
- Hits       258756   258564   -192     
- Misses      17214    17217     +3     
+ Partials     9908     9863    -45     
Files with missing lines Coverage Δ
src/inspector/dom_storage_agent.cc 81.28% <100.00%> (-1.98%) ⬇️
src/inspector/inspector_object_utils.cc 93.05% <100.00%> (+3.25%) ⬆️
src/inspector/network_agent.cc 85.51% <100.00%> (-2.52%) ⬇️
src/node_ffi.h 82.60% <ø> (ø)
src/node_report.cc 91.92% <100.00%> (-0.47%) ⬇️
src/node_ffi.cc 75.93% <95.23%> (+1.11%) ⬆️
src/js_native_api_v8.cc 77.31% <85.00%> (+0.65%) ⬆️
src/permission/permission.cc 79.91% <50.00%> (+3.91%) ⬆️
src/module_wrap.cc 73.69% <45.45%> (+0.38%) ⬆️
src/util.cc 88.34% <92.85%> (+0.70%) ⬆️
... and 1 more

... and 29 files with indirect coverage changes

🚀 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.

@vmoroz vmoroz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node-API related changes look good.

@jasnell jasnell added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 18, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 18, 2026
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@jasnell
jasnell requested a review from anonrig November 20, 2026 06:44
@jasnell jasnell added author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue PRs queued for automated landing through the Commit Queue. and removed commit-queue PRs queued for automated landing through the Commit Queue. labels Nov 22, 2026
@jasnell
jasnell force-pushed the consolidate-cpp-duplicates-2 branch from 88b79b8 to 185c98b Compare November 22, 2026 17:07
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@jasnell jasnell added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 24, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 24, 2026
@nodejs-github-bot

This comment was marked as outdated.

@jasnell jasnell added commit-queue PRs queued for automated landing through the Commit Queue. commit-queue-rebase PRs the Commit Queue should land as multiple self-contained commits. labels Nov 25, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. and removed commit-queue PRs queued for automated landing through the Commit Queue. labels Nov 25, 2026
@nodejs-github-bot

This comment was marked as outdated.

@jasnell
jasnell force-pushed the consolidate-cpp-duplicates-2 branch from 185c98b to 0c449bf Compare November 26, 2026 16:12
@nodejs-github-bot

This comment was marked as outdated.

The loong64, ppc64, riscv64, and s390x fast trampoline emitters each
duplicated the signature validation, executable memory allocation,
cache flush and mprotect sequence, trampoline release, and (for the
fixed-width 32-bit ISAs) the instruction word emitters. Move them into
a shared scalar_trampoline.h header so each platform file only
contains its architecture-specific instruction encoding.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
The System V and Win64 halves of the x64 fast trampoline emitter each
defined identical copies of the register constants, the byte/word
emitters, the REX/ModRM, mov, call, jmp, stack adjustment, and ret
encoders, and the narrow return normalization helpers. Define them
once ahead of the ABI-specific code.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
napi_create_error(), napi_create_type_error(), napi_create_range_error()
and node_api_create_syntax_error() differed only in the v8::Exception
factory used, as did the corresponding napi_throw_*() functions. Move
the bodies into internal CreateError() and ThrowError() helpers that
take the factory. The exported functions and their signatures are
unchanged, so there is no ABI impact.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
DynamicLibrary::UnregisterCallback(), RefCallback(), and UnrefCallback()
each duplicated the closed-library check, pointer argument validation,
and callback map lookup. Move them into a shared FindCallback() helper.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
The network and DOM storage agents repeated the same pattern dozens of
times: read a property with an ObjectGet*() helper and throw a
"Missing <name> in event" TypeError if it was absent. Add
ObjectGetRequired() overloads that combine the two, move the duplicated
ThrowEventError() into inspector_object_utils, and use them throughout
both agents. Error messages are unchanged.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
The SetMethod(), SetFastMethod(), SetMethodNoSideEffect(),
SetProtoMethod(), SetInstanceMethod(), and SetProto*Dispose() variants
each repeated the same function template construction, internalized
name string creation, and installation code, differing only in side
effect type, receiver signature, and target. Factor that into a small
set of internal helpers.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
When the creation context of the import.meta object has no associated
Realm, the getter threw ERR_INVALID_INVOCATION but then fell through
and dereferenced the null Realm. Return after throwing, as the other
error paths in the getter already do.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
ImportMetaResolveLazyGetter() and PathHelpersLazyGetter() duplicated
the code that retrieves the creation context from the holder object.
Move it into a shared GetHolderCreationContext() helper.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
All three callers of report::WriteNodeReport() computed the
excludeNetwork and excludeEnv options the same way, falling back to the
process-wide defaults when there is no Environment. Do that once inside
WriteNodeReport() instead.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
FastHas() duplicated the scope parsing in FastHasResource(). Move the
shared logic into FastHasImpl(), with FastHas() passing an empty
resource.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
StreamBase::WriteBuffer() and WriteString() duplicated the code that
creates a request object when needed and attaches the handle being sent
over an IPC pipe. Move it into a shared PrepareSendHandle() helper.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
@jasnell
jasnell force-pushed the consolidate-cpp-duplicates-2 branch from 0c449bf to 9eb547c Compare November 27, 2026 17:01
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

jasnell added a commit that referenced this pull request Nov 28, 2026
The loong64, ppc64, riscv64, and s390x fast trampoline emitters each
duplicated the signature validation, executable memory allocation,
cache flush and mprotect sequence, trampoline release, and (for the
fixed-width 32-bit ISAs) the instruction word emitters. Move them into
a shared scalar_trampoline.h header so each platform file only
contains its architecture-specific instruction encoding.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: #67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
jasnell added a commit that referenced this pull request Nov 28, 2026
The System V and Win64 halves of the x64 fast trampoline emitter each
defined identical copies of the register constants, the byte/word
emitters, the REX/ModRM, mov, call, jmp, stack adjustment, and ret
encoders, and the narrow return normalization helpers. Define them
once ahead of the ABI-specific code.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: #67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
jasnell added a commit that referenced this pull request Nov 28, 2026
napi_create_error(), napi_create_type_error(), napi_create_range_error()
and node_api_create_syntax_error() differed only in the v8::Exception
factory used, as did the corresponding napi_throw_*() functions. Move
the bodies into internal CreateError() and ThrowError() helpers that
take the factory. The exported functions and their signatures are
unchanged, so there is no ABI impact.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: #67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
jasnell added a commit that referenced this pull request Nov 28, 2026
DynamicLibrary::UnregisterCallback(), RefCallback(), and UnrefCallback()
each duplicated the closed-library check, pointer argument validation,
and callback map lookup. Move them into a shared FindCallback() helper.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: #67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
jasnell added a commit that referenced this pull request Nov 28, 2026
The network and DOM storage agents repeated the same pattern dozens of
times: read a property with an ObjectGet*() helper and throw a
"Missing <name> in event" TypeError if it was absent. Add
ObjectGetRequired() overloads that combine the two, move the duplicated
ThrowEventError() into inspector_object_utils, and use them throughout
both agents. Error messages are unchanged.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: #67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
jasnell added a commit that referenced this pull request Nov 28, 2026
The SetMethod(), SetFastMethod(), SetMethodNoSideEffect(),
SetProtoMethod(), SetInstanceMethod(), and SetProto*Dispose() variants
each repeated the same function template construction, internalized
name string creation, and installation code, differing only in side
effect type, receiver signature, and target. Factor that into a small
set of internal helpers.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: #67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
jasnell added a commit that referenced this pull request Nov 28, 2026
When the creation context of the import.meta object has no associated
Realm, the getter threw ERR_INVALID_INVOCATION but then fell through
and dereferenced the null Realm. Return after throwing, as the other
error paths in the getter already do.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: #67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
jasnell added a commit that referenced this pull request Nov 28, 2026
ImportMetaResolveLazyGetter() and PathHelpersLazyGetter() duplicated
the code that retrieves the creation context from the holder object.
Move it into a shared GetHolderCreationContext() helper.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: #67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
jasnell added a commit that referenced this pull request Nov 28, 2026
All three callers of report::WriteNodeReport() computed the
excludeNetwork and excludeEnv options the same way, falling back to the
process-wide defaults when there is no Environment. Do that once inside
WriteNodeReport() instead.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: #67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
jasnell added a commit that referenced this pull request Nov 28, 2026
FastHas() duplicated the scope parsing in FastHasResource(). Move the
shared logic into FastHasImpl(), with FastHas() passing an empty
resource.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: #67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
jasnell added a commit that referenced this pull request Nov 28, 2026
StreamBase::WriteBuffer() and WriteString() duplicated the code that
creates a request object when needed and attaches the handle being sent
over an IPC pipe. Move it into a shared PrepareSendHandle() helper.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: #67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
@jasnell

jasnell commented Nov 28, 2026

Copy link
Copy Markdown
Member Author

Landed in d23dd95...c58ccfa

@jasnell jasnell closed this Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. commit-queue-rebase PRs the Commit Queue should land as multiple self-contained commits. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants