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

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

Issue 225673003: Return MaybeHandle from GetProperty. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 months 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 | Annotate | Revision Log
« no previous file with comments | « src/ic.cc ('k') | src/objects.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 // 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 74 }
75 75
76 INLINE(void AppendAscii(const char* chars)) { 76 INLINE(void AppendAscii(const char* chars)) {
77 if (is_ascii_) { 77 if (is_ascii_) {
78 Append_<true>(reinterpret_cast<const uint8_t*>(chars)); 78 Append_<true>(reinterpret_cast<const uint8_t*>(chars));
79 } else { 79 } else {
80 Append_<false>(reinterpret_cast<const uint8_t*>(chars)); 80 Append_<false>(reinterpret_cast<const uint8_t*>(chars));
81 } 81 }
82 } 82 }
83 83
84 Handle<Object> ApplyToJsonFunction(Handle<Object> object, 84 MUST_USE_RESULT MaybeHandle<Object> ApplyToJsonFunction
85 Handle<Object> key); 85 Handle<Object> object,
86 Handle<Object> key);
86 87
87 Result SerializeGeneric(Handle<Object> object, 88 Result SerializeGeneric(Handle<Object> object,
88 Handle<Object> key, 89 Handle<Object> key,
89 bool deferred_comma, 90 bool deferred_comma,
90 bool deferred_key); 91 bool deferred_key);
91 92
92 template <typename ResultType, typename Char> 93 template <typename ResultType, typename Char>
93 INLINE(static MaybeObject* StringifyString_(Isolate* isolate, 94 INLINE(static MaybeObject* StringifyString_(Isolate* isolate,
94 Vector<Char> vector, 95 Vector<Char> vector,
95 Handle<String> result)); 96 Handle<String> result));
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 if (current_index_ == part_length_) Extend(); 355 if (current_index_ == part_length_) Extend();
355 } 356 }
356 357
357 358
358 template <bool is_ascii, typename Char> 359 template <bool is_ascii, typename Char>
359 void BasicJsonStringifier::Append_(const Char* chars) { 360 void BasicJsonStringifier::Append_(const Char* chars) {
360 for ( ; *chars != '\0'; chars++) Append_<is_ascii, Char>(*chars); 361 for ( ; *chars != '\0'; chars++) Append_<is_ascii, Char>(*chars);
361 } 362 }
362 363
363 364
364 Handle<Object> BasicJsonStringifier::ApplyToJsonFunction( 365 MaybeHandle<Object> BasicJsonStringifier::ApplyToJsonFunction(
365 Handle<Object> object, Handle<Object> key) { 366 Handle<Object> object, Handle<Object> key) {
366 LookupResult lookup(isolate_); 367 LookupResult lookup(isolate_);
367 JSObject::cast(*object)->LookupRealNamedProperty(*tojson_string_, &lookup); 368 JSObject::cast(*object)->LookupRealNamedProperty(*tojson_string_, &lookup);
368 if (!lookup.IsProperty()) return object; 369 if (!lookup.IsProperty()) return object;
369 PropertyAttributes attr; 370 PropertyAttributes attr;
370 Handle<Object> fun = 371 Handle<Object> fun;
371 Object::GetProperty(object, object, &lookup, tojson_string_, &attr); 372 ASSIGN_RETURN_ON_EXCEPTION(
372 if (fun.is_null()) return Handle<Object>::null(); 373 isolate_, fun,
374 Object::GetProperty(object, object, &lookup, tojson_string_, &attr),
375 Object);
373 if (!fun->IsJSFunction()) return object; 376 if (!fun->IsJSFunction()) return object;
374 377
375 // Call toJSON function. 378 // Call toJSON function.
376 if (key->IsSmi()) key = factory_->NumberToString(key); 379 if (key->IsSmi()) key = factory_->NumberToString(key);
377 Handle<Object> argv[] = { key }; 380 Handle<Object> argv[] = { key };
378 bool has_exception = false; 381 bool has_exception = false;
379 HandleScope scope(isolate_); 382 HandleScope scope(isolate_);
380 object = Execution::Call(isolate_, fun, object, 1, argv, &has_exception); 383 object = Execution::Call(isolate_, fun, object, 1, argv, &has_exception);
381 // Return empty handle to signal an exception. 384 // Return empty handle to signal an exception.
382 if (has_exception) return Handle<Object>::null(); 385 if (has_exception) return MaybeHandle<Object>();
383 return scope.CloseAndEscape(object); 386 return scope.CloseAndEscape(object);
384 } 387 }
385 388
386 389
387 BasicJsonStringifier::Result BasicJsonStringifier::StackPush( 390 BasicJsonStringifier::Result BasicJsonStringifier::StackPush(
388 Handle<Object> object) { 391 Handle<Object> object) {
389 StackLimitCheck check(isolate_); 392 StackLimitCheck check(isolate_);
390 if (check.HasOverflowed()) return STACK_OVERFLOW; 393 if (check.HasOverflowed()) return STACK_OVERFLOW;
391 394
392 int length = Smi::cast(stack_->length())->value(); 395 int length = Smi::cast(stack_->length())->value();
(...skipping 16 matching lines...) Expand all
409 void BasicJsonStringifier::StackPop() { 412 void BasicJsonStringifier::StackPop() {
410 int length = Smi::cast(stack_->length())->value(); 413 int length = Smi::cast(stack_->length())->value();
411 stack_->set_length(Smi::FromInt(length - 1)); 414 stack_->set_length(Smi::FromInt(length - 1));
412 } 415 }
413 416
414 417
415 template <bool deferred_string_key> 418 template <bool deferred_string_key>
416 BasicJsonStringifier::Result BasicJsonStringifier::Serialize_( 419 BasicJsonStringifier::Result BasicJsonStringifier::Serialize_(
417 Handle<Object> object, bool comma, Handle<Object> key) { 420 Handle<Object> object, bool comma, Handle<Object> key) {
418 if (object->IsJSObject()) { 421 if (object->IsJSObject()) {
419 object = ApplyToJsonFunction(object, key); 422 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
420 if (object.is_null()) return EXCEPTION; 423 isolate_, object,
424 ApplyToJsonFunction(object, key),
425 EXCEPTION);
421 } 426 }
422 427
423 if (object->IsSmi()) { 428 if (object->IsSmi()) {
424 if (deferred_string_key) SerializeDeferredKey(comma, key); 429 if (deferred_string_key) SerializeDeferredKey(comma, key);
425 return SerializeSmi(Smi::cast(*object)); 430 return SerializeSmi(Smi::cast(*object));
426 } 431 }
427 432
428 switch (HeapObject::cast(*object)->map()->instance_type()) { 433 switch (HeapObject::cast(*object)->map()->instance_type()) {
429 case HEAP_NUMBER_TYPE: 434 case HEAP_NUMBER_TYPE:
430 if (deferred_string_key) SerializeDeferredKey(comma, key); 435 if (deferred_string_key) SerializeDeferredKey(comma, key);
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 SerializeString_<false, uint8_t>(object); 886 SerializeString_<false, uint8_t>(object);
882 } else { 887 } else {
883 SerializeString_<false, uc16>(object); 888 SerializeString_<false, uc16>(object);
884 } 889 }
885 } 890 }
886 } 891 }
887 892
888 } } // namespace v8::internal 893 } } // namespace v8::internal
889 894
890 #endif // V8_JSON_STRINGIFIER_H_ 895 #endif // V8_JSON_STRINGIFIER_H_
OLDNEW
« no previous file with comments | « src/ic.cc ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698