#ifndef vm_JSONPrinter_h
#define vm_JSONPrinter_h
#include "mozilla/TimeStamp.h"
#include <stdio.h>
#include "js/TypeDecls.h"
#include "vm/Printer.h"
struct DtoaState;
namespace js {
class JSONPrinter {
protected:
int indentLevel_;
bool indent_;
bool first_;
GenericPrinter& out_;
DtoaState* dtoaState_;
void indent();
public:
explicit JSONPrinter(GenericPrinter& out, bool indent = true)
: indentLevel_(0),
indent_(indent),
first_(true),
out_(out),
dtoaState_(nullptr) {}
~JSONPrinter();
void beginObject();
void beginList();
void beginObjectProperty(const char* name);
void beginListProperty(const char* name);
void value(const char* format, ...) MOZ_FORMAT_PRINTF(2, 3);
void value(int value);
void property(const char* name, const char* value);
void property(const char* name, int32_t value);
void property(const char* name, uint32_t value);
void property(const char* name, int64_t value);
void property(const char* name, uint64_t value);
#if defined(XP_DARWIN) || defined(__OpenBSD__)
void property(const char* name, size_t value);
#endif
void formatProperty(const char* name, const char* format, ...)
MOZ_FORMAT_PRINTF(3, 4);
void formatProperty(const char* name, const char* format, va_list ap);
enum TimePrecision { SECONDS, MILLISECONDS, MICROSECONDS };
void property(const char* name, const mozilla::TimeDuration& dur,
TimePrecision precision);
void floatProperty(const char* name, double value, size_t precision);
void beginStringProperty(const char* name);
void endStringProperty();
void endObject();
void endList();
void outOfMemory() { out_.reportOutOfMemory(); }
protected:
void propertyName(const char* name);
};
}
#endif