Skip to content

Commit

Permalink
src: merge debug-only SealHandleScopes
Browse files Browse the repository at this point in the history
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 <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
  • Loading branch information
addaleax authored and BridgeAR committed Mar 14, 2019
1 parent 8e7204e commit edc4af0
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 31 deletions.
5 changes: 1 addition & 4 deletions src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ using v8::MaybeLocal;
using v8::Message;
using v8::MicrotasksPolicy;
using v8::ObjectTemplate;
using v8::SealHandleScope;
using v8::String;
using v8::Value;

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

static bool ShouldAbortOnUncaughtException(Isolate* isolate) {
#ifdef DEBUG
SealHandleScope scope(isolate);
#endif
DebugSealHandleScope scope(isolate);
Environment* env = Environment::GetCurrent(isolate);
return env != nullptr &&
(env->is_main_thread() || !env->is_stopping_worker()) &&
Expand Down
7 changes: 2 additions & 5 deletions src/api/hooks.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "env-inl.h"
#include "node.h"
#include "node_internals.h"
#include "node_process.h"
#include "async_wrap.h"

Expand All @@ -11,7 +11,6 @@ using v8::Integer;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::SealHandleScope;
using v8::String;
using v8::Value;
using v8::NewStringType;
Expand Down Expand Up @@ -116,9 +115,7 @@ async_context EmitAsyncInit(Isolate* isolate,
Local<Object> resource,
Local<String> name,
async_id trigger_async_id) {
#ifdef DEBUG
SealHandleScope handle_scope(isolate);
#endif
DebugSealHandleScope handle_scope(isolate);
Environment* env = Environment::GetCurrent(isolate);
CHECK_NOT_NULL(env);

Expand Down
4 changes: 1 addition & 3 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -644,9 +644,7 @@ void Environment::RunAndClearNativeImmediates() {
auto drain_list = [&]() {
TryCatchScope try_catch(this);
for (auto it = list.begin(); it != list.end(); ++it) {
#ifdef DEBUG
v8::SealHandleScope seal_handle_scope(isolate());
#endif
DebugSealHandleScope seal_handle_scope(isolate());
it->cb_(this, it->data_);
if (it->refed_)
ref_count++;
Expand Down
14 changes: 14 additions & 0 deletions src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,20 @@ class InternalCallbackScope {
bool closed_ = false;
};

class DebugSealHandleScope {
public:
explicit inline DebugSealHandleScope(v8::Isolate* isolate)
#ifdef DEBUG
: actual_scope_(isolate)
#endif
{}

private:
#ifdef DEBUG
v8::SealHandleScope actual_scope_;
#endif
};

class ThreadPoolWork {
public:
explicit inline ThreadPoolWork(Environment* env) : env_(env) {
Expand Down
5 changes: 1 addition & 4 deletions src/node_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::Platform;
using v8::SealHandleScope;
using v8::Task;
using node::tracing::TracingController;

Expand Down Expand Up @@ -332,9 +331,7 @@ int NodePlatform::NumberOfWorkerThreads() {

void PerIsolatePlatformData::RunForegroundTask(std::unique_ptr<Task> task) {
Isolate* isolate = Isolate::GetCurrent();
#ifdef DEBUG
SealHandleScope scope(isolate);
#endif
DebugSealHandleScope scope(isolate);
Environment* env = Environment::GetCurrent(isolate);
if (env != nullptr) {
InternalCallbackScope cb_scope(env, Local<Object>(), { 0, 0 },
Expand Down
20 changes: 5 additions & 15 deletions src/stream_base-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,39 +113,29 @@ inline void StreamResource::RemoveStreamListener(StreamListener* listener) {
}

inline uv_buf_t StreamResource::EmitAlloc(size_t suggested_size) {
#ifdef DEBUG
v8::SealHandleScope handle_scope(v8::Isolate::GetCurrent());
#endif
DebugSealHandleScope handle_scope(v8::Isolate::GetCurrent());
return listener_->OnStreamAlloc(suggested_size);
}

inline void StreamResource::EmitRead(ssize_t nread, const uv_buf_t& buf) {
#ifdef DEBUG
v8::SealHandleScope handle_scope(v8::Isolate::GetCurrent());
#endif
DebugSealHandleScope handle_scope(v8::Isolate::GetCurrent());
if (nread > 0)
bytes_read_ += static_cast<uint64_t>(nread);
listener_->OnStreamRead(nread, buf);
}

inline void StreamResource::EmitAfterWrite(WriteWrap* w, int status) {
#ifdef DEBUG
v8::SealHandleScope handle_scope(v8::Isolate::GetCurrent());
#endif
DebugSealHandleScope handle_scope(v8::Isolate::GetCurrent());
listener_->OnStreamAfterWrite(w, status);
}

inline void StreamResource::EmitAfterShutdown(ShutdownWrap* w, int status) {
#ifdef DEBUG
v8::SealHandleScope handle_scope(v8::Isolate::GetCurrent());
#endif
DebugSealHandleScope handle_scope(v8::Isolate::GetCurrent());
listener_->OnStreamAfterShutdown(w, status);
}

inline void StreamResource::EmitWantsWrite(size_t suggested_size) {
#ifdef DEBUG
v8::SealHandleScope handle_scope(v8::Isolate::GetCurrent());
#endif
DebugSealHandleScope handle_scope(v8::Isolate::GetCurrent());
listener_->OnStreamWantsWrite(suggested_size);
}

Expand Down

0 comments on commit edc4af0

Please sign in to comment.