Commit 8077ec87 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[json] Simplify JSValue serialization

Bug: v8:7067
Change-Id: Ie9c0a84492965d08f67c910c489e59cbc50a5918
Reviewed-on: https://chromium-review.googlesource.com/778819Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49502}
parent c71fd20c
......@@ -353,26 +353,24 @@ JsonStringifier::Result JsonStringifier::Serialize_(Handle<Object> object,
JsonStringifier::Result JsonStringifier::SerializeJSValue(
Handle<JSValue> object) {
String* class_name = object->class_name();
if (class_name == isolate_->heap()->String_string()) {
Object* raw = object->value();
if (raw->IsString()) {
Handle<Object> value;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate_, value, Object::ToString(isolate_, object), EXCEPTION);
SerializeString(Handle<String>::cast(value));
} else if (class_name == isolate_->heap()->Number_string()) {
} else if (raw->IsNumber()) {
Handle<Object> value;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate_, value, Object::ToNumber(object),
EXCEPTION);
if (value->IsSmi()) return SerializeSmi(Smi::cast(*value));
SerializeHeapNumber(Handle<HeapNumber>::cast(value));
} else if (class_name == isolate_->heap()->BigInt_string()) {
} else if (raw->IsBigInt()) {
isolate_->Throw(
*factory()->NewTypeError(MessageTemplate::kBigIntSerializeJSON));
return EXCEPTION;
} else if (class_name == isolate_->heap()->Boolean_string()) {
Object* value = JSValue::cast(*object)->value();
DCHECK(value->IsBoolean());
builder_.AppendCString(value->IsTrue(isolate_) ? "true" : "false");
} else if (raw->IsBoolean()) {
builder_.AppendCString(raw->IsTrue(isolate_) ? "true" : "false");
} else {
// ES6 24.3.2.1 step 10.c, serialize as an ordinary JSObject.
return SerializeJSObject(object);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment