ref: 63a542aa08477b30e3ce3f7dcceb347396ee4844
parent: 62c6e3f62cf79731d34d25bb2a96c14352099856
author: Tor Andersson <tor.andersson@artifex.com>
date: Wed Jan 7 16:34:25 EST 2015
strict mode: No duplicate formal parameters.
--- a/jscompile.c
+++ b/jscompile.c
@@ -114,13 +114,19 @@
return F->strlen++;
}
-static void addlocal(JF, const char *name, int reuse)
+static void addlocal(JF, js_Ast *ident, int reuse)
{
- if (reuse) {
+ const char *name = ident->string;
+ if (reuse || J->strict) {
unsigned int i;
- for (i = 0; i < F->varlen; ++i)
- if (!strcmp(F->vartab[i], name))
- return;
+ for (i = 0; i < F->varlen; ++i) {
+ if (!strcmp(F->vartab[i], name)) {
+ if (reuse)
+ return;
+ if (J->strict)
+ jsC_error(J, ident, "duplicate formal parameter '%s'", name);
+ }
+ }
}
if (F->varlen >= F->varcap) {
F->varcap = F->varcap ? F->varcap * 2 : 16;
@@ -1178,7 +1184,7 @@
{
F->numparams = listlength(list);
while (list) {
- addlocal(J, F, list->a->string, 0);
+ addlocal(J, F, list->a, 0);
list = list->b;
}
}
@@ -1190,7 +1196,7 @@
if (node->type == EXP_VAR) {
if (F->lightweight)
- addlocal(J, F, node->a->string, 1);
+ addlocal(J, F, node->a, 1);
else
emitstring(J, F, OP_DEFVAR, node->a->string);
}
@@ -1229,7 +1235,7 @@
if (name) {
emit(J, F, OP_CURRENT);
if (F->lightweight) {
- addlocal(J, F, name->string, 0);
+ addlocal(J, F, name, 0);
emit(J, F, OP_INITLOCAL);
emitraw(J, F, findlocal(J, F, name->string));
} else {