Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/json-stringifier.h

Issue 2010533002: [json] support replacer function in BasicJsonStringifier. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@jsonproplist
Patch Set: fix Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/js/json.js ('k') | src/json-stringifier.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 JsonStringifier BASE_EMBEDDED {
15 public: 15 public:
16 explicit BasicJsonStringifier(Isolate* isolate); 16 explicit JsonStringifier(Isolate* isolate);
17 17
18 ~BasicJsonStringifier() { DeleteArray(gap_); } 18 ~JsonStringifier() { 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> replacer, 21 Handle<Object> replacer,
22 Handle<Object> gap); 22 Handle<Object> gap);
23 23
24 MUST_USE_RESULT static MaybeHandle<Object> StringifyString(
25 Isolate* isolate, Handle<String> object);
26
27 private: 24 private:
28 enum Result { UNCHANGED, SUCCESS, EXCEPTION }; 25 enum Result { UNCHANGED, SUCCESS, EXCEPTION };
29 26
30 bool InitializeReplacer(Handle<Object> replacer); 27 bool InitializeReplacer(Handle<Object> replacer);
31 bool InitializeGap(Handle<Object> gap); 28 bool InitializeGap(Handle<Object> gap);
32 29
33 MUST_USE_RESULT MaybeHandle<Object> ApplyToJsonFunction( 30 MUST_USE_RESULT MaybeHandle<Object> ApplyToJsonFunction(
34 Handle<Object> object, 31 Handle<Object> object,
35 Handle<Object> key); 32 Handle<Object> key);
33 MUST_USE_RESULT MaybeHandle<Object> ApplyReplacerFunction(
34 Handle<Object> object, Handle<Object> key);
36 35
37 // Entry point to serialize the object. 36 // Entry point to serialize the object.
38 INLINE(Result SerializeObject(Handle<Object> obj)) { 37 INLINE(Result SerializeObject(Handle<Object> obj)) {
39 return Serialize_<false>(obj, false, factory()->empty_string()); 38 return Serialize_<false>(obj, false, factory()->empty_string());
40 } 39 }
41 40
42 // Serialize an array element. 41 // Serialize an array element.
43 // The index may serve as argument for the toJSON function. 42 // The index may serve as argument for the toJSON function.
44 INLINE(Result SerializeElement(Isolate* isolate, 43 INLINE(Result SerializeElement(Isolate* isolate,
45 Handle<Object> object, 44 Handle<Object> object,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 INLINE(void SerializeString_(Handle<String> string)); 92 INLINE(void SerializeString_(Handle<String> string));
94 93
95 template <typename Char> 94 template <typename Char>
96 INLINE(static bool DoNotEscape(Char c)); 95 INLINE(static bool DoNotEscape(Char c));
97 96
98 INLINE(void NewLine()); 97 INLINE(void NewLine());
99 INLINE(void Indent() { indent_++; }); 98 INLINE(void Indent() { indent_++; });
100 INLINE(void Unindent() { indent_--; }); 99 INLINE(void Unindent() { indent_--; });
101 INLINE(void Separator(bool first)); 100 INLINE(void Separator(bool first));
102 101
102 Handle<JSReceiver> CurrentHolder(Handle<Object> value);
103
103 Result StackPush(Handle<Object> object); 104 Result StackPush(Handle<Object> object);
104 void StackPop(); 105 void StackPop();
105 106
106 Factory* factory() { return isolate_->factory(); } 107 Factory* factory() { return isolate_->factory(); }
107 108
108 Isolate* isolate_; 109 Isolate* isolate_;
109 IncrementalStringBuilder builder_; 110 IncrementalStringBuilder builder_;
110 Handle<String> tojson_string_; 111 Handle<String> tojson_string_;
111 Handle<JSArray> stack_; 112 Handle<JSArray> stack_;
112 Handle<FixedArray> property_list_; 113 Handle<FixedArray> property_list_;
114 Handle<JSReceiver> replacer_function_;
113 uc16* gap_; 115 uc16* gap_;
114 int indent_; 116 int indent_;
115 117
116 static const int kJsonEscapeTableEntrySize = 8; 118 static const int kJsonEscapeTableEntrySize = 8;
117 static const char* const JsonEscapeTable; 119 static const char* const JsonEscapeTable;
118 }; 120 };
119 121
120 } // namespace internal 122 } // namespace internal
121 } // namespace v8 123 } // namespace v8
122 124
123 #endif // V8_JSON_STRINGIFIER_H_ 125 #endif // V8_JSON_STRINGIFIER_H_
OLDNEW
« no previous file with comments | « src/js/json.js ('k') | src/json-stringifier.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698