OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 bool deferred_comma, | 84 bool deferred_comma, |
85 bool deferred_key); | 85 bool deferred_key); |
86 | 86 |
87 // Entry point to serialize the object. | 87 // Entry point to serialize the object. |
88 INLINE(Result SerializeObject(Handle<Object> obj)) { | 88 INLINE(Result SerializeObject(Handle<Object> obj)) { |
89 return Serialize_<false>(obj, false, factory_->empty_string()); | 89 return Serialize_<false>(obj, false, factory_->empty_string()); |
90 } | 90 } |
91 | 91 |
92 // Serialize an array element. | 92 // Serialize an array element. |
93 // The index may serve as argument for the toJSON function. | 93 // The index may serve as argument for the toJSON function. |
94 INLINE(Result SerializeElement(Handle<Object> object, int i)) { | 94 INLINE(Result SerializeElement(Isolate* isolate, |
95 return Serialize_<false>(object, false, Handle<Object>(Smi::FromInt(i))); | 95 Handle<Object> object, |
| 96 int i)) { |
| 97 return Serialize_<false>(object, |
| 98 false, |
| 99 Handle<Object>(Smi::FromInt(i), isolate)); |
96 } | 100 } |
97 | 101 |
98 // Serialize a object property. | 102 // Serialize a object property. |
99 // The key may or may not be serialized depending on the property. | 103 // The key may or may not be serialized depending on the property. |
100 // The key may also serve as argument for the toJSON function. | 104 // The key may also serve as argument for the toJSON function. |
101 INLINE(Result SerializeProperty(Handle<Object> object, | 105 INLINE(Result SerializeProperty(Handle<Object> object, |
102 bool deferred_comma, | 106 bool deferred_comma, |
103 Handle<String> deferred_key)) { | 107 Handle<String> deferred_key)) { |
104 ASSERT(!deferred_key.is_null()); | 108 ASSERT(!deferred_key.is_null()); |
105 return Serialize_<true>(object, deferred_comma, deferred_key); | 109 return Serialize_<true>(object, deferred_comma, deferred_key); |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 SerializeDouble(elements->get_scalar(i)); | 501 SerializeDouble(elements->get_scalar(i)); |
498 } | 502 } |
499 break; | 503 break; |
500 } | 504 } |
501 case FAST_ELEMENTS: { | 505 case FAST_ELEMENTS: { |
502 Handle<FixedArray> elements( | 506 Handle<FixedArray> elements( |
503 FixedArray::cast(object->elements()), isolate_); | 507 FixedArray::cast(object->elements()), isolate_); |
504 for (int i = 0; i < length; i++) { | 508 for (int i = 0; i < length; i++) { |
505 if (i > 0) Append(','); | 509 if (i > 0) Append(','); |
506 Result result = | 510 Result result = |
507 SerializeElement(Handle<Object>(elements->get(i), isolate_), i); | 511 SerializeElement(isolate_, |
| 512 Handle<Object>(elements->get(i), isolate_), |
| 513 i); |
508 if (result == SUCCESS) continue; | 514 if (result == SUCCESS) continue; |
509 if (result == UNCHANGED) { | 515 if (result == UNCHANGED) { |
510 AppendAscii("null"); | 516 AppendAscii("null"); |
511 } else { | 517 } else { |
512 return result; | 518 return result; |
513 } | 519 } |
514 } | 520 } |
515 break; | 521 break; |
516 } | 522 } |
517 // TODO(yangguo): The FAST_HOLEY_* cases could be handled in a faster way. | 523 // TODO(yangguo): The FAST_HOLEY_* cases could be handled in a faster way. |
(...skipping 13 matching lines...) Expand all Loading... |
531 | 537 |
532 | 538 |
533 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSArraySlow( | 539 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSArraySlow( |
534 Handle<JSArray> object, int length) { | 540 Handle<JSArray> object, int length) { |
535 for (int i = 0; i < length; i++) { | 541 for (int i = 0; i < length; i++) { |
536 if (i > 0) Append(','); | 542 if (i > 0) Append(','); |
537 Handle<Object> element = Object::GetElement(object, i); | 543 Handle<Object> element = Object::GetElement(object, i); |
538 if (element->IsUndefined()) { | 544 if (element->IsUndefined()) { |
539 AppendAscii("null"); | 545 AppendAscii("null"); |
540 } else { | 546 } else { |
541 Result result = SerializeElement(element, i); | 547 Result result = SerializeElement(object->GetIsolate(), element, i); |
542 if (result == SUCCESS) continue; | 548 if (result == SUCCESS) continue; |
543 if (result == UNCHANGED) { | 549 if (result == UNCHANGED) { |
544 AppendAscii("null"); | 550 AppendAscii("null"); |
545 } else { | 551 } else { |
546 return result; | 552 return result; |
547 } | 553 } |
548 } | 554 } |
549 } | 555 } |
550 return SUCCESS; | 556 return SUCCESS; |
551 } | 557 } |
(...skipping 22 matching lines...) Expand all Loading... |
574 Handle<String> key(map->instance_descriptors()->GetKey(i), isolate_); | 580 Handle<String> key(map->instance_descriptors()->GetKey(i), isolate_); |
575 PropertyDetails details = map->instance_descriptors()->GetDetails(i); | 581 PropertyDetails details = map->instance_descriptors()->GetDetails(i); |
576 if (details.IsDontEnum() || details.IsDeleted()) continue; | 582 if (details.IsDontEnum() || details.IsDeleted()) continue; |
577 Handle<Object> property; | 583 Handle<Object> property; |
578 if (details.type() == FIELD && *map == object->map()) { | 584 if (details.type() == FIELD && *map == object->map()) { |
579 property = Handle<Object>( | 585 property = Handle<Object>( |
580 object->FastPropertyAt( | 586 object->FastPropertyAt( |
581 map->instance_descriptors()->GetFieldIndex(i)), | 587 map->instance_descriptors()->GetFieldIndex(i)), |
582 isolate_); | 588 isolate_); |
583 } else { | 589 } else { |
584 property = GetProperty(object, key); | 590 property = GetProperty(isolate_, object, key); |
585 if (property.is_null()) return EXCEPTION; | 591 if (property.is_null()) return EXCEPTION; |
586 } | 592 } |
587 Result result = SerializeProperty(property, comma, key); | 593 Result result = SerializeProperty(property, comma, key); |
588 if (!comma && result == SUCCESS) comma = true; | 594 if (!comma && result == SUCCESS) comma = true; |
589 if (result >= EXCEPTION) return result; | 595 if (result >= EXCEPTION) return result; |
590 } | 596 } |
591 } else { | 597 } else { |
592 bool has_exception = false; | 598 bool has_exception = false; |
593 Handle<FixedArray> contents = | 599 Handle<FixedArray> contents = |
594 GetKeysInFixedArrayFor(object, LOCAL_ONLY, &has_exception); | 600 GetKeysInFixedArrayFor(object, LOCAL_ONLY, &has_exception); |
595 if (has_exception) return EXCEPTION; | 601 if (has_exception) return EXCEPTION; |
596 | 602 |
597 for (int i = 0; i < contents->length(); i++) { | 603 for (int i = 0; i < contents->length(); i++) { |
598 Object* key = contents->get(i); | 604 Object* key = contents->get(i); |
599 Handle<String> key_handle; | 605 Handle<String> key_handle; |
600 Handle<Object> property; | 606 Handle<Object> property; |
601 if (key->IsString()) { | 607 if (key->IsString()) { |
602 key_handle = Handle<String>(String::cast(key), isolate_); | 608 key_handle = Handle<String>(String::cast(key), isolate_); |
603 property = GetProperty(object, key_handle); | 609 property = GetProperty(isolate_, object, key_handle); |
604 } else { | 610 } else { |
605 ASSERT(key->IsNumber()); | 611 ASSERT(key->IsNumber()); |
606 key_handle = factory_->NumberToString(Handle<Object>(key, isolate_)); | 612 key_handle = factory_->NumberToString(Handle<Object>(key, isolate_)); |
607 uint32_t index; | 613 uint32_t index; |
608 if (key->IsSmi()) { | 614 if (key->IsSmi()) { |
609 property = Object::GetElement(object, Smi::cast(key)->value()); | 615 property = Object::GetElement(object, Smi::cast(key)->value()); |
610 } else if (key_handle->AsArrayIndex(&index)) { | 616 } else if (key_handle->AsArrayIndex(&index)) { |
611 property = Object::GetElement(object, index); | 617 property = Object::GetElement(object, index); |
612 } else { | 618 } else { |
613 property = GetProperty(object, key_handle); | 619 property = GetProperty(isolate_, object, key_handle); |
614 } | 620 } |
615 } | 621 } |
616 if (property.is_null()) return EXCEPTION; | 622 if (property.is_null()) return EXCEPTION; |
617 Result result = SerializeProperty(property, comma, key_handle); | 623 Result result = SerializeProperty(property, comma, key_handle); |
618 if (!comma && result == SUCCESS) comma = true; | 624 if (!comma && result == SUCCESS) comma = true; |
619 if (result >= EXCEPTION) return result; | 625 if (result >= EXCEPTION) return result; |
620 } | 626 } |
621 } | 627 } |
622 | 628 |
623 Append('}'); | 629 Append('}'); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 SerializeString_<false, uint8_t>(object); | 779 SerializeString_<false, uint8_t>(object); |
774 } else { | 780 } else { |
775 SerializeString_<false, uc16>(object); | 781 SerializeString_<false, uc16>(object); |
776 } | 782 } |
777 } | 783 } |
778 } | 784 } |
779 | 785 |
780 } } // namespace v8::internal | 786 } } // namespace v8::internal |
781 | 787 |
782 #endif // V8_JSON_STRINGIFIER_H_ | 788 #endif // V8_JSON_STRINGIFIER_H_ |
OLD | NEW |