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

Unified Diff: test/cctest/test-api.cc

Issue 1891203002: Expose JSON stringifier through V8 API (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
« src/api.cc ('K') | « src/runtime/runtime-object.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 6bea3eaefee603ed7bc02a56be251082ba6ad27a..63932b0919de5d2e13224df4af3ab1a1fbd0f811 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -21947,6 +21947,15 @@ THREADED_TEST(Regress260106) {
CHECK(function->IsFunction());
}
+THREADED_TEST(JSONParseObjectWithContext) {
+ LocalContext context;
+ HandleScope scope(context->GetIsolate());
+ Local<Value> obj =
+ v8::JSON::Parse(context.local(), v8_str("{\"x\":42}")).ToLocalChecked();
+ Local<Object> global = context->Global();
+ global->Set(context.local(), v8_str("obj"), obj).FromJust();
+ ExpectString("JSON.stringify(obj)", "{\"x\":42}");
+}
THREADED_TEST(JSONParseObject) {
LocalContext context;
@@ -21970,6 +21979,20 @@ THREADED_TEST(JSONParseNumber) {
ExpectString("JSON.stringify(obj)", "42");
}
+THREADED_TEST(JSONStringifyObject) {
+ LocalContext context;
+ HandleScope scope(context->GetIsolate());
+ Local<Value> value =
+ v8::JSON::Parse(context->GetIsolate(), v8_str("{\"x\":42}"))
+ .ToLocalChecked();
+ Local<Object> obj = value->ToObject(context.local()).ToLocalChecked();
+ Local<Object> global = context->Global();
+ global->Set(context.local(), v8_str("obj"), obj).FromJust();
+ Local<String> json =
+ v8::JSON::Stringify(context->GetIsolate(), obj).ToLocalChecked();
+ v8::String::Utf8Value utf8(json);
+ ExpectString("JSON.stringify(obj)", *utf8);
+}
#if V8_OS_POSIX && !V8_OS_NACL
class ThreadInterruptTest {
« src/api.cc ('K') | « src/runtime/runtime-object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698