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 <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include "src/wasm/module-decoder.h" | 8 #include "src/wasm/module-decoder.h" |
9 #include "src/wasm/wasm-macro-gen.h" | 9 #include "src/wasm/wasm-macro-gen.h" |
10 #include "src/wasm/wasm-module-builder.h" | 10 #include "src/wasm/wasm-module-builder.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 Isolate* isolate = CcTest::InitIsolateOnce(); | 190 Isolate* isolate = CcTest::InitIsolateOnce(); |
191 ErrorThrower thrower(isolate, ""); | 191 ErrorThrower thrower(isolate, ""); |
192 uint8_t* bytes = nullptr; | 192 uint8_t* bytes = nullptr; |
193 size_t bytes_size = 0; | 193 size_t bytes_size = 0; |
194 v8::WasmCompiledModule::SerializedModule data; | 194 v8::WasmCompiledModule::SerializedModule data; |
195 { | 195 { |
196 HandleScope scope(isolate); | 196 HandleScope scope(isolate); |
197 testing::SetupIsolateForWasmModule(isolate); | 197 testing::SetupIsolateForWasmModule(isolate); |
198 | 198 |
199 ModuleResult decoding_result = DecodeWasmModule( | 199 ModuleResult decoding_result = DecodeWasmModule( |
200 isolate, &zone, buffer.begin(), buffer.end(), false, kWasmOrigin); | 200 isolate, buffer.begin(), buffer.end(), false, kWasmOrigin); |
201 std::unique_ptr<const WasmModule> module(decoding_result.val); | 201 if (decoding_result.failed()) { |
202 CHECK(!decoding_result.failed()); | 202 delete decoding_result.val; |
203 | 203 CHECK(false); |
| 204 } |
| 205 WasmModule* module = const_cast<WasmModule*>(decoding_result.val); |
| 206 Handle<WasmModuleWrapper> module_wrapper = |
| 207 WasmModuleWrapper::New(isolate, module); |
204 MaybeHandle<WasmCompiledModule> compiled_module = | 208 MaybeHandle<WasmCompiledModule> compiled_module = |
205 module->CompileFunctions(isolate, &thrower); | 209 module->CompileFunctions(isolate, module_wrapper, &thrower); |
206 CHECK(!compiled_module.is_null()); | 210 CHECK(!compiled_module.is_null()); |
207 Handle<JSObject> module_obj = CreateCompiledModuleObject( | 211 Handle<JSObject> module_obj = CreateWasmModuleObject( |
208 isolate, compiled_module.ToHandleChecked(), ModuleOrigin::kWasmOrigin); | 212 isolate, compiled_module.ToHandleChecked(), ModuleOrigin::kWasmOrigin); |
209 v8::Local<v8::Object> v8_module_obj = v8::Utils::ToLocal(module_obj); | 213 v8::Local<v8::Object> v8_module_obj = v8::Utils::ToLocal(module_obj); |
210 CHECK(v8_module_obj->IsWebAssemblyCompiledModule()); | 214 CHECK(v8_module_obj->IsWebAssemblyCompiledModule()); |
211 | 215 |
212 v8::Local<v8::WasmCompiledModule> v8_compiled_module = | 216 v8::Local<v8::WasmCompiledModule> v8_compiled_module = |
213 v8_module_obj.As<v8::WasmCompiledModule>(); | 217 v8_module_obj.As<v8::WasmCompiledModule>(); |
214 v8::Local<v8::String> uncompiled_bytes = | 218 v8::Local<v8::String> uncompiled_bytes = |
215 v8_compiled_module->GetWasmWireBytes(); | 219 v8_compiled_module->GetWasmWireBytes(); |
216 bytes_size = static_cast<size_t>(uncompiled_bytes->Length()); | 220 bytes_size = static_cast<size_t>(uncompiled_bytes->Length()); |
217 bytes = zone.NewArray<uint8_t>(uncompiled_bytes->Length()); | 221 bytes = zone.NewArray<uint8_t>(uncompiled_bytes->Length()); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 WASM_I32V(121)}; | 371 WASM_I32V(121)}; |
368 f->EmitCode(code, sizeof(code)); | 372 f->EmitCode(code, sizeof(code)); |
369 ZoneBuffer buffer(&zone); | 373 ZoneBuffer buffer(&zone); |
370 builder->WriteTo(buffer); | 374 builder->WriteTo(buffer); |
371 | 375 |
372 HandleScope scope(isolate); | 376 HandleScope scope(isolate); |
373 testing::SetupIsolateForWasmModule(isolate); | 377 testing::SetupIsolateForWasmModule(isolate); |
374 ErrorThrower thrower(isolate, "Test"); | 378 ErrorThrower thrower(isolate, "Test"); |
375 const Handle<JSObject> instance = | 379 const Handle<JSObject> instance = |
376 testing::CompileInstantiateWasmModuleForTesting( | 380 testing::CompileInstantiateWasmModuleForTesting( |
377 isolate, &thrower, &zone, buffer.begin(), buffer.end(), | 381 isolate, &thrower, buffer.begin(), buffer.end(), |
378 ModuleOrigin::kWasmOrigin); | 382 ModuleOrigin::kWasmOrigin); |
379 CHECK(!instance.is_null()); | 383 CHECK(!instance.is_null()); |
380 | 384 |
381 MaybeHandle<JSArrayBuffer> maybe_memory = | 385 MaybeHandle<JSArrayBuffer> maybe_memory = |
382 GetInstanceMemory(isolate, instance); | 386 GetInstanceMemory(isolate, instance); |
383 Handle<JSArrayBuffer> memory = maybe_memory.ToHandleChecked(); | 387 Handle<JSArrayBuffer> memory = maybe_memory.ToHandleChecked(); |
384 int32_t* memory_array = reinterpret_cast<int32_t*>(memory->backing_store()); | 388 int32_t* memory_array = reinterpret_cast<int32_t*>(memory->backing_store()); |
385 | 389 |
386 InterruptThread thread(isolate, memory_array); | 390 InterruptThread thread(isolate, memory_array); |
387 thread.Start(); | 391 thread.Start(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V(index))}; | 445 WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V(index))}; |
442 f->EmitCode(code, sizeof(code)); | 446 f->EmitCode(code, sizeof(code)); |
443 | 447 |
444 HandleScope scope(isolate); | 448 HandleScope scope(isolate); |
445 ZoneBuffer buffer(&zone); | 449 ZoneBuffer buffer(&zone); |
446 builder->WriteTo(buffer); | 450 builder->WriteTo(buffer); |
447 testing::SetupIsolateForWasmModule(isolate); | 451 testing::SetupIsolateForWasmModule(isolate); |
448 | 452 |
449 ErrorThrower thrower(isolate, "Test"); | 453 ErrorThrower thrower(isolate, "Test"); |
450 Handle<JSObject> instance = testing::CompileInstantiateWasmModuleForTesting( | 454 Handle<JSObject> instance = testing::CompileInstantiateWasmModuleForTesting( |
451 isolate, &thrower, &zone, buffer.begin(), buffer.end(), | 455 isolate, &thrower, buffer.begin(), buffer.end(), |
452 ModuleOrigin::kWasmOrigin); | 456 ModuleOrigin::kWasmOrigin); |
453 CHECK(!instance.is_null()); | 457 CHECK(!instance.is_null()); |
454 | 458 |
455 // Initial memory size is 16 pages, should trap till index > MemSize on | 459 // Initial memory size is 16 pages, should trap till index > MemSize on |
456 // consecutive GrowMem calls | 460 // consecutive GrowMem calls |
457 for (uint32_t i = 1; i < 5; i++) { | 461 for (uint32_t i = 1; i < 5; i++) { |
458 Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(i), isolate)}; | 462 Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(i), isolate)}; |
459 v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate)); | 463 v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate)); |
460 testing::RunWasmModuleForTesting(isolate, instance, 1, params, | 464 testing::RunWasmModuleForTesting(isolate, instance, 1, params, |
461 ModuleOrigin::kWasmOrigin); | 465 ModuleOrigin::kWasmOrigin); |
(...skipping 24 matching lines...) Expand all Loading... |
486 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))}; | 490 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))}; |
487 f->EmitCode(code, sizeof(code)); | 491 f->EmitCode(code, sizeof(code)); |
488 | 492 |
489 HandleScope scope(isolate); | 493 HandleScope scope(isolate); |
490 ZoneBuffer buffer(&zone); | 494 ZoneBuffer buffer(&zone); |
491 builder->WriteTo(buffer); | 495 builder->WriteTo(buffer); |
492 testing::SetupIsolateForWasmModule(isolate); | 496 testing::SetupIsolateForWasmModule(isolate); |
493 | 497 |
494 ErrorThrower thrower(isolate, "Test"); | 498 ErrorThrower thrower(isolate, "Test"); |
495 Handle<JSObject> instance = testing::CompileInstantiateWasmModuleForTesting( | 499 Handle<JSObject> instance = testing::CompileInstantiateWasmModuleForTesting( |
496 isolate, &thrower, &zone, buffer.begin(), buffer.end(), | 500 isolate, &thrower, buffer.begin(), buffer.end(), |
497 ModuleOrigin::kWasmOrigin); | 501 ModuleOrigin::kWasmOrigin); |
498 | 502 |
499 CHECK(!instance.is_null()); | 503 CHECK(!instance.is_null()); |
500 | 504 |
501 // Initial memory size is 16 pages, should trap till index > MemSize on | 505 // Initial memory size is 16 pages, should trap till index > MemSize on |
502 // consecutive GrowMem calls | 506 // consecutive GrowMem calls |
503 for (int i = 1; i < 5; i++) { | 507 for (int i = 1; i < 5; i++) { |
504 Handle<Object> params[1] = { | 508 Handle<Object> params[1] = { |
505 Handle<Object>(Smi::FromInt((16 + i) * kPageSize - 3), isolate)}; | 509 Handle<Object>(Smi::FromInt((16 + i) * kPageSize - 3), isolate)}; |
506 v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate)); | 510 v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate)); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 | 614 |
611 TEST(Run_WasmModule_Global_f32) { | 615 TEST(Run_WasmModule_Global_f32) { |
612 RunWasmModuleGlobalInitTest<float>(kAstF32, -983.9f); | 616 RunWasmModuleGlobalInitTest<float>(kAstF32, -983.9f); |
613 RunWasmModuleGlobalInitTest<float>(kAstF32, 1122.99f); | 617 RunWasmModuleGlobalInitTest<float>(kAstF32, 1122.99f); |
614 } | 618 } |
615 | 619 |
616 TEST(Run_WasmModule_Global_f64) { | 620 TEST(Run_WasmModule_Global_f64) { |
617 RunWasmModuleGlobalInitTest<double>(kAstF64, -833.9); | 621 RunWasmModuleGlobalInitTest<double>(kAstF64, -833.9); |
618 RunWasmModuleGlobalInitTest<double>(kAstF64, 86374.25); | 622 RunWasmModuleGlobalInitTest<double>(kAstF64, 86374.25); |
619 } | 623 } |
OLD | NEW |