Skip to content

Commit edc4af0

Browse files
addaleaxBridgeAR
authored andcommitted
src: merge debug-only SealHandleScopes
Instead of repeating the same `#ifdef DEBUG` + `SealHandleScope` pattern over and over, create an utility that does this for us. PR-URL: #26459 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent 8e7204e commit edc4af0

File tree

6 files changed

+24
-31
lines changed

6 files changed

+24
-31
lines changed

Diff for: src/api/environment.cc

+1-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ using v8::MaybeLocal;
2323
using v8::Message;
2424
using v8::MicrotasksPolicy;
2525
using v8::ObjectTemplate;
26-
using v8::SealHandleScope;
2726
using v8::String;
2827
using v8::Value;
2928

@@ -35,9 +34,7 @@ static bool AllowWasmCodeGenerationCallback(Local<Context> context,
3534
}
3635

3736
static bool ShouldAbortOnUncaughtException(Isolate* isolate) {
38-
#ifdef DEBUG
39-
SealHandleScope scope(isolate);
40-
#endif
37+
DebugSealHandleScope scope(isolate);
4138
Environment* env = Environment::GetCurrent(isolate);
4239
return env != nullptr &&
4340
(env->is_main_thread() || !env->is_stopping_worker()) &&

Diff for: src/api/hooks.cc

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "env-inl.h"
2-
#include "node.h"
2+
#include "node_internals.h"
33
#include "node_process.h"
44
#include "async_wrap.h"
55

@@ -11,7 +11,6 @@ using v8::Integer;
1111
using v8::Isolate;
1212
using v8::Local;
1313
using v8::Object;
14-
using v8::SealHandleScope;
1514
using v8::String;
1615
using v8::Value;
1716
using v8::NewStringType;
@@ -116,9 +115,7 @@ async_context EmitAsyncInit(Isolate* isolate,
116115
Local<Object> resource,
117116
Local<String> name,
118117
async_id trigger_async_id) {
119-
#ifdef DEBUG
120-
SealHandleScope handle_scope(isolate);
121-
#endif
118+
DebugSealHandleScope handle_scope(isolate);
122119
Environment* env = Environment::GetCurrent(isolate);
123120
CHECK_NOT_NULL(env);
124121

Diff for: src/env.cc

+1-3
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,7 @@ void Environment::RunAndClearNativeImmediates() {
644644
auto drain_list = [&]() {
645645
TryCatchScope try_catch(this);
646646
for (auto it = list.begin(); it != list.end(); ++it) {
647-
#ifdef DEBUG
648-
v8::SealHandleScope seal_handle_scope(isolate());
649-
#endif
647+
DebugSealHandleScope seal_handle_scope(isolate());
650648
it->cb_(this, it->data_);
651649
if (it->refed_)
652650
ref_count++;

Diff for: src/node_internals.h

+14
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,20 @@ class InternalCallbackScope {
217217
bool closed_ = false;
218218
};
219219

220+
class DebugSealHandleScope {
221+
public:
222+
explicit inline DebugSealHandleScope(v8::Isolate* isolate)
223+
#ifdef DEBUG
224+
: actual_scope_(isolate)
225+
#endif
226+
{}
227+
228+
private:
229+
#ifdef DEBUG
230+
v8::SealHandleScope actual_scope_;
231+
#endif
232+
};
233+
220234
class ThreadPoolWork {
221235
public:
222236
explicit inline ThreadPoolWork(Environment* env) : env_(env) {

Diff for: src/node_platform.cc

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ using v8::Isolate;
1212
using v8::Local;
1313
using v8::Object;
1414
using v8::Platform;
15-
using v8::SealHandleScope;
1615
using v8::Task;
1716
using node::tracing::TracingController;
1817

@@ -332,9 +331,7 @@ int NodePlatform::NumberOfWorkerThreads() {
332331

333332
void PerIsolatePlatformData::RunForegroundTask(std::unique_ptr<Task> task) {
334333
Isolate* isolate = Isolate::GetCurrent();
335-
#ifdef DEBUG
336-
SealHandleScope scope(isolate);
337-
#endif
334+
DebugSealHandleScope scope(isolate);
338335
Environment* env = Environment::GetCurrent(isolate);
339336
if (env != nullptr) {
340337
InternalCallbackScope cb_scope(env, Local<Object>(), { 0, 0 },

Diff for: src/stream_base-inl.h

+5-15
Original file line numberDiff line numberDiff line change
@@ -113,39 +113,29 @@ inline void StreamResource::RemoveStreamListener(StreamListener* listener) {
113113
}
114114

115115
inline uv_buf_t StreamResource::EmitAlloc(size_t suggested_size) {
116-
#ifdef DEBUG
117-
v8::SealHandleScope handle_scope(v8::Isolate::GetCurrent());
118-
#endif
116+
DebugSealHandleScope handle_scope(v8::Isolate::GetCurrent());
119117
return listener_->OnStreamAlloc(suggested_size);
120118
}
121119

122120
inline void StreamResource::EmitRead(ssize_t nread, const uv_buf_t& buf) {
123-
#ifdef DEBUG
124-
v8::SealHandleScope handle_scope(v8::Isolate::GetCurrent());
125-
#endif
121+
DebugSealHandleScope handle_scope(v8::Isolate::GetCurrent());
126122
if (nread > 0)
127123
bytes_read_ += static_cast<uint64_t>(nread);
128124
listener_->OnStreamRead(nread, buf);
129125
}
130126

131127
inline void StreamResource::EmitAfterWrite(WriteWrap* w, int status) {
132-
#ifdef DEBUG
133-
v8::SealHandleScope handle_scope(v8::Isolate::GetCurrent());
134-
#endif
128+
DebugSealHandleScope handle_scope(v8::Isolate::GetCurrent());
135129
listener_->OnStreamAfterWrite(w, status);
136130
}
137131

138132
inline void StreamResource::EmitAfterShutdown(ShutdownWrap* w, int status) {
139-
#ifdef DEBUG
140-
v8::SealHandleScope handle_scope(v8::Isolate::GetCurrent());
141-
#endif
133+
DebugSealHandleScope handle_scope(v8::Isolate::GetCurrent());
142134
listener_->OnStreamAfterShutdown(w, status);
143135
}
144136

145137
inline void StreamResource::EmitWantsWrite(size_t suggested_size) {
146-
#ifdef DEBUG
147-
v8::SealHandleScope handle_scope(v8::Isolate::GetCurrent());
148-
#endif
138+
DebugSealHandleScope handle_scope(v8::Isolate::GetCurrent());
149139
listener_->OnStreamWantsWrite(suggested_size);
150140
}
151141

0 commit comments

Comments
 (0)