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

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

Issue 231103002: Object::GetElements() and friends maybehandlification. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: FixedArray::UnionOfKeys() maybehandlified Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/isolate.cc ('k') | src/log.cc » ('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 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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 return SerializeGeneric(object, key, comma, deferred_string_key); 475 return SerializeGeneric(object, key, comma, deferred_string_key);
476 } 476 }
477 477
478 478
479 BasicJsonStringifier::Result BasicJsonStringifier::SerializeGeneric( 479 BasicJsonStringifier::Result BasicJsonStringifier::SerializeGeneric(
480 Handle<Object> object, 480 Handle<Object> object,
481 Handle<Object> key, 481 Handle<Object> key,
482 bool deferred_comma, 482 bool deferred_comma,
483 bool deferred_key) { 483 bool deferred_key) {
484 Handle<JSObject> builtins(isolate_->native_context()->builtins()); 484 Handle<JSObject> builtins(isolate_->native_context()->builtins());
485 Handle<JSFunction> builtin = 485 Handle<JSFunction> builtin = Handle<JSFunction>::cast(
486 Handle<JSFunction>::cast(GetProperty(builtins, "JSONSerializeAdapter")); 486 GetProperty(builtins, "JSONSerializeAdapter").ToHandleChecked());
487 487
488 Handle<Object> argv[] = { key, object }; 488 Handle<Object> argv[] = { key, object };
489 bool has_exception = false; 489 bool has_exception = false;
490 Handle<Object> result = 490 Handle<Object> result =
491 Execution::Call(isolate_, builtin, object, 2, argv, &has_exception); 491 Execution::Call(isolate_, builtin, object, 2, argv, &has_exception);
492 if (has_exception) return EXCEPTION; 492 if (has_exception) return EXCEPTION;
493 if (result->IsUndefined()) return UNCHANGED; 493 if (result->IsUndefined()) return UNCHANGED;
494 if (deferred_key) { 494 if (deferred_key) {
495 if (key->IsSmi()) key = factory_->NumberToString(key); 495 if (key->IsSmi()) key = factory_->NumberToString(key);
496 SerializeDeferredKey(deferred_comma, key); 496 SerializeDeferredKey(deferred_comma, key);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 StackPop(); 618 StackPop();
619 current_part_ = handle_scope.CloseAndEscape(current_part_); 619 current_part_ = handle_scope.CloseAndEscape(current_part_);
620 return SUCCESS; 620 return SUCCESS;
621 } 621 }
622 622
623 623
624 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSArraySlow( 624 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSArraySlow(
625 Handle<JSArray> object, int length) { 625 Handle<JSArray> object, int length) {
626 for (int i = 0; i < length; i++) { 626 for (int i = 0; i < length; i++) {
627 if (i > 0) Append(','); 627 if (i > 0) Append(',');
628 Handle<Object> element = Object::GetElement(isolate_, object, i); 628 Handle<Object> element;
629 RETURN_IF_EMPTY_HANDLE_VALUE(isolate_, element, EXCEPTION); 629 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
630 isolate_, element,
631 Object::GetElement(isolate_, object, i),
632 EXCEPTION);
630 if (element->IsUndefined()) { 633 if (element->IsUndefined()) {
631 AppendAscii("null"); 634 AppendAscii("null");
632 } else { 635 } else {
633 Result result = SerializeElement(isolate_, element, i); 636 Result result = SerializeElement(isolate_, element, i);
634 if (result == SUCCESS) continue; 637 if (result == SUCCESS) continue;
635 if (result == UNCHANGED) { 638 if (result == UNCHANGED) {
636 AppendAscii("null"); 639 AppendAscii("null");
637 } else { 640 } else {
638 return result; 641 return result;
639 } 642 }
(...skipping 29 matching lines...) Expand all
669 Handle<String> key = Handle<String>::cast(name); 672 Handle<String> key = Handle<String>::cast(name);
670 PropertyDetails details = map->instance_descriptors()->GetDetails(i); 673 PropertyDetails details = map->instance_descriptors()->GetDetails(i);
671 if (details.IsDontEnum()) continue; 674 if (details.IsDontEnum()) continue;
672 Handle<Object> property; 675 Handle<Object> property;
673 if (details.type() == FIELD && *map == object->map()) { 676 if (details.type() == FIELD && *map == object->map()) {
674 property = Handle<Object>( 677 property = Handle<Object>(
675 object->RawFastPropertyAt( 678 object->RawFastPropertyAt(
676 map->instance_descriptors()->GetFieldIndex(i)), 679 map->instance_descriptors()->GetFieldIndex(i)),
677 isolate_); 680 isolate_);
678 } else { 681 } else {
679 property = Object::GetPropertyOrElement(object, key); 682 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
680 RETURN_IF_EMPTY_HANDLE_VALUE(isolate_, property, EXCEPTION); 683 isolate_, property,
684 Object::GetPropertyOrElement(object, key),
685 EXCEPTION);
681 } 686 }
682 Result result = SerializeProperty(property, comma, key); 687 Result result = SerializeProperty(property, comma, key);
683 if (!comma && result == SUCCESS) comma = true; 688 if (!comma && result == SUCCESS) comma = true;
684 if (result >= EXCEPTION) return result; 689 if (result >= EXCEPTION) return result;
685 } 690 }
686 } else { 691 } else {
687 bool has_exception = false; 692 Handle<FixedArray> contents;
688 Handle<FixedArray> contents = 693 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
689 GetKeysInFixedArrayFor(object, LOCAL_ONLY, &has_exception); 694 isolate_, contents,
690 if (has_exception) return EXCEPTION; 695 GetKeysInFixedArrayFor(object, LOCAL_ONLY),
696 EXCEPTION);
691 697
692 for (int i = 0; i < contents->length(); i++) { 698 for (int i = 0; i < contents->length(); i++) {
693 Object* key = contents->get(i); 699 Object* key = contents->get(i);
694 Handle<String> key_handle; 700 Handle<String> key_handle;
695 Handle<Object> property; 701 MaybeHandle<Object> maybe_property;
696 if (key->IsString()) { 702 if (key->IsString()) {
697 key_handle = Handle<String>(String::cast(key), isolate_); 703 key_handle = Handle<String>(String::cast(key), isolate_);
698 property = Object::GetPropertyOrElement(object, key_handle); 704 maybe_property = Object::GetPropertyOrElement(object, key_handle);
699 } else { 705 } else {
700 ASSERT(key->IsNumber()); 706 ASSERT(key->IsNumber());
701 key_handle = factory_->NumberToString(Handle<Object>(key, isolate_)); 707 key_handle = factory_->NumberToString(Handle<Object>(key, isolate_));
702 uint32_t index; 708 uint32_t index;
703 if (key->IsSmi()) { 709 if (key->IsSmi()) {
704 property = Object::GetElement( 710 maybe_property = Object::GetElement(
705 isolate_, object, Smi::cast(key)->value()); 711 isolate_, object, Smi::cast(key)->value());
706 } else if (key_handle->AsArrayIndex(&index)) { 712 } else if (key_handle->AsArrayIndex(&index)) {
707 property = Object::GetElement(isolate_, object, index); 713 maybe_property = Object::GetElement(isolate_, object, index);
708 } else { 714 } else {
709 property = Object::GetPropertyOrElement(object, key_handle); 715 maybe_property = Object::GetPropertyOrElement(object, key_handle);
710 } 716 }
711 } 717 }
712 RETURN_IF_EMPTY_HANDLE_VALUE(isolate_, property, EXCEPTION); 718 Handle<Object> property;
719 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
720 isolate_, property, maybe_property, EXCEPTION);
713 Result result = SerializeProperty(property, comma, key_handle); 721 Result result = SerializeProperty(property, comma, key_handle);
714 if (!comma && result == SUCCESS) comma = true; 722 if (!comma && result == SUCCESS) comma = true;
715 if (result >= EXCEPTION) return result; 723 if (result >= EXCEPTION) return result;
716 } 724 }
717 } 725 }
718 726
719 Append('}'); 727 Append('}');
720 StackPop(); 728 StackPop();
721 current_part_ = handle_scope.CloseAndEscape(current_part_); 729 current_part_ = handle_scope.CloseAndEscape(current_part_);
722 return SUCCESS; 730 return SUCCESS;
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 SerializeString_<false, uint8_t>(object); 894 SerializeString_<false, uint8_t>(object);
887 } else { 895 } else {
888 SerializeString_<false, uc16>(object); 896 SerializeString_<false, uc16>(object);
889 } 897 }
890 } 898 }
891 } 899 }
892 900
893 } } // namespace v8::internal 901 } } // namespace v8::internal
894 902
895 #endif // V8_JSON_STRINGIFIER_H_ 903 #endif // V8_JSON_STRINGIFIER_H_
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | src/log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698