OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_JSON_STRINGIFIER_H_ | 5 #ifndef V8_JSON_STRINGIFIER_H_ |
6 #define V8_JSON_STRINGIFIER_H_ | 6 #define V8_JSON_STRINGIFIER_H_ |
7 | 7 |
8 #include "src/objects.h" | 8 #include "src/objects.h" |
9 #include "src/string-builder.h" | 9 #include "src/string-builder.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 class BasicJsonStringifier BASE_EMBEDDED { | 14 class BasicJsonStringifier BASE_EMBEDDED { |
15 public: | 15 public: |
16 BasicJsonStringifier(Isolate* isolate, Handle<String> gap); | 16 explicit BasicJsonStringifier(Isolate* isolate); |
17 | 17 |
18 ~BasicJsonStringifier() { DeleteArray(gap_); } | 18 ~BasicJsonStringifier() { DeleteArray(gap_); } |
19 | 19 |
20 MUST_USE_RESULT MaybeHandle<Object> Stringify(Handle<Object> object); | 20 MUST_USE_RESULT MaybeHandle<Object> Stringify(Handle<Object> object, |
| 21 Handle<Object> gap); |
21 | 22 |
22 MUST_USE_RESULT static MaybeHandle<Object> StringifyString( | 23 MUST_USE_RESULT static MaybeHandle<Object> StringifyString( |
23 Isolate* isolate, Handle<String> object); | 24 Isolate* isolate, Handle<String> object); |
24 | 25 |
25 private: | 26 private: |
26 enum Result { UNCHANGED, SUCCESS, EXCEPTION }; | 27 enum Result { UNCHANGED, SUCCESS, EXCEPTION }; |
27 | 28 |
| 29 bool InitializeGap(Handle<Object> gap); |
| 30 |
28 MUST_USE_RESULT MaybeHandle<Object> ApplyToJsonFunction( | 31 MUST_USE_RESULT MaybeHandle<Object> ApplyToJsonFunction( |
29 Handle<Object> object, | 32 Handle<Object> object, |
30 Handle<Object> key); | 33 Handle<Object> key); |
31 | 34 |
32 // Entry point to serialize the object. | 35 // Entry point to serialize the object. |
33 INLINE(Result SerializeObject(Handle<Object> obj)) { | 36 INLINE(Result SerializeObject(Handle<Object> obj)) { |
34 return Serialize_<false>(obj, false, factory()->empty_string()); | 37 return Serialize_<false>(obj, false, factory()->empty_string()); |
35 } | 38 } |
36 | 39 |
37 // Serialize an array element. | 40 // Serialize an array element. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 100 |
98 Result StackPush(Handle<Object> object); | 101 Result StackPush(Handle<Object> object); |
99 void StackPop(); | 102 void StackPop(); |
100 | 103 |
101 Factory* factory() { return isolate_->factory(); } | 104 Factory* factory() { return isolate_->factory(); } |
102 | 105 |
103 Isolate* isolate_; | 106 Isolate* isolate_; |
104 IncrementalStringBuilder builder_; | 107 IncrementalStringBuilder builder_; |
105 Handle<String> tojson_string_; | 108 Handle<String> tojson_string_; |
106 Handle<JSArray> stack_; | 109 Handle<JSArray> stack_; |
107 Handle<String> gap_string_; | |
108 uc16* gap_; | 110 uc16* gap_; |
109 int indent_; | 111 int indent_; |
110 | 112 |
111 static const int kJsonEscapeTableEntrySize = 8; | 113 static const int kJsonEscapeTableEntrySize = 8; |
112 static const char* const JsonEscapeTable; | 114 static const char* const JsonEscapeTable; |
113 }; | 115 }; |
114 | 116 |
115 } // namespace internal | 117 } // namespace internal |
116 } // namespace v8 | 118 } // namespace v8 |
117 | 119 |
118 #endif // V8_JSON_STRINGIFIER_H_ | 120 #endif // V8_JSON_STRINGIFIER_H_ |
OLD | NEW |