Skip to content

src,lib: support path in v8.writeHeapSnapshot output #58959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

juanarbol
Copy link
Member


I'm a bit rusty with my C++. Any feedback will be more than valuable.

@juanarbol juanarbol requested a review from BridgeAR July 5, 2025 06:32
@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 Jul 5, 2025
@juanarbol juanarbol changed the title Juan/filepath v8 src,lib: support path in v8.writeHeapSnapshot output Jul 5, 2025
Copy link

codecov bot commented Jul 5, 2025

Codecov Report

Attention: Patch coverage is 69.23077% with 12 lines in your changes missing coverage. Please review.

Project coverage is 90.08%. Comparing base (cc856b3) to head (3ef78c4).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/heap_utils.cc 61.29% 6 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #58959      +/-   ##
==========================================
- Coverage   90.09%   90.08%   -0.01%     
==========================================
  Files         640      640              
  Lines      188471   188498      +27     
  Branches    36973    36970       -3     
==========================================
+ Hits       169802   169814      +12     
- Misses      11382    11399      +17     
+ Partials     7287     7285       -2     
Files with missing lines Coverage Δ
lib/v8.js 99.38% <100.00%> (+<0.01%) ⬆️
src/node_internals.h 81.03% <ø> (ø)
src/heap_utils.cc 78.38% <61.29%> (-1.75%) ⬇️

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

@juanarbol juanarbol added semver-minor PRs that contain new features and should be released in the next minor version. v8 module Issues and PRs related to the "v8" subsystem. labels Jul 6, 2025
permission::PermissionScope::kFileSystemWrite,
path.ToStringView());

final_filename = std::string(*path) + "/" +
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
final_filename = std::string(*path) + "/" +
final_filename = path.ToString() + "/" +

THROW_IF_INSUFFICIENT_PERMISSIONS(
env,
permission::PermissionScope::kFileSystemWrite,
std::string(*path) + "/" + std::string(*filename));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
std::string(*path) + "/" + std::string(*filename));
path.ToString() + "/" + filename.ToString();

env,
permission::PermissionScope::kFileSystemWrite,
std::string(*path) + "/" + std::string(*filename));
final_filename = std::string(*path) + "/" + std::string(*filename);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
final_filename = std::string(*path) + "/" + std::string(*filename);
final_filename = path.ToString() + "/" + filename.ToString();

But I'd encourage you to move this line up before the THROW_IF_INSUFFICIENT_PERMISSIONS one and then just use the same variable in that

env,
permission::PermissionScope::kFileSystemWrite,
filename.ToStringView());
final_filename = *filename;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
final_filename = *filename;
final_filename = filename.ToString();

Local<Value> filename_v = args[0];
auto options = GetHeapSnapshotOptions(args[1]);
Local<String> path_v = args[2].As<String>();
Copy link
Contributor

@Renegade334 Renegade334 Jul 7, 2025

Choose a reason for hiding this comment

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

getValidatedPath can return a Uint8Array, so typeguarding probably needs to happen before casting?

Copy link
Member

@jasnell jasnell Jul 7, 2025

Choose a reason for hiding this comment

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

You'll want to use BufferValue here... or, skip this and have the BufferValue uses below just accept args[2]. Casting as a string here is incorrect.

const filename = writeHeapSnapshot(undefined, options);
// If path is set, the filename will be the provided path.
if (path) assert(filename.includes(tmpdir.path));
Copy link
Member

Choose a reason for hiding this comment

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

The test should be expanded to cover at least cases such as:

  1. Passing the path as a Buffer and as a URL
  2. Passing an unwritable path
  3. Passing invalid types for path (to test the type checking)

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

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

The BufferValue uses need to be cleaned up

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. semver-minor PRs that contain new features and should be released in the next minor version. v8 module Issues and PRs related to the "v8" subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants