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:   12-Jun-2009 21:29:28
  Branch: HEAD                             Handle: 2009061219292701

  Added files:
    rpm/js                  rpmaug-js.c rpmaug-js.h
    rpm/js/tscripts         Aug.js
  Modified files:
    rpm                     CHANGES
    rpm/js                  Makefile.am rpmps-js.h tjs.c

  Log:
    - js: stub-in a Aug class.

  Summary:
    Revision    Changes     Path
    1.3020      +1  -0      rpm/CHANGES
    1.16        +4  -4      rpm/js/Makefile.am
    1.1         +226 -0     rpm/js/rpmaug-js.c
    1.1         +26 -0      rpm/js/rpmaug-js.h
    1.2         +1  -1      rpm/js/rpmps-js.h
    1.32        +2  -0      rpm/js/tjs.c
    1.1         +9  -0      rpm/js/tscripts/Aug.js
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.3019 -r1.3020 CHANGES
  --- rpm/CHANGES       12 Jun 2009 19:04:33 -0000      1.3019
  +++ rpm/CHANGES       12 Jun 2009 19:29:27 -0000      1.3020
  @@ -1,5 +1,6 @@
   
   5.2b1 -> 5.3a1
  +    - jbj: js: stub-in a Aug class.
       - jbj: augeas: stub-in rpmaug object with ctors/dtors.
       - jbj: augeas: add AutoFu to find augeas libraries.
       - jbj: js: stub-in requires/loadModule global methods.
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/Makefile.am
  ============================================================================
  $ cvs diff -u -r1.15 -r1.16 Makefile.am
  --- rpm/js/Makefile.am        4 Jun 2009 17:31:44 -0000       1.15
  +++ rpm/js/Makefile.am        12 Jun 2009 19:29:27 -0000      1.16
  @@ -64,14 +64,14 @@
   
   noinst_HEADERS = \
        rpmjsfile.h \
  -     rpmds-js.h rpmfi-js.h rpmhdr-js.h rpmmc-js.h rpmmi-js.h rpmps-js.h \
  -     rpmte-js.h rpmts-js.h \
  +     rpmaug-js.h rpmds-js.h rpmfi-js.h rpmhdr-js.h rpmmc-js.h rpmmi-js.h \
  +     rpmps-js.h rpmte-js.h rpmts-js.h \
        syck-js.h uuid-js.h
   
   rpmjsm_la_SOURCES = \
        rpmjsfile.c \
  -     rpmds-js.c rpmfi-js.c rpmhdr-js.c rpmmc-js.c rpmmi-js.c rpmps-js.c \
  -     rpmte-js.c rpmts-js.c \
  +     rpmaug-js.c rpmds-js.c rpmfi-js.c rpmhdr-js.c rpmmc-js.c rpmmi-js.c \
  +     rpmps-js.c rpmte-js.c rpmts-js.c \
        syck-js.c uuid-js.c
   
   librpmjsm_la_SOURCES = $(rpmjsm_la_SOURCES)
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/rpmaug-js.c
  ============================================================================
  $ cvs diff -u -r0 -r1.1 rpmaug-js.c
  --- /dev/null 2009-06-12 21:22:00 +0200
  +++ rpmaug-js.c       2009-06-12 21:29:28 +0200
  @@ -0,0 +1,226 @@
  +/** \ingroup js_c
  + * \file js/rpmaug-js.c
  + */
  +
  +#include "system.h"
  +
  +#include "rpmaug-js.h"
  +#include "rpmjs-debug.h"
  +
  +#define      _RPMPS_INTERNAL
  +#include <rpmaug.h>
  +
  +#include "debug.h"
  +
  +/*...@unchecked@*/
  +static int _debug = 0;
  +
  +#define      rpmaug_addprop  JS_PropertyStub
  +#define      rpmaug_delprop  JS_PropertyStub
  +#define      rpmaug_convert  JS_ConvertStub
  +
  +/* --- helpers */
  +
  +/* --- Object methods */
  +#ifdef       REFERENCE
  +static JSBool
  +rpmaug_print(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval 
*rval)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL);
  +    rpmaug aug = ptr;
  +    JSBool ok = JS_FALSE;
  +
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p,%p[%u],%p) ptr %p\n", __FUNCTION__, cx, obj, 
argv, (unsigned)argc, rval, ptr);
  +
  +    rpmaugPrint(NULL, aug);
  +
  +    ok = JS_TRUE;
  +    return ok;
  +}
  +#endif
  +
  +static JSFunctionSpec rpmaug_funcs[] = {
  +#ifdef       REFERENCE
  +    JS_FS("push",    rpmaug_push,            0,0,0),
  +    JS_FS("print",   rpmaug_print,           0,0,0),
  +#endif
  +    JS_FS_END
  +};
  +
  +/* --- Object properties */
  +enum rpmaug_tinyid {
  +    _DEBUG   = -2,
  +    _LENGTH  = -3,
  +};
  +
  +static JSPropertySpec rpmaug_props[] = {
  +    {"debug",        _DEBUG,         JSPROP_ENUMERATE,       NULL,   NULL},
  +    {NULL, 0, 0, NULL, NULL}
  +};
  +
  +static JSBool
  +rpmaug_getprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL);
  +    rpmaug aug = ptr;
  +    jsint tiny = JSVAL_TO_INT(id);
  +
  +    /* XXX the class has ptr == NULL, instances have ptr != NULL. */
  +    if (ptr == NULL)
  +     return JS_TRUE;
  +
  +    switch (tiny) {
  +    case _DEBUG:
  +     *vp = INT_TO_JSVAL(_debug);
  +     break;
  +    default:
  +     break;
  +    }
  +
  +    return JS_TRUE;
  +}
  +
  +static JSBool
  +rpmaug_setprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL);
  +    jsint tiny = JSVAL_TO_INT(id);
  +
  +    /* XXX the class has ptr == NULL, instances have ptr != NULL. */
  +    if (ptr == NULL)
  +     return JS_TRUE;
  +
  +    switch (tiny) {
  +    case _DEBUG:
  +     if (!JS_ValueToInt32(cx, *vp, &_debug))
  +         break;
  +     break;
  +    default:
  +     break;
  +    }
  +
  +    return JS_TRUE;
  +}
  +
  +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 ((flags & JSRESOLVE_ASSIGNING)
  +     || (aug == 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
  +rpmaug_enumerate(JSContext *cx, JSObject *obj, JSIterateOp op,
  +               jsval *statep, jsid *idp)
  +{
  +
  +_ENUMERATE_DEBUG_ENTRY(_debug);
  +
  +exit:
  +    return JS_TRUE;
  +}
  +
  +/* --- Object ctors/dtors */
  +static rpmaug
  +rpmaug_init(JSContext *cx, JSObject *obj)
  +{
  +    rpmaug aug;
  +
  +    if ((aug = rpmaugNew(NULL, 0)) == NULL)
  +     return NULL;
  +    if (!JS_SetPrivate(cx, obj, aug)) {
  +     /* XXX error msg */
  +     (void) rpmaugFree(aug);
  +     return NULL;
  +    }
  +    return aug;
  +}
  +
  +static void
  +rpmaug_dtor(JSContext *cx, JSObject *obj)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL);
  +    rpmaug aug = ptr;
  +
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p) ptr %p\n", __FUNCTION__, cx, obj, ptr);
  +
  +    aug = rpmaugFree(aug);
  +}
  +
  +static JSBool
  +rpmaug_ctor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval 
*rval)
  +{
  +    JSBool ok = JS_FALSE;
  +
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p,%p[%u],%p)\n", __FUNCTION__, cx, obj, argv, 
(unsigned)argc, rval);
  +
  +    if (cx->fp->flags & JSFRAME_CONSTRUCTING) {
  +     if (rpmaug_init(cx, obj) == NULL)
  +         goto exit;
  +    } else {
  +     if ((obj = JS_NewObject(cx, &rpmaugClass, NULL, NULL)) == NULL)
  +         goto exit;
  +     *rval = OBJECT_TO_JSVAL(obj);
  +    }
  +    ok = JS_TRUE;
  +
  +exit:
  +    return ok;
  +}
  +
  +/* --- Class initialization */
  +JSClass rpmaugClass = {
  +    "Aug", JSCLASS_NEW_RESOLVE | JSCLASS_HAS_PRIVATE,
  +    rpmaug_addprop,   rpmaug_delprop, rpmaug_getprop, rpmaug_setprop,
  +    (JSEnumerateOp)rpmaug_enumerate, (JSResolveOp)rpmaug_resolve,
  +    rpmaug_convert,  rpmaug_dtor,
  +    JSCLASS_NO_OPTIONAL_MEMBERS
  +};
  +
  +JSObject *
  +rpmjs_InitAugClass(JSContext *cx, JSObject* obj)
  +{
  +    JSObject * o;
  +
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p)\n", __FUNCTION__, cx, obj);
  +
  +    o = JS_InitClass(cx, obj, NULL, &rpmaugClass, rpmaug_ctor, 1,
  +             rpmaug_props, rpmaug_funcs, NULL, NULL);
  +assert(o != NULL);
  +    return o;
  +}
  +
  +JSObject *
  +rpmjs_NewAugObject(JSContext *cx)
  +{
  +    JSObject *obj;
  +    rpmaug aug;
  +
  +    if ((obj = JS_NewObject(cx, &rpmaugClass, NULL, NULL)) == NULL) {
  +     /* XXX error msg */
  +     return NULL;
  +    }
  +    if ((aug = rpmaug_init(cx, obj)) == NULL) {
  +     /* XXX error msg */
  +     return NULL;
  +    }
  +    return obj;
  +}
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/rpmaug-js.h
  ============================================================================
  $ cvs diff -u -r0 -r1.1 rpmaug-js.h
  --- /dev/null 2009-06-12 21:22:00 +0200
  +++ rpmaug-js.h       2009-06-12 21:29:28 +0200
  @@ -0,0 +1,26 @@
  +#ifndef H_RPMAUG_JS
  +#define H_RPMAUG_JS
  +
  +/**
  + * \file js/rpmaug-js.h
  + */
  +
  +#include "rpm-js.h"
  +
  +extern JSClass rpmaugClass;
  +
  +#ifdef __cplusplus
  +extern "C" {
  +#endif
  +
  +extern JSObject *
  +rpmjs_InitAugClass(JSContext *cx, JSObject* obj);
  +
  +extern JSObject *
  +rpmjs_NewAugObject(JSContext *cx);
  +
  +#ifdef __cplusplus      
  +}
  +#endif
  +
  +#endif       /* H_RPMAUG_JS */
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/rpmps-js.h
  ============================================================================
  $ cvs diff -u -r1.1 -r1.2 rpmps-js.h
  --- rpm/js/rpmps-js.h 24 Apr 2009 13:51:48 -0000      1.1
  +++ rpm/js/rpmps-js.h 12 Jun 2009 19:29:27 -0000      1.2
  @@ -23,4 +23,4 @@
   }
   #endif
   
  -#endif       /* H_RPMDS_JS */
  +#endif       /* H_RPMPS_JS */
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/tjs.c
  ============================================================================
  $ cvs diff -u -r1.31 -r1.32 tjs.c
  --- rpm/js/tjs.c      3 Jun 2009 12:20:48 -0000       1.31
  +++ rpm/js/tjs.c      12 Jun 2009 19:29:27 -0000      1.32
  @@ -8,6 +8,7 @@
   #define      _RPMJS_INTERNAL
   #include <rpmjs.h>
   
  +#include "rpmaug-js.h"
   #include "rpmds-js.h"
   #include "rpmfi-js.h"
   #include "rpmhdr-js.h"
  @@ -43,6 +44,7 @@
   
   /*...@unchecked@*/ /*...@observer@*/
   static struct rpmjsClassTable_s classTable[] = {
  +    { "Aug",         rpmjs_InitAugClass,      25 },
       { "Ds",          rpmjs_InitDsClass,       13 },
       { "Fi",          rpmjs_InitFiClass,       14 },
       { "File",                   js_InitFileClass,      1 },
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/tscripts/Aug.js
  ============================================================================
  $ cvs diff -u -r0 -r1.1 Aug.js
  --- /dev/null 2009-06-12 21:22:00 +0200
  +++ Aug.js    2009-06-12 21:29:28 +0200
  @@ -0,0 +1,9 @@
  +if (loglvl) print("--> Aug.js");
  +
  +var aug = new Aug();
  +ack("typeof aug;", "object");
  +ack("aug instanceof Aug;", true);
  +ack("aug = 1;", 1);
  +ack("aug = 0;", 0);
  +
  +if (loglvl) print("<-- Aug.js");
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to