| 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 1726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1737 EXPECT_TRUE( | 1737 EXPECT_TRUE( |
| 1738 EvaluateScriptForResultBool("result.a instanceof ArrayBuffer")); | 1738 EvaluateScriptForResultBool("result.a instanceof ArrayBuffer")); |
| 1739 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); | 1739 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); |
| 1740 }); | 1740 }); |
| 1741 } | 1741 } |
| 1742 | 1742 |
| 1743 TEST_F(ValueSerializerTest, DecodeInvalidArrayBuffer) { | 1743 TEST_F(ValueSerializerTest, DecodeInvalidArrayBuffer) { |
| 1744 InvalidDecodeTest({0xff, 0x09, 0x42, 0xff, 0xff, 0x00}); | 1744 InvalidDecodeTest({0xff, 0x09, 0x42, 0xff, 0xff, 0x00}); |
| 1745 } | 1745 } |
| 1746 | 1746 |
| 1747 // An array buffer allocator that never has available memory. |
| 1748 class OOMArrayBufferAllocator : public ArrayBuffer::Allocator { |
| 1749 public: |
| 1750 void* Allocate(size_t) override { return nullptr; } |
| 1751 void* AllocateUninitialized(size_t) override { return nullptr; } |
| 1752 void Free(void*, size_t) override {} |
| 1753 }; |
| 1754 |
| 1755 TEST_F(ValueSerializerTest, DecodeArrayBufferOOM) { |
| 1756 // This test uses less of the harness, because it has to customize the |
| 1757 // isolate. |
| 1758 OOMArrayBufferAllocator allocator; |
| 1759 Isolate::CreateParams params; |
| 1760 params.array_buffer_allocator = &allocator; |
| 1761 Isolate* isolate = Isolate::New(params); |
| 1762 Isolate::Scope isolate_scope(isolate); |
| 1763 HandleScope handle_scope(isolate); |
| 1764 Local<Context> context = Context::New(isolate); |
| 1765 Context::Scope context_scope(context); |
| 1766 TryCatch try_catch(isolate); |
| 1767 |
| 1768 const std::vector<uint8_t> data = {0xff, 0x09, 0x3f, 0x00, 0x42, |
| 1769 0x03, 0x00, 0x80, 0xff, 0x00}; |
| 1770 ValueDeserializer deserializer(isolate, &data[0], |
| 1771 static_cast<int>(data.size()), nullptr); |
| 1772 deserializer.SetSupportsLegacyWireFormat(true); |
| 1773 ASSERT_TRUE(deserializer.ReadHeader(context).FromMaybe(false)); |
| 1774 ASSERT_FALSE(try_catch.HasCaught()); |
| 1775 EXPECT_TRUE(deserializer.ReadValue(context).IsEmpty()); |
| 1776 EXPECT_TRUE(try_catch.HasCaught()); |
| 1777 } |
| 1778 |
| 1747 // Includes an ArrayBuffer wrapper marked for transfer from the serialization | 1779 // Includes an ArrayBuffer wrapper marked for transfer from the serialization |
| 1748 // context to the deserialization context. | 1780 // context to the deserialization context. |
| 1749 class ValueSerializerTestWithArrayBufferTransfer : public ValueSerializerTest { | 1781 class ValueSerializerTestWithArrayBufferTransfer : public ValueSerializerTest { |
| 1750 protected: | 1782 protected: |
| 1751 static const size_t kTestByteLength = 4; | 1783 static const size_t kTestByteLength = 4; |
| 1752 | 1784 |
| 1753 ValueSerializerTestWithArrayBufferTransfer() { | 1785 ValueSerializerTestWithArrayBufferTransfer() { |
| 1754 { | 1786 { |
| 1755 Context::Scope scope(serialization_context()); | 1787 Context::Scope scope(serialization_context()); |
| 1756 input_buffer_ = ArrayBuffer::New(isolate(), nullptr, 0); | 1788 input_buffer_ = ArrayBuffer::New(isolate(), nullptr, 0); |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2566 InvalidDecodeTest(raw); | 2598 InvalidDecodeTest(raw); |
| 2567 } | 2599 } |
| 2568 | 2600 |
| 2569 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) { | 2601 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) { |
| 2570 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00}); | 2602 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00}); |
| 2571 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f}); | 2603 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f}); |
| 2572 } | 2604 } |
| 2573 | 2605 |
| 2574 } // namespace | 2606 } // namespace |
| 2575 } // namespace v8 | 2607 } // namespace v8 |
| OLD | NEW |