Index: src/api.cc |
diff --git a/src/api.cc b/src/api.cc |
index 170b45402ad9b9c6c2b81efaa101f669a9897021..3e773f7347800c243617ac365bb4c8d72aeab3ef 100644 |
--- a/src/api.cc |
+++ b/src/api.cc |
@@ -7615,6 +7615,24 @@ 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)); |
+ 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(); |