Commit 7b582b61 authored by Thibaud Michaud's avatar Thibaud Michaud Committed by Commit Bot

[wasm] Store the source URL in CompiledWasmModule

This allows us to preserve the script URL when importing a module in a
worker.

R=ahaas@chromium.org,clemensb@chromium.org
CC=kimanh@chromium.org

Bug: chromium:1064548
Change-Id: Id5e48c840e2dba8eadb5c854fcb389787ce11215
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2167866
Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67543}
parent f1400e43
......@@ -4762,11 +4762,17 @@ class V8_EXPORT CompiledWasmModule {
*/
MemorySpan<const uint8_t> GetWireBytesRef();
const std::string& source_url() const { return source_url_; }
private:
explicit CompiledWasmModule(std::shared_ptr<internal::wasm::NativeModule>);
friend class Utils;
friend class WasmModuleObject;
friend class WasmStreaming;
explicit CompiledWasmModule(std::shared_ptr<internal::wasm::NativeModule>,
const char* source_url, size_t url_length);
const std::shared_ptr<internal::wasm::NativeModule> native_module_;
const std::string source_url_;
};
// An instance of WebAssembly.Module.
......
......@@ -7226,8 +7226,10 @@ MaybeLocal<Proxy> Proxy::New(Local<Context> context, Local<Object> local_target,
}
CompiledWasmModule::CompiledWasmModule(
std::shared_ptr<internal::wasm::NativeModule> native_module)
: native_module_(std::move(native_module)) {
std::shared_ptr<internal::wasm::NativeModule> native_module,
const char* source_url, size_t url_length)
: native_module_(std::move(native_module)),
source_url_(source_url, url_length) {
CHECK_NOT_NULL(native_module_);
}
......@@ -7248,7 +7250,13 @@ MemorySpan<const uint8_t> CompiledWasmModule::GetWireBytesRef() {
CompiledWasmModule WasmModuleObject::GetCompiledModule() {
i::Handle<i::WasmModuleObject> obj =
i::Handle<i::WasmModuleObject>::cast(Utils::OpenHandle(this));
return Utils::Convert(obj->shared_native_module());
auto source_url = i::String::cast(obj->script().source_url());
int length;
std::unique_ptr<char[]> cstring = source_url.ToCString(
i::DISALLOW_NULLS, i::FAST_STRING_TRAVERSAL, &length);
i::Handle<i::String> url(source_url, obj->GetIsolate());
return CompiledWasmModule(std::move(obj->shared_native_module()),
cstring.get(), length);
}
MaybeLocal<WasmModuleObject> WasmModuleObject::FromCompiledModule(
......@@ -7256,7 +7264,8 @@ MaybeLocal<WasmModuleObject> WasmModuleObject::FromCompiledModule(
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::Handle<i::WasmModuleObject> module_object =
i_isolate->wasm_engine()->ImportNativeModule(
i_isolate, Utils::Open(compiled_module));
i_isolate, compiled_module.native_module_,
i::VectorOf(compiled_module.source_url()));
return Local<WasmModuleObject>::Cast(
Utils::ToLocal(i::Handle<i::JSObject>::cast(module_object)));
}
......
......@@ -274,16 +274,6 @@ class Utils {
return OpenHandle(*handle);
}
static inline CompiledWasmModule Convert(
std::shared_ptr<i::wasm::NativeModule> native_module) {
return CompiledWasmModule{std::move(native_module)};
}
static inline const std::shared_ptr<i::wasm::NativeModule>& Open(
const CompiledWasmModule& compiled_module) {
return compiled_module.native_module_;
}
private:
static void ReportApiFailure(const char* location, const char* message);
};
......
......@@ -1273,7 +1273,7 @@ RUNTIME_FUNCTION(Runtime_CloneWasmModule) {
Handle<WasmModuleObject> new_module_object =
isolate->wasm_engine()->ImportNativeModule(
isolate, module_object->shared_native_module());
isolate, module_object->shared_native_module(), {});
return *new_module_object;
}
......
......@@ -732,10 +732,12 @@ Handle<Script> CreateWasmScript(Isolate* isolate,
} // namespace
Handle<WasmModuleObject> WasmEngine::ImportNativeModule(
Isolate* isolate, std::shared_ptr<NativeModule> shared_native_module) {
Isolate* isolate, std::shared_ptr<NativeModule> shared_native_module,
Vector<const char> source_url) {
NativeModule* native_module = shared_native_module.get();
ModuleWireBytes wire_bytes(native_module->wire_bytes());
Handle<Script> script = GetOrCreateScript(isolate, shared_native_module);
Handle<Script> script =
GetOrCreateScript(isolate, shared_native_module, source_url);
Handle<FixedArray> export_wrappers;
CompileJsToWasmWrappers(isolate, native_module->module(), &export_wrappers);
Handle<WasmModuleObject> module_object = WasmModuleObject::New(
......
......@@ -206,7 +206,8 @@ class V8_EXPORT_PRIVATE WasmEngine {
// Imports the shared part of a module from a different Context/Isolate using
// the the same engine, recreating a full module object in the given Isolate.
Handle<WasmModuleObject> ImportNativeModule(
Isolate* isolate, std::shared_ptr<NativeModule> shared_module);
Isolate* isolate, std::shared_ptr<NativeModule> shared_module,
Vector<const char> source_url);
WasmCodeManager* code_manager() { return &code_manager_; }
......
......@@ -73,8 +73,12 @@ class WasmStreaming::WasmStreamingImpl {
void SetClient(std::shared_ptr<Client> client) {
streaming_decoder_->SetModuleCompiledCallback(
[client](const std::shared_ptr<i::wasm::NativeModule>& native_module) {
client->OnModuleCompiled(Utils::Convert(native_module));
[client, streaming_decoder = streaming_decoder_](
const std::shared_ptr<i::wasm::NativeModule>& native_module) {
i::Vector<const char> url = streaming_decoder->url();
auto compiled_wasm_module =
CompiledWasmModule(native_module, url.begin(), url.size());
client->OnModuleCompiled(compiled_wasm_module);
});
}
......
......@@ -86,7 +86,8 @@ class SharedEngineIsolate {
Handle<WasmInstanceObject> ImportInstance(SharedModule shared_module) {
Handle<WasmModuleObject> module_object =
isolate()->wasm_engine()->ImportNativeModule(isolate(), shared_module);
isolate()->wasm_engine()->ImportNativeModule(isolate(), shared_module,
{});
ErrorThrower thrower(isolate(), "ImportInstance");
MaybeHandle<WasmInstanceObject> instance =
isolate()->wasm_engine()->SyncInstantiate(isolate(), &thrower,
......
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