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 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 Handle<Object> fun; | 371 Handle<Object> fun; |
372 ASSIGN_RETURN_ON_EXCEPTION( | 372 ASSIGN_RETURN_ON_EXCEPTION( |
373 isolate_, fun, | 373 isolate_, fun, |
374 Object::GetProperty(object, object, &lookup, tojson_string_, &attr), | 374 Object::GetProperty(object, object, &lookup, tojson_string_, &attr), |
375 Object); | 375 Object); |
376 if (!fun->IsJSFunction()) return object; | 376 if (!fun->IsJSFunction()) return object; |
377 | 377 |
378 // Call toJSON function. | 378 // Call toJSON function. |
379 if (key->IsSmi()) key = factory_->NumberToString(key); | 379 if (key->IsSmi()) key = factory_->NumberToString(key); |
380 Handle<Object> argv[] = { key }; | 380 Handle<Object> argv[] = { key }; |
381 bool has_exception = false; | |
382 HandleScope scope(isolate_); | 381 HandleScope scope(isolate_); |
383 object = Execution::Call(isolate_, fun, object, 1, argv, &has_exception); | 382 ASSIGN_RETURN_ON_EXCEPTION( |
384 // Return empty handle to signal an exception. | 383 isolate_, object, |
385 if (has_exception) return MaybeHandle<Object>(); | 384 Execution::Call(isolate_, fun, object, 1, argv), |
| 385 Object); |
386 return scope.CloseAndEscape(object); | 386 return scope.CloseAndEscape(object); |
387 } | 387 } |
388 | 388 |
389 | 389 |
390 BasicJsonStringifier::Result BasicJsonStringifier::StackPush( | 390 BasicJsonStringifier::Result BasicJsonStringifier::StackPush( |
391 Handle<Object> object) { | 391 Handle<Object> object) { |
392 StackLimitCheck check(isolate_); | 392 StackLimitCheck check(isolate_); |
393 if (check.HasOverflowed()) return STACK_OVERFLOW; | 393 if (check.HasOverflowed()) return STACK_OVERFLOW; |
394 | 394 |
395 int length = Smi::cast(stack_->length())->value(); | 395 int length = Smi::cast(stack_->length())->value(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 BasicJsonStringifier::Result BasicJsonStringifier::SerializeGeneric( | 479 BasicJsonStringifier::Result BasicJsonStringifier::SerializeGeneric( |
480 Handle<Object> object, | 480 Handle<Object> object, |
481 Handle<Object> key, | 481 Handle<Object> key, |
482 bool deferred_comma, | 482 bool deferred_comma, |
483 bool deferred_key) { | 483 bool deferred_key) { |
484 Handle<JSObject> builtins(isolate_->native_context()->builtins()); | 484 Handle<JSObject> builtins(isolate_->native_context()->builtins()); |
485 Handle<JSFunction> builtin = Handle<JSFunction>::cast( | 485 Handle<JSFunction> builtin = Handle<JSFunction>::cast( |
486 GetProperty(builtins, "JSONSerializeAdapter").ToHandleChecked()); | 486 GetProperty(builtins, "JSONSerializeAdapter").ToHandleChecked()); |
487 | 487 |
488 Handle<Object> argv[] = { key, object }; | 488 Handle<Object> argv[] = { key, object }; |
489 bool has_exception = false; | 489 Handle<Object> result; |
490 Handle<Object> result = | 490 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
491 Execution::Call(isolate_, builtin, object, 2, argv, &has_exception); | 491 isolate_, result, |
492 if (has_exception) return EXCEPTION; | 492 Execution::Call(isolate_, builtin, object, 2, argv), |
| 493 EXCEPTION); |
493 if (result->IsUndefined()) return UNCHANGED; | 494 if (result->IsUndefined()) return UNCHANGED; |
494 if (deferred_key) { | 495 if (deferred_key) { |
495 if (key->IsSmi()) key = factory_->NumberToString(key); | 496 if (key->IsSmi()) key = factory_->NumberToString(key); |
496 SerializeDeferredKey(deferred_comma, key); | 497 SerializeDeferredKey(deferred_comma, key); |
497 } | 498 } |
498 | 499 |
499 Handle<String> result_string = Handle<String>::cast(result); | 500 Handle<String> result_string = Handle<String>::cast(result); |
500 // Shrink current part, attach it to the accumulator, also attach the result | 501 // Shrink current part, attach it to the accumulator, also attach the result |
501 // string to the accumulator, and allocate a new part. | 502 // string to the accumulator, and allocate a new part. |
502 ShrinkCurrentPart(); // Shrink. | 503 ShrinkCurrentPart(); // Shrink. |
503 part_length_ = kInitialPartLength; // Allocate conservatively. | 504 part_length_ = kInitialPartLength; // Allocate conservatively. |
504 Extend(); // Attach current part and allocate new part. | 505 Extend(); // Attach current part and allocate new part. |
505 // Attach result string to the accumulator. | 506 // Attach result string to the accumulator. |
506 Handle<String> cons; | 507 Handle<String> cons; |
507 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 508 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
508 isolate_, cons, | 509 isolate_, cons, |
509 factory_->NewConsString(accumulator(), result_string), | 510 factory_->NewConsString(accumulator(), result_string), |
510 EXCEPTION); | 511 EXCEPTION); |
511 set_accumulator(cons); | 512 set_accumulator(cons); |
512 return SUCCESS; | 513 return SUCCESS; |
513 } | 514 } |
514 | 515 |
515 | 516 |
516 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSValue( | 517 BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSValue( |
517 Handle<JSValue> object) { | 518 Handle<JSValue> object) { |
518 bool has_exception = false; | |
519 String* class_name = object->class_name(); | 519 String* class_name = object->class_name(); |
520 if (class_name == isolate_->heap()->String_string()) { | 520 if (class_name == isolate_->heap()->String_string()) { |
521 Handle<Object> value = | 521 Handle<Object> value; |
522 Execution::ToString(isolate_, object, &has_exception); | 522 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
523 if (has_exception) return EXCEPTION; | 523 isolate_, value, Execution::ToString(isolate_, object), EXCEPTION); |
524 SerializeString(Handle<String>::cast(value)); | 524 SerializeString(Handle<String>::cast(value)); |
525 } else if (class_name == isolate_->heap()->Number_string()) { | 525 } else if (class_name == isolate_->heap()->Number_string()) { |
526 Handle<Object> value = | 526 Handle<Object> value; |
527 Execution::ToNumber(isolate_, object, &has_exception); | 527 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
528 if (has_exception) return EXCEPTION; | 528 isolate_, value, Execution::ToNumber(isolate_, object), EXCEPTION); |
529 if (value->IsSmi()) return SerializeSmi(Smi::cast(*value)); | 529 if (value->IsSmi()) return SerializeSmi(Smi::cast(*value)); |
530 SerializeHeapNumber(Handle<HeapNumber>::cast(value)); | 530 SerializeHeapNumber(Handle<HeapNumber>::cast(value)); |
531 } else { | 531 } else { |
532 ASSERT(class_name == isolate_->heap()->Boolean_string()); | 532 ASSERT(class_name == isolate_->heap()->Boolean_string()); |
533 Object* value = JSValue::cast(*object)->value(); | 533 Object* value = JSValue::cast(*object)->value(); |
534 ASSERT(value->IsBoolean()); | 534 ASSERT(value->IsBoolean()); |
535 AppendAscii(value->IsTrue() ? "true" : "false"); | 535 AppendAscii(value->IsTrue() ? "true" : "false"); |
536 } | 536 } |
537 return SUCCESS; | 537 return SUCCESS; |
538 } | 538 } |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 SerializeString_<false, uint8_t>(object); | 894 SerializeString_<false, uint8_t>(object); |
895 } else { | 895 } else { |
896 SerializeString_<false, uc16>(object); | 896 SerializeString_<false, uc16>(object); |
897 } | 897 } |
898 } | 898 } |
899 } | 899 } |
900 | 900 |
901 } } // namespace v8::internal | 901 } } // namespace v8::internal |
902 | 902 |
903 #endif // V8_JSON_STRINGIFIER_H_ | 903 #endif // V8_JSON_STRINGIFIER_H_ |
OLD | NEW |