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

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

Issue 2914163002: Check that Diagnostic subclasses are registered in presubmit. (Closed)
Patch Set: Created 3 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/discover_cmdline.html
diff --git a/tracing/tracing/value/diagnostics/discover_cmdline.html b/tracing/tracing/value/diagnostics/discover_cmdline.html
new file mode 100644
index 0000000000000000000000000000000000000000..293a5086508dd1bd1aff9bb0b51d3fb516050ffb
--- /dev/null
+++ b/tracing/tracing/value/diagnostics/discover_cmdline.html
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
eakuefner 2017/06/01 21:40:48 It bothers me that we have more than one discover_
eakuefner 2017/06/01 22:12:21 nvm
+<!--
+Copyright 2017 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/value/diagnostics/diagnostic.html">
+
+<script>
+'use strict';
+/* eslint-disable no-console */
+
+function isDiagnosticSubclass(cls) {
+ cls = cls.__proto__;
+ while (cls) {
+ if (cls === tr.v.d.Diagnostic) return true;
+ cls = cls.__proto__;
+ }
+ return false;
+}
+
+function discoverDiagnostics(args) {
+ const discoveryMode = args.shift();
+ for (const arg of args) HTMLImportsLoader.loadHTML(arg);
+
+ const results = [];
+ if (discoveryMode === 'registry') {
+ for (const typeInfo of tr.v.d.Diagnostic.getAllRegisteredTypeInfos()) {
+ results.push(typeInfo.constructor.name);
+ }
+ } else if (discoveryMode === 'namespace') {
+ for (const cls of Object.values(tr.v.d)) {
+ if (isDiagnosticSubclass(cls)) results.push(cls.name);
+ }
+ } else {
+ console.log('First argument must be either "registry" or "namespace".');
+ return 1;
+ }
+ console.log(JSON.stringify(results));
+ return 0;
+}
+
+if (tr.isHeadless) {
+ quit(discoverDiagnostics(sys.argv.slice(1)));
+}
+</script>

Powered by Google App Engine
This is Rietveld 408576698