| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 #include "src/json-stringifier.h" | 5 #include "src/json-stringifier.h" |
| 6 | 6 |
| 7 #include "src/conversions.h" | 7 #include "src/conversions.h" |
| 8 #include "src/lookup.h" | 8 #include "src/lookup.h" |
| 9 #include "src/messages.h" | 9 #include "src/messages.h" |
| 10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 return SUCCESS; | 527 return SUCCESS; |
| 528 } | 528 } |
| 529 | 529 |
| 530 JsonStringifier::Result JsonStringifier::SerializeJSReceiverSlow( | 530 JsonStringifier::Result JsonStringifier::SerializeJSReceiverSlow( |
| 531 Handle<JSReceiver> object) { | 531 Handle<JSReceiver> object) { |
| 532 Handle<FixedArray> contents = property_list_; | 532 Handle<FixedArray> contents = property_list_; |
| 533 if (contents.is_null()) { | 533 if (contents.is_null()) { |
| 534 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 534 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 535 isolate_, contents, | 535 isolate_, contents, |
| 536 KeyAccumulator::GetKeys(object, KeyCollectionMode::kOwnOnly, | 536 KeyAccumulator::GetKeys(object, KeyCollectionMode::kOwnOnly, |
| 537 ENUMERABLE_STRINGS), | 537 ENUMERABLE_STRINGS, |
| 538 GetKeysConversion::kConvertToString), |
| 538 EXCEPTION); | 539 EXCEPTION); |
| 539 } | 540 } |
| 540 builder_.AppendCharacter('{'); | 541 builder_.AppendCharacter('{'); |
| 541 Indent(); | 542 Indent(); |
| 542 bool comma = false; | 543 bool comma = false; |
| 543 for (int i = 0; i < contents->length(); i++) { | 544 for (int i = 0; i < contents->length(); i++) { |
| 544 Object* key = contents->get(i); | 545 Handle<String> key(String::cast(contents->get(i)), isolate_); |
| 545 Handle<String> key_handle; | |
| 546 MaybeHandle<Object> maybe_property; | |
| 547 if (key->IsString()) { | |
| 548 key_handle = Handle<String>(String::cast(key), isolate_); | |
| 549 maybe_property = Object::GetPropertyOrElement(object, key_handle); | |
| 550 } else { | |
| 551 DCHECK(key->IsNumber()); | |
| 552 key_handle = factory()->NumberToString(Handle<Object>(key, isolate_)); | |
| 553 if (key->IsSmi()) { | |
| 554 maybe_property = | |
| 555 JSReceiver::GetElement(isolate_, object, Smi::cast(key)->value()); | |
| 556 } else { | |
| 557 maybe_property = Object::GetPropertyOrElement(object, key_handle); | |
| 558 } | |
| 559 } | |
| 560 Handle<Object> property; | 546 Handle<Object> property; |
| 561 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate_, property, maybe_property, | 547 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate_, property, |
| 548 Object::GetPropertyOrElement(object, key), |
| 562 EXCEPTION); | 549 EXCEPTION); |
| 563 Result result = SerializeProperty(property, comma, key_handle); | 550 Result result = SerializeProperty(property, comma, key); |
| 564 if (!comma && result == SUCCESS) comma = true; | 551 if (!comma && result == SUCCESS) comma = true; |
| 565 if (result == EXCEPTION) return result; | 552 if (result == EXCEPTION) return result; |
| 566 } | 553 } |
| 567 Unindent(); | 554 Unindent(); |
| 568 if (comma) NewLine(); | 555 if (comma) NewLine(); |
| 569 builder_.AppendCharacter('}'); | 556 builder_.AppendCharacter('}'); |
| 570 return SUCCESS; | 557 return SUCCESS; |
| 571 } | 558 } |
| 572 | 559 |
| 573 JsonStringifier::Result JsonStringifier::SerializeJSProxy( | 560 JsonStringifier::Result JsonStringifier::SerializeJSProxy( |
| 574 Handle<JSProxy> object) { | 561 Handle<JSProxy> object) { |
| 562 HandleScope scope(isolate_); |
| 575 Result stack_push = StackPush(object); | 563 Result stack_push = StackPush(object); |
| 576 if (stack_push != SUCCESS) return stack_push; | 564 if (stack_push != SUCCESS) return stack_push; |
| 577 Maybe<bool> is_array = Object::IsArray(object); | 565 Maybe<bool> is_array = Object::IsArray(object); |
| 578 if (is_array.IsNothing()) return EXCEPTION; | 566 if (is_array.IsNothing()) return EXCEPTION; |
| 579 if (is_array.FromJust()) { | 567 if (is_array.FromJust()) { |
| 580 Handle<Object> length_object; | 568 Handle<Object> length_object; |
| 581 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 569 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 582 isolate_, length_object, | 570 isolate_, length_object, |
| 583 Object::GetLengthFromArrayLike(isolate_, object), EXCEPTION); | 571 Object::GetLengthFromArrayLike(isolate_, object), EXCEPTION); |
| 584 uint32_t length; | 572 uint32_t length; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 if (object->IsOneByteRepresentationUnderneath()) { | 682 if (object->IsOneByteRepresentationUnderneath()) { |
| 695 SerializeString_<uint8_t, uc16>(object); | 683 SerializeString_<uint8_t, uc16>(object); |
| 696 } else { | 684 } else { |
| 697 SerializeString_<uc16, uc16>(object); | 685 SerializeString_<uc16, uc16>(object); |
| 698 } | 686 } |
| 699 } | 687 } |
| 700 } | 688 } |
| 701 | 689 |
| 702 } // namespace internal | 690 } // namespace internal |
| 703 } // namespace v8 | 691 } // namespace v8 |
| OLD | NEW |