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( ...@@ -2858,7 +2858,8 @@ MaybeHandle<SharedFunctionInfo> GetSharedFunctionInfoForScriptImpl(
} }
} }
if (magic_matches) { if (magic_matches) {
return Compiler::GetSharedFunctionInfoForWebSnapshot(isolate, source); return Compiler::GetSharedFunctionInfoForWebSnapshot(
isolate, source, script_details.name_obj);
} }
} }
...@@ -3153,7 +3154,8 @@ Compiler::GetSharedFunctionInfoForStreamedScript( ...@@ -3153,7 +3154,8 @@ Compiler::GetSharedFunctionInfoForStreamedScript(
// static // static
Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForWebSnapshot( 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; // This script won't hold the functions created from the web snapshot;
// reserving space only for the top-level SharedFunctionInfo is enough. // reserving space only for the top-level SharedFunctionInfo is enough.
Handle<WeakFixedArray> shared_function_infos = Handle<WeakFixedArray> shared_function_infos =
...@@ -3161,6 +3163,12 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForWebSnapshot( ...@@ -3161,6 +3163,12 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForWebSnapshot(
Handle<Script> script = isolate->factory()->NewScript(source); Handle<Script> script = isolate->factory()->NewScript(source);
script->set_type(Script::TYPE_WEB_SNAPSHOT); script->set_type(Script::TYPE_WEB_SNAPSHOT);
script->set_shared_function_infos(*shared_function_infos); 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 = Handle<SharedFunctionInfo> shared =
isolate->factory()->NewSharedFunctionInfoForWebSnapshot(); isolate->factory()->NewSharedFunctionInfoForWebSnapshot();
......
...@@ -215,7 +215,7 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic { ...@@ -215,7 +215,7 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic {
const ScriptDetails& script_details, ScriptStreamingData* streaming_data); const ScriptDetails& script_details, ScriptStreamingData* streaming_data);
static Handle<SharedFunctionInfo> GetSharedFunctionInfoForWebSnapshot( 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 // Create a shared function info object for the given function literal
// node (the code may be lazily compiled). // node (the code may be lazily compiled).
......
...@@ -1001,6 +1001,7 @@ bool WebSnapshotDeserializer::UseWebSnapshot( ...@@ -1001,6 +1001,7 @@ bool WebSnapshotDeserializer::UseWebSnapshot(
Handle<Script> snapshot_as_script) { Handle<Script> snapshot_as_script) {
Handle<String> source = Handle<String> source =
handle(String::cast(snapshot_as_script->source()), isolate_); handle(String::cast(snapshot_as_script->source()), isolate_);
script_name_ = handle(snapshot_as_script->name(), isolate_);
if (source->IsExternalOneByteString()) { if (source->IsExternalOneByteString()) {
const v8::String::ExternalOneByteStringResource* resource = const v8::String::ExternalOneByteStringResource* resource =
ExternalOneByteString::cast(*source).resource(); ExternalOneByteString::cast(*source).resource();
...@@ -1121,9 +1122,7 @@ bool WebSnapshotDeserializer::DeserializeScript() { ...@@ -1121,9 +1122,7 @@ bool WebSnapshotDeserializer::DeserializeScript() {
NewStringType::kNormal, static_cast<int>(remaining_bytes)) NewStringType::kNormal, static_cast<int>(remaining_bytes))
.ToLocalChecked(); .ToLocalChecked();
ScriptOrigin origin(v8_isolate, v8::String::NewFromUtf8Literal( ScriptOrigin origin(v8_isolate, Utils::ToLocal(script_name_));
v8_isolate, "(web snapshot)",
NewStringType::kInternalized));
ScriptCompiler::Source script_source(source, origin); ScriptCompiler::Source script_source(source, origin);
Local<UnboundScript> script; Local<UnboundScript> script;
......
...@@ -281,6 +281,7 @@ class V8_EXPORT WebSnapshotDeserializer ...@@ -281,6 +281,7 @@ class V8_EXPORT WebSnapshotDeserializer
Handle<WeakFixedArray> shared_function_infos_; Handle<WeakFixedArray> shared_function_infos_;
Handle<ObjectHashTable> shared_function_info_table_; Handle<ObjectHashTable> shared_function_info_table_;
Handle<Script> script_; Handle<Script> script_;
Handle<Object> script_name_;
uint32_t string_count_ = 0; uint32_t string_count_ = 0;
uint32_t map_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