GeezerVison is showing github.com — permission: support v8.setHeapSnapshotNearHeapLimit · nodejs/node@e970e67
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/node_v8.cc +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
27 | 27 | #include "node.h" |
28 | 28 | #include "node_external_reference.h" |
29 | 29 | #include "node_profiling.h" |
| 30 | +#include "permission/permission.h" |
30 | 31 | #include "util-inl.h" |
31 | 32 | #include "v8-profiler.h" |
32 | 33 | #include "v8.h" |
@@ -200,6 +201,14 @@ void SetHeapSnapshotNearHeapLimit(const FunctionCallbackInfo<Value>& args) { |
200 | 201 | Environment* env = Environment::GetCurrent(args); |
201 | 202 | uint32_t limit = args[0].As<v8::Uint32>()->Value(); |
202 | 203 | CHECK_GT(limit, 0); |
| 204 | + |
| 205 | + std::string dir = env->options()->diagnostic_dir; |
| 206 | + if (dir.empty()) { |
| 207 | + dir = Environment::GetCwd(env->exec_path()); |
| 208 | + } |
| 209 | + THROW_IF_INSUFFICIENT_PERMISSIONS( |
| 210 | + env, permission::PermissionScope::kFileSystemWrite, dir); |
| 211 | + |
203 | 212 | env->AddHeapSnapshotNearHeapLimitCallback(); |
204 | 213 | env->set_heap_snapshot_near_heap_limit(limit); |
205 | 214 | } |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-permission-fs-write-v8.js +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,3 +34,12 @@ const path = require('path'); |
34 | 34 | permission: 'FileSystemWrite', |
35 | 35 | })); |
36 | 36 | } |
| 37 | + |
| 38 | +{ |
| 39 | + assert.throws(() => { |
| 40 | + v8.setHeapSnapshotNearHeapLimit(1); |
| 41 | + }, common.expectsError({ |
| 42 | + code: 'ERR_ACCESS_DENIED', |
| 43 | + permission: 'FileSystemWrite', |
| 44 | + })); |
| 45 | +} |