[gjs] coverage: Don't propagate exceptions raised in debugger context



commit d27882ce9c34d13ca536b3da400a662e7f819140
Author: Sam Spilsbury <smspillaz gmail com>
Date:   Wed Jan 14 19:04:53 2015 +0800

    coverage: Don't propagate exceptions raised in debugger context

 modules/coverage.js |   61 +++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 45 insertions(+), 16 deletions(-)
---
diff --git a/modules/coverage.js b/modules/coverage.js
index 4609069..54e3d2c 100644
--- a/modules/coverage.js
+++ b/modules/coverage.js
@@ -697,6 +697,10 @@ function CoverageStatisticsContainer(files) {
             throw new Error('Not tracking statistics for ' + filename);
         return statistics;
     };
+
+    this.deleteStatistics = function(filename) {
+        coveredFiles[filename] = undefined;
+    };
 }
 
 /**
@@ -707,6 +711,7 @@ function CoverageStatisticsContainer(files) {
 function CoverageStatistics(files) {
     this.container = new CoverageStatisticsContainer(files);
     let fetchStatistics = this.container.fetchStatistics.bind(this.container);
+    let deleteStatistics = this.container.deleteStatistics.bind(this.container);
 
     /* 'debuggee' comes from the invocation from
      * a separate compartment inside of coverage.cpp */
@@ -743,17 +748,34 @@ function CoverageStatistics(files) {
             return undefined;
         }
 
+        function _logExceptionAndReset(exception, callee, line) {
+            warning(e.fileName + ":" + e.lineNumber + " (processing " +
+                    frame.script.url + ":" + callee + ":" + line + ") - " +
+                    e.message);
+            warning("Will not log statistics for this file");
+            frame.onStep = undefined;
+            frame._branchTracker = undefined;
+            deleteStatistics(frame.script.url);
+        }
+
         /* Log function calls */
         if (frame.callee !== null && frame.callee.callable) {
             let name = frame.callee.name ? frame.callee.name : "(anonymous)";
             let line = frame.script.getOffsetLine(frame.offset);
             let nArgs = frame.callee.parameterNames.length;
 
-            _incrementFunctionCounters(statistics.functionCounters,
-                                       statistics.linesWithKnownFunctions,
-                                       name,
-                                       line,
-                                       nArgs);
+            try {
+                _incrementFunctionCounters(statistics.functionCounters,
+                                           statistics.linesWithKnownFunctions,
+                                           name,
+                                           line,
+                                           nArgs);
+            } catch (e) {
+                /* Something bad happened. Log the exception and delete
+                 * statistics for this file */
+                _logExceptionAndReset(e, name, line);
+                return undefined;
+            }
         }
 
         /* Upon entering the frame, the active branch is always inactive */
@@ -765,19 +787,26 @@ function CoverageStatistics(files) {
             let offset = this.offset;
             let offsetLine = this.script.getOffsetLine(offset);
 
-            _incrementExpressionCounters(statistics.expressionCounters,
-                                         offsetLine,
-                                         function(line) {
-                                             warning("executed " +
-                                                     frame.script.url +
-                                                     ":" +
-                                                     offsetLine +
-                                                     " which we thought wasn't executable");
-                                         });
-
-            this._branchTracker.incrementBranchCounters(offsetLine);
+            try {
+                _incrementExpressionCounters(statistics.expressionCounters,
+                                             offsetLine,
+                                             function(line) {
+                                                 warning("executed " +
+                                                         frame.script.url +
+                                                         ":" +
+                                                         offsetLine +
+                                                         " which we thought" +
+                                                         " wasn't executable");
+                                             });
+                this._branchTracker.incrementBranchCounters(offsetLine);
+            } catch (e) {
+                /* Something bad happened. Log the exception and delete
+                 * statistics for this file */
+                _logExceptionAndReset(e, name, line);
+            }
         };
 
+        /* Explicitly return here to satisfy strict mode */
         return undefined;
     };
 }


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