Exemplo n.º 1
0
static JSBool
rpmxar_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 * _fn = "popt-1.14.xar";
    const char * _fmode = "r";

_CTOR_DEBUG_ENTRY(_debug);

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

    if (JS_IsConstructing(cx, vp)) {
	(void) rpmxar_init(cx, obj, _fn, _fmode);
    } else {
	if ((obj = JS_NewObject(cx, &rpmxarClass, NULL, NULL)) == NULL)
	    goto exit;
	*vp = OBJECT_TO_JSVAL(obj);
    }
    ok = JS_TRUE;

exit:
    return ok;
}
Exemplo n.º 2
0
/**
 *  Binary constructor
 *
 *  @param	cx	JavaScript context
 *  @param	obj	Pre-allocated Binary object
 *  @param	argc	Number of arguments passed to constructor
 *  @param	argv	Arguments passed to constructor
 *  @param	rval	The new object returned to JavaScript
 *
 *  @returns 	JS_TRUE on success
 */
static JSBool Binary(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
  /* Binary() called as function. */   
  if (JS_IsConstructing(cx) != JS_TRUE)
    return gpsee_throw(cx, CLASS_ID ".constructor.notFunction: Cannot call constructor as a function!");

  /* Binary() called as constructor */
  return gpsee_throw(cx, CLASS_ID ".constructor: this class may not be instanciated!");
}  
Exemplo n.º 3
0
 static
 JSBool
 bytearray_cons
 (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 {
     if (!JS_IsConstructing(cx)) {
         // todo
         EJS_THROW_ERROR(cx,obj,"not yet implemented");
     }
     return JS_TRUE;
 }
Exemplo n.º 4
0
gboolean
gjs_check_constructing(JSContext *context)
{
    JS_BeginRequest(context);
    if (!JS_IsConstructing(context)) {
        JS_EndRequest(context);
        gjs_throw(context,
                  "Constructor called as normal method. Use 'new SomeObject()' not 'SomeObject()'");
        return FALSE;
    }

    JS_EndRequest(context);
    return TRUE;
}
Exemplo n.º 5
0
static JSBool
rpmmpf_ctor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    JSBool ok = JS_FALSE;

_CTOR_DEBUG_ENTRY(_debug);

    if (JS_IsConstructing(cx)) {
	(void) rpmmpf_init(cx, obj);
    } else {
	if ((obj = JS_NewObject(cx, &rpmmpfClass, NULL, NULL)) == NULL)
	    goto exit;
	*rval = OBJECT_TO_JSVAL(obj);
    }
    ok = JS_TRUE;

exit:
    return ok;
}
Exemplo n.º 6
0
JSBool JsSceneBinding::Create(JSContext *context, unsigned int argc, jsval *vp) {
	if (argc == 0) {
		JsScene* pScene = JsScene::node();
		if (pScene == NULL) {
			JS_ReportOutOfMemory(context);
			return JS_FALSE;
		}
		if (JS_IsConstructing(context, vp)) {
			JSObject *newObj = JS_NewObject(context, &clz, obj, NULL);
			JS_SetPrivate(context, newObj, pScene);
			JS_SET_RVAL(context, vp, OBJECT_TO_JSVAL(newObj));
		} else {
			JSObject *thisObj = JS_THIS_OBJECT(context, vp);
			JS_SetPrivate(context, thisObj, pScene);
		}
		return JS_TRUE;
	}
	return JS_FALSE;
}
Exemplo n.º 7
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.º 8
0
static JSBool
rpmdir_ctor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    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)) {
	(void) rpmdir_init(cx, obj, _dn);
    } else {
	if ((obj = JS_NewObject(cx, &rpmdirClass, NULL, NULL)) == NULL)
	    goto exit;
	*rval = OBJECT_TO_JSVAL(obj);
    }
    ok = JS_TRUE;

exit:
    return ok;
}
Exemplo n.º 9
0
static JSBool
syck_ctor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    JSBool ok = JS_FALSE;

_CTOR_DEBUG_ENTRY(_debug);

    if (JS_IsConstructing(cx)) {
	JSSyck ptr = xcalloc(0, sizeof(*ptr));

	if (ptr == NULL || !JS_SetPrivate(cx, obj, ptr)) {
	    ptr = _free(ptr);
	    goto exit;
	}
    } else {
	if ((obj = JS_NewObject(cx, &syckClass, NULL, NULL)) == NULL)
	    goto exit;
	*rval = OBJECT_TO_JSVAL(obj);
    }
    ok = JS_TRUE;

exit:
    return ok;
}
Exemplo n.º 10
0
static JSBool
rpmdc_ctor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    JSBool ok = JS_FALSE;
    unsigned int _dalgo = PGPHASHALGO_NONE;
    unsigned int _flags = RPMDIGEST_NONE;

_CTOR_DEBUG_ENTRY(_debug);

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

    if (JS_IsConstructing(cx)) {
	(void) rpmdc_init(cx, obj, _dalgo, _flags);
    } else {
	if ((obj = JS_NewObject(cx, &rpmdcClass, NULL, NULL)) == NULL)
	    goto exit;
	*rval = OBJECT_TO_JSVAL(obj);
    }
    ok = JS_TRUE;

exit:
    return ok;
}
Exemplo n.º 11
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.º 12
0
static JSBool
Exception(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    uint32 lineno;
    JSString *message, *filename;
    JSStackFrame *fp;

    if (!JS_IsConstructing(cx)) {
        /*
         * ECMA ed. 3, 15.11.1 requires Error, etc., to construct even when
         * called as functions, without operator new.  But as we do not give
         * each constructor a distinct JSClass, whose .name member is used by
         * js_NewObject to find the class prototype, we must get the class
         * prototype ourselves.
         */
        if (!JSVAL_TO_OBJECT(argv[-2])->getProperty(cx,
                                                    ATOM_TO_JSID(cx->runtime->atomState
                                                                 .classPrototypeAtom),
                                                    rval)) {
            return JS_FALSE;
        }
        obj = js_NewObject(cx, &js_ErrorClass, JSVAL_TO_OBJECT(*rval), NULL);
        if (!obj)
            return JS_FALSE;
        *rval = OBJECT_TO_JSVAL(obj);
    }

    /*
     * If it's a new object of class Exception, then null out the private
     * data so that the finalizer doesn't attempt to free it.
     */
    if (OBJ_GET_CLASS(cx, obj) == &js_ErrorClass)
        obj->setPrivate(NULL);

    /* Set the 'message' property. */
    if (argc != 0) {
        message = js_ValueToString(cx, argv[0]);
        if (!message)
            return JS_FALSE;
        argv[0] = STRING_TO_JSVAL(message);
    } else {
        message = cx->runtime->emptyString;
    }

    /* Set the 'fileName' property. */
    if (argc > 1) {
        filename = js_ValueToString(cx, argv[1]);
        if (!filename)
            return JS_FALSE;
        argv[1] = STRING_TO_JSVAL(filename);
        fp = NULL;
    } else {
        fp = js_GetScriptedCaller(cx, NULL);
        if (fp) {
            filename = FilenameToString(cx, fp->script->filename);
            if (!filename)
                return JS_FALSE;
        } else {
            filename = cx->runtime->emptyString;
        }
    }

    /* Set the 'lineNumber' property. */
    if (argc > 2) {
        lineno = js_ValueToECMAUint32(cx, &argv[2]);
        if (JSVAL_IS_NULL(argv[2]))
            return JS_FALSE;
    } else {
        if (!fp)
            fp = js_GetScriptedCaller(cx, NULL);
        lineno = (fp && fp->regs) ? js_FramePCToLineNumber(cx, fp) : 0;
    }

    return (OBJ_GET_CLASS(cx, obj) != &js_ErrorClass) ||
            InitExnPrivate(cx, obj, message, filename, lineno, NULL);
}