Commit 0bd9f1b8 authored by mtrofin's avatar mtrofin Committed by Commit bot

[wasm] Module Builder v8 API: bytes passed in are owned by caller.

This reflects both the contract in blink, as well as what we
plan to do in streamed compilation, where we'll want to lay out
bytes received such that each section and each function body is
contiguous, but they may all be separate - which entails a copy.

BUG=chromium:697028

Review-Url: https://codereview.chromium.org/2797653002
Cr-Commit-Position: refs/heads/master@{#44387}
parent 6d89de7b
......@@ -4053,7 +4053,8 @@ class V8_EXPORT WasmCompiledModule : public Object {
class V8_EXPORT WasmModuleObjectBuilder final {
public:
WasmModuleObjectBuilder(Isolate* isolate) : isolate_(isolate) {}
void OnBytesReceived(std::unique_ptr<const uint8_t[]>&& bytes, size_t size);
// The buffer passed into OnBytesReceived is owned by the caller.
void OnBytesReceived(const uint8_t*, size_t size);
MaybeLocal<WasmCompiledModule> Finish();
private:
......
......@@ -7589,9 +7589,14 @@ MaybeLocal<WasmCompiledModule> WasmCompiledModule::Compile(Isolate* isolate,
Utils::ToLocal(maybe_compiled.ToHandleChecked()));
}
void WasmModuleObjectBuilder::OnBytesReceived(
std::unique_ptr<const uint8_t[]>&& bytes, size_t size) {
received_buffers_.push_back(Buffer(std::move(bytes), size));
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;
}
......
......@@ -464,9 +464,9 @@ TEST(ModuleBuilder) {
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(std::move(first_part), first_mark);
builder.OnBytesReceived(std::move(second_part), second_mark - first_mark);
builder.OnBytesReceived(std::move(third_part), 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();
......@@ -490,7 +490,7 @@ TEST(FailingModuleBuilder) {
v8::WasmModuleObjectBuilder builder(CcTest::isolate());
std::unique_ptr<const uint8_t[]> first_part =
CreatePayload(buffer.begin(), first_mark);
builder.OnBytesReceived(std::move(first_part), first_mark);
builder.OnBytesReceived(first_part.get(), first_mark);
{
HandleScope scope(i_isolate);
v8::MaybeLocal<v8::WasmCompiledModule> maybe_module = builder.Finish();
......
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