Bug 1099054 - Fix bogus error messages caused by the decompiler falling back to the current pc. r=nbp
authorJan de Mooij <jdemooij@mozilla.com>
Fri, 11 Nov 2016 12:52:33 +0100
changeset 322175 f0103ae8bdd0200622f03235c02c3101bc9610a5
parent 322174 3f1ec7d616d64068b447ede8d6fe2d59d2cf09b2
child 322176 385cf64debf70955bec05f8729f42ed8477f1d81
push id21
push usermaklebus@msu.edu
push dateThu, 01 Dec 2016 06:22:08 +0000
reviewersnbp
bugs1099054
milestone52.0a1
Bug 1099054 - Fix bogus error messages caused by the decompiler falling back to the current pc. r=nbp
js/src/jit-test/tests/basic/expression-autopsy.js
js/src/jsopcode.cpp
--- a/js/src/jit-test/tests/basic/expression-autopsy.js
+++ b/js/src/jit-test/tests/basic/expression-autopsy.js
@@ -90,16 +90,17 @@ for (let tok of ["|", "^", "&", "==", "!
 check("o[!(o)]");
 check("o[~(o)]");
 check("o[+ (o)]");
 check("o[- (o)]");
 
 
 // A few one off tests
 check_one("6", (function () { 6() }), " is not a function");
+check_one("4", (function() { (4||eval)(); }), " is not a function");
 check_one("0", (function () { Array.prototype.reverse.call('123'); }), " is read-only");
 check_one("(intermediate value)[Symbol.iterator](...).next(...).value",
           function () { ieval("{ let x; var [a, b, [c0, c1]] = [x, x, x]; }") }, " is undefined");
 check_one("void 1", function() { (void 1)(); }, " is not a function");
 check_one("void o[1]", function() { var o = []; (void o[1])() }, " is not a function");
 
 // Manual testing for this case: the only way to trigger an error is *not* on
 // an attempted property access during destructuring, and the error message
--- a/js/src/jsopcode.cpp
+++ b/js/src/jsopcode.cpp
@@ -1419,29 +1419,28 @@ ExpressionDecompiler::getOutput(char** r
 
 }  // anonymous namespace
 
 static bool
 FindStartPC(JSContext* cx, const FrameIter& iter, int spindex, int skipStackHits, const Value& v,
             jsbytecode** valuepc)
 {
     jsbytecode* current = *valuepc;
+    *valuepc = nullptr;
 
     if (spindex == JSDVG_IGNORE_STACK)
         return true;
 
     /*
      * FIXME: Fall back if iter.isIon(), since the stack snapshot may be for the
      * previous pc (see bug 831120).
      */
     if (iter.isIon())
         return true;
 
-    *valuepc = nullptr;
-
     BytecodeParser parser(cx, iter.script());
     if (!parser.parse())
         return false;
 
     if (spindex < 0 && spindex + int(parser.stackDepthAtPC(current)) < 0)
         spindex = JSDVG_SEARCH_STACK;
 
     if (spindex == JSDVG_SEARCH_STACK) {
@@ -1463,23 +1462,22 @@ FindStartPC(JSContext* cx, const FrameIt
             if (!index)
                 return true;
             s = iter.frameSlotValue(--index);
         } while (s != v || stackHits++ != skipStackHits);
 
         // If the current PC has fewer values on the stack than the index we are
         // looking for, the blamed value must be one pushed by the current
         // bytecode, so restore *valuepc.
-        jsbytecode* pc = nullptr;
         if (index < size_t(parser.stackDepthAtPC(current)))
-            pc = parser.pcForStackOperand(current, index);
-        *valuepc = pc ? pc : current;
+            *valuepc = parser.pcForStackOperand(current, index);
+        else
+            *valuepc = current;
     } else {
-        jsbytecode* pc = parser.pcForStackOperand(current, spindex);
-        *valuepc = pc ? pc : current;
+        *valuepc = parser.pcForStackOperand(current, spindex);
     }
     return true;
 }
 
 static bool
 DecompileExpressionFromStack(JSContext* cx, int spindex, int skipStackHits, HandleValue v, char** res)
 {
     MOZ_ASSERT(spindex < 0 ||