Skip to content

Commit

Permalink
src: fix EnvInst::GetCurrent()
Browse files Browse the repository at this point in the history
Handle the case where the `Environment` is already nullptr.

PR-URL: #25
Reviewed-by: Trevor Norris <[email protected]>
  • Loading branch information
santigimeno authored and trevnorris committed Nov 30, 2023
1 parent 33c8b29 commit 2e55267
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/nsolid/nsolid_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,10 @@ void EnvInst::SetNodeStartupTime(const char* name, uint64_t ts) {
std::string EnvInst::GetOnBlockedBody() {
DCHECK(utils::are_threads_equal(creation_thread(), uv_thread_self()));
uv_metrics_t metrics;
auto SharedEnvInst = GetCurrent(isolate_);
SharedEnvInst envinst = GetCurrent(isolate_);
if (envinst == nullptr) {
return "";
}

HandleScope scope(isolate_);
Local<StackTrace> stack =
Expand All @@ -316,7 +319,7 @@ std::string EnvInst::GetOnBlockedBody() {
std::string body_string = "{";
// TODO(trevnorris): REMOVE provider_times so libuv don't need to use the
// floating patch.
uv_metrics_info(SharedEnvInst->event_loop(), &metrics);
uv_metrics_info(envinst->event_loop(), &metrics);
uint64_t exit_time = metrics.loop_count == 0 ?
env()->time_origin() : provider_times().second;

Expand Down Expand Up @@ -401,12 +404,14 @@ SharedEnvInst EnvInst::GetInst(uint64_t thread_id) {


SharedEnvInst EnvInst::GetCurrent(Isolate* isolate) {
return Environment::GetCurrent(isolate)->envinst_;
Environment* env = Environment::GetCurrent(isolate);
return env == nullptr ? nullptr : env->envinst_;
}


SharedEnvInst EnvInst::GetCurrent(Local<Context> context) {
return Environment::GetCurrent(context)->envinst_;
Environment* env = Environment::GetCurrent(context);
return env == nullptr ? nullptr : env->envinst_;
}


Expand Down

0 comments on commit 2e55267

Please sign in to comment.