Skip to content

Commit

Permalink
fix(shared): SourceLocation::ToString
Browse files Browse the repository at this point in the history
  • Loading branch information
vadzz-dev committed Dec 29, 2023
1 parent f02660a commit c73c1a7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions shared/V8Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,18 @@ V8Helpers::SourceLocation::SourceLocation(std::string&& _fileName, int _line, v8
context.Reset(ctx->GetIsolate(), ctx);
}

std::string V8Helpers::SourceLocation::ToString()
std::string V8Helpers::SourceLocation::ToString(v8::Isolate* isolate)
{
auto isolate = v8::Isolate::GetCurrent();

std::stringstream stream;
stream << "[";

// Check if not inside a worker
if(!(*static_cast<bool*>(isolate->GetData(v8::Isolate::GetNumberOfDataSlots() - 1))))
bool* isWorker = static_cast<bool*>(isolate->GetData(v8::Isolate::GetNumberOfDataSlots() - 1));
if (!isWorker || !(*isWorker))
{
stream << V8ResourceImpl::Get(context.Get(v8::Isolate::GetCurrent()))->GetResource()->GetName() << ":";
stream << V8ResourceImpl::Get(context.Get(isolate))->GetResource()->GetName() << ":";
}

stream << fileName << ":" << line << "]";
return stream.str();
}
Expand Down
2 changes: 1 addition & 1 deletion shared/V8Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace V8Helpers
return line;
}

std::string ToString();
std::string ToString(v8::Isolate* isolate);

static SourceLocation GetCurrent(v8::Isolate* isolate, V8ResourceImpl* resource = nullptr);

Expand Down
2 changes: 1 addition & 1 deletion shared/V8ResourceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class V8ResourceImpl : public alt::IResource::Impl

if(!anyHandlerRemoved)
{
Log::Warning << location.ToString() << " alt.off was called for event \"" << ev << "\" with function reference that was not subscribed" << Log::Endl;
Log::Warning << location.ToString(isolate) << " alt.off was called for event \"" << ev << "\" with function reference that was not subscribed" << Log::Endl;
return;
}

Expand Down
2 changes: 1 addition & 1 deletion shared/helpers/Macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,6 @@
{ \
V8_GET_ISOLATE(); \
V8_GET_RESOURCE(); \
Log::Warning << V8Helpers::SourceLocation::GetCurrent(isolate, resource).ToString() << " " << oldName << " is deprecated and will be removed in future versions. Consider using " \
Log::Warning << V8Helpers::SourceLocation::GetCurrent(isolate, resource).ToString(isolate) << " " << oldName << " is deprecated and will be removed in future versions. Consider using " \
<< newName << " instead" << Log::Endl; \
}
2 changes: 1 addition & 1 deletion shared/helpers/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local<v8::Value> val, bool allowFunction)
{
if(!allowFunction)
{
Log::Error << V8Helpers::SourceLocation::GetCurrent(isolate).ToString() << " "
Log::Error << V8Helpers::SourceLocation::GetCurrent(isolate).ToString(isolate) << " "
<< "Cannot convert function to MValue" << Log::Endl;
return core.CreateMValueNone();
}
Expand Down

0 comments on commit c73c1a7

Please sign in to comment.