Skip to content

Commit ec1c853

Browse files
committed
Fixups
Don't patch Environment::GetCurrent. Make sure to avoid calls into JS when the isolate is terminating @ node_http2.cc
1 parent ca3d8a3 commit ec1c853

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/env-inl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ inline bool TickInfo::has_rejection_to_warn() const {
172172
}
173173

174174
inline Environment* Environment::GetCurrent(v8::Isolate* isolate) {
175-
if (UNLIKELY(!isolate->InContext() ||
176-
isolate->IsExecutionTerminating())) return nullptr;
175+
if (UNLIKELY(!isolate->InContext())) return nullptr;
177176
v8::HandleScope handle_scope(isolate);
178177
return GetCurrent(isolate->GetCurrentContext());
179178
}

src/node_http2.cc

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,13 +1120,15 @@ int Http2Session::OnStreamClose(nghttp2_session* handle,
11201120
// It is possible for the stream close to occur before the stream is
11211121
// ever passed on to the javascript side. If that happens, the callback
11221122
// will return false.
1123-
Local<Value> arg = Integer::NewFromUnsigned(isolate, code);
1124-
MaybeLocal<Value> answer =
1125-
stream->MakeCallback(env->http2session_on_stream_close_function(),
1126-
1, &arg);
1127-
if (answer.IsEmpty() || answer.ToLocalChecked()->IsFalse()) {
1128-
// Skip to destroy
1129-
stream->Destroy();
1123+
if (env->can_call_into_js()) {
1124+
Local<Value> arg = Integer::NewFromUnsigned(isolate, code);
1125+
MaybeLocal<Value> answer =
1126+
stream->MakeCallback(env->http2session_on_stream_close_function(),
1127+
1, &arg);
1128+
if (answer.IsEmpty() || answer.ToLocalChecked()->IsFalse()) {
1129+
// Skip to destroy
1130+
stream->Destroy();
1131+
}
11301132
}
11311133
return 0;
11321134
}
@@ -1629,9 +1631,11 @@ void Http2Session::MaybeScheduleWrite() {
16291631

16301632
// Sending data may call arbitrary JS code, so keep track of
16311633
// async context.
1632-
HandleScope handle_scope(env->isolate());
1633-
InternalCallbackScope callback_scope(this);
1634-
SendPendingData();
1634+
if (env->can_call_into_js()) {
1635+
HandleScope handle_scope(env->isolate());
1636+
InternalCallbackScope callback_scope(this);
1637+
SendPendingData();
1638+
}
16351639
});
16361640
}
16371641
}

src/node_platform.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ int NodePlatform::NumberOfWorkerThreads() {
406406
}
407407

408408
void PerIsolatePlatformData::RunForegroundTask(std::unique_ptr<Task> task) {
409+
if (isolate_->IsExecutionTerminating())
410+
return task->Run();
409411
DebugSealHandleScope scope(isolate_);
410412
Environment* env = Environment::GetCurrent(isolate_);
411413
if (env != nullptr) {

0 commit comments

Comments
 (0)