Skip to content

Commit 2e55267

Browse files
santigimenotrevnorris
authored andcommitted
src: fix EnvInst::GetCurrent()
Handle the case where the `Environment` is already nullptr. PR-URL: #25 Reviewed-by: Trevor Norris <[email protected]>
1 parent 33c8b29 commit 2e55267

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/nsolid/nsolid_api.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,10 @@ void EnvInst::SetNodeStartupTime(const char* name, uint64_t ts) {
301301
std::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

403406
SharedEnvInst 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

408412
SharedEnvInst 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

Comments
 (0)