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

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

Issue 223553003: Return MaybeHandle from JsonParser. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/api.cc ('k') | src/runtime.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 25 matching lines...) Expand all
36 #include "spaces-inl.h" 36 #include "spaces-inl.h"
37 #include "token.h" 37 #include "token.h"
38 38
39 namespace v8 { 39 namespace v8 {
40 namespace internal { 40 namespace internal {
41 41
42 // A simple json parser. 42 // A simple json parser.
43 template <bool seq_ascii> 43 template <bool seq_ascii>
44 class JsonParser BASE_EMBEDDED { 44 class JsonParser BASE_EMBEDDED {
45 public: 45 public:
46 static Handle<Object> Parse(Handle<String> source) { 46 static MaybeHandle<Object> Parse(Handle<String> source) {
47 return JsonParser(source).ParseJson(); 47 return JsonParser(source).ParseJson();
48 } 48 }
49 49
50 static const int kEndOfString = -1; 50 static const int kEndOfString = -1;
51 51
52 private: 52 private:
53 explicit JsonParser(Handle<String> source) 53 explicit JsonParser(Handle<String> source)
54 : source_(source), 54 : source_(source),
55 source_length_(source->length()), 55 source_length_(source->length()),
56 isolate_(source->map()->GetHeap()->isolate()), 56 isolate_(source->map()->GetHeap()->isolate()),
57 factory_(isolate_->factory()), 57 factory_(isolate_->factory()),
58 zone_(isolate_), 58 zone_(isolate_),
59 object_constructor_(isolate_->native_context()->object_function(), 59 object_constructor_(isolate_->native_context()->object_function(),
60 isolate_), 60 isolate_),
61 position_(-1) { 61 position_(-1) {
62 FlattenString(source_); 62 FlattenString(source_);
63 pretenure_ = (source_length_ >= kPretenureTreshold) ? TENURED : NOT_TENURED; 63 pretenure_ = (source_length_ >= kPretenureTreshold) ? TENURED : NOT_TENURED;
64 64
65 // Optimized fast case where we only have ASCII characters. 65 // Optimized fast case where we only have ASCII characters.
66 if (seq_ascii) { 66 if (seq_ascii) {
67 seq_source_ = Handle<SeqOneByteString>::cast(source_); 67 seq_source_ = Handle<SeqOneByteString>::cast(source_);
68 } 68 }
69 } 69 }
70 70
71 // Parse a string containing a single JSON value. 71 // Parse a string containing a single JSON value.
72 Handle<Object> ParseJson(); 72 MaybeHandle<Object> ParseJson();
73 73
74 inline void Advance() { 74 inline void Advance() {
75 position_++; 75 position_++;
76 if (position_ >= source_length_) { 76 if (position_ >= source_length_) {
77 c0_ = kEndOfString; 77 c0_ = kEndOfString;
78 } else if (seq_ascii) { 78 } else if (seq_ascii) {
79 c0_ = seq_source_->SeqOneByteStringGet(position_); 79 c0_ = seq_source_->SeqOneByteStringGet(position_);
80 } else { 80 } else {
81 c0_ = source_->Get(position_); 81 c0_ = source_->Get(position_);
82 } 82 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 PretenureFlag pretenure_; 212 PretenureFlag pretenure_;
213 Isolate* isolate_; 213 Isolate* isolate_;
214 Factory* factory_; 214 Factory* factory_;
215 Zone zone_; 215 Zone zone_;
216 Handle<JSFunction> object_constructor_; 216 Handle<JSFunction> object_constructor_;
217 uc32 c0_; 217 uc32 c0_;
218 int position_; 218 int position_;
219 }; 219 };
220 220
221 template <bool seq_ascii> 221 template <bool seq_ascii>
222 Handle<Object> JsonParser<seq_ascii>::ParseJson() { 222 MaybeHandle<Object> JsonParser<seq_ascii>::ParseJson() {
223 // Advance to the first character (possibly EOS) 223 // Advance to the first character (possibly EOS)
224 AdvanceSkipWhitespace(); 224 AdvanceSkipWhitespace();
225 Handle<Object> result = ParseJsonValue(); 225 Handle<Object> result = ParseJsonValue();
226 if (result.is_null() || c0_ != kEndOfString) { 226 if (result.is_null() || c0_ != kEndOfString) {
227 // Some exception (for example stack overflow) is already pending. 227 // Some exception (for example stack overflow) is already pending.
228 if (isolate_->has_pending_exception()) return Handle<Object>::null(); 228 if (isolate_->has_pending_exception()) return Handle<Object>::null();
229 229
230 // Parse failed. Current character is the unexpected token. 230 // Parse failed. Current character is the unexpected token.
231 const char* message; 231 const char* message;
232 Factory* factory = this->factory(); 232 Factory* factory = this->factory();
(...skipping 28 matching lines...) Expand all
261 LookupSingleCharacterStringFromCode(isolate_, c0_); 261 LookupSingleCharacterStringFromCode(isolate_, c0_);
262 Handle<FixedArray> element = factory->NewFixedArray(1); 262 Handle<FixedArray> element = factory->NewFixedArray(1);
263 element->set(0, *name); 263 element->set(0, *name);
264 array = factory->NewJSArrayWithElements(element); 264 array = factory->NewJSArrayWithElements(element);
265 break; 265 break;
266 } 266 }
267 267
268 MessageLocation location(factory->NewScript(source_), 268 MessageLocation location(factory->NewScript(source_),
269 position_, 269 position_,
270 position_ + 1); 270 position_ + 1);
271 Handle<Object> result = factory->NewSyntaxError(message, array); 271 Handle<Object> error = factory->NewSyntaxError(message, array);
272 isolate()->Throw(*result, &location); 272 return isolate()->template Throw<Object>(error, &location);
273 return Handle<Object>::null();
274 } 273 }
275 return result; 274 return result;
276 } 275 }
277 276
278 277
279 // Parse any JSON value. 278 // Parse any JSON value.
280 template <bool seq_ascii> 279 template <bool seq_ascii>
281 Handle<Object> JsonParser<seq_ascii>::ParseJsonValue() { 280 Handle<Object> JsonParser<seq_ascii>::ParseJsonValue() {
282 StackLimitCheck stack_check(isolate_); 281 StackLimitCheck stack_check(isolate_);
283 if (stack_check.HasOverflowed()) { 282 if (stack_check.HasOverflowed()) {
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 798
800 ASSERT_EQ('"', c0_); 799 ASSERT_EQ('"', c0_);
801 // Advance past the last '"'. 800 // Advance past the last '"'.
802 AdvanceSkipWhitespace(); 801 AdvanceSkipWhitespace();
803 return result; 802 return result;
804 } 803 }
805 804
806 } } // namespace v8::internal 805 } } // namespace v8::internal
807 806
808 #endif // V8_JSON_PARSER_H_ 807 #endif // V8_JSON_PARSER_H_
OLDNEW
« no previous file with comments | « src/api.cc ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698