mirror of
https://github.com/bellard/quickjs.git
synced 2025-05-11 10:54:20 +08:00
fixed the delete operator with global variables
This commit is contained in:
parent
894ce9de1c
commit
2d4e1cc20c
25
quickjs.c
25
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user