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

Side by Side Diff: test/unittests/value-serializer-unittest.cc

Issue 2274173003: Implement Big-Endian eqv test for DecodeDate and DecodeValueObjects (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 3 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 | « no previous file | no next file » | 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/value-serializer.h" 5 #include "src/value-serializer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "include/v8.h" 10 #include "include/v8.h"
(...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 }); 1093 });
1094 RoundTripTest( 1094 RoundTripTest(
1095 "({ a: new Date(), get b() { return this.a; } })", 1095 "({ a: new Date(), get b() { return this.a; } })",
1096 [this](Local<Value> value) { 1096 [this](Local<Value> value) {
1097 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof Date")); 1097 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof Date"));
1098 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); 1098 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b"));
1099 }); 1099 });
1100 } 1100 }
1101 1101
1102 TEST_F(ValueSerializerTest, DecodeDate) { 1102 TEST_F(ValueSerializerTest, DecodeDate) {
1103 #if defined(V8_TARGET_LITTLE_ENDIAN)
1103 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x80, 0x84, 1104 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x80, 0x84,
1104 0x2e, 0x41, 0x00}, 1105 0x2e, 0x41, 0x00},
1105 [this](Local<Value> value) { 1106 [this](Local<Value> value) {
1106 ASSERT_TRUE(value->IsDate()); 1107 ASSERT_TRUE(value->IsDate());
1108 double val = Date::Cast(*value)->ValueOf();
1109 printf("val = %f\n", val);
jbroman 2016/08/24 20:22:24 please remove this printf (and the line before it)
john.yan 2016/08/24 22:32:44 Really sorry for this. The printf was intended to
jbroman 2016/08/24 23:38:14 No need to apologize; I sometimes forget to remove
1107 EXPECT_EQ(1e6, Date::Cast(*value)->ValueOf()); 1110 EXPECT_EQ(1e6, Date::Cast(*value)->ValueOf());
1108 EXPECT_TRUE("Object.getPrototypeOf(result) === Date.prototype"); 1111 EXPECT_TRUE("Object.getPrototypeOf(result) === Date.prototype");
1109 }); 1112 });
1110 DecodeTest( 1113 DecodeTest(
1111 {0xff, 0x09, 0x3f, 0x00, 0x44, 0x00, 0x00, 0x20, 0x45, 0x27, 0x89, 0x87, 1114 {0xff, 0x09, 0x3f, 0x00, 0x44, 0x00, 0x00, 0x20, 0x45, 0x27, 0x89, 0x87,
1112 0xc2, 0x00}, 1115 0xc2, 0x00},
1113 [this](Local<Value> value) { 1116 [this](Local<Value> value) {
1114 ASSERT_TRUE(value->IsDate()); 1117 ASSERT_TRUE(value->IsDate());
1115 EXPECT_TRUE("result.toISOString() === '1867-07-01T00:00:00.000Z'"); 1118 EXPECT_TRUE("result.toISOString() === '1867-07-01T00:00:00.000Z'");
1116 }); 1119 });
1117 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 1120 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1118 0xf8, 0x7f, 0x00}, 1121 0xf8, 0x7f, 0x00},
1119 [this](Local<Value> value) { 1122 [this](Local<Value> value) {
1120 ASSERT_TRUE(value->IsDate()); 1123 ASSERT_TRUE(value->IsDate());
1121 EXPECT_TRUE(std::isnan(Date::Cast(*value)->ValueOf())); 1124 EXPECT_TRUE(std::isnan(Date::Cast(*value)->ValueOf()));
1122 }); 1125 });
1126 #else
1127 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x44, 0x41, 0x2e, 0x84, 0x80, 0x00, 0x00,
1128 0x00, 0x00, 0x00},
1129 [this](Local<Value> value) {
1130 ASSERT_TRUE(value->IsDate());
1131 double val = Date::Cast(*value)->ValueOf();
1132 printf("val = %f\n", val);
1133 EXPECT_EQ(1e6, Date::Cast(*value)->ValueOf());
1134 EXPECT_TRUE("Object.getPrototypeOf(result) === Date.prototype");
1135 });
1136 DecodeTest(
1137 {0xff, 0x09, 0x3f, 0x00, 0x44, 0xc2, 0x87, 0x89, 0x27, 0x45, 0x20, 0x00,
1138 0x00, 0x00},
1139 [this](Local<Value> value) {
1140 ASSERT_TRUE(value->IsDate());
1141 EXPECT_TRUE("result.toISOString() === '1867-07-01T00:00:00.000Z'");
1142 });
1143 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x44, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00,
1144 0x00, 0x00, 0x00},
1145 [this](Local<Value> value) {
1146 ASSERT_TRUE(value->IsDate());
1147 EXPECT_TRUE(std::isnan(Date::Cast(*value)->ValueOf()));
1148 });
1149 #endif
1123 DecodeTest( 1150 DecodeTest(
1124 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, 0x61, 0x3f, 1151 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, 0x61, 0x3f,
1125 0x01, 0x44, 0x00, 0x20, 0x39, 0x50, 0x37, 0x6a, 0x75, 0x42, 0x3f, 1152 0x01, 0x44, 0x00, 0x20, 0x39, 0x50, 0x37, 0x6a, 0x75, 0x42, 0x3f,
1126 0x02, 0x53, 0x01, 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02}, 1153 0x02, 0x53, 0x01, 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02},
1127 [this](Local<Value> value) { 1154 [this](Local<Value> value) {
1128 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof Date")); 1155 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof Date"));
1129 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); 1156 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b"));
1130 }); 1157 });
1131 } 1158 }
1132 1159
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 "Object.getPrototypeOf(result) === Boolean.prototype")); 1232 "Object.getPrototypeOf(result) === Boolean.prototype"));
1206 EXPECT_TRUE(EvaluateScriptForResultBool("result.valueOf() === false")); 1233 EXPECT_TRUE(EvaluateScriptForResultBool("result.valueOf() === false"));
1207 }); 1234 });
1208 DecodeTest( 1235 DecodeTest(
1209 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, 0x61, 0x3f, 0x01, 1236 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, 0x61, 0x3f, 0x01,
1210 0x79, 0x3f, 0x02, 0x53, 0x01, 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02}, 1237 0x79, 0x3f, 0x02, 0x53, 0x01, 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02},
1211 [this](Local<Value> value) { 1238 [this](Local<Value> value) {
1212 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof Boolean")); 1239 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof Boolean"));
1213 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); 1240 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b"));
1214 }); 1241 });
1242 #if defined(V8_TARGET_LITTLE_ENDIAN)
1215 DecodeTest( 1243 DecodeTest(
1216 {0xff, 0x09, 0x3f, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 1244 {0xff, 0x09, 0x3f, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45,
1217 0xc0, 0x00}, 1245 0xc0, 0x00},
1218 [this](Local<Value> value) { 1246 [this](Local<Value> value) {
1219 EXPECT_TRUE(EvaluateScriptForResultBool( 1247 EXPECT_TRUE(EvaluateScriptForResultBool(
1220 "Object.getPrototypeOf(result) === Number.prototype")); 1248 "Object.getPrototypeOf(result) === Number.prototype"));
1221 EXPECT_TRUE(EvaluateScriptForResultBool("result.valueOf() === -42")); 1249 EXPECT_TRUE(EvaluateScriptForResultBool("result.valueOf() === -42"));
1222 }); 1250 });
1223 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 1251 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1224 0xf8, 0x7f, 0x00}, 1252 0xf8, 0x7f, 0x00},
1225 [this](Local<Value> value) { 1253 [this](Local<Value> value) {
1226 EXPECT_TRUE(EvaluateScriptForResultBool( 1254 EXPECT_TRUE(EvaluateScriptForResultBool(
1227 "Object.getPrototypeOf(result) === Number.prototype")); 1255 "Object.getPrototypeOf(result) === Number.prototype"));
1228 EXPECT_TRUE(EvaluateScriptForResultBool( 1256 EXPECT_TRUE(EvaluateScriptForResultBool(
1229 "Number.isNaN(result.valueOf())")); 1257 "Number.isNaN(result.valueOf())"));
1230 }); 1258 });
1259 #else
1260 DecodeTest(
1261 {0xff, 0x09, 0x3f, 0x00, 0x6e, 0xc0, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00,
1262 0x00, 0x00},
1263 [this](Local<Value> value) {
1264 EXPECT_TRUE(EvaluateScriptForResultBool(
1265 "Object.getPrototypeOf(result) === Number.prototype"));
1266 EXPECT_TRUE(EvaluateScriptForResultBool("result.valueOf() === -42"));
1267 });
1268 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x6e, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00,
1269 0x00, 0x00, 0x00},
1270 [this](Local<Value> value) {
1271 EXPECT_TRUE(EvaluateScriptForResultBool(
1272 "Object.getPrototypeOf(result) === Number.prototype"));
1273 EXPECT_TRUE(EvaluateScriptForResultBool(
1274 "Number.isNaN(result.valueOf())"));
1275 });
1276 #endif
1231 DecodeTest( 1277 DecodeTest(
1232 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, 0x61, 0x3f, 1278 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, 0x61, 0x3f,
1233 0x01, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x40, 0x3f, 1279 0x01, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x40, 0x3f,
1234 0x02, 0x53, 0x01, 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02}, 1280 0x02, 0x53, 0x01, 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02},
1235 [this](Local<Value> value) { 1281 [this](Local<Value> value) {
1236 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof Number")); 1282 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof Number"));
1237 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); 1283 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b"));
1238 }); 1284 });
1239 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x73, 0x07, 0x51, 0x75, 0xc3, 0xa9, 0x62, 1285 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x73, 0x07, 0x51, 0x75, 0xc3, 0xa9, 0x62,
1240 0x65, 0x63, 0x00}, 1286 0x65, 0x63, 0x00},
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 ASSERT_TRUE(value->IsSet()); 1558 ASSERT_TRUE(value->IsSet());
1513 EXPECT_TRUE(EvaluateScriptForResultBool( 1559 EXPECT_TRUE(EvaluateScriptForResultBool(
1514 "!('baz' in Array.from(result.keys())[0])")); 1560 "!('baz' in Array.from(result.keys())[0])"));
1515 EXPECT_TRUE(EvaluateScriptForResultBool( 1561 EXPECT_TRUE(EvaluateScriptForResultBool(
1516 "Array.from(result.keys())[1].foo === 'bar'")); 1562 "Array.from(result.keys())[1].foo === 'bar'"));
1517 }); 1563 });
1518 } 1564 }
1519 1565
1520 } // namespace 1566 } // namespace
1521 } // namespace v8 1567 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698