Bug 1414546 - Don't treat "yield" as a keyword in JS1.7. r=jandem
authorAndré Bargull <andre.bargull@gmail.com>
Tue, 07 Nov 2017 06:10:30 -0800
changeset 443793 e12503415ea547ed43fa7dbb91f6e8180f6b4fa9
parent 443792 55f9dc61e9f70361546da610e349ec20ce6e774b
child 443799 cc777e5019993d68de03a83d5b8cfe54fece31d8
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1414546
milestone58.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 1414546 - Don't treat "yield" as a keyword in JS1.7. r=jandem
js/src/frontend/Parser.cpp
js/src/jit-test/tests/basic/destructuring-rest-identifiers.js
js/src/jit-test/tests/gc/bug-1370069.js
js/src/jit-test/tests/generators/yield-regexp.js
js/src/jit-test/tests/parser/yield-in-formal-destructuring.js
js/src/tests/js1_7/lexical/regress-351515.js
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -8999,17 +8999,17 @@ Parser<ParseHandler, CharT>::checkLabelO
         MOZ_ASSERT(hint == ReservedWordTokenKind(ident), "hint doesn't match actual token kind");
         tt = hint;
     }
 
     if (tt == TOK_NAME)
         return true;
     if (TokenKindIsContextualKeyword(tt)) {
         if (tt == TOK_YIELD) {
-            if (yieldHandling == YieldIsKeyword || versionNumber() >= JSVERSION_1_7) {
+            if (yieldHandling == YieldIsKeyword) {
                 errorAt(offset, JSMSG_RESERVED_ID, "yield");
                 return false;
             }
             if (pc->sc()->needStrictChecks()) {
                 if (!strictModeErrorAt(offset, JSMSG_RESERVED_ID, "yield"))
                     return false;
             }
             return true;
--- a/js/src/jit-test/tests/basic/destructuring-rest-identifiers.js
+++ b/js/src/jit-test/tests/basic/destructuring-rest-identifiers.js
@@ -37,32 +37,28 @@ var reserved = [
   'true',
   'false'
 ];
 reserved.forEach(ident => {
   assertThrowsInstanceOf(() => new Function('var [...' + ident + '] = []'), SyntaxError);
 });
 
 var strictIdentifiers = [
-  // XXX: see bug 1032150. Once fixed, please uncomment these values and
-  // remove the assertions below
-  //'yield',
-  //'let',
+  'yield',
+  'let',
   'eval',
   'arguments',
   'implements',
   'interface',
   'package',
   'private',
   'protected',
   'public',
   'static'
 ];
-assertThrowsInstanceOf(() => new Function('[...yield] = []'), SyntaxError);
-assertThrowsInstanceOf(() => new Function('"use strict"; [...let] = []'), SyntaxError);
 
 strictIdentifiers.forEach(ident =>
   assertThrowsInstanceOf(() =>
     new Function('"use strict"; [...' + ident + '] = []'), SyntaxError));
 
 var globalEval = eval;
 strictIdentifiers.forEach(ident => {
   globalEval(ident + ' = null');
--- a/js/src/jit-test/tests/gc/bug-1370069.js
+++ b/js/src/jit-test/tests/gc/bug-1370069.js
@@ -1,6 +1,6 @@
-// |jit-test| error:SyntaxError
+// |jit-test| error:ReferenceError
 try {
     eval("}");
 } catch (exc) {}
 gczeal(17, 1);
 6.900653737167637, (yield);
--- a/js/src/jit-test/tests/generators/yield-regexp.js
+++ b/js/src/jit-test/tests/generators/yield-regexp.js
@@ -1,36 +1,25 @@
 // Bug 1099956
 
 load(libdir + "asserts.js");
 
-// ES6 treating yield as an identifier except in ES6 generators introduces a
-// syntax conflict with permissible JS >= 1.7 legacy generator syntax.  Is
-// |yield /a/g| inside a function an attempt to convert the function into a
-// legacy generator, yielding a RegExp instance?  Or does it instead read as
-// |(yield / a) / g|?  Similar ambiguities exist for different textual content
-// in place of |a| -- |yield /x+17/g| or |(yield / x) + 17 / g|, and so on.
-// (And, much less importantly, is |yield /a/g| a syntax error in global code
-// as in JS >= 1.7, or is it |(yield / a) / g|.)
-//
-// For now, in JS >= 1.7, we preserve the old behavior.  In all other JS we
-// conform to ES6: |yield /a/g| is a YieldExpression inside an ES6 generator,
-// and it's an IdentifierReference divided twice when not in an ES6 generator.
-// This test will need changes if we change our JS >= 1.7 parsing to be
-// ES6-compatible.
+// Parses as IDENT(yield) DIV IDENT(abc) DIV IDENT(g).
+eval(`function f1() { yield /abc/g; }`);
 
-// TODO: fix yield in non-generator functions.
+// Throws a ReferenceError because no global "yield" variable is defined.
 var ex;
 try {
-  eval(`function f1() { yield /abc/g; }`);
+  f1();
 } catch(e) {
   ex = e;
 }
-assertEq(ex.message.includes("reserved identifier"), true);
+assertEq(ex instanceof ReferenceError, true);
 
+// Parses as YIELD REGEXP(/abc/g).
 function* f2() {
   yield /abc/g;
 }
 
 g = f2();
 v = g.next();
 assertEq(v.done, false);
 assertEq(v.value instanceof RegExp, true);
--- a/js/src/jit-test/tests/parser/yield-in-formal-destructuring.js
+++ b/js/src/jit-test/tests/parser/yield-in-formal-destructuring.js
@@ -1,2 +1,1 @@
-// |jit-test| error: SyntaxError
 function d([{ [yield]: {} } ]) f
--- a/js/src/tests/js1_7/lexical/regress-351515.js
+++ b/js/src/tests/js1_7/lexical/regress-351515.js
@@ -11,29 +11,29 @@ var expect = '';
 
 
 //-----------------------------------------------------------------------------
 test();
 //-----------------------------------------------------------------------------
 
 try
 {
-  expect = "SyntaxError";
+  expect = "No Error";
   eval('yield = 1;');
   actual = 'No Error';
 }
 catch(ex)
 {
   actual = ex.name;
 }
 reportCompare(expect, actual, summary + ': global: yield = 1');
 
 try
 {
-  expect = "SyntaxError";
+  expect = "No Error";
   eval('(function(){yield = 1;})');
   actual = 'No Error';
 }
 catch(ex)
 {
   actual = ex.name;
 }
 reportCompare(expect, actual, summary + ': local: yield = 1');
@@ -52,30 +52,30 @@ reportCompare(expect, actual, summary + 
 
 function test()
 {
   printBugNumber(BUGNUMBER);
   printStatus (summary);
  
   try
   {
-    expect = "SyntaxError";
+    expect = "No Error";
     eval('function f(yield, let) { return yield+let; }');
     actual = 'No Error';
   }
   catch(ex)
   {
     actual = ex.name;
   }
   reportCompare(expect, actual, summary +
 		': function f(yield, let) { return yield+let; }');
 
   try
   {
-    expect = "SyntaxError";
+    expect = "No Error";
     eval('var yield = 1;');
     actual = 'No Error';
   }
   catch(ex)
   {
     actual = ex.name;
   }
   reportCompare(expect, actual, summary + ': function () {var yield;}');