Skip to content

Commit

Permalink
add v8::Locker around callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
blattersturm committed Nov 7, 2017
1 parent f76ce0a commit ad8ca65
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config.gypi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# idk
{

}
1 change: 1 addition & 0 deletions src/async-wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ RetainedObjectInfo* WrapperInfo(uint16_t class_id, Local<Value> wrapper) {
static void DestroyAsyncIdsCallback(uv_timer_t* handle) {
Environment* env = Environment::from_destroy_async_ids_timer_handle(handle);

v8::Locker locker(env->isolate());
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());
Local<Function> fn = env->async_hooks_destroy_function();
Expand Down
2 changes: 2 additions & 0 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
GetAddrInfoReqWrap* req_wrap = static_cast<GetAddrInfoReqWrap*>(req->data);
Environment* env = req_wrap->env();

v8::Locker locker(env->isolate());
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());

Expand Down Expand Up @@ -1876,6 +1877,7 @@ void AfterGetNameInfo(uv_getnameinfo_t* req,
GetNameInfoReqWrap* req_wrap = static_cast<GetNameInfoReqWrap*>(req->data);
Environment* env = req_wrap->env();

v8::Locker locker(env->isolate());
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());

Expand Down
2 changes: 2 additions & 0 deletions src/connection_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void ConnectionWrap<WrapType, UVType>::OnConnection(uv_stream_t* handle,
CHECK_EQ(&wrap_data->handle_, reinterpret_cast<UVType*>(handle));

Environment* env = wrap_data->env();
v8::Locker locker(env->isolate());
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());

Expand Down Expand Up @@ -82,6 +83,7 @@ void ConnectionWrap<WrapType, UVType>::AfterConnect(uv_connect_t* req,
CHECK_EQ(req_wrap->env(), wrap->env());
Environment* env = wrap->env();

v8::Locker locker(env->isolate());
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());

Expand Down
1 change: 1 addition & 0 deletions src/fs_event_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
FSEventWrap* wrap = static_cast<FSEventWrap*>(handle->data);
Environment* env = wrap->env();

v8::Locker locker(env->isolate());
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());

Expand Down
1 change: 1 addition & 0 deletions src/handle_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ HandleWrap::~HandleWrap() {
void HandleWrap::OnClose(uv_handle_t* handle) {
HandleWrap* wrap = static_cast<HandleWrap*>(handle->data);
Environment* env = wrap->env();
v8::Locker locker(env->isolate());
HandleScope scope(env->isolate());
Context::Scope context_scope(env->context());

Expand Down
1 change: 1 addition & 0 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ void After(uv_fs_t *req) {
req_wrap->ReleaseEarly(); // Free memory that's no longer used now.

Environment* env = req_wrap->env();
v8::Locker locker(env->isolate());
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());

Expand Down
13 changes: 13 additions & 0 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Http2Session::Http2Session(Environment* env,
prep_->data = static_cast<void*>(this);
uv_prepare_start(prep_, [](uv_prepare_t* t) {
Http2Session* session = static_cast<Http2Session*>(t->data);
v8::Locker locker(session->env()->isolate());
HandleScope scope(session->env()->isolate());
Context::Scope context_scope(session->env()->context());

Expand Down Expand Up @@ -133,6 +134,7 @@ ssize_t Http2Session::OnCallbackPadding(size_t frameLen,
Isolate* isolate = env()->isolate();
Local<Context> context = env()->context();

v8::Locker locker(isolate);
HandleScope handle_scope(isolate);
Context::Scope context_scope(context);

Expand Down Expand Up @@ -178,6 +180,7 @@ void HttpErrorString(const FunctionCallbackInfo<Value>& args) {
// output for an HTTP2-Settings header field.
void PackSettings(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
v8::Locker locker(env->isolate());
HandleScope scope(env->isolate());

std::vector<nghttp2_settings_entry> entries;
Expand Down Expand Up @@ -813,6 +816,7 @@ void Http2Session::UpdateChunksSent(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = env->isolate();
ASSIGN_OR_RETURN_UNWRAP(&session, args.Holder());

v8::Locker locker(isolate);
HandleScope scope(isolate);

uint32_t length = session->chunks_sent_since_last_write_;
Expand Down Expand Up @@ -928,6 +932,7 @@ void Http2Session::OnTrailers(Nghttp2Stream* stream,
stream->id());
Local<Context> context = env()->context();
Isolate* isolate = env()->isolate();
v8::Locker locker(isolate);
HandleScope scope(isolate);
Context::Scope context_scope(context);

Expand Down Expand Up @@ -956,6 +961,7 @@ void Http2Session::OnHeaders(
Local<Context> context = env()->context();
Isolate* isolate = env()->isolate();
Context::Scope context_scope(context);
v8::Locker locker(isolate);
HandleScope scope(isolate);
Local<String> name_str;
Local<String> value_str;
Expand Down Expand Up @@ -1010,6 +1016,7 @@ void Http2Session::OnHeaders(
void Http2Session::OnStreamClose(int32_t id, uint32_t code) {
Isolate* isolate = env()->isolate();
Local<Context> context = env()->context();
v8::Locker locker(isolate);
HandleScope scope(isolate);
Context::Scope context_scope(context);

Expand All @@ -1025,6 +1032,7 @@ void Http2Session::OnDataChunk(
uv_buf_t* chunk) {
Isolate* isolate = env()->isolate();
Local<Context> context = env()->context();
v8::Locker locker(isolate);
HandleScope scope(isolate);
Local<Object> obj = Object::New(isolate);
obj->Set(context,
Expand All @@ -1042,6 +1050,7 @@ void Http2Session::OnDataChunk(
void Http2Session::OnSettings(bool ack) {
Local<Context> context = env()->context();
Isolate* isolate = env()->isolate();
v8::Locker locker(isolate);
HandleScope scope(isolate);
Context::Scope context_scope(context);

Expand All @@ -1052,6 +1061,7 @@ void Http2Session::OnSettings(bool ack) {
void Http2Session::OnFrameError(int32_t id, uint8_t type, int error_code) {
Local<Context> context = env()->context();
Isolate* isolate = env()->isolate();
v8::Locker locker(isolate);
HandleScope scope(isolate);
Context::Scope context_scope(context);

Expand All @@ -1069,6 +1079,7 @@ void Http2Session::OnPriority(int32_t stream,
int8_t exclusive) {
Local<Context> context = env()->context();
Isolate* isolate = env()->isolate();
v8::Locker locker(isolate);
HandleScope scope(isolate);
Context::Scope context_scope(context);

Expand All @@ -1087,6 +1098,7 @@ void Http2Session::OnGoAway(int32_t lastStreamID,
size_t length) {
Local<Context> context = env()->context();
Isolate* isolate = env()->isolate();
v8::Locker locker(isolate);
HandleScope scope(isolate);
Context::Scope context_scope(context);

Expand Down Expand Up @@ -1247,6 +1259,7 @@ void Initialize(Local<Object> target,
void* priv) {
Environment* env = Environment::GetCurrent(context);
Isolate* isolate = env->isolate();
v8::Locker locker(isolate);
HandleScope scope(isolate);

http2_state* state = new http2_state(isolate);
Expand Down
1 change: 1 addition & 0 deletions src/node_perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ void PerformanceGCCallback(uv_async_t* handle) {
static_cast<PerformanceEntry::Data*>(handle->data);
Environment* env = data->env();
Isolate* isolate = env->isolate();
v8::Locker locker(env->isolate());
HandleScope scope(isolate);
Local<Context> context = env->context();
Context::Scope context_scope(context);
Expand Down
1 change: 1 addition & 0 deletions src/node_stat_watcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ void StatWatcher::Callback(uv_fs_poll_t* handle,
StatWatcher* wrap = static_cast<StatWatcher*>(handle->data);
CHECK_EQ(wrap->watcher_, handle);
Environment* env = wrap->env();
v8::Locker locker(wrap->env()->isolate());
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());

Expand Down
1 change: 1 addition & 0 deletions src/node_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace node {

inline uv_stream_t* HandleToStream(Environment* env,
v8::Local<v8::Object> obj) {
v8::Locker locker(env->isolate());
v8::HandleScope scope(env->isolate());

WITH_GENERIC_UV_STREAM(env, obj, {
Expand Down
1 change: 1 addition & 0 deletions src/process_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ class ProcessWrap : public HandleWrap {
CHECK_EQ(&wrap->process_, handle);

Environment* env = wrap->env();
v8::Locker locker(wrap->env()->isolate());
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());

Expand Down
1 change: 1 addition & 0 deletions src/signal_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class SignalWrap : public HandleWrap {
static void OnSignal(uv_signal_t* handle, int signum) {
SignalWrap* wrap = ContainerOf(&SignalWrap::handle_, handle);
Environment* env = wrap->env();
v8::Locker locker(wrap->env()->isolate());
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());

Expand Down
2 changes: 2 additions & 0 deletions src/stream_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ void StreamBase::AfterShutdown(ShutdownWrap* req_wrap, int status) {
// The wrap and request objects should still be there.
CHECK_EQ(req_wrap->persistent().IsEmpty(), false);

v8::Locker locker(env->isolate());
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());

Expand Down Expand Up @@ -399,6 +400,7 @@ void StreamBase::AfterWrite(WriteWrap* req_wrap, int status) {
StreamBase* wrap = req_wrap->wrap();
Environment* env = req_wrap->env();

v8::Locker locker(env->isolate());
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());

Expand Down
7 changes: 7 additions & 0 deletions src/stream_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ bool LibuvStreamWrap::IsIPCPipe() {


uint32_t LibuvStreamWrap::UpdateWriteQueueSize() {
v8::Locker locker(env()->isolate());
HandleScope scope(env()->isolate());
uint32_t write_queue_size = stream()->write_queue_size;
object()->Set(env()->context(),
Expand All @@ -170,6 +171,7 @@ void LibuvStreamWrap::OnAlloc(uv_handle_t* handle,
size_t suggested_size,
uv_buf_t* buf) {
LibuvStreamWrap* wrap = static_cast<LibuvStreamWrap*>(handle->data);
v8::Locker locker(wrap->env()->isolate());
HandleScope scope(wrap->env()->isolate());
Context::Scope context_scope(wrap->env()->context());

Expand All @@ -187,6 +189,7 @@ void LibuvStreamWrap::OnAllocImpl(size_t size, uv_buf_t* buf, void* ctx) {

template <class WrapType, class UVType>
static Local<Object> AcceptHandle(Environment* env, LibuvStreamWrap* parent) {
v8::Locker locker(env->isolate());
EscapableHandleScope scope(env->isolate());
Local<Object> wrap_obj;
UVType* handle;
Expand All @@ -212,6 +215,7 @@ void LibuvStreamWrap::OnReadImpl(ssize_t nread,
void* ctx) {
LibuvStreamWrap* wrap = static_cast<LibuvStreamWrap*>(ctx);
Environment* env = wrap->env();
v8::Locker locker(wrap->env()->isolate());
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());

Expand Down Expand Up @@ -252,6 +256,7 @@ void LibuvStreamWrap::OnRead(uv_stream_t* handle,
ssize_t nread,
const uv_buf_t* buf) {
LibuvStreamWrap* wrap = static_cast<LibuvStreamWrap*>(handle->data);
v8::Locker locker(wrap->env()->isolate());
HandleScope scope(wrap->env()->isolate());
Context::Scope context_scope(wrap->env()->context());
uv_handle_type type = UV_UNKNOWN_HANDLE;
Expand Down Expand Up @@ -311,6 +316,7 @@ int LibuvStreamWrap::DoShutdown(ShutdownWrap* req_wrap) {
void LibuvStreamWrap::AfterShutdown(uv_shutdown_t* req, int status) {
ShutdownWrap* req_wrap = ShutdownWrap::from_req(req);
CHECK_NE(req_wrap, nullptr);
v8::Locker locker(req_wrap->env()->isolate());
HandleScope scope(req_wrap->env()->isolate());
Context::Scope context_scope(req_wrap->env()->context());
req_wrap->Done(status);
Expand Down Expand Up @@ -389,6 +395,7 @@ int LibuvStreamWrap::DoWrite(WriteWrap* w,
void LibuvStreamWrap::AfterWrite(uv_write_t* req, int status) {
WriteWrap* req_wrap = WriteWrap::from_req(req);
CHECK_NE(req_wrap, nullptr);
v8::Locker locker(req_wrap->env()->isolate());
HandleScope scope(req_wrap->env()->isolate());
Context::Scope context_scope(req_wrap->env()->context());
req_wrap->Done(status);
Expand Down
2 changes: 2 additions & 0 deletions src/tcp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ using AsyncHooks = Environment::AsyncHooks;


Local<Object> TCPWrap::Instantiate(Environment* env, AsyncWrap* parent) {
v8::Locker locker(env->isolate());
EscapableHandleScope handle_scope(env->isolate());
AsyncHooks::InitScope init_scope(env, parent->get_async_id());
CHECK_EQ(env->tcp_constructor_template().IsEmpty(), false);
Expand Down Expand Up @@ -324,6 +325,7 @@ void TCPWrap::Connect6(const FunctionCallbackInfo<Value>& args) {
Local<Object> AddressToJS(Environment* env,
const sockaddr* addr,
Local<Object> info) {
v8::Locker locker(env->isolate());
EscapableHandleScope scope(env->isolate());
char ip[INET6_ADDRSTRLEN];
const sockaddr_in *a4;
Expand Down
1 change: 1 addition & 0 deletions src/timer_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class TimerWrap : public HandleWrap {
static void OnTimeout(uv_timer_t* handle) {
TimerWrap* wrap = static_cast<TimerWrap*>(handle->data);
Environment* env = wrap->env();
v8::Locker locker(env->isolate());
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());
wrap->MakeCallback(kOnTimeout, 0, nullptr);
Expand Down
3 changes: 3 additions & 0 deletions src/udp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ void UDPWrap::OnSend(uv_udp_send_t* req, int status) {
SendWrap* req_wrap = static_cast<SendWrap*>(req->data);
if (req_wrap->have_callback()) {
Environment* env = req_wrap->env();
v8::Locker locker(env->isolate());
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());
Local<Value> arg[] = {
Expand Down Expand Up @@ -470,6 +471,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle,
UDPWrap* wrap = static_cast<UDPWrap*>(handle->data);
Environment* env = wrap->env();

v8::Locker locker(env->isolate());
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());

Expand All @@ -496,6 +498,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle,


Local<Object> UDPWrap::Instantiate(Environment* env, AsyncWrap* parent) {
v8::Locker locker(env->isolate());
EscapableHandleScope scope(env->isolate());
AsyncHooks::InitScope init_scope(env, parent->get_async_id());
// If this assert fires then Initialize hasn't been called yet.
Expand Down

0 comments on commit ad8ca65

Please sign in to comment.