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

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

Issue 2887653002: [json] Specialize parsed arrays to most specific kind (Closed)
Patch Set: Created 3 years, 7 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:
Download patch
« no previous file with comments | « src/json-parser.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 c3d45cc4b1c0b78c165ecbd1b0e69db1fa0ac577..d60130f54bac9d118286523edb3610ca82bc89ae 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -22646,6 +22646,43 @@ THREADED_TEST(JSONParseNumber) {
ExpectString("JSON.stringify(obj)", "42");
}
+namespace {
+void TestJSONParseArray(Local<Context> context, const char* input_str,
+ const char* expected_output_str,
+ i::ElementsKind expected_elements_kind) {
+ Local<Value> obj =
+ v8::JSON::Parse(context, v8_str(input_str)).ToLocalChecked();
+
+ i::Handle<i::JSArray> a =
+ i::Handle<i::JSArray>::cast(v8::Utils::OpenHandle(*obj));
+ CHECK_EQ(expected_elements_kind, a->GetElementsKind());
+
+ Local<Object> global = context->Global();
+ global->Set(context, v8_str("obj"), obj).FromJust();
+ ExpectString("JSON.stringify(obj)", expected_output_str);
+}
+} // namespace
+
+THREADED_TEST(JSONParseArray) {
+ LocalContext context;
+ HandleScope scope(context->GetIsolate());
+
+ TestJSONParseArray(context.local(), "[0, 1, 2]", "[0,1,2]",
+ i::FAST_SMI_ELEMENTS);
+ TestJSONParseArray(context.local(), "[0, 1.2, 2]", "[0,1.2,2]",
+ i::FAST_DOUBLE_ELEMENTS);
+ TestJSONParseArray(context.local(), "[0.2, 1, 2]", "[0.2,1,2]",
+ i::FAST_DOUBLE_ELEMENTS);
+ TestJSONParseArray(context.local(), "[0, \"a\", 2]", "[0,\"a\",2]",
+ i::FAST_ELEMENTS);
+ TestJSONParseArray(context.local(), "[\"a\", 1, 2]", "[\"a\",1,2]",
+ i::FAST_ELEMENTS);
+ TestJSONParseArray(context.local(), "[\"a\", 1.2, 2]", "[\"a\",1.2,2]",
+ i::FAST_ELEMENTS);
+ TestJSONParseArray(context.local(), "[0, 1.2, \"a\"]", "[0,1.2,\"a\"]",
+ i::FAST_ELEMENTS);
+}
+
THREADED_TEST(JSONStringifyObject) {
LocalContext context;
HandleScope scope(context->GetIsolate());
« no previous file with comments | « src/json-parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698