summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabrice Bellard <fabrice@bellard.org>2025-04-28 16:32:23 +0200
committerFabrice Bellard <fabrice@bellard.org>2025-04-28 16:32:23 +0200
commit2d4e1cc20cc7c1fe234d0d03857758a787a9c6f6 (patch)
treed231a5ecc555821d06000c6403d7077059db86de
parent894ce9de1c76acb6b84385e152ff1cd6cb6626bd (diff)
downloadquickjs-2d4e1cc20cc7c1fe234d0d03857758a787a9c6f6.tar.gz
quickjs-2d4e1cc20cc7c1fe234d0d03857758a787a9c6f6.zip
fixed the delete operator with global variables
-rw-r--r--quickjs.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/quickjs.c b/quickjs.c
index adfd93e..bae3ea7 100644
--- a/quickjs.c
+++ b/quickjs.c
@@ -10098,6 +10098,29 @@ static int JS_SetGlobalVar(JSContext *ctx, JSAtom prop, JSValue val,
return JS_SetPropertyInternal(ctx, ctx->global_obj, prop, val, ctx->global_obj, flags);
}
+/* return -1, FALSE or TRUE */
+static int JS_DeleteGlobalVar(JSContext *ctx, JSAtom prop)
+{
+ JSObject *p;
+ JSShapeProperty *prs;
+ JSProperty *pr;
+ int ret;
+
+ /* 9.1.1.4.7 DeleteBinding ( N ) */
+ p = JS_VALUE_GET_OBJ(ctx->global_var_obj);
+ prs = find_own_property(&pr, p, prop);
+ if (prs)
+ return FALSE; /* lexical variables cannot be deleted */
+ ret = JS_HasProperty(ctx, ctx->global_obj, prop);
+ if (ret < 0)
+ return -1;
+ if (ret) {
+ return JS_DeleteProperty(ctx, ctx->global_obj, prop, 0);
+ } else {
+ return TRUE;
+ }
+}
+
/* return -1, FALSE or TRUE. return FALSE if not configurable or
invalid object. return -1 in case of exception.
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,
pc += 4;
sf->cur_pc = pc;
- ret = JS_DeleteProperty(ctx, ctx->global_obj, atom, 0);
+ ret = JS_DeleteGlobalVar(ctx, atom);
if (unlikely(ret < 0))
goto exception;
*sp++ = JS_NewBool(ctx, ret);