mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-13 20:14:57 -10:00
bug 455981 - duplicated arguments no longer supported when destructuring pattern is used. r=brendan
This commit is contained in:
1 parent
c0f380c2f1
commit
17800844f7
2 files changed
+46
-38
No files matched your search
+1
-1
@@ -155,7 +155,7 @@ MSG_DEF(JSMSG_CURLY_BEFORE_BODY, 72, 0, JSEXN_SYNTAXERR, "missing { before
|
||||
MSG_DEF(JSMSG_CURLY_AFTER_BODY, 73, 0, JSEXN_SYNTAXERR, "missing } after function body")
|
||||
MSG_DEF(JSMSG_PAREN_BEFORE_COND, 74, 0, JSEXN_SYNTAXERR, "missing ( before condition")
|
||||
MSG_DEF(JSMSG_PAREN_AFTER_COND, 75, 0, JSEXN_SYNTAXERR, "missing ) after condition")
|
||||
MSG_DEF(JSMSG_UNUSED76, 76, 0, JSEXN_NONE, "unused76")
|
||||
MSG_DEF(JSMSG_DESTRUCT_DUP_ARG, 76, 0, JSEXN_SYNTAXERR, "duplicate argument is mixed with destructuring pattern")
|
||||
MSG_DEF(JSMSG_NAME_AFTER_DOT, 77, 0, JSEXN_SYNTAXERR, "missing name after . operator")
|
||||
MSG_DEF(JSMSG_BRACKET_IN_INDEX, 78, 0, JSEXN_SYNTAXERR, "missing ] in index expression")
|
||||
MSG_DEF(JSMSG_UNUSED79, 79, 0, JSEXN_NONE, "unused79")
|
||||
|
||||
+45
-37
@@ -995,29 +995,6 @@ struct BindData {
|
||||
} u;
|
||||
};
|
||||
|
||||
static JSBool
|
||||
BindArg(JSContext *cx, JSAtom *atom, JSTreeContext *tc)
|
||||
{
|
||||
const char *name;
|
||||
|
||||
/*
|
||||
* Check for a duplicate parameter name, a "feature" required by ECMA-262.
|
||||
*/
|
||||
JS_ASSERT(tc->flags & TCF_IN_FUNCTION);
|
||||
if (js_LookupLocal(cx, tc->u.fun, atom, NULL) != JSLOCAL_NONE) {
|
||||
name = js_AtomToPrintableString(cx, atom);
|
||||
if (!name ||
|
||||
!js_ReportCompileErrorNumber(cx, TS(tc->parseContext), NULL,
|
||||
JSREPORT_WARNING | JSREPORT_STRICT,
|
||||
JSMSG_DUPLICATE_FORMAL,
|
||||
name)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return js_AddLocal(cx, tc->u.fun, atom, JSLOCAL_ARG);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
BindLocalVariable(JSContext *cx, JSFunction *fun, JSAtom *atom,
|
||||
JSLocalKind localKind)
|
||||
@@ -1049,7 +1026,6 @@ BindDestructuringArg(JSContext *cx, BindData *data, JSAtom *atom,
|
||||
JSTreeContext *tc)
|
||||
{
|
||||
JSAtomListElement *ale;
|
||||
const char *name;
|
||||
|
||||
JS_ASSERT(tc->flags & TCF_IN_FUNCTION);
|
||||
ATOM_LIST_SEARCH(ale, &tc->decls, atom);
|
||||
@@ -1061,19 +1037,11 @@ BindDestructuringArg(JSContext *cx, BindData *data, JSAtom *atom,
|
||||
}
|
||||
|
||||
if (js_LookupLocal(cx, tc->u.fun, atom, NULL) != JSLOCAL_NONE) {
|
||||
name = js_AtomToPrintableString(cx, atom);
|
||||
if (!name ||
|
||||
!js_ReportCompileErrorNumber(cx, TS(tc->parseContext), data->pn,
|
||||
JSREPORT_WARNING | JSREPORT_STRICT,
|
||||
JSMSG_DUPLICATE_FORMAL,
|
||||
name)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
} else {
|
||||
if (!BindLocalVariable(cx, tc->u.fun, atom, JSLOCAL_VAR))
|
||||
return JS_FALSE;
|
||||
js_ReportCompileErrorNumber(cx, TS(tc->parseContext), NULL,
|
||||
JSREPORT_ERROR, JSMSG_DESTRUCT_DUP_ARG);
|
||||
return JS_FALSE;
|
||||
}
|
||||
return JS_TRUE;
|
||||
return BindLocalVariable(cx, tc->u.fun, atom, JSLOCAL_VAR);
|
||||
}
|
||||
#endif /* JS_HAS_DESTRUCTURING */
|
||||
|
||||
@@ -1130,6 +1098,7 @@ FunctionDef(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc,
|
||||
JSTreeContext funtc;
|
||||
#if JS_HAS_DESTRUCTURING
|
||||
JSParseNode *item, *list = NULL;
|
||||
bool destructuringArg = false, duplicatedArg = false;
|
||||
#endif
|
||||
|
||||
/* Make a TOK_FUNCTION node. */
|
||||
@@ -1254,6 +1223,11 @@ FunctionDef(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc,
|
||||
JSParseNode *lhs, *rhs;
|
||||
jsint slot;
|
||||
|
||||
/* See comment below in the TOK_NAME case. */
|
||||
if (duplicatedArg)
|
||||
goto report_dup_and_destructuring;
|
||||
destructuringArg = true;
|
||||
|
||||
/*
|
||||
* A destructuring formal parameter turns into one or more
|
||||
* local variables initialized from properties of a single
|
||||
@@ -1304,14 +1278,48 @@ FunctionDef(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc,
|
||||
#endif /* JS_HAS_DESTRUCTURING */
|
||||
|
||||
case TOK_NAME:
|
||||
if (!BindArg(cx, CURRENT_TOKEN(ts).t_atom, &funtc))
|
||||
{
|
||||
/*
|
||||
* Check for a duplicate parameter name, a "feature" that
|
||||
* ECMA-262 requires. Still if any argument is a destructuring
|
||||
* pattern, we will report error either now or later, when we
|
||||
* find the first pattern.
|
||||
*/
|
||||
JSAtom *atom = CURRENT_TOKEN(ts).t_atom;
|
||||
if (js_LookupLocal(cx, fun, atom, NULL) != JSLOCAL_NONE) {
|
||||
#if JS_HAS_DESTRUCTURING
|
||||
if (destructuringArg)
|
||||
goto report_dup_and_destructuring;
|
||||
duplicatedArg = true;
|
||||
#endif
|
||||
const char *name = js_AtomToPrintableString(cx, atom);
|
||||
if (!name ||
|
||||
!js_ReportCompileErrorNumber(cx, TS(tc->parseContext),
|
||||
NULL,
|
||||
JSREPORT_WARNING |
|
||||
JSREPORT_STRICT,
|
||||
JSMSG_DUPLICATE_FORMAL,
|
||||
name)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (!js_AddLocal(cx, fun, atom, JSLOCAL_ARG))
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
js_ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR,
|
||||
JSMSG_MISSING_FORMAL);
|
||||
return NULL;
|
||||
|
||||
#if JS_HAS_DESTRUCTURING
|
||||
report_dup_and_destructuring:
|
||||
js_ReportCompileErrorNumber(cx, TS(tc->parseContext), NULL,
|
||||
JSREPORT_ERROR,
|
||||
JSMSG_DESTRUCT_DUP_ARG);
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
} while (js_MatchToken(cx, ts, TOK_COMMA));
|
||||
|
||||
|
||||
Reference in new issue
Block a user