OLD | NEW |
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 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 [this](Local<Value> value) { | 1066 [this](Local<Value> value) { |
1067 ASSERT_TRUE(value->IsArray()); | 1067 ASSERT_TRUE(value->IsArray()); |
1068 EXPECT_EQ(2, Array::Cast(*value)->Length()); | 1068 EXPECT_EQ(2, Array::Cast(*value)->Length()); |
1069 EXPECT_TRUE(EvaluateScriptForResultBool("!(0 in result)")); | 1069 EXPECT_TRUE(EvaluateScriptForResultBool("!(0 in result)")); |
1070 EXPECT_TRUE(EvaluateScriptForResultBool("result[1] instanceof Array")); | 1070 EXPECT_TRUE(EvaluateScriptForResultBool("result[1] instanceof Array")); |
1071 EXPECT_TRUE(EvaluateScriptForResultBool("!(0 in result[1])")); | 1071 EXPECT_TRUE(EvaluateScriptForResultBool("!(0 in result[1])")); |
1072 EXPECT_TRUE(EvaluateScriptForResultBool("result[1][1] === true")); | 1072 EXPECT_TRUE(EvaluateScriptForResultBool("result[1][1] === true")); |
1073 }); | 1073 }); |
1074 } | 1074 } |
1075 | 1075 |
| 1076 TEST_F(ValueSerializerTest, RoundTripDate) { |
| 1077 RoundTripTest("new Date(1e6)", [this](Local<Value> value) { |
| 1078 ASSERT_TRUE(value->IsDate()); |
| 1079 EXPECT_EQ(1e6, Date::Cast(*value)->ValueOf()); |
| 1080 EXPECT_TRUE("Object.getPrototypeOf(result) === Date.prototype"); |
| 1081 }); |
| 1082 RoundTripTest("new Date(Date.UTC(1867, 6, 1))", [this](Local<Value> value) { |
| 1083 ASSERT_TRUE(value->IsDate()); |
| 1084 EXPECT_TRUE("result.toISOString() === '1867-07-01T00:00:00.000Z'"); |
| 1085 }); |
| 1086 RoundTripTest("new Date(NaN)", [this](Local<Value> value) { |
| 1087 ASSERT_TRUE(value->IsDate()); |
| 1088 EXPECT_TRUE(std::isnan(Date::Cast(*value)->ValueOf())); |
| 1089 }); |
| 1090 RoundTripTest( |
| 1091 "({ a: new Date(), get b() { return this.a; } })", |
| 1092 [this](Local<Value> value) { |
| 1093 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof Date")); |
| 1094 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); |
| 1095 }); |
| 1096 } |
| 1097 |
| 1098 TEST_F(ValueSerializerTest, DecodeDate) { |
| 1099 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x80, 0x84, |
| 1100 0x2e, 0x41, 0x00}, |
| 1101 [this](Local<Value> value) { |
| 1102 ASSERT_TRUE(value->IsDate()); |
| 1103 EXPECT_EQ(1e6, Date::Cast(*value)->ValueOf()); |
| 1104 EXPECT_TRUE("Object.getPrototypeOf(result) === Date.prototype"); |
| 1105 }); |
| 1106 DecodeTest( |
| 1107 {0xff, 0x09, 0x3f, 0x00, 0x44, 0x00, 0x00, 0x20, 0x45, 0x27, 0x89, 0x87, |
| 1108 0xc2, 0x00}, |
| 1109 [this](Local<Value> value) { |
| 1110 ASSERT_TRUE(value->IsDate()); |
| 1111 EXPECT_TRUE("result.toISOString() === '1867-07-01T00:00:00.000Z'"); |
| 1112 }); |
| 1113 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1114 0xf8, 0x7f, 0x00}, |
| 1115 [this](Local<Value> value) { |
| 1116 ASSERT_TRUE(value->IsDate()); |
| 1117 EXPECT_TRUE(std::isnan(Date::Cast(*value)->ValueOf())); |
| 1118 }); |
| 1119 DecodeTest( |
| 1120 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, 0x61, 0x3f, |
| 1121 0x01, 0x44, 0x00, 0x20, 0x39, 0x50, 0x37, 0x6a, 0x75, 0x42, 0x3f, |
| 1122 0x02, 0x53, 0x01, 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02}, |
| 1123 [this](Local<Value> value) { |
| 1124 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof Date")); |
| 1125 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); |
| 1126 }); |
| 1127 } |
| 1128 |
1076 } // namespace | 1129 } // namespace |
1077 } // namespace v8 | 1130 } // namespace v8 |
OLD | NEW |