5 #ifndef V8_STRING_STREAM_H_ 6 #define V8_STRING_STREAM_H_ 8 #include "src/allocation.h" 9 #include "src/handles.h" 10 #include "src/objects/heap-object.h" 11 #include "src/vector.h" 23 virtual char* allocate(
unsigned bytes) = 0;
28 virtual char* grow(
unsigned* bytes) = 0;
36 char* allocate(
unsigned bytes)
override;
37 char* grow(
unsigned* bytes)
override;
47 : buffer_(buffer), length_(length) {}
50 char* allocate(
unsigned bytes)
override;
51 char* grow(
unsigned* bytes)
override;
62 FmtElm(
int value) : FmtElm(INT) {
65 explicit FmtElm(
double value) : FmtElm(DOUBLE) {
66 data_.u_double_ = value;
68 FmtElm(
const char* value) : FmtElm(C_STR) {
69 data_.u_c_str_ = value;
72 data_.u_lc_str_ = &value;
74 FmtElm(
Object* value) : FmtElm(OBJ) {
78 data_.u_obj_ =
reinterpret_cast<Object*
>(value.ptr());
81 data_.u_handle_ = value.location();
83 FmtElm(
void* value) : FmtElm(POINTER) {
84 data_.u_pointer_ = value;
89 enum Type { INT, DOUBLE, C_STR, LC_STR, OBJ, HANDLE, POINTER };
95 explicit FmtElm(
Type) {}
101 const char* u_c_str_;
110 enum ObjectPrintMode { kPrintObjectConcise, kPrintObjectVerbose };
112 ObjectPrintMode object_print_mode = kPrintObjectVerbose)
113 : allocator_(allocator),
114 object_print_mode_(object_print_mode),
115 capacity_(kInitialCapacity),
117 buffer_(allocator_->allocate(kInitialCapacity)) {
123 bool Put(
String str,
int start,
int end);
124 void Add(
const char* format) { Add(CStrVector(format)); }
127 template <
typename... Args>
128 void Add(
const char* format, Args... args) {
129 Add(CStrVector(format), args...);
132 template <
typename... Args>
134 FmtElm elems[]{args...};
135 Add(format, ArrayVector(elems));
139 void OutputToFile(FILE* out);
140 void OutputToStdOut() { OutputToFile(stdout); }
143 std::unique_ptr<char[]> ToCString()
const;
144 int length()
const {
return length_; }
147 void PrintName(
Object* o);
148 void PrintFixedArray(
FixedArray array,
unsigned int limit);
150 void PrintUsingMap(
JSObject* js_object);
152 void PrintSecurityTokenIfChanged(
JSFunction*
function);
163 void PrintMentionedObjectCache(
Isolate* isolate);
164 static void ClearMentionedObjectCache(
Isolate* isolate);
166 bool IsMentionedObjectCacheClear(
Isolate* isolate);
169 static const int kInitialCapacity = 16;
173 void PrintObject(
Object* obj);
176 ObjectPrintMode object_print_mode_;
181 bool full()
const {
return (capacity_ - length_) == 1; }
182 int space()
const {
return capacity_ - length_; }
190 #endif // V8_STRING_STREAM_H_