Skip to content

Commit 30e4767

Browse files
Fabrice Bellardbnoordhuis
authored andcommitted
fixed lexical scope of 'this' with eval (github issue #192)
1 parent f1b7b6d commit 30e4767

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

quickjs.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28382,12 +28382,13 @@ static void add_eval_variables(JSContext *ctx, JSFunctionDef *s)
2838228382
is_arg_scope = (scope_idx == ARG_SCOPE_END);
2838328383
if (!is_arg_scope) {
2838428384
/* add unscoped variables */
28385+
/* XXX: propagate is_const and var_kind too ? */
2838528386
for(i = 0; i < fd->arg_count; i++) {
2838628387
vd = &fd->args[i];
2838728388
if (vd->var_name != JS_ATOM_NULL) {
2838828389
get_closure_var(ctx, s, fd,
28389-
TRUE, i, vd->var_name, FALSE, FALSE,
28390-
JS_VAR_NORMAL);
28390+
TRUE, i, vd->var_name, FALSE,
28391+
vd->is_lexical, JS_VAR_NORMAL);
2839128392
}
2839228393
}
2839328394
for(i = 0; i < fd->var_count; i++) {
@@ -28397,8 +28398,8 @@ static void add_eval_variables(JSContext *ctx, JSFunctionDef *s)
2839728398
vd->var_name != JS_ATOM__ret_ &&
2839828399
vd->var_name != JS_ATOM_NULL) {
2839928400
get_closure_var(ctx, s, fd,
28400-
FALSE, i, vd->var_name, FALSE, FALSE,
28401-
JS_VAR_NORMAL);
28401+
FALSE, i, vd->var_name, FALSE,
28402+
vd->is_lexical, JS_VAR_NORMAL);
2840228403
}
2840328404
}
2840428405
} else {
@@ -28407,8 +28408,8 @@ static void add_eval_variables(JSContext *ctx, JSFunctionDef *s)
2840728408
/* do not close top level last result */
2840828409
if (vd->scope_level == 0 && is_var_in_arg_scope(vd)) {
2840928410
get_closure_var(ctx, s, fd,
28410-
FALSE, i, vd->var_name, FALSE, FALSE,
28411-
JS_VAR_NORMAL);
28411+
FALSE, i, vd->var_name, FALSE,
28412+
vd->is_lexical, JS_VAR_NORMAL);
2841228413
}
2841328414
}
2841428415
}

0 commit comments

Comments
 (0)