[gnome-shell] scripting.js: small cleanups



commit 44a1bc539644b4e24d8cdb4fa355e71c36ce7247
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Tue Mar 8 18:51:15 2011 -0500

    scripting.js: small cleanups
    
    - Fix missing trailing semicolons
    - Catch when something results in metrics not being to avoid
      hard-to-debug JSON parse errors.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=644265

 js/ui/scripting.js |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
---
diff --git a/js/ui/scripting.js b/js/ui/scripting.js
index 2e38d10..1fc583e 100644
--- a/js/ui/scripting.js
+++ b/js/ui/scripting.js
@@ -246,8 +246,8 @@ function _collect(scriptModule, outputFile) {
         Shell.write_string_to_stream(out, '"events":\n');
         Shell.PerfLog.get_default().dump_events(out);
 
-        let monitors = global.get_monitors()
-        let primary = global.get_primary_monitor()
+        let monitors = global.get_monitors();
+        let primary = global.get_primary_monitor();
         Shell.write_string_to_stream(out, ',\n"monitors":\n[');
         for (let i = 0; i < monitors.length; i++) {
             let monitor = monitors[i];
@@ -266,7 +266,21 @@ function _collect(scriptModule, outputFile) {
         Shell.write_string_to_stream(out, ',\n"metrics":\n[ ');
         let first = true;
         for (let name in scriptModule.METRICS) {
-            let metric = scriptModule.METRICS[name]; 
+            let metric = scriptModule.METRICS[name];
+            // Extra checks here because JSON.stringify generates
+            // invalid JSON for undefined values
+            if (metric.description == null) {
+                log("Error: No description found for metric " + name);
+                continue;
+            }
+            if (metric.units == null) {
+                log("Error: No units found for metric " + name);
+                continue;
+            }
+            if (metric.value == null) {
+                log("Error: No value found for metric " + name);
+                continue;
+            }
 
             if (!first)
                 Shell.write_string_to_stream(out, ',\n  ');



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]