| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 36035e0 commit 74b9baa
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -267,6 +267,10 @@ disk unless [`v8.stopCoverage()`][] is invoked before the process exits. | |||
| 267 | 267 | ||
| 268 | 268 | <!-- YAML | |
| 269 | 269 | added: v11.13.0 | |
| 270 | + changes: | ||
| 271 | + - version: REPLACEME | ||
| 272 | + pr-url: https://github.com/nodejs/node/pull/41373 | ||
| 273 | + description: An exception will now be thrown if the file could not be written. | ||
| 270 | 274 | --> | |
| 271 | 275 | ||
| 272 | 276 | * `filename` {string} The file path where the V8 heap snapshot is to be | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1643,7 +1643,7 @@ size_t Environment::NearHeapLimitCallback(void* data, | |||
| 1643 | 1643 | env->isolate()->RemoveNearHeapLimitCallback(NearHeapLimitCallback, | |
| 1644 | 1644 | initial_heap_limit); | |
| 1645 | 1645 | ||
| 1646 | - heap::WriteSnapshot(env->isolate(), filename.c_str()); | ||
| 1646 | + heap::WriteSnapshot(env, filename.c_str()); | ||
| 1647 | 1647 | env->heap_limit_snapshot_taken_ += 1; | |
| 1648 | 1648 | ||
| 1649 | 1649 | // Don't take more snapshots than the number specified by | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -308,21 +308,26 @@ class HeapSnapshotStream : public AsyncWrap, | |||
| 308 | 308 | HeapSnapshotPointer snapshot_; | |
| 309 | 309 | }; | |
| 310 | 310 | ||
| 311 | - inline void TakeSnapshot(Isolate* isolate, v8::OutputStream* out) { | ||
| 311 | + inline void TakeSnapshot(Environment* env, v8::OutputStream* out) { | ||
| 312 | 312 | HeapSnapshotPointer snapshot { | |
| 313 | - isolate->GetHeapProfiler()->TakeHeapSnapshot() }; | ||
| 313 | + env->isolate()->GetHeapProfiler()->TakeHeapSnapshot() }; | ||
| 314 | 314 | snapshot->Serialize(out, HeapSnapshot::kJSON); | |
| 315 | 315 | } | |
| 316 | 316 | ||
| 317 | 317 | } // namespace | |
| 318 | 318 | ||
| 319 | - bool WriteSnapshot(Isolate* isolate, const char* filename) { | ||
| 319 | + bool WriteSnapshot(Environment* env, const char* filename) { | ||
| 320 | 320 | FILE* fp = fopen(filename, "w"); | |
| 321 | - if (fp == nullptr) | ||
| 321 | + if (fp == nullptr) { | ||
| 322 | + env->ThrowErrnoException(errno, "open"); | ||
| 322 | 323 | return false; | |
| 324 | + } | ||
| 323 | 325 | FileOutputStream stream(fp); | |
| 324 | - TakeSnapshot(isolate, &stream); | ||
| 325 | - fclose(fp); | ||
| 326 | + TakeSnapshot(env, &stream); | ||
| 327 | + if (fclose(fp) == EOF) { | ||
| 328 | + env->ThrowErrnoException(errno, "close"); | ||
| 329 | + return false; | ||
| 330 | + } | ||
| 326 | 331 | return true; | |
| 327 | 332 | } | |
| 328 | 333 | ||
@@ -374,7 +379,7 @@ void TriggerHeapSnapshot(const FunctionCallbackInfo<Value>& args) { | |||
| 374 | 379 | ||
| 375 | 380 | if (filename_v->IsUndefined()) { | |
| 376 | 381 | DiagnosticFilename name(env, "Heap", "heapsnapshot"); | |
| 377 | - if (!WriteSnapshot(isolate, *name)) | ||
| 382 | + if (!WriteSnapshot(env, *name)) | ||
| 378 | 383 | return; | |
| 379 | 384 | if (String::NewFromUtf8(isolate, *name).ToLocal(&filename_v)) { | |
| 380 | 385 | args.GetReturnValue().Set(filename_v); | |
@@ -384,7 +389,7 @@ void TriggerHeapSnapshot(const FunctionCallbackInfo<Value>& args) { | |||
| 384 | 389 | ||
| 385 | 390 | BufferValue path(isolate, filename_v); | |
| 386 | 391 | CHECK_NOT_NULL(*path); | |
| 387 | - if (!WriteSnapshot(isolate, *path)) | ||
| 392 | + if (!WriteSnapshot(env, *path)) | ||
| 388 | 393 | return; | |
| 389 | 394 | return args.GetReturnValue().Set(filename_v); | |
| 390 | 395 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -379,7 +379,7 @@ class DiagnosticFilename { | |||
| 379 | 379 | }; | |
| 380 | 380 | ||
| 381 | 381 | namespace heap { | |
| 382 | - bool WriteSnapshot(v8::Isolate* isolate, const char* filename); | ||
| 382 | + bool WriteSnapshot(Environment* env, const char* filename); | ||
| 383 | 383 | } | |
| 384 | 384 | ||
| 385 | 385 | class TraceEventScope { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,6 +24,19 @@ process.chdir(tmpdir.path); | |||
| 24 | 24 | fs.accessSync(heapdump); | |
| 25 | 25 | } | |
| 26 | 26 | ||
| 27 | + { | ||
| 28 | + const readonlyFile = 'ro'; | ||
| 29 | + fs.writeFileSync(readonlyFile, Buffer.alloc(0), { mode: 0o444 }); | ||
| 30 | + assert.throws(() => { | ||
| 31 | + writeHeapSnapshot(readonlyFile); | ||
| 32 | + }, (e) => { | ||
| 33 | + assert.ok(e, 'writeHeapSnapshot should error'); | ||
| 34 | + assert.strictEqual(e.code, 'EACCES'); | ||
| 35 | + assert.strictEqual(e.syscall, 'open'); | ||
| 36 | + return true; | ||
| 37 | + }); | ||
| 38 | + } | ||
| 39 | + | ||
| 27 | 40 | [1, true, {}, [], null, Infinity, NaN].forEach((i) => { | |
| 28 | 41 | assert.throws(() => writeHeapSnapshot(i), { | |
| 29 | 42 | code: 'ERR_INVALID_ARG_TYPE', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments