Skip to content

Commit d50d6ca

Browse files
Fabrice Bellardpast-due
Fabrice Bellard
authored andcommitted
Fixed the delete operator with global variables
bellard/quickjs@2d4e1cc
1 parent a241f2a commit d50d6ca

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

quickjs.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10124,6 +10124,29 @@ static int JS_SetGlobalVar(JSContext *ctx, JSAtom prop, JSValue val,
1012410124
return JS_SetPropertyInternal(ctx, ctx->global_obj, prop, val, flags);
1012510125
}
1012610126

10127+
/* return -1, FALSE or TRUE */
10128+
static int JS_DeleteGlobalVar(JSContext *ctx, JSAtom prop)
10129+
{
10130+
JSObject *p;
10131+
JSShapeProperty *prs;
10132+
JSProperty *pr;
10133+
int ret;
10134+
10135+
/* 9.1.1.4.7 DeleteBinding ( N ) */
10136+
p = JS_VALUE_GET_OBJ(ctx->global_var_obj);
10137+
prs = find_own_property(&pr, p, prop);
10138+
if (prs)
10139+
return FALSE; /* lexical variables cannot be deleted */
10140+
ret = JS_HasProperty(ctx, ctx->global_obj, prop);
10141+
if (ret < 0)
10142+
return -1;
10143+
if (ret) {
10144+
return JS_DeleteProperty(ctx, ctx->global_obj, prop, 0);
10145+
} else {
10146+
return TRUE;
10147+
}
10148+
}
10149+
1012710150
/* return -1, false or true. return false if not configurable or
1012810151
invalid object. return -1 in case of exception.
1012910152
flags can be 0, JS_PROP_THROW or JS_PROP_THROW_STRICT */
@@ -18669,7 +18692,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
1866918692
pc += 4;
1867018693

1867118694
sf->cur_pc = pc;
18672-
ret = JS_DeleteProperty(ctx, ctx->global_obj, atom, 0);
18695+
ret = JS_DeleteGlobalVar(ctx, atom);
1867318696
if (unlikely(ret < 0))
1867418697
goto exception;
1867518698
*sp++ = js_bool(ret);

0 commit comments

Comments
 (0)