Skip to content

Commit fb6528f

Browse files
committed
src: add HandleScope to edge loop in heap_utils
1 parent f0b8472 commit fb6528f

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

src/heap_utils.cc

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
#include "stream_base-inl.h"
88
#include "util-inl.h"
99

10-
// Copied from
11-
// https://github.com/nodejs/node/blob/b07dc4d19fdbc15b4f76557dc45b3ce3a43ad0c3/src/util.cc#L36-L41.
10+
// Copied from https://github.com/nodejs/node/blob/b07dc4d19fdbc15b4f76557dc45b3ce3a43ad0c3/src/util.cc#L36-L41.
1211
#ifdef _WIN32
1312
#include <io.h> // _S_IREAD _S_IWRITE
1413
#ifndef S_IRUSR
@@ -81,9 +80,10 @@ class JSGraph : public EmbedderGraph {
8180
explicit JSGraph(Isolate* isolate) : isolate_(isolate) {}
8281

8382
Node* V8Node(const Local<v8::Data>& value) override {
84-
std::unique_ptr<JSGraphJSNode> n{new JSGraphJSNode(isolate_, value)};
83+
std::unique_ptr<JSGraphJSNode> n { new JSGraphJSNode(isolate_, value) };
8584
auto it = engine_nodes_.find(n.get());
86-
if (it != engine_nodes_.end()) return *it;
85+
if (it != engine_nodes_.end())
86+
return *it;
8787
engine_nodes_.insert(n.get());
8888
return AddNode(std::unique_ptr<Node>(n.release()));
8989
}
@@ -187,7 +187,7 @@ class JSGraph : public EmbedderGraph {
187187
const char* edge_name = edge.first;
188188
if (edge_name != nullptr) {
189189
if (!String::NewFromUtf8(isolate_, edge_name)
190-
.ToLocal(&edge_name_value)) {
190+
.ToLocal(&edge_name_value)) {
191191
return MaybeLocal<Array>();
192192
}
193193
} else {
@@ -216,7 +216,8 @@ void BuildEmbedderGraph(const FunctionCallbackInfo<Value>& args) {
216216
JSGraph graph(env->isolate());
217217
Environment::BuildEmbedderGraph(env->isolate(), &graph, env);
218218
Local<Array> ret;
219-
if (graph.CreateObject().ToLocal(&ret)) args.GetReturnValue().Set(ret);
219+
if (graph.CreateObject().ToLocal(&ret))
220+
args.GetReturnValue().Set(ret);
220221
}
221222

222223
namespace {
@@ -235,8 +236,13 @@ class FileOutputStream : public v8::OutputStream {
235236
int offset = 0;
236237
while (offset < size) {
237238
const uv_buf_t buf = uv_buf_init(data + offset, size - offset);
238-
const int num_bytes_written =
239-
uv_fs_write(nullptr, req_, fd_, &buf, 1, -1, nullptr);
239+
const int num_bytes_written = uv_fs_write(nullptr,
240+
req_,
241+
fd_,
242+
&buf,
243+
1,
244+
-1,
245+
nullptr);
240246
uv_fs_req_cleanup(req_);
241247
if (num_bytes_written < 0) {
242248
status_ = num_bytes_written;
@@ -261,12 +267,13 @@ class HeapSnapshotStream : public AsyncWrap,
261267
public StreamBase,
262268
public v8::OutputStream {
263269
public:
264-
HeapSnapshotStream(Environment* env,
265-
HeapSnapshotPointer&& snapshot,
266-
Local<Object> obj)
267-
: AsyncWrap(env, obj, AsyncWrap::PROVIDER_HEAPSNAPSHOT),
268-
StreamBase(env),
269-
snapshot_(std::move(snapshot)) {
270+
HeapSnapshotStream(
271+
Environment* env,
272+
HeapSnapshotPointer&& snapshot,
273+
Local<Object> obj) :
274+
AsyncWrap(env, obj, AsyncWrap::PROVIDER_HEAPSNAPSHOT),
275+
StreamBase(env),
276+
snapshot_(std::move(snapshot)) {
270277
MakeWeak();
271278
StreamBase::AttachToObject(GetObject());
272279
}
@@ -287,7 +294,8 @@ class HeapSnapshotStream : public AsyncWrap,
287294
while (len != 0) {
288295
uv_buf_t buf = EmitAlloc(size);
289296
ssize_t avail = len;
290-
if (static_cast<ssize_t>(buf.len) < avail) avail = buf.len;
297+
if (static_cast<ssize_t>(buf.len) < avail)
298+
avail = buf.len;
291299
memcpy(buf.base, data, avail);
292300
data += avail;
293301
len -= static_cast<int>(avail);
@@ -302,9 +310,13 @@ class HeapSnapshotStream : public AsyncWrap,
302310
return 0;
303311
}
304312

305-
int ReadStop() override { return 0; }
313+
int ReadStop() override {
314+
return 0;
315+
}
306316

307-
int DoShutdown(ShutdownWrap* req_wrap) override { UNREACHABLE(); }
317+
int DoShutdown(ShutdownWrap* req_wrap) override {
318+
UNREACHABLE();
319+
}
308320

309321
int DoWrite(WriteWrap* w,
310322
uv_buf_t* bufs,
@@ -430,7 +442,8 @@ void CreateHeapSnapshotStream(const FunctionCallbackInfo<Value>& args) {
430442
CHECK(snapshot);
431443
BaseObjectPtr<AsyncWrap> stream =
432444
CreateHeapSnapshotStream(env, std::move(snapshot));
433-
if (stream) args.GetReturnValue().Set(stream->object());
445+
if (stream)
446+
args.GetReturnValue().Set(stream->object());
434447
}
435448

436449
void TriggerHeapSnapshot(const FunctionCallbackInfo<Value>& args) {

0 commit comments

Comments
 (0)