diff --git a/js/src/jsparse.cpp b/js/src/jsparse.cpp index d36ce1dae230..b4dea33ed1ad 100644 --- a/js/src/jsparse.cpp +++ b/js/src/jsparse.cpp @@ -8066,18 +8066,23 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) return NULL; pn->pn_num = (jsint) tokenStream.currentToken().t_dval; tt = tokenStream.getToken(TSF_OPERAND); - if (tt == TOK_USESHARP || tt == TOK_DEFSHARP || -#if JS_HAS_XML_SUPPORT - tt == TOK_STAR || tt == TOK_AT || - tt == TOK_XMLSTAGO /* XXXbe could be sharp? */ || -#endif - tt == TOK_STRING || tt == TOK_NUMBER || tt == TOK_PRIMARY) { - reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_SHARP_VAR_DEF); - return NULL; - } pn->pn_kid = primaryExpr(tt, JS_FALSE); if (!pn->pn_kid) return NULL; + if (PN_TYPE(pn->pn_kid) == TOK_USESHARP || + PN_TYPE(pn->pn_kid) == TOK_DEFSHARP || +#if JS_HAS_XML_SUPPORT + PN_TYPE(pn->pn_kid) == TOK_XMLCOMMENT || + PN_TYPE(pn->pn_kid) == TOK_XMLCDATA || + PN_TYPE(pn->pn_kid) == TOK_XMLPTAGC || + PN_TYPE(pn->pn_kid) == TOK_XMLELEM || +#endif + PN_TYPE(pn->pn_kid) == TOK_STRING || + PN_TYPE(pn->pn_kid) == TOK_NUMBER || + PN_TYPE(pn->pn_kid) == TOK_PRIMARY) { + reportErrorNumber(pn->pn_kid, JSREPORT_ERROR, JSMSG_BAD_SHARP_VAR_DEF); + return NULL; + } if (!tc->ensureSharpSlots()) return NULL; break; diff --git a/js/src/tests/e4x/extensions/jstests.list b/js/src/tests/e4x/extensions/jstests.list index 8f0e6b60d64d..495fa6c0d694 100644 --- a/js/src/tests/e4x/extensions/jstests.list +++ b/js/src/tests/e4x/extensions/jstests.list @@ -5,6 +5,7 @@ script regress-313080.js script regress-321547.js script regress-327534.js script regress-327897.js +script regress-335051.js script regress-337226.js script regress-352846-01.js script regress-352846-02.js diff --git a/js/src/tests/e4x/extensions/regress-335051.js b/js/src/tests/e4x/extensions/regress-335051.js new file mode 100644 index 000000000000..6ca5a9091081 --- /dev/null +++ b/js/src/tests/e4x/extensions/regress-335051.js @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + * Contributor: + * rje(a)dbc.dk + */ + +var gTestfile = 'regress-335051.js'; +//----------------------------------------------------------------------------- +var BUGNUMBER = 335051; +var summary = 'E4X literals should be acceptable values for sharp variables'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- +function testSyntax(syntax, isValid) { + var result; + try { + eval(syntax); + result = true; + } catch(exception) { + if (SyntaxError.prototype.isPrototypeOf(exception)) { + result = false; + } + } + reportCompare(isValid, result, "test " + (isValid?"":"in") + "valid syntax: " + syntax); +} + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + var oldVersion = false; + + testSyntax("#1={}", true); + testSyntax("#1=[]", true); + testSyntax("#1=([])", true); + + testSyntax("#1=[1, 2, 3]", true); + testSyntax("#1={a:1, b:2}", true); + + testSyntax("#1=function() { }", true); + testSyntax("#1=(new Date())", true); + + testSyntax("#1=", false); + testSyntax("#1=", false); + testSyntax("#1=b", false); + testSyntax("[#1=b, #1#]", false); + testSyntax("#1=()", false); + testSyntax("#1=()", false); + + testSyntax("#1=123", false); + testSyntax("#1='foo'", false); + testSyntax("#1=1+2", false); + testSyntax("#1=-1", false); + testSyntax("#1=(123)", false); + testSyntax("#1=true", false); + + exitFunc ('test'); +}