RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: j...@rpm5.org Module: rpm Date: 24-Apr-2009 14:50:59 Branch: HEAD Handle: 2009042412505801 Added files: rpm/js rpmds-js.c rpmds-js.h rpmfi-js.c rpmfi-js.h Modified files: rpm/js Makefile.am tjs.c Log: - js: stub in Ds/Fi classes for rpmds/rpmfi objects. Summary: Revision Changes Path 1.8 +6 -2 rpm/js/Makefile.am 1.1 +335 -0 rpm/js/rpmds-js.c 1.1 +26 -0 rpm/js/rpmds-js.h 1.1 +337 -0 rpm/js/rpmfi-js.c 1.1 +26 -0 rpm/js/rpmfi-js.h 1.8 +6 -0 rpm/js/tjs.c ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/js/Makefile.am ============================================================================ $ cvs diff -u -r1.7 -r1.8 Makefile.am --- rpm/js/Makefile.am 23 Apr 2009 20:49:50 -0000 1.7 +++ rpm/js/Makefile.am 24 Apr 2009 12:50:58 -0000 1.8 @@ -57,10 +57,14 @@ @LTLIBINTL@ noinst_HEADERS = \ - rpmjsfile.h rpmts-js.h rpmmi-js.h rpmhdr-js.h uuid-js.h # syck-js.h + rpmjsfile.h \ + rpmds-js.h rpmfi-js.h rpmhdr-js.h rpmmi-js.h rpmts-js.h \ + uuid-js.h # syck-js.h rpmjsm_la_SOURCES = \ - rpmjsfile.c rpmts-js.c rpmmi-js.c rpmhdr-js.c uuid-js.c # syck-js.c + rpmjsfile.c \ + rpmds-js.c rpmfi-js.c rpmhdr-js.c rpmmi-js.c rpmts-js.c \ + uuid-js.c # syck-js.c .PHONY: lint lint: @@ . patch -p0 <<'@@ .' Index: rpm/js/rpmds-js.c ============================================================================ $ cvs diff -u -r0 -r1.1 rpmds-js.c --- /dev/null 2009-04-24 14:50:00 +0200 +++ rpmds-js.c 2009-04-24 14:50:59 +0200 @@ -0,0 +1,335 @@ +/** \ingroup js_c + * \file js/rpmds-js.c + */ + +#include "system.h" + +#include "rpmds-js.h" +#include "rpmhdr-js.h" + +#include <argv.h> +#include <mire.h> + +#include <rpmdb.h> + +#define _RPMTS_INTERNAL +#include <rpmds.h> + +#include "debug.h" + +/*...@unchecked@*/ +extern int _rpmjs_debug; + +/*...@unchecked@*/ +static int _debug = 1; + +/* --- Object methods */ + +static JSFunctionSpec rpmds_funcs[] = { + JS_FS_END +}; + +/* --- Object properties */ +enum rpmds_tinyid { + _DEBUG = -2, +}; + +static JSPropertySpec rpmds_props[] = { + {"debug", _DEBUG, JSPROP_ENUMERATE, NULL, NULL}, + {NULL, 0, 0, NULL, NULL} +}; + +static JSBool +rpmds_addprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + void * ptr = JS_GetInstancePrivate(cx, obj, &rpmdsClass, NULL); + +if (_debug < 0) +fprintf(stderr, "==> %s(%p,%p,0x%lx[%u],%p) ptr %p %s = %s\n", __FUNCTION__, cx, obj, (unsigned long)id, (unsigned)JSVAL_TAG(id), vp, ptr, JS_GetStringBytes(JS_ValueToString(cx, id)), JS_GetStringBytes(JS_ValueToString(cx, *vp))); + + return JS_TRUE; +} + +static JSBool +rpmds_delprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + void * ptr = JS_GetInstancePrivate(cx, obj, &rpmdsClass, NULL); + +if (_debug) +fprintf(stderr, "==> %s(%p,%p,0x%lx[%u],%p) ptr %p %s = %s\n", __FUNCTION__, cx, obj, (unsigned long)id, (unsigned)JSVAL_TAG(id), vp, ptr, JS_GetStringBytes(JS_ValueToString(cx, id)), JS_GetStringBytes(JS_ValueToString(cx, *vp))); + + return JS_TRUE; +} +static JSBool +rpmds_getprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + void * ptr = JS_GetInstancePrivate(cx, obj, &rpmdsClass, NULL); + rpmds ds = ptr; + jsint tiny = JSVAL_TO_INT(id); + /* XXX the class has ptr == NULL, instances have ptr != NULL. */ + JSBool ok = (ptr ? JS_FALSE : JS_TRUE); + + switch (tiny) { + case _DEBUG: + *vp = INT_TO_JSVAL(_debug); + ok = JS_TRUE; + break; + default: + break; + } + + if (!ok) { +if (_debug) { +fprintf(stderr, "==> %s(%p,%p,0x%lx[%u],%p) ptr %p %s = %s\n", __FUNCTION__, cx, obj, (unsigned long)id, (unsigned)JSVAL_TAG(id), vp, ptr, JS_GetStringBytes(JS_ValueToString(cx, id)), JS_GetStringBytes(JS_ValueToString(cx, *vp))); +ok = JS_TRUE; /* XXX return JS_TRUE iff ... ? */ +} + } + return ok; +} + +static JSBool +rpmds_setprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + void * ptr = JS_GetInstancePrivate(cx, obj, &rpmdsClass, NULL); + rpmds ds = (rpmds)ptr; + jsint tiny = JSVAL_TO_INT(id); + /* XXX the class has ptr == NULL, instances have ptr != NULL. */ + JSBool ok = (ptr ? JS_FALSE : JS_TRUE); + int myint; + + switch (tiny) { + case _DEBUG: + if (JS_ValueToInt32(cx, *vp, &_debug)) + ok = JS_TRUE; + break; + default: + break; + } + + if (!ok) { +if (_debug) { +fprintf(stderr, "==> %s(%p,%p,0x%lx[%u],%p) ptr %p %s = %s\n", __FUNCTION__, cx, obj, (unsigned long)id, (unsigned)JSVAL_TAG(id), vp, ptr, JS_GetStringBytes(JS_ValueToString(cx, id)), JS_GetStringBytes(JS_ValueToString(cx, *vp))); +ok = JS_TRUE; /* XXX return JS_TRUE iff ... ? */ +} + } + return ok; +} + +static JSBool +rpmds_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, + JSObject **objp) +{ + void * ptr = JS_GetInstancePrivate(cx, obj, &rpmdsClass, NULL); + static char hex[] = "0123456789abcdef"; + JSString *idstr; + const char * name; + JSString * valstr; + char value[5]; + JSBool ok = JS_FALSE; + +if (_debug) +fprintf(stderr, "==> %s(%p,%p,0x%lx[%u],0x%x,%p) ptr %p property %s flags 0x%x{%s,%s,%s,%s,%s}\n", __FUNCTION__, cx, obj, (unsigned long)id, (unsigned)JSVAL_TAG(id), (unsigned)flags, objp, ptr, + JS_GetStringBytes(JS_ValueToString(cx, id)), flags, + (flags & JSRESOLVE_QUALIFIED) ? "qualified" : "", + (flags & JSRESOLVE_ASSIGNING) ? "assigning" : "", + (flags & JSRESOLVE_DETECTING) ? "detecting" : "", + (flags & JSRESOLVE_DETECTING) ? "declaring" : "", + (flags & JSRESOLVE_DETECTING) ? "classname" : ""); + + if (flags & JSRESOLVE_ASSIGNING) { + ok = JS_TRUE; + goto exit; + } + + if ((idstr = JS_ValueToString(cx, id)) == NULL) + goto exit; + + name = JS_GetStringBytes(idstr); + if (name[1] == '\0' && xisalpha(name[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; + *objp = obj; + } + ok = JS_TRUE; +exit: + return ok; +} + +static JSBool +rpmds_enumerate(JSContext *cx, JSObject *obj, JSIterateOp op, + jsval *statep, jsid *idp) +{ + JSObject *iterator; + JSBool ok = JS_FALSE; + +if (_debug) +fprintf(stderr, "==> %s(%p,%p,%d,%p,%p)\n", __FUNCTION__, cx, obj, op, statep, idp); + +#ifdef DYING + switch (op) { + case JSENUMERATE_INIT: + 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 (*idp != JSVAL_VOID) + 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 + ok = JS_TRUE; +exit: + return ok; +} + +static JSBool +rpmds_convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp) +{ + void * ptr = JS_GetInstancePrivate(cx, obj, &rpmdsClass, NULL); +if (_debug) +fprintf(stderr, "==> %s(%p,%p,%d,%p) ptr %p convert to %s\n", __FUNCTION__, cx, obj, type, vp, ptr, JS_GetTypeName(cx, type)); + return JS_TRUE; +} + +/* --- Object ctors/dtors */ +static rpmds +rpmds_init(JSContext *cx, JSObject *obj, Header h, int _tagN) +{ + rpmds ds; + int flags = 0; + + if ((ds = rpmdsNew(h, _tagN, flags)) == NULL) + return NULL; + if (!JS_SetPrivate(cx, obj, (void *)ds)) { + /* XXX error msg */ + (void) rpmdsFree(ds); + return NULL; + } + return ds; +} + +static void +rpmds_dtor(JSContext *cx, JSObject *obj) +{ + void * ptr = JS_GetInstancePrivate(cx, obj, &rpmdsClass, NULL); + rpmds ds = ptr; + +if (_debug) +fprintf(stderr, "==> %s(%p,%p) ptr %p\n", __FUNCTION__, cx, obj, ptr); + +#ifdef BUGGY + (void) rpmdsFree(ds); +#endif +} + +static JSBool +rpmds_ctor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + JSBool ok = JS_FALSE; + JSObject *hdro = NULL; + int tagN = RPMTAG_REQUIRENAME; + +if (_debug) +fprintf(stderr, "==> %s(%p,%p,%p[%u],%p)\n", __FUNCTION__, cx, obj, argv, (unsigned)argc, rval); + + if (!(ok = JS_ConvertArguments(cx, argc, argv, "o/i", &hdro, tagN))) + goto exit; + + if (cx->fp->flags & JSFRAME_CONSTRUCTING) { + Header h = JS_GetInstancePrivate(cx, hdro, &rpmhdrClass, NULL); + if (rpmds_init(cx, obj, h, tagN) == NULL) + goto exit; + } else { + if ((obj = JS_NewObject(cx, &rpmdsClass, NULL, NULL)) == NULL) + goto exit; + *rval = OBJECT_TO_JSVAL(obj); + } + ok = JS_TRUE; + +exit: + return ok; +} + +/* --- Class initialization */ +#ifdef HACKERY +JSClass rpmdsClass = { + "Ds", JSCLASS_NEW_RESOLVE | JSCLASS_NEW_ENUMERATE | JSCLASS_HAS_PRIVATE | JSCLASS_HAS_CACHED_PROTO(JSProto_Object), + rpmds_addprop, rpmds_delprop, rpmds_getprop, rpmds_setprop, + (JSEnumerateOp)rpmds_enumerate, (JSResolveOp)rpmds_resolve, + rpmds_convert, rpmds_dtor, + JSCLASS_NO_OPTIONAL_MEMBERS +}; +#else +JSClass rpmdsClass = { + "Ds", JSCLASS_NEW_RESOLVE | JSCLASS_HAS_PRIVATE, + JS_PropertyStub, JS_PropertyStub, rpmds_getprop, JS_PropertyStub, + (JSEnumerateOp)rpmds_enumerate, (JSResolveOp)rpmds_resolve, + JS_ConvertStub, rpmds_dtor, + JSCLASS_NO_OPTIONAL_MEMBERS +}; +#endif + +JSObject * +rpmjs_InitDsClass(JSContext *cx, JSObject* obj) +{ + JSObject * o; + +if (_debug) +fprintf(stderr, "==> %s(%p,%p)\n", __FUNCTION__, cx, obj); + + o = JS_InitClass(cx, obj, NULL, &rpmdsClass, rpmds_ctor, 1, + rpmds_props, rpmds_funcs, NULL, NULL); +assert(o != NULL); + return o; +} + +JSObject * +rpmjs_NewDsObject(JSContext *cx, void * _h, int _tagN) +{ + JSObject *obj; + rpmds ds; + + if ((obj = JS_NewObject(cx, &rpmdsClass, NULL, NULL)) == NULL) { + /* XXX error msg */ + return NULL; + } + if ((ds = rpmds_init(cx, obj, _h, _tagN)) == NULL) { + /* XXX error msg */ + return NULL; + } + return obj; +} @@ . patch -p0 <<'@@ .' Index: rpm/js/rpmds-js.h ============================================================================ $ cvs diff -u -r0 -r1.1 rpmds-js.h --- /dev/null 2009-04-24 14:50:00 +0200 +++ rpmds-js.h 2009-04-24 14:50:59 +0200 @@ -0,0 +1,26 @@ +#ifndef H_RPMDS_JS +#define H_RPMDS_JS + +/** + * \file js/rpmds-js.h + */ + +#include "rpm-js.h" + +extern JSClass rpmdsClass; + +#ifdef __cplusplus +extern "C" { +#endif + +extern JSObject * +rpmjs_InitDsClass(JSContext *cx, JSObject* obj); + +extern JSObject * +rpmjs_NewDsObject(JSContext *cx, void * _h, int _tagN); + +#ifdef __cplusplus +} +#endif + +#endif /* H_RPMDS_JS */ @@ . patch -p0 <<'@@ .' Index: rpm/js/rpmfi-js.c ============================================================================ $ cvs diff -u -r0 -r1.1 rpmfi-js.c --- /dev/null 2009-04-24 14:50:00 +0200 +++ rpmfi-js.c 2009-04-24 14:50:59 +0200 @@ -0,0 +1,337 @@ +/** \ingroup js_c + * \file js/rpmfi-js.c + */ + +#include "system.h" + +#include "rpmfi-js.h" +#include "rpmhdr-js.h" + +#include <argv.h> +#include <mire.h> + +#include <rpmdb.h> + +#define _RPMTS_INTERNAL +#include <rpmfi.h> + +#include "debug.h" + +/*...@unchecked@*/ +extern int _rpmjs_debug; + +/*...@unchecked@*/ +static int _debug = 1; + +/* --- Object methods */ + +static JSFunctionSpec rpmfi_funcs[] = { + JS_FS_END +}; + +/* --- Object properties */ +enum rpmfi_tinyid { + _DEBUG = -2, +}; + +static JSPropertySpec rpmfi_props[] = { + {"debug", _DEBUG, JSPROP_ENUMERATE, NULL, NULL}, + {NULL, 0, 0, NULL, NULL} +}; + +static JSBool +rpmfi_addprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + void * ptr = JS_GetInstancePrivate(cx, obj, &rpmfiClass, NULL); + +if (_debug < 0) +fprintf(stderr, "==> %s(%p,%p,0x%lx[%u],%p) ptr %p %s = %s\n", __FUNCTION__, cx, obj, (unsigned long)id, (unsigned)JSVAL_TAG(id), vp, ptr, JS_GetStringBytes(JS_ValueToString(cx, id)), JS_GetStringBytes(JS_ValueToString(cx, *vp))); + + return JS_TRUE; +} + +static JSBool +rpmfi_delprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + void * ptr = JS_GetInstancePrivate(cx, obj, &rpmfiClass, NULL); + +if (_debug) +fprintf(stderr, "==> %s(%p,%p,0x%lx[%u],%p) ptr %p %s = %s\n", __FUNCTION__, cx, obj, (unsigned long)id, (unsigned)JSVAL_TAG(id), vp, ptr, JS_GetStringBytes(JS_ValueToString(cx, id)), JS_GetStringBytes(JS_ValueToString(cx, *vp))); + + return JS_TRUE; +} +static JSBool +rpmfi_getprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + void * ptr = JS_GetInstancePrivate(cx, obj, &rpmfiClass, NULL); + rpmfi fi = ptr; + jsint tiny = JSVAL_TO_INT(id); + /* XXX the class has ptr == NULL, instances have ptr != NULL. */ + JSBool ok = (ptr ? JS_FALSE : JS_TRUE); + + switch (tiny) { + case _DEBUG: + *vp = INT_TO_JSVAL(_debug); + ok = JS_TRUE; + break; + default: + break; + } + + if (!ok) { +if (_debug) { +fprintf(stderr, "==> %s(%p,%p,0x%lx[%u],%p) ptr %p %s = %s\n", __FUNCTION__, cx, obj, (unsigned long)id, (unsigned)JSVAL_TAG(id), vp, ptr, JS_GetStringBytes(JS_ValueToString(cx, id)), JS_GetStringBytes(JS_ValueToString(cx, *vp))); +ok = JS_TRUE; /* XXX return JS_TRUE iff ... ? */ +} + } + return ok; +} + +static JSBool +rpmfi_setprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + void * ptr = JS_GetInstancePrivate(cx, obj, &rpmfiClass, NULL); + rpmfi fi = (rpmfi)ptr; + jsint tiny = JSVAL_TO_INT(id); + /* XXX the class has ptr == NULL, instances have ptr != NULL. */ + JSBool ok = (ptr ? JS_FALSE : JS_TRUE); + int myint; + + switch (tiny) { + case _DEBUG: + if (JS_ValueToInt32(cx, *vp, &_debug)) + ok = JS_TRUE; + break; + default: + break; + } + + if (!ok) { +if (_debug) { +fprintf(stderr, "==> %s(%p,%p,0x%lx[%u],%p) ptr %p %s = %s\n", __FUNCTION__, cx, obj, (unsigned long)id, (unsigned)JSVAL_TAG(id), vp, ptr, JS_GetStringBytes(JS_ValueToString(cx, id)), JS_GetStringBytes(JS_ValueToString(cx, *vp))); +ok = JS_TRUE; /* XXX return JS_TRUE iff ... ? */ +} + } + return ok; +} + +static JSBool +rpmfi_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, + JSObject **objp) +{ + void * ptr = JS_GetInstancePrivate(cx, obj, &rpmfiClass, NULL); + static char hex[] = "0123456789abcdef"; + JSString *idstr; + const char * name; + JSString * valstr; + char value[5]; + JSBool ok = JS_FALSE; + +if (_debug) +fprintf(stderr, "==> %s(%p,%p,0x%lx[%u],0x%x,%p) ptr %p property %s flags 0x%x{%s,%s,%s,%s,%s}\n", __FUNCTION__, cx, obj, (unsigned long)id, (unsigned)JSVAL_TAG(id), (unsigned)flags, objp, ptr, + JS_GetStringBytes(JS_ValueToString(cx, id)), flags, + (flags & JSRESOLVE_QUALIFIED) ? "qualified" : "", + (flags & JSRESOLVE_ASSIGNING) ? "assigning" : "", + (flags & JSRESOLVE_DETECTING) ? "detecting" : "", + (flags & JSRESOLVE_DETECTING) ? "declaring" : "", + (flags & JSRESOLVE_DETECTING) ? "classname" : ""); + + if (flags & JSRESOLVE_ASSIGNING) { + ok = JS_TRUE; + goto exit; + } + + if ((idstr = JS_ValueToString(cx, id)) == NULL) + goto exit; + + name = JS_GetStringBytes(idstr); + if (name[1] == '\0' && xisalpha(name[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; + *objp = obj; + } + ok = JS_TRUE; +exit: + return ok; +} + +static JSBool +rpmfi_enumerate(JSContext *cx, JSObject *obj, JSIterateOp op, + jsval *statep, jsid *idp) +{ + JSObject *iterator; + JSBool ok = JS_FALSE; + +if (_debug) +fprintf(stderr, "==> %s(%p,%p,%d,%p,%p)\n", __FUNCTION__, cx, obj, op, statep, idp); + +#ifdef DYING + switch (op) { + case JSENUMERATE_INIT: + 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 (*idp != JSVAL_VOID) + 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 + ok = JS_TRUE; +exit: + return ok; +} + +static JSBool +rpmfi_convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp) +{ + void * ptr = JS_GetInstancePrivate(cx, obj, &rpmfiClass, NULL); +if (_debug) +fprintf(stderr, "==> %s(%p,%p,%d,%p) ptr %p convert to %s\n", __FUNCTION__, cx, obj, type, vp, ptr, JS_GetTypeName(cx, type)); + return JS_TRUE; +} + +/* --- Object ctors/dtors */ +static rpmfi +rpmfi_init(JSContext *cx, JSObject *obj, rpmts ts, Header h, int _tagN) +{ + rpmfi fi; + int flags = 0; + + if ((fi = rpmfiNew(ts, h, _tagN, flags)) == NULL) + return NULL; + if (!JS_SetPrivate(cx, obj, (void *)fi)) { + /* XXX error msg */ + (void) rpmfiFree(fi); + return NULL; + } + return fi; +} + +static void +rpmfi_dtor(JSContext *cx, JSObject *obj) +{ + void * ptr = JS_GetInstancePrivate(cx, obj, &rpmfiClass, NULL); + rpmfi fi = ptr; + +if (_debug) +fprintf(stderr, "==> %s(%p,%p) ptr %p\n", __FUNCTION__, cx, obj, ptr); + +#ifdef BUGGY + (void) rpmfiFree(fi); +#endif +} + +static JSBool +rpmfi_ctor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + JSBool ok = JS_FALSE; + rpmts ts = NULL; /* XXX FIXME: should be a ts method? */ + JSObject *hdro = NULL; + int tagN = RPMTAG_BASENAMES; + +if (_debug) +fprintf(stderr, "==> %s(%p,%p,%p[%u],%p)\n", __FUNCTION__, cx, obj, argv, (unsigned)argc, rval); + + if (!(ok = JS_ConvertArguments(cx, argc, argv, "o/i", &hdro, tagN))) + goto exit; + + if (cx->fp->flags & JSFRAME_CONSTRUCTING) { + Header h = JS_GetInstancePrivate(cx, hdro, &rpmhdrClass, NULL); + if (rpmfi_init(cx, obj, ts, h, tagN) == NULL) + goto exit; + } else { + if ((obj = JS_NewObject(cx, &rpmfiClass, NULL, NULL)) == NULL) + goto exit; + *rval = OBJECT_TO_JSVAL(obj); + } + ok = JS_TRUE; + +exit: + return ok; +} + +/* --- Class initialization */ +#ifdef HACKERY +JSClass rpmfiClass = { + "Fi", JSCLASS_NEW_RESOLVE | JSCLASS_NEW_ENUMERATE | JSCLASS_HAS_PRIVATE | JSCLASS_HAS_CACHED_PROTO(JSProto_Object), + rpmfi_addprop, rpmfi_delprop, rpmfi_getprop, rpmfi_setprop, + (JSEnumerateOp)rpmfi_enumerate, (JSResolveOp)rpmfi_resolve, + rpmfi_convert, rpmfi_dtor, + JSCLASS_NO_OPTIONAL_MEMBERS +}; +#else +JSClass rpmfiClass = { + "Fi", JSCLASS_NEW_RESOLVE | JSCLASS_HAS_PRIVATE, + JS_PropertyStub, JS_PropertyStub, rpmfi_getprop, JS_PropertyStub, + (JSEnumerateOp)rpmfi_enumerate, (JSResolveOp)rpmfi_resolve, + JS_ConvertStub, rpmfi_dtor, + JSCLASS_NO_OPTIONAL_MEMBERS +}; +#endif + +JSObject * +rpmjs_InitFiClass(JSContext *cx, JSObject* obj) +{ + JSObject * o; + +if (_debug) +fprintf(stderr, "==> %s(%p,%p)\n", __FUNCTION__, cx, obj); + + o = JS_InitClass(cx, obj, NULL, &rpmfiClass, rpmfi_ctor, 1, + rpmfi_props, rpmfi_funcs, NULL, NULL); +assert(o != NULL); + return o; +} + +JSObject * +rpmjs_NewFiObject(JSContext *cx, void * _h, int _tagN) +{ + JSObject *obj; + rpmts ts = NULL; /* XXX FIXME: should be a ts method? */ + rpmfi fi; + + if ((obj = JS_NewObject(cx, &rpmfiClass, NULL, NULL)) == NULL) { + /* XXX error msg */ + return NULL; + } + if ((fi = rpmfi_init(cx, obj, ts, _h, _tagN)) == NULL) { + /* XXX error msg */ + return NULL; + } + return obj; +} @@ . patch -p0 <<'@@ .' Index: rpm/js/rpmfi-js.h ============================================================================ $ cvs diff -u -r0 -r1.1 rpmfi-js.h --- /dev/null 2009-04-24 14:50:00 +0200 +++ rpmfi-js.h 2009-04-24 14:50:59 +0200 @@ -0,0 +1,26 @@ +#ifndef H_RPMFI_JS +#define H_RPMFI_JS + +/** + * \file js/rpmfi-js.h + */ + +#include "rpm-js.h" + +extern JSClass rpmfiClass; + +#ifdef __cplusplus +extern "C" { +#endif + +extern JSObject * +rpmjs_InitFiClass(JSContext *cx, JSObject* obj); + +extern JSObject * +rpmjs_NewFiObject(JSContext *cx, void * _h, int _tagN); + +#ifdef __cplusplus +} +#endif + +#endif /* H_RPMFI_JS */ @@ . patch -p0 <<'@@ .' Index: rpm/js/tjs.c ============================================================================ $ cvs diff -u -r1.7 -r1.8 tjs.c --- rpm/js/tjs.c 23 Apr 2009 20:49:50 -0000 1.7 +++ rpm/js/tjs.c 24 Apr 2009 12:50:59 -0000 1.8 @@ -6,6 +6,8 @@ #define _RPMJS_INTERNAL #include <rpmjs.h> +#include "rpmds-js.h" +#include "rpmfi-js.h" #include "rpmts-js.h" #include "rpmmi-js.h" #include "rpmhdr-js.h" @@ -59,6 +61,10 @@ (void) rpmjsRun(NULL, "print(\"\tMi\");", &result); (void) rpmjs_InitTsClass(js->cx, js->glob); (void) rpmjsRun(NULL, "print(\"\tTs\");", &result); + (void) rpmjs_InitDsClass(js->cx, js->glob); + (void) rpmjsRun(NULL, "print(\"\tDs\");", &result); + (void) rpmjs_InitFiClass(js->cx, js->glob); + (void) rpmjsRun(NULL, "print(\"\tFi\");", &result); (void) js_InitFileClass(js->cx, js->glob); (void) rpmjsRun(NULL, "print(\"\tFile\");", &result); } @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org