Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Unified Diff: tracing/tracing/value/diagnostics/diagnostic_map.html

Issue 2258583003: Modernize DiagnosticMap to subclass ES6 Map. (Closed) Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: fix longTasksMetric and Composition Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tracing/tracing/value/diagnostics/diagnostic_map.html
diff --git a/tracing/tracing/value/diagnostics/diagnostic_map.html b/tracing/tracing/value/diagnostics/diagnostic_map.html
index 8a0e39792543b2f8b3d9a11fb00c79db7254d6f3..f84cfb7119963c6a5ded088539d2e070c891217c 100644
--- a/tracing/tracing/value/diagnostics/diagnostic_map.html
+++ b/tracing/tracing/value/diagnostics/diagnostic_map.html
@@ -22,84 +22,55 @@ found in the LICENSE file.
'use strict';
tr.exportTo('tr.v.d', function() {
- /** @constructor */
- function DiagnosticMap(opt_diagnosticsByName) {
- if (opt_diagnosticsByName !== undefined)
- return DiagnosticMap.fromObject(opt_diagnosticsByName);
-
- this.diagnosticsByName_ = {};
- }
-
- DiagnosticMap.prototype = {
+ class DiagnosticMap extends Map {
/**
* Add a new Diagnostic to this map.
*
* @param {string} name
* @param {!tr.v.d.Diagnostic} diagnostic
*/
- add: function(name, diagnostic) {
- if (!(diagnostic instanceof tr.v.d.Diagnostic))
- throw new Error('Must be instanceof Diagnostic: ' + diagnostic);
-
+ set(name, diagnostic) {
if (typeof(name) !== 'string')
throw new Error('name must be string, not ' + name);
- if (this.diagnosticsByName_[name])
- throw new Error('Attempt to add duplicate diagnostic ' + name);
+ if (!(diagnostic instanceof tr.v.d.Diagnostic))
+ throw new Error('Must be instanceof Diagnostic: ' + diagnostic);
- this.diagnosticsByName_[name] = diagnostic;
- },
+ Map.prototype.set.call(this, name, diagnostic);
+ }
/**
* Add Diagnostics from a dictionary of dictionaries.
*
* @param {Object} dict
*/
- addDicts: function(dict) {
+ addDicts(dict) {
tr.b.iterItems(dict, function(name, diagnosticDict) {
- this.add(name, tr.v.d.Diagnostic.fromDict(diagnosticDict));
+ this.set(name, tr.v.d.Diagnostic.fromDict(diagnosticDict));
}, this);
- },
-
- /**
- * @param {string} name
- * @return {tr.v.d.Diagnostic}
- */
- get: function(name) {
- return this.diagnosticsByName_[name];
- },
-
- /**
- * Iterate over this map's key-value-pairs.
- *
- * @param {function(string, tr.v.d.Diagnostic)} callback
- * @param {Object=} opt_this
- */
- forEach: function(callback, opt_this) {
- tr.b.iterItems(this.diagnosticsByName_, callback, opt_this || this);
- },
+ }
- asDict: function() {
+ asDict() {
var dict = {};
- this.forEach(function(name, diagnostic) {
+ for (var [name, diagnostic] of this) {
dict[name] = diagnostic.asDict();
- });
+ }
return dict;
}
- };
- DiagnosticMap.fromDict = function(d) {
- var diagnostics = new DiagnosticMap();
- diagnostics.addDicts(d);
- return diagnostics;
- };
+ static fromDict(d) {
+ var diagnostics = new DiagnosticMap();
+ diagnostics.addDicts(d);
+ return diagnostics;
+ }
- DiagnosticMap.fromObject = function(obj) {
- var diagnostics = new DiagnosticMap();
- tr.b.iterItems(obj, function(name, diagnostic) {
- diagnostics.add(name, diagnostic);
- });
- return diagnostics;
+ static fromObject(obj) {
+ var diagnostics = new DiagnosticMap();
+ tr.b.iterItems(obj, function(name, diagnostic) {
+ diagnostics.set(name, diagnostic);
+ });
+ return diagnostics;
+ }
};
return {
« no previous file with comments | « tracing/tracing/value/diagnostics/composition.html ('k') | tracing/tracing/value/diagnostics/iteration_info.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698