Bug 1304638 - Don't return "(intermediate value)" while decompiling SETELEM/STRICTSETELEM. r=nbp
authorEmilio Cobos Álvarez <ecoal95@gmail.com>
Sun, 09 Oct 2016 15:39:15 +0200
changeset 319836 27f76213fa87e8469387d9783afcb7c3e404eb0f
parent 319835 9459cdff732abc4f4cc89b650322c29422e190b9
child 319837 107238b89fccb625ed3eedcb6854e7e91b5609a1
push id20748
push userphilringnalda@gmail.com
push dateFri, 28 Oct 2016 03:39:55 +0000
treeherderfx-team@715360440695 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnbp
bugs1304638
milestone52.0a1
Bug 1304638 - Don't return "(intermediate value)" while decompiling SETELEM/STRICTSETELEM. r=nbp This caused us to go to the fallback, and call `ValueToSource` to set the message exception[1]. [1]: http://searchfox.org/mozilla-central/rev/c635b8c61d648bb8a0317c19f8905b3be8132a8a/js/src/jsopcode.cpp#1536 MozReview-Commit-ID: J7tfxoDnUUr Signed-off-by: Emilio Cobos Álvarez <ecoal95@gmail.com>
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
@@ -11,17 +11,17 @@ function check_one(expected, f, err) {
         assertEq(s.slice(0, 11), "TypeError: ");
         assertEq(s.slice(-err.length), err, "" + f);
         assertEq(s.slice(11, -err.length), expected);
     }
     if (!failed)
         throw new Error("didn't fail");
 }
 ieval = eval;
-function check(expr, expected=expr) {
+function check(expr, expected=expr, testStrict=true) {
     var end, err;
     for ([end, err] of [[".random_prop", " is undefined"], ["()", " is not a function"]]) {
         var statement = "o = {};" + expr + end, f;
         var cases = [
             // Global scope
             function () {
                 ieval("var o, undef;\n" + statement);
             },
@@ -42,16 +42,21 @@ function check(expr, expected=expr) {
             // Let in a switch
             Function("var x = 4; switch (x) { case 4: let o, undef;" + statement + "\ncase 6: break;}"),
             // Try-catch blocks
             Function("o", "undef", "try { let q = 4; try { let p = 4; } catch (e) {} } catch (e) {} { let o, undef; " + statement + " }"),
             // Let in for-in (uses with to prevent jit compilation: bug 942804, bug 831120 and bug 1041586)
             Function("with ({}) {} var undef, o; for (let z in [1, 2]) { " + statement + " }"),
         ];
 
+        if (testStrict) {
+            // Strict mode.
+            cases.push(Function("o", "undef", "\"use strict\";\n" + statement));
+        }
+
         for (var f of cases) {
             check_one(expected, f, err);
         }
     }
 }
 
 check("undef");
 check("o.b");
@@ -62,22 +67,25 @@ check("o[null]");
 check("o[0]");
 check("o[1]");
 check("o[3]");
 check("o[256]");
 check("o[65536]");
 check("o[268435455]");
 check("o['1.1']");
 check("o[4 + 'h']", "o['4h']");
-check("this.x");
 check("ieval(undef)", "ieval(...)");
 check("ieval.call()", "ieval.call(...)");
 check("ieval(...[])", "ieval(...)");
 check("ieval(...[undef])", "ieval(...)");
 check("ieval(...[undef, undef])", "ieval(...)");
+check("(o[0] = 4).foo", "o[0].foo");
+// NOTE: This one produces different output in strict mode since "this" is
+// undefined in that case.
+check("this.x", "this.x", false);
 
 for (let tok of ["|", "^", "&", "==", "!==", "===", "!==", "<", "<=", ">", ">=",
                  ">>", "<<", ">>>", "+", "-", "*", "/", "%"]) {
     check("o[(undef " + tok + " 4)]");
 }
 
 check("o[!(o)]");
 check("o[~(o)]");
@@ -105,10 +113,25 @@ try
 }
 catch (e)
 {
   assertEq(e instanceof TypeError, true,
            "expected TypeError, got " + e);
   assertEq(e.message, "can't convert null to object");
 }
 
+try {
+  (function() {
+    "use strict";
+    var o = [];
+    Object.freeze(o);
+    o[0] = "foo";
+  }());
+  throw new Error("didn't throw");
+} catch (e) {
+  assertEq(e instanceof TypeError, true,
+           "expected TypeError, got " + e);
+  assertEq(e.message,
+           "can't define array index property past the end of an array with non-writable length");
+}
+
 // Check fallback behavior
 assertThrowsInstanceOf(function () { for (let x of undefined) {} }, TypeError);
--- a/js/src/jsopcode.cpp
+++ b/js/src/jsopcode.cpp
@@ -1260,16 +1260,26 @@ ExpressionDecompiler::decompilePC(jsbyte
                write("]");
       }
       case JSOP_GETPROP_SUPER:
       {
         RootedAtom prop(cx, loadAtom(pc));
         return write("super.") &&
                quote(prop, '\0');
       }
+      case JSOP_SETELEM:
+      case JSOP_STRICTSETELEM:
+        // NOTE: We don't show the right hand side of the operation because
+        // it's used in error messages like: "a[0] is not readable".
+        //
+        // We could though.
+        return decompilePCForStackOperand(pc, -3) &&
+               write("[") &&
+               decompilePCForStackOperand(pc, -2) &&
+               write("]");
       case JSOP_GETELEM:
       case JSOP_CALLELEM:
         return decompilePCForStackOperand(pc, -2) &&
                write("[") &&
                decompilePCForStackOperand(pc, -1) &&
                write("]");
       case JSOP_GETELEM_SUPER:
         return write("super[") &&