Bug 819509 - Reimplement banning of XML in defaults. r=njn
authorBenjamin Peterson <benjamin@python.org>
Wed, 12 Dec 2012 01:35:06 -0500
changeset 115803 d29ea23dde5f1ce72fc39795ea003a4b5c4497d2
parent 115802 fa10b335dd65339f89ecfe2a4c938596271e1b3b
child 115804 3a07784f694d2e5b4b827621d83bf0afd2a85b2e
push id24028
push useremorley@mozilla.com
push dateThu, 13 Dec 2012 15:56:02 +0000
treeherderautoland@9db79b97abbb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs819509
milestone20.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 819509 - Reimplement banning of XML in defaults. r=njn
js/src/frontend/Parser.cpp
js/src/frontend/Parser.h
js/src/frontend/TokenStream.cpp
js/src/frontend/TokenStream.h
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -1671,18 +1671,20 @@ Parser::functionArgsAndBody(ParseNode *p
     /* Initialize early for possible flags mutation via destructuringExpr. */
     ParseContext funpc(this, funbox, outerpc->staticLevel + 1, outerpc->blockidGen);
     if (!funpc.init())
         return false;
 
     /* Now parse formal argument list and compute fun->nargs. */
     ParseNode *prelude = NULL;
     bool hasRest;
+    tokenStream.incBanXML();
     if (!functionArguments(&prelude, pn, hasRest))
         return false;
+    tokenStream.decBanXML();
 
     fun->setArgCount(funpc.numArgs());
     if (funbox->ndefaults)
         fun->setHasDefaults();
     if (hasRest)
         fun->setHasRest();
 
     if (type == Getter && fun->nargs > 0) {
--- a/js/src/frontend/Parser.h
+++ b/js/src/frontend/Parser.h
@@ -451,28 +451,17 @@ struct Parser : private AutoGCRooter
     ParseNode *returnOrYield(bool useAssignExpr);
     ParseNode *destructuringExpr(BindData *data, TokenKind tt);
 
     bool checkForFunctionNode(PropertyName *name, ParseNode *node);
 
     ParseNode *identifierName(bool afterDoubleDot);
 
 #if JS_HAS_XML_SUPPORT
-    // 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 pc->sc->strictModeState == StrictMode::NOTSTRICT && tokenStream.allowsXML();
-    }
+    bool allowsXML() const { return tokenStream.allowsXML(); }
 
     ParseNode *endBracketedExpr();
 
     ParseNode *propertySelector();
     ParseNode *qualifiedSuffix(ParseNode *pn);
     ParseNode *qualifiedIdentifier();
     ParseNode *attributeIdentifier();
     ParseNode *xmlExpr(bool inTag);
--- a/js/src/frontend/TokenStream.cpp
+++ b/js/src/frontend/TokenStream.cpp
@@ -129,17 +129,17 @@ TokenStream::TokenStream(JSContext *cx, 
     linebaseRoot(cx, &linebase),
     prevLinebaseRoot(cx, &prevLinebase),
     userbuf(base.get(), length),
     filename(options.filename),
     sourceMap(NULL),
     listenerTSData(),
     tokenbuf(cx),
     version(options.version),
-    allowXML(VersionHasAllowXML(options.version)),
+    banXML(VersionHasAllowXML(options.version) ? 0 : 1),
     moarXML(VersionHasMoarXML(options.version)),
     cx(cx),
     originPrincipals(JSScript::normalizeOriginPrincipals(options.principals,
                                                          options.originPrincipals)),
     strictModeGetter(smg)
 {
     if (originPrincipals)
         JS_HoldPrincipals(originPrincipals);
--- a/js/src/frontend/TokenStream.h
+++ b/js/src/frontend/TokenStream.h
@@ -533,21 +533,21 @@ class TokenStream
         return tok.ptr - userbuf.base();
     }
     const CharBuffer &getTokenbuf() const { return tokenbuf; }
     const char *getFilename() const { return filename; }
     unsigned getLineno() const { return lineno; }
     /* 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 allowsXML() const { return banXML == 0 && strictModeState() != StrictMode::STRICT; }
     bool hasMoarXML() const { return moarXML || VersionShouldParseXML(versionNumber()); }
     void setMoarXML(bool enabled) { moarXML = enabled; }
+    void incBanXML() { banXML++; }
+    void decBanXML() { JS_ASSERT(banXML); banXML--; }
     bool hadError() const { return !!(flags & TSF_HAD_ERROR); }
 
     bool isCurrentTokenEquality() const {
         return TokenKindIsEquality(currentToken().type);
     }
 
     bool isCurrentTokenRelational() const {
         return TokenKindIsRelational(currentToken().type);
@@ -906,17 +906,17 @@ class TokenStream
     const char          *filename;      /* input filename or null */
     jschar              *sourceMap;     /* source map's filename or null */
     void                *listenerTSData;/* listener data for this TokenStream */
     CharBuffer          tokenbuf;       /* current token string buffer */
     int8_t              oneCharTokens[128];  /* table of one-char tokens */
     bool                maybeEOL[256];       /* probabilistic EOL lookup table */
     bool                maybeStrSpecial[256];/* speeds up string scanning */
     JSVersion           version;        /* (i.e. to identify keywords) */
-    bool                allowXML;       /* see JSOPTION_ALLOW_XML */
+    unsigned            banXML;         /* see JSOPTION_ALLOW_XML */
     bool                moarXML;        /* see JSOPTION_MOAR_XML */
     JSContext           *const cx;
     JSPrincipals        *const originPrincipals;
     StrictModeGetter    *strictModeGetter; /* used to test for strict mode */
     Position            lastFunctionKeyword; /* used as a starting point for reparsing strict functions */
 };
 
 struct KeywordInfo {