Exemplo n.º 1
0
static JSBool
rpmhdr_ctor(JSContext *cx, uintN argc, jsval *vp)
{
    jsval *argv = JS_ARGV(cx , vp);
    JSObject *obj = JS_NewObjectForConstructor(cx , vp);
    if(!obj) {
	JS_ReportError(cx , "Failed to create 'this' object");
	return JS_FALSE;
    }
    JSBool ok = JS_FALSE;
    JSObject *tso = NULL;

_CTOR_DEBUG_ENTRY(_debug);

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

    if (JS_IsConstructing(cx, vp)) {
	if (rpmhdr_init(cx, obj, NULL))
	    goto exit;
    } else {
	if ((obj = JS_NewObject(cx, &rpmhdrClass, NULL, NULL)) == NULL)
	    goto exit;
	JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
    }
    ok = JS_TRUE;

exit:
    return ok;
}
Exemplo n.º 2
0
static JSBool
rpmhdr_setorigin(JSContext *cx, uintN argc, jsval *vp)
{
    jsval *argv = JS_ARGV(cx , vp);
    JSObject *obj = JS_NewObjectForConstructor(cx , vp);
    if(!obj) {
	JS_ReportError(cx , "Failed to create 'this' object");
	return JS_FALSE;
    }
    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmhdrClass, NULL);
    Header h = ptr;
    char * s = NULL;
    JSBool ok = JS_FALSE;

_METHOD_DEBUG_ENTRY(_debug);

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

    (void) headerSetOrigin(h, s);
    JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, headerGetOrigin(h))));
    ok = JS_TRUE;
exit:
    return ok;
}
Exemplo n.º 3
0
static JSBool
rpmmg_call(JSContext *cx, uintN argc, jsval *vp)
{
    jsval *argv = JS_ARGV(cx , vp);
    JSObject *obj = JS_NewObjectForConstructor(cx , vp);
    if(!obj) {
	JS_ReportError(cx , "Failed to create 'this' object");
	return JS_FALSE;
    }
    /* XXX obj is the global object so lookup "this" object. */
    JSObject * o = JSVAL_TO_OBJECT(argv[-2]);
    void * ptr = JS_GetInstancePrivate(cx, o, &rpmmgClass, NULL);
    rpmmg mg = ptr;
    JSBool ok = JS_FALSE;
    const char * _fn = NULL;
    const char * s = NULL;

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

    if (mg)
	s = rpmmgFile(mg, _fn);
    JS_SET_RVAL(cx, vp, (s ? STRING_TO_JSVAL(JS_NewStringCopyZ(cx, s)) : JSVAL_NULL));

    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, &JS_RVAL(cx, vp), o, mg);
    s = _free(s);
    return ok;
}
Exemplo n.º 4
0
static JSBool
rpmbf_ctor(JSContext *cx, uintN argc, jsval *vp)
{
    jsval *argv = JS_ARGV(cx, vp);
    JSObject *obj = JS_NewObjectForConstructor(cx, vp);
    unsigned int _m = 0;
    unsigned int _k = 0;
    unsigned int _flags = 0;
    JSBool ok = JS_FALSE;

_CTOR_DEBUG_ENTRY(_debug);

    if (!(ok = JS_ConvertArguments(cx, argc, argv, "/uuu", &_m, &_k, &_flags)))
	goto exit;
    ok = JS_FALSE;	/* XXX reset */

    if (JS_IsConstructing(cx, vp)) {
	if ((obj = JS_NewObject(cx, &rpmbfClass, NULL, NULL)) == NULL)
	    goto exit;
	if (rpmbf_init(cx, obj, _m, _k, _flags) == NULL)
	    goto exit;
    } else {
	obj = JS_THIS_OBJECT(cx, vp);
	*vp = OBJECT_TO_JSVAL(obj);
    }
    ok = JS_TRUE;

exit:
    return ok;
}
Exemplo n.º 5
0
static JSBool
rpmmg_ctor(JSContext *cx, uintN argc, jsval *vp)
{
    jsval *argv = JS_ARGV(cx , vp);
    JSObject *obj = JS_NewObjectForConstructor(cx , vp);
    if(!obj) {
	JS_ReportError(cx , "Failed to create 'this' object");
	return JS_FALSE;
    }
    JSBool ok = JS_FALSE;
    const char * _magicfile = NULL;
    int _flags = 0;

_CTOR_DEBUG_ENTRY(_debug);

    if (!(ok = JS_ConvertArguments(cx, argc, argv, "/su", &_magicfile, &_flags)))
        goto exit;

    if (JS_IsConstructing(cx, vp)) {
	(void) rpmmg_init(cx, obj, _magicfile, _flags);
    } else {
	if ((obj = JS_NewObject(cx, &rpmmgClass, NULL, NULL)) == NULL)
	    goto exit;
	JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
    }
    ok = JS_TRUE;

exit:
    return ok;
}
Exemplo n.º 6
0
static JSBool
rpmaug_ctor( JSContext* cx, uintN argc, jsval* vp )
{
    jsval *argv = JS_ARGV( cx , vp );
    JSObject *obj = JS_NewObjectForConstructor( cx , vp );
    if( ! obj ) {
	JS_ReportError( cx , "Failed to create 'this' object" );
	return JS_FALSE;
    }
    JSBool ok = JS_FALSE;
    const char * _root = _rpmaugRoot;
    const char * _loadpath = _rpmaugLoadpath;
    unsigned int _flags = _rpmaugFlags;

_CTOR_DEBUG_ENTRY(_debug, vp);

    if (!(ok = JS_ConvertArguments(cx, argc, argv, "/ssu", &_root, &_loadpath, &_flags)))
	goto exit;

    if (JS_IsConstructing(cx, vp)) {
	if (rpmaug_init(cx, obj, _root, _loadpath, _flags) == NULL)
	    goto exit;
    } else {
	if ((obj = JS_NewObject(cx, &rpmaugClass, NULL, NULL)) == NULL)
	    goto exit;
        JS_SET_RVAL( cx , vp , OBJECT_TO_JSVAL( obj ) );
    }
    ok = JS_TRUE;

exit:
    return ok;
}
Exemplo n.º 7
0
static JSBool
rpmseq_Close(JSContext *cx, uintN argc, jsval *vp)
{
    jsval *argv = JS_ARGV(cx , vp);
    JSObject *obj = JS_NewObjectForConstructor(cx , vp);
    if(!obj) {
	JS_ReportError(cx , "Failed to create 'this' object");
	return JS_FALSE;
    }
    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmseqClass, NULL);
    DB_SEQUENCE * seq = ptr;
    uint32_t _flags = 0;
    JSBool ok = JS_FALSE;

_METHOD_DEBUG_ENTRY(_debug);

    if (seq == NULL) goto exit;
    JS_SET_RVAL(cx, vp, JSVAL_FALSE);

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

    {	int ret = seq->close(seq, _flags);
	if (ret)
	    fprintf(stderr, "DB_SEQUENCE->close: %s\n", db_strerror(ret));
	else
	    JS_SET_RVAL(cx, vp, JSVAL_TRUE);
	seq = ptr = NULL;
	(void) JS_SetPrivate(cx, obj, ptr);
    }

    ok = JS_TRUE;
exit:
    return ok;
}
Exemplo n.º 8
0
static JSBool
rpmseq_ctor(JSContext *cx, uintN argc, jsval *vp)
{
    jsval *argv = JS_ARGV(cx , vp);
    JSObject *obj = JS_NewObjectForConstructor(cx , vp);
    if(!obj) {
	JS_ReportError(cx , "Failed to create 'this' object");
	return JS_FALSE;
    }
    JSObject * o = NULL;
    DB * _db = NULL;
    uint32_t _flags = 0;
    JSBool ok = JS_FALSE;

_CTOR_DEBUG_ENTRY(_debug);

    if (!(ok = JS_ConvertArguments(cx, argc, argv, "o/u", &o, &_flags)))
	goto exit;

    if (OBJ_IS_RPMDB(cx, o))
	_db = JS_GetInstancePrivate(cx, o, &rpmdbClass, NULL);

    if (JS_IsConstructing(cx, vp)) {
	(void) rpmseq_init(cx, obj, _db, _flags);
    } else {
	if ((obj = JS_NewObject(cx, &rpmseqClass, NULL, NULL)) == NULL)
	    goto exit;
	JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
    }
    ok = JS_TRUE;

exit:
    return ok;
}
Exemplo n.º 9
0
static JSBool
rpmsp_ctor(JSContext *cx, uintN argc, jsval *vp)
{
    jsval *argv = JS_ARGV(cx , vp);
    JSObject *obj = JS_NewObjectForConstructor(cx , vp);
    if(!obj) {
	JS_ReportError(cx , "Failed to create 'this' object");
	return JS_FALSE;
    }
    JSBool ok = JS_FALSE;

_CTOR_DEBUG_ENTRY(_debug);

    if (JS_IsConstructing(cx, vp)) {
	(void) rpmsp_init(cx, obj);
    } else {
	if ((obj = JS_NewObject(cx, &rpmspClass, NULL, NULL)) == NULL)
	    goto exit;
	JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
    }
    ok = JS_TRUE;

exit:
    return ok;
}
Exemplo n.º 10
0
static JSBool
rpmsp_call(JSContext *cx, uintN argc, jsval *vp)
{
    jsval *argv = JS_ARGV(cx , vp);
    JSObject *obj = JS_NewObjectForConstructor(cx , vp);
    if(!obj) {
	JS_ReportError(cx , "Failed to create 'this' object");
	return JS_FALSE;
    }
    /* XXX obj is the global object so lookup "this" object. */
    JSObject * o = JSVAL_TO_OBJECT(argv[-2]);
    void * ptr = JS_GetInstancePrivate(cx, o, &rpmspClass, NULL);
    JSBool ok = JS_FALSE;
#ifdef	FIXME
    rpmsp sp = ptr;
    const char *_fn = NULL;
    const char * _con = NULL;

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

    *rval = (sp && _fn && (_con = rpmspLgetfilecon(sp, _fn)) != NULL)
	? STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _con)) : JSVAL_VOID;
    _con = _free(_con);

    ok = JS_TRUE;

exit:
#endif

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

    return ok;
}
Exemplo n.º 11
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;
}
Exemplo n.º 12
0
static JSBool
rpmhdr_sprintf(JSContext *cx, uintN argc, jsval *vp)
{
    jsval *argv = JS_ARGV(cx , vp);
    JSObject *obj = JS_NewObjectForConstructor(cx , vp);
    if(!obj) {
	JS_ReportError(cx , "Failed to create 'this' object");
	return JS_FALSE;
    }
    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmhdrClass, NULL);
    Header h = ptr;
    char * qfmt = NULL;
    const char * s = NULL;
    const char * errstr = NULL;
    JSBool ok = JS_FALSE;

_METHOD_DEBUG_ENTRY(_debug);

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

    if ((s = headerSprintf(h, qfmt, NULL, rpmHeaderFormats, &errstr)) == NULL)
	s = errstr; 	/* XXX FIXME: returning errstr in-band. */
    JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, s)));
    ok = JS_TRUE;
exit:
    return ok;
}
Exemplo n.º 13
0
static bool
IterClassConstructor(JSContext *cx, unsigned argc, jsval *vp)
{
    JSObject *obj = JS_NewObjectForConstructor(cx, Jsvalify(&HasCustomIterClass), vp);
    if (!obj)
        return false;
    JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
    return true;
}
Exemplo n.º 14
0
JSBool
IterClassConstructor(JSContext *cx, uintN argc, jsval *vp)
{
    JSObject *obj = JS_NewObjectForConstructor(cx, vp);
    if (!obj)
        return false;
    JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
    return true;
}
Exemplo n.º 15
0
static bool
Prof(JSContext* cx, unsigned argc, jsval *vp)
{
    JSObject *obj = JS_NewObjectForConstructor(cx, &ptestClass, vp);
    if (!obj)
        return false;
    JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
    return true;
}
Exemplo n.º 16
0
static bool
PTest(JSContext* cx, unsigned argc, jsval* vp)
{
    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    JSObject* obj = JS_NewObjectForConstructor(cx, &ptestClass, args);
    if (!obj)
        return false;
    args.rval().setObject(*obj);
    return true;
}
Exemplo n.º 17
0
static JSBool
rpmseq_Get(JSContext *cx, uintN argc, jsval *vp)
{
    jsval *argv = JS_ARGV(cx , vp);
    JSObject *obj = JS_NewObjectForConstructor(cx , vp);
    if(!obj) {
	JS_ReportError(cx , "Failed to create 'this' object");
	return JS_FALSE;
    }
    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmseqClass, NULL);
    DB_SEQUENCE * seq = ptr;
    JSObject * o = NULL;
    DB_TXN * _txn = NULL;
    int32_t _delta = 1;
    uint32_t _flags = 0;
    JSBool ok = JS_FALSE;

_METHOD_DEBUG_ENTRY(_debug);

    if (seq == NULL) goto exit;
    JS_SET_RVAL(cx, vp, JSVAL_FALSE);

    if (!(ok = JS_ConvertArguments(cx, argc, argv, "o/iu", &o, &_delta, &_flags)))
	goto exit;

    if (o && OBJ_IS_RPMTXN(cx, o))
	_txn = JS_GetInstancePrivate(cx, o, &rpmtxnClass, NULL);
    if (_delta <= 0)
	goto exit;

    {	jsdouble d = 0;
	db_seq_t _seqno = 0;
	int ret = seq->get(seq, _txn, _delta, &_seqno, _flags);
	switch (ret) {
	default:
	    fprintf(stderr, "DB_SEQUENCE->get: %s\n", db_strerror(ret));
	    goto exit;
	    break;
	case 0:
	    d = _seqno;
	    if (!JS_NewNumberValue(cx, d, &JS_RVAL(cx, vp)))
		JS_SET_RVAL(cx, vp, JSVAL_FALSE);
	    break;
	}
    }

    ok = JS_TRUE;

exit:
    return ok;
}
Exemplo n.º 18
0
static JSBool
rpmseq_Open(JSContext *cx, uintN argc, jsval *vp)
{
    jsval *argv = JS_ARGV(cx , vp);
    JSObject *obj = JS_NewObjectForConstructor(cx , vp);
    if(!obj) {
	JS_ReportError(cx , "Failed to create 'this' object");
	return JS_FALSE;
    }
    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmseqClass, NULL);
    DB_SEQUENCE * seq = ptr;
    JSObject * o = NULL;
    DB_TXN * _txn = NULL;
    jsval _kv = JSVAL_NULL;
    _RPMDBT _k = _RPMDBT_INIT;
    uint32_t _flags = DB_CREATE;
    JSBool ok = JS_FALSE;

_METHOD_DEBUG_ENTRY(_debug);

    if (seq == NULL) goto exit;
    JS_SET_RVAL(cx, vp, JSVAL_FALSE);

    if (!(ok = JS_ConvertArguments(cx, argc, argv, "ov/u", &o, &_kv, &_flags)))
	goto exit;

    if (o && OBJ_IS_RPMTXN(cx, o))
	_txn = JS_GetInstancePrivate(cx, o, &rpmtxnClass, NULL);
    if (rpmdb_v2dbt(cx, _kv, &_k))
	goto exit;

    {	int ret = seq->open(seq, _txn, _RPMDBT_PTR(_k), _flags);
	switch (ret) {
	default:
	    fprintf(stderr, "DB_SEQUENCE->open: %s\n", db_strerror(ret));
	    goto exit;
	    break;
	case 0:
	    JS_SET_RVAL(cx, vp, JSVAL_TRUE);
	    seq->api_internal = obj;
	    break;
	}
    }

    ok = JS_TRUE;

exit:
    return ok;
}
Exemplo n.º 19
0
static JSBool
perlsub_construct(
    JSContext *cx,
    DEFJSFSARGS_
) {
    dTHX;
    DECJSFSARGS;
    JSObject *func = JSVAL_TO_OBJECT(JS_ARGV_CALLEE(argv));
    SV *callee = (SV *)JS_GetPrivate(cx, func);
    SV *caller = NULL;
#if JS_VERSION < 185
    JSObject *This = JSVAL_TO_OBJECT(argv[-1]);
#else
    JSObject *This = JS_NewObjectForConstructor(cx, vp);
#endif
    JSObject *proto = JS_GetPrototype(cx, This);

    PJS_DEBUG1("Want construct, This is a %s", PJS_GET_CLASS(cx, This)->name);
    if(PJS_GET_CLASS(cx, proto) == &perlpackage_class ||
       ( JS_LookupProperty(cx, func, "prototype", &argv[-1])
         && JSVAL_IS_OBJECT(argv[-1]) && !JSVAL_IS_NULL(argv[-1])
         && (proto = JS_GetPrototype(cx, JSVAL_TO_OBJECT(argv[-1]))) 
         && strEQ(PJS_GET_CLASS(cx, proto)->name, PJS_PACKAGE_CLASS_NAME))
    ) {
	SV *rsv = NULL;
	char *pkgname = PJS_GetPackageName(aTHX_ cx, proto);
#if JS_VERSION >= 185
	JSAutoByteString bytes;
	bytes.initBytes(pkgname);
#endif
	caller = newSVpv(pkgname, 0);

	argv[-1] = OBJECT_TO_JSVAL(This);
	if(!PJS_Call_sv_with_jsvals_rsv(aTHX_ cx, obj, callee, caller,
	                                argc, argv, &rsv, G_SCALAR))
	    return JS_FALSE;

	if(SvROK(rsv) && sv_derived_from(rsv, pkgname)) {
	    JSObject *newobj = PJS_NewPerlObject(aTHX_ cx, JS_GetParent(cx, func), rsv);
	    *rval = OBJECT_TO_JSVAL(newobj);
	    return JS_TRUE;
	}
	JS_ReportError(cx, "%s's constructor don't return an object",
	               SvPV_nolen(caller));
    }
    else JS_ReportError(cx, "Can't use as a constructor"); // Yet! ;-)

    return JS_FALSE;
}
Exemplo n.º 20
0
static JSBool
rpmseq_Remove(JSContext *cx, uintN argc, jsval *vp)
{
    jsval *argv = JS_ARGV(cx , vp);
    JSObject *obj = JS_NewObjectForConstructor(cx , vp);
    if(!obj) {
	JS_ReportError(cx , "Failed to create 'this' object");
	return JS_FALSE;
    }
    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmseqClass, NULL);
    DB_SEQUENCE * seq = ptr;
    JSObject * o = NULL;
    DB_TXN * _txn = NULL;
    uint32_t _flags = 0;
    JSBool ok = JS_FALSE;

_METHOD_DEBUG_ENTRY(_debug);

    if (seq == NULL) goto exit;
    JS_SET_RVAL(cx, vp, JSVAL_FALSE);

    if (!(ok = JS_ConvertArguments(cx, argc, argv, "o/u", &o, &_flags)))
	goto exit;

    if (o && OBJ_IS_RPMTXN(cx, o))
	_txn = JS_GetInstancePrivate(cx, o, &rpmtxnClass, NULL);

    {	int ret = seq->remove(seq, _txn, _flags);
	switch (ret) {
	default:
	    fprintf(stderr, "DB_SEQUENCE->remove: %s\n", db_strerror(ret));
	    goto exit;
	    break;
	case 0:
	    JS_SET_RVAL(cx, vp, JSVAL_TRUE);
	    break;
	}
	seq = ptr = NULL;
	(void) JS_SetPrivate(cx, obj, ptr);
    }

    ok = JS_TRUE;

exit:
    return ok;
}
JSObject *JSWrapperClass::instantiate( JS::CallArgs *args )
{
    JSObject *object = JS_NewObjectForConstructor( m_cx, m_jsClass, *args );
    RootedObject obj( m_cx, object ); RootedValue v( m_cx, JS::UndefinedValue() );

    for (std::map<std::string,bool (*) (JSContext *cx, unsigned argc, jsval *vp)>::iterator it = m_funcs.begin(); it != m_funcs.end(); it++)
    {
        JS_DefineFunction( m_cx, HandleObject(obj), it->first.c_str(), it->second, 0, 0);
    }

    args->rval().set( OBJECT_TO_JSVAL( object ) );

    for ( int i=0; i < m_properties.size(); ++i )
    {
        JS_DefineProperty( m_cx, HandleObject(obj), m_properties[i].c_str(), HandleValue(&v), JSPROP_SHARED, (JSNative) m_getProperties[i], (JSNative) m_setProperties[i] );
    }

    return object;
}
Exemplo n.º 22
0
static JSBool
rpmfc_ctor(JSContext *cx, uintN argc, jsval *vp)
{
    jsval *argv = JS_ARGV(cx, vp);
    JSObject *obj = JS_NewObjectForConstructor(cx, vp);
    JSBool ok = JS_FALSE;

_CTOR_DEBUG_ENTRY(_debug);

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

exit:
    return ok;
}
Exemplo n.º 23
0
bool RenderTargetConstructor( JSContext *cx, unsigned argc, jsval *vp )
{
    //printf( "RenderTarget Constructor!%d\n", argc );

    JS::CallArgs args = JS::CallArgsFromVp( argc, vp );

    JSObject *object = JS_NewObjectForConstructor( cx, &RenderTargetClass, args );
    RootedObject obj(cx, object ); RootedValue v(cx, JS::UndefinedValue() );
    JS_DefineFunctions( cx, HandleObject(obj), rendertarget_functions );
    JS_DefineProperty( cx, HandleObject(obj), "w", HandleValue(&v), JSPROP_SHARED, (JSPropertyOp) GetRenderTargetProperty, (JSStrictPropertyOp) SetRenderTargetProperty );
    JS_DefineProperty( cx, HandleObject(obj), "h", HandleValue(&v), JSPROP_SHARED, (JSPropertyOp) GetRenderTargetProperty, (JSStrictPropertyOp) SetRenderTargetProperty );
    JS_DefineProperty( cx, HandleObject(obj), "autoResize", HandleValue(&v), JSPROP_SHARED, (JSPropertyOp) GetRenderTargetProperty, (JSStrictPropertyOp) SetRenderTargetProperty );
    JS_DefineProperty( cx, HandleObject(obj), "main", HandleValue(&v), JSPROP_SHARED, (JSPropertyOp) GetRenderTargetProperty, (JSStrictPropertyOp) SetRenderTargetProperty );

    GLint w=0;
    GLint h=0;
    bool main=false;

    if ( argc >= 1 ) w=args[0].toInt32();
    if ( argc >= 2 ) h=args[1].toInt32();
    if ( argc >= 3 ) main=args[2].toBoolean();

    RenderTarget *target = new RenderTarget( w, h, main );

    JS_SetPrivate( object, target );
    args.rval().set( OBJECT_TO_JSVAL( object ) );

    //VG.Renderer().addResource(this);

    RootedValue rendererRC(cx); RootedObject global( cx,JS_GetGlobalForObject( cx, object ) );
    bool ok = JS_EvaluateScript( cx, HandleObject( global ), "VG.Renderer()", strlen("VG.Renderer()"), "unknown", 1, MutableHandleValue(&rendererRC) );    
    if ( ok )
    {
        RootedValue objectValue( cx, OBJECT_TO_JSVAL(object) );
        RootedObject renderer(cx, &rendererRC.toObject() ); MutableHandleValue handleValue( &rendererRC );
        ok=Call( cx, HandleObject(renderer), "addResource", HandleValueArray( objectValue ), handleValue );
    }

    return true;
}
Exemplo n.º 24
0
/* --- Object methods */
static JSBool
rpmhdr_ds(JSContext *cx, uintN argc, jsval *vp)
{
    jsval *argv = JS_ARGV(cx , vp);
    JSObject *obj = JS_NewObjectForConstructor(cx , vp);
    if(!obj) {
	JS_ReportError(cx , "Failed to create 'this' object");
	return JS_FALSE;
    }
    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmhdrClass, NULL);
    rpmTag tagN = RPMTAG_NAME;
    JSBool ok = JS_FALSE;

_METHOD_DEBUG_ENTRY(_debug);

    if (!(ok = JS_ConvertArguments(cx, argc, argv, "/u", &tagN)))
        goto exit;
    JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(rpmjs_NewDsObject(cx, OBJECT_TO_JSVAL(obj), tagN)));
    ok = JS_TRUE;
exit:
    return ok;
}
Exemplo n.º 25
0
static JSBool
constructHook(JSContext *cx, unsigned argc, jsval *vp)
{
    // Check that arguments were passed properly from JS_New.
    JS::RootedObject callee(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));

    JS::RootedObject obj(cx, JS_NewObjectForConstructor(cx, js::Jsvalify(&JSObject::class_), vp));
    if (!obj) {
        JS_ReportError(cx, "test failed, could not construct object");
        return false;
    }
    if (strcmp(JS_GetClass(obj)->name, "Object") != 0) {
        JS_ReportError(cx, "test failed, wrong class for 'this'");
        return false;
    }
    if (argc != 3) {
        JS_ReportError(cx, "test failed, argc == %d", argc);
        return false;
    }
    if (!JSVAL_IS_INT(argv[2]) || JSVAL_TO_INT(argv[2]) != 2) {
        JS_ReportError(cx, "test failed, wrong value in argv[2]");
        return false;
    }
    if (!JS_IsConstructing(cx, vp)) {
        JS_ReportError(cx, "test failed, not constructing");
        return false;
    }

    // Perform a side-effect to indicate that this hook was actually called.
    if (!JS_SetElement(cx, callee, 0, &argv[0]))
        return false;

    *vp = OBJECT_TO_JSVAL(obj);
    argv[0] = argv[1] = argv[2] = JSVAL_VOID;  // trash the argv, perversely
    return true;
}
Exemplo n.º 26
0
CEXPORT JSObject *animate_create_ctor_object(JSContext *cx, jsval *vp) {
	return JS_NewObjectForConstructor(cx, (JSClass*)&animate_class, vp);
}
CEXPORT JSObject *timestep_image_map_create_ctor_object(JSContext *cx, jsval *vp) {
	return JS_NewObjectForConstructor(cx, (JSClass*)&timestep_image_map_class, vp);
}