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 1499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1510 "})()", | 1510 "})()", |
1511 [this](Local<Value> value) { | 1511 [this](Local<Value> value) { |
1512 ASSERT_TRUE(value->IsSet()); | 1512 ASSERT_TRUE(value->IsSet()); |
1513 EXPECT_TRUE(EvaluateScriptForResultBool( | 1513 EXPECT_TRUE(EvaluateScriptForResultBool( |
1514 "!('baz' in Array.from(result.keys())[0])")); | 1514 "!('baz' in Array.from(result.keys())[0])")); |
1515 EXPECT_TRUE(EvaluateScriptForResultBool( | 1515 EXPECT_TRUE(EvaluateScriptForResultBool( |
1516 "Array.from(result.keys())[1].foo === 'bar'")); | 1516 "Array.from(result.keys())[1].foo === 'bar'")); |
1517 }); | 1517 }); |
1518 } | 1518 } |
1519 | 1519 |
| 1520 TEST_F(ValueSerializerTest, RoundTripArrayBuffer) { |
| 1521 RoundTripTest("new ArrayBuffer()", [this](Local<Value> value) { |
| 1522 ASSERT_TRUE(value->IsArrayBuffer()); |
| 1523 EXPECT_EQ(0u, ArrayBuffer::Cast(*value)->ByteLength()); |
| 1524 EXPECT_TRUE(EvaluateScriptForResultBool( |
| 1525 "Object.getPrototypeOf(result) === ArrayBuffer.prototype")); |
| 1526 }); |
| 1527 RoundTripTest("new Uint8Array([0, 128, 255]).buffer", |
| 1528 [this](Local<Value> value) { |
| 1529 ASSERT_TRUE(value->IsArrayBuffer()); |
| 1530 EXPECT_EQ(3u, ArrayBuffer::Cast(*value)->ByteLength()); |
| 1531 EXPECT_TRUE(EvaluateScriptForResultBool( |
| 1532 "new Uint8Array(result).toString() === '0,128,255'")); |
| 1533 }); |
| 1534 RoundTripTest( |
| 1535 "({ a: new ArrayBuffer(), get b() { return this.a; }})", |
| 1536 [this](Local<Value> value) { |
| 1537 EXPECT_TRUE( |
| 1538 EvaluateScriptForResultBool("result.a instanceof ArrayBuffer")); |
| 1539 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); |
| 1540 }); |
| 1541 } |
| 1542 |
| 1543 TEST_F(ValueSerializerTest, DecodeArrayBuffer) { |
| 1544 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x42, 0x00}, |
| 1545 [this](Local<Value> value) { |
| 1546 ASSERT_TRUE(value->IsArrayBuffer()); |
| 1547 EXPECT_EQ(0u, ArrayBuffer::Cast(*value)->ByteLength()); |
| 1548 EXPECT_TRUE(EvaluateScriptForResultBool( |
| 1549 "Object.getPrototypeOf(result) === ArrayBuffer.prototype")); |
| 1550 }); |
| 1551 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x42, 0x03, 0x00, 0x80, 0xff, 0x00}, |
| 1552 [this](Local<Value> value) { |
| 1553 ASSERT_TRUE(value->IsArrayBuffer()); |
| 1554 EXPECT_EQ(3u, ArrayBuffer::Cast(*value)->ByteLength()); |
| 1555 EXPECT_TRUE(EvaluateScriptForResultBool( |
| 1556 "new Uint8Array(result).toString() === '0,128,255'")); |
| 1557 }); |
| 1558 DecodeTest( |
| 1559 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, |
| 1560 0x61, 0x3f, 0x01, 0x42, 0x00, 0x3f, 0x02, 0x53, 0x01, |
| 1561 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02, 0x00}, |
| 1562 [this](Local<Value> value) { |
| 1563 EXPECT_TRUE( |
| 1564 EvaluateScriptForResultBool("result.a instanceof ArrayBuffer")); |
| 1565 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); |
| 1566 }); |
| 1567 } |
| 1568 |
| 1569 TEST_F(ValueSerializerTest, DecodeInvalidArrayBuffer) { |
| 1570 InvalidDecodeTest({0xff, 0x09, 0x42, 0xff, 0xff, 0x00}); |
| 1571 } |
| 1572 |
1520 } // namespace | 1573 } // namespace |
1521 } // namespace v8 | 1574 } // namespace v8 |
OLD | NEW |