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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 return ParseJsonArray(); | 282 return ParseJsonArray(); |
283 default: | 283 default: |
284 return ReportUnexpectedCharacter(); | 284 return ReportUnexpectedCharacter(); |
285 } | 285 } |
286 } | 286 } |
287 | 287 |
288 | 288 |
289 // Parse a JSON object. Position must be right at '{'. | 289 // Parse a JSON object. Position must be right at '{'. |
290 template <bool seq_ascii> | 290 template <bool seq_ascii> |
291 Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() { | 291 Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() { |
292 int current_index = 0; | |
293 Handle<Object> prototype; | 292 Handle<Object> prototype; |
294 Handle<JSFunction> object_constructor( | 293 Handle<JSFunction> object_constructor( |
295 isolate()->native_context()->object_function()); | 294 isolate()->native_context()->object_function()); |
296 Handle<JSObject> json_object = | 295 Handle<JSObject> json_object = |
297 isolate()->factory()->NewJSObject(object_constructor); | 296 isolate()->factory()->NewJSObject(object_constructor); |
298 ASSERT_EQ(c0_, '{'); | 297 ASSERT_EQ(c0_, '{'); |
299 | 298 |
300 AdvanceSkipWhitespace(); | 299 AdvanceSkipWhitespace(); |
301 if (c0_ != '}') { | 300 if (c0_ != '}') { |
302 do { | 301 do { |
(...skipping 29 matching lines...) Expand all Loading... |
332 if (key.is_null() || c0_ != ':') return ReportUnexpectedCharacter(); | 331 if (key.is_null() || c0_ != ':') return ReportUnexpectedCharacter(); |
333 | 332 |
334 AdvanceSkipWhitespace(); | 333 AdvanceSkipWhitespace(); |
335 Handle<Object> value = ParseJsonValue(); | 334 Handle<Object> value = ParseJsonValue(); |
336 if (value.is_null()) return ReportUnexpectedCharacter(); | 335 if (value.is_null()) return ReportUnexpectedCharacter(); |
337 | 336 |
338 if (key->Equals(isolate()->heap()->Proto_symbol())) { | 337 if (key->Equals(isolate()->heap()->Proto_symbol())) { |
339 prototype = value; | 338 prototype = value; |
340 } else { | 339 } else { |
341 if (JSObject::TryTransitionToField(json_object, key)) { | 340 if (JSObject::TryTransitionToField(json_object, key)) { |
342 json_object->FastPropertyAtPut(current_index++, *value); | 341 int index = json_object->LastAddedFieldIndex(); |
| 342 json_object->FastPropertyAtPut(index, *value); |
343 } else { | 343 } else { |
344 JSObject::SetLocalPropertyIgnoreAttributes( | 344 JSObject::SetLocalPropertyIgnoreAttributes( |
345 json_object, key, value, NONE); | 345 json_object, key, value, NONE); |
346 current_index = json_object->NumberOfLocalProperties(); | |
347 } | 346 } |
348 } | 347 } |
349 } | 348 } |
350 } while (MatchSkipWhiteSpace(',')); | 349 } while (MatchSkipWhiteSpace(',')); |
351 if (c0_ != '}') { | 350 if (c0_ != '}') { |
352 return ReportUnexpectedCharacter(); | 351 return ReportUnexpectedCharacter(); |
353 } | 352 } |
354 if (!prototype.is_null()) SetPrototype(json_object, prototype); | 353 if (!prototype.is_null()) SetPrototype(json_object, prototype); |
355 } | 354 } |
356 AdvanceSkipWhitespace(); | 355 AdvanceSkipWhitespace(); |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 } | 678 } |
680 ASSERT_EQ('"', c0_); | 679 ASSERT_EQ('"', c0_); |
681 // Advance past the last '"'. | 680 // Advance past the last '"'. |
682 AdvanceSkipWhitespace(); | 681 AdvanceSkipWhitespace(); |
683 return result; | 682 return result; |
684 } | 683 } |
685 | 684 |
686 } } // namespace v8::internal | 685 } } // namespace v8::internal |
687 | 686 |
688 #endif // V8_JSON_PARSER_H_ | 687 #endif // V8_JSON_PARSER_H_ |
OLD | NEW |