| 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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSObject( | 553 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSObject( |
| 554 Handle<JSObject> object) { | 554 Handle<JSObject> object) { |
| 555 HandleScope handle_scope(isolate_); | 555 HandleScope handle_scope(isolate_); |
| 556 Result stack_push = StackPush(object); | 556 Result stack_push = StackPush(object); |
| 557 if (stack_push != SUCCESS) return stack_push; | 557 if (stack_push != SUCCESS) return stack_push; |
| 558 if (object->IsJSGlobalProxy()) { | 558 if (object->IsJSGlobalProxy()) { |
| 559 object = Handle<JSObject>( | 559 object = Handle<JSObject>( |
| 560 JSObject::cast(object->GetPrototype()), isolate_); | 560 JSObject::cast(object->GetPrototype()), isolate_); |
| 561 ASSERT(object->IsGlobalObject()); | 561 ASSERT(object->IsGlobalObject()); |
| 562 } | 562 } |
| 563 bool has_exception = false; | 563 |
| 564 Handle<FixedArray> contents = | |
| 565 GetKeysInFixedArrayFor(object, LOCAL_ONLY, &has_exception); | |
| 566 if (has_exception) return EXCEPTION; | |
| 567 Append('{'); | 564 Append('{'); |
| 568 bool comma = false; | 565 bool comma = false; |
| 569 for (int i = 0; i < contents->length(); i++) { | 566 |
| 570 Object* key = contents->get(i); | 567 if (object->HasFastProperties() && |
| 571 Handle<String> key_handle; | 568 !object->HasIndexedInterceptor() && |
| 572 Handle<Object> property; | 569 !object->HasNamedInterceptor() && |
| 573 if (key->IsString()) { | 570 object->elements() == isolate_->heap()->empty_fixed_array()) { |
| 574 key_handle = Handle<String>(String::cast(key), isolate_); | 571 Handle<DescriptorArray> descs( |
| 575 property = GetProperty(object, key_handle); | 572 object->map()->instance_descriptors(), isolate_); |
| 576 } else { | 573 int num_desc = object->map()->NumberOfOwnDescriptors(); |
| 577 ASSERT(key->IsNumber()); | 574 Handle<Map> map(object->map()); |
| 578 key_handle = factory_->NumberToString(Handle<Object>(key, isolate_)); | 575 bool map_changed = false; |
| 579 uint32_t index; | 576 for (int i = 0; i < num_desc; i++) { |
| 580 if (key->IsSmi()) { | 577 Handle<String> key(descs->GetKey(i), isolate_); |
| 581 property = Object::GetElement(object, Smi::cast(key)->value()); | 578 PropertyDetails details = descs->GetDetails(i); |
| 582 } else if (key_handle->AsArrayIndex(&index)) { | 579 if (details.IsDontEnum() || details.IsDeleted()) continue; |
| 583 property = Object::GetElement(object, index); | 580 Handle<Object> property; |
| 581 if (details.type() == FIELD && !map_changed) { |
| 582 property = Handle<Object>( |
| 583 object->FastPropertyAt(descs->GetFieldIndex(i)), isolate_); |
| 584 } else { | 584 } else { |
| 585 property = GetProperty(object, key); |
| 586 } |
| 587 if (property.is_null()) return EXCEPTION; |
| 588 Result result = SerializeProperty(property, comma, key); |
| 589 if (!comma && result == SUCCESS) comma = true; |
| 590 if (result >= EXCEPTION) return result; |
| 591 if (*map != object->map()) map_changed = true; |
| 592 } |
| 593 } else { |
| 594 bool has_exception = false; |
| 595 Handle<FixedArray> contents = |
| 596 GetKeysInFixedArrayFor(object, LOCAL_ONLY, &has_exception); |
| 597 if (has_exception) return EXCEPTION; |
| 598 |
| 599 for (int i = 0; i < contents->length(); i++) { |
| 600 Object* key = contents->get(i); |
| 601 Handle<String> key_handle; |
| 602 Handle<Object> property; |
| 603 if (key->IsString()) { |
| 604 key_handle = Handle<String>(String::cast(key), isolate_); |
| 585 property = GetProperty(object, key_handle); | 605 property = GetProperty(object, key_handle); |
| 606 } else { |
| 607 ASSERT(key->IsNumber()); |
| 608 key_handle = factory_->NumberToString(Handle<Object>(key, isolate_)); |
| 609 uint32_t index; |
| 610 if (key->IsSmi()) { |
| 611 property = Object::GetElement(object, Smi::cast(key)->value()); |
| 612 } else if (key_handle->AsArrayIndex(&index)) { |
| 613 property = Object::GetElement(object, index); |
| 614 } else { |
| 615 property = GetProperty(object, key_handle); |
| 616 } |
| 586 } | 617 } |
| 618 if (property.is_null()) return EXCEPTION; |
| 619 Result result = SerializeProperty(property, comma, key_handle); |
| 620 if (!comma && result == SUCCESS) comma = true; |
| 621 if (result >= EXCEPTION) return result; |
| 587 } | 622 } |
| 588 if (property.is_null()) return EXCEPTION; | |
| 589 Result result = SerializeProperty(property, comma, key_handle); | |
| 590 if (!comma && result == SUCCESS) comma = true; | |
| 591 if (result >= EXCEPTION) return result; | |
| 592 } | 623 } |
| 624 |
| 593 Append('}'); | 625 Append('}'); |
| 594 StackPop(); | 626 StackPop(); |
| 595 current_part_ = handle_scope.CloseAndEscape(current_part_); | 627 current_part_ = handle_scope.CloseAndEscape(current_part_); |
| 596 return SUCCESS; | 628 return SUCCESS; |
| 597 } | 629 } |
| 598 | 630 |
| 599 | 631 |
| 600 void BasicJsonStringifier::ShrinkCurrentPart() { | 632 void BasicJsonStringifier::ShrinkCurrentPart() { |
| 601 ASSERT(current_index_ < part_length_); | 633 ASSERT(current_index_ < part_length_); |
| 602 if (current_index_ == 0) { | 634 if (current_index_ == 0) { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 SerializeString_<false, char>(flat.ToAsciiVector(), object); | 795 SerializeString_<false, char>(flat.ToAsciiVector(), object); |
| 764 } else { | 796 } else { |
| 765 SerializeString_<false, uc16>(flat.ToUC16Vector(), object); | 797 SerializeString_<false, uc16>(flat.ToUC16Vector(), object); |
| 766 } | 798 } |
| 767 } | 799 } |
| 768 } | 800 } |
| 769 | 801 |
| 770 } } // namespace v8::internal | 802 } } // namespace v8::internal |
| 771 | 803 |
| 772 #endif // V8_JSON_STRINGIFIER_H_ | 804 #endif // V8_JSON_STRINGIFIER_H_ |
| OLD | NEW |