Commit 1f2acdba authored by Marja Hölttä's avatar Marja Hölttä Committed by V8 LUCI CQ

[web snapshot] Name scripts better

Give the "phantom" script containing the web snapshot functions the same
name as the original script.

Bug: v8:11525
Change-Id: Iae77d58152642256560ceb3688bc2b3d0d9800be
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3394707Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78643}
parent db9f6bff
......@@ -2858,7 +2858,8 @@ MaybeHandle<SharedFunctionInfo> GetSharedFunctionInfoForScriptImpl(
}
}
if (magic_matches) {
return Compiler::GetSharedFunctionInfoForWebSnapshot(isolate, source);
return Compiler::GetSharedFunctionInfoForWebSnapshot(
isolate, source, script_details.name_obj);
}
}
......@@ -3153,7 +3154,8 @@ Compiler::GetSharedFunctionInfoForStreamedScript(
// static
Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForWebSnapshot(
Isolate* isolate, Handle<String> source) {
Isolate* isolate, Handle<String> source,
MaybeHandle<Object> maybe_script_name) {
// This script won't hold the functions created from the web snapshot;
// reserving space only for the top-level SharedFunctionInfo is enough.
Handle<WeakFixedArray> shared_function_infos =
......@@ -3161,6 +3163,12 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForWebSnapshot(
Handle<Script> script = isolate->factory()->NewScript(source);
script->set_type(Script::TYPE_WEB_SNAPSHOT);
script->set_shared_function_infos(*shared_function_infos);
Handle<Object> script_name;
if (maybe_script_name.ToHandle(&script_name) && script_name->IsString()) {
script->set_name(String::cast(*script_name));
} else {
script->set_name(*isolate->factory()->empty_string());
}
Handle<SharedFunctionInfo> shared =
isolate->factory()->NewSharedFunctionInfoForWebSnapshot();
......
......@@ -215,7 +215,7 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic {
const ScriptDetails& script_details, ScriptStreamingData* streaming_data);
static Handle<SharedFunctionInfo> GetSharedFunctionInfoForWebSnapshot(
Isolate* isolate, Handle<String> source);
Isolate* isolate, Handle<String> source, MaybeHandle<Object> script_name);
// Create a shared function info object for the given function literal
// node (the code may be lazily compiled).
......
......@@ -1001,6 +1001,7 @@ bool WebSnapshotDeserializer::UseWebSnapshot(
Handle<Script> snapshot_as_script) {
Handle<String> source =
handle(String::cast(snapshot_as_script->source()), isolate_);
script_name_ = handle(snapshot_as_script->name(), isolate_);
if (source->IsExternalOneByteString()) {
const v8::String::ExternalOneByteStringResource* resource =
ExternalOneByteString::cast(*source).resource();
......@@ -1121,9 +1122,7 @@ bool WebSnapshotDeserializer::DeserializeScript() {
NewStringType::kNormal, static_cast<int>(remaining_bytes))
.ToLocalChecked();
ScriptOrigin origin(v8_isolate, v8::String::NewFromUtf8Literal(
v8_isolate, "(web snapshot)",
NewStringType::kInternalized));
ScriptOrigin origin(v8_isolate, Utils::ToLocal(script_name_));
ScriptCompiler::Source script_source(source, origin);
Local<UnboundScript> script;
......
......@@ -281,6 +281,7 @@ class V8_EXPORT WebSnapshotDeserializer
Handle<WeakFixedArray> shared_function_infos_;
Handle<ObjectHashTable> shared_function_info_table_;
Handle<Script> script_;
Handle<Object> script_name_;
uint32_t string_count_ = 0;
uint32_t map_count_ = 0;
......
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