Skip to content

Commit 2d4e1cc

Browse files
author
Fabrice Bellard
committed
fixed the delete operator with global variables
1 parent 894ce9d commit 2d4e1cc

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
@@ -10098,6 +10098,29 @@ static int JS_SetGlobalVar(JSContext *ctx, JSAtom prop, JSValue val,
1009810098
return JS_SetPropertyInternal(ctx, ctx->global_obj, prop, val, ctx->global_obj, flags);
1009910099
}
1010010100

10101+
/* return -1, FALSE or TRUE */
10102+
static int JS_DeleteGlobalVar(JSContext *ctx, JSAtom prop)
10103+
{
10104+
JSObject *p;
10105+
JSShapeProperty *prs;
10106+
JSProperty *pr;
10107+
int ret;
10108+
10109+
/* 9.1.1.4.7 DeleteBinding ( N ) */
10110+
p = JS_VALUE_GET_OBJ(ctx->global_var_obj);
10111+
prs = find_own_property(&pr, p, prop);
10112+
if (prs)
10113+
return FALSE; /* lexical variables cannot be deleted */
10114+
ret = JS_HasProperty(ctx, ctx->global_obj, prop);
10115+
if (ret < 0)
10116+
return -1;
10117+
if (ret) {
10118+
return JS_DeleteProperty(ctx, ctx->global_obj, prop, 0);
10119+
} else {
10120+
return TRUE;
10121+
}
10122+
}
10123+
1010110124
/* return -1, FALSE or TRUE. return FALSE if not configurable or
1010210125
invalid object. return -1 in case of exception.
1010310126
flags can be 0, JS_PROP_THROW or JS_PROP_THROW_STRICT */
@@ -18490,7 +18513,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
1849018513
pc += 4;
1849118514
sf->cur_pc = pc;
1849218515

18493-
ret = JS_DeleteProperty(ctx, ctx->global_obj, atom, 0);
18516+
ret = JS_DeleteGlobalVar(ctx, atom);
1849418517
if (unlikely(ret < 0))
1849518518
goto exception;
1849618519
*sp++ = JS_NewBool(ctx, ret);

0 commit comments

Comments
 (0)