Chromium Code Reviews| 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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 | 297 | 
| 298 AdvanceSkipWhitespace(); | 298 AdvanceSkipWhitespace(); | 
| 299 if (c0_ != '}') { | 299 if (c0_ != '}') { | 
| 300 do { | 300 do { | 
| 301 if (c0_ != '"') return ReportUnexpectedCharacter(); | 301 if (c0_ != '"') return ReportUnexpectedCharacter(); | 
| 302 | 302 | 
| 303 int start_position = position_; | 303 int start_position = position_; | 
| 304 Advance(); | 304 Advance(); | 
| 305 | 305 | 
| 306 uint32_t index = 0; | 306 uint32_t index = 0; | 
| 307 while (c0_ >= '0' && c0_ <= '9') { | 307 if (c0_ >= '0' && c0_ <= '9') { | 
| 308 int d = c0_ - '0'; | 308 // Maybe an array index, try to parse it. | 
| 309 if (index > 429496729U - ((d > 5) ? 1 : 0)) break; | 309 if (c0_ == '0') { | 
| 310 index = (index * 10) + d; | 310 // With a leading zero, the string has to be "0" only to be an index. | 
| 311 Advance(); | 311 Advance(); | 
| 312 } else { | |
| 313 do { | |
| 314 int d = c0_ - '0'; | |
| 315 if (index > 429496729U - ((d > 5) ? 1 : 0)) break; | |
| 316 index = (index * 10) + d; | |
| 317 Advance(); | |
| 318 } while (c0_ >= '0' && c0_ <= '9'); | |
| 319 } | |
| 320 | |
| 321 if (position_ != start_position + 1 && c0_ == '"') { | |
| 
 
Toon Verwaest
2012/10/29 11:08:22
Now that this if moved into the parent if, the fir
 
Yang
2012/10/29 12:01:12
Done.
 
 | |
| 322 // Successfully parsed index, parse and store element. | |
| 323 AdvanceSkipWhitespace(); | |
| 324 | |
| 325 if (c0_ != ':') return ReportUnexpectedCharacter(); | |
| 326 AdvanceSkipWhitespace(); | |
| 327 Handle<Object> value = ParseJsonValue(); | |
| 328 if (value.is_null()) return ReportUnexpectedCharacter(); | |
| 329 | |
| 330 JSObject::SetOwnElement(json_object, index, value, kNonStrictMode); | |
| 331 continue; | |
| 332 } | |
| 333 // Not an index, fallback to the slow path. | |
| 312 } | 334 } | 
| 313 | 335 | 
| 314 if (position_ != start_position + 1 && c0_ == '"') { | 336 position_ = start_position; | 
| 315 AdvanceSkipWhitespace(); | |
| 316 | |
| 317 if (c0_ != ':') return ReportUnexpectedCharacter(); | |
| 318 AdvanceSkipWhitespace(); | |
| 319 Handle<Object> value = ParseJsonValue(); | |
| 320 if (value.is_null()) return ReportUnexpectedCharacter(); | |
| 321 | |
| 322 JSObject::SetOwnElement(json_object, index, value, kNonStrictMode); | |
| 323 } else { | |
| 324 position_ = start_position; | |
| 325 #ifdef DEBUG | 337 #ifdef DEBUG | 
| 326 c0_ = '"'; | 338 c0_ = '"'; | 
| 327 #endif | 339 #endif | 
| 328 | 340 | 
| 329 Handle<String> key = ParseJsonSymbol(); | 341 Handle<String> key = ParseJsonSymbol(); | 
| 330 if (key.is_null() || c0_ != ':') return ReportUnexpectedCharacter(); | 342 if (key.is_null() || c0_ != ':') return ReportUnexpectedCharacter(); | 
| 331 | 343 | 
| 332 AdvanceSkipWhitespace(); | 344 AdvanceSkipWhitespace(); | 
| 333 Handle<Object> value = ParseJsonValue(); | 345 Handle<Object> value = ParseJsonValue(); | 
| 334 if (value.is_null()) return ReportUnexpectedCharacter(); | 346 if (value.is_null()) return ReportUnexpectedCharacter(); | 
| 335 | 347 | 
| 336 if (key->Equals(isolate()->heap()->Proto_symbol())) { | 348 if (key->Equals(isolate()->heap()->Proto_symbol())) { | 
| 337 prototype = value; | 349 prototype = value; | 
| 350 } else { | |
| 351 if (JSObject::TryTransitionToField(json_object, key)) { | |
| 352 int index = json_object->LastAddedFieldIndex(); | |
| 353 json_object->FastPropertyAtPut(index, *value); | |
| 338 } else { | 354 } else { | 
| 339 if (JSObject::TryTransitionToField(json_object, key)) { | 355 JSObject::SetLocalPropertyIgnoreAttributes( | 
| 340 int index = json_object->LastAddedFieldIndex(); | 356 json_object, key, value, NONE); | 
| 341 json_object->FastPropertyAtPut(index, *value); | |
| 342 } else { | |
| 343 JSObject::SetLocalPropertyIgnoreAttributes( | |
| 344 json_object, key, value, NONE); | |
| 345 } | |
| 346 } | 357 } | 
| 347 } | 358 } | 
| 348 } while (MatchSkipWhiteSpace(',')); | 359 } while (MatchSkipWhiteSpace(',')); | 
| 349 if (c0_ != '}') { | 360 if (c0_ != '}') { | 
| 350 return ReportUnexpectedCharacter(); | 361 return ReportUnexpectedCharacter(); | 
| 351 } | 362 } | 
| 352 if (!prototype.is_null()) SetPrototype(json_object, prototype); | 363 if (!prototype.is_null()) SetPrototype(json_object, prototype); | 
| 353 } | 364 } | 
| 354 AdvanceSkipWhitespace(); | 365 AdvanceSkipWhitespace(); | 
| 355 return json_object; | 366 return json_object; | 
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 684 } | 695 } | 
| 685 ASSERT_EQ('"', c0_); | 696 ASSERT_EQ('"', c0_); | 
| 686 // Advance past the last '"'. | 697 // Advance past the last '"'. | 
| 687 AdvanceSkipWhitespace(); | 698 AdvanceSkipWhitespace(); | 
| 688 return result; | 699 return result; | 
| 689 } | 700 } | 
| 690 | 701 | 
| 691 } } // namespace v8::internal | 702 } } // namespace v8::internal | 
| 692 | 703 | 
| 693 #endif // V8_JSON_PARSER_H_ | 704 #endif // V8_JSON_PARSER_H_ | 
| OLD | NEW |