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->GetTransferrableModule()); | |
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 | |
509 TEST(MemorySize) { | 472 TEST(MemorySize) { |
510 { | 473 { |
511 // Initial memory size is 16, see wasm-module-builder.cc | 474 // Initial memory size is 16, see wasm-module-builder.cc |
512 static const int kExpectedValue = 16; | 475 static const int kExpectedValue = 16; |
513 TestSignatures sigs; | 476 TestSignatures sigs; |
514 v8::internal::AccountingAllocator allocator; | 477 v8::internal::AccountingAllocator allocator; |
515 Zone zone(&allocator, ZONE_NAME); | 478 Zone zone(&allocator, ZONE_NAME); |
516 | 479 |
517 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 480 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
518 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 481 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 ModuleOrigin::kWasmOrigin); | 1032 ModuleOrigin::kWasmOrigin); |
1070 CHECK_EQ(kExpectedValue, result); | 1033 CHECK_EQ(kExpectedValue, result); |
1071 // Free the buffer as the tracker does not know about it. | 1034 // Free the buffer as the tracker does not know about it. |
1072 if (!memory->has_guard_region()) { | 1035 if (!memory->has_guard_region()) { |
1073 isolate->array_buffer_allocator()->Free( | 1036 isolate->array_buffer_allocator()->Free( |
1074 memory->backing_store(), NumberToSize(memory->byte_length())); | 1037 memory->backing_store(), NumberToSize(memory->byte_length())); |
1075 } | 1038 } |
1076 } | 1039 } |
1077 Cleanup(); | 1040 Cleanup(); |
1078 } | 1041 } |
OLD | NEW |