| OLD | NEW |
| 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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 PropertyAttributes attr; | 360 PropertyAttributes attr; |
| 361 Handle<Object> fun = | 361 Handle<Object> fun = |
| 362 Object::GetProperty(object, object, &lookup, tojson_string_, &attr); | 362 Object::GetProperty(object, object, &lookup, tojson_string_, &attr); |
| 363 if (!fun->IsJSFunction()) return object; | 363 if (!fun->IsJSFunction()) return object; |
| 364 | 364 |
| 365 // Call toJSON function. | 365 // Call toJSON function. |
| 366 if (key->IsSmi()) key = factory_->NumberToString(key); | 366 if (key->IsSmi()) key = factory_->NumberToString(key); |
| 367 Handle<Object> argv[] = { key }; | 367 Handle<Object> argv[] = { key }; |
| 368 bool has_exception = false; | 368 bool has_exception = false; |
| 369 HandleScope scope(isolate_); | 369 HandleScope scope(isolate_); |
| 370 object = Execution::Call(fun, object, 1, argv, &has_exception); | 370 object = Execution::Call(isolate_, fun, object, 1, argv, &has_exception); |
| 371 // Return empty handle to signal an exception. | 371 // Return empty handle to signal an exception. |
| 372 if (has_exception) return Handle<Object>::null(); | 372 if (has_exception) return Handle<Object>::null(); |
| 373 return scope.CloseAndEscape(object); | 373 return scope.CloseAndEscape(object); |
| 374 } | 374 } |
| 375 | 375 |
| 376 | 376 |
| 377 BasicJsonStringifier::Result BasicJsonStringifier::StackPush( | 377 BasicJsonStringifier::Result BasicJsonStringifier::StackPush( |
| 378 Handle<Object> object) { | 378 Handle<Object> object) { |
| 379 StackLimitCheck check(isolate_); | 379 StackLimitCheck check(isolate_); |
| 380 if (check.HasOverflowed()) return STACK_OVERFLOW; | 380 if (check.HasOverflowed()) return STACK_OVERFLOW; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 Handle<Object> key, | 463 Handle<Object> key, |
| 464 bool deferred_comma, | 464 bool deferred_comma, |
| 465 bool deferred_key) { | 465 bool deferred_key) { |
| 466 Handle<JSObject> builtins(isolate_->native_context()->builtins()); | 466 Handle<JSObject> builtins(isolate_->native_context()->builtins()); |
| 467 Handle<JSFunction> builtin = | 467 Handle<JSFunction> builtin = |
| 468 Handle<JSFunction>::cast(GetProperty(builtins, "JSONSerializeAdapter")); | 468 Handle<JSFunction>::cast(GetProperty(builtins, "JSONSerializeAdapter")); |
| 469 | 469 |
| 470 Handle<Object> argv[] = { key, object }; | 470 Handle<Object> argv[] = { key, object }; |
| 471 bool has_exception = false; | 471 bool has_exception = false; |
| 472 Handle<Object> result = | 472 Handle<Object> result = |
| 473 Execution::Call(builtin, object, 2, argv, &has_exception); | 473 Execution::Call(isolate_, builtin, object, 2, argv, &has_exception); |
| 474 if (has_exception) return EXCEPTION; | 474 if (has_exception) return EXCEPTION; |
| 475 if (result->IsUndefined()) return UNCHANGED; | 475 if (result->IsUndefined()) return UNCHANGED; |
| 476 if (deferred_key) { | 476 if (deferred_key) { |
| 477 if (key->IsSmi()) key = factory_->NumberToString(key); | 477 if (key->IsSmi()) key = factory_->NumberToString(key); |
| 478 SerializeDeferredKey(deferred_comma, key); | 478 SerializeDeferredKey(deferred_comma, key); |
| 479 } | 479 } |
| 480 | 480 |
| 481 Handle<String> result_string = Handle<String>::cast(result); | 481 Handle<String> result_string = Handle<String>::cast(result); |
| 482 // Shrink current part, attach it to the accumulator, also attach the result | 482 // Shrink current part, attach it to the accumulator, also attach the result |
| 483 // string to the accumulator, and allocate a new part. | 483 // string to the accumulator, and allocate a new part. |
| 484 ShrinkCurrentPart(); // Shrink. | 484 ShrinkCurrentPart(); // Shrink. |
| 485 part_length_ = kInitialPartLength; // Allocate conservatively. | 485 part_length_ = kInitialPartLength; // Allocate conservatively. |
| 486 Extend(); // Attach current part and allocate new part. | 486 Extend(); // Attach current part and allocate new part. |
| 487 // Attach result string to the accumulator. | 487 // Attach result string to the accumulator. |
| 488 set_accumulator(factory_->NewConsString(accumulator(), result_string)); | 488 set_accumulator(factory_->NewConsString(accumulator(), result_string)); |
| 489 return SUCCESS; | 489 return SUCCESS; |
| 490 } | 490 } |
| 491 | 491 |
| 492 | 492 |
| 493 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSValue( | 493 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSValue( |
| 494 Handle<JSValue> object) { | 494 Handle<JSValue> object) { |
| 495 bool has_exception = false; | 495 bool has_exception = false; |
| 496 String* class_name = object->class_name(); | 496 String* class_name = object->class_name(); |
| 497 if (class_name == isolate_->heap()->String_string()) { | 497 if (class_name == isolate_->heap()->String_string()) { |
| 498 Handle<Object> value = Execution::ToString(object, &has_exception); | 498 Handle<Object> value = |
| 499 Execution::ToString(isolate_, object, &has_exception); |
| 499 if (has_exception) return EXCEPTION; | 500 if (has_exception) return EXCEPTION; |
| 500 SerializeString(Handle<String>::cast(value)); | 501 SerializeString(Handle<String>::cast(value)); |
| 501 } else if (class_name == isolate_->heap()->Number_string()) { | 502 } else if (class_name == isolate_->heap()->Number_string()) { |
| 502 Handle<Object> value = Execution::ToNumber(object, &has_exception); | 503 Handle<Object> value = |
| 504 Execution::ToNumber(isolate_, object, &has_exception); |
| 503 if (has_exception) return EXCEPTION; | 505 if (has_exception) return EXCEPTION; |
| 504 if (value->IsSmi()) return SerializeSmi(Smi::cast(*value)); | 506 if (value->IsSmi()) return SerializeSmi(Smi::cast(*value)); |
| 505 SerializeHeapNumber(Handle<HeapNumber>::cast(value)); | 507 SerializeHeapNumber(Handle<HeapNumber>::cast(value)); |
| 506 } else { | 508 } else { |
| 507 ASSERT(class_name == isolate_->heap()->Boolean_string()); | 509 ASSERT(class_name == isolate_->heap()->Boolean_string()); |
| 508 Object* value = JSValue::cast(*object)->value(); | 510 Object* value = JSValue::cast(*object)->value(); |
| 509 ASSERT(value->IsBoolean()); | 511 ASSERT(value->IsBoolean()); |
| 510 AppendAscii(value->IsTrue() ? "true" : "false"); | 512 AppendAscii(value->IsTrue() ? "true" : "false"); |
| 511 } | 513 } |
| 512 return SUCCESS; | 514 return SUCCESS; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 StackPop(); | 595 StackPop(); |
| 594 current_part_ = handle_scope.CloseAndEscape(current_part_); | 596 current_part_ = handle_scope.CloseAndEscape(current_part_); |
| 595 return SUCCESS; | 597 return SUCCESS; |
| 596 } | 598 } |
| 597 | 599 |
| 598 | 600 |
| 599 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSArraySlow( | 601 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSArraySlow( |
| 600 Handle<JSArray> object, int length) { | 602 Handle<JSArray> object, int length) { |
| 601 for (int i = 0; i < length; i++) { | 603 for (int i = 0; i < length; i++) { |
| 602 if (i > 0) Append(','); | 604 if (i > 0) Append(','); |
| 603 Handle<Object> element = Object::GetElement(object, i); | 605 Handle<Object> element = Object::GetElement(isolate_, object, i); |
| 604 RETURN_IF_EMPTY_HANDLE_VALUE(isolate_, element, EXCEPTION); | 606 RETURN_IF_EMPTY_HANDLE_VALUE(isolate_, element, EXCEPTION); |
| 605 if (element->IsUndefined()) { | 607 if (element->IsUndefined()) { |
| 606 AppendAscii("null"); | 608 AppendAscii("null"); |
| 607 } else { | 609 } else { |
| 608 Result result = SerializeElement(object->GetIsolate(), element, i); | 610 Result result = SerializeElement(isolate_, element, i); |
| 609 if (result == SUCCESS) continue; | 611 if (result == SUCCESS) continue; |
| 610 if (result == UNCHANGED) { | 612 if (result == UNCHANGED) { |
| 611 AppendAscii("null"); | 613 AppendAscii("null"); |
| 612 } else { | 614 } else { |
| 613 return result; | 615 return result; |
| 614 } | 616 } |
| 615 } | 617 } |
| 616 } | 618 } |
| 617 return SUCCESS; | 619 return SUCCESS; |
| 618 } | 620 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 Handle<String> key_handle; | 671 Handle<String> key_handle; |
| 670 Handle<Object> property; | 672 Handle<Object> property; |
| 671 if (key->IsString()) { | 673 if (key->IsString()) { |
| 672 key_handle = Handle<String>(String::cast(key), isolate_); | 674 key_handle = Handle<String>(String::cast(key), isolate_); |
| 673 property = GetProperty(isolate_, object, key_handle); | 675 property = GetProperty(isolate_, object, key_handle); |
| 674 } else { | 676 } else { |
| 675 ASSERT(key->IsNumber()); | 677 ASSERT(key->IsNumber()); |
| 676 key_handle = factory_->NumberToString(Handle<Object>(key, isolate_)); | 678 key_handle = factory_->NumberToString(Handle<Object>(key, isolate_)); |
| 677 uint32_t index; | 679 uint32_t index; |
| 678 if (key->IsSmi()) { | 680 if (key->IsSmi()) { |
| 679 property = Object::GetElement(object, Smi::cast(key)->value()); | 681 property = Object::GetElement( |
| 682 isolate_, object, Smi::cast(key)->value()); |
| 680 } else if (key_handle->AsArrayIndex(&index)) { | 683 } else if (key_handle->AsArrayIndex(&index)) { |
| 681 property = Object::GetElement(object, index); | 684 property = Object::GetElement(isolate_, object, index); |
| 682 } else { | 685 } else { |
| 683 property = GetProperty(isolate_, object, key_handle); | 686 property = GetProperty(isolate_, object, key_handle); |
| 684 } | 687 } |
| 685 } | 688 } |
| 686 if (property.is_null()) return EXCEPTION; | 689 if (property.is_null()) return EXCEPTION; |
| 687 Result result = SerializeProperty(property, comma, key_handle); | 690 Result result = SerializeProperty(property, comma, key_handle); |
| 688 if (!comma && result == SUCCESS) comma = true; | 691 if (!comma && result == SUCCESS) comma = true; |
| 689 if (result >= EXCEPTION) return result; | 692 if (result >= EXCEPTION) return result; |
| 690 } | 693 } |
| 691 } | 694 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 SerializeString_<false, uint8_t>(object); | 846 SerializeString_<false, uint8_t>(object); |
| 844 } else { | 847 } else { |
| 845 SerializeString_<false, uc16>(object); | 848 SerializeString_<false, uc16>(object); |
| 846 } | 849 } |
| 847 } | 850 } |
| 848 } | 851 } |
| 849 | 852 |
| 850 } } // namespace v8::internal | 853 } } // namespace v8::internal |
| 851 | 854 |
| 852 #endif // V8_JSON_STRINGIFIER_H_ | 855 #endif // V8_JSON_STRINGIFIER_H_ |
| OLD | NEW |