@@ -301,7 +301,10 @@ void EnvInst::SetNodeStartupTime(const char* name, uint64_t ts) {
301301std::string EnvInst::GetOnBlockedBody () {
302302 DCHECK (utils::are_threads_equal (creation_thread (), uv_thread_self ()));
303303 uv_metrics_t metrics;
304- auto SharedEnvInst = GetCurrent (isolate_);
304+ SharedEnvInst envinst = GetCurrent (isolate_);
305+ if (envinst == nullptr ) {
306+ return " " ;
307+ }
305308
306309 HandleScope scope (isolate_);
307310 Local<StackTrace> stack =
@@ -316,7 +319,7 @@ std::string EnvInst::GetOnBlockedBody() {
316319 std::string body_string = " {" ;
317320 // TODO(trevnorris): REMOVE provider_times so libuv don't need to use the
318321 // floating patch.
319- uv_metrics_info (SharedEnvInst ->event_loop (), &metrics);
322+ uv_metrics_info (envinst ->event_loop (), &metrics);
320323 uint64_t exit_time = metrics.loop_count == 0 ?
321324 env ()->time_origin () : provider_times ().second ;
322325
@@ -401,12 +404,14 @@ SharedEnvInst EnvInst::GetInst(uint64_t thread_id) {
401404
402405
403406SharedEnvInst EnvInst::GetCurrent (Isolate* isolate) {
404- return Environment::GetCurrent (isolate)->envinst_ ;
407+ Environment* env = Environment::GetCurrent (isolate);
408+ return env == nullptr ? nullptr : env->envinst_ ;
405409}
406410
407411
408412SharedEnvInst EnvInst::GetCurrent (Local<Context> context) {
409- return Environment::GetCurrent (context)->envinst_ ;
413+ Environment* env = Environment::GetCurrent (context);
414+ return env == nullptr ? nullptr : env->envinst_ ;
410415}
411416
412417
0 commit comments