Skip to content

Commit ff92f3d

Browse files
committed
src: avoid duplicating namespaces in node_internals.h
Signed-off-by: Juan José Arboleda <[email protected]>
1 parent c7f35cf commit ff92f3d

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

lib/v8.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ function writeHeapSnapshot(filename, options) {
9292
options.path = getValidatedPath(options.path);
9393
}
9494

95+
if (options?.encoding == undefined) {
96+
options.encoding == 'utf8'
97+
}
98+
9599
const optionArray = getHeapSnapshotOptions(options);
96-
return triggerHeapSnapshot(filename, optionArray, options?.path);
100+
return triggerHeapSnapshot(filename, optionArray, options?.path, options.encoding);
97101
}
98102

99103
/**

src/heap_utils.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "permission/permission.h"
77
#include "stream_base-inl.h"
88
#include "util-inl.h"
9+
#include "string_bytes.h"
910

1011
// Copied from https://github.com/nodejs/node/blob/b07dc4d19fdbc15b4f76557dc45b3ce3a43ad0c3/src/util.cc#L36-L41.
1112
#ifdef _WIN32
@@ -448,14 +449,16 @@ void CreateHeapSnapshotStream(const FunctionCallbackInfo<Value>& args) {
448449
void TriggerHeapSnapshot(const FunctionCallbackInfo<Value>& args) {
449450
Environment* env = Environment::GetCurrent(args);
450451
Isolate* isolate = args.GetIsolate();
451-
CHECK_EQ(args.Length(), 3);
452+
CHECK_EQ(args.Length(), 4);
452453
Local<Value> filename_v = args[0];
453454
auto options = GetHeapSnapshotOptions(args[1]);
454455
bool has_path = !args[2]->IsUndefined() && !args[2]->IsNull();
455456
std::string final_filename;
456457
BufferValue path_v(isolate, args[2]);
457458
ToNamespacedPath(env, &path_v);
458459

460+
const enum encoding encoding = ParseEncoding(isolate, args[3], UTF8);
461+
459462
if (filename_v->IsUndefined()) {
460463
DiagnosticFilename name(env, "Heap", "heapsnapshot");
461464
if (!has_path) {
@@ -492,8 +495,11 @@ void TriggerHeapSnapshot(const FunctionCallbackInfo<Value>& args) {
492495

493496
if (WriteSnapshot(env, final_filename.c_str(), options).IsNothing()) return;
494497

495-
args.GetReturnValue().Set(
496-
String::NewFromUtf8(isolate, final_filename.c_str()).ToLocalChecked());
498+
Local<Value> ret;
499+
if (StringBytes::Encode(isolate, final_filename.c_str(), encoding)
500+
.ToLocal(&ret)) {
501+
args.GetReturnValue().Set(ret);
502+
}
497503
}
498504

499505
void Initialize(Local<Object> target,

src/node_internals.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,16 +447,17 @@ namespace heap {
447447
v8::Maybe<void> WriteSnapshot(Environment* env,
448448
const char* filename,
449449
v8::HeapProfiler::HeapSnapshotOptions options);
450-
}
451-
452-
namespace heap {
453450

454451
void DeleteHeapSnapshot(const v8::HeapSnapshot* snapshot);
455452
using HeapSnapshotPointer =
456453
DeleteFnPtr<const v8::HeapSnapshot, DeleteHeapSnapshot>;
457454

458455
BaseObjectPtr<AsyncWrap> CreateHeapSnapshotStream(
459456
Environment* env, HeapSnapshotPointer&& snapshot);
457+
458+
v8::HeapProfiler::HeapSnapshotOptions GetHeapSnapshotOptions(
459+
v8::Local<v8::Value> options);
460+
460461
} // namespace heap
461462

462463
node_module napi_module_to_node_module(const napi_module* mod);
@@ -485,11 +486,6 @@ std::ostream& operator<<(std::ostream& output,
485486

486487
bool linux_at_secure();
487488

488-
namespace heap {
489-
v8::HeapProfiler::HeapSnapshotOptions GetHeapSnapshotOptions(
490-
v8::Local<v8::Value> options);
491-
} // namespace heap
492-
493489
enum encoding ParseEncoding(v8::Isolate* isolate,
494490
v8::Local<v8::Value> encoding_v,
495491
v8::Local<v8::Value> encoding_id,

0 commit comments

Comments
 (0)