Skip to content

Conversation

@iknoom
Copy link
Contributor

@iknoom iknoom commented Oct 8, 2025

This PR removes ToLocalChecked() usage from UnionBytes to avoid unexpected crashes.

  • Rename UnionBytes::ToStringChecked() -> UnionBytes::ToString().
    • Remove ToLocalChecked() usage.
    • Change return type to MaybeLocal.
  • Update call sites to handle empty MaybeLocal.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Oct 8, 2025
@codecov
Copy link

codecov bot commented Oct 8, 2025

Codecov Report

❌ Patch coverage is 58.33333% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.54%. Comparing base (b13f24c) to head (59aef2d).
⚠️ Report is 21 commits behind head on main.

Files with missing lines Patch % Lines
src/node_builtins.cc 44.44% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #60164    +/-   ##
========================================
  Coverage   88.53%   88.54%            
========================================
  Files         703      704     +1     
  Lines      207997   208094    +97     
  Branches    40015    40024     +9     
========================================
+ Hits       184150   184251   +101     
+ Misses      15864    15858     -6     
- Partials     7983     7985     +2     
Files with missing lines Coverage Δ
src/node_union_bytes.h 100.00% <ø> (ø)
src/util.cc 85.62% <100.00%> (-0.06%) ⬇️
src/node_builtins.cc 78.95% <44.44%> (-0.37%) ⬇️

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

Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

UnionBytes is used for built-in strings (like built-in module sources). It is intended that if a UnionBytes failed to create the external string, the process should crash as soon as possible.

} else {
return String::NewExternalTwoByte(isolate, two_byte_resource_)
.ToLocalChecked();
return String::NewExternalTwoByte(isolate, two_byte_resource_);
Copy link
Member

Choose a reason for hiding this comment

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

This change kind of only brings us halfway towards the right semantics, because the comment in this snippet also applies here:

node/src/util-inl.h

Lines 347 to 357 in 1527825

if (str.size() >= static_cast<size_t>(v8::String::kMaxLength)) [[unlikely]] {
// V8 only has a TODO comment about adding an exception when the maximum
// string size is exceeded.
ThrowErrStringTooLong(isolate);
return v8::MaybeLocal<v8::Value>();
}
return v8::String::NewFromUtf8(
isolate, str.data(), v8::NewStringType::kNormal, str.size())
.FromMaybe(v8::Local<v8::String>());
}

if (out->Set(context, key, value).IsNothing()) {
return;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Just a suggestion, but if we add support for UnionBytes in ToV8Value(), this entirely loop could be replaced by a ToV8Value() call

if (!config_.ToString(isolate).ToLocal(&config_str)) {
return {};
}
return config_str;
Copy link
Member

Choose a reason for hiding this comment

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

Let's not do this – this is dangerous and strictly worse than the previous code, because a return type of Local<String> (as opposed to MaybeLocal<String>) typically means that the value won't be empty, so the caller might assume that it's always safe to dereference the handle.

@iknoom
Copy link
Contributor Author

iknoom commented Oct 11, 2025

Thanks for the review and guidance! I approached this too narrowly without fully understanding the overall design. I’ll close this PR.

@iknoom iknoom closed this Oct 11, 2025
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++. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants