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

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

Issue 223573002: Return MaybeHandle from NewRaw???String. (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/json-parser.h ('k') | src/runtime.cc » ('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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 258
259 BasicJsonStringifier::BasicJsonStringifier(Isolate* isolate) 259 BasicJsonStringifier::BasicJsonStringifier(Isolate* isolate)
260 : isolate_(isolate), 260 : isolate_(isolate),
261 current_index_(0), 261 current_index_(0),
262 is_ascii_(true), 262 is_ascii_(true),
263 overflowed_(false) { 263 overflowed_(false) {
264 factory_ = isolate_->factory(); 264 factory_ = isolate_->factory();
265 accumulator_store_ = Handle<JSValue>::cast( 265 accumulator_store_ = Handle<JSValue>::cast(
266 factory_->ToObject(factory_->empty_string())); 266 factory_->ToObject(factory_->empty_string()));
267 part_length_ = kInitialPartLength; 267 part_length_ = kInitialPartLength;
268 current_part_ = factory_->NewRawOneByteString(part_length_); 268 current_part_ = factory_->NewRawOneByteString(part_length_).ToHandleChecked();
269 ASSERT(!current_part_.is_null());
270 tojson_string_ = factory_->toJSON_string(); 269 tojson_string_ = factory_->toJSON_string();
271 stack_ = factory_->NewJSArray(8); 270 stack_ = factory_->NewJSArray(8);
272 } 271 }
273 272
274 273
275 MaybeObject* BasicJsonStringifier::Stringify(Handle<Object> object) { 274 MaybeObject* BasicJsonStringifier::Stringify(Handle<Object> object) {
276 switch (SerializeObject(object)) { 275 switch (SerializeObject(object)) {
277 case UNCHANGED: 276 case UNCHANGED:
278 return isolate_->heap()->undefined_value(); 277 return isolate_->heap()->undefined_value();
279 case SUCCESS: { 278 case SUCCESS: {
(...skipping 21 matching lines...) Expand all
301 object->length() * kJsonQuoteWorstCaseBlowup + kSpaceForQuotes; 300 object->length() * kJsonQuoteWorstCaseBlowup + kSpaceForQuotes;
302 301
303 if (worst_case_length > 32 * KB) { // Slow path if too large. 302 if (worst_case_length > 32 * KB) { // Slow path if too large.
304 BasicJsonStringifier stringifier(isolate); 303 BasicJsonStringifier stringifier(isolate);
305 return stringifier.Stringify(object); 304 return stringifier.Stringify(object);
306 } 305 }
307 306
308 FlattenString(object); 307 FlattenString(object);
309 ASSERT(object->IsFlat()); 308 ASSERT(object->IsFlat());
310 if (object->IsOneByteRepresentationUnderneath()) { 309 if (object->IsOneByteRepresentationUnderneath()) {
311 Handle<String> result = 310 Handle<String> result = isolate->factory()->NewRawOneByteString(
312 isolate->factory()->NewRawOneByteString(worst_case_length); 311 worst_case_length).ToHandleChecked();
313 ASSERT(!result.is_null());
314 DisallowHeapAllocation no_gc; 312 DisallowHeapAllocation no_gc;
315 return StringifyString_<SeqOneByteString>( 313 return StringifyString_<SeqOneByteString>(
316 isolate, 314 isolate,
317 object->GetFlatContent().ToOneByteVector(), 315 object->GetFlatContent().ToOneByteVector(),
318 result); 316 result);
319 } else { 317 } else {
320 Handle<String> result = 318 Handle<String> result = isolate->factory()->NewRawTwoByteString(
321 isolate->factory()->NewRawTwoByteString(worst_case_length); 319 worst_case_length).ToHandleChecked();
322 ASSERT(!result.is_null());
323 DisallowHeapAllocation no_gc; 320 DisallowHeapAllocation no_gc;
324 return StringifyString_<SeqTwoByteString>( 321 return StringifyString_<SeqTwoByteString>(
325 isolate, 322 isolate,
326 object->GetFlatContent().ToUC16Vector(), 323 object->GetFlatContent().ToUC16Vector(),
327 result); 324 result);
328 } 325 }
329 } 326 }
330 327
331 328
332 template <typename ResultType, typename Char> 329 template <typename ResultType, typename Char>
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 } 732 }
736 } 733 }
737 734
738 735
739 void BasicJsonStringifier::Extend() { 736 void BasicJsonStringifier::Extend() {
740 Accumulate(); 737 Accumulate();
741 if (part_length_ <= kMaxPartLength / kPartLengthGrowthFactor) { 738 if (part_length_ <= kMaxPartLength / kPartLengthGrowthFactor) {
742 part_length_ *= kPartLengthGrowthFactor; 739 part_length_ *= kPartLengthGrowthFactor;
743 } 740 }
744 if (is_ascii_) { 741 if (is_ascii_) {
745 current_part_ = factory_->NewRawOneByteString(part_length_); 742 current_part_ =
743 factory_->NewRawOneByteString(part_length_).ToHandleChecked();
746 } else { 744 } else {
747 current_part_ = factory_->NewRawTwoByteString(part_length_); 745 current_part_ =
746 factory_->NewRawTwoByteString(part_length_).ToHandleChecked();
748 } 747 }
749 ASSERT(!current_part_.is_null()); 748 ASSERT(!current_part_.is_null());
750 current_index_ = 0; 749 current_index_ = 0;
751 } 750 }
752 751
753 752
754 void BasicJsonStringifier::ChangeEncoding() { 753 void BasicJsonStringifier::ChangeEncoding() {
755 ShrinkCurrentPart(); 754 ShrinkCurrentPart();
756 Accumulate(); 755 Accumulate();
757 current_part_ = factory_->NewRawTwoByteString(part_length_); 756 current_part_ =
757 factory_->NewRawTwoByteString(part_length_).ToHandleChecked();
758 ASSERT(!current_part_.is_null()); 758 ASSERT(!current_part_.is_null());
759 current_index_ = 0; 759 current_index_ = 0;
760 is_ascii_ = false; 760 is_ascii_ = false;
761 } 761 }
762 762
763 763
764 template <typename SrcChar, typename DestChar> 764 template <typename SrcChar, typename DestChar>
765 int BasicJsonStringifier::SerializeStringUnchecked_(const SrcChar* src, 765 int BasicJsonStringifier::SerializeStringUnchecked_(const SrcChar* src,
766 DestChar* dest, 766 DestChar* dest,
767 int length) { 767 int length) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 SerializeString_<false, uint8_t>(object); 877 SerializeString_<false, uint8_t>(object);
878 } else { 878 } else {
879 SerializeString_<false, uc16>(object); 879 SerializeString_<false, uc16>(object);
880 } 880 }
881 } 881 }
882 } 882 }
883 883
884 } } // namespace v8::internal 884 } } // namespace v8::internal
885 885
886 #endif // V8_JSON_STRINGIFIER_H_ 886 #endif // V8_JSON_STRINGIFIER_H_
OLDNEW
« no previous file with comments | « src/json-parser.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698