Exemple #1
0
static JSBool
rpmdir_call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    /* XXX obj is the global object so lookup "this" object. */
    JSObject * o = JSVAL_TO_OBJECT(argv[-2]);
    void * ptr = JS_GetInstancePrivate(cx, o, &rpmdirClass, NULL);
    DIR * dir = ptr;
    JSBool ok = JS_FALSE;
    const char * _dn = NULL;

if (_debug)
fprintf(stderr, "==> %s(%p,%p,%p[%u],%p) o %p ptr %p\n", __FUNCTION__, cx, obj, argv, (unsigned)argc, rval, o, ptr);
    if (!(ok = JS_ConvertArguments(cx, argc, argv, "/s", &_dn)))
        goto exit;

    if (dir) {
	(void) Closedir(dir);
	/* XXX error msg */
	dir = ptr = NULL;
	(void) JS_SetPrivate(cx, o, (void *)dir);
    }

    dir = ptr = rpmdir_init(cx, o, _dn);

    *rval = OBJECT_TO_JSVAL(o);

    ok = JS_TRUE;

exit:
if (_debug)
fprintf(stderr, "<== %s(%p,%p,%p[%u],%p) o %p ptr %p\n", __FUNCTION__, cx, obj, argv, (unsigned)argc, rval, o, ptr);

    return ok;
}
Exemple #2
0
static JSBool
rpmdir_ctor(JSContext *cx, uintN argc, jsval *vp)
{
    jsval *argv = JS_ARGV(cx, vp);
    JSObject *obj = JS_NewObjectForConstructor(cx, vp);
    JSBool ok = JS_FALSE;
    const char * _dn = NULL;

_CTOR_DEBUG_ENTRY(_debug);

    if (!(ok = JS_ConvertArguments(cx, argc, argv, "/s", &_dn)))
        goto exit;

    if (JS_IsConstructing(cx, vp)) {
	(void) rpmdir_init(cx, obj, _dn);
    } else {
	if ((obj = JS_NewObject(cx, &rpmdirClass, NULL, NULL)) == NULL)
	    goto exit;
	*vp = OBJECT_TO_JSVAL(obj);
    }
    ok = JS_TRUE;

exit:
    return ok;
}
Exemple #3
0
JSObject *
rpmjs_NewDirObject(JSContext *cx, const char * _dn)
{
    JSObject *obj;
    DIR * dir;

    if ((obj = JS_NewObject(cx, &rpmdirClass, NULL, NULL)) == NULL) {
	/* XXX error msg */
	return NULL;
    }
    if ((dir = rpmdir_init(cx, obj, _dn)) == NULL) {
	/* XXX error msg */
	return NULL;
    }
    return obj;
}