From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- dom/media/doctor/DDLogValue.cpp | 120 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 dom/media/doctor/DDLogValue.cpp (limited to 'dom/media/doctor/DDLogValue.cpp') diff --git a/dom/media/doctor/DDLogValue.cpp b/dom/media/doctor/DDLogValue.cpp new file mode 100644 index 0000000000..74044ca05a --- /dev/null +++ b/dom/media/doctor/DDLogValue.cpp @@ -0,0 +1,120 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "DDLogValue.h" + +#include "mozilla/JSONWriter.h" + +namespace mozilla { + +struct LogValueMatcher { + nsCString& mString; + + void operator()(const DDNoValue&) const {} + void operator()(const DDLogObject& a) const { a.AppendPrintf(mString); } + void operator()(const char* a) const { mString.AppendPrintf(R"("%s")", a); } + void operator()(const nsCString& a) const { + mString.AppendPrintf(R"(nsCString("%s"))", a.Data()); + } + void operator()(bool a) const { mString.AppendPrintf(a ? "true" : "false"); } + void operator()(int8_t a) const { + mString.AppendPrintf("int8_t(%" PRIi8 ")", a); + } + void operator()(uint8_t a) const { + mString.AppendPrintf("uint8_t(%" PRIu8 ")", a); + } + void operator()(int16_t a) const { + mString.AppendPrintf("int16_t(%" PRIi16 ")", a); + } + void operator()(uint16_t a) const { + mString.AppendPrintf("uint16_t(%" PRIu16 ")", a); + } + void operator()(int32_t a) const { + mString.AppendPrintf("int32_t(%" PRIi32 ")", a); + } + void operator()(uint32_t a) const { + mString.AppendPrintf("uint32_t(%" PRIu32 ")", a); + } + void operator()(int64_t a) const { + mString.AppendPrintf("int64_t(%" PRIi64 ")", a); + } + void operator()(uint64_t a) const { + mString.AppendPrintf("uint64_t(%" PRIu64 ")", a); + } + void operator()(double a) const { mString.AppendPrintf("double(%f)", a); } + void operator()(const DDRange& a) const { + mString.AppendPrintf("%" PRIi64 "<=(%" PRIi64 "B)<%" PRIi64 "", a.mOffset, + a.mBytes, a.mOffset + a.mBytes); + } + void operator()(const nsresult& a) const { + nsCString name; + GetErrorName(a, name); + mString.AppendPrintf("nsresult(%s =0x%08" PRIx32 ")", name.get(), + static_cast(a)); + } + void operator()(const MediaResult& a) const { + nsCString name; + GetErrorName(a.Code(), name); + mString.AppendPrintf("MediaResult(%s =0x%08" PRIx32 ", \"%s\")", name.get(), + static_cast(a.Code()), a.Message().get()); + } +}; + +void AppendToString(const DDLogValue& aValue, nsCString& aString) { + aValue.match(LogValueMatcher{aString}); +} + +struct LogValueMatcherJson { + JSONWriter& mJW; + const Span mPropertyName; + + void operator()(const DDNoValue&) const { mJW.NullProperty(mPropertyName); } + void operator()(const DDLogObject& a) const { + nsPrintfCString s(R"("%s[%p]")", a.TypeName(), a.Pointer()); + mJW.StringProperty(mPropertyName, s); + } + void operator()(const char* a) const { + mJW.StringProperty(mPropertyName, MakeStringSpan(a)); + } + void operator()(const nsCString& a) const { + mJW.StringProperty(mPropertyName, a); + } + void operator()(bool a) const { mJW.BoolProperty(mPropertyName, a); } + void operator()(int8_t a) const { mJW.IntProperty(mPropertyName, a); } + void operator()(uint8_t a) const { mJW.IntProperty(mPropertyName, a); } + void operator()(int16_t a) const { mJW.IntProperty(mPropertyName, a); } + void operator()(uint16_t a) const { mJW.IntProperty(mPropertyName, a); } + void operator()(int32_t a) const { mJW.IntProperty(mPropertyName, a); } + void operator()(uint32_t a) const { mJW.IntProperty(mPropertyName, a); } + void operator()(int64_t a) const { mJW.IntProperty(mPropertyName, a); } + void operator()(uint64_t a) const { mJW.DoubleProperty(mPropertyName, a); } + void operator()(double a) const { mJW.DoubleProperty(mPropertyName, a); } + void operator()(const DDRange& a) const { + mJW.StartArrayProperty(mPropertyName); + mJW.IntElement(a.mOffset); + mJW.IntElement(a.mOffset + a.mBytes); + mJW.EndArray(); + } + void operator()(const nsresult& a) const { + nsCString name; + GetErrorName(a, name); + mJW.StringProperty(mPropertyName, name); + } + void operator()(const MediaResult& a) const { + nsCString name; + GetErrorName(a.Code(), name); + mJW.StringProperty(mPropertyName, + nsPrintfCString(R"lit("MediaResult(%s, %s)")lit", + name.get(), a.Message().get())); + } +}; + +void ToJSON(const DDLogValue& aValue, JSONWriter& aJSONWriter, + const char* aPropertyName) { + aValue.match(LogValueMatcherJson{aJSONWriter, MakeStringSpan(aPropertyName)}); +} + +} // namespace mozilla -- cgit v1.2.3