@@ -1037,14 +1037,17 @@ void WallProfiler::SetContext(Isolate* isolate, Local<Value> value) {
1037
1037
// No Node AsyncContextFrame in this continuation yet
1038
1038
if (!cped->IsObject ()) return ;
1039
1039
1040
+ auto v8Ctx = isolate->GetCurrentContext ();
1041
+ // This should always be called from a V8 context, but check just in case.
1042
+ if (v8Ctx.IsEmpty ()) return ;
1043
+
1040
1044
auto cpedObj = cped.As <Object>();
1041
1045
auto localSymbol = cpedSymbol_.Get (isolate);
1042
- auto v8Ctx = isolate->GetCurrentContext ();
1043
1046
auto maybeProfData = cpedObj->Get (v8Ctx, localSymbol);
1044
1047
if (maybeProfData.IsEmpty ()) return ;
1045
- auto profData = maybeProfData.ToLocalChecked ();
1046
1048
1047
1049
PersistentContextPtr* contextPtr = nullptr ;
1050
+ auto profData = maybeProfData.ToLocalChecked ();
1048
1051
if (profData->IsUndefined ()) {
1049
1052
contextPtr = new PersistentContextPtr ();
1050
1053
@@ -1091,19 +1094,26 @@ ContextPtr WallProfiler::GetContextPtr(Isolate* isolate) {
1091
1094
return curContext_.Get ();
1092
1095
}
1093
1096
1097
+ #define RETURN_EMPTY_IF (x ) if (x) return std::shared_ptr<Global<Value>>()
1098
+
1094
1099
auto cped = isolate->GetContinuationPreservedEmbedderData ();
1095
- if (!cped->IsObject ()) return std::shared_ptr<Global<Value>>();
1100
+ RETURN_EMPTY_IF (!cped->IsObject ());
1101
+
1102
+ auto v8Ctx = isolate->GetCurrentContext ();
1103
+ RETURN_EMPTY_IF (v8Ctx.IsEmpty ());
1096
1104
1097
1105
auto cpedObj = cped.As <Object>();
1098
1106
auto localSymbol = cpedSymbol_.Get (isolate);
1099
- auto maybeProfData = cpedObj->Get (isolate->GetCurrentContext (), localSymbol);
1100
- if (maybeProfData.IsEmpty ()) return std::shared_ptr<Global<Value>>();
1101
- auto profData = maybeProfData.ToLocalChecked ();
1107
+ auto maybeProfData = cpedObj->Get (v8Ctx, localSymbol);
1108
+ RETURN_EMPTY_IF (maybeProfData.IsEmpty ());
1102
1109
1103
- if (profData->IsUndefined ()) return std::shared_ptr<Global<Value>>();
1110
+ auto profData = maybeProfData.ToLocalChecked ();
1111
+ RETURN_EMPTY_IF (profData->IsUndefined ());
1104
1112
1105
1113
return static_cast <PersistentContextPtr*>(profData.As <External>()->Value ())
1106
1114
->Get ();
1115
+
1116
+ #undef RETURN_EMPTY_IF
1107
1117
#else
1108
1118
return curContext_.Get ();
1109
1119
#endif
0 commit comments