Allow SourceReport to have duplicate URL entries if the VM scripts does

When using a concatenated dill file, several scripts with the same URL
can exist. They are not the same though, and should not be treated as
such.

Bug: #34841
Change-Id: Icd46357ffcf72ed35251b2a2793e1f83c02c4a8e
Reviewed-on: https://dart-review.googlesource.com/c/80821
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
diff --git a/runtime/vm/source_report.cc b/runtime/vm/source_report.cc
index 50b44d9..0bcef13 100644
--- a/runtime/vm/source_report.cc
+++ b/runtime/vm/source_report.cc
@@ -112,15 +112,18 @@
 }
 
 intptr_t SourceReport::GetScriptIndex(const Script& script) {
+  ScriptTableEntry wrapper;
   const String& url = String::Handle(zone(), script.url());
-  ScriptTableEntry* pair = script_table_.LookupValue(&url);
+  wrapper.key = &url;
+  wrapper.script = &Script::Handle(zone(), script.raw());
+  ScriptTableEntry* pair = script_table_.LookupValue(&wrapper);
   if (pair != NULL) {
     return pair->index;
   }
   ScriptTableEntry* tmp = new ScriptTableEntry();
   tmp->key = &url;
   tmp->index = next_script_index_++;
-  tmp->script = &Script::Handle(zone(), script.raw());
+  tmp->script = wrapper.script;
   script_table_entries_.Add(tmp);
   script_table_.Insert(tmp);
   ASSERT(script_table_entries_.length() == next_script_index_);
@@ -139,7 +142,10 @@
     ASSERT(i == index);
     const String& url2 = String::Handle(zone(), script->url());
     ASSERT(url2.Equals(*url));
-    ScriptTableEntry* pair = script_table_.LookupValue(&url2);
+    ScriptTableEntry wrapper;
+    wrapper.key = &url2;
+    wrapper.script = &Script::Handle(zone(), script->raw());
+    ScriptTableEntry* pair = script_table_.LookupValue(&wrapper);
     ASSERT(i == pair->index);
   }
 }
diff --git a/runtime/vm/source_report.h b/runtime/vm/source_report.h
index 8db2418..5ab147f 100644
--- a/runtime/vm/source_report.h
+++ b/runtime/vm/source_report.h
@@ -94,17 +94,17 @@
   // Needed for DirectChainedHashMap.
   struct ScriptTableTrait {
     typedef ScriptTableEntry* Value;
-    typedef const String* Key;
+    typedef const ScriptTableEntry* Key;
     typedef ScriptTableEntry* Pair;
 
-    static Key KeyOf(Pair kv) { return kv->key; }
+    static Key KeyOf(Pair kv) { return kv; }
 
     static Value ValueOf(Pair kv) { return kv; }
 
-    static inline intptr_t Hashcode(Key key) { return key->Hash(); }
+    static inline intptr_t Hashcode(Key key) { return key->key->Hash(); }
 
     static inline bool IsKeyEqual(Pair kv, Key key) {
-      return kv->key->Equals(*key);
+      return kv->script->raw() == key->script->raw();
     }
   };