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

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

Issue 1458833003: Version 4.6.85.32 (cherry-pick) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@4.6
Patch Set: Created 5 years, 1 month 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 | « include/v8-version.h ('k') | src/snapshot/serialize.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 #ifndef V8_JSON_STRINGIFIER_H_ 5 #ifndef V8_JSON_STRINGIFIER_H_
6 #define V8_JSON_STRINGIFIER_H_ 6 #define V8_JSON_STRINGIFIER_H_
7 7
8 #include "src/conversions.h" 8 #include "src/conversions.h"
9 #include "src/lookup.h" 9 #include "src/lookup.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 Result SerializeDouble(double number); 75 Result SerializeDouble(double number);
76 INLINE(Result SerializeHeapNumber(Handle<HeapNumber> object)) { 76 INLINE(Result SerializeHeapNumber(Handle<HeapNumber> object)) {
77 return SerializeDouble(object->value()); 77 return SerializeDouble(object->value());
78 } 78 }
79 79
80 Result SerializeJSValue(Handle<JSValue> object); 80 Result SerializeJSValue(Handle<JSValue> object);
81 81
82 INLINE(Result SerializeJSArray(Handle<JSArray> object)); 82 INLINE(Result SerializeJSArray(Handle<JSArray> object));
83 INLINE(Result SerializeJSObject(Handle<JSObject> object)); 83 INLINE(Result SerializeJSObject(Handle<JSObject> object));
84 84
85 Result SerializeJSArraySlow(Handle<JSArray> object, uint32_t length); 85 Result SerializeJSArraySlow(Handle<JSArray> object, uint32_t start,
86 uint32_t length);
86 87
87 void SerializeString(Handle<String> object); 88 void SerializeString(Handle<String> object);
88 89
89 template <typename SrcChar, typename DestChar> 90 template <typename SrcChar, typename DestChar>
90 INLINE(static void SerializeStringUnchecked_( 91 INLINE(static void SerializeStringUnchecked_(
91 Vector<const SrcChar> src, 92 Vector<const SrcChar> src,
92 IncrementalStringBuilder::NoExtend<DestChar>* dest)); 93 IncrementalStringBuilder::NoExtend<DestChar>* dest));
93 94
94 template <typename SrcChar, typename DestChar> 95 template <typename SrcChar, typename DestChar>
95 INLINE(void SerializeString_(Handle<String> string)); 96 INLINE(void SerializeString_(Handle<String> string));
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSArray( 430 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSArray(
430 Handle<JSArray> object) { 431 Handle<JSArray> object) {
431 HandleScope handle_scope(isolate_); 432 HandleScope handle_scope(isolate_);
432 Result stack_push = StackPush(object); 433 Result stack_push = StackPush(object);
433 if (stack_push != SUCCESS) return stack_push; 434 if (stack_push != SUCCESS) return stack_push;
434 uint32_t length = 0; 435 uint32_t length = 0;
435 CHECK(object->length()->ToArrayLength(&length)); 436 CHECK(object->length()->ToArrayLength(&length));
436 builder_.AppendCharacter('['); 437 builder_.AppendCharacter('[');
437 switch (object->GetElementsKind()) { 438 switch (object->GetElementsKind()) {
438 case FAST_SMI_ELEMENTS: { 439 case FAST_SMI_ELEMENTS: {
439 Handle<FixedArray> elements( 440 Handle<FixedArray> elements(FixedArray::cast(object->elements()),
440 FixedArray::cast(object->elements()), isolate_); 441 isolate_);
441 for (uint32_t i = 0; i < length; i++) { 442 for (uint32_t i = 0; i < length; i++) {
442 if (i > 0) builder_.AppendCharacter(','); 443 if (i > 0) builder_.AppendCharacter(',');
443 SerializeSmi(Smi::cast(elements->get(i))); 444 SerializeSmi(Smi::cast(elements->get(i)));
444 } 445 }
445 break; 446 break;
446 } 447 }
447 case FAST_DOUBLE_ELEMENTS: { 448 case FAST_DOUBLE_ELEMENTS: {
448 // Empty array is FixedArray but not FixedDoubleArray. 449 // Empty array is FixedArray but not FixedDoubleArray.
449 if (length == 0) break; 450 if (length == 0) break;
450 Handle<FixedDoubleArray> elements( 451 Handle<FixedDoubleArray> elements(
451 FixedDoubleArray::cast(object->elements()), isolate_); 452 FixedDoubleArray::cast(object->elements()), isolate_);
452 for (uint32_t i = 0; i < length; i++) { 453 for (uint32_t i = 0; i < length; i++) {
453 if (i > 0) builder_.AppendCharacter(','); 454 if (i > 0) builder_.AppendCharacter(',');
454 SerializeDouble(elements->get_scalar(i)); 455 SerializeDouble(elements->get_scalar(i));
455 } 456 }
456 break; 457 break;
457 } 458 }
458 case FAST_ELEMENTS: { 459 case FAST_ELEMENTS: {
459 Handle<FixedArray> elements( 460 Handle<Object> old_length(object->length(), isolate_);
460 FixedArray::cast(object->elements()), isolate_);
461 for (uint32_t i = 0; i < length; i++) { 461 for (uint32_t i = 0; i < length; i++) {
462 if (object->length() != *old_length ||
463 object->GetElementsKind() != FAST_ELEMENTS) {
464 Result result = SerializeJSArraySlow(object, i, length);
465 if (result != SUCCESS) return result;
466 break;
467 }
462 if (i > 0) builder_.AppendCharacter(','); 468 if (i > 0) builder_.AppendCharacter(',');
463 Result result = 469 Result result = SerializeElement(
464 SerializeElement(isolate_, 470 isolate_,
465 Handle<Object>(elements->get(i), isolate_), 471 Handle<Object>(FixedArray::cast(object->elements())->get(i),
466 i); 472 isolate_),
473 i);
467 if (result == SUCCESS) continue; 474 if (result == SUCCESS) continue;
468 if (result == UNCHANGED) { 475 if (result == UNCHANGED) {
469 builder_.AppendCString("null"); 476 builder_.AppendCString("null");
470 } else { 477 } else {
471 return result; 478 return result;
472 } 479 }
473 } 480 }
474 break; 481 break;
475 } 482 }
476 // TODO(yangguo): The FAST_HOLEY_* cases could be handled in a faster way. 483 // The FAST_HOLEY_* cases could be handled in a faster way. They resemble
477 // They resemble the non-holey cases except that a prototype chain lookup 484 // the non-holey cases except that a lookup is necessary for holes.
478 // is necessary for holes.
479 default: { 485 default: {
480 Result result = SerializeJSArraySlow(object, length); 486 Result result = SerializeJSArraySlow(object, 0, length);
481 if (result != SUCCESS) return result; 487 if (result != SUCCESS) return result;
482 break; 488 break;
483 } 489 }
484 } 490 }
485 builder_.AppendCharacter(']'); 491 builder_.AppendCharacter(']');
486 StackPop(); 492 StackPop();
487 return SUCCESS; 493 return SUCCESS;
488 } 494 }
489 495
490 496
491 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSArraySlow( 497 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSArraySlow(
492 Handle<JSArray> object, uint32_t length) { 498 Handle<JSArray> object, uint32_t start, uint32_t length) {
493 for (uint32_t i = 0; i < length; i++) { 499 for (uint32_t i = start; i < length; i++) {
494 if (i > 0) builder_.AppendCharacter(','); 500 if (i > 0) builder_.AppendCharacter(',');
495 Handle<Object> element; 501 Handle<Object> element;
496 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 502 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
497 isolate_, element, 503 isolate_, element,
498 Object::GetElement(isolate_, object, i), 504 Object::GetElement(isolate_, object, i),
499 EXCEPTION); 505 EXCEPTION);
500 if (element->IsUndefined()) { 506 if (element->IsUndefined()) {
501 builder_.AppendCString("null"); 507 builder_.AppendCString("null");
502 } else { 508 } else {
503 Result result = SerializeElement(isolate_, element, i); 509 Result result = SerializeElement(isolate_, element, i);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 SerializeString_<uint8_t, uc16>(object); 677 SerializeString_<uint8_t, uc16>(object);
672 } else { 678 } else {
673 SerializeString_<uc16, uc16>(object); 679 SerializeString_<uc16, uc16>(object);
674 } 680 }
675 } 681 }
676 } 682 }
677 683
678 } } // namespace v8::internal 684 } } // namespace v8::internal
679 685
680 #endif // V8_JSON_STRINGIFIER_H_ 686 #endif // V8_JSON_STRINGIFIER_H_
OLDNEW
« no previous file with comments | « include/v8-version.h ('k') | src/snapshot/serialize.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698