Bug 1177329 - make sure sourcemapped frames appear in order. r=fitzgen, a=ritu
authorJames Long <longster@gmail.com>
Tue, 22 Mar 2016 14:05:15 -0400
changeset 323807 e747410012445c980fd18e9b323c475d11ee2ea6
parent 323806 ce278e1caab89e7e526c501c9c6ffc1cd151e8b5
child 323808 b8a888b7858ac9dd12c06875f0803bf82d196d25
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfitzgen, ritu
bugs1177329
milestone47.0a2
Bug 1177329 - make sure sourcemapped frames appear in order. r=fitzgen, a=ritu
devtools/server/actors/script.js
devtools/server/tests/unit/test_sourcemaps-17.js
--- a/devtools/server/actors/script.js
+++ b/devtools/server/actors/script.js
@@ -1254,43 +1254,45 @@ ThreadActor.prototype = {
     let i = 0;
     while (frame && (i < start)) {
       frame = frame.older;
       i++;
     }
 
     // Return request.count frames, or all remaining
     // frames if count is not defined.
-    let frames = [];
     let promises = [];
     for (; frame && (!count || i < (start + count)); i++, frame=frame.older) {
       let form = this._createFrameActor(frame).form();
       form.depth = i;
 
       let promise = this.sources.getOriginalLocation(new GeneratedLocation(
         this.sources.createNonSourceMappedActor(frame.script.source),
         form.where.line,
         form.where.column
       )).then((originalLocation) => {
-        if (originalLocation.originalSourceActor) {
-          let sourceForm = originalLocation.originalSourceActor.form();
-          form.where = {
-            source: sourceForm,
-            line: originalLocation.originalLine,
-            column: originalLocation.originalColumn
-          };
-          form.source = sourceForm;
-          frames.push(form);
+        if (!originalLocation.originalSourceActor) {
+          return null;
         }
+
+        let sourceForm = originalLocation.originalSourceActor.form();
+        form.where = {
+          source: sourceForm,
+          line: originalLocation.originalLine,
+          column: originalLocation.originalColumn
+        };
+        form.source = sourceForm;
+        return form;
       });
       promises.push(promise);
     }
 
-    return all(promises).then(function () {
-      return { frames: frames };
+    return all(promises).then(function (frames) {
+      // Filter null values because sourcemapping may have failed.
+      return { frames: frames.filter(x => !!x) };
     });
   },
 
   onReleaseMany: function (aRequest) {
     if (!aRequest.actors) {
       return { error: "missingParameter",
                message: "no actors were specified" };
     }
--- a/devtools/server/tests/unit/test_sourcemaps-17.js
+++ b/devtools/server/tests/unit/test_sourcemaps-17.js
@@ -22,33 +22,42 @@ function run_test() {
       test_source_map();
     });
   });
   do_test_pending();
 }
 
 function test_source_map() {
    // Set up debuggee code.
-  const a = new SourceNode(1, 1, "foo.js", "function a() { b(); }");
+  const a = new SourceNode(1, 1, "a.js", "function a() { b(); }");
   const b = new SourceNode(null, null, null, "function b() { c(); }");
-  const c = new SourceNode(2, 1, "foo.js", "function c() { debugger; }");
-  const { map, code } = (new SourceNode(null, null, null, [a,b,c])).toStringWithSourceMap({
-    file: "bar.js",
+  const c = new SourceNode(1, 1, "c.js", "function c() { d(); }");
+  const d = new SourceNode(null, null, null, "function d() { e(); }");
+  const e = new SourceNode(1, 1, "e.js", "function e() { debugger; }");
+  const { map, code } = (new SourceNode(null, null, null, [a,b,c,d,e])).toStringWithSourceMap({
+    file: "root.js",
     sourceRoot: "root",
   });
   Components.utils.evalInSandbox(
     code + "//# sourceMappingURL=data:text/json;base64," + btoa(map.toString()),
     gDebuggee,
     "1.8",
     "http://example.com/www/js/abc.js",
     1
   );
 
   gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
-    gThreadClient.fillFrames(50, function(res) {
-      do_check_true(!res.error, "Should not get an error: " + res.error);
+    gThreadClient.getFrames(0, 50, function({ error, frames }) {
+      do_check_true(!error);
+      do_check_eq(frames.length, 4);
+      // b.js should be skipped
+      do_check_eq(frames[0].where.source.url, "http://example.com/www/root/e.js");
+      do_check_eq(frames[1].where.source.url, "http://example.com/www/root/c.js");
+      do_check_eq(frames[2].where.source.url, "http://example.com/www/root/a.js");
+      do_check_eq(frames[3].where.source.url, null);
+
       finishClient(gClient);
     })
   });
 
     // Trigger it.
   gDebuggee.eval("a()");
 }