JSBool js_cocos2dx_CCMenuItemAtlasFont_create(JSContext *cx, uint32_t argc, jsval *vp)
{
    const char *arg0 = NULL;
    const char *arg1 = NULL;
    do {
        if (argc >= 5) {
            jsval *argv = JS_ARGV(cx, vp);
            do { JSString *tmp = JS_ValueToString(cx, argv[0]); arg0 = JS_EncodeString(cx, tmp); } while (0);
            do { JSString *tmp = JS_ValueToString(cx, argv[1]); arg1 = JS_EncodeString(cx, tmp); } while (0);
            int arg2; if (!JS_ValueToInt32(cx, argv[2], &arg2)) break;
            int arg3; if (!JS_ValueToInt32(cx, argv[3], &arg3)) break;
            int arg4; if (!JS_ValueToInt32(cx, argv[4], &arg4)) break;
            cocos2d::CCMenuItemAtlasFont* ret = cocos2d::CCMenuItemAtlasFont::create(arg0, arg1, arg2, arg3, arg4);

            JS_free(cx, (void*)arg0);
            JS_free(cx, (void*)arg1);
            
            JSObject *obj = bind_menu_item<cocos2d::CCMenuItemAtlasFont>(cx, ret, (argc == 7 ? argv[6] : JSVAL_VOID), (argc >= 6 ? argv[5] : JSVAL_VOID));
            JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
            return JS_TRUE;
        }
    } while(0);
    
    JS_free(cx, (void*)arg0);
    JS_free(cx, (void*)arg1);
    
	return JS_FALSE;
}
Пример #2
0
static JSBool
js_inkey(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
	char		key[2];
	int32		mode=0;
	int32		timeout=0;
	sbbs_t*		sbbs;
    JSString*	js_str;

	if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
		return(JS_FALSE);

	if(argc)
		JS_ValueToInt32(cx,argv[0],&mode);
	if(argc>1)
		JS_ValueToInt32(cx,argv[1],&timeout);
	key[0]=sbbs->inkey(mode,timeout);
	key[1]=0;

	if((js_str = JS_NewStringCopyZ(cx, key))==NULL)
		return(JS_FALSE);

	*rval = STRING_TO_JSVAL(js_str);
    return(JS_TRUE);
}
Пример #3
0
static JSBool
js_printtail(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
	int			lines=0;
	long		mode=0;
	uintN		i;
	sbbs_t*		sbbs;
    JSString*	js_str=NULL;

	if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
		return(JS_FALSE);

	for(i=0;i<argc;i++) {
		if(JSVAL_IS_NUMBER(argv[i])) {
			if(!lines)
				JS_ValueToInt32(cx,argv[i],(int32*)&lines);
			else
				JS_ValueToInt32(cx,argv[i],(int32*)&mode);
		} else if(JSVAL_IS_STRING(argv[i]))
			js_str = JS_ValueToString(cx, argv[i]);
	}

	if(js_str==NULL)
		return(JS_FALSE);

	if(!lines) 
		lines=5;

	sbbs->printtail(JS_GetStringBytes(js_str),lines,mode);
    return(JS_TRUE);
}
Пример #4
0
/**
 * This method is called when setting a Property in HTMLTextArea
 */
static JSBool jhtml_textarea_setProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
	HTMLElement *pElem = (HTMLElement *) jhutil_GetPrivate(cx, obj);
	HTMLTextArea *pText = (pElem)? (HTMLTextArea *) pElem : 0;

	if (!pText)
		return JS_TRUE;

	switch (JSVAL_TO_INT(id))
	{
		case HTMLTEXTAREAELEMENT_COLS:
			if (JSVAL_IS_INT(*vp))
			{
				int32 cols;
				JS_ValueToInt32(cx, *vp, &cols);
				pText->SetCols(cols);
				pText->Update(0,0);
				return JS_TRUE;
			}
			break;
		case HTMLTEXTAREAELEMENT_ROWS:
			if (JSVAL_IS_INT(*vp))
			{
				int32 rows;
				JS_ValueToInt32(cx, *vp, &rows);
				pText->SetRows(rows);
				pText->Update(0,0);
				return JS_TRUE;
			}
			break;
		default:
			break;
	}//end switch
	return JS_TRUE;
}
Пример #5
0
static JSBool
fill_rectangle(JSContext *context, JSObject *obj,
               cairo_rectangle_int_t *rect)
{
    jsval val;

    if (!gjs_object_get_property_const(context, obj, GJS_STRING_X, &val))
        return JS_FALSE;
    if (!JS_ValueToInt32(context, val, &rect->x))
        return JS_FALSE;

    if (!gjs_object_get_property_const(context, obj, GJS_STRING_Y, &val))
        return JS_FALSE;
    if (!JS_ValueToInt32(context, val, &rect->y))
        return JS_FALSE;

    if (!gjs_object_get_property_const(context, obj, GJS_STRING_WIDTH, &val))
        return JS_FALSE;
    if (!JS_ValueToInt32(context, val, &rect->width))
        return JS_FALSE;

    if (!gjs_object_get_property_const(context, obj, GJS_STRING_HEIGHT, &val))
        return JS_FALSE;
    if (!JS_ValueToInt32(context, val, &rect->height))
        return JS_FALSE;

    return JS_TRUE;
}
Пример #6
0
JSBool
Window_redraw (JSContext* cx, JSObject* object, uintN argc, jsval* argv, jsval* rval)
{
    if (argc != 2 && argc != 0) {
        JS_ReportError(cx, "Not enough parameters.");
        return JS_FALSE;
    }

    WINDOW* win = ((WindowInformation*)JS_GetPrivate(cx, object))->win;

    JS_BeginRequest(cx);
    JS_EnterLocalRootScope(cx);
    switch (argc) {
        case 0: {
            wrefresh(win);
        } break;

        case 2: {
            jsint beg; JS_ValueToInt32(cx, argv[0], &beg);
            jsint num; JS_ValueToInt32(cx, argv[1], &num);

            wredrawln(win, beg, num);
        } break;
    }
    JS_LeaveLocalRootScope(cx);
    JS_EndRequest(cx);

    return JS_TRUE;

}
Пример #7
0
static JSBool
js_uploaded_file(JSContext *cx, uintN argc, jsval *arglist)
{
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
	jsval *argv=JS_ARGV(cx, arglist);
	private_t*	p;
	int32	files=1;
	int32	bytes=0;
	jsrefcount	rc;
	scfg_t*		scfg;

	scfg=JS_GetRuntimePrivate(JS_GetRuntime(cx));

	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL)
		return JS_FALSE;

	if(argc) {
		if(!JS_ValueToInt32(cx, argv[0], &bytes))
			return JS_FALSE;
	}
	if(argc>1) {
		if(!JS_ValueToInt32(cx, argv[1], &files))
			return JS_FALSE;
	}

	rc=JS_SUSPENDREQUEST(cx);
	js_getuserdat(scfg,p);

	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(user_uploaded(scfg, p->user, files, bytes)));
	JS_RESUMEREQUEST(cx, rc);

	return JS_TRUE;
}
Пример #8
0
static JSBool
js_conio_window(JSContext *cx, uintN argc, jsval *arglist)
{
	jsval *argv=JS_ARGV(cx, arglist);
	int32 left=1;
	int32 top=1;
	int32 right=cio_textinfo.screenwidth;
	int32 bottom=cio_textinfo.screenheight;
	jsrefcount	rc;

	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if(argc > 4)
		return(JS_FALSE);

	if(argc > 0) {
		if(!JSVAL_IS_NUMBER(argv[0]))
			return(JS_FALSE);
		if(!JS_ValueToInt32(cx, argv[0], &left))
			return(JS_FALSE);
	}
	if(argc > 1) {
		if(!JSVAL_IS_NUMBER(argv[1]))
			return(JS_FALSE);
		if(!JS_ValueToInt32(cx, argv[1], &top))
			return(JS_FALSE);
	}
	if(argc > 2) {
		if(!JSVAL_IS_NUMBER(argv[2]))
			return(JS_FALSE);
		if(!JS_ValueToInt32(cx, argv[2], &right))
			return(JS_FALSE);
	}
	if(argc > 3) {
		if(!JSVAL_IS_NUMBER(argv[3]))
			return(JS_FALSE);
		if(!JS_ValueToInt32(cx, argv[3], &bottom))
			return(JS_FALSE);
	}

	rc=JS_SUSPENDREQUEST(cx);
	window(left, top, right, bottom);
	JS_RESUMEREQUEST(cx, rc);
	if(cio_textinfo.winleft == left
			&& cio_textinfo.winright==right
			&& cio_textinfo.wintop==top
			&& cio_textinfo.winbottom==bottom) {
		JS_SET_RVAL(cx, arglist,JSVAL_TRUE);
	}
	else {
		JS_SET_RVAL(cx, arglist,JSVAL_FALSE);
	}
	return(JS_TRUE);
}
Пример #9
0
/** set numeric property (xn).
 */
JSBool xgg_pbar_propop_xn_set(JSContext *pcxa, JSObject *pobja, jsval id, jsval *vp)
{
	XGGPRIVHDR*		phdr = JS_GetPrivate(pcxa, pobja);
	XGG_PBAR_PRIV*	pv0 = JS_GetPrivate(pcxa, pobja);
	XJSEXADGELEM*	pelem0 = phdr->pxadgelem;
	XJSECTX*		pjsectx = (XJSECTX*)JS_GetContextPrivate(pcxa);
	XJSE_ASSERT(pelem0 != 0);	// basicelement inheritances must have this

	xjse_result_t	xr1;
	xjse_int_t		nid = 0;//, nvalue = 0;//, n1;
	char*			psz0;
	JS_ValueToInt32(pcxa, id, &nid);
	//JS_ValueToInt32(pcxa, vp[0], &nvalue);
	//XJSE_TRACE("xgg_pbar_propop_xn_set. [%d](%d)", nid, nvalue);

	switch(nid) {
	case PBAR_TID_EMPTYIMAGE:
		psz0 = JS_GetStringBytes(JS_ValueToString(pcxa, vp[0]));
		xr1 = xgg_xadget_reload_img(pjsectx, &(pv0->ppbempty), psz0, 0, 0);
		if(xr1 != XJSE_SUCCESS)
			goto	failed;
		if(pelem0->fcx == 0.0f)
			pelem0->fcx = (xjse_float_t)(pv0->ppbempty->nimgwidth);
		if(pelem0->fcy == 0.0f)
			pelem0->fcy = (xjse_float_t)(pv0->ppbempty->nimgheight);
		break;
	case PBAR_TID_FULLIMAGE:
		psz0 = JS_GetStringBytes(JS_ValueToString(pcxa, vp[0]));
		xr1 = xgg_xadget_reload_img(pjsectx, &(pv0->ppbfull), psz0, 0, 0);
		if(xr1 != XJSE_SUCCESS)
			goto	failed;
		break;
	case PBAR_TID_MAX:
		JS_ValueToInt32(pcxa, vp[0], &(pv0->nmax));
		break;
	case PBAR_TID_MIN:
		JS_ValueToInt32(pcxa, vp[0], &(pv0->nmin));
		break;
	case PBAR_TID_VALUE:
		JS_ValueToInt32(pcxa, vp[0], &(pv0->nvalue));
		break;
	default:
		XJSE_TRACE("(E) unknown xn prop [property id: %d]", nid);
	}

	return	JS_TRUE;

failed:
	return	JS_FALSE;
}
Пример #10
0
static JSBool
js_getstr(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
	char		*p;
	long		mode=0;
	uintN		i;
	size_t		maxlen=0;
	sbbs_t*		sbbs;
    JSString*	js_str=NULL;

	if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
		return(JS_FALSE);

	for(i=0;i<argc;i++) {
		if(JSVAL_IS_NUMBER(argv[i])) {
			if(!maxlen)
				JS_ValueToInt32(cx,argv[i],(int32*)&maxlen);
			else
				JS_ValueToInt32(cx,argv[i],(int32*)&mode);
			continue;
		}
		if(JSVAL_IS_STRING(argv[i])) {
			js_str = JS_ValueToString(cx, argv[i]);
			if (!js_str)
			    return(JS_FALSE);
		}
	}

	if(!maxlen) maxlen=128;

	if((p=(char *)calloc(1,maxlen+1))==NULL)
		return(JS_FALSE);

	if(js_str!=NULL)
		sprintf(p,"%.*s",(int)maxlen,JS_GetStringBytes(js_str));

	sbbs->getstr(p,maxlen,mode);

	js_str = JS_NewStringCopyZ(cx, p);

	free(p);

	if(js_str==NULL)
		return(JS_FALSE);

	*rval = STRING_TO_JSVAL(js_str);
    return(JS_TRUE);
}
Пример #11
0
/**
 * The function used as ZOOUpdateStatus from the JavaScript environment
 * (ZOO-API).
 *
 * @param cx the JavaScript context
 * @param argc the number of parameters
 * @param argv1 the parameter values
 * @return true
 * @see setHeader,_updateStatus
 */
JSBool
JSUpdateStatus(JSContext *cx, uintN argc, jsval *argv1)
{
  jsval *argv = JS_ARGV(cx,argv1);
  JS_MaybeGC(cx);
  int istatus=0;
  char *status=NULL;
  maps *conf;
  if(argc>2){
#ifdef JS_DEBUG
    fprintf(stderr,"Number of arguments used to call the function : %i",argc);
#endif
    return JS_FALSE;
  }
  conf=mapsFromJSObject(cx,argv[0]);
  if(JS_ValueToInt32(cx,argv[1],&istatus)==JS_TRUE){
    char tmpStatus[4];
    sprintf(tmpStatus,"%i",istatus);
    tmpStatus[3]=0;
    status=strdup(tmpStatus);
  }
  if(getMapFromMaps(conf,"lenv","status")!=NULL){
    if(status!=NULL){
      setMapInMaps(conf,"lenv","status",status);
      free(status);
    }
    else
      setMapInMaps(conf,"lenv","status","15");
    _updateStatus(conf);
  }
  freeMaps(&conf);
  free(conf);
  JS_MaybeGC(cx);
  return JS_TRUE;
}
Пример #12
0
template<> bool ScriptInterface::FromJSVal<unsigned long>(JSContext* cx, jsval v, unsigned long& out)
{
	int32 tmp;
	JSBool ok = JS_ValueToInt32(cx, v, &tmp);
	out = (unsigned long)tmp;
	return ok == JS_TRUE;
}
Пример #13
0
JSBool
TCP_connect (JSContext* cx, JSObject* object, uintN argc, jsval* argv, jsval* rval)
{
    char*    host;
    int      port    = -1;
    jsdouble timeout = 30;

    JS_BeginRequest(cx);

    if (argc < 1) {
        JS_ReportError(cx, "Not enough parameters.");
        JS_EndRequest(cx);
        return JS_FALSE;
    }

    jsval jsConnected;
    JS_GetProperty(cx, object, "connected", &jsConnected);

    if (jsConnected == JSVAL_TRUE) {
        JS_ReportError(cx, "The socket is already connected.");
        JS_EndRequest(cx);
        return JS_FALSE;
    }

    switch (argc) {
        case 3: JS_ValueToNumber(cx, argv[2], &timeout);
        case 2: JS_ValueToInt32(cx, argv[1], &port);
        case 1: host = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
    }

    TCPInformation* data = (TCPInformation*) JS_GetPrivate(cx, object);
    PRNetAddr addr; 

    if (__Sockets_initAddr(&addr, host, port) == PR_FAILURE) {
        *rval = JSVAL_FALSE;
        JS_EndRequest(cx);
        return JS_TRUE;
    }

    if (PR_Connect(data->socket, &addr, (timeout == -1)
        ? PR_INTERVAL_NO_TIMEOUT
        : PR_MicrosecondsToInterval(timeout*1000000)) == PR_FAILURE)
    {
        if (PR_GetError() == PR_CONNECT_RESET_ERROR) {
            JS_ReportError(cx, "Connection reset by peer.");
        }

        jsConnected = JSVAL_FALSE;
        JS_SetProperty(cx, object, "connected", &jsConnected);

        JS_EndRequest(cx);
        return JS_FALSE;
    }

    jsConnected = JSVAL_TRUE;
    JS_SetProperty(cx, object, "connected", &jsConnected);

    JS_EndRequest(cx);
    return JS_TRUE;
}
Пример #14
0
int
to_erl_int(emonk_buf_t* buf, JSContext* cx, jsval val)
{
    int32_t rval;
    
    if(!JS_ValueToInt32(cx, val, &rval)) return ERROR;
    
    if((unsigned int) rval < 255)
    {
        REQUEST(2);
        BUFPTR[0] = SMALL_INTEGER;
        BUFPTR[1] = (char) rval;
        buf->used += 2;
    }
    else
    {
        REQUEST(5);
        BUFPTR[0] = INTEGER;
        rval = htonl(rval);
        memcpy(BUFPTR+1, &rval, 4);
        buf->used += 5;
    }

    return OK;    
}
Пример #15
0
static JSBool
js_handle_ctrlkey(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
	char		key;
	int32		mode=0;
	sbbs_t*		sbbs;
    JSString*	js_str;

	*rval = JSVAL_FALSE;

	if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
		return(JS_FALSE);

	if(JSVAL_IS_INT(argv[0]))
		key=(char)JSVAL_TO_INT(argv[0]);
	else {
		if((js_str=JS_ValueToString(cx, argv[0]))==NULL)
			return(JS_FALSE);
		key=*JS_GetStringBytes(js_str);
	}

	if(argc>1)
		JS_ValueToInt32(cx, argv[1], &mode);

	*rval = BOOLEAN_TO_JSVAL(sbbs->handle_ctrlkey(key,mode)==0);
    return(JS_TRUE);
}
Пример #16
0
/**
 * InsertCell - insert a cell into this row
 *
 * params - int index - this index tells where to put the new cell.
 * return - HTMLElement - the newly added Cell
 */
JSBool jhtml_tablerow_insertCell(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
  #if (WEBC_SUPPORT_TABLES)
	HTMLElement *pElem = (HTMLElement *) jhutil_GetPrivate(cx, obj);
	HTMLTableRow *ptrow = (pElem)? (HTMLTableRow *) pElem : 0;
	if (ptrow && (argc > 0 && JSVAL_IS_INT(argv[0])))
	{
		int32 index = 0;
		JS_ValueToInt32(cx, argv[0], &index);

		HTMLElement *pElem = ptrow->InsertCell(index);
		ptrow->Update(0,0);
		if (pElem)
		{
			*rval = OBJECT_TO_JSVAL(pElem->CreateJSObject());
		}
		else
		{
			*rval = JSVAL_NULL;
		}
	}
	return JS_TRUE;
  #else // WEBC_SUPPORT_TABLES
    return JS_FALSE;
  #endif // WEBC_SUPPORT_TABLES
}
Пример #17
0
/**
 * Converts a jsval into a vibration duration, checking that the duration is in
 * bounds (non-negative and not larger than sMaxVibrateMS).
 *
 * Returns true on success, false on failure.
 */
bool
GetVibrationDurationFromJsval(const jsval& aJSVal, JSContext* cx,
                              int32_t* aOut)
{
  return JS_ValueToInt32(cx, aJSVal, aOut) &&
         *aOut >= 0 && static_cast<uint32_t>(*aOut) <= sMaxVibrateMS;
}
Пример #18
0
static JSBool
rpmhdr_setprop(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
{
    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmhdrClass, NULL);
    jsval idval;
    JS_IdToValue(cx, id, &idval);
    jsint tiny = JSVAL_TO_INT(idval);

_PROP_DEBUG_ENTRY(_debug < 0);

    /* 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;
}
Пример #19
0
static JSBool
js_conio_cgets(JSContext *cx, uintN argc, jsval *arglist)
{
	jsval *argv=JS_ARGV(cx, arglist);
	char	buf[258];
	int32	maxlen=255;
	char	*ret;
	jsrefcount	rc;

	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if(argc > 1)
		return(JS_FALSE);
	if(argc > 0) {
		if(!JSVAL_IS_NUMBER(argv[0]))
			return(JS_FALSE);
		if(!JS_ValueToInt32(cx, argv[0], &maxlen))
			return(JS_FALSE);
		if(maxlen > 255)
			return(JS_FALSE);
	}
	buf[0]=(char)maxlen;
	rc=JS_SUSPENDREQUEST(cx);
	ret=cgets(buf);
	JS_RESUMEREQUEST(cx, rc);
	if(ret==NULL)
		JS_SET_RVAL(cx, arglist,JSVAL_NULL);
	else {
		buf[257]=0;
		JS_SET_RVAL(cx, arglist,STRING_TO_JSVAL(JS_NewStringCopyZ(cx,ret)));
	}

	return(JS_TRUE);
}
Пример #20
0
Eina_Bool
elixir_object_get_int(JSContext *cx, JSObject *obj, const char *name, int *value)
{
   jsval propertie;
   jsdouble localdbl;

   if (!JS_GetProperty(cx, obj, name, &propertie))
     return EINA_FALSE;

   if (JSVAL_IS_INT(propertie)
       || JSVAL_IS_STRING(propertie))
     {
        if (!JS_ValueToInt32(cx, propertie, value))
          return EINA_FALSE;
     }
   else
     if (JSVAL_IS_DOUBLE(propertie))
       {
          if (!JS_ValueToNumber(cx, propertie, &localdbl))
            return EINA_FALSE;
          *value = localdbl;
       }
     else
       if (JSVAL_IS_BOOLEAN(propertie))
         {
            *value = JSVAL_TO_BOOLEAN(propertie);
         }
       else
         return EINA_FALSE;

   return EINA_TRUE;
}
Пример #21
0
double
elixir_get_dbl(JSContext *cx, jsval arg)
{
   double ret = 0;

   switch (elixir_params_get_type(arg))
     {
     case JINT:
     {
        int     lnum;

        if (JS_ValueToInt32(cx, arg, &lnum))
          ret = lnum;

        break;
     }
     case JDOUBLE:
     case JSTRING:
        JS_ValueToNumber(cx, arg, &ret);
        break;
     default:
        break;
     }

   return ret;
}
Пример #22
0
int
elixir_get_int(JSContext *cx, jsval arg)
{
   int ret = 0;

   switch (elixir_params_get_type(arg))
     {
     case JINT:
     case JSTRING:
        JS_ValueToInt32(cx, arg, &ret);
        break;
     case JDOUBLE:
     {
        jsdouble ldbl;

        if (JS_ValueToNumber(cx, arg, &ldbl))
          ret = ldbl;

        break;
     }
     default:
        break;
     }
   return ret;
}
Пример #23
0
static JSBool
js_conio_gettext(JSContext *cx, uintN argc, jsval *arglist)
{
	jsval *argv=JS_ARGV(cx, arglist);
	int32	args[4];
	unsigned char	*result;
	int		i;
	int		size;
	JSObject *array;
	jsval	val;
	jsrefcount	rc;

	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	/* default values: */
	args[0]=1;
	args[1]=1;
	args[2]=cio_textinfo.screenwidth;
	args[3]=cio_textinfo.screenheight;

	if(argc > 4)
		return(JS_FALSE);
	for(i=0; i<(int)argc; i++) {
		if(!JSVAL_IS_NUMBER(argv[i]))
			return(JS_FALSE);
		if(!JS_ValueToInt32(cx, argv[i], &args[i]))
			return(JS_FALSE);
	}
	if(args[0] < 1 || args[1] < 1 || args[2] < 1 || args[3] < 1
			|| args[0] > args[2] || args[1] > args[3]
			|| args[2] > cio_textinfo.screenwidth || args[3] > cio_textinfo.screenheight) {
		JS_SET_RVAL(cx, arglist,JSVAL_FALSE);
		return(JS_TRUE);
	}
	size=(args[2]-args[0]+1)*(args[3]-args[1]+1)*2;
	result=(unsigned char *)malloc(size);
	if(result==NULL)
		return(JS_FALSE);

	rc=JS_SUSPENDREQUEST(cx);

	if(gettext(args[0], args[1], args[2], args[3], result)) {
		JS_RESUMEREQUEST(cx, rc);
		array=JS_NewArrayObject(cx, 0, NULL);
		for(i=0; i<size; i++) {
			val=UINT_TO_JSVAL(result[i]);
			if(!JS_SetElement(cx, array, i, &val)) {
				free(result);
				return(JS_FALSE);
			}
		}
		JS_SET_RVAL(cx, arglist,OBJECT_TO_JSVAL(array));
	}
	else {
		JS_RESUMEREQUEST(cx, rc);
		JS_SET_RVAL(cx, arglist,JSVAL_NULL);
	}
	free(result);
	return(JS_TRUE);
}
Пример #24
0
JS_CLASS_METHOD(JsSpriteBatchNodeBinding,Create) {
	if(argc == 0 ) {
		jsval *args = JS_ARGV(context, vp);
		JSObject *jsonObj;
		JS_ValueToObject(context, args[0], &jsonObj);
		jsval fileNameVal;
		JS_GetProperty(context, jsonObj,
				"fileName", &fileNameVal);
		jsval capacityVal;
		JS_GetProperty(context, jsonObj,
				"capacity", &capacityVal);
		if(!JSVAL_IS_NULL(fileNameVal) && !JSVAL_IS_NULL(capacityVal)) {
			JSString *fileNameStr = JS_ValueToString(context, fileNameVal);
			char * fileName = JS_EncodeString(context,fileNameStr);
			int capacity = 0;
			JS_ValueToInt32(context,capacityVal,&capacity);
			CCSpriteBatchNode *pBatchNode = CCSpriteBatchNode::batchNodeWithFile(
					fileName, capacity);
			JS_free(context, fileName);
			if(pBatchNode) {
				JSObject *newObj = JS_NewObject(context, &clz, obj, NULL);
				JS_SetPrivate(context,newObj, pBatchNode);
				JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(newObj));
			}

		}
	}
	return JS_TRUE;
}
Пример #25
0
static JSBool Sys_openlog(JSContext *cx, unsigned argc, jsval *vp)
{
	static char ident[40] = "mailfilter";
	size_t len = sizeof(ident) - 1;
	int32_t facility = LOG_MAIL;

	if (argc >= 1) {
		JSString *str = JSVAL_TO_STRING(JS_ARGV(cx, vp)[0]);
		len = JS_EncodeStringToBuffer(str, ident, len);
		if (len < 0 || len >= sizeof(ident))
			len = sizeof(ident) - 1;
		ident[len] = '\0';
	}

	if (argc >= 2)
		JS_ValueToInt32(cx, JS_ARGV(cx, vp)[1], &facility);

	openlog(ident, LOG_PID, facility);

	// FIXME for better portability, do not pass vsyslog directly;
	// instead create a wrapper function that translates priority
	// from JS_LOG_* to LOG_*
	JS_LogSetCallback(vsyslog);

	return JS_TRUE;
}
static JSBool socket_read_bytes(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
	js_socket_obj_t *socket = JS_GetPrivate(cx, obj);
	if (socket == NULL) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to find js object.\n");
		return JS_FALSE;
	}

	if (argc == 1) {
		int32 bytes_to_read;
		switch_status_t ret;
		switch_size_t len;

		JS_ValueToInt32(cx, argv[0], &bytes_to_read);
		len = (switch_size_t) bytes_to_read;

		if (socket->buffer_size < len) {
			socket->read_buffer = switch_core_alloc(socket->pool, len + 1);
			socket->buffer_size = bytes_to_read + 1;
		}

		socket->saveDepth = JS_SuspendRequest(cx);
		ret = switch_socket_recv(socket->socket, socket->read_buffer, &len);
		JS_ResumeRequest(cx, socket->saveDepth);
		if (ret != SWITCH_STATUS_SUCCESS) {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "switch_socket_send failed: %d.\n", ret);
			*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
		} else {
			socket->read_buffer[len] = 0;
			*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, socket->read_buffer));
		}
	}

	return JS_TRUE;
}
Пример #27
0
static JSBool
rpmaug_setprop(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);

_PROP_DEBUG_ENTRY(_debug < 0);

    /* 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:
	/* XXX expr = undefined same as deleting? */
        if (JSVAL_IS_STRING(id)) {
            const char * name = JS_GetStringBytes(JS_ValueToString(cx, id));
            const char * expr = JS_GetStringBytes(JS_ValueToString(cx, *vp));
	    /* XXX should *setprop be permitted to delete NAME?!? */
	    /* XXX return is no. nodes in EXPR match. */
	    (void) rpmaugDefvar(aug, name, expr);
            break;
        }
	break;
    }

    return JS_TRUE;
}
Пример #28
0
static JSBool
js_get_time_left(JSContext *cx, uintN argc, jsval *arglist)
{
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
	jsval *argv=JS_ARGV(cx, arglist);
	private_t*	p;
	int32	start_time=0;
	jsrefcount	rc;
	scfg_t*		scfg;

	scfg=JS_GetRuntimePrivate(JS_GetRuntime(cx));

	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL)
		return JS_FALSE;

	if(argc) {
		if(!JS_ValueToInt32(cx, argv[0], &start_time))
			return JS_FALSE;
	}

	rc=JS_SUSPENDREQUEST(cx);
	js_getuserdat(scfg,p);

	JS_SET_RVAL(cx, arglist, INT_TO_JSVAL((int32_t)gettimeleft(scfg, p->user, start_time)));
	JS_RESUMEREQUEST(cx, rc);

	return JS_TRUE;
}
JSBool jsval_to_opaque( JSContext *cx, jsval vp, void **r)
{
#ifdef __LP64__
	JSObject *tmp_arg;
	if( ! JS_ValueToObject( cx, vp, &tmp_arg ) )
		return JS_FALSE;

	JSB_PRECONDITION( js_IsTypedArray( tmp_arg ), "jsb: Not a TypedArray object");

	JSB_PRECONDITION( JS_GetTypedArrayByteLength( tmp_arg ) == sizeof(void*), "jsb: Invalid Typed Array lenght");
	
	int32_t* arg_array = (int32_t*)JS_GetTypedArrayData( tmp_arg );
	uint64 ret =  arg_array[0];
	ret = ret << 32;
	ret |= arg_array[1];
	
#else
	assert( sizeof(int)==4);
	int32_t ret;
	if( ! JS_ValueToInt32(cx, vp, &ret ) )
	  return JS_FALSE;
#endif
	*r = (void*)ret;
	return JS_TRUE;
}
Пример #30
0
static JSBool
js_sent_email(JSContext *cx, uintN argc, jsval *arglist)
{
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
	jsval *argv=JS_ARGV(cx, arglist);
	private_t*	p;
	int32	count=1;
	BOOL	feedback=FALSE;
	jsrefcount	rc;
	scfg_t*		scfg;

	scfg=JS_GetRuntimePrivate(JS_GetRuntime(cx));

	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL)
		return JS_FALSE;

	if(argc) {
		if(!JS_ValueToInt32(cx, argv[0], &count))
			return JS_FALSE;
	}
	if(argc>1)
		JS_ValueToBoolean(cx, argv[1], &feedback);

	rc=JS_SUSPENDREQUEST(cx);
	js_getuserdat(scfg,p);

	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(user_sent_email(scfg, p->user, count, feedback)));
	JS_RESUMEREQUEST(cx, rc);

	return JS_TRUE;
}