Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Unified Diff: test/cctest/wasm/test-run-wasm-module.cc

Issue 2395793003: [wasm] Support recompilation if deserialization fails. (Closed)
Patch Set: Feedback Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/api.cc ('K') | « src/snapshot/code-serializer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/wasm/test-run-wasm-module.cc
diff --git a/test/cctest/wasm/test-run-wasm-module.cc b/test/cctest/wasm/test-run-wasm-module.cc
index 3b30e56076a57854f81040c8eb04b560fac35552..0e5ff72130ae58d61369aea6cee67f4594f3e027 100644
--- a/test/cctest/wasm/test-run-wasm-module.cc
+++ b/test/cctest/wasm/test-run-wasm-module.cc
@@ -197,6 +197,8 @@ TEST(Run_WasmModule_Serialization) {
Isolate* isolate = CcTest::InitIsolateOnce();
ErrorThrower thrower(isolate, "");
+ uint8_t* bytes = nullptr;
+ int buffer_size = -1;
v8::WasmCompiledModule::SerializedModule data;
{
HandleScope scope(isolate);
@@ -217,6 +219,11 @@ TEST(Run_WasmModule_Serialization) {
v8::Local<v8::WasmCompiledModule> v8_compiled_module =
v8_module_obj.As<v8::WasmCompiledModule>();
+ v8::Local<v8::String> uncompiled_bytes =
+ v8_compiled_module->GetUncompiledBytes();
+ buffer_size = uncompiled_bytes->Length();
+ bytes = zone.NewArray<uint8_t>(buffer_size);
+ uncompiled_bytes->WriteOneByte(bytes);
data = v8_compiled_module->Serialize();
}
@@ -224,32 +231,44 @@ TEST(Run_WasmModule_Serialization) {
create_params.array_buffer_allocator =
CcTest::InitIsolateOnce()->array_buffer_allocator();
- v8::Isolate* v8_isolate = v8::Isolate::New(create_params);
- {
- v8::Isolate::Scope isolate_scope(v8_isolate);
- v8::HandleScope new_scope(v8_isolate);
- v8::Local<v8::Context> new_ctx = v8::Context::New(v8_isolate);
- new_ctx->Enter();
- isolate = reinterpret_cast<Isolate*>(v8_isolate);
- testing::SetupIsolateForWasmModule(isolate);
-
- v8::MaybeLocal<v8::WasmCompiledModule> deserialized =
- v8::WasmCompiledModule::Deserialize(v8_isolate, data);
- v8::Local<v8::WasmCompiledModule> compiled_module;
- CHECK(deserialized.ToLocal(&compiled_module));
- Handle<JSObject> module_object =
- Handle<JSObject>::cast(v8::Utils::OpenHandle(*compiled_module));
- Handle<JSObject> instance =
- WasmModule::Instantiate(isolate, &thrower, module_object,
- Handle<JSReceiver>::null(),
- Handle<JSArrayBuffer>::null())
- .ToHandleChecked();
- Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(41), isolate)};
- int32_t result = testing::CallWasmFunctionForTesting(
- isolate, instance, &thrower, kFunctionName, 1, params,
- ModuleOrigin::kWasmOrigin);
- CHECK(result == 42);
- new_ctx->Exit();
+ for (int i = 0; i < 2; ++i) {
+ v8::Isolate* v8_isolate = v8::Isolate::New(create_params);
+ if (i == 1) {
+ // Mess with the serialized data to force recompilation.
+ data.first.reset();
+ data.second = 0;
+ }
+ {
+ v8::Isolate::Scope isolate_scope(v8_isolate);
+ v8::HandleScope new_scope(v8_isolate);
+ v8::Local<v8::Context> new_ctx = v8::Context::New(v8_isolate);
+ new_ctx->Enter();
+ isolate = reinterpret_cast<Isolate*>(v8_isolate);
+ testing::SetupIsolateForWasmModule(isolate);
+ Vector<const uint8_t> raw(bytes, buffer_size);
+ v8::MaybeLocal<v8::WasmCompiledModule> deserialized =
+ v8::WasmCompiledModule::DeserializeOrCompile(
+ v8_isolate, data,
+ v8::Utils::ToLocal(isolate->factory()
+ ->NewStringFromOneByte(raw)
+ .ToHandleChecked()));
+ v8::Local<v8::WasmCompiledModule> compiled_module;
+ CHECK(deserialized.ToLocal(&compiled_module));
+ Handle<JSObject> module_object =
+ Handle<JSObject>::cast(v8::Utils::OpenHandle(*compiled_module));
+ Handle<JSObject> instance =
+ WasmModule::Instantiate(isolate, &thrower, module_object,
+ Handle<JSReceiver>::null(),
+ Handle<JSArrayBuffer>::null())
+ .ToHandleChecked();
+ Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(41), isolate)};
+ int32_t result = testing::CallWasmFunctionForTesting(
+ isolate, instance, &thrower, kFunctionName, 1, params,
+ ModuleOrigin::kWasmOrigin);
+ CHECK(result == 42);
+ new_ctx->Exit();
+ }
+ v8_isolate->Dispose();
}
}
« src/api.cc ('K') | « src/snapshot/code-serializer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698