Bug 497869 - Forbid let and yield in strict mode code in scripts which are not JS1.7 or greater (that is, any web script not explicitly opted into JS1.7+ with a <script type>). r=brendan
authorJeff Walden <jwalden@mit.edu>
Mon, 24 Jan 2011 07:26:26 -0800
changeset 61228 3d6533055424fa46de6e9ac797e61aad3ad37501
parent 61227 b21d0f75e50a22a9919a5fa89d6531db5d0986bd
child 61229 9de332a8e330844d52d9ebd4ab1255a7acb2bc5d
push id18277
push usercleary@mozilla.com
push dateTue, 25 Jan 2011 03:52:51 +0000
treeherdermozilla-central@7ee91bd90e7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbrendan
bugs497869
milestone2.0b10pre
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 497869 - Forbid let and yield in strict mode code in scripts which are not JS1.7 or greater (that is, any web script not explicitly opted into JS1.7+ with a <script type>). r=brendan
js/src/jsscan.cpp
js/src/tests/ecma_5/misc/future-reserved-words.js
--- a/js/src/jsscan.cpp
+++ b/js/src/jsscan.cpp
@@ -1050,20 +1050,33 @@ TokenStream::getTokenInternal()
             } else if (kw->tokentype == TOK_STRICT_RESERVED) {
                 if (isStrictMode()
                     ? !ReportStrictModeError(cx, this, NULL, NULL, JSMSG_RESERVED_ID, kw->chars)
                     : !ReportCompileErrorNumber(cx, this, NULL,
                                                 JSREPORT_STRICT | JSREPORT_WARNING,
                                                 JSMSG_RESERVED_ID, kw->chars)) {
                     goto error;
                 }
-            } else if (kw->version <= VersionNumber(version)) {
-                tt = kw->tokentype;
-                tp->t_op = (JSOp) kw->op;
-                goto out;
+            } else {
+                if (kw->version <= VersionNumber(version)) {
+                    tt = kw->tokentype;
+                    tp->t_op = (JSOp) kw->op;
+                    goto out;
+                }
+
+                /*
+                 * let/yield are a Mozilla extension starting in JS1.7. If we
+                 * aren't parsing for a version supporting these extensions,
+                 * conform to ES5 and forbid these names in strict mode.
+                 */
+                if ((kw->tokentype == TOK_LET || kw->tokentype == TOK_YIELD) &&
+                    !ReportStrictModeError(cx, this, NULL, NULL, JSMSG_RESERVED_ID, kw->chars))
+                {
+                    goto error;
+                }
             }
         }
 
         atom = atomize(cx, tokenbuf);
         if (!atom)
             goto error;
         tp->t_op = JSOP_NAME;
         tp->t_atom = atom;
--- a/js/src/tests/ecma_5/misc/future-reserved-words.js
+++ b/js/src/tests/ecma_5/misc/future-reserved-words.js
@@ -9,35 +9,37 @@ var summary = "Implement FutureReservedW
 
 print(BUGNUMBER + ": " + summary);
 
 /**************
  * BEGIN TEST *
  **************/
 
 var futureReservedWords =
-  ["class",
+  [
+   "class",
    // "const", // Mozilla extension enabled even for versionless code
    "enum",
    "export",
    "extends",
    "import",
-   "super"];
+   "super",
+  ];
 
 var strictFutureReservedWords =
   [
    "implements",
    "interface",
-   // "let", // Mozilla extension, strict checks disabled for now
+   "let", // enabled: this file doesn't execute as JS1.7
    "package",
    "private",
    "protected",
    "public",
    "static",
-   // "yield", // Mozilla extension, strict checks disabled for now
+   "yield", // enabled: this file doesn't execute as JS1.7
   ];
 
 function testWord(word, expectNormal, expectStrict)
 {
   var actual, status;
 
   // USE IN VARIABLE DECLARATION