Commit 0ee594dd authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm][api] Remove the WasmModuleObjectBuilder

The WasmModuleObjectBuilder was the first interface for streaming
compilation of WebAssembly. Over time we realized that the interface
is insufficient, and we introduced the WasmModuleObjectBuilderStreaming
class, which is used now for streaming compilation. Since the
WasmModuleObjectBuilder was never fully functional, I think it is okay
to remove it without a deprecation period.

R=clemensh@chromium.org, adamk@chromium.org

Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: Ia3ac5f150fdad7bc1ad04ba89aee53538d43ce01
Reviewed-on: https://chromium-review.googlesource.com/913614Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51305}
parent 841763be
......@@ -4187,30 +4187,6 @@ class V8_EXPORT WasmModuleObjectBuilderStreaming final {
std::shared_ptr<internal::wasm::StreamingDecoder> streaming_decoder_;
};
class V8_EXPORT WasmModuleObjectBuilder final {
public:
WasmModuleObjectBuilder(Isolate* isolate) : isolate_(isolate) {}
// The buffer passed into OnBytesReceived is owned by the caller.
void OnBytesReceived(const uint8_t*, size_t size);
MaybeLocal<WasmCompiledModule> Finish();
private:
Isolate* isolate_ = nullptr;
// TODO(ahaas): We probably need none of this below here once streamed
// compilation is implemented.
typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> Buffer;
// Disable copy semantics *in this implementation*. We can choose to
// relax this, albeit it's not clear why.
WasmModuleObjectBuilder(const WasmModuleObjectBuilder&) = delete;
WasmModuleObjectBuilder(WasmModuleObjectBuilder&&) = default;
WasmModuleObjectBuilder& operator=(const WasmModuleObjectBuilder&) = delete;
WasmModuleObjectBuilder& operator=(WasmModuleObjectBuilder&&) = default;
std::vector<Buffer> received_buffers_;
size_t total_size_ = 0;
};
#ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
// The number of required internal fields can be defined by embedder.
#define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
......
......@@ -7709,29 +7709,6 @@ WasmModuleObjectBuilderStreaming::~WasmModuleObjectBuilderStreaming() {
promise_.Reset();
}
void WasmModuleObjectBuilder::OnBytesReceived(const uint8_t* bytes,
size_t size) {
std::unique_ptr<uint8_t[]> cloned_bytes(new uint8_t[size]);
memcpy(cloned_bytes.get(), bytes, size);
received_buffers_.push_back(
Buffer(std::unique_ptr<const uint8_t[]>(
const_cast<const uint8_t*>(cloned_bytes.release())),
size));
total_size_ += size;
}
MaybeLocal<WasmCompiledModule> WasmModuleObjectBuilder::Finish() {
std::unique_ptr<uint8_t[]> wire_bytes(new uint8_t[total_size_]);
uint8_t* insert_at = wire_bytes.get();
for (size_t i = 0; i < received_buffers_.size(); ++i) {
const Buffer& buff = received_buffers_[i];
memcpy(insert_at, buff.first.get(), buff.second);
insert_at += buff.second;
}
return WasmCompiledModule::Compile(isolate_, wire_bytes.get(), total_size_);
}
// static
v8::ArrayBuffer::Allocator* v8::ArrayBuffer::Allocator::NewDefaultAllocator() {
return new ArrayBufferAllocator();
......
......@@ -445,67 +445,6 @@ TEST(DeserializeWireBytesAndSerializedDataInvalid) {
Cleanup();
}
std::unique_ptr<const uint8_t[]> CreatePayload(const uint8_t* start,
size_t size) {
uint8_t* ret = new uint8_t[size];
memcpy(ret, start, size);
return std::unique_ptr<const uint8_t[]>(const_cast<const uint8_t*>(ret));
}
TEST(ModuleBuilder) {
v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME);
ZoneBuffer buffer(&zone);
WasmSerializationTest::BuildWireBytes(&zone, &buffer);
CHECK_GT(buffer.size(), 0);
size_t third = buffer.size() / 3;
size_t first_mark = third - 2;
size_t second_mark = buffer.size() - 2 - third;
CHECK_LT(0, first_mark);
CHECK(first_mark < second_mark);
CHECK(second_mark < buffer.size());
Isolate* i_isolate = CcTest::InitIsolateOnce();
v8::WasmModuleObjectBuilder builder(CcTest::isolate());
std::unique_ptr<const uint8_t[]> first_part =
CreatePayload(buffer.begin(), first_mark);
std::unique_ptr<const uint8_t[]> second_part =
CreatePayload(buffer.begin() + first_mark, second_mark - first_mark);
std::unique_ptr<const uint8_t[]> third_part =
CreatePayload(buffer.begin() + second_mark, buffer.size() - second_mark);
builder.OnBytesReceived(first_part.get(), first_mark);
builder.OnBytesReceived(second_part.get(), second_mark - first_mark);
builder.OnBytesReceived(third_part.get(), buffer.size() - second_mark);
{
HandleScope scope(i_isolate);
v8::MaybeLocal<v8::WasmCompiledModule> maybe_module = builder.Finish();
CHECK(!maybe_module.IsEmpty());
}
}
TEST(FailingModuleBuilder) {
v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME);
ZoneBuffer buffer(&zone);
WasmSerializationTest::BuildWireBytes(&zone, &buffer);
CHECK_GT(buffer.size(), 0);
size_t third = buffer.size() / 3;
size_t first_mark = third - 2;
size_t second_mark = buffer.size() - 2 - third;
CHECK_LT(0, first_mark);
CHECK(first_mark < second_mark);
CHECK(second_mark < buffer.size());
Isolate* i_isolate = CcTest::InitIsolateOnce();
v8::WasmModuleObjectBuilder builder(CcTest::isolate());
std::unique_ptr<const uint8_t[]> first_part =
CreatePayload(buffer.begin(), first_mark);
builder.OnBytesReceived(first_part.get(), first_mark);
{
HandleScope scope(i_isolate);
v8::MaybeLocal<v8::WasmCompiledModule> maybe_module = builder.Finish();
CHECK(maybe_module.IsEmpty());
}
}
bool False(v8::Local<v8::Context> context, v8::Local<v8::String> source) {
return false;
}
......
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