[api] Change Wasm ModuleCompiled notification

- Removes ModuleCompiledCallback typedef and Set function.
- Adds WasmStreaming::Client abstraction and Set function.

Bug: chromium:719172
Change-Id: I8a207b628394a7660bda73cde560da1e461248a7
Reviewed-on: https://chromium-review.googlesource.com/c/1377450
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Adam Klein <adamk@chromium.org>
Commit-Queue: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58454}
This commit is contained in:
Bill Budge 2018-12-21 10:23:40 -08:00 committed by Commit Bot
parent 644b26e684
commit fc479d516b
3 changed files with 36 additions and 35 deletions

View File

@ -4453,6 +4453,19 @@ class V8_EXPORT WasmStreaming final {
public:
class WasmStreamingImpl;
/**
* Client to receive streaming event notifications.
*/
class Client {
public:
virtual ~Client() = default;
/**
* Passes the fully compiled module to the client. This can be used to
* implement code caching.
*/
virtual void OnModuleCompiled(CompiledWasmModule compiled_module) = 0;
};
explicit WasmStreaming(std::unique_ptr<WasmStreamingImpl> impl);
~WasmStreaming();
@ -4478,28 +4491,20 @@ class V8_EXPORT WasmStreaming final {
void Abort(MaybeLocal<Value> exception);
/**
* Callback for module compiled notifications. |data| is the identifier
* passed to {SetModuleCompiledCallback}, |compiled_module| is the result.
*/
typedef void (*ModuleCompiledCallback)(intptr_t data,
CompiledWasmModule compiled_module);
/**
* Sets a callback for when compilation of the Wasm module has been completed
* to the highest tier. |data| will be passed as the first callback parameter.
*/
void SetModuleCompiledCallback(ModuleCompiledCallback callback,
intptr_t data);
/**
* Passes previously compiled module bytes. This must be called before calling
* any non-static methods of this class. Returns true if the module bytes can
* be used, false otherwise. The buffer passed into {SetCompiledModuleBytes}
* Passes previously compiled module bytes. This must be called before
* {OnBytesReceived}, {Finish}, or {Abort}. Returns true if the module bytes
* can be used, false otherwise. The buffer passed via {bytes} and {size}
* is owned by the caller. If {SetCompiledModuleBytes} returns true, the
* buffer must remain valid until either {Finish} or {Abort} completes.
*/
bool SetCompiledModuleBytes(const uint8_t* bytes, size_t size);
/**
* Sets the client object that will receive streaming event notifications.
* This must be called before {OnBytesReceived}, {Finish}, or {Abort}.
*/
void SetClient(std::shared_ptr<Client> client);
/**
* Unpacks a {WasmStreaming} object wrapped in a {Managed} for the embedder.
* Since the embedder is on the other side of the API, it cannot unpack the

View File

@ -157,8 +157,7 @@ void StreamingDecoder::NotifyRuntimeObjectsCreated(
auto* comp_state = module_object->native_module()->compilation_state();
comp_state->AddCallback(TopTierCompiledCallback{
std::move(native_module), std::move(module_compiled_callback_)});
// The callback took ownership of the callback:
DCHECK_NULL(module_compiled_callback_);
module_compiled_callback_ = {};
}
// An abstract class to share code among the states which decode VarInts. This

View File

@ -59,22 +59,20 @@ class WasmStreaming::WasmStreamingImpl {
Utils::OpenHandle(*exception.ToLocalChecked()));
}
void SetModuleCompiledCallback(ModuleCompiledCallback callback,
intptr_t data) {
// Wrap the embedder callback here so we can also wrap the result as a
// Local<WasmModuleObject> here.
streaming_decoder_->SetModuleCompiledCallback(
[callback,
data](const std::shared_ptr<i::wasm::NativeModule>& native_module) {
callback(data, Utils::Convert(native_module));
});
}
bool SetCompiledModuleBytes(const uint8_t* bytes, size_t size) {
if (!i::wasm::IsSupportedVersion({bytes, size})) return false;
return streaming_decoder_->SetCompiledModuleBytes({bytes, size});
}
void SetClient(std::shared_ptr<Client> client) {
// There are no other event notifications so just pass client to decoder.
// Wrap the client with a callback here so we can also wrap the result.
streaming_decoder_->SetModuleCompiledCallback(
[client](const std::shared_ptr<i::wasm::NativeModule>& native_module) {
client->OnModuleCompiled(Utils::Convert(native_module));
});
}
private:
Isolate* isolate_ = nullptr;
std::shared_ptr<internal::wasm::StreamingDecoder> streaming_decoder_;
@ -98,15 +96,14 @@ void WasmStreaming::Abort(MaybeLocal<Value> exception) {
impl_->Abort(exception);
}
void WasmStreaming::SetModuleCompiledCallback(ModuleCompiledCallback callback,
intptr_t data) {
impl_->SetModuleCompiledCallback(callback, data);
}
bool WasmStreaming::SetCompiledModuleBytes(const uint8_t* bytes, size_t size) {
return impl_->SetCompiledModuleBytes(bytes, size);
}
void WasmStreaming::SetClient(std::shared_ptr<Client> client) {
impl_->SetClient(client);
}
// static
std::shared_ptr<WasmStreaming> WasmStreaming::Unpack(Isolate* isolate,
Local<Value> value) {