Skip to content

Commit 446099a

Browse files
committed
added Object.hasOwn()
1 parent b9f5880 commit 446099a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

quickjs.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36882,6 +36882,32 @@ static JSValue js_object_hasOwnProperty(JSContext *ctx, JSValueConst this_val,
3688236882
return JS_NewBool(ctx, ret);
3688336883
}
3688436884

36885+
static JSValue js_object_hasOwn(JSContext *ctx, JSValueConst this_val,
36886+
int argc, JSValueConst *argv)
36887+
{
36888+
JSValue obj;
36889+
JSAtom atom;
36890+
JSObject *p;
36891+
BOOL ret;
36892+
36893+
obj = JS_ToObject(ctx, argv[0]);
36894+
if (JS_IsException(obj))
36895+
return obj;
36896+
atom = JS_ValueToAtom(ctx, argv[1]);
36897+
if (unlikely(atom == JS_ATOM_NULL)) {
36898+
JS_FreeValue(ctx, obj);
36899+
return JS_EXCEPTION;
36900+
}
36901+
p = JS_VALUE_GET_OBJ(obj);
36902+
ret = JS_GetOwnPropertyInternal(ctx, NULL, p, atom);
36903+
JS_FreeAtom(ctx, atom);
36904+
JS_FreeValue(ctx, obj);
36905+
if (ret < 0)
36906+
return JS_EXCEPTION;
36907+
else
36908+
return JS_NewBool(ctx, ret);
36909+
}
36910+
3688536911
static JSValue js_object_valueOf(JSContext *ctx, JSValueConst this_val,
3688636912
int argc, JSValueConst *argv)
3688736913
{
@@ -37454,6 +37480,7 @@ static const JSCFunctionListEntry js_object_funcs[] = {
3745437480
//JS_CFUNC_DEF("__getObjectData", 1, js_object___getObjectData ),
3745537481
//JS_CFUNC_DEF("__setObjectData", 2, js_object___setObjectData ),
3745637482
JS_CFUNC_DEF("fromEntries", 1, js_object_fromEntries ),
37483+
JS_CFUNC_DEF("hasOwn", 2, js_object_hasOwn ),
3745737484
};
3745837485

3745937486
static const JSCFunctionListEntry js_object_proto_funcs[] = {

0 commit comments

Comments
 (0)