Commit a184598f authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Deprecate unused {DeserializeOrCompile} API

This API was used for IndexedDB support and for transferring modules by
serializing and deserializing (before we were sharing code between
isolates). Last uses were removed in https://crrev.com/c/1847366, thus
this whole API is unused by now.
This CL deprecates the API and refactors tests to use the internal APIs
instead.

R=adamk@chromium.org

Bug: v8:10146
Change-Id: I838039b4be7ea4eebe6769f31f48e51e7bcd4645
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2006090
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65908}
parent bb278115
...@@ -4780,9 +4780,13 @@ class V8_EXPORT WasmModuleObject : public Object { ...@@ -4780,9 +4780,13 @@ class V8_EXPORT WasmModuleObject : public Object {
* If possible, deserialize the module, otherwise compile it from the provided * If possible, deserialize the module, otherwise compile it from the provided
* uncompiled bytes. * uncompiled bytes.
*/ */
V8_DEPRECATED(
"Use WasmStreaming for deserialization from cache or the "
"CompiledWasmModule to transfer between isolates")
static MaybeLocal<WasmModuleObject> DeserializeOrCompile( static MaybeLocal<WasmModuleObject> DeserializeOrCompile(
Isolate* isolate, MemorySpan<const uint8_t> serialized_module, Isolate* isolate, MemorySpan<const uint8_t> serialized_module,
MemorySpan<const uint8_t> wire_bytes); MemorySpan<const uint8_t> wire_bytes);
V8_INLINE static WasmModuleObject* Cast(Value* obj); V8_INLINE static WasmModuleObject* Cast(Value* obj);
private: private:
......
...@@ -664,8 +664,8 @@ DEFINE_DEBUG_BOOL(trace_wasm_native_heap, false, ...@@ -664,8 +664,8 @@ DEFINE_DEBUG_BOOL(trace_wasm_native_heap, false,
"trace wasm native heap events") "trace wasm native heap events")
DEFINE_BOOL(wasm_write_protect_code_memory, false, DEFINE_BOOL(wasm_write_protect_code_memory, false,
"write protect code memory on the wasm native heap") "write protect code memory on the wasm native heap")
DEFINE_BOOL(trace_wasm_serialization, false, DEFINE_DEBUG_BOOL(trace_wasm_serialization, false,
"trace serialization/deserialization") "trace serialization/deserialization")
DEFINE_BOOL(wasm_async_compilation, true, DEFINE_BOOL(wasm_async_compilation, true,
"enable actual asynchronous compilation for WebAssembly.compile") "enable actual asynchronous compilation for WebAssembly.compile")
DEFINE_BOOL(wasm_test_streaming, false, DEFINE_BOOL(wasm_test_streaming, false,
......
...@@ -127,24 +127,6 @@ TEST(WasmStreamingAbortWithoutReject) { ...@@ -127,24 +127,6 @@ TEST(WasmStreamingAbortWithoutReject) {
v8::Promise::kPending); v8::Promise::kPending);
} }
TEST(WasmModuleObjectCompileFailure) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
{
v8::TryCatch try_catch(isolate);
uint8_t buffer[] = {0xDE, 0xAD, 0xBE, 0xEF};
v8::MemorySpan<const uint8_t> serialized_module;
v8::MemorySpan<const uint8_t> wire_bytes = {buffer, arraysize(buffer)};
v8::MaybeLocal<v8::WasmModuleObject> maybe_module =
v8::WasmModuleObject::DeserializeOrCompile(isolate, serialized_module,
wire_bytes);
CHECK(maybe_module.IsEmpty());
CHECK(try_catch.HasCaught());
}
}
namespace { namespace {
bool wasm_threads_enabled_value = false; bool wasm_threads_enabled_value = false;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
// change the isolate in terms of callbacks allow_code_gen_callback and // change the isolate in terms of callbacks allow_code_gen_callback and
// allow_wasm_code_gen_callback. // allow_wasm_code_gen_callback.
#include "src/api/api-inl.h"
#include "src/wasm/wasm-module-builder.h" #include "src/wasm/wasm-module-builder.h"
#include "src/wasm/wasm-objects-inl.h" #include "src/wasm/wasm-objects-inl.h"
#include "src/wasm/wasm-objects.h" #include "src/wasm/wasm-objects.h"
...@@ -59,13 +60,37 @@ void BuildTrivialModule(Zone* zone, ZoneBuffer* buffer) { ...@@ -59,13 +60,37 @@ void BuildTrivialModule(Zone* zone, ZoneBuffer* buffer) {
bool TestModule(Isolate* isolate, v8::MemorySpan<const uint8_t> wire_bytes) { bool TestModule(Isolate* isolate, v8::MemorySpan<const uint8_t> wire_bytes) {
HandleScope scope(isolate); HandleScope scope(isolate);
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
v8::MemorySpan<const uint8_t> serialized_module; v8::Local<v8::Context> context =
MaybeLocal<v8::WasmModuleObject> module = Utils::ToLocal(Handle<Context>::cast(isolate->native_context()));
v8::WasmModuleObject::DeserializeOrCompile(
reinterpret_cast<v8::Isolate*>(isolate), serialized_module, // Get the "WebAssembly.Module" function.
wire_bytes); auto get_property = [context, v8_isolate](
return !module.IsEmpty(); v8::Local<v8::Object> obj,
const char* property_name) -> v8::Local<v8::Object> {
auto name = v8::String::NewFromUtf8(v8_isolate, property_name,
NewStringType::kInternalized)
.ToLocalChecked();
return obj->Get(context, name).ToLocalChecked().As<v8::Object>();
};
auto wasm_class = get_property(context->Global(), "WebAssembly");
auto module_class = get_property(wasm_class, "Module");
// Create an arraybuffer with the wire bytes.
v8::Local<v8::ArrayBuffer> buf =
v8::ArrayBuffer::New(v8_isolate, wire_bytes.size());
memcpy(static_cast<uint8_t*>(buf->GetBackingStore()->Data()),
wire_bytes.data(), wire_bytes.size());
// Now call the "WebAssembly.Module" function with the array buffer. Return
// true if this succeeded, false otherwise.
v8::TryCatch try_catch(v8_isolate);
v8::Local<v8::Value> args[] = {buf};
MaybeLocal<Value> module_object =
module_class->CallAsConstructor(context, arraysize(args), args);
CHECK_EQ(try_catch.HasCaught(), module_object.IsEmpty());
return !module_object.IsEmpty();
} }
} // namespace } // namespace
...@@ -78,7 +103,6 @@ TEST(PropertiesOfCodegenCallbacks) { ...@@ -78,7 +103,6 @@ TEST(PropertiesOfCodegenCallbacks) {
v8::MemorySpan<const uint8_t> wire_bytes = {buffer.begin(), buffer.size()}; v8::MemorySpan<const uint8_t> wire_bytes = {buffer.begin(), buffer.size()};
Isolate* isolate = CcTest::InitIsolateOnce(); Isolate* isolate = CcTest::InitIsolateOnce();
HandleScope scope(isolate); HandleScope scope(isolate);
testing::SetupIsolateForWasmModule(isolate);
for (TestValue codegen : AllTestValues) { for (TestValue codegen : AllTestValues) {
for (TestValue wasm_codegen : AllTestValues) { for (TestValue wasm_codegen : AllTestValues) {
...@@ -94,6 +118,15 @@ TEST(PropertiesOfCodegenCallbacks) { ...@@ -94,6 +118,15 @@ TEST(PropertiesOfCodegenCallbacks) {
} }
} }
TEST(WasmModuleObjectCompileFailure) {
const uint8_t wire_bytes_arr[] = {0xDE, 0xAD, 0xBE, 0xEF};
v8::MemorySpan<const uint8_t> wire_bytes = {wire_bytes_arr,
arraysize(wire_bytes_arr)};
Isolate* isolate = CcTest::InitIsolateOnce();
HandleScope scope(isolate);
CHECK(!TestModule(isolate, wire_bytes));
}
} // namespace wasm } // namespace wasm
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "src/objects/backing-store.h" #include "src/objects/backing-store.h"
#include "src/objects/objects-inl.h" #include "src/objects/objects-inl.h"
#include "src/wasm/wasm-objects.h" #include "src/wasm/wasm-objects.h"
#include "src/wasm/wasm-result.h"
#include "test/unittests/test-utils.h" #include "test/unittests/test-utils.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -2453,7 +2454,7 @@ TEST_F(ValueSerializerTestWithHostArrayBufferView, RoundTripUint8ArrayInput) { ...@@ -2453,7 +2454,7 @@ TEST_F(ValueSerializerTestWithHostArrayBufferView, RoundTripUint8ArrayInput) {
// A simple module which exports an "increment" function. // A simple module which exports an "increment" function.
// Copied from test/mjsunit/wasm/incrementer.wasm. // Copied from test/mjsunit/wasm/incrementer.wasm.
const unsigned char kIncrementerWasm[] = { constexpr uint8_t kIncrementerWasm[] = {
0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 1, 127, 1, 127, 0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 1, 127, 1, 127,
3, 2, 1, 0, 7, 13, 1, 9, 105, 110, 99, 114, 101, 109, 101, 110, 3, 2, 1, 0, 7, 13, 1, 9, 105, 110, 99, 114, 101, 109, 101, 110,
116, 0, 0, 10, 9, 1, 7, 0, 32, 0, 65, 1, 106, 11, 116, 0, 0, 10, 9, 1, 7, 0, 32, 0, 65, 1, 106, 11,
...@@ -2558,10 +2559,15 @@ class ValueSerializerTestWithWasm : public ValueSerializerTest { ...@@ -2558,10 +2559,15 @@ class ValueSerializerTestWithWasm : public ValueSerializerTest {
Local<WasmModuleObject> MakeWasm() { Local<WasmModuleObject> MakeWasm() {
Context::Scope scope(serialization_context()); Context::Scope scope(serialization_context());
return WasmModuleObject::DeserializeOrCompile( i::wasm::ErrorThrower thrower(i_isolate(), "MakeWasm");
isolate(), {nullptr, 0}, auto enabled_features = i::wasm::WasmFeatures::FromIsolate(i_isolate());
{kIncrementerWasm, sizeof(kIncrementerWasm)}) i::MaybeHandle<i::JSObject> compiled =
.ToLocalChecked(); i_isolate()->wasm_engine()->SyncCompile(
i_isolate(), enabled_features, &thrower,
i::wasm::ModuleWireBytes(i::ArrayVector(kIncrementerWasm)));
CHECK(!thrower.error());
return Local<WasmModuleObject>::Cast(
Utils::ToLocal(compiled.ToHandleChecked()));
} }
void ExpectPass() { void ExpectPass() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment