summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);