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

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

Issue 247063003: Handle boxed length in JSON stringify. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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 | « no previous file | no next file » | 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 Result SerializeDouble(double number); 135 Result SerializeDouble(double number);
136 INLINE(Result SerializeHeapNumber(Handle<HeapNumber> object)) { 136 INLINE(Result SerializeHeapNumber(Handle<HeapNumber> object)) {
137 return SerializeDouble(object->value()); 137 return SerializeDouble(object->value());
138 } 138 }
139 139
140 Result SerializeJSValue(Handle<JSValue> object); 140 Result SerializeJSValue(Handle<JSValue> object);
141 141
142 INLINE(Result SerializeJSArray(Handle<JSArray> object)); 142 INLINE(Result SerializeJSArray(Handle<JSArray> object));
143 INLINE(Result SerializeJSObject(Handle<JSObject> object)); 143 INLINE(Result SerializeJSObject(Handle<JSObject> object));
144 144
145 Result SerializeJSArraySlow(Handle<JSArray> object, int length); 145 Result SerializeJSArraySlow(Handle<JSArray> object, uint32_t length);
146 146
147 void SerializeString(Handle<String> object); 147 void SerializeString(Handle<String> object);
148 148
149 template <typename SrcChar, typename DestChar> 149 template <typename SrcChar, typename DestChar>
150 INLINE(static int SerializeStringUnchecked_(const SrcChar* src, 150 INLINE(static int SerializeStringUnchecked_(const SrcChar* src,
151 DestChar* dest, 151 DestChar* dest,
152 int length)); 152 int length));
153 153
154 template <bool is_ascii, typename Char> 154 template <bool is_ascii, typename Char>
155 INLINE(void SerializeString_(Handle<String> string)); 155 INLINE(void SerializeString_(Handle<String> string));
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 AppendAscii(DoubleToCString(number, buffer)); 562 AppendAscii(DoubleToCString(number, buffer));
563 return SUCCESS; 563 return SUCCESS;
564 } 564 }
565 565
566 566
567 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSArray( 567 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSArray(
568 Handle<JSArray> object) { 568 Handle<JSArray> object) {
569 HandleScope handle_scope(isolate_); 569 HandleScope handle_scope(isolate_);
570 Result stack_push = StackPush(object); 570 Result stack_push = StackPush(object);
571 if (stack_push != SUCCESS) return stack_push; 571 if (stack_push != SUCCESS) return stack_push;
572 int length = Smi::cast(object->length())->value(); 572 uint32_t length = 0;
573 CHECK(object->length()->ToArrayIndex(&length));
573 Append('['); 574 Append('[');
574 switch (object->GetElementsKind()) { 575 switch (object->GetElementsKind()) {
575 case FAST_SMI_ELEMENTS: { 576 case FAST_SMI_ELEMENTS: {
576 Handle<FixedArray> elements( 577 Handle<FixedArray> elements(
577 FixedArray::cast(object->elements()), isolate_); 578 FixedArray::cast(object->elements()), isolate_);
578 for (int i = 0; i < length; i++) { 579 for (uint32_t i = 0; i < length; i++) {
579 if (i > 0) Append(','); 580 if (i > 0) Append(',');
580 SerializeSmi(Smi::cast(elements->get(i))); 581 SerializeSmi(Smi::cast(elements->get(i)));
581 } 582 }
582 break; 583 break;
583 } 584 }
584 case FAST_DOUBLE_ELEMENTS: { 585 case FAST_DOUBLE_ELEMENTS: {
585 Handle<FixedDoubleArray> elements( 586 Handle<FixedDoubleArray> elements(
586 FixedDoubleArray::cast(object->elements()), isolate_); 587 FixedDoubleArray::cast(object->elements()), isolate_);
587 for (int i = 0; i < length; i++) { 588 for (uint32_t i = 0; i < length; i++) {
588 if (i > 0) Append(','); 589 if (i > 0) Append(',');
589 SerializeDouble(elements->get_scalar(i)); 590 SerializeDouble(elements->get_scalar(i));
590 } 591 }
591 break; 592 break;
592 } 593 }
593 case FAST_ELEMENTS: { 594 case FAST_ELEMENTS: {
594 Handle<FixedArray> elements( 595 Handle<FixedArray> elements(
595 FixedArray::cast(object->elements()), isolate_); 596 FixedArray::cast(object->elements()), isolate_);
596 for (int i = 0; i < length; i++) { 597 for (uint32_t i = 0; i < length; i++) {
597 if (i > 0) Append(','); 598 if (i > 0) Append(',');
598 Result result = 599 Result result =
599 SerializeElement(isolate_, 600 SerializeElement(isolate_,
600 Handle<Object>(elements->get(i), isolate_), 601 Handle<Object>(elements->get(i), isolate_),
601 i); 602 i);
602 if (result == SUCCESS) continue; 603 if (result == SUCCESS) continue;
603 if (result == UNCHANGED) { 604 if (result == UNCHANGED) {
604 AppendAscii("null"); 605 AppendAscii("null");
605 } else { 606 } else {
606 return result; 607 return result;
(...skipping 11 matching lines...) Expand all
618 } 619 }
619 } 620 }
620 Append(']'); 621 Append(']');
621 StackPop(); 622 StackPop();
622 current_part_ = handle_scope.CloseAndEscape(current_part_); 623 current_part_ = handle_scope.CloseAndEscape(current_part_);
623 return SUCCESS; 624 return SUCCESS;
624 } 625 }
625 626
626 627
627 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSArraySlow( 628 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSArraySlow(
628 Handle<JSArray> object, int length) { 629 Handle<JSArray> object, uint32_t length) {
629 for (int i = 0; i < length; i++) { 630 for (uint32_t i = 0; i < length; i++) {
630 if (i > 0) Append(','); 631 if (i > 0) Append(',');
631 Handle<Object> element; 632 Handle<Object> element;
632 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 633 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
633 isolate_, element, 634 isolate_, element,
634 Object::GetElement(isolate_, object, i), 635 Object::GetElement(isolate_, object, i),
635 EXCEPTION); 636 EXCEPTION);
636 if (element->IsUndefined()) { 637 if (element->IsUndefined()) {
637 AppendAscii("null"); 638 AppendAscii("null");
638 } else { 639 } else {
639 Result result = SerializeElement(isolate_, element, i); 640 Result result = SerializeElement(isolate_, element, i);
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 SerializeString_<false, uint8_t>(object); 898 SerializeString_<false, uint8_t>(object);
898 } else { 899 } else {
899 SerializeString_<false, uc16>(object); 900 SerializeString_<false, uc16>(object);
900 } 901 }
901 } 902 }
902 } 903 }
903 904
904 } } // namespace v8::internal 905 } } // namespace v8::internal
905 906
906 #endif // V8_JSON_STRINGIFIER_H_ 907 #endif // V8_JSON_STRINGIFIER_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698