add property get
This commit is contained in:
@@ -812,7 +812,6 @@ struct JSObject {
|
||||
uint8_t free_mark : 1; /* only used when freeing objects with cycles */
|
||||
uint8_t is_exotic : 1; /* TRUE if object has exotic property handlers */
|
||||
uint8_t fast_array : 1; /* TRUE if u.array is used for get/put (for JS_CLASS_ARRAY and typed arrays) */
|
||||
uint8_t is_constructor : 1; /* TRUE if object is a constructor function */
|
||||
uint8_t has_immutable_prototype : 1; /* cannot modify the prototype */
|
||||
uint8_t tmp_mark : 1; /* used in JS_WriteObjectRec() */
|
||||
uint16_t class_id; /* see JS_CLASS_x */
|
||||
@@ -4760,7 +4759,6 @@ static JSValue JS_NewObjectFromShape(JSContext *ctx, JSShape *sh, JSClassID clas
|
||||
p->free_mark = 0;
|
||||
p->is_exotic = 0;
|
||||
p->fast_array = 0;
|
||||
p->is_constructor = 0;
|
||||
p->has_immutable_prototype = 0;
|
||||
p->tmp_mark = 0;
|
||||
p->object_key_atom = JS_ATOM_NULL;
|
||||
@@ -4975,10 +4973,7 @@ static JSValue JS_NewCFunction3(JSContext *ctx, JSCFunction *func,
|
||||
p->u.cfunc.length = length;
|
||||
p->u.cfunc.cproto = cproto;
|
||||
p->u.cfunc.magic = magic;
|
||||
p->is_constructor = (cproto == JS_CFUNC_constructor ||
|
||||
cproto == JS_CFUNC_constructor_magic ||
|
||||
cproto == JS_CFUNC_constructor_or_func ||
|
||||
cproto == JS_CFUNC_constructor_or_func_magic);
|
||||
/* Note: is_constructor bit removed - constructors are called as regular functions */
|
||||
if (!name)
|
||||
name = "";
|
||||
name_atom = JS_NewAtom(ctx, name);
|
||||
@@ -8220,6 +8215,33 @@ int JS_SetPropertyStr(JSContext *ctx, JSValueConst this_obj,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Property access with JSValue key - supports object keys via symbols */
|
||||
JSValue JS_GetPropertyKey(JSContext *ctx, JSValueConst this_obj, JSValueConst key)
|
||||
{
|
||||
JSAtom atom;
|
||||
JSValue ret;
|
||||
atom = JS_ValueToAtom(ctx, key);
|
||||
if (atom == JS_ATOM_NULL)
|
||||
return JS_EXCEPTION;
|
||||
ret = JS_GetProperty(ctx, this_obj, atom);
|
||||
JS_FreeAtom(ctx, atom);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int JS_SetPropertyKey(JSContext *ctx, JSValueConst this_obj, JSValueConst key, JSValue val)
|
||||
{
|
||||
JSAtom atom;
|
||||
int ret;
|
||||
atom = JS_ValueToAtom(ctx, key);
|
||||
if (atom == JS_ATOM_NULL) {
|
||||
JS_FreeValue(ctx, val);
|
||||
return -1;
|
||||
}
|
||||
ret = JS_SetPropertyInternal(ctx, this_obj, atom, val, this_obj, JS_PROP_THROW);
|
||||
JS_FreeAtom(ctx, atom);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* compute the property flags. For each flag: (JS_PROP_HAS_x forces
|
||||
it, otherwise def_flags is used)
|
||||
Note: makes assumption about the bit pattern of the flags
|
||||
|
||||
@@ -721,6 +721,11 @@ int JS_SetPropertyInt64(JSContext *ctx, JSValueConst this_obj,
|
||||
int64_t idx, JSValue val);
|
||||
int JS_SetPropertyStr(JSContext *ctx, JSValueConst this_obj,
|
||||
const char *prop, JSValue val);
|
||||
|
||||
/* Property access with JSValue key (supports object keys via symbols) */
|
||||
JSValue JS_GetPropertyKey(JSContext *ctx, JSValueConst this_obj, JSValueConst key);
|
||||
int JS_SetPropertyKey(JSContext *ctx, JSValueConst this_obj, JSValueConst key, JSValue val);
|
||||
|
||||
int JS_HasProperty(JSContext *ctx, JSValueConst this_obj, JSAtom prop);
|
||||
int JS_IsExtensible(JSContext *ctx, JSValueConst obj);
|
||||
int JS_PreventExtensions(JSContext *ctx, JSValueConst obj);
|
||||
|
||||
Reference in New Issue
Block a user