Skip to content

src: reduce duplication through consolidation - #67497

Open
jasnell wants to merge 4 commits into
nodejs:mainfrom
jasnell:consolidate-cpp-structural
Open

jasnell wants to merge 4 commits into
nodejs:mainfrom
jasnell:consolidate-cpp-structural

Conversation

@jasnell

@jasnell jasnell commented Nov 15, 2026

Copy link
Copy Markdown
Member

Reduce code by consolidating cleanup. See individual commits

The MX, CAA, TLSA, TXT, SRV, and NAPTR reply parsers each repeated the
same structure: lazily create the record dictionary template, parse the
reply, iterate the answer section filtering by record type, build and
append each record, and report ENODATA when nothing matched. Factor
that into GetRecordTemplate(), ForEachAnswer(), and AppendRecord()
helpers so each parser only contains its record-specific extraction.

Behavior is unchanged, including TLSA results being indexed by answer
position and never reporting ENODATA.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
Eleven snapshotable binding data classes implemented Deserialize() with
the same sequence of opening a handle scope, looking up the Realm, and
recreating the binding data on the holder, and six of them implemented
Serialize() by handing over the InternalFieldInfo allocated in
PrepareForSerialization(). Add Realm::DeserializeBindingData() and
TakeInternalFieldInfo() helpers and use them.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
Eleven fs bindings (stat, statfs, link, rename, unlink, realpath,
readdir, copyFile, chown, lchown, mkdtemp) repeated every permission
check in both the asynchronous and the synchronous branch, differing
only in whether the denial is reported through the request or thrown.
Obtain the request wrap up front with a new GetAsyncReqWrap() helper
and perform each check once with FS_THROW_IF_INSUFFICIENT_PERMISSIONS(),
which picks the reporting style based on whether the call is async.

How permission denials are reported is unchanged.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
Replace the repeated `if (argc > N) { req = GetReqWrap(args, N);
CHECK_NOT_NULL(req); ...` prologue of the fs bindings that select the
asynchronous path by argument count with GetAsyncReqWrap().

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/net
  • @nodejs/realm
  • @nodejs/startup
  • @nodejs/url

@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

@gurgunday gurgunday 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.

lgtm

@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 15, 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 15, 2026
@nodejs-github-bot

nodejs-github-bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

@codecov

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.49407% with 62 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.70%. Comparing base (d105ef7) to head (5f73d63).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/cares_wrap.cc 67.42% 34 Missing and 9 partials ⚠️
src/node_file.cc 81.11% 0 Missing and 17 partials ⚠️
src/glob/node_glob.cc 0.00% 1 Missing ⚠️
src/node_realm-inl.h 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67497      +/-   ##
==========================================
+ Coverage   90.67%   90.70%   +0.03%     
==========================================
  Files         799      799              
  Lines      280245   280039     -206     
  Branches    54125    54028      -97     
==========================================
- Hits       254100   254014      -86     
+ Misses      16280    16215      -65     
+ Partials     9865     9810      -55     
Files with missing lines Coverage Δ
src/encoding_binding.cc 56.60% <100.00%> (-0.50%) ⬇️
src/node_blob.cc 73.40% <100.00%> (-0.09%) ⬇️
src/node_diagnostics_channel.cc 85.23% <100.00%> (+1.05%) ⬆️
src/node_modules.cc 79.75% <100.00%> (-0.16%) ⬇️
src/node_process_methods.cc 88.67% <100.00%> (-0.15%) ⬇️
src/node_realm.h 100.00% <ø> (ø)
src/node_snapshotable.cc 73.68% <100.00%> (-0.06%) ⬇️
src/node_snapshotable.h 100.00% <100.00%> (ø)
src/node_url.cc 78.93% <100.00%> (-0.52%) ⬇️
src/node_v8.cc 87.41% <100.00%> (+0.04%) ⬆️
... and 5 more

... and 34 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.

@mcollina mcollina 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.

rslgtm

@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. commit-queue-rebase PRs the Commit Queue should land as multiple self-contained commits. labels Nov 15, 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 PRs queued for automated landing through the Commit Queue. 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