| OLD | NEW |
| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 if (seq_ascii) { | 188 if (seq_ascii) { |
| 189 seq_source_ = Handle<SeqAsciiString>::cast(source_); | 189 seq_source_ = Handle<SeqAsciiString>::cast(source_); |
| 190 } | 190 } |
| 191 | 191 |
| 192 // Set initial position right before the string. | 192 // Set initial position right before the string. |
| 193 position_ = -1; | 193 position_ = -1; |
| 194 // Advance to the first character (possibly EOS) | 194 // Advance to the first character (possibly EOS) |
| 195 AdvanceSkipWhitespace(); | 195 AdvanceSkipWhitespace(); |
| 196 Handle<Object> result = ParseJsonValue(); | 196 Handle<Object> result = ParseJsonValue(); |
| 197 if (result.is_null() || c0_ != kEndOfString) { | 197 if (result.is_null() || c0_ != kEndOfString) { |
| 198 // Some exception (for example stack overflow) is already pending. |
| 199 if (isolate_->has_pending_exception()) return Handle<Object>::null(); |
| 200 |
| 198 // Parse failed. Current character is the unexpected token. | 201 // Parse failed. Current character is the unexpected token. |
| 199 | |
| 200 const char* message; | 202 const char* message; |
| 201 Factory* factory = this->factory(); | 203 Factory* factory = this->factory(); |
| 202 Handle<JSArray> array; | 204 Handle<JSArray> array; |
| 203 | 205 |
| 204 switch (c0_) { | 206 switch (c0_) { |
| 205 case kEndOfString: | 207 case kEndOfString: |
| 206 message = "unexpected_eos"; | 208 message = "unexpected_eos"; |
| 207 array = factory->NewJSArray(0); | 209 array = factory->NewJSArray(0); |
| 208 break; | 210 break; |
| 209 case '-': | 211 case '-': |
| (...skipping 30 matching lines...) Expand all Loading... |
| 240 isolate()->Throw(*result, &location); | 242 isolate()->Throw(*result, &location); |
| 241 return Handle<Object>::null(); | 243 return Handle<Object>::null(); |
| 242 } | 244 } |
| 243 return result; | 245 return result; |
| 244 } | 246 } |
| 245 | 247 |
| 246 | 248 |
| 247 // Parse any JSON value. | 249 // Parse any JSON value. |
| 248 template <bool seq_ascii> | 250 template <bool seq_ascii> |
| 249 Handle<Object> JsonParser<seq_ascii>::ParseJsonValue() { | 251 Handle<Object> JsonParser<seq_ascii>::ParseJsonValue() { |
| 252 StackLimitCheck stack_check(isolate_); |
| 253 if (stack_check.HasOverflowed()) { |
| 254 isolate_->StackOverflow(); |
| 255 return Handle<Object>::null(); |
| 256 } |
| 257 |
| 250 if (c0_ == '"') return ParseJsonString(); | 258 if (c0_ == '"') return ParseJsonString(); |
| 251 if ((c0_ >= '0' && c0_ <= '9') || c0_ == '-') return ParseJsonNumber(); | 259 if ((c0_ >= '0' && c0_ <= '9') || c0_ == '-') return ParseJsonNumber(); |
| 252 if (c0_ == '{') return ParseJsonObject(); | 260 if (c0_ == '{') return ParseJsonObject(); |
| 253 if (c0_ == '[') return ParseJsonArray(); | 261 if (c0_ == '[') return ParseJsonArray(); |
| 254 if (c0_ == 'f') { | 262 if (c0_ == 'f') { |
| 255 if (AdvanceGetChar() == 'a' && AdvanceGetChar() == 'l' && | 263 if (AdvanceGetChar() == 'a' && AdvanceGetChar() == 'l' && |
| 256 AdvanceGetChar() == 's' && AdvanceGetChar() == 'e') { | 264 AdvanceGetChar() == 's' && AdvanceGetChar() == 'e') { |
| 257 AdvanceSkipWhitespace(); | 265 AdvanceSkipWhitespace(); |
| 258 return factory()->false_value(); | 266 return factory()->false_value(); |
| 259 } | 267 } |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 } | 684 } |
| 677 ASSERT_EQ('"', c0_); | 685 ASSERT_EQ('"', c0_); |
| 678 // Advance past the last '"'. | 686 // Advance past the last '"'. |
| 679 AdvanceSkipWhitespace(); | 687 AdvanceSkipWhitespace(); |
| 680 return result; | 688 return result; |
| 681 } | 689 } |
| 682 | 690 |
| 683 } } // namespace v8::internal | 691 } } // namespace v8::internal |
| 684 | 692 |
| 685 #endif // V8_JSON_PARSER_H_ | 693 #endif // V8_JSON_PARSER_H_ |
| OLD | NEW |