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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 const Local<Context>& serialization_context() { | 70 const Local<Context>& serialization_context() { |
71 return serialization_context_; | 71 return serialization_context_; |
72 } | 72 } |
73 const Local<Context>& deserialization_context() { | 73 const Local<Context>& deserialization_context() { |
74 return deserialization_context_; | 74 return deserialization_context_; |
75 } | 75 } |
76 | 76 |
| 77 bool ExpectInlineWasm() const { return expect_inline_wasm_; } |
| 78 void SetExpectInlineWasm(bool value) { expect_inline_wasm_ = value; } |
| 79 |
77 // Overridden in more specific fixtures. | 80 // Overridden in more specific fixtures. |
78 virtual ValueSerializer::Delegate* GetSerializerDelegate() { return nullptr; } | 81 virtual ValueSerializer::Delegate* GetSerializerDelegate() { return nullptr; } |
79 virtual void BeforeEncode(ValueSerializer*) {} | 82 virtual void BeforeEncode(ValueSerializer*) {} |
80 virtual void AfterEncode() {} | 83 virtual void AfterEncode() {} |
81 virtual ValueDeserializer::Delegate* GetDeserializerDelegate() { | 84 virtual ValueDeserializer::Delegate* GetDeserializerDelegate() { |
82 return nullptr; | 85 return nullptr; |
83 } | 86 } |
84 virtual void BeforeDecode(ValueDeserializer*) {} | 87 virtual void BeforeDecode(ValueDeserializer*) {} |
85 | 88 |
86 template <typename InputFunctor, typename OutputFunctor> | 89 template <typename InputFunctor, typename OutputFunctor> |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 template <typename OutputFunctor> | 168 template <typename OutputFunctor> |
166 void DecodeTest(const std::vector<uint8_t>& data, | 169 void DecodeTest(const std::vector<uint8_t>& data, |
167 const OutputFunctor& output_functor) { | 170 const OutputFunctor& output_functor) { |
168 Local<Context> context = deserialization_context(); | 171 Local<Context> context = deserialization_context(); |
169 Context::Scope scope(context); | 172 Context::Scope scope(context); |
170 TryCatch try_catch(isolate()); | 173 TryCatch try_catch(isolate()); |
171 ValueDeserializer deserializer(isolate(), &data[0], | 174 ValueDeserializer deserializer(isolate(), &data[0], |
172 static_cast<int>(data.size()), | 175 static_cast<int>(data.size()), |
173 GetDeserializerDelegate()); | 176 GetDeserializerDelegate()); |
174 deserializer.SetSupportsLegacyWireFormat(true); | 177 deserializer.SetSupportsLegacyWireFormat(true); |
| 178 deserializer.SetExpectInlineWasm(ExpectInlineWasm()); |
175 BeforeDecode(&deserializer); | 179 BeforeDecode(&deserializer); |
176 ASSERT_TRUE(deserializer.ReadHeader(context).FromMaybe(false)); | 180 ASSERT_TRUE(deserializer.ReadHeader(context).FromMaybe(false)); |
177 Local<Value> result; | 181 Local<Value> result; |
178 ASSERT_TRUE(deserializer.ReadValue(context).ToLocal(&result)); | 182 ASSERT_TRUE(deserializer.ReadValue(context).ToLocal(&result)); |
179 ASSERT_FALSE(result.IsEmpty()); | 183 ASSERT_FALSE(result.IsEmpty()); |
180 ASSERT_FALSE(try_catch.HasCaught()); | 184 ASSERT_FALSE(try_catch.HasCaught()); |
181 ASSERT_TRUE( | 185 ASSERT_TRUE( |
182 context->Global() | 186 context->Global() |
183 ->CreateDataProperty(context, StringFromUtf8("result"), result) | 187 ->CreateDataProperty(context, StringFromUtf8("result"), result) |
184 .FromMaybe(false)); | 188 .FromMaybe(false)); |
185 output_functor(result); | 189 output_functor(result); |
186 ASSERT_FALSE(try_catch.HasCaught()); | 190 ASSERT_FALSE(try_catch.HasCaught()); |
187 } | 191 } |
188 | 192 |
189 template <typename OutputFunctor> | 193 template <typename OutputFunctor> |
190 void DecodeTestForVersion0(const std::vector<uint8_t>& data, | 194 void DecodeTestForVersion0(const std::vector<uint8_t>& data, |
191 const OutputFunctor& output_functor) { | 195 const OutputFunctor& output_functor) { |
192 Local<Context> context = deserialization_context(); | 196 Local<Context> context = deserialization_context(); |
193 Context::Scope scope(context); | 197 Context::Scope scope(context); |
194 TryCatch try_catch(isolate()); | 198 TryCatch try_catch(isolate()); |
195 ValueDeserializer deserializer(isolate(), &data[0], | 199 ValueDeserializer deserializer(isolate(), &data[0], |
196 static_cast<int>(data.size()), | 200 static_cast<int>(data.size()), |
197 GetDeserializerDelegate()); | 201 GetDeserializerDelegate()); |
198 deserializer.SetSupportsLegacyWireFormat(true); | 202 deserializer.SetSupportsLegacyWireFormat(true); |
| 203 deserializer.SetExpectInlineWasm(ExpectInlineWasm()); |
199 BeforeDecode(&deserializer); | 204 BeforeDecode(&deserializer); |
200 ASSERT_TRUE(deserializer.ReadHeader(context).FromMaybe(false)); | 205 ASSERT_TRUE(deserializer.ReadHeader(context).FromMaybe(false)); |
201 ASSERT_EQ(0u, deserializer.GetWireFormatVersion()); | 206 ASSERT_EQ(0u, deserializer.GetWireFormatVersion()); |
202 Local<Value> result; | 207 Local<Value> result; |
203 ASSERT_TRUE(deserializer.ReadValue(context).ToLocal(&result)); | 208 ASSERT_TRUE(deserializer.ReadValue(context).ToLocal(&result)); |
204 ASSERT_FALSE(result.IsEmpty()); | 209 ASSERT_FALSE(result.IsEmpty()); |
205 ASSERT_FALSE(try_catch.HasCaught()); | 210 ASSERT_FALSE(try_catch.HasCaught()); |
206 ASSERT_TRUE( | 211 ASSERT_TRUE( |
207 context->Global() | 212 context->Global() |
208 ->CreateDataProperty(context, StringFromUtf8("result"), result) | 213 ->CreateDataProperty(context, StringFromUtf8("result"), result) |
209 .FromMaybe(false)); | 214 .FromMaybe(false)); |
210 output_functor(result); | 215 output_functor(result); |
211 ASSERT_FALSE(try_catch.HasCaught()); | 216 ASSERT_FALSE(try_catch.HasCaught()); |
212 } | 217 } |
213 | 218 |
214 void InvalidDecodeTest(const std::vector<uint8_t>& data) { | 219 void InvalidDecodeTest(const std::vector<uint8_t>& data) { |
215 Local<Context> context = deserialization_context(); | 220 Local<Context> context = deserialization_context(); |
216 Context::Scope scope(context); | 221 Context::Scope scope(context); |
217 TryCatch try_catch(isolate()); | 222 TryCatch try_catch(isolate()); |
218 ValueDeserializer deserializer(isolate(), &data[0], | 223 ValueDeserializer deserializer(isolate(), &data[0], |
219 static_cast<int>(data.size()), | 224 static_cast<int>(data.size()), |
220 GetDeserializerDelegate()); | 225 GetDeserializerDelegate()); |
221 deserializer.SetSupportsLegacyWireFormat(true); | 226 deserializer.SetSupportsLegacyWireFormat(true); |
| 227 deserializer.SetExpectInlineWasm(ExpectInlineWasm()); |
222 BeforeDecode(&deserializer); | 228 BeforeDecode(&deserializer); |
223 Maybe<bool> header_result = deserializer.ReadHeader(context); | 229 Maybe<bool> header_result = deserializer.ReadHeader(context); |
224 if (header_result.IsNothing()) { | 230 if (header_result.IsNothing()) { |
225 EXPECT_TRUE(try_catch.HasCaught()); | 231 EXPECT_TRUE(try_catch.HasCaught()); |
226 return; | 232 return; |
227 } | 233 } |
228 ASSERT_TRUE(header_result.ToChecked()); | 234 ASSERT_TRUE(header_result.ToChecked()); |
229 ASSERT_TRUE(deserializer.ReadValue(context).IsEmpty()); | 235 ASSERT_TRUE(deserializer.ReadValue(context).IsEmpty()); |
230 EXPECT_TRUE(try_catch.HasCaught()); | 236 EXPECT_TRUE(try_catch.HasCaught()); |
231 } | 237 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 Local<ArrayBuffer> ab = | 274 Local<ArrayBuffer> ab = |
269 ArrayBuffer::New(isolate(), static_cast<void*>(data), sizeof(data)); | 275 ArrayBuffer::New(isolate(), static_cast<void*>(data), sizeof(data)); |
270 return Uint8Array::New(ab, 0, sizeof(data)); | 276 return Uint8Array::New(ab, 0, sizeof(data)); |
271 } | 277 } |
272 | 278 |
273 private: | 279 private: |
274 Local<Context> serialization_context_; | 280 Local<Context> serialization_context_; |
275 Local<Context> deserialization_context_; | 281 Local<Context> deserialization_context_; |
276 Local<FunctionTemplate> host_object_constructor_template_; | 282 Local<FunctionTemplate> host_object_constructor_template_; |
277 i::Isolate* isolate_; | 283 i::Isolate* isolate_; |
| 284 bool expect_inline_wasm_ = false; |
278 | 285 |
279 DISALLOW_COPY_AND_ASSIGN(ValueSerializerTest); | 286 DISALLOW_COPY_AND_ASSIGN(ValueSerializerTest); |
280 }; | 287 }; |
281 | 288 |
282 TEST_F(ValueSerializerTest, DecodeInvalid) { | 289 TEST_F(ValueSerializerTest, DecodeInvalid) { |
283 // Version tag but no content. | 290 // Version tag but no content. |
284 InvalidDecodeTest({0xff}); | 291 InvalidDecodeTest({0xff}); |
285 // Version too large. | 292 // Version too large. |
286 InvalidDecodeTest({0xff, 0x7f, 0x5f}); | 293 InvalidDecodeTest({0xff, 0x7f, 0x5f}); |
287 // Nonsense tag. | 294 // Nonsense tag. |
(...skipping 2299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2587 EXPECT_TRUE( | 2594 EXPECT_TRUE( |
2588 EvaluateScriptForResultBool("result.a.toString() === '4,5,6'")); | 2595 EvaluateScriptForResultBool("result.a.toString() === '4,5,6'")); |
2589 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); | 2596 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); |
2590 }); | 2597 }); |
2591 } | 2598 } |
2592 | 2599 |
2593 // It's expected that WebAssembly has more exhaustive tests elsewhere; this | 2600 // It's expected that WebAssembly has more exhaustive tests elsewhere; this |
2594 // mostly checks that the logic to embed it in structured clone serialization | 2601 // mostly checks that the logic to embed it in structured clone serialization |
2595 // works correctly. | 2602 // works correctly. |
2596 | 2603 |
| 2604 // A simple module which exports an "increment" function. |
| 2605 // Copied from test/mjsunit/wasm/incrementer.wasm. |
| 2606 const unsigned char kIncrementerWasm[] = { |
| 2607 0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 1, 127, 1, 127, |
| 2608 3, 2, 1, 0, 7, 13, 1, 9, 105, 110, 99, 114, 101, 109, 101, 110, |
| 2609 116, 0, 0, 10, 9, 1, 7, 0, 32, 0, 65, 1, 106, 11, |
| 2610 }; |
| 2611 |
2597 class ValueSerializerTestWithWasm : public ValueSerializerTest { | 2612 class ValueSerializerTestWithWasm : public ValueSerializerTest { |
| 2613 public: |
| 2614 ValueSerializerTestWithWasm() |
| 2615 : serialize_delegate_(&transfer_modules_), |
| 2616 deserialize_delegate_(&transfer_modules_) {} |
| 2617 |
| 2618 void Reset() { |
| 2619 current_serializer_delegate_ = nullptr; |
| 2620 transfer_modules_.clear(); |
| 2621 SetExpectInlineWasm(false); |
| 2622 } |
| 2623 |
| 2624 void EnableTransferSerialization() { |
| 2625 current_serializer_delegate_ = &serialize_delegate_; |
| 2626 } |
| 2627 |
| 2628 void EnableTransferDeserialization() { |
| 2629 current_deserializer_delegate_ = &deserialize_delegate_; |
| 2630 } |
| 2631 |
| 2632 void EnableThrowingSerializer() { |
| 2633 current_serializer_delegate_ = &throwing_serializer_; |
| 2634 } |
| 2635 |
| 2636 void EnableDefaultDeserializer() { |
| 2637 current_deserializer_delegate_ = &default_deserializer_; |
| 2638 } |
| 2639 |
2598 protected: | 2640 protected: |
2599 static void SetUpTestCase() { | 2641 static void SetUpTestCase() { |
2600 g_saved_flag = i::FLAG_expose_wasm; | 2642 g_saved_flag = i::FLAG_expose_wasm; |
2601 i::FLAG_expose_wasm = true; | 2643 i::FLAG_expose_wasm = true; |
2602 ValueSerializerTest::SetUpTestCase(); | 2644 ValueSerializerTest::SetUpTestCase(); |
2603 } | 2645 } |
2604 | 2646 |
2605 static void TearDownTestCase() { | 2647 static void TearDownTestCase() { |
2606 ValueSerializerTest::TearDownTestCase(); | 2648 ValueSerializerTest::TearDownTestCase(); |
2607 i::FLAG_expose_wasm = g_saved_flag; | 2649 i::FLAG_expose_wasm = g_saved_flag; |
2608 g_saved_flag = false; | 2650 g_saved_flag = false; |
2609 } | 2651 } |
2610 | 2652 |
| 2653 class ThrowingSerializer : public ValueSerializer::Delegate { |
| 2654 public: |
| 2655 Maybe<uint32_t> GetWasmModuleTransferId( |
| 2656 Isolate* v8_isolate, Local<WasmCompiledModule> module) override { |
| 2657 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 2658 isolate->ScheduleThrow(*isolate->factory()->NewError( |
| 2659 isolate->error_function(), i::MessageTemplate::kDataCloneError, |
| 2660 Utils::OpenHandle(*module))); |
| 2661 return Nothing<uint32_t>(); |
| 2662 } |
| 2663 |
| 2664 void ThrowDataCloneError(Local<String> message) override { UNREACHABLE(); } |
| 2665 }; |
| 2666 |
| 2667 class SerializeToTransfer : public ValueSerializer::Delegate { |
| 2668 public: |
| 2669 SerializeToTransfer( |
| 2670 std::vector<WasmCompiledModule::TransferrableModule>* modules) |
| 2671 : modules_(modules) {} |
| 2672 Maybe<uint32_t> GetWasmModuleTransferId( |
| 2673 Isolate* isolate, Local<WasmCompiledModule> module) override { |
| 2674 modules_->push_back(module->GetTransferrableModule()); |
| 2675 return Just(static_cast<uint32_t>(modules_->size()) - 1); |
| 2676 } |
| 2677 |
| 2678 void ThrowDataCloneError(Local<String> message) override { UNREACHABLE(); } |
| 2679 |
| 2680 private: |
| 2681 std::vector<WasmCompiledModule::TransferrableModule>* modules_; |
| 2682 }; |
| 2683 |
| 2684 class DeserializeFromTransfer : public ValueDeserializer::Delegate { |
| 2685 public: |
| 2686 DeserializeFromTransfer( |
| 2687 std::vector<WasmCompiledModule::TransferrableModule>* modules) |
| 2688 : modules_(modules) {} |
| 2689 |
| 2690 MaybeLocal<WasmCompiledModule> GetWasmModuleFromId(Isolate* isolate, |
| 2691 uint32_t id) override { |
| 2692 return WasmCompiledModule::FromTransferrableModule(isolate, |
| 2693 modules_->at(id)); |
| 2694 } |
| 2695 |
| 2696 private: |
| 2697 std::vector<WasmCompiledModule::TransferrableModule>* modules_; |
| 2698 }; |
| 2699 |
| 2700 ValueSerializer::Delegate* GetSerializerDelegate() override { |
| 2701 return current_serializer_delegate_; |
| 2702 } |
| 2703 |
| 2704 ValueDeserializer::Delegate* GetDeserializerDelegate() override { |
| 2705 return current_deserializer_delegate_; |
| 2706 } |
| 2707 |
| 2708 Local<WasmCompiledModule> MakeWasm() { |
| 2709 return WasmCompiledModule::DeserializeOrCompile( |
| 2710 isolate(), {nullptr, 0}, |
| 2711 {kIncrementerWasm, sizeof(kIncrementerWasm)}) |
| 2712 .ToLocalChecked(); |
| 2713 } |
| 2714 |
| 2715 void ExpectPass() { |
| 2716 RoundTripTest( |
| 2717 [this]() { return MakeWasm(); }, |
| 2718 [this](Local<Value> value) { |
| 2719 ASSERT_TRUE(value->IsWebAssemblyCompiledModule()); |
| 2720 EXPECT_TRUE(EvaluateScriptForResultBool( |
| 2721 "new WebAssembly.Instance(result).exports.increment(8) === 9")); |
| 2722 }); |
| 2723 } |
| 2724 |
| 2725 void ExpectFail() { |
| 2726 EncodeTest( |
| 2727 [this]() { return MakeWasm(); }, |
| 2728 [this](const std::vector<uint8_t>& data) { InvalidDecodeTest(data); }); |
| 2729 } |
| 2730 |
| 2731 Local<Value> GetComplexObjectWithDuplicate() { |
| 2732 Local<Value> wasm_module = MakeWasm(); |
| 2733 serialization_context() |
| 2734 ->Global() |
| 2735 ->CreateDataProperty(serialization_context(), |
| 2736 StringFromUtf8("wasm_module"), wasm_module) |
| 2737 .FromMaybe(false); |
| 2738 Local<Script> script = |
| 2739 Script::Compile( |
| 2740 serialization_context(), |
| 2741 StringFromUtf8("({mod1: wasm_module, num: 2, mod2: wasm_module})")) |
| 2742 .ToLocalChecked(); |
| 2743 return script->Run(serialization_context()).ToLocalChecked(); |
| 2744 } |
| 2745 |
| 2746 void VerifyComplexObject(Local<Value> value) { |
| 2747 ASSERT_TRUE(value->IsObject()); |
| 2748 EXPECT_TRUE(EvaluateScriptForResultBool( |
| 2749 "result.mod1 instanceof WebAssembly.Module")); |
| 2750 EXPECT_TRUE(EvaluateScriptForResultBool( |
| 2751 "result.mod2 instanceof WebAssembly.Module")); |
| 2752 EXPECT_TRUE(EvaluateScriptForResultBool("result.num === 2")); |
| 2753 } |
| 2754 |
| 2755 Local<Value> GetComplexObjectWithMany() { |
| 2756 Local<Value> wasm_module1 = MakeWasm(); |
| 2757 Local<Value> wasm_module2 = MakeWasm(); |
| 2758 serialization_context() |
| 2759 ->Global() |
| 2760 ->CreateDataProperty(serialization_context(), |
| 2761 StringFromUtf8("wasm_module1"), wasm_module1) |
| 2762 .FromMaybe(false); |
| 2763 serialization_context() |
| 2764 ->Global() |
| 2765 ->CreateDataProperty(serialization_context(), |
| 2766 StringFromUtf8("wasm_module2"), wasm_module2) |
| 2767 .FromMaybe(false); |
| 2768 Local<Script> script = |
| 2769 Script::Compile( |
| 2770 serialization_context(), |
| 2771 StringFromUtf8( |
| 2772 "({mod1: wasm_module1, num: 2, mod2: wasm_module2})")) |
| 2773 .ToLocalChecked(); |
| 2774 return script->Run(serialization_context()).ToLocalChecked(); |
| 2775 } |
| 2776 |
2611 private: | 2777 private: |
2612 static bool g_saved_flag; | 2778 static bool g_saved_flag; |
| 2779 std::vector<WasmCompiledModule::TransferrableModule> transfer_modules_; |
| 2780 SerializeToTransfer serialize_delegate_; |
| 2781 DeserializeFromTransfer deserialize_delegate_; |
| 2782 ValueSerializer::Delegate* current_serializer_delegate_ = nullptr; |
| 2783 ValueDeserializer::Delegate* current_deserializer_delegate_ = nullptr; |
| 2784 ThrowingSerializer throwing_serializer_; |
| 2785 ValueDeserializer::Delegate default_deserializer_; |
2613 }; | 2786 }; |
2614 | 2787 |
2615 bool ValueSerializerTestWithWasm::g_saved_flag = false; | 2788 bool ValueSerializerTestWithWasm::g_saved_flag = false; |
2616 | 2789 |
2617 // A simple module which exports an "increment" function. | 2790 // The default implementation of the serialization |
2618 // Copied from test/mjsunit/wasm/incrementer.wasm. | 2791 // delegate throws when trying to serialize wasm. The |
2619 const unsigned char kIncrementerWasm[] = { | 2792 // embedder must decide serialization policy. |
2620 0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 1, 127, 1, 127, | 2793 TEST_F(ValueSerializerTestWithWasm, DefaultSerializationDelegate) { |
2621 3, 2, 1, 0, 7, 13, 1, 9, 105, 110, 99, 114, 101, 109, 101, 110, | 2794 EnableThrowingSerializer(); |
2622 116, 0, 0, 10, 9, 1, 7, 0, 32, 0, 65, 1, 106, 11, | 2795 InvalidEncodeTest([this]() { return MakeWasm(); }, |
2623 }; | 2796 [](Local<Message> message) { |
2624 | 2797 ASSERT_TRUE(message->Get()->Length() > 0); |
2625 TEST_F(ValueSerializerTestWithWasm, RoundTripWasmModule) { | 2798 }); |
2626 RoundTripTest( | 2799 } |
2627 [this]() { | 2800 |
2628 return WasmCompiledModule::DeserializeOrCompile( | 2801 // The default deserializer throws if wasm transfer is attempted |
2629 isolate(), {nullptr, 0}, | 2802 TEST_F(ValueSerializerTestWithWasm, DefaultDeserializationDelegate) { |
2630 {kIncrementerWasm, sizeof(kIncrementerWasm)}) | 2803 EnableTransferSerialization(); |
2631 .ToLocalChecked(); | 2804 EnableDefaultDeserializer(); |
2632 }, | 2805 EncodeTest( |
2633 [this](Local<Value> value) { | 2806 [this]() { return MakeWasm(); }, |
2634 ASSERT_TRUE(value->IsWebAssemblyCompiledModule()); | 2807 [this](const std::vector<uint8_t>& data) { InvalidDecodeTest(data); }); |
2635 EXPECT_TRUE(EvaluateScriptForResultBool( | 2808 } |
2636 "new WebAssembly.Instance(result).exports.increment(8) === 9")); | 2809 |
2637 }); | 2810 // We only want to allow deserialization through |
2638 } | 2811 // transferred modules - which requres both serializer |
2639 | 2812 // and deserializer to understand that - or through |
| 2813 // explicitly allowing inlined data, which requires |
| 2814 // deserializer opt-in (we default the serializer to |
| 2815 // inlined data because we don't trust that data on the |
| 2816 // receiving end anyway). |
| 2817 |
| 2818 TEST_F(ValueSerializerTestWithWasm, RoundtripWasmTransfer) { |
| 2819 EnableTransferSerialization(); |
| 2820 EnableTransferDeserialization(); |
| 2821 ExpectPass(); |
| 2822 } |
| 2823 |
| 2824 TEST_F(ValueSerializerTestWithWasm, RountripWasmInline) { |
| 2825 SetExpectInlineWasm(true); |
| 2826 ExpectPass(); |
| 2827 } |
| 2828 |
| 2829 TEST_F(ValueSerializerTestWithWasm, CannotDeserializeWasmInlineData) { |
| 2830 ExpectFail(); |
| 2831 } |
| 2832 |
| 2833 TEST_F(ValueSerializerTestWithWasm, CannotTransferWasmWhenExpectingInline) { |
| 2834 EnableTransferSerialization(); |
| 2835 SetExpectInlineWasm(true); |
| 2836 ExpectFail(); |
| 2837 } |
| 2838 |
| 2839 TEST_F(ValueSerializerTestWithWasm, ComplexObjectDuplicateTransfer) { |
| 2840 EnableTransferSerialization(); |
| 2841 EnableTransferDeserialization(); |
| 2842 RoundTripTest( |
| 2843 [this]() { return GetComplexObjectWithDuplicate(); }, |
| 2844 [this](Local<Value> value) { |
| 2845 VerifyComplexObject(value); |
| 2846 EXPECT_TRUE(EvaluateScriptForResultBool("result.mod1 === result.mod2")); |
| 2847 }); |
| 2848 } |
| 2849 |
| 2850 TEST_F(ValueSerializerTestWithWasm, ComplexObjectDuplicateInline) { |
| 2851 SetExpectInlineWasm(true); |
| 2852 RoundTripTest( |
| 2853 [this]() { return GetComplexObjectWithDuplicate(); }, |
| 2854 [this](Local<Value> value) { |
| 2855 VerifyComplexObject(value); |
| 2856 EXPECT_TRUE(EvaluateScriptForResultBool("result.mod1 === result.mod2")); |
| 2857 }); |
| 2858 } |
| 2859 |
| 2860 TEST_F(ValueSerializerTestWithWasm, ComplexObjectWithManyTransfer) { |
| 2861 EnableTransferSerialization(); |
| 2862 EnableTransferDeserialization(); |
| 2863 RoundTripTest( |
| 2864 [this]() { return GetComplexObjectWithMany(); }, |
| 2865 [this](Local<Value> value) { |
| 2866 VerifyComplexObject(value); |
| 2867 EXPECT_TRUE(EvaluateScriptForResultBool("result.mod1 != result.mod2")); |
| 2868 }); |
| 2869 } |
| 2870 |
| 2871 TEST_F(ValueSerializerTestWithWasm, ComplexObjectWithManyInline) { |
| 2872 SetExpectInlineWasm(true); |
| 2873 RoundTripTest( |
| 2874 [this]() { return GetComplexObjectWithMany(); }, |
| 2875 [this](Local<Value> value) { |
| 2876 VerifyComplexObject(value); |
| 2877 EXPECT_TRUE(EvaluateScriptForResultBool("result.mod1 != result.mod2")); |
| 2878 }); |
| 2879 } |
| 2880 |
2640 // As produced around Chrome 56. | 2881 // As produced around Chrome 56. |
2641 const unsigned char kSerializedIncrementerWasm[] = { | 2882 const unsigned char kSerializedIncrementerWasm[] = { |
2642 0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x2d, 0x00, 0x61, 0x73, 0x6d, 0x0d, | 2883 0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x2d, 0x00, 0x61, 0x73, 0x6d, 0x0d, |
2643 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60, 0x01, 0x7f, 0x01, 0x7f, 0x03, | 2884 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60, 0x01, 0x7f, 0x01, 0x7f, 0x03, |
2644 0x02, 0x01, 0x00, 0x07, 0x0d, 0x01, 0x09, 0x69, 0x6e, 0x63, 0x72, 0x65, | 2885 0x02, 0x01, 0x00, 0x07, 0x0d, 0x01, 0x09, 0x69, 0x6e, 0x63, 0x72, 0x65, |
2645 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x00, 0x0a, 0x08, 0x01, 0x06, 0x00, 0x20, | 2886 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x00, 0x0a, 0x08, 0x01, 0x06, 0x00, 0x20, |
2646 0x00, 0x41, 0x01, 0x6a, 0xf8, 0x04, 0xa1, 0x06, 0xde, 0xc0, 0xc6, 0x44, | 2887 0x00, 0x41, 0x01, 0x6a, 0xf8, 0x04, 0xa1, 0x06, 0xde, 0xc0, 0xc6, 0x44, |
2647 0x3c, 0x29, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x02, 0x00, 0x00, 0x81, 0x4e, | 2888 0x3c, 0x29, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x02, 0x00, 0x00, 0x81, 0x4e, |
2648 0xce, 0x7c, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x30, 0x02, | 2889 0xce, 0x7c, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x30, 0x02, |
2649 0x00, 0x00, 0xb0, 0x25, 0x30, 0xe3, 0xf2, 0xdb, 0x2e, 0x48, 0x00, 0x00, | 2890 0x00, 0x00, 0xb0, 0x25, 0x30, 0xe3, 0xf2, 0xdb, 0x2e, 0x48, 0x00, 0x00, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2744 InvalidDecodeTest(raw); | 2985 InvalidDecodeTest(raw); |
2745 } | 2986 } |
2746 | 2987 |
2747 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) { | 2988 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) { |
2748 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00}); | 2989 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00}); |
2749 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f}); | 2990 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f}); |
2750 } | 2991 } |
2751 | 2992 |
2752 } // namespace | 2993 } // namespace |
2753 } // namespace v8 | 2994 } // namespace v8 |
OLD | NEW |