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

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: Remove another 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());
1107 EXPECT_EQ(1e6, Date::Cast(*value)->ValueOf()); 1108 EXPECT_EQ(1e6, Date::Cast(*value)->ValueOf());
1108 EXPECT_TRUE("Object.getPrototypeOf(result) === Date.prototype"); 1109 EXPECT_TRUE("Object.getPrototypeOf(result) === Date.prototype");
1109 }); 1110 });
1110 DecodeTest( 1111 DecodeTest(
1111 {0xff, 0x09, 0x3f, 0x00, 0x44, 0x00, 0x00, 0x20, 0x45, 0x27, 0x89, 0x87, 1112 {0xff, 0x09, 0x3f, 0x00, 0x44, 0x00, 0x00, 0x20, 0x45, 0x27, 0x89, 0x87,
1112 0xc2, 0x00}, 1113 0xc2, 0x00},
1113 [this](Local<Value> value) { 1114 [this](Local<Value> value) {
1114 ASSERT_TRUE(value->IsDate()); 1115 ASSERT_TRUE(value->IsDate());
1115 EXPECT_TRUE("result.toISOString() === '1867-07-01T00:00:00.000Z'"); 1116 EXPECT_TRUE("result.toISOString() === '1867-07-01T00:00:00.000Z'");
1116 }); 1117 });
1117 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 1118 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1118 0xf8, 0x7f, 0x00}, 1119 0xf8, 0x7f, 0x00},
1119 [this](Local<Value> value) { 1120 [this](Local<Value> value) {
1120 ASSERT_TRUE(value->IsDate()); 1121 ASSERT_TRUE(value->IsDate());
1121 EXPECT_TRUE(std::isnan(Date::Cast(*value)->ValueOf())); 1122 EXPECT_TRUE(std::isnan(Date::Cast(*value)->ValueOf()));
1122 }); 1123 });
1124 #else
1125 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x44, 0x41, 0x2e, 0x84, 0x80, 0x00, 0x00,
1126 0x00, 0x00, 0x00},
1127 [this](Local<Value> value) {
1128 ASSERT_TRUE(value->IsDate());
1129 EXPECT_EQ(1e6, Date::Cast(*value)->ValueOf());
1130 EXPECT_TRUE("Object.getPrototypeOf(result) === Date.prototype");
1131 });
1132 DecodeTest(
1133 {0xff, 0x09, 0x3f, 0x00, 0x44, 0xc2, 0x87, 0x89, 0x27, 0x45, 0x20, 0x00,
1134 0x00, 0x00},
1135 [this](Local<Value> value) {
1136 ASSERT_TRUE(value->IsDate());
1137 EXPECT_TRUE("result.toISOString() === '1867-07-01T00:00:00.000Z'");
1138 });
1139 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x44, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00,
1140 0x00, 0x00, 0x00},
1141 [this](Local<Value> value) {
1142 ASSERT_TRUE(value->IsDate());
1143 EXPECT_TRUE(std::isnan(Date::Cast(*value)->ValueOf()));
1144 });
1145 #endif
1123 DecodeTest( 1146 DecodeTest(
1124 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, 0x61, 0x3f, 1147 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, 0x61, 0x3f,
1125 0x01, 0x44, 0x00, 0x20, 0x39, 0x50, 0x37, 0x6a, 0x75, 0x42, 0x3f, 1148 0x01, 0x44, 0x00, 0x20, 0x39, 0x50, 0x37, 0x6a, 0x75, 0x42, 0x3f,
1126 0x02, 0x53, 0x01, 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02}, 1149 0x02, 0x53, 0x01, 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02},
1127 [this](Local<Value> value) { 1150 [this](Local<Value> value) {
1128 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof Date")); 1151 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof Date"));
1129 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); 1152 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b"));
1130 }); 1153 });
1131 } 1154 }
1132 1155
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 "Object.getPrototypeOf(result) === Boolean.prototype")); 1228 "Object.getPrototypeOf(result) === Boolean.prototype"));
1206 EXPECT_TRUE(EvaluateScriptForResultBool("result.valueOf() === false")); 1229 EXPECT_TRUE(EvaluateScriptForResultBool("result.valueOf() === false"));
1207 }); 1230 });
1208 DecodeTest( 1231 DecodeTest(
1209 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, 0x61, 0x3f, 0x01, 1232 {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}, 1233 0x79, 0x3f, 0x02, 0x53, 0x01, 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02},
1211 [this](Local<Value> value) { 1234 [this](Local<Value> value) {
1212 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof Boolean")); 1235 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof Boolean"));
1213 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); 1236 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b"));
1214 }); 1237 });
1238 #if defined(V8_TARGET_LITTLE_ENDIAN)
1215 DecodeTest( 1239 DecodeTest(
1216 {0xff, 0x09, 0x3f, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 1240 {0xff, 0x09, 0x3f, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45,
1217 0xc0, 0x00}, 1241 0xc0, 0x00},
1218 [this](Local<Value> value) { 1242 [this](Local<Value> value) {
1219 EXPECT_TRUE(EvaluateScriptForResultBool( 1243 EXPECT_TRUE(EvaluateScriptForResultBool(
1220 "Object.getPrototypeOf(result) === Number.prototype")); 1244 "Object.getPrototypeOf(result) === Number.prototype"));
1221 EXPECT_TRUE(EvaluateScriptForResultBool("result.valueOf() === -42")); 1245 EXPECT_TRUE(EvaluateScriptForResultBool("result.valueOf() === -42"));
1222 }); 1246 });
1223 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 1247 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1224 0xf8, 0x7f, 0x00}, 1248 0xf8, 0x7f, 0x00},
1225 [this](Local<Value> value) { 1249 [this](Local<Value> value) {
1226 EXPECT_TRUE(EvaluateScriptForResultBool( 1250 EXPECT_TRUE(EvaluateScriptForResultBool(
1227 "Object.getPrototypeOf(result) === Number.prototype")); 1251 "Object.getPrototypeOf(result) === Number.prototype"));
1228 EXPECT_TRUE(EvaluateScriptForResultBool( 1252 EXPECT_TRUE(EvaluateScriptForResultBool(
1229 "Number.isNaN(result.valueOf())")); 1253 "Number.isNaN(result.valueOf())"));
1230 }); 1254 });
1255 #else
1256 DecodeTest(
1257 {0xff, 0x09, 0x3f, 0x00, 0x6e, 0xc0, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00,
1258 0x00, 0x00},
1259 [this](Local<Value> value) {
1260 EXPECT_TRUE(EvaluateScriptForResultBool(
1261 "Object.getPrototypeOf(result) === Number.prototype"));
1262 EXPECT_TRUE(EvaluateScriptForResultBool("result.valueOf() === -42"));
1263 });
1264 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x6e, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00,
1265 0x00, 0x00, 0x00},
1266 [this](Local<Value> value) {
1267 EXPECT_TRUE(EvaluateScriptForResultBool(
1268 "Object.getPrototypeOf(result) === Number.prototype"));
1269 EXPECT_TRUE(EvaluateScriptForResultBool(
1270 "Number.isNaN(result.valueOf())"));
1271 });
1272 #endif
1231 DecodeTest( 1273 DecodeTest(
1232 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, 0x61, 0x3f, 1274 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, 0x61, 0x3f,
1233 0x01, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x40, 0x3f, 1275 0x01, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x40, 0x3f,
1234 0x02, 0x53, 0x01, 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02}, 1276 0x02, 0x53, 0x01, 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02},
1235 [this](Local<Value> value) { 1277 [this](Local<Value> value) {
1236 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof Number")); 1278 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof Number"));
1237 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); 1279 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b"));
1238 }); 1280 });
1239 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x73, 0x07, 0x51, 0x75, 0xc3, 0xa9, 0x62, 1281 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x73, 0x07, 0x51, 0x75, 0xc3, 0xa9, 0x62,
1240 0x65, 0x63, 0x00}, 1282 0x65, 0x63, 0x00},
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 ASSERT_TRUE(value->IsSet()); 1554 ASSERT_TRUE(value->IsSet());
1513 EXPECT_TRUE(EvaluateScriptForResultBool( 1555 EXPECT_TRUE(EvaluateScriptForResultBool(
1514 "!('baz' in Array.from(result.keys())[0])")); 1556 "!('baz' in Array.from(result.keys())[0])"));
1515 EXPECT_TRUE(EvaluateScriptForResultBool( 1557 EXPECT_TRUE(EvaluateScriptForResultBool(
1516 "Array.from(result.keys())[1].foo === 'bar'")); 1558 "Array.from(result.keys())[1].foo === 'bar'"));
1517 }); 1559 });
1518 } 1560 }
1519 1561
1520 } // namespace 1562 } // namespace
1521 } // namespace v8 1563 } // 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