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

Side by Side Diff: src/json-stringifier.cc

Issue 2026563002: [json] implement InternalizeJSONProperty in C++. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « src/json-parser.cc ('k') | src/runtime/runtime.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 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 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 StackPop(); 526 StackPop();
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, OWN_ONLY, ENUMERABLE_STRINGS), 536 KeyAccumulator::GetKeys(object, OWN_ONLY, ENUMERABLE_STRINGS,
537 CONVERT_TO_STRING),
537 EXCEPTION); 538 EXCEPTION);
538 } 539 }
539 builder_.AppendCharacter('{'); 540 builder_.AppendCharacter('{');
540 Indent(); 541 Indent();
541 bool comma = false; 542 bool comma = false;
542 for (int i = 0; i < contents->length(); i++) { 543 for (int i = 0; i < contents->length(); i++) {
543 Object* key = contents->get(i); 544 Handle<String> key(String::cast(contents->get(i)));
Camillo Bruni 2016/05/30 14:25:20 nit: pass in the isolate_ directly
544 Handle<String> key_handle;
545 MaybeHandle<Object> maybe_property;
546 if (key->IsString()) {
547 key_handle = Handle<String>(String::cast(key), isolate_);
548 maybe_property = Object::GetPropertyOrElement(object, key_handle);
549 } else {
550 DCHECK(key->IsNumber());
551 key_handle = factory()->NumberToString(Handle<Object>(key, isolate_));
552 if (key->IsSmi()) {
553 maybe_property =
554 JSReceiver::GetElement(isolate_, object, Smi::cast(key)->value());
555 } else {
556 maybe_property = Object::GetPropertyOrElement(object, key_handle);
557 }
558 }
559 Handle<Object> property; 545 Handle<Object> property;
560 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate_, property, maybe_property, 546 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate_, property,
547 Object::GetPropertyOrElement(object, key),
561 EXCEPTION); 548 EXCEPTION);
562 Result result = SerializeProperty(property, comma, key_handle); 549 Result result = SerializeProperty(property, comma, key);
563 if (!comma && result == SUCCESS) comma = true; 550 if (!comma && result == SUCCESS) comma = true;
564 if (result == EXCEPTION) return result; 551 if (result == EXCEPTION) return result;
565 } 552 }
566 Unindent(); 553 Unindent();
567 if (comma) NewLine(); 554 if (comma) NewLine();
568 builder_.AppendCharacter('}'); 555 builder_.AppendCharacter('}');
569 return SUCCESS; 556 return SUCCESS;
570 } 557 }
571 558
572 JsonStringifier::Result JsonStringifier::SerializeJSProxy( 559 JsonStringifier::Result JsonStringifier::SerializeJSProxy(
573 Handle<JSProxy> object) { 560 Handle<JSProxy> object) {
561 HandleScope scope(isolate_);
574 Result stack_push = StackPush(object); 562 Result stack_push = StackPush(object);
575 if (stack_push != SUCCESS) return stack_push; 563 if (stack_push != SUCCESS) return stack_push;
576 Maybe<bool> is_array = Object::IsArray(object); 564 Maybe<bool> is_array = Object::IsArray(object);
577 if (is_array.IsNothing()) return EXCEPTION; 565 if (is_array.IsNothing()) return EXCEPTION;
578 if (is_array.FromJust()) { 566 if (is_array.FromJust()) {
579 Handle<Object> length_object; 567 Handle<Object> length_object;
580 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 568 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
581 isolate_, length_object, 569 isolate_, length_object,
582 Object::GetLengthFromArrayLike(isolate_, object), EXCEPTION); 570 Object::GetLengthFromArrayLike(isolate_, object), EXCEPTION);
583 uint32_t length; 571 uint32_t length;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 if (object->IsOneByteRepresentationUnderneath()) { 681 if (object->IsOneByteRepresentationUnderneath()) {
694 SerializeString_<uint8_t, uc16>(object); 682 SerializeString_<uint8_t, uc16>(object);
695 } else { 683 } else {
696 SerializeString_<uc16, uc16>(object); 684 SerializeString_<uc16, uc16>(object);
697 } 685 }
698 } 686 }
699 } 687 }
700 688
701 } // namespace internal 689 } // namespace internal
702 } // namespace v8 690 } // namespace v8
OLDNEW
« no previous file with comments | « src/json-parser.cc ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698