Bug 772691 - Disallow XML in function defaults. r=njn

This commit is contained in:
Benjamin Peterson 2012-07-10 21:41:00 -04:00
Родитель 86de31fdd0
Коммит 67b19a9db9
4 изменённых файлов: 39 добавлений и 5 удалений

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

@ -7019,31 +7019,38 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
#if JS_HAS_XML_SUPPORT
case TOK_AT:
case TOK_STAR:
if (!allowsXML())
goto syntaxerror;
pn = starOrAtPropertyIdentifier(tt);
break;
case TOK_XMLSTAGO:
if (!allowsXML())
goto syntaxerror;
pn = xmlElementOrListRoot(true);
if (!pn)
return NULL;
break;
case TOK_XMLCDATA:
JS_ASSERT(allowsXML());
if (!allowsXML())
goto syntaxerror;
pn = atomNode(PNK_XMLCDATA, JSOP_XMLCDATA);
if (!pn)
return NULL;
break;
case TOK_XMLCOMMENT:
JS_ASSERT(allowsXML());
if (!allowsXML())
goto syntaxerror;
pn = atomNode(PNK_XMLCOMMENT, JSOP_XMLCOMMENT);
if (!pn)
return NULL;
break;
case TOK_XMLPI: {
JS_ASSERT(allowsXML());
if (!allowsXML())
goto syntaxerror;
const Token &tok = tokenStream.currentToken();
pn = new_<XMLProcessingInstruction>(tok.xmlPITarget(), tok.xmlPIData(), tok.pos);
if (!pn)
@ -7112,6 +7119,7 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
/* The scanner or one of its subroutines reported the error. */
return NULL;
syntaxerror:
default:
reportError(NULL, JSMSG_SYNTAX_ERROR);
return NULL;

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

@ -230,8 +230,18 @@ struct Parser : private AutoGCRooter
ParseNode *identifierName(bool afterDoubleDot);
#if JS_HAS_XML_SUPPORT
// True if E4X syntax is allowed in the current syntactic context.
bool allowsXML() const { return tokenStream.allowsXML(); }
// True if E4X syntax is allowed in the current syntactic context. Note this
// function may be false while TokenStream::allowsXML() is true!
// Specifically, when strictModeState is not STRICT, Parser::allowsXML()
// will be false, where TokenStream::allowsXML() is only false when
// strictModeState is STRICT. The reason for this is when we are parsing the
// directive prologue, the tokenizer looks ahead into the body of the
// function. So, we have to be lenient in case the function is not
// strict. This also effectively bans XML in function defaults. See bug
// 772691.
bool allowsXML() const {
return tc->sc->strictModeState == StrictMode::NOTSTRICT && tokenStream.allowsXML();
}
ParseNode *endBracketedExpr();

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

@ -500,6 +500,8 @@ class TokenStream
/* Note that the version and hasMoarXML can get out of sync via setMoarXML. */
JSVersion versionNumber() const { return VersionNumber(version); }
JSVersion versionWithFlags() const { return version; }
// TokenStream::allowsXML() can be true even if Parser::allowsXML() is
// false. Read the comment at Parser::allowsXML() to find out why.
bool allowsXML() const { return allowXML && strictModeState() != StrictMode::STRICT; }
bool hasMoarXML() const { return moarXML || VersionShouldParseXML(versionNumber()); }
void setMoarXML(bool enabled) { moarXML = enabled; }

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

@ -0,0 +1,14 @@
load(libdir + "asserts.js");
assertThrowsInstanceOf(function () {
eval("function f(a=<x/>) {}");
}, SyntaxError);
assertThrowsInstanceOf(function () {
eval("function f(a=<x/>) { 'use strict'; }");
}, SyntaxError);
assertThrowsInstanceOf(function () {
eval("function f(a=(function () { <x/> })) {}");
}, SyntaxError);
assertThrowsInstanceOf(function () {
eval("function f(a=(function () { <x/> })) { 'use strict'; }");
}, SyntaxError);