Skip to content

Commit

Permalink
Don't dereference null global object. (youtube#1279)
Browse files Browse the repository at this point in the history
During thread shutdown, the global object can be destroyed before the
last task on the thread is completed. If an xhr raises an exception
exactly during this time, we can not set the exception state anymore.

b/295571346
  • Loading branch information
jellefoks committed Aug 16, 2023
1 parent f20c565 commit ac106f8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions cobalt/script/v8c/v8c_exception_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void V8cExceptionState::SetException(

V8cGlobalEnvironment* global_environment =
V8cGlobalEnvironment::GetFromIsolate(isolate_);
if (!global_environment) return;
v8::Local<v8::Object> wrapper =
global_environment->wrapper_factory()->GetWrapper(exception);

Expand Down
5 changes: 3 additions & 2 deletions cobalt/script/v8c/v8c_global_environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ V8cGlobalEnvironment::ModifyCodeGenerationFromStringsCallback(
V8cGlobalEnvironment* global_environment =
V8cGlobalEnvironment::GetFromIsolate(context->GetIsolate());
DCHECK(global_environment);
if (!global_environment->report_eval_.is_null()) {
if (global_environment && !global_environment->report_eval_.is_null()) {
global_environment->report_eval_.Run();
}
// This callback should only be called while code generation from strings is
Expand All @@ -396,7 +396,8 @@ void V8cGlobalEnvironment::MessageHandler(v8::Local<v8::Message> message,
v8::Isolate* isolate = v8::Isolate::GetCurrent();
V8cGlobalEnvironment* global_environment =
V8cGlobalEnvironment::GetFromIsolate(isolate);
if (isolate->GetEnteredOrMicrotaskContext().IsEmpty()) {
if (!global_environment ||
isolate->GetEnteredOrMicrotaskContext().IsEmpty()) {
return;
}
if (message->ErrorLevel() != v8::Isolate::kMessageError) {
Expand Down

0 comments on commit ac106f8

Please sign in to comment.