| OLD | NEW |
| 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/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 Handle<Object> value; | 389 Handle<Object> value; |
| 390 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 390 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 391 isolate_, value, Execution::ToString(isolate_, object), EXCEPTION); | 391 isolate_, value, Execution::ToString(isolate_, object), EXCEPTION); |
| 392 SerializeString(Handle<String>::cast(value)); | 392 SerializeString(Handle<String>::cast(value)); |
| 393 } else if (class_name == isolate_->heap()->Number_string()) { | 393 } else if (class_name == isolate_->heap()->Number_string()) { |
| 394 Handle<Object> value; | 394 Handle<Object> value; |
| 395 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 395 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 396 isolate_, value, Execution::ToNumber(isolate_, object), EXCEPTION); | 396 isolate_, value, Execution::ToNumber(isolate_, object), EXCEPTION); |
| 397 if (value->IsSmi()) return SerializeSmi(Smi::cast(*value)); | 397 if (value->IsSmi()) return SerializeSmi(Smi::cast(*value)); |
| 398 SerializeHeapNumber(Handle<HeapNumber>::cast(value)); | 398 SerializeHeapNumber(Handle<HeapNumber>::cast(value)); |
| 399 } else { | 399 } else if (class_name == isolate_->heap()->Boolean_string()) { |
| 400 DCHECK(class_name == isolate_->heap()->Boolean_string()); | |
| 401 Object* value = JSValue::cast(*object)->value(); | 400 Object* value = JSValue::cast(*object)->value(); |
| 402 DCHECK(value->IsBoolean()); | 401 DCHECK(value->IsBoolean()); |
| 403 builder_.AppendCString(value->IsTrue() ? "true" : "false"); | 402 builder_.AppendCString(value->IsTrue() ? "true" : "false"); |
| 403 } else { |
| 404 // Fail gracefully for special value wrappers. |
| 405 isolate_->ThrowIllegalOperation(); |
| 406 return EXCEPTION; |
| 404 } | 407 } |
| 405 return SUCCESS; | 408 return SUCCESS; |
| 406 } | 409 } |
| 407 | 410 |
| 408 | 411 |
| 409 BasicJsonStringifier::Result BasicJsonStringifier::SerializeSmi(Smi* object) { | 412 BasicJsonStringifier::Result BasicJsonStringifier::SerializeSmi(Smi* object) { |
| 410 static const int kBufferSize = 100; | 413 static const int kBufferSize = 100; |
| 411 char chars[kBufferSize]; | 414 char chars[kBufferSize]; |
| 412 Vector<char> buffer(chars, kBufferSize); | 415 Vector<char> buffer(chars, kBufferSize); |
| 413 builder_.AppendCString(IntToCString(object->value(), buffer)); | 416 builder_.AppendCString(IntToCString(object->value(), buffer)); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 SerializeString_<uint8_t, uc16>(object); | 680 SerializeString_<uint8_t, uc16>(object); |
| 678 } else { | 681 } else { |
| 679 SerializeString_<uc16, uc16>(object); | 682 SerializeString_<uc16, uc16>(object); |
| 680 } | 683 } |
| 681 } | 684 } |
| 682 } | 685 } |
| 683 | 686 |
| 684 } } // namespace v8::internal | 687 } } // namespace v8::internal |
| 685 | 688 |
| 686 #endif // V8_JSON_STRINGIFIER_H_ | 689 #endif // V8_JSON_STRINGIFIER_H_ |
| OLD | NEW |