| 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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 } | 284 } |
| 285 return ReportUnexpectedCharacter(); | 285 return ReportUnexpectedCharacter(); |
| 286 } | 286 } |
| 287 return ReportUnexpectedCharacter(); | 287 return ReportUnexpectedCharacter(); |
| 288 } | 288 } |
| 289 | 289 |
| 290 | 290 |
| 291 // Parse a JSON object. Position must be right at '{'. | 291 // Parse a JSON object. Position must be right at '{'. |
| 292 template <bool seq_ascii> | 292 template <bool seq_ascii> |
| 293 Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() { | 293 Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() { |
| 294 Handle<Object> prototype; |
| 294 Handle<JSObject> json_object = | 295 Handle<JSObject> json_object = |
| 295 factory()->NewJSObject(object_constructor(), pretenure_); | 296 factory()->NewJSObject(object_constructor(), pretenure_); |
| 296 ASSERT_EQ(c0_, '{'); | 297 ASSERT_EQ(c0_, '{'); |
| 297 | 298 |
| 298 AdvanceSkipWhitespace(); | 299 AdvanceSkipWhitespace(); |
| 299 if (c0_ != '}') { | 300 if (c0_ != '}') { |
| 300 do { | 301 do { |
| 301 if (c0_ != '"') return ReportUnexpectedCharacter(); | 302 if (c0_ != '"') return ReportUnexpectedCharacter(); |
| 302 | 303 |
| 303 int start_position = position_; | 304 int start_position = position_; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 c0_ = '"'; | 339 c0_ = '"'; |
| 339 #endif | 340 #endif |
| 340 | 341 |
| 341 Handle<String> key = ParseJsonSymbol(); | 342 Handle<String> key = ParseJsonSymbol(); |
| 342 if (key.is_null() || c0_ != ':') return ReportUnexpectedCharacter(); | 343 if (key.is_null() || c0_ != ':') return ReportUnexpectedCharacter(); |
| 343 | 344 |
| 344 AdvanceSkipWhitespace(); | 345 AdvanceSkipWhitespace(); |
| 345 Handle<Object> value = ParseJsonValue(); | 346 Handle<Object> value = ParseJsonValue(); |
| 346 if (value.is_null()) return ReportUnexpectedCharacter(); | 347 if (value.is_null()) return ReportUnexpectedCharacter(); |
| 347 | 348 |
| 348 if (JSObject::TryTransitionToField(json_object, key)) { | 349 if (key->Equals(isolate()->heap()->Proto_symbol())) { |
| 349 int index = json_object->LastAddedFieldIndex(); | 350 prototype = value; |
| 350 json_object->FastPropertyAtPut(index, *value); | |
| 351 } else { | 351 } else { |
| 352 JSObject::SetLocalPropertyIgnoreAttributes( | 352 if (JSObject::TryTransitionToField(json_object, key)) { |
| 353 json_object, key, value, NONE); | 353 int index = json_object->LastAddedFieldIndex(); |
| 354 json_object->FastPropertyAtPut(index, *value); |
| 355 } else { |
| 356 JSObject::SetLocalPropertyIgnoreAttributes( |
| 357 json_object, key, value, NONE); |
| 358 } |
| 354 } | 359 } |
| 355 } while (MatchSkipWhiteSpace(',')); | 360 } while (MatchSkipWhiteSpace(',')); |
| 356 if (c0_ != '}') { | 361 if (c0_ != '}') { |
| 357 return ReportUnexpectedCharacter(); | 362 return ReportUnexpectedCharacter(); |
| 358 } | 363 } |
| 364 if (!prototype.is_null()) SetPrototype(json_object, prototype); |
| 359 } | 365 } |
| 360 AdvanceSkipWhitespace(); | 366 AdvanceSkipWhitespace(); |
| 361 return json_object; | 367 return json_object; |
| 362 } | 368 } |
| 363 | 369 |
| 364 // Parse a JSON array. Position must be right at '['. | 370 // Parse a JSON array. Position must be right at '['. |
| 365 template <bool seq_ascii> | 371 template <bool seq_ascii> |
| 366 Handle<Object> JsonParser<seq_ascii>::ParseJsonArray() { | 372 Handle<Object> JsonParser<seq_ascii>::ParseJsonArray() { |
| 367 ZoneScope zone_scope(zone(), DELETE_ON_EXIT); | 373 ZoneScope zone_scope(zone(), DELETE_ON_EXIT); |
| 368 ZoneList<Handle<Object> > elements(4, zone()); | 374 ZoneList<Handle<Object> > elements(4, zone()); |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 } | 705 } |
| 700 ASSERT_EQ('"', c0_); | 706 ASSERT_EQ('"', c0_); |
| 701 // Advance past the last '"'. | 707 // Advance past the last '"'. |
| 702 AdvanceSkipWhitespace(); | 708 AdvanceSkipWhitespace(); |
| 703 return result; | 709 return result; |
| 704 } | 710 } |
| 705 | 711 |
| 706 } } // namespace v8::internal | 712 } } // namespace v8::internal |
| 707 | 713 |
| 708 #endif // V8_JSON_PARSER_H_ | 714 #endif // V8_JSON_PARSER_H_ |
| OLD | NEW |