Bug 701886: Don't redefine/reset existing vars in script code.

If a var is already declared in the same scope, don't redeclare it.
Should fix issues with "var" used in eval() code.
This commit is contained in:
Tor Andersson
2021-03-04 12:20:46 +01:00
parent 9f34a074eb
commit a34fdf2af8

View File

@@ -1038,9 +1038,12 @@ static void jsR_callscript(js_State *J, int n, js_Function *F, js_Environment *s
js_pop(J, n);
for (i = 0; i < F->varlen; ++i) {
js_pushundefined(J);
js_initvar(J, F->vartab[i], -1);
js_pop(J, 1);
/* Bug 701886: don't redefine existing vars in eval/scripts */
if (!js_hasvar(J, F->vartab[i])) {
js_pushundefined(J);
js_initvar(J, F->vartab[i], -1);
js_pop(J, 1);
}
}
jsR_run(J, F);