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 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1256 DecodeTest( | 1256 DecodeTest( |
1257 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, | 1257 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, |
1258 0x61, 0x3f, 0x01, 0x73, 0x00, 0x3f, 0x02, 0x53, 0x01, | 1258 0x61, 0x3f, 0x01, 0x73, 0x00, 0x3f, 0x02, 0x53, 0x01, |
1259 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02, 0x00}, | 1259 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02, 0x00}, |
1260 [this](Local<Value> value) { | 1260 [this](Local<Value> value) { |
1261 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof String")); | 1261 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof String")); |
1262 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); | 1262 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); |
1263 }); | 1263 }); |
1264 } | 1264 } |
1265 | 1265 |
| 1266 TEST_F(ValueSerializerTest, RoundTripRegExp) { |
| 1267 RoundTripTest("/foo/g", [this](Local<Value> value) { |
| 1268 ASSERT_TRUE(value->IsRegExp()); |
| 1269 EXPECT_TRUE(EvaluateScriptForResultBool( |
| 1270 "Object.getPrototypeOf(result) === RegExp.prototype")); |
| 1271 EXPECT_TRUE(EvaluateScriptForResultBool("result.toString() === '/foo/g'")); |
| 1272 }); |
| 1273 RoundTripTest("new RegExp('Qu\\xe9bec', 'i')", [this](Local<Value> value) { |
| 1274 ASSERT_TRUE(value->IsRegExp()); |
| 1275 EXPECT_TRUE( |
| 1276 EvaluateScriptForResultBool("result.toString() === '/Qu\\xe9bec/i'")); |
| 1277 }); |
| 1278 RoundTripTest("new RegExp('\\ud83d\\udc4a', 'ug')", |
| 1279 [this](Local<Value> value) { |
| 1280 ASSERT_TRUE(value->IsRegExp()); |
| 1281 EXPECT_TRUE(EvaluateScriptForResultBool( |
| 1282 "result.toString() === '/\\ud83d\\udc4a/gu'")); |
| 1283 }); |
| 1284 RoundTripTest( |
| 1285 "({ a: /foo/gi, get b() { return this.a; }})", |
| 1286 [this](Local<Value> value) { |
| 1287 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof RegExp")); |
| 1288 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); |
| 1289 }); |
| 1290 } |
| 1291 |
| 1292 TEST_F(ValueSerializerTest, DecodeRegExp) { |
| 1293 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x01}, |
| 1294 [this](Local<Value> value) { |
| 1295 ASSERT_TRUE(value->IsRegExp()); |
| 1296 EXPECT_TRUE(EvaluateScriptForResultBool( |
| 1297 "Object.getPrototypeOf(result) === RegExp.prototype")); |
| 1298 EXPECT_TRUE(EvaluateScriptForResultBool( |
| 1299 "result.toString() === '/foo/g'")); |
| 1300 }); |
| 1301 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x52, 0x07, 0x51, 0x75, 0xc3, 0xa9, 0x62, |
| 1302 0x65, 0x63, 0x02}, |
| 1303 [this](Local<Value> value) { |
| 1304 ASSERT_TRUE(value->IsRegExp()); |
| 1305 EXPECT_TRUE(EvaluateScriptForResultBool( |
| 1306 "result.toString() === '/Qu\\xe9bec/i'")); |
| 1307 }); |
| 1308 DecodeTest( |
| 1309 {0xff, 0x09, 0x3f, 0x00, 0x52, 0x04, 0xf0, 0x9f, 0x91, 0x8a, 0x11, 0x00}, |
| 1310 [this](Local<Value> value) { |
| 1311 ASSERT_TRUE(value->IsRegExp()); |
| 1312 EXPECT_TRUE(EvaluateScriptForResultBool( |
| 1313 "result.toString() === '/\\ud83d\\udc4a/gu'")); |
| 1314 }); |
| 1315 DecodeTest( |
| 1316 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, 0x61, |
| 1317 0x3f, 0x01, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x03, 0x3f, 0x02, |
| 1318 0x53, 0x01, 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02, 0x00}, |
| 1319 [this](Local<Value> value) { |
| 1320 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof RegExp")); |
| 1321 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); |
| 1322 }); |
| 1323 } |
| 1324 |
1266 } // namespace | 1325 } // namespace |
1267 } // namespace v8 | 1326 } // namespace v8 |
OLD | NEW |