Bug 343675: allow to use keywords as function names. r=brendan

This commit is contained in:
igor.bukanov%gmail.com 2006-09-07 11:28:30 +00:00
Родитель 9c24e1d492
Коммит 68e51513e2
1 изменённых файлов: 17 добавлений и 3 удалений

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

@ -1034,11 +1034,11 @@ FunctionDef(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc,
{ {
JSOp op, prevop; JSOp op, prevop;
JSParseNode *pn, *body, *result; JSParseNode *pn, *body, *result;
JSTokenType tt;
JSAtom *funAtom, *objAtom; JSAtom *funAtom, *objAtom;
JSStackFrame *fp; JSStackFrame *fp;
JSObject *varobj, *pobj; JSObject *varobj, *pobj;
JSAtomListElement *ale; JSAtomListElement *ale;
JSTokenType tt;
JSProperty *prop; JSProperty *prop;
JSFunction *fun; JSFunction *fun;
JSTreeContext funtc; JSTreeContext funtc;
@ -1055,7 +1055,15 @@ FunctionDef(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc,
return NULL; return NULL;
/* Scan the optional function name into funAtom. */ /* Scan the optional function name into funAtom. */
funAtom = js_MatchToken(cx, ts, TOK_NAME) ? CURRENT_TOKEN(ts).t_atom : NULL; ts->flags |= TSF_KEYWORD_IS_NAME;
tt = js_GetToken(cx, ts);
ts->flags &= ~TSF_KEYWORD_IS_NAME;
if (tt == TOK_NAME) {
funAtom = CURRENT_TOKEN(ts).t_atom;
} else {
funAtom = NULL;
js_UngetToken(ts);
}
/* Find the nearest variable-declaring scope and use it as our parent. */ /* Find the nearest variable-declaring scope and use it as our parent. */
fp = cx->fp; fp = cx->fp;
@ -2500,7 +2508,10 @@ Statement(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc)
case TOK_FUNCTION: case TOK_FUNCTION:
#if JS_HAS_XML_SUPPORT #if JS_HAS_XML_SUPPORT
if (js_PeekToken(cx, ts) == TOK_DBLCOLON) ts->flags |= TSF_KEYWORD_IS_NAME;
tt = js_PeekToken(cx, ts);
ts->flags &= ~TSF_KEYWORD_IS_NAME;
if (tt == TOK_DBLCOLON)
goto expression; goto expression;
#endif #endif
return FunctionStmt(cx, ts, tc); return FunctionStmt(cx, ts, tc);
@ -5063,7 +5074,9 @@ PrimaryExpr(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc,
switch (tt) { switch (tt) {
case TOK_FUNCTION: case TOK_FUNCTION:
#if JS_HAS_XML_SUPPORT #if JS_HAS_XML_SUPPORT
ts->flags |= TSF_KEYWORD_IS_NAME;
if (js_MatchToken(cx, ts, TOK_DBLCOLON)) { if (js_MatchToken(cx, ts, TOK_DBLCOLON)) {
ts->flags &= ~TSF_KEYWORD_IS_NAME;
pn2 = NewParseNode(cx, ts, PN_NULLARY, tc); pn2 = NewParseNode(cx, ts, PN_NULLARY, tc);
if (!pn2) if (!pn2)
return NULL; return NULL;
@ -5073,6 +5086,7 @@ PrimaryExpr(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc,
return NULL; return NULL;
break; break;
} }
ts->flags &= ~TSF_KEYWORD_IS_NAME;
#endif #endif
pn = FunctionExpr(cx, ts, tc); pn = FunctionExpr(cx, ts, tc);
if (!pn) if (!pn)