|
6 | 6 | #include "permission/permission.h" |
7 | 7 | #include "stream_base-inl.h" |
8 | 8 | #include "util-inl.h" |
| 9 | +#include "string_bytes.h" |
9 | 10 |
|
10 | 11 | // Copied from https://github.com/nodejs/node/blob/b07dc4d19fdbc15b4f76557dc45b3ce3a43ad0c3/src/util.cc#L36-L41. |
11 | 12 | #ifdef _WIN32 |
@@ -448,14 +449,16 @@ void CreateHeapSnapshotStream(const FunctionCallbackInfo<Value>& args) { |
448 | 449 | void TriggerHeapSnapshot(const FunctionCallbackInfo<Value>& args) { |
449 | 450 | Environment* env = Environment::GetCurrent(args); |
450 | 451 | Isolate* isolate = args.GetIsolate(); |
451 | | - CHECK_EQ(args.Length(), 3); |
| 452 | + CHECK_EQ(args.Length(), 4); |
452 | 453 | Local<Value> filename_v = args[0]; |
453 | 454 | auto options = GetHeapSnapshotOptions(args[1]); |
454 | 455 | bool has_path = !args[2]->IsUndefined() && !args[2]->IsNull(); |
455 | 456 | std::string final_filename; |
456 | 457 | BufferValue path_v(isolate, args[2]); |
457 | 458 | ToNamespacedPath(env, &path_v); |
458 | 459 |
|
| 460 | + const enum encoding encoding = ParseEncoding(isolate, args[3], UTF8); |
| 461 | + |
459 | 462 | if (filename_v->IsUndefined()) { |
460 | 463 | DiagnosticFilename name(env, "Heap", "heapsnapshot"); |
461 | 464 | if (!has_path) { |
@@ -492,8 +495,11 @@ void TriggerHeapSnapshot(const FunctionCallbackInfo<Value>& args) { |
492 | 495 |
|
493 | 496 | if (WriteSnapshot(env, final_filename.c_str(), options).IsNothing()) return; |
494 | 497 |
|
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 | + } |
497 | 503 | } |
498 | 504 |
|
499 | 505 | void Initialize(Local<Object> target, |
|
0 commit comments