Skip to content

Conversation

addaleax
Copy link
Member

src: use Utf8Value and TwoByteValue instead of V8 helpers

Our own helper classes have the advantage of using stack storage
a lot of the time, so they should always be preferred.

tools: add C++ lint rule to avoid using String::Utf8Value

We should be using our own helpers for this instead.

Our own helper classes have the advantage of using stack storage
a lot of the time, so they should always be preferred.
We should be using our own helpers for this instead.
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/inspector
  • @nodejs/node-api
  • @nodejs/security-wg
  • @nodejs/sqlite

@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 related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Oct 13, 2025
@addaleax addaleax added the commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. label Oct 13, 2025
Copy link

codecov bot commented Oct 13, 2025

Codecov Report

❌ Patch coverage is 86.79245% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.55%. Comparing base (da9cd74) to head (2f9d49a).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
src/string_bytes.cc 33.33% 4 Missing ⚠️
src/permission/permission.cc 60.00% 1 Missing and 1 partial ⚠️
src/node_buffer.cc 95.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #60244      +/-   ##
==========================================
- Coverage   88.56%   88.55%   -0.02%     
==========================================
  Files         704      704              
  Lines      208123   208152      +29     
  Branches    40014    40011       -3     
==========================================
- Hits       184330   184319      -11     
- Misses      15815    15861      +46     
+ Partials     7978     7972       -6     
Files with missing lines Coverage Δ
src/api/async_resource.cc 95.55% <100.00%> (+0.31%) ⬆️
src/api/hooks.cc 89.13% <100.00%> (+0.32%) ⬆️
src/inspector_js_api.cc 85.40% <100.00%> (ø)
src/node.h 92.30% <ø> (ø)
src/node_api.cc 75.25% <100.00%> (ø)
src/node_errors.cc 63.70% <100.00%> (-0.07%) ⬇️
src/node_report.cc 93.14% <100.00%> (-0.02%) ⬇️
src/node_sqlite.cc 80.13% <100.00%> (-0.02%) ⬇️
src/node_v8.cc 81.51% <100.00%> (ø)
src/node_buffer.cc 68.87% <95.00%> (+0.03%) ⬆️
... and 2 more

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

Local<String> type =
String::NewFromUtf8(isolate, name, NewStringType::kInternalized)
.ToLocalChecked();
Local<String> type = ToV8Value(isolate->GetCurrentContext(), name, isolate)
Copy link
Member

Choose a reason for hiding this comment

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

Technically, this new code behaves a bit differently from the old one: it creates a normal string, while before it used to created an internalized string.
Should we add ToV8InternalizedString utility function? Or add optional string type parameter to ToV8Value. Otherwise, we can keep it here as

String::NewFromUtf8(isolate, name.data(), NewStringType::kInternalized, name.size())

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

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants