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

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

Issue 1495473002: [es6] correctly handle object wrappers in JSON.stringify. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase, add tests, address nit Created 5 years 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 | « no previous file | test/mjsunit/es6/symbols.js » ('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 // 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/conversions.h" 8 #include "src/conversions.h"
9 #include "src/lookup.h" 9 #include "src/lookup.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 Handle<Object> value; 390 Handle<Object> value;
391 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate_, value, Object::ToNumber(object), 391 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate_, value, Object::ToNumber(object),
392 EXCEPTION); 392 EXCEPTION);
393 if (value->IsSmi()) return SerializeSmi(Smi::cast(*value)); 393 if (value->IsSmi()) return SerializeSmi(Smi::cast(*value));
394 SerializeHeapNumber(Handle<HeapNumber>::cast(value)); 394 SerializeHeapNumber(Handle<HeapNumber>::cast(value));
395 } else if (class_name == isolate_->heap()->Boolean_string()) { 395 } else if (class_name == isolate_->heap()->Boolean_string()) {
396 Object* value = JSValue::cast(*object)->value(); 396 Object* value = JSValue::cast(*object)->value();
397 DCHECK(value->IsBoolean()); 397 DCHECK(value->IsBoolean());
398 builder_.AppendCString(value->IsTrue() ? "true" : "false"); 398 builder_.AppendCString(value->IsTrue() ? "true" : "false");
399 } else { 399 } else {
400 // Fail gracefully for special value wrappers. 400 // ES6 24.3.2.1 step 10.c, serialize as an ordinary JSObject.
401 isolate_->ThrowIllegalOperation(); 401 CHECK(!object->IsAccessCheckNeeded());
402 return EXCEPTION; 402 CHECK(!object->IsJSGlobalProxy());
403 return SerializeJSObject(object);
403 } 404 }
404 return SUCCESS; 405 return SUCCESS;
405 } 406 }
406 407
407 408
408 BasicJsonStringifier::Result BasicJsonStringifier::SerializeSmi(Smi* object) { 409 BasicJsonStringifier::Result BasicJsonStringifier::SerializeSmi(Smi* object) {
409 static const int kBufferSize = 100; 410 static const int kBufferSize = 100;
410 char chars[kBufferSize]; 411 char chars[kBufferSize];
411 Vector<char> buffer(chars, kBufferSize); 412 Vector<char> buffer(chars, kBufferSize);
412 builder_.AppendCString(IntToCString(object->value(), buffer)); 413 builder_.AppendCString(IntToCString(object->value(), buffer));
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 } else { 680 } else {
680 SerializeString_<uc16, uc16>(object); 681 SerializeString_<uc16, uc16>(object);
681 } 682 }
682 } 683 }
683 } 684 }
684 685
685 } // namespace internal 686 } // namespace internal
686 } // namespace v8 687 } // namespace v8
687 688
688 #endif // V8_JSON_STRINGIFIER_H_ 689 #endif // V8_JSON_STRINGIFIER_H_
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/es6/symbols.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698