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

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

Issue 2404673002: [wasm] Avoid copying when deserializing wasm (Closed)
Patch Set: 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
« no previous file with comments | « src/api.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 0e5ff72130ae58d61369aea6cee67f4594f3e027..dd6e05be63ebcb7253bed03ee0d141a14f3ee5cd 100644
--- a/test/cctest/wasm/test-run-wasm-module.cc
+++ b/test/cctest/wasm/test-run-wasm-module.cc
@@ -198,7 +198,7 @@ TEST(Run_WasmModule_Serialization) {
Isolate* isolate = CcTest::InitIsolateOnce();
ErrorThrower thrower(isolate, "");
uint8_t* bytes = nullptr;
- int buffer_size = -1;
+ size_t bytes_size = 0;
v8::WasmCompiledModule::SerializedModule data;
{
HandleScope scope(isolate);
@@ -221,12 +221,16 @@ TEST(Run_WasmModule_Serialization) {
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);
+ bytes_size = static_cast<size_t>(uncompiled_bytes->Length());
+ bytes = zone.NewArray<uint8_t>(uncompiled_bytes->Length());
uncompiled_bytes->WriteOneByte(bytes);
data = v8_compiled_module->Serialize();
}
+ v8::WasmCompiledModule::UncompiledBytes uncompressed_bytes = {
+ std::unique_ptr<const uint8_t[]>(const_cast<const uint8_t*>(bytes)),
+ bytes_size};
+
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator =
CcTest::InitIsolateOnce()->array_buffer_allocator();
@@ -245,13 +249,9 @@ TEST(Run_WasmModule_Serialization) {
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::WasmCompiledModule::DeserializeOrCompile(v8_isolate, data,
+ uncompressed_bytes);
v8::Local<v8::WasmCompiledModule> compiled_module;
CHECK(deserialized.ToLocal(&compiled_module));
Handle<JSObject> module_object =
@@ -270,6 +270,9 @@ TEST(Run_WasmModule_Serialization) {
}
v8_isolate->Dispose();
}
+ // Release, because we allocated the bytes with the zone allocator, and
+ // that doesn't have a delete.
+ uncompressed_bytes.first.release();
}
TEST(MemorySize) {
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698