OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_JSON_PARSER_H_ | 5 #ifndef V8_JSON_PARSER_H_ |
6 #define V8_JSON_PARSER_H_ | 6 #define V8_JSON_PARSER_H_ |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/char-predicates-inl.h" | 10 #include "src/char-predicates-inl.h" |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 value = ParseJsonValue(); | 380 value = ParseJsonValue(); |
381 if (value.is_null()) return ReportUnexpectedCharacter(); | 381 if (value.is_null()) return ReportUnexpectedCharacter(); |
382 | 382 |
383 if (transitioning) { | 383 if (transitioning) { |
384 int descriptor = map->NumberOfOwnDescriptors(); | 384 int descriptor = map->NumberOfOwnDescriptors(); |
385 PropertyDetails details = | 385 PropertyDetails details = |
386 target->instance_descriptors()->GetDetails(descriptor); | 386 target->instance_descriptors()->GetDetails(descriptor); |
387 Representation expected_representation = details.representation(); | 387 Representation expected_representation = details.representation(); |
388 | 388 |
389 if (value->FitsRepresentation(expected_representation)) { | 389 if (value->FitsRepresentation(expected_representation)) { |
390 if (expected_representation.IsDouble()) { | 390 // If the target representation is double and the value is already |
391 value = Object::NewStorageFor(isolate(), value, | 391 // double, use the existing box. |
392 expected_representation); | 392 if (value->IsSmi() && expected_representation.IsDouble()) { |
| 393 value = factory()->NewHeapNumber( |
| 394 Handle<Smi>::cast(value)->value()); |
393 } else if (expected_representation.IsHeapObject() && | 395 } else if (expected_representation.IsHeapObject() && |
394 !target->instance_descriptors()->GetFieldType( | 396 !target->instance_descriptors()->GetFieldType( |
395 descriptor)->NowContains(value)) { | 397 descriptor)->NowContains(value)) { |
396 Handle<HeapType> value_type(value->OptimalType( | 398 Handle<HeapType> value_type(value->OptimalType( |
397 isolate(), expected_representation)); | 399 isolate(), expected_representation)); |
398 Map::GeneralizeFieldType(target, descriptor, value_type); | 400 Map::GeneralizeFieldType(target, descriptor, value_type); |
399 } | 401 } |
400 ASSERT(target->instance_descriptors()->GetFieldType( | 402 ASSERT(target->instance_descriptors()->GetFieldType( |
401 descriptor)->NowContains(value)); | 403 descriptor)->NowContains(value)); |
402 properties.Add(value, zone()); | 404 properties.Add(value, zone()); |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 | 783 |
782 ASSERT_EQ('"', c0_); | 784 ASSERT_EQ('"', c0_); |
783 // Advance past the last '"'. | 785 // Advance past the last '"'. |
784 AdvanceSkipWhitespace(); | 786 AdvanceSkipWhitespace(); |
785 return result; | 787 return result; |
786 } | 788 } |
787 | 789 |
788 } } // namespace v8::internal | 790 } } // namespace v8::internal |
789 | 791 |
790 #endif // V8_JSON_PARSER_H_ | 792 #endif // V8_JSON_PARSER_H_ |
OLD | NEW |