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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } | 251 } |
252 | 252 |
253 | 253 |
254 MaybeHandle<Object> BasicJsonStringifier::Stringify(Handle<Object> object) { | 254 MaybeHandle<Object> BasicJsonStringifier::Stringify(Handle<Object> object) { |
255 Result result = SerializeObject(object); | 255 Result result = SerializeObject(object); |
256 if (result == UNCHANGED) return isolate_->factory()->undefined_value(); | 256 if (result == UNCHANGED) return isolate_->factory()->undefined_value(); |
257 if (result == SUCCESS) { | 257 if (result == SUCCESS) { |
258 ShrinkCurrentPart(); | 258 ShrinkCurrentPart(); |
259 Accumulate(); | 259 Accumulate(); |
260 if (overflowed_) { | 260 if (overflowed_) { |
261 return isolate_->Throw<Object>( | 261 THROW_NEW_ERROR(isolate_, NewInvalidStringLengthError(), Object); |
262 isolate_->factory()->NewInvalidStringLengthError()); | |
263 } | 262 } |
264 return accumulator(); | 263 return accumulator(); |
265 } | 264 } |
266 DCHECK(result == EXCEPTION); | 265 DCHECK(result == EXCEPTION); |
267 return MaybeHandle<Object>(); | 266 return MaybeHandle<Object>(); |
268 } | 267 } |
269 | 268 |
270 | 269 |
271 MaybeHandle<Object> BasicJsonStringifier::StringifyString( | 270 MaybeHandle<Object> BasicJsonStringifier::StringifyString( |
272 Isolate* isolate, Handle<String> object) { | 271 Isolate* isolate, Handle<String> object) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 return EXCEPTION; | 364 return EXCEPTION; |
366 } | 365 } |
367 | 366 |
368 int length = Smi::cast(stack_->length())->value(); | 367 int length = Smi::cast(stack_->length())->value(); |
369 { | 368 { |
370 DisallowHeapAllocation no_allocation; | 369 DisallowHeapAllocation no_allocation; |
371 FixedArray* elements = FixedArray::cast(stack_->elements()); | 370 FixedArray* elements = FixedArray::cast(stack_->elements()); |
372 for (int i = 0; i < length; i++) { | 371 for (int i = 0; i < length; i++) { |
373 if (elements->get(i) == *object) { | 372 if (elements->get(i) == *object) { |
374 AllowHeapAllocation allow_to_return_error; | 373 AllowHeapAllocation allow_to_return_error; |
375 isolate_->Throw(*factory_->NewTypeError( | 374 Handle<Object> error; |
376 "circular_structure", HandleVector<Object>(NULL, 0))); | 375 MaybeHandle<Object> maybe_error = factory_->NewTypeError( |
| 376 "circular_structure", HandleVector<Object>(NULL, 0)); |
| 377 if (maybe_error.ToHandle(&error)) isolate_->Throw(*error); |
377 return EXCEPTION; | 378 return EXCEPTION; |
378 } | 379 } |
379 } | 380 } |
380 } | 381 } |
381 JSArray::EnsureSize(stack_, length + 1); | 382 JSArray::EnsureSize(stack_, length + 1); |
382 FixedArray::cast(stack_->elements())->set(length, *object); | 383 FixedArray::cast(stack_->elements())->set(length, *object); |
383 stack_->set_length(Smi::FromInt(length + 1)); | 384 stack_->set_length(Smi::FromInt(length + 1)); |
384 return SUCCESS; | 385 return SUCCESS; |
385 } | 386 } |
386 | 387 |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 SerializeString_<false, uint8_t>(object); | 870 SerializeString_<false, uint8_t>(object); |
870 } else { | 871 } else { |
871 SerializeString_<false, uc16>(object); | 872 SerializeString_<false, uc16>(object); |
872 } | 873 } |
873 } | 874 } |
874 } | 875 } |
875 | 876 |
876 } } // namespace v8::internal | 877 } } // namespace v8::internal |
877 | 878 |
878 #endif // V8_JSON_STRINGIFIER_H_ | 879 #endif // V8_JSON_STRINGIFIER_H_ |
OLD | NEW |