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

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

Issue 2000063006: Define DiagnosticMap and a basic Diagnostic hierarchy (Closed) Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: rebase Created 4 years, 7 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.html
diff --git a/tracing/tracing/value/diagnostics/diagnostic.html b/tracing/tracing/value/diagnostics/diagnostic.html
new file mode 100644
index 0000000000000000000000000000000000000000..061f099a5f9edeb074d1382ebe421247ffc1d108
--- /dev/null
+++ b/tracing/tracing/value/diagnostics/diagnostic.html
@@ -0,0 +1,60 @@
+<!DOCTYPE html>
+<!--
+Copyright 2016 The Chromium Authors. All rights reserved.
+Use of this source code is governed by a BSD-style license that can be
+found in the LICENSE file.
+-->
+
+<link rel="import" href="/tracing/base/extension_registry.html">
+
+<script>
+'use strict';
+
+tr.exportTo('tr.v.d', function() {
+ /** @constructor */
+ function Diagnostic() {
+ }
+
+ Diagnostic.prototype = {
+ asDict: function() {
+ var result = {type: this.constructor.name};
+ this._asDictInto(result);
+ return result;
+ },
+
+ _asDictInto: function(d) {
+ throw new Error('Abstract virtual method');
+ }
+ };
+
+ var options = new tr.b.ExtensionRegistryOptions(tr.b.BASIC_REGISTRY_MODE);
+ options.defaultMetadata = {};
+ options.mandatoryBaseClass = Diagnostic;
+ tr.b.decorateExtensionRegistry(Diagnostic, options);
+
+ Diagnostic.addEventListener('will-register', function(e) {
+ var constructor = e.typeInfo.constructor;
+ if (!(constructor.fromDict instanceof Function) ||
+ (constructor.fromDict.length !== 1)) {
+ throw new Error('Diagnostics must define fromDict(d)');
+ }
+
+ // When subclasses set their prototype to an entirely new object and omit
+ // their constructor, then it becomes impossible for asDict() to find their
+ // constructor name. Add it back here so that asDict() can find it.
+ constructor.prototype.constructor = constructor;
+ });
+
+ Diagnostic.fromDict = function(d) {
+ var typeInfo = Diagnostic.findTypeInfoWithName(d.type);
+ if (!typeInfo)
+ throw new Error('Unrecognized diagnostic type: ' + d.type);
+
+ return typeInfo.constructor.fromDict(d);
+ };
+
+ return {
+ Diagnostic: Diagnostic
+ };
+});
+</script>
« no previous file with comments | « tracing/tracing/value/diagnostics/composition.html ('k') | tracing/tracing/value/diagnostics/diagnostic_map.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698