OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright 2016 The Chromium Authors. All rights reserved. | 3 Copyright 2016 The Chromium Authors. All rights reserved. |
4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
5 found in the LICENSE file. | 5 found in the LICENSE file. |
6 --> | 6 --> |
7 | 7 |
8 <link rel="import" href="/tracing/base/iteration_helpers.html"> | 8 <link rel="import" href="/tracing/base/iteration_helpers.html"> |
9 <link rel="import" href="/tracing/value/diagnostics/related_value_set.html"> | 9 <link rel="import" href="/tracing/value/diagnostics/related_value_set.html"> |
10 | 10 |
11 <script> | 11 <script> |
12 'use strict'; | 12 'use strict'; |
13 | 13 |
14 tr.exportTo('tr.v.d', function() { | 14 tr.exportTo('tr.v.d', function() { |
15 /** @constructor */ | 15 /** @constructor */ |
16 function RelatedValueMap() { | 16 function RelatedValueMap() { |
17 this.valuesByName_ = {}; | 17 this.valuesByName_ = {}; |
18 } | 18 } |
19 | 19 |
20 RelatedValueMap.prototype = { | 20 RelatedValueMap.prototype = { |
21 __proto__: tr.v.d.Diagnostic.prototype, | 21 __proto__: tr.v.d.Diagnostic.prototype, |
22 | 22 |
23 /** | 23 /** |
24 * Add a named Value to this map. | 24 * Add a Value by an explicit name to this map. |
25 * | 25 * |
26 * @param {string} name | 26 * @param {string} name |
27 * @param {!(tr.v.d.ValueRef|tr.v.Value)} value | 27 * @param {!(tr.v.d.ValueRef|tr.v.Value)} value |
28 */ | 28 */ |
29 set: function(name, value) { | 29 set: function(name, value) { |
30 if (!(value instanceof tr.v.Value) && | 30 if (!(value instanceof tr.v.Value) && |
31 !(value instanceof tr.v.d.ValueRef)) | 31 !(value instanceof tr.v.d.ValueRef)) |
32 throw new Error('Must be instanceof Value or ValueRef: ' + value); | 32 throw new Error('Must be instanceof Value or ValueRef: ' + value); |
33 | 33 |
34 this.valuesByName_[name] = value; | 34 this.valuesByName_[name] = value; |
35 }, | 35 }, |
36 | 36 |
37 /** | 37 /** |
| 38 * Add a Value implicitly by its own name to this map. |
| 39 * |
| 40 * @param {!(tr.v.d.ValueRef|tr.v.Value)} value |
| 41 */ |
| 42 add: function(value) { |
| 43 this.set(value.name, value); |
| 44 }, |
| 45 |
| 46 /** |
38 * Iterate over the named Values. | 47 * Iterate over the named Values. |
39 * | 48 * |
40 * @param {!function(string, !(tr.v.d.ValueRef|tr.v.Value))} callback | 49 * @param {!function(string, !(tr.v.d.ValueRef|tr.v.Value))} callback |
41 * @param {*=} opt_this | 50 * @param {*=} opt_this |
42 */ | 51 */ |
43 iterItems: function(callback, opt_this) { | 52 iterItems: function(callback, opt_this) { |
44 tr.b.iterItems(this.valuesByName_, callback, opt_this || this); | 53 tr.b.iterItems(this.valuesByName_, callback, opt_this || this); |
45 }, | 54 }, |
46 | 55 |
47 /** | 56 /** |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 tr.v.d.Diagnostic.register(RelatedValueMap, { | 110 tr.v.d.Diagnostic.register(RelatedValueMap, { |
102 elementName: 'tr-v-ui-related-value-map-span' | 111 elementName: 'tr-v-ui-related-value-map-span' |
103 }); | 112 }); |
104 | 113 |
105 | 114 |
106 return { | 115 return { |
107 RelatedValueMap: RelatedValueMap | 116 RelatedValueMap: RelatedValueMap |
108 }; | 117 }; |
109 }); | 118 }); |
110 </script> | 119 </script> |
OLD | NEW |