static JSBool rpmte_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmteClass, NULL); _RESOLVE_DEBUG_ENTRY(_debug); if (flags & JSRESOLVE_ASSIGNING) { *objp = NULL; goto exit; } *objp = obj; /* XXX always resolve in this object. */ exit: return JS_TRUE; }
static JSBool rpmdir_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmdirClass, NULL); _RESOLVE_DEBUG_ENTRY(_debug < 0); if ((flags & JSRESOLVE_ASSIGNING) || (ptr == NULL)) { /* don't resolve to parent prototypes objects. */ *objp = NULL; goto exit; } *objp = obj; /* XXX always resolve in this object. */ exit: return JS_TRUE; }
static JSBool rpmhdr_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmhdrClass, NULL); Header h = ptr; JSBool ok = JS_FALSE; _RESOLVE_DEBUG_ENTRY(_debug); if ((flags & JSRESOLVE_ASSIGNING) || (h == NULL)) { /* don't resolve to parent prototypes objects. */ *objp = NULL; ok = JS_TRUE; goto exit; } if (JSVAL_IS_INT(id) || JSVAL_IS_STRING(id)) { char * s = NULL; rpmTag tag = JSVAL_IS_INT(id) ? (rpmTag) JSVAL_TO_INT(id) : tagValue(JS_EncodeString(cx, JS_ValueToString(cx, id))); JSObject * arr = rpmhdrLoadTag(cx, obj, h, tag, NULL); if (s) JS_free(cx, s); if (!JS_DefineElement(cx, obj, tag, OBJECT_TO_JSVAL(arr), NULL, NULL, JSPROP_ENUMERATE)) { *objp = NULL; goto exit; } *objp = obj; } else *objp = NULL; ok = JS_TRUE; exit: return ok; }
static JSBool rpmts_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmtsClass, NULL); rpmts ts = ptr; JSBool ok = JS_FALSE; int oc; _RESOLVE_DEBUG_ENTRY(_debug); if (flags & JSRESOLVE_ASSIGNING) { ok = JS_TRUE; goto exit; } if (JSVAL_IS_INT(id) && (oc = JSVAL_TO_INT(id)) >= 0 && oc < rpmtsNElements(ts)) { JSObject *teo = NULL; rpmte te = NULL; /* XXX rpmteLink/rpmteUnlink are no-ops */ if ((te = rpmtsElement(ts, oc)) == NULL || (teo = JS_NewObject(cx, &rpmteClass, NULL, NULL)) == NULL || !JS_SetPrivate(cx, teo, rpmteLink(te)) || !JS_DefineElement(cx, obj, oc, OBJECT_TO_JSVAL(teo), NULL, NULL, JSPROP_ENUMERATE)) { *objp = NULL; goto exit; } *objp = obj; } else *objp = NULL; ok = JS_TRUE; exit: return ok; }
static JSBool rpmaug_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL); rpmaug aug = ptr; _RESOLVE_DEBUG_ENTRY(_debug); if (ptr == NULL) { /* don't resolve to parent prototypes objects. */ *objp = NULL; goto exit; } /* Lazily resolve new strings, with duplication to Augeas defvar too. */ if ((flags & JSRESOLVE_ASSIGNING) && JSVAL_IS_STRING(id)) { const char *name = JS_GetStringBytes(JS_ValueToString(cx, id)); const char * _path; const char * _value; int xx; JSFunctionSpec *fsp; /* XXX avoid "aug.print" method namess duped into defvar space? */ for (fsp = rpmaug_funcs; fsp->name != NULL; fsp++) { if (!strcmp(fsp->name, name)) { *objp = obj; /* XXX always resolve in this object. */ goto exit; } } /* See if NAME exists in DEFVAR path. */ _path = rpmGetPath(_defvar, "/", name, NULL); _value = NULL; switch (rpmaugGet(aug, _path, &_value)) { /* XXX For now, force all defvar's to be single valued strings. */ case -1:/* multiply defined */ case 0: /* not found */ /* Create an empty Augeas defvar for NAME */ xx = rpmaugDefvar(aug, name, ""); /*@fallthrough@*/ case 1: /* found */ /* Reflect the Augeas defvar NAME into JS Aug properties. */ if (JS_DefineProperty(cx, obj, name, (_value != NULL ? STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _value)) : JSVAL_VOID), NULL, NULL, JSPROP_ENUMERATE)) break; /*@fallthrough@*/ default: assert(0); break; } _path = _free(_path); _value = _free(_value); } *objp = obj; /* XXX always resolve in this object. */ exit: return JS_TRUE; }