static JSBool rpmbf_enumerate(JSContext *cx, JSObject *obj, JSIterateOp op, jsval *statep, jsid *idp) { _ENUMERATE_DEBUG_ENTRY(_debug); switch (op) { case JSENUMERATE_INIT: case JSENUMERATE_INIT_ALL: *statep = JSVAL_VOID; if (idp) *idp = JSVAL_ZERO; break; case JSENUMERATE_NEXT: *statep = JSVAL_VOID; if (*idp != (jsid)JSVAL_VOID) break; /*@fallthrough@*/ case JSENUMERATE_DESTROY: *statep = JSVAL_NULL; break; } return JS_TRUE; }
static JSBool rpmhdr_enumerate(JSContext *cx, JSObject *obj, JSIterateOp op, jsval *statep, jsid *idp) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmhdrClass, NULL); Header h = ptr; HeaderIterator hi = NULL; HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); JSObject *ho = NULL; JSBool ok = JS_FALSE; _ENUMERATE_DEBUG_ENTRY(_debug); switch (op) { case JSENUMERATE_INIT: if ((ho = JS_NewObject(cx, &rpmhiClass, NULL, obj)) == NULL) goto exit; if ((hi = headerInit(h)) == NULL) goto exit; if (!JS_SetPrivate(cx, ho, (void *)hi)) { hi = headerFini(hi); goto exit; } *statep = OBJECT_TO_JSVAL(ho); if (idp) *idp = JSVAL_ZERO; if (_debug) fprintf(stderr, "\tINIT ho %p hi %p\n", ho, hi); break; case JSENUMERATE_NEXT: ho = (JSObject *) JSVAL_TO_OBJECT(*statep); hi = JS_GetInstancePrivate(cx, ho, &rpmhiClass, NULL); if (_debug) fprintf(stderr, "\tNEXT ho %p hi %p\n", ho, hi); if (headerNext(hi, he, 0)) { JS_ValueToId(cx, INT_TO_JSVAL(he->tag), idp); he->p.ptr = _free(he->p.ptr); } else *idp = JSVAL_VOID; if (*idp != JSVAL_VOID) break; /*@fallthrough@*/ case JSENUMERATE_DESTROY: ho = (JSObject *) JSVAL_TO_OBJECT(*statep); hi = JS_GetInstancePrivate(cx, ho, &rpmhiClass, NULL); if (_debug) fprintf(stderr, "\tFINI ho %p hi %p\n", ho, hi); /* Allow our iterator object to be GC'd. */ *statep = JSVAL_NULL; break; } ok = JS_TRUE; exit: return ok; }
static JSBool rpmts_enumerate(JSContext *cx, JSObject *obj, JSIterateOp op, jsval *statep, jsid *idp) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmtsClass, NULL); rpmts ts = ptr; rpmtsi tsi; JSObject *tsio = NULL; JSBool ok = JS_FALSE; _ENUMERATE_DEBUG_ENTRY(_debug); switch (op) { case JSENUMERATE_INIT: if ((tsio = JS_NewObject(cx, &rpmtsiClass, NULL, obj)) == NULL) goto exit; if ((tsi = rpmtsiInit(ts)) == NULL) goto exit; if (!JS_SetPrivate(cx, tsio, (void *)tsi)) { tsi = rpmtsiFree(tsi); goto exit; } *statep = OBJECT_TO_JSVAL(tsio); if (idp) *idp = JSVAL_ZERO; if (_debug) fprintf(stderr, "\tINIT tsio %p tsi %p\n", tsio, tsi); break; case JSENUMERATE_NEXT: tsio = (JSObject *) JSVAL_TO_OBJECT(*statep); tsi = JS_GetInstancePrivate(cx, tsio, &rpmtsiClass, NULL); if (rpmtsiNext(tsi, 0) != NULL) { int oc = rpmtsiOc(tsi); if (_debug) fprintf(stderr, "\tNEXT tsio %p tsi %p[%d]\n", tsio, tsi, oc); JS_ValueToId(cx, INT_TO_JSVAL(oc), idp); } else *idp = JSVAL_VOID; if (*idp != JSVAL_VOID) break; /*@fallthrough@*/ case JSENUMERATE_DESTROY: tsio = (JSObject *) JSVAL_TO_OBJECT(*statep); tsi = JS_GetInstancePrivate(cx, tsio, &rpmtsiClass, NULL); if (_debug) fprintf(stderr, "\tFINI tsio %p tsi %p\n", tsio, tsi); /* Allow our iterator object to be GC'd. */ *statep = JSVAL_NULL; break; } ok = JS_TRUE; exit: return ok; }
static JSBool rpmmg_enumerate(JSContext *cx, JSObject *obj, JSIterateOp op, jsval *statep, jsid *idp) { #ifdef NOTYET void * ptr = JS_GetInstancePrivate(cx, obj, &rpmmgClass, NULL); rpmmg mg = ptr; struct dirent * dp; unsigned int ix = 0; #endif _ENUMERATE_DEBUG_ENTRY(_debug < 0); #ifdef NOTYET switch (op) { case JSENUMERATE_INIT: if (idp) *idp = JSVAL_ZERO; *statep = INT_TO_JSVAL(ix); if (_debug) fprintf(stderr, "\tINIT mg %p\n", mg); break; case JSENUMERATE_NEXT: ix = JSVAL_TO_INT(*statep); if ((dp = Readdir(dir)) != NULL) { (void) JS_DefineElement(cx, obj, ix, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, dp->d_name)), NULL, NULL, JSPROP_ENUMERATE); JS_ValueToId(cx, *statep, idp); if (_debug) fprintf(stderr, "\tNEXT mg %p[%u] dirent %p \"%s\"\n", mg, ix, dp, dp->d_name); *statep = INT_TO_JSVAL(ix+1); } else *idp = JSVAL_VOID; if (*idp != JSVAL_VOID) break; /*@fallthrough@*/ case JSENUMERATE_DESTROY: ix = JSVAL_TO_INT(*statep); (void) JS_DefineProperty(cx, obj, "length", INT_TO_JSVAL(ix), NULL, NULL, JSPROP_ENUMERATE); if (_debug) fprintf(stderr, "\tFINI mg %p[%u]\n", mg, ix); *statep = JSVAL_NULL; break; } #else *statep = JSVAL_NULL; #endif return JS_TRUE; }
static JSBool rpmps_enumerate(JSContext *cx, JSObject *obj, JSIterateOp op, jsval *statep, jsid *idp) { _ENUMERATE_DEBUG_ENTRY(_debug); #ifdef DYING switch (op) { case JSENUMERATE_INIT: case JSENUMERATE_INIT_ALL: if ((iterator = JS_NewPropertyIterator(cx, obj)) == NULL) goto exit; *statep = OBJECT_TO_JSVAL(iterator); if (idp) *idp = JSVAL_ZERO; break; case JSENUMERATE_NEXT: iterator = (JSObject *) JSVAL_TO_OBJECT(*statep); if (!JS_NextProperty(cx, iterator, idp)) goto exit; if (!JSID_IS_VOID(*idp)) break; /*@fallthrough@*/ case JSENUMERATE_DESTROY: /* Allow our iterator object to be GC'd. */ *statep = JSVAL_NULL; break; } #else { static const char hex[] = "0123456789abcdef"; const char * s; char name[2]; JSString * valstr; char value[5]; for (s = "AaBbCc"; *s != '\0'; s++) { name[0] = s[0]; name[1] = '\0'; value[0] = '0'; value[1] = 'x'; value[2] = hex[(name[0] >> 4) & 0xf]; value[3] = hex[(name[0] ) & 0xf]; value[4] = '\0'; if ((valstr = JS_NewStringCopyZ(cx, value)) == NULL || !JS_DefineProperty(cx, obj, name, STRING_TO_JSVAL(valstr), NULL, NULL, JSPROP_ENUMERATE)) goto exit; } } #endif exit: return JS_TRUE; }
static JSBool rpmdir_enumerate(JSContext *cx, JSObject *obj, JSIterateOp op, jsval *statep, jsid *idp) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmdirClass, NULL); DIR * dir = ptr; struct dirent * dp; unsigned int ix = 0; /* XXX VG: JS_Enumerate (jsobj.c:4211) doesn't initialize some fields. */ _ENUMERATE_DEBUG_ENTRY(_debug < 0); switch (op) { case JSENUMERATE_INIT: case JSENUMERATE_INIT_ALL: if (idp) *idp = JSVAL_ZERO; *statep = INT_TO_JSVAL(ix); if (_debug) fprintf(stderr, "\tINIT dir %p\n", dir); break; case JSENUMERATE_NEXT: ix = JSVAL_TO_INT(*statep); if ((dp = Readdir(dir)) != NULL) { (void) JS_DefineElement(cx, obj, ix, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, dp->d_name)), NULL, NULL, JSPROP_ENUMERATE); JS_ValueToId(cx, *statep, idp); if (_debug) fprintf(stderr, "\tNEXT dir %p[%u] dirent %p \"%s\"\n", dir, ix, dp, dp->d_name); *statep = INT_TO_JSVAL(ix+1); } else *idp = JSVAL_VOID; if (!JSID_IS_VOID(*idp)) break; /*@fallthrough@*/ case JSENUMERATE_DESTROY: ix = JSVAL_TO_INT(*statep); (void) JS_DefineProperty(cx, obj, "length", INT_TO_JSVAL(ix), NULL, NULL, JSPROP_ENUMERATE); if (_debug) fprintf(stderr, "\tFINI dir %p[%u]\n", dir, ix); *statep = JSVAL_NULL; break; } return JS_TRUE; }
static JSBool rpmxar_enumerate(JSContext *cx, JSObject *obj, JSIterateOp op, jsval *statep, jsid *idp) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmxarClass, NULL); rpmxar xar = ptr; int ix = 0; _ENUMERATE_DEBUG_ENTRY(_debug < 0); switch (op) { case JSENUMERATE_INIT: if (idp) *idp = JSVAL_ZERO; *statep = INT_TO_JSVAL(ix); if (_debug) fprintf(stderr, "\tINIT xar %p\n", xar); break; case JSENUMERATE_NEXT: ix = JSVAL_TO_INT(*statep); if (!rpmxarNext(xar)) { const char * path = rpmxarPath(xar); struct stat * st = xmalloc(sizeof(*st)); JSObject * arr = JS_NewArrayObject(cx, 0, NULL); JSBool ok = JS_AddRoot(cx, &arr); JSObject * o; jsval v; v = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, path)); ok = JS_SetElement(cx, arr, 0, &v); if (!rpmxarStat(xar, st) && (o = JS_NewObject(cx, &rpmstClass, NULL, NULL)) != NULL && JS_SetPrivate(cx, o, (void *)st)) v = OBJECT_TO_JSVAL(o); else { st = _free(st); v = JSVAL_NULL; } ok = JS_SetElement(cx, arr, 1, &v); v = OBJECT_TO_JSVAL(arr); ok = JS_DefineElement(cx, obj, ix, v, NULL, NULL, JSPROP_ENUMERATE); (void) JS_RemoveRoot(cx, &arr); if (_debug) fprintf(stderr, "\tNEXT xar %p[%u] \"%s\"\n", xar, ix, path); path = _free(path); JS_ValueToId(cx, *statep, idp); *statep = INT_TO_JSVAL(ix+1); } else *idp = JSVAL_VOID; if (*idp != JSVAL_VOID) break; /*@fallthrough@*/ case JSENUMERATE_DESTROY: ix = JSVAL_TO_INT(*statep); (void) JS_DefineProperty(cx, obj, "length", INT_TO_JSVAL(ix), NULL, NULL, JSPROP_ENUMERATE); if (_debug) fprintf(stderr, "\tFINI xar %p[%u]\n", xar, ix); *statep = JSVAL_NULL; break; } return JS_TRUE; }