OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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_PARSER_H_ | 5 #ifndef V8_JSON_PARSER_H_ |
6 #define V8_JSON_PARSER_H_ | 6 #define V8_JSON_PARSER_H_ |
7 | 7 |
8 #include "src/factory.h" | 8 #include "src/factory.h" |
9 #include "src/objects.h" | 9 #include "src/objects.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 enum ParseElementResult { kElementFound, kElementNotFound, kNullHandle }; | 14 enum ParseElementResult { kElementFound, kElementNotFound, kNullHandle }; |
15 | 15 |
| 16 class JsonParseInternalizer BASE_EMBEDDED { |
| 17 public: |
| 18 static MaybeHandle<Object> Internalize(Isolate* isolate, |
| 19 Handle<Object> object, |
| 20 Handle<Object> reviver); |
| 21 |
| 22 private: |
| 23 JsonParseInternalizer(Isolate* isolate, Handle<JSReceiver> reviver) |
| 24 : isolate_(isolate), reviver_(reviver) {} |
| 25 |
| 26 MaybeHandle<Object> InternalizeJsonProperty(Handle<JSReceiver> holder, |
| 27 Handle<String> key); |
| 28 |
| 29 bool RecurseAndApply(Handle<JSReceiver> holder, Handle<String> name); |
| 30 |
| 31 Isolate* isolate_; |
| 32 Handle<JSReceiver> reviver_; |
| 33 }; |
16 | 34 |
17 // A simple json parser. | 35 // A simple json parser. |
18 template <bool seq_one_byte> | 36 template <bool seq_one_byte> |
19 class JsonParser BASE_EMBEDDED { | 37 class JsonParser BASE_EMBEDDED { |
20 public: | 38 public: |
21 MUST_USE_RESULT static MaybeHandle<Object> Parse(Handle<String> source) { | 39 MUST_USE_RESULT static MaybeHandle<Object> Parse(Isolate* isolate, |
22 return JsonParser(source).ParseJson(); | 40 Handle<String> source, |
| 41 Handle<Object> reviver) { |
| 42 Handle<Object> result; |
| 43 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, |
| 44 JsonParser(isolate, source).ParseJson(), Object); |
| 45 if (reviver->IsCallable()) { |
| 46 return JsonParseInternalizer::Internalize(isolate, result, reviver); |
| 47 } |
| 48 return result; |
23 } | 49 } |
24 | 50 |
25 static const int kEndOfString = -1; | 51 static const int kEndOfString = -1; |
26 | 52 |
27 private: | 53 private: |
28 explicit JsonParser(Handle<String> source); | 54 JsonParser(Isolate* isolate, Handle<String> source); |
29 | 55 |
30 // Parse a string containing a single JSON value. | 56 // Parse a string containing a single JSON value. |
31 MaybeHandle<Object> ParseJson(); | 57 MaybeHandle<Object> ParseJson(); |
32 | 58 |
33 INLINE(void Advance()); | 59 INLINE(void Advance()); |
34 | 60 |
35 // The JSON lexical grammar is specified in the ECMAScript 5 standard, | 61 // The JSON lexical grammar is specified in the ECMAScript 5 standard, |
36 // section 15.12.1.1. The only allowed whitespace characters between tokens | 62 // section 15.12.1.1. The only allowed whitespace characters between tokens |
37 // are tab, carriage-return, newline and space. | 63 // are tab, carriage-return, newline and space. |
38 | 64 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 Zone zone_; | 156 Zone zone_; |
131 Handle<JSFunction> object_constructor_; | 157 Handle<JSFunction> object_constructor_; |
132 uc32 c0_; | 158 uc32 c0_; |
133 int position_; | 159 int position_; |
134 }; | 160 }; |
135 | 161 |
136 } // namespace internal | 162 } // namespace internal |
137 } // namespace v8 | 163 } // namespace v8 |
138 | 164 |
139 #endif // V8_JSON_PARSER_H_ | 165 #endif // V8_JSON_PARSER_H_ |
OLD | NEW |