Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/serialization/DebugSerializer.cpp
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < value.size(); ++i) | ||||
else | else | ||||
escaped += value[i]; | escaped += value[i]; | ||||
m_Stream << INDENT << name << ": " << "\"" << escaped << "\"\n"; | m_Stream << INDENT << name << ": " << "\"" << escaped << "\"\n"; | ||||
} | } | ||||
void CDebugSerializer::PutScriptVal(const char* name, JS::MutableHandleValue value) | void CDebugSerializer::PutScriptVal(const char* name, JS::MutableHandleValue value) | ||||
{ | { | ||||
std::string source = m_ScriptInterface.ToString(value, true); | ScriptRequest rq(m_ScriptInterface); | ||||
JS::RootedValue serialize(rq.cx); | |||||
if (m_ScriptInterface.GetProperty(value, "Serialize", &serialize) && !serialize.isNullOrUndefined()) | |||||
{ | |||||
// If the value has a Serialize property, pretty-parse that and return the value as a raw string. | |||||
// This gives more debug data for components in case of OOS. | |||||
m_ScriptInterface.CallFunction(value, "Serialize", &serialize); | |||||
std::string serialized_source = m_ScriptInterface.ToString(&serialize, true); | |||||
std::string source = m_ScriptInterface.ToString(value, false); | |||||
m_Stream << INDENT << name << ": " << serialized_source << " (raw: " << source << ")\n"; | |||||
} | |||||
else | |||||
{ | |||||
std::string source = m_ScriptInterface.ToString(value, true); | |||||
m_Stream << INDENT << name << ": " << source << "\n"; | m_Stream << INDENT << name << ": " << source << "\n"; | ||||
} | } | ||||
} | |||||
void CDebugSerializer::PutRaw(const char* name, const u8* data, size_t len) | void CDebugSerializer::PutRaw(const char* name, const u8* data, size_t len) | ||||
{ | { | ||||
m_Stream << INDENT << name << ": (" << len << " bytes)"; | m_Stream << INDENT << name << ": (" << len << " bytes)"; | ||||
char buf[4]; | char buf[4]; | ||||
for (size_t i = 0; i < len; ++i) | for (size_t i = 0; i < len; ++i) | ||||
{ | { | ||||
Show All 16 Lines |
Wildfire Games · Phabricator