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

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

Issue 2059173002: Reland of place all remaining Oddball checks with new function (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « src/json-parser.cc ('k') | src/log.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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 #include "src/json-stringifier.h" 5 #include "src/json-stringifier.h"
6 6
7 #include "src/conversions.h" 7 #include "src/conversions.h"
8 #include "src/lookup.h" 8 #include "src/lookup.h"
9 #include "src/messages.h" 9 #include "src/messages.h"
10 #include "src/objects-inl.h" 10 #include "src/objects-inl.h"
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 int length = Smi::cast(stack_->length())->value(); 267 int length = Smi::cast(stack_->length())->value();
268 stack_->set_length(Smi::FromInt(length - 1)); 268 stack_->set_length(Smi::FromInt(length - 1));
269 } 269 }
270 270
271 template <bool deferred_string_key> 271 template <bool deferred_string_key>
272 JsonStringifier::Result JsonStringifier::Serialize_(Handle<Object> object, 272 JsonStringifier::Result JsonStringifier::Serialize_(Handle<Object> object,
273 bool comma, 273 bool comma,
274 Handle<Object> key) { 274 Handle<Object> key) {
275 StackLimitCheck interrupt_check(isolate_); 275 StackLimitCheck interrupt_check(isolate_);
276 if (interrupt_check.InterruptRequested() && 276 if (interrupt_check.InterruptRequested() &&
277 isolate_->stack_guard()->HandleInterrupts()->IsException()) { 277 isolate_->stack_guard()->HandleInterrupts()->IsException(isolate_)) {
278 return EXCEPTION; 278 return EXCEPTION;
279 } 279 }
280 if (object->IsJSReceiver()) { 280 if (object->IsJSReceiver()) {
281 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 281 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
282 isolate_, object, ApplyToJsonFunction(object, key), EXCEPTION); 282 isolate_, object, ApplyToJsonFunction(object, key), EXCEPTION);
283 } 283 }
284 if (!replacer_function_.is_null()) { 284 if (!replacer_function_.is_null()) {
285 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 285 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
286 isolate_, object, ApplyReplacerFunction(object, key), EXCEPTION); 286 isolate_, object, ApplyReplacerFunction(object, key), EXCEPTION);
287 } 287 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 SerializeString(Handle<String>::cast(value)); 353 SerializeString(Handle<String>::cast(value));
354 } else if (class_name == isolate_->heap()->Number_string()) { 354 } else if (class_name == isolate_->heap()->Number_string()) {
355 Handle<Object> value; 355 Handle<Object> value;
356 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate_, value, Object::ToNumber(object), 356 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate_, value, Object::ToNumber(object),
357 EXCEPTION); 357 EXCEPTION);
358 if (value->IsSmi()) return SerializeSmi(Smi::cast(*value)); 358 if (value->IsSmi()) return SerializeSmi(Smi::cast(*value));
359 SerializeHeapNumber(Handle<HeapNumber>::cast(value)); 359 SerializeHeapNumber(Handle<HeapNumber>::cast(value));
360 } else if (class_name == isolate_->heap()->Boolean_string()) { 360 } else if (class_name == isolate_->heap()->Boolean_string()) {
361 Object* value = JSValue::cast(*object)->value(); 361 Object* value = JSValue::cast(*object)->value();
362 DCHECK(value->IsBoolean()); 362 DCHECK(value->IsBoolean());
363 builder_.AppendCString(value->IsTrue() ? "true" : "false"); 363 builder_.AppendCString(value->IsTrue(isolate_) ? "true" : "false");
364 } else { 364 } else {
365 // ES6 24.3.2.1 step 10.c, serialize as an ordinary JSObject. 365 // ES6 24.3.2.1 step 10.c, serialize as an ordinary JSObject.
366 return SerializeJSObject(object); 366 return SerializeJSObject(object);
367 } 367 }
368 return SUCCESS; 368 return SUCCESS;
369 } 369 }
370 370
371 JsonStringifier::Result JsonStringifier::SerializeSmi(Smi* object) { 371 JsonStringifier::Result JsonStringifier::SerializeSmi(Smi* object) {
372 static const int kBufferSize = 100; 372 static const int kBufferSize = 100;
373 char chars[kBufferSize]; 373 char chars[kBufferSize];
(...skipping 26 matching lines...) Expand all
400 Indent(); 400 Indent();
401 uint32_t i = 0; 401 uint32_t i = 0;
402 if (replacer_function_.is_null()) { 402 if (replacer_function_.is_null()) {
403 switch (object->GetElementsKind()) { 403 switch (object->GetElementsKind()) {
404 case FAST_SMI_ELEMENTS: { 404 case FAST_SMI_ELEMENTS: {
405 Handle<FixedArray> elements(FixedArray::cast(object->elements()), 405 Handle<FixedArray> elements(FixedArray::cast(object->elements()),
406 isolate_); 406 isolate_);
407 StackLimitCheck interrupt_check(isolate_); 407 StackLimitCheck interrupt_check(isolate_);
408 while (i < length) { 408 while (i < length) {
409 if (interrupt_check.InterruptRequested() && 409 if (interrupt_check.InterruptRequested() &&
410 isolate_->stack_guard()->HandleInterrupts()->IsException()) { 410 isolate_->stack_guard()->HandleInterrupts()->IsException(
411 isolate_)) {
411 return EXCEPTION; 412 return EXCEPTION;
412 } 413 }
413 Separator(i == 0); 414 Separator(i == 0);
414 SerializeSmi(Smi::cast(elements->get(i))); 415 SerializeSmi(Smi::cast(elements->get(i)));
415 i++; 416 i++;
416 } 417 }
417 break; 418 break;
418 } 419 }
419 case FAST_DOUBLE_ELEMENTS: { 420 case FAST_DOUBLE_ELEMENTS: {
420 // Empty array is FixedArray but not FixedDoubleArray. 421 // Empty array is FixedArray but not FixedDoubleArray.
421 if (length == 0) break; 422 if (length == 0) break;
422 Handle<FixedDoubleArray> elements( 423 Handle<FixedDoubleArray> elements(
423 FixedDoubleArray::cast(object->elements()), isolate_); 424 FixedDoubleArray::cast(object->elements()), isolate_);
424 StackLimitCheck interrupt_check(isolate_); 425 StackLimitCheck interrupt_check(isolate_);
425 while (i < length) { 426 while (i < length) {
426 if (interrupt_check.InterruptRequested() && 427 if (interrupt_check.InterruptRequested() &&
427 isolate_->stack_guard()->HandleInterrupts()->IsException()) { 428 isolate_->stack_guard()->HandleInterrupts()->IsException(
429 isolate_)) {
428 return EXCEPTION; 430 return EXCEPTION;
429 } 431 }
430 Separator(i == 0); 432 Separator(i == 0);
431 SerializeDouble(elements->get_scalar(i)); 433 SerializeDouble(elements->get_scalar(i));
432 i++; 434 i++;
433 } 435 }
434 break; 436 break;
435 } 437 }
436 case FAST_ELEMENTS: { 438 case FAST_ELEMENTS: {
437 Handle<Object> old_length(object->length(), isolate_); 439 Handle<Object> old_length(object->length(), isolate_);
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 if (object->IsOneByteRepresentationUnderneath()) { 701 if (object->IsOneByteRepresentationUnderneath()) {
700 SerializeString_<uint8_t, uc16>(object); 702 SerializeString_<uint8_t, uc16>(object);
701 } else { 703 } else {
702 SerializeString_<uc16, uc16>(object); 704 SerializeString_<uc16, uc16>(object);
703 } 705 }
704 } 706 }
705 } 707 }
706 708
707 } // namespace internal 709 } // namespace internal
708 } // namespace v8 710 } // namespace v8
OLDNEW
« no previous file with comments | « src/json-parser.cc ('k') | src/log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698