| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 "test/unittests/test-utils.h" | 5 #include "test/unittests/test-utils.h" |
| 6 | 6 |
| 7 #include "src/handles.h" | 7 #include "src/handles.h" |
| 8 #include "src/objects-inl.h" | 8 #include "src/objects-inl.h" |
| 9 #include "src/wasm/module-decoder.h" | 9 #include "src/wasm/module-decoder.h" |
| 10 #include "src/wasm/wasm-limits.h" | 10 #include "src/wasm/wasm-limits.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 public: | 134 public: |
| 135 ModuleResult DecodeModule(const byte* module_start, const byte* module_end) { | 135 ModuleResult DecodeModule(const byte* module_start, const byte* module_end) { |
| 136 // Add the wasm magic and version number automatically. | 136 // Add the wasm magic and version number automatically. |
| 137 size_t size = static_cast<size_t>(module_end - module_start); | 137 size_t size = static_cast<size_t>(module_end - module_start); |
| 138 byte header[] = {WASM_MODULE_HEADER}; | 138 byte header[] = {WASM_MODULE_HEADER}; |
| 139 size_t total = sizeof(header) + size; | 139 size_t total = sizeof(header) + size; |
| 140 auto temp = new byte[total]; | 140 auto temp = new byte[total]; |
| 141 memcpy(temp, header, sizeof(header)); | 141 memcpy(temp, header, sizeof(header)); |
| 142 memcpy(temp + sizeof(header), module_start, size); | 142 memcpy(temp + sizeof(header), module_start, size); |
| 143 ModuleResult result = | 143 ModuleResult result = |
| 144 DecodeWasmModule(isolate(), temp, temp + total, false, kWasmOrigin); | 144 SyncDecodeWasmModule(isolate(), temp, temp + total, false, kWasmOrigin); |
| 145 delete[] temp; | 145 delete[] temp; |
| 146 return result; | 146 return result; |
| 147 } | 147 } |
| 148 ModuleResult DecodeModuleNoHeader(const byte* module_start, | 148 ModuleResult DecodeModuleNoHeader(const byte* module_start, |
| 149 const byte* module_end) { | 149 const byte* module_end) { |
| 150 return DecodeWasmModule(isolate(), module_start, module_end, false, | 150 return SyncDecodeWasmModule(isolate(), module_start, module_end, false, |
| 151 kWasmOrigin); | 151 kWasmOrigin); |
| 152 } | 152 } |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 TEST_F(WasmModuleVerifyTest, WrongMagic) { | 155 TEST_F(WasmModuleVerifyTest, WrongMagic) { |
| 156 for (uint32_t x = 1; x; x <<= 1) { | 156 for (uint32_t x = 1; x; x <<= 1) { |
| 157 const byte data[] = {U32_LE(kWasmMagic ^ x), U32_LE(kWasmVersion)}; | 157 const byte data[] = {U32_LE(kWasmMagic ^ x), U32_LE(kWasmVersion)}; |
| 158 ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data)); | 158 ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data)); |
| 159 EXPECT_FALSE(result.ok()); | 159 EXPECT_FALSE(result.ok()); |
| 160 } | 160 } |
| 161 } | 161 } |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 kLocalI32, // -- | 917 kLocalI32, // -- |
| 918 4, | 918 4, |
| 919 kLocalI64, // -- | 919 kLocalI64, // -- |
| 920 5, | 920 5, |
| 921 kLocalF32, // -- | 921 kLocalF32, // -- |
| 922 6, | 922 6, |
| 923 kLocalF64, // -- | 923 kLocalF64, // -- |
| 924 kExprEnd // body | 924 kExprEnd // body |
| 925 }; | 925 }; |
| 926 | 926 |
| 927 FunctionResult result = DecodeWasmFunction(isolate(), zone(), get_env(), data, | 927 FunctionResult result = SyncDecodeWasmFunction(isolate(), zone(), get_env(), |
| 928 data + sizeof(data)); | 928 data, data + sizeof(data)); |
| 929 EXPECT_OK(result); | 929 EXPECT_OK(result); |
| 930 | 930 |
| 931 if (result.val && result.ok()) { | 931 if (result.val && result.ok()) { |
| 932 WasmFunction* function = result.val.get(); | 932 WasmFunction* function = result.val.get(); |
| 933 EXPECT_EQ(0u, function->sig->parameter_count()); | 933 EXPECT_EQ(0u, function->sig->parameter_count()); |
| 934 EXPECT_EQ(0u, function->sig->return_count()); | 934 EXPECT_EQ(0u, function->sig->return_count()); |
| 935 EXPECT_EQ(0u, function->name_offset); | 935 EXPECT_EQ(0u, function->name_offset); |
| 936 EXPECT_EQ(static_cast<uint32_t>(SIZEOF_SIG_ENTRY_v_v), | 936 EXPECT_EQ(static_cast<uint32_t>(SIZEOF_SIG_ENTRY_v_v), |
| 937 function->code_start_offset); | 937 function->code_start_offset); |
| 938 EXPECT_EQ(sizeof(data), function->code_end_offset); | 938 EXPECT_EQ(sizeof(data), function->code_end_offset); |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1595 {19, 20, 1, 21, 2, 4}, // -- | 1595 {19, 20, 1, 21, 2, 4}, // -- |
| 1596 {29, 30, 5, 35, 2, 8}, // -- | 1596 {29, 30, 5, 35, 2, 8}, // -- |
| 1597 }; | 1597 }; |
| 1598 | 1598 |
| 1599 CheckSections(data, data + sizeof(data), expected, arraysize(expected)); | 1599 CheckSections(data, data + sizeof(data), expected, arraysize(expected)); |
| 1600 } | 1600 } |
| 1601 | 1601 |
| 1602 } // namespace wasm | 1602 } // namespace wasm |
| 1603 } // namespace internal | 1603 } // namespace internal |
| 1604 } // namespace v8 | 1604 } // namespace v8 |
| OLD | NEW |