[wasm][debug] Set script URL from WasmStreaming

Add a method to set the URL of a Wasm script from a WasmStreaming object.
This will allow devtools to report the actual URL when it is available.

R=clemensb@chromium.org

Bug: v8:9762
Change-Id: Iccd41d76c9a4a2e1858716e8d555782404719faa
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1944153
Reviewed-by: Adam Klein <adamk@chromium.org>
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65405}
This commit is contained in:
Thibaud Michaud 2019-12-10 15:11:22 +01:00 committed by Commit Bot
parent 6bd85fc611
commit a68ee60ac3
7 changed files with 45 additions and 17 deletions

View File

@ -4767,6 +4767,12 @@ class V8_EXPORT WasmStreaming final {
*/
void SetClient(std::shared_ptr<Client> client);
/*
* Sets the UTF-8 encoded source URL for the {Script} object. This must be
* called before {Finish}.
*/
void SetUrl(const char* url, size_t length);
/**
* 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

@ -1518,8 +1518,10 @@ void AsyncCompileJob::PrepareRuntimeObjects() {
// Create heap objects for script and module bytes to be stored in the
// module object. Asm.js is not compiled asynchronously.
const WasmModule* module = native_module_->module();
Handle<Script> script = CreateWasmScript(
isolate_, wire_bytes_, module->source_map_url, module->name);
auto source_url = stream_ ? stream_->url() : Vector<const char>();
Handle<Script> script =
CreateWasmScript(isolate_, wire_bytes_, VectorOf(module->source_map_url),
module->name, source_url);
Handle<WasmModuleObject> module_object =
WasmModuleObject::New(isolate_, native_module_, script);
@ -2700,8 +2702,9 @@ WasmCode* CompileImportWrapper(
Handle<Script> CreateWasmScript(Isolate* isolate,
const ModuleWireBytes& wire_bytes,
const std::string& source_map_url,
WireBytesRef name) {
Vector<const char> source_map_url,
WireBytesRef name,
Vector<const char> source_url) {
Handle<Script> script =
isolate->factory()->NewScript(isolate->factory()->empty_string());
script->set_context_data(isolate->native_context()->debug_context_id());
@ -2714,9 +2717,6 @@ Handle<Script> CreateWasmScript(Isolate* isolate,
const int kBufferSize = 32;
char buffer[kBufferSize];
Handle<String> url_prefix =
isolate->factory()->InternalizeString(StaticCharVector("wasm://wasm/"));
// Script name is "<module_name>-hash" if name is available and "hash"
// otherwise.
Handle<String> name_str;
@ -2746,13 +2746,20 @@ Handle<Script> CreateWasmScript(Isolate* isolate,
.ToHandleChecked();
}
script->set_name(*name_str);
MaybeHandle<String> url_str =
isolate->factory()->NewConsString(url_prefix, name_str);
MaybeHandle<String> url_str;
if (!source_url.empty()) {
url_str =
isolate->factory()->NewStringFromUtf8(source_url, AllocationType::kOld);
} else {
Handle<String> url_prefix =
isolate->factory()->InternalizeString(StaticCharVector("wasm://wasm/"));
url_str = isolate->factory()->NewConsString(url_prefix, name_str);
}
script->set_source_url(*url_str.ToHandleChecked());
if (source_map_url.size() != 0) {
if (!source_map_url.empty()) {
MaybeHandle<String> src_map_str = isolate->factory()->NewStringFromUtf8(
CStrVector(source_map_url.c_str()), AllocationType::kOld);
source_map_url, AllocationType::kOld);
script->set_source_mapping_url(*src_map_str.ToHandleChecked());
}
return script;

View File

@ -59,7 +59,8 @@ WasmCode* CompileImportWrapper(
V8_EXPORT_PRIVATE Handle<Script> CreateWasmScript(
Isolate* isolate, const ModuleWireBytes& wire_bytes,
const std::string& source_map_url, WireBytesRef name);
Vector<const char> source_map_url, WireBytesRef name,
Vector<const char> source_url = {});
// Triggered by the WasmCompileLazy builtin. The return value indicates whether
// compilation was successful. Lazy compilation can fail only if validation is

View File

@ -90,6 +90,11 @@ class V8_EXPORT_PRIVATE StreamingDecoder {
void NotifyNativeModuleCreated(
const std::shared_ptr<NativeModule>& native_module);
Vector<const char> url() { return VectorOf(url_); }
void SetUrl(Vector<const char> url) {
url_.assign(url.begin(), url.length());
}
private:
// TODO(ahaas): Put the whole private state of the StreamingDecoder into the
// cc file (PIMPL design pattern).
@ -266,6 +271,7 @@ class V8_EXPORT_PRIVATE StreamingDecoder {
bool code_section_processed_ = false;
uint32_t module_offset_ = 0;
size_t total_size_ = 0;
std::string url_;
// Caching support.
ModuleCompiledCallback module_compiled_callback_ = nullptr;

View File

@ -302,9 +302,9 @@ MaybeHandle<WasmModuleObject> WasmEngine::SyncCompile(
std::move(result).value(), bytes, &export_wrappers);
if (!native_module) return {};
Handle<Script> script =
CreateWasmScript(isolate, bytes, native_module->module()->source_map_url,
native_module->module()->name);
Handle<Script> script = CreateWasmScript(
isolate, bytes, VectorOf(native_module->module()->source_map_url),
native_module->module()->name);
// Create the module object.
// TODO(clemensb): For the same module (same bytes / same hash), we should
@ -443,7 +443,7 @@ Handle<WasmModuleObject> WasmEngine::ImportNativeModule(
NativeModule* native_module = shared_native_module.get();
ModuleWireBytes wire_bytes(native_module->wire_bytes());
Handle<Script> script = CreateWasmScript(
isolate, wire_bytes, native_module->module()->source_map_url,
isolate, wire_bytes, VectorOf(native_module->module()->source_map_url),
native_module->module()->name);
Handle<FixedArray> export_wrappers;
CompileJsToWasmWrappers(isolate, native_module->module(), &export_wrappers);

View File

@ -76,6 +76,10 @@ class WasmStreaming::WasmStreamingImpl {
});
}
void SetUrl(internal::Vector<const char> url) {
streaming_decoder_->SetUrl(url);
}
private:
Isolate* const isolate_;
std::shared_ptr<internal::wasm::StreamingDecoder> streaming_decoder_;
@ -107,6 +111,10 @@ void WasmStreaming::SetClient(std::shared_ptr<Client> client) {
impl_->SetClient(client);
}
void WasmStreaming::SetUrl(const char* url, size_t length) {
impl_->SetUrl(internal::VectorOf(url, length));
}
// static
std::shared_ptr<WasmStreaming> WasmStreaming::Unpack(Isolate* isolate,
Local<Value> value) {

View File

@ -617,7 +617,7 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
std::shared_ptr<WasmModule> module = std::move(decode_result.value());
CHECK_NOT_NULL(module);
Handle<Script> script = CreateWasmScript(
isolate, wire_bytes, module->source_map_url, module->name);
isolate, wire_bytes, VectorOf(module->source_map_url), module->name);
const bool kIncludeLiftoff = false;
size_t code_size_estimate =