| 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>
|
|
|