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

This commit is contained in:
Jeff Walden 2011-01-24 07:26:26 -08:00
Родитель ccaa2e2118
Коммит 11e4b9c104
2 изменённых файлов: 23 добавлений и 8 удалений

Просмотреть файл

@ -1055,10 +1055,23 @@ TokenStream::getTokenInternal()
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;
}
}
}

Просмотреть файл

@ -14,25 +14,27 @@ print(BUGNUMBER + ": " + summary);
**************/
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)