Commit 13532c08 authored by Mircea Trofin's avatar Mircea Trofin Committed by Commit Bot

[wasm] Streaming API: own the promise.

Avoid leaking because the persistent handle isn't released. To further
clarify ownership, the v8 side owns now completely the promise.

Bug: 
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: Ief9e44e60235fe6199fc4884ad1ccbd9e34cce8a
Reviewed-on: https://chromium-review.googlesource.com/591067Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46978}
parent 8be73bad
...@@ -4165,11 +4165,14 @@ class V8_EXPORT WasmCompiledModule : public Object { ...@@ -4165,11 +4165,14 @@ class V8_EXPORT WasmCompiledModule : public Object {
// to simply WasmModuleObjectBuilder // to simply WasmModuleObjectBuilder
class V8_EXPORT WasmModuleObjectBuilderStreaming final { class V8_EXPORT WasmModuleObjectBuilderStreaming final {
public: public:
WasmModuleObjectBuilderStreaming(Isolate* isolate, Local<Promise> promise); WasmModuleObjectBuilderStreaming(Isolate* isolate);
// The buffer passed into OnBytesReceived is owned by the caller. // The buffer passed into OnBytesReceived is owned by the caller.
void OnBytesReceived(const uint8_t*, size_t size); void OnBytesReceived(const uint8_t*, size_t size);
void Finish(); void Finish();
void Abort(Local<Value> exception); void Abort(Local<Value> exception);
Local<Promise> GetPromise();
~WasmModuleObjectBuilderStreaming();
private: private:
typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> Buffer; typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> Buffer;
......
...@@ -7806,9 +7806,20 @@ MaybeLocal<WasmCompiledModule> WasmCompiledModule::Compile(Isolate* isolate, ...@@ -7806,9 +7806,20 @@ MaybeLocal<WasmCompiledModule> WasmCompiledModule::Compile(Isolate* isolate,
} }
WasmModuleObjectBuilderStreaming::WasmModuleObjectBuilderStreaming( WasmModuleObjectBuilderStreaming::WasmModuleObjectBuilderStreaming(
Isolate* isolate, Local<Promise> promise) Isolate* isolate)
: isolate_(isolate) { : isolate_(isolate) {
promise_.Reset(isolate, promise); MaybeLocal<Promise::Resolver> maybe_promise =
Promise::Resolver::New(isolate->GetCurrentContext());
Local<Promise::Resolver> promise;
if (maybe_promise.ToLocal(&promise)) {
promise_.Reset(isolate, promise->GetPromise());
} else {
UNREACHABLE();
}
}
Local<Promise> WasmModuleObjectBuilderStreaming::GetPromise() {
return promise_.Get(isolate_);
} }
void WasmModuleObjectBuilderStreaming::OnBytesReceived(const uint8_t* bytes, void WasmModuleObjectBuilderStreaming::OnBytesReceived(const uint8_t* bytes,
...@@ -7848,6 +7859,10 @@ void WasmModuleObjectBuilderStreaming::Abort(Local<Value> exception) { ...@@ -7848,6 +7859,10 @@ void WasmModuleObjectBuilderStreaming::Abort(Local<Value> exception) {
CHECK_IMPLIES(!maybe.FromMaybe(false), i_isolate->has_scheduled_exception()); CHECK_IMPLIES(!maybe.FromMaybe(false), i_isolate->has_scheduled_exception());
} }
WasmModuleObjectBuilderStreaming::~WasmModuleObjectBuilderStreaming() {
promise_.Reset();
}
void WasmModuleObjectBuilder::OnBytesReceived(const uint8_t* bytes, void WasmModuleObjectBuilder::OnBytesReceived(const uint8_t* bytes,
size_t size) { size_t size) {
std::unique_ptr<uint8_t[]> cloned_bytes(new uint8_t[size]); std::unique_ptr<uint8_t[]> cloned_bytes(new uint8_t[size]);
......
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