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/objects-inl.h" | 8 #include "src/objects-inl.h" |
9 #include "src/snapshot/code-serializer.h" | 9 #include "src/snapshot/code-serializer.h" |
10 #include "src/version.h" | 10 #include "src/version.h" |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 { | 462 { |
463 HandleScope scope(test.current_isolate()); | 463 HandleScope scope(test.current_isolate()); |
464 test.current_isolate_v8()->SetAllowCodeGenerationFromStringsCallback(False); | 464 test.current_isolate_v8()->SetAllowCodeGenerationFromStringsCallback(False); |
465 v8::MaybeLocal<v8::WasmCompiledModule> nothing = test.Deserialize(); | 465 v8::MaybeLocal<v8::WasmCompiledModule> nothing = test.Deserialize(); |
466 CHECK(nothing.IsEmpty()); | 466 CHECK(nothing.IsEmpty()); |
467 } | 467 } |
468 Cleanup(test.current_isolate()); | 468 Cleanup(test.current_isolate()); |
469 Cleanup(); | 469 Cleanup(); |
470 } | 470 } |
471 | 471 |
| 472 TEST(TransferrableWasmModules) { |
| 473 v8::internal::AccountingAllocator allocator; |
| 474 Zone zone(&allocator, ZONE_NAME); |
| 475 |
| 476 ZoneBuffer buffer(&zone); |
| 477 WasmSerializationTest::BuildWireBytes(&zone, &buffer); |
| 478 |
| 479 Isolate* from_isolate = CcTest::InitIsolateOnce(); |
| 480 ErrorThrower thrower(from_isolate, ""); |
| 481 std::vector<v8::WasmCompiledModule::TransferrableModule> store; |
| 482 { |
| 483 HandleScope scope(from_isolate); |
| 484 testing::SetupIsolateForWasmModule(from_isolate); |
| 485 |
| 486 MaybeHandle<WasmModuleObject> module_object = SyncCompile( |
| 487 from_isolate, &thrower, ModuleWireBytes(buffer.begin(), buffer.end())); |
| 488 v8::Local<v8::WasmCompiledModule> v8_module = |
| 489 v8::Local<v8::WasmCompiledModule>::Cast(v8::Utils::ToLocal( |
| 490 Handle<JSObject>::cast(module_object.ToHandleChecked()))); |
| 491 store.push_back(v8_module->AsTransferrableModule()); |
| 492 } |
| 493 |
| 494 { |
| 495 v8::Isolate::CreateParams create_params; |
| 496 create_params.array_buffer_allocator = |
| 497 from_isolate->array_buffer_allocator(); |
| 498 v8::Isolate* to_isolate = v8::Isolate::New(create_params); |
| 499 v8::HandleScope new_scope(to_isolate); |
| 500 v8::Local<v8::Context> deserialization_context = |
| 501 v8::Context::New(to_isolate); |
| 502 deserialization_context->Enter(); |
| 503 v8::MaybeLocal<v8::WasmCompiledModule> mod = |
| 504 v8::WasmCompiledModule::FromTransferrableModule(to_isolate, store[0]); |
| 505 CHECK(!mod.IsEmpty()); |
| 506 } |
| 507 } |
| 508 |
472 TEST(MemorySize) { | 509 TEST(MemorySize) { |
473 { | 510 { |
474 // Initial memory size is 16, see wasm-module-builder.cc | 511 // Initial memory size is 16, see wasm-module-builder.cc |
475 static const int kExpectedValue = 16; | 512 static const int kExpectedValue = 16; |
476 TestSignatures sigs; | 513 TestSignatures sigs; |
477 v8::internal::AccountingAllocator allocator; | 514 v8::internal::AccountingAllocator allocator; |
478 Zone zone(&allocator, ZONE_NAME); | 515 Zone zone(&allocator, ZONE_NAME); |
479 | 516 |
480 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 517 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
481 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 518 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 }; | 1004 }; |
968 | 1005 |
969 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data, | 1006 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data, |
970 data + arraysize(data), | 1007 data + arraysize(data), |
971 ModuleOrigin::kWasmOrigin); | 1008 ModuleOrigin::kWasmOrigin); |
972 // It should not be possible to instantiate this module. | 1009 // It should not be possible to instantiate this module. |
973 CHECK(thrower.error()); | 1010 CHECK(thrower.error()); |
974 } | 1011 } |
975 Cleanup(); | 1012 Cleanup(); |
976 } | 1013 } |
OLD | NEW |