Bug 1140196. r=jorendorff
authorJeff Walden <jwalden@mit.edu>
Thu, 05 Mar 2015 18:03:56 -0800
changeset 232340 39488bb38d8da22a1aed3888ffb4a1d9a1328add
parent 232339 dc86a4e16519d1cf511dedbd1d043a49149a8ac8
child 232341 efa7c6cf88fce711716619cb1b37035fa48387bc
push id56520
push userjwalden@mit.edu
push dateSat, 07 Mar 2015 01:37:23 +0000
treeherdermozilla-inbound@39488bb38d8d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1140196
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1140196. r=jorendorff
js/src/frontend/ParseNode.cpp
js/src/jit-test/tests/basic/destructuring-default.js
js/src/js.msg
js/src/vm/Xdr.h
--- a/js/src/frontend/ParseNode.cpp
+++ b/js/src/frontend/ParseNode.cpp
@@ -744,24 +744,18 @@ Parser<FullParseHandler>::cloneLeftHandS
  *    [a = default] or {a: b = default}
  */
 template <>
 ParseNode *
 Parser<FullParseHandler>::cloneDestructuringDefault(ParseNode *opn)
 {
     MOZ_ASSERT(opn->isKind(PNK_ASSIGN));
 
-    ParseNode *target = cloneLeftHandSide(opn->pn_left);
-    if (!target)
-        return nullptr;
-    ParseNode *defaultNode = cloneParseTree(opn->pn_right);
-    if (!defaultNode)
-        return nullptr;
-
-    return handler.new_<BinaryNode>(opn->getKind(), JSOP_NOP, opn->pn_pos, target, defaultNode);
+    report(ParseError, false, opn, JSMSG_DEFAULT_IN_PATTERN);
+    return null();
 }
 
 /*
  * Used by Parser::forStatement and comprehensionTail to clone the TARGET in
  *   for (var/const/let TARGET in EXPR)
  *
  * opn must be the pn_head of a node produced by Parser::variables, so its form
  * is known to be LHS = NAME | [LHS] | {id:LHS}.
--- a/js/src/jit-test/tests/basic/destructuring-default.js
+++ b/js/src/jit-test/tests/basic/destructuring-default.js
@@ -161,23 +161,37 @@ var evaled = false;
 assertEq(evaled, true);
 evaled = false;
 assertThrowsInstanceOf(() => { [[] = (evaled = true, 2)] = [] }, TypeError);
 assertEq(evaled, true);
 
 assertThrowsInstanceOf(() => new Function('var [...rest = defaults] = [];'), SyntaxError);
 
 // bug 1124480: destructuring defaults should work correctly as part of for-in
-b = undefined;
-for (var [a, b = 10] in " ") {}
-assertEq(b, 10);
-
-b = undefined;
-for (let [a, c = 10] in " ") { b = c; }
-assertEq(b, 10);
+var defaultsSupportedInForVar = false;
+try
+{
+  new Function('for (var [a, b = 10] in " ") {}');
+  defaultsSupportedInForVar = true;
+}
+catch (e)
+{
+}
 
-b = undefined;
-for (var {1: b = 10} in " ") {}
-assertEq(b, 10);
+if (defaultsSupportedInForVar) {
+  new Function(`
+    b = undefined;
+    for (var [a, b = 10] in " ") {}
+    assertEq(b, 10);
+
+    b = undefined;
+    for (let [a, c = 10] in " ") { b = c; }
+    assertEq(b, 10);
 
-b = undefined;
-for (let {1: c = 10} in " ") { b = c; }
-assertEq(b, 10);
+    b = undefined;
+    for (var {1: b = 10} in " ") {}
+    assertEq(b, 10);
+
+    b = undefined;
+    for (let {1: c = 10} in " ") { b = c; }
+    assertEq(b, 10);
+  `)();
+}
--- a/js/src/js.msg
+++ b/js/src/js.msg
@@ -321,16 +321,17 @@ MSG_DEF(JSMSG_UNTERMINATED_STRING,     0
 MSG_DEF(JSMSG_USELESS_EXPR,            0, JSEXN_TYPEERR, "useless expression")
 MSG_DEF(JSMSG_USE_ASM_DIRECTIVE_FAIL,  0, JSEXN_SYNTAXERR, "\"use asm\" is only meaningful in the Directive Prologue of a function body")
 MSG_DEF(JSMSG_VAR_HIDES_ARG,           1, JSEXN_TYPEERR, "variable {0} redeclares argument")
 MSG_DEF(JSMSG_WHILE_AFTER_DO,          0, JSEXN_SYNTAXERR, "missing while after do-loop body")
 MSG_DEF(JSMSG_YIELD_IN_ARROW,          0, JSEXN_SYNTAXERR, "arrow function may not contain yield")
 MSG_DEF(JSMSG_YIELD_IN_DEFAULT,        0, JSEXN_SYNTAXERR, "yield in default expression")
 MSG_DEF(JSMSG_BAD_COLUMN_NUMBER,       0, JSEXN_RANGEERR, "column number out of range")
 MSG_DEF(JSMSG_COMPUTED_NAME_IN_PATTERN,0, JSEXN_SYNTAXERR, "computed property names aren't supported in this destructuring declaration")
+MSG_DEF(JSMSG_DEFAULT_IN_PATTERN,      0, JSEXN_SYNTAXERR, "destructuring defaults aren't supported in this destructuring declaration")
 
 // asm.js
 MSG_DEF(JSMSG_USE_ASM_TYPE_FAIL,       1, JSEXN_TYPEERR, "asm.js type error: {0}")
 MSG_DEF(JSMSG_USE_ASM_LINK_FAIL,       1, JSEXN_TYPEERR, "asm.js link error: {0}")
 MSG_DEF(JSMSG_USE_ASM_TYPE_OK,         1, JSEXN_NONE,    "Successfully compiled asm.js code ({0})")
 
 // Proxy
 MSG_DEF(JSMSG_BAD_TRAP_RETURN_VALUE,   2, JSEXN_TYPEERR,"trap {1} for {0} returned a primitive value")
--- a/js/src/vm/Xdr.h
+++ b/js/src/vm/Xdr.h
@@ -24,21 +24,21 @@ namespace js {
  * versions.  If deserialization fails, the data should be invalidated if
  * possible.
  *
  * When you change this, run make_opcode_doc.py and copy the new output into
  * this wiki page:
  *
  *  https://developer.mozilla.org/en-US/docs/SpiderMonkey/Internals/Bytecode
  */
-static const uint32_t XDR_BYTECODE_VERSION_SUBTRAHEND = 240;
+static const uint32_t XDR_BYTECODE_VERSION_SUBTRAHEND = 241;
 static const uint32_t XDR_BYTECODE_VERSION =
     uint32_t(0xb973c0de - XDR_BYTECODE_VERSION_SUBTRAHEND);
 
-static_assert(JSErr_Limit == 374,
+static_assert(JSErr_Limit == 375,
               "GREETINGS, POTENTIAL SUBTRAHEND INCREMENTER! If you added or "
               "removed MSG_DEFs from js.msg, you should increment "
               "XDR_BYTECODE_VERSION_SUBTRAHEND and update this assertion's "
               "expected JSErr_Limit value.");
 
 class XDRBuffer {
   public:
     explicit XDRBuffer(JSContext *cx)