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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 Handle<JSFunction> object_constructor( | 294 Handle<JSFunction> object_constructor( |
295 isolate()->native_context()->object_function()); | 295 isolate()->native_context()->object_function()); |
296 Handle<JSObject> json_object = | 296 Handle<JSObject> json_object = |
297 isolate()->factory()->NewJSObject(object_constructor); | 297 isolate()->factory()->NewJSObject(object_constructor); |
298 ASSERT_EQ(c0_, '{'); | 298 ASSERT_EQ(c0_, '{'); |
299 | 299 |
300 AdvanceSkipWhitespace(); | 300 AdvanceSkipWhitespace(); |
301 if (c0_ != '}') { | 301 if (c0_ != '}') { |
302 do { | 302 do { |
303 if (c0_ != '"') return ReportUnexpectedCharacter(); | 303 if (c0_ != '"') return ReportUnexpectedCharacter(); |
304 Handle<String> key = ParseJsonSymbol(); | |
305 if (key.is_null() || c0_ != ':') return ReportUnexpectedCharacter(); | |
306 AdvanceSkipWhitespace(); | |
307 Handle<Object> value = ParseJsonValue(); | |
308 if (value.is_null()) return ReportUnexpectedCharacter(); | |
309 | 304 |
310 uint32_t index; | 305 int position = position_; |
Yang
2012/10/18 13:45:32
maybe something more descriptive than "position",
Toon Verwaest
2012/10/18 14:15:26
Done.
| |
311 if (key->AsArrayIndex(&index)) { | 306 Advance(); |
307 | |
308 int digits = 0; | |
309 uint32_t index = 0; | |
310 while (c0_ >= '0' && c0_ <= '9') { | |
311 index = index * 10 + c0_ - '0'; | |
312 digits++; | |
313 Advance(); | |
314 } | |
315 | |
316 if (digits > 0 && c0_ == '"' && digits < 10) { | |
Yang
2012/10/18 13:45:32
Why 10?
The logic of calculating array index (in S
| |
317 AdvanceSkipWhitespace(); | |
318 | |
319 if (c0_ != ':') return ReportUnexpectedCharacter(); | |
320 AdvanceSkipWhitespace(); | |
321 Handle<Object> value = ParseJsonValue(); | |
322 if (value.is_null()) return ReportUnexpectedCharacter(); | |
323 | |
312 JSObject::SetOwnElement(json_object, index, value, kNonStrictMode); | 324 JSObject::SetOwnElement(json_object, index, value, kNonStrictMode); |
313 } else if (key->Equals(isolate()->heap()->Proto_symbol())) { | |
314 prototype = value; | |
315 } else { | 325 } else { |
316 if (JSObject::TryTransitionToField(json_object, key)) { | 326 position_ = position; |
317 json_object->FastPropertyAtPut(current_index++, *value); | 327 #ifdef DEBUG |
328 c0_ = '"'; | |
329 #endif | |
330 | |
331 Handle<String> key = ParseJsonSymbol(); | |
332 if (key.is_null()) return ReportUnexpectedCharacter(); | |
Yang
2012/10/18 13:45:32
Keeping it as
if (key.is_null() || c0_ != ':') ret
Toon Verwaest
2012/10/18 14:15:26
Done.
| |
333 | |
334 if (c0_ != ':') return ReportUnexpectedCharacter(); | |
335 AdvanceSkipWhitespace(); | |
336 Handle<Object> value = ParseJsonValue(); | |
337 if (value.is_null()) return ReportUnexpectedCharacter(); | |
338 | |
339 if (key->AsArrayIndex(&index)) { | |
340 JSObject::SetOwnElement(json_object, index, value, kNonStrictMode); | |
341 } else if (key->Equals(isolate()->heap()->Proto_symbol())) { | |
342 prototype = value; | |
318 } else { | 343 } else { |
319 JSObject::SetLocalPropertyIgnoreAttributes( | 344 if (JSObject::TryTransitionToField(json_object, key)) { |
320 json_object, key, value, NONE); | 345 json_object->FastPropertyAtPut(current_index++, *value); |
346 } else { | |
347 JSObject::SetLocalPropertyIgnoreAttributes( | |
348 json_object, key, value, NONE); | |
349 } | |
321 } | 350 } |
322 } | 351 } |
323 } while (MatchSkipWhiteSpace(',')); | 352 } while (MatchSkipWhiteSpace(',')); |
324 if (c0_ != '}') { | 353 if (c0_ != '}') { |
325 return ReportUnexpectedCharacter(); | 354 return ReportUnexpectedCharacter(); |
326 } | 355 } |
327 if (!prototype.is_null()) SetPrototype(json_object, prototype); | 356 if (!prototype.is_null()) SetPrototype(json_object, prototype); |
328 } | 357 } |
329 AdvanceSkipWhitespace(); | 358 AdvanceSkipWhitespace(); |
330 return json_object; | 359 return json_object; |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
649 } | 678 } |
650 ASSERT_EQ('"', c0_); | 679 ASSERT_EQ('"', c0_); |
651 // Advance past the last '"'. | 680 // Advance past the last '"'. |
652 AdvanceSkipWhitespace(); | 681 AdvanceSkipWhitespace(); |
653 return result; | 682 return result; |
654 } | 683 } |
655 | 684 |
656 } } // namespace v8::internal | 685 } } // namespace v8::internal |
657 | 686 |
658 #endif // V8_JSON_PARSER_H_ | 687 #endif // V8_JSON_PARSER_H_ |
OLD | NEW |