Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(821)

Side by Side Diff: src/json-parser.h

Issue 14146005: Track representations of fields (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add test for tracking fields Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ic.cc ('k') | src/objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 Handle<Map> target = JSObject::FindTransitionToField(map, key); 397 Handle<Map> target = JSObject::FindTransitionToField(map, key);
398 // If a transition was found, follow it and continue. 398 // If a transition was found, follow it and continue.
399 if (!target.is_null()) { 399 if (!target.is_null()) {
400 map = target; 400 map = target;
401 } else { 401 } else {
402 // If no transition was found, commit the intermediate state to the 402 // If no transition was found, commit the intermediate state to the
403 // object and stop transitioning. 403 // object and stop transitioning.
404 JSObject::TransitionToMap(json_object, map); 404 JSObject::TransitionToMap(json_object, map);
405 int length = properties.length(); 405 int length = properties.length();
406 for (int i = 0; i < length; i++) { 406 for (int i = 0; i < length; i++) {
407 json_object->FastPropertyAtPut(i, *properties[i]); 407 Handle<Object> value = properties[i];
408 Representation representation =
409 map->instance_descriptors()->GetDetails(i).representation();
410 if (representation.IsDouble() && value->IsSmi()) {
411 // TODO(verwaest): Allocate heap number.
412 }
413 json_object->FastPropertyAtPut(i, *value);
408 } 414 }
409 transitioning = false; 415 transitioning = false;
410 } 416 }
411 } 417 }
412 if (c0_ != ':') return ReportUnexpectedCharacter(); 418 if (c0_ != ':') return ReportUnexpectedCharacter();
413 419
414 AdvanceSkipWhitespace(); 420 AdvanceSkipWhitespace();
415 value = ParseJsonValue(); 421 value = ParseJsonValue();
416 if (value.is_null()) return ReportUnexpectedCharacter(); 422 if (value.is_null()) return ReportUnexpectedCharacter();
417 423
418 properties.Add(value, zone()); 424 properties.Add(value, zone());
419 if (transitioning) continue; 425 if (transitioning) {
426 int field = properties.length() - 1;
427 Representation expected_representation =
428 map->instance_descriptors()->GetDetails(field).representation();
429 if (!value->FitsRepresentation(expected_representation)) {
430 map = Map::GeneralizeRepresentation(
431 map, field, value->OptimalRepresentation());
432 }
433 continue;
434 }
420 } else { 435 } else {
421 key = ParseJsonInternalizedString(); 436 key = ParseJsonInternalizedString();
422 if (key.is_null() || c0_ != ':') return ReportUnexpectedCharacter(); 437 if (key.is_null() || c0_ != ':') return ReportUnexpectedCharacter();
423 438
424 AdvanceSkipWhitespace(); 439 AdvanceSkipWhitespace();
425 value = ParseJsonValue(); 440 value = ParseJsonValue();
426 if (value.is_null()) return ReportUnexpectedCharacter(); 441 if (value.is_null()) return ReportUnexpectedCharacter();
427 } 442 }
428 443
429 JSObject::SetLocalPropertyIgnoreAttributes( 444 JSObject::SetLocalPropertyIgnoreAttributes(
430 json_object, key, value, NONE); 445 json_object, key, value, NONE);
431 } while (MatchSkipWhiteSpace(',')); 446 } while (MatchSkipWhiteSpace(','));
432 if (c0_ != '}') { 447 if (c0_ != '}') {
433 return ReportUnexpectedCharacter(); 448 return ReportUnexpectedCharacter();
434 } 449 }
435 450
436 // If we transitioned until the very end, transition the map now. 451 // If we transitioned until the very end, transition the map now.
437 if (transitioning) { 452 if (transitioning) {
438 JSObject::TransitionToMap(json_object, map); 453 JSObject::TransitionToMap(json_object, map);
439 int length = properties.length(); 454 int length = properties.length();
440 for (int i = 0; i < length; i++) { 455 for (int i = 0; i < length; i++) {
441 json_object->FastPropertyAtPut(i, *properties[i]); 456 Handle<Object> value = properties[i];
457 Representation representation =
458 map->instance_descriptors()->GetDetails(i).representation();
459 if (representation.IsDouble() && value->IsSmi()) {
460 // TODO(verwaest): Allocate heap number.
461 }
462 json_object->FastPropertyAtPut(i, *value);
442 } 463 }
443 } 464 }
444 } 465 }
445 AdvanceSkipWhitespace(); 466 AdvanceSkipWhitespace();
446 return scope.CloseAndEscape(json_object); 467 return scope.CloseAndEscape(json_object);
447 } 468 }
448 469
449 // Parse a JSON array. Position must be right at '['. 470 // Parse a JSON array. Position must be right at '['.
450 template <bool seq_ascii> 471 template <bool seq_ascii>
451 Handle<Object> JsonParser<seq_ascii>::ParseJsonArray() { 472 Handle<Object> JsonParser<seq_ascii>::ParseJsonArray() {
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 803
783 ASSERT_EQ('"', c0_); 804 ASSERT_EQ('"', c0_);
784 // Advance past the last '"'. 805 // Advance past the last '"'.
785 AdvanceSkipWhitespace(); 806 AdvanceSkipWhitespace();
786 return result; 807 return result;
787 } 808 }
788 809
789 } } // namespace v8::internal 810 } } // namespace v8::internal
790 811
791 #endif // V8_JSON_PARSER_H_ 812 #endif // V8_JSON_PARSER_H_
OLDNEW
« no previous file with comments | « src/ic.cc ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698