Skip to content

Commit

Permalink
src: add missing context scopes
Browse files Browse the repository at this point in the history
Add scopes that ensure that the context associated with the
current Environment is always entered when working with it.

PR-URL: #36413
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
addaleax authored and targos committed May 1, 2021
1 parent fee0389 commit 4b386e3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,8 @@ void Environment::InitializeLibuv() {
[](uv_async_t* async) {
Environment* env = ContainerOf(
&Environment::task_queues_async_, async);
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());
env->RunAndClearNativeImmediates();
});
uv_unref(reinterpret_cast<uv_handle_t*>(&task_queues_async_));
Expand Down
2 changes: 2 additions & 0 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ inline void FileHandle::Close() {
void FileHandle::CloseReq::Resolve() {
Isolate* isolate = env()->isolate();
HandleScope scope(isolate);
Context::Scope context_scope(env()->context());
InternalCallbackScope callback_scope(this);
Local<Promise> promise = promise_.Get(isolate);
Local<Promise::Resolver> resolver = promise.As<Promise::Resolver>();
Expand All @@ -297,6 +298,7 @@ void FileHandle::CloseReq::Resolve() {
void FileHandle::CloseReq::Reject(Local<Value> reason) {
Isolate* isolate = env()->isolate();
HandleScope scope(isolate);
Context::Scope context_scope(env()->context());
InternalCallbackScope callback_scope(this);
Local<Promise> promise = promise_.Get(isolate);
Local<Promise::Resolver> resolver = promise.As<Promise::Resolver>();
Expand Down

0 comments on commit 4b386e3

Please sign in to comment.