OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <!-- |
| 3 Copyright 2017 The Chromium Authors. All rights reserved. |
| 4 Use of this source code is governed by a BSD-style license that can be |
| 5 found in the LICENSE file. |
| 6 --> |
| 7 |
| 8 <link rel="import" href="/tracing/base/utils.html"> |
| 9 <link rel="import" href="/tracing/value/diagnostics/diagnostic.html"> |
| 10 |
| 11 <script> |
| 12 'use strict'; |
| 13 |
| 14 tr.exportTo('tr.v.d', function() { |
| 15 class RelatedNameMap extends tr.v.d.Diagnostic { |
| 16 constructor(opt_info) { |
| 17 super(); |
| 18 this.map_ = new Map(); |
| 19 } |
| 20 |
| 21 clone() { |
| 22 const clone = new RelatedNameMap(); |
| 23 clone.addDiagnostic(this); |
| 24 return clone; |
| 25 } |
| 26 |
| 27 equals(other) { |
| 28 if (!(other instanceof RelatedNameMap)) return false; |
| 29 |
| 30 const keys1 = new Set(this.map_.keys()); |
| 31 const keys2 = new Set(other.map_.keys()); |
| 32 if (!tr.b.setsEqual(keys1, keys2)) return false; |
| 33 |
| 34 for (const [key, name] of this) { |
| 35 if (name !== other.get(key)) return false; |
| 36 } |
| 37 |
| 38 return true; |
| 39 } |
| 40 |
| 41 canAddDiagnostic(otherDiagnostic) { |
| 42 return otherDiagnostic instanceof RelatedNameMap; |
| 43 } |
| 44 |
| 45 addDiagnostic(otherDiagnostic) { |
| 46 for (const [key, name] of otherDiagnostic) { |
| 47 const existing = this.get(key); |
| 48 if (existing === undefined) { |
| 49 this.set(key, name); |
| 50 } else if (existing !== name) { |
| 51 throw new Error('Histogram names differ: ' + |
| 52 `"${existing}" != "${name}"`); |
| 53 } |
| 54 } |
| 55 } |
| 56 |
| 57 asDictInto_(d) { |
| 58 d.names = {}; |
| 59 for (const [key, name] of this) d.names[key] = name; |
| 60 } |
| 61 |
| 62 set(key, name) { |
| 63 this.map_.set(key, name); |
| 64 } |
| 65 |
| 66 get(key) { |
| 67 return this.map_.get(key); |
| 68 } |
| 69 |
| 70 * [Symbol.iterator]() { |
| 71 for (const pair of this.map_) yield pair; |
| 72 } |
| 73 |
| 74 * values() { |
| 75 for (const value of this.map_.values()) yield value; |
| 76 } |
| 77 |
| 78 static fromEntries(entries) { |
| 79 const names = new RelatedNameMap(); |
| 80 for (const [key, name] of entries) { |
| 81 names.set(key, name); |
| 82 } |
| 83 return names; |
| 84 } |
| 85 |
| 86 static fromDict(d) { |
| 87 return RelatedNameMap.fromEntries(Object.entries(d.names || {})); |
| 88 } |
| 89 } |
| 90 |
| 91 tr.v.d.Diagnostic.register(RelatedNameMap, { |
| 92 elementName: 'tr-v-ui-related-name-map-span', |
| 93 }); |
| 94 |
| 95 return { |
| 96 RelatedNameMap, |
| 97 }; |
| 98 }); |
| 99 </script> |
OLD | NEW |