Bug 1783397 - Part 8: Add JS::PropertyKey::dump. r=mgaudet

Differential Revision: https://phabricator.services.mozilla.com/D199823
This commit is contained in:
Tooru Fujisawa 2024-01-31 08:54:44 +00:00
Родитель ca5831076c
Коммит 05e4b02975
2 изменённых файлов: 53 добавлений и 0 удалений

Просмотреть файл

@ -37,6 +37,11 @@
#include "js/TracingAPI.h"
#include "js/TypeDecls.h"
namespace js {
class JS_PUBLIC_API GenericPrinter;
class JSONPrinter;
} // namespace js
namespace JS {
enum class SymbolCode : uint32_t;
@ -204,6 +209,14 @@ class PropertyKey {
return reinterpret_cast<JSLinearString*>(toString());
}
#if defined(DEBUG) || defined(JS_JITSPEW)
void dump() const;
void dump(js::GenericPrinter& out) const;
void dump(js::JSONPrinter& json) const;
void dumpFields(js::JSONPrinter& json) const;
#endif
private:
static bool isNonIntAtom(JSAtom* atom);
static bool isNonIntAtom(JSString* atom);

Просмотреть файл

@ -5,9 +5,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "js/Id.h"
#include "js/Printer.h" // js::GenericPrinter, js::Fprinter
#include "js/RootingAPI.h"
#include "vm/JSContext.h"
#include "vm/JSONPrinter.h" // js::JSONPrinter
#include "vm/SymbolType.h"
#include "vm/JSAtomUtils-inl.h" // AtomToId
@ -48,3 +50,41 @@ bool JS::PropertyKey::isWellKnownSymbol(JS::SymbolCode code) const {
/* static */ bool JS::PropertyKey::isNonIntAtom(JSString* str) {
return JS::PropertyKey::isNonIntAtom(&str->asAtom());
}
#if defined(DEBUG) || defined(JS_JITSPEW)
void JS::PropertyKey::dump() const {
js::Fprinter out(stderr);
dump(out);
}
void JS::PropertyKey::dump(js::GenericPrinter& out) const {
js::JSONPrinter json(out);
dump(json);
out.put("\n");
}
void JS::PropertyKey::dump(js::JSONPrinter& json) const {
json.beginObject();
dumpFields(json);
json.endObject();
}
void JS::PropertyKey::dumpFields(js::JSONPrinter& json) const {
if (isAtom()) {
json.property("type", "atom");
toAtom()->dumpFields(json);
} else if (isInt()) {
json.property("type", "int");
json.property("value", toInt());
} else if (isSymbol()) {
json.property("type", "symbol");
toSymbol()->dumpFields(json);
} else if (isVoid()) {
json.property("type", "void");
} else {
json.formatProperty("type", "Unknown(%zx)", size_t(asRawBits()));
}
}
#endif /* defined(DEBUG) || defined(JS_JITSPEW) */