예제 #1
0
파일: PJS_PerlSub.c 프로젝트: gitpan/JSPL
static JSBool
perlsub_call(
    JSContext *cx, 
    DEFJSFSARGS_
) {
    dTHX;
    DECJSFSARGS;
    JSObject *func = JSVAL_TO_OBJECT(JS_ARGV_CALLEE(argv));
    SV *callee = (SV *)JS_GetPrivate(cx, func);
    JSObject *This = JSVAL_TO_OBJECT(argv[-1]);
    JSClass *clasp = PJS_GET_CLASS(cx, This);
    SV *caller;
    JSBool wanta, isclass = JS_FALSE;

    if(!JS_GetProperty(cx, func, "$wantarray", rval) ||
       !JS_ValueToBoolean(cx, *rval, &wanta))
	return JS_FALSE;

    PJS_DEBUG1("In PSC: obj is %s\n", PJS_GET_CLASS(cx, obj)->name);
    if(clasp == &perlpackage_class) {
       if(!JS_GetProperty(cx, This, "$__im_a_class", rval) ||
          !JS_ValueToBoolean(cx, *rval, &isclass))
	    return JS_FALSE;
    }

    if(isclass ||
       ( clasp == &perlsub_class /* Constructors has a Stash in __proto__ */
         && (func = JS_GetPrototype(cx, This))
         && PJS_GET_CLASS(cx, func) == &perlpackage_class)
    ) { // Caller is a stash, make a static call
	char *pkgname = PJS_GetPackageName(aTHX_ cx, This);
	if(!pkgname) return JS_FALSE;
	caller = newSVpv(pkgname, 0);
	PJS_DEBUG1("Caller is a stash: %s\n", pkgname);
#if JS_VERSION >= 185
	Safefree(pkgname);
#endif
    }
    else if(IS_PERL_CLASS(clasp) &&
	    sv_isobject(caller = (SV *)JS_GetPrivate(cx, This))
    ) { // Caller is a perl object
	SvREFCNT_inc_void_NN(caller);
	PJS_DEBUG1("Caller is an object: %s\n", SvPV_nolen(caller));
    }
    else {
	caller = NULL;
	PJS_DEBUG1("Caller is %s\n", clasp->name);
    }

    return PJS_Call_sv_with_jsvals(aTHX_ cx, obj, callee, caller, argc, argv,
                                   rval, wanta ? G_ARRAY : G_SCALAR);
}
JSBool js_skeleton_setAnimation(JSContext *cx, uint32_t argc, jsval *vp)
{
    JSObject *obj = NULL;
    cocos2d::extension::CCSkeletonAnimation* cobj = NULL;
    obj = JS_THIS_OBJECT(cx, vp);
    js_proxy_t *proxy = jsb_get_js_proxy(obj);
    // 获取 js 绑定的实际对象 通过 proxy->ptr
    cobj = (cocos2d::extension::CCSkeletonAnimation*)(proxy ? proxy->ptr : NULL);
    JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
    if (argc == 2) {
        jsval *argvp = JS_ARGV(cx,vp);
        JSBool ok = JS_TRUE;
        const char* arg1; JSBool arg2;
        
        ok &= jsval_to_charptr(cx, *argvp++, &arg1);
        ok &= JS_ValueToBoolean(cx, *argvp++, &arg2);
        JSB_PRECONDITION(ok, "Error processing arguments");
        
        cobj->setAnimation(arg1, arg2);
        JS_SET_RVAL(cx, vp, JSVAL_VOID);
        return ok;
    }
    
    JS_ReportError(cx, "wrong number of arguments");
    return JS_FALSE;
}
예제 #3
0
파일: jssql.c 프로젝트: mindbit/libjssql
static JSBool DriverManager_getDriver(JSContext *cx, unsigned argc, jsval *vp)
{
	jsval drivers;
	JS_LookupProperty(cx, JS_THIS_OBJECT(cx, vp), "drivers", &drivers);
	// FIXME check return code; check that drivers is an array
	JSObject *obj = JSVAL_TO_OBJECT(drivers);

	uint32_t len, i;
	JS_GetArrayLength(cx, obj, &len);

	for (i = 0; i < len; i++) {
		jsval driver, rval;
		jsval acceptsURL_argv[] = {JS_ARGV(cx, vp)[0]};

		JS_GetElement(cx, obj, i, &driver);
		JS_CallFunctionName(cx, JSVAL_TO_OBJECT(driver), "acceptsURL", 1, &acceptsURL_argv[0], &rval); // FIXME check return value

		JSBool acceptsURL;
		JS_ValueToBoolean(cx, rval, &acceptsURL); // FIXME check ret val
		if (acceptsURL) {
			JS_SET_RVAL(cx, vp, driver);
			return JS_TRUE;
		}
	}

	JS_ReportError(cx, "No suitable driver");
	JS_SET_RVAL(cx, vp, JSVAL_NULL);
	return JS_FALSE;
}
예제 #4
0
static JSBool
js_gc(JSContext *cx, uintN argc, jsval *arglist)
{
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
	jsval *argv=JS_ARGV(cx, arglist);
	JSBool			forced=JS_TRUE;
	js_callback_t*	cb;

	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((cb=(js_callback_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_FALSE);

	if(argc)
		JS_ValueToBoolean(cx,argv[0],&forced);

	if(forced)
		JS_GC(cx);
	else
		JS_MaybeGC(cx);

	cb->gc_attempts++;

	return(JS_TRUE);
}
예제 #5
0
NS_IMETHODIMP
nsPluginArray::Refresh()
{
  nsCOMPtr<nsIXPCNativeCallContext> ncc;
  nsresult rv = nsContentUtils::XPConnect()->
    GetCurrentNativeCallContext(getter_AddRefs(ncc));
  NS_ENSURE_SUCCESS(rv, rv);

  if (!ncc)
    return NS_ERROR_NOT_AVAILABLE;

  PRBool reload_doc = PR_FALSE;

  PRUint32 argc;

  ncc->GetArgc(&argc);

  if (argc > 0) {
    jsval *argv = nsnull;

    ncc->GetArgvPtr(&argv);
    NS_ENSURE_TRUE(argv, NS_ERROR_UNEXPECTED);

    JSContext *cx = nsnull;

    rv = ncc->GetJSContext(&cx);
    NS_ENSURE_SUCCESS(rv, rv);

    JS_ValueToBoolean(cx, argv[0], &reload_doc);
  }

  return Refresh(reload_doc);
}
예제 #6
0
JSBool js_cocos2dx_spine_SkeletonAnimation_setAnimation(JSContext *cx, uint32_t argc, jsval *vp)
{
	jsval *argv = JS_ARGV(cx, vp);
	JSBool ok = JS_TRUE;
	JSObject *obj = JS_THIS_OBJECT(cx, vp);
	js_proxy_t *proxy = jsb_get_js_proxy(obj);
	spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL);
	JSB_PRECONDITION2( cobj, cx, JS_FALSE, "js_cocos2dx_spine_SkeletonAnimation_setAnimation : Invalid Native Object");
	if (argc == 3) {
		int arg0;
		const char* arg1;
		JSBool arg2;
		ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0);
		std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str();
		ok &= JS_ValueToBoolean(cx, argv[2], &arg2);
		JSB_PRECONDITION2(ok, cx, JS_FALSE, "js_cocos2dx_spine_SkeletonAnimation_setAnimation : Error processing arguments");
		spTrackEntry* ret = cobj->setAnimation(arg0, arg1, arg2);
		jsval jsret = JSVAL_NULL;
		#pragma warning NO CONVERSION FROM NATIVE FOR spTrackEntry*;
		JS_SET_RVAL(cx, vp, jsret);
		return JS_TRUE;
	}

	JS_ReportError(cx, "js_cocos2dx_spine_SkeletonAnimation_setAnimation : wrong number of arguments: %d, was expecting %d", argc, 3);
	return JS_FALSE;
}
예제 #7
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;
}
예제 #8
0
	/** 
	 * Converts a jsval to a C++ boolean
	 *   - uses ECMAScript conversion function if jsval is not boolean
	 *   - throws exception if conversion fails
	 *
	 * \param 	val   Value to convert
	 * \return	C++ boolean
	 */
	static bool jsval_to_boolean_convert_x(JSContext* cx, jsval val)
	{
		JSBool result;
		if(!JS_ValueToBoolean(cx, val, &result))
			throw exception("Could not convert jsval to boolean");

		return result != 0;
	}
예제 #9
0
static JSBool js_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
{
	jsval idval;
    jsint			tiny;
	js_callback_t*	cb;

	if((cb=(js_callback_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_FALSE);

    JS_IdToValue(cx, id, &idval);
    tiny = JSVAL_TO_INT(idval);

	switch(tiny) {
		case PROP_TERMINATED:
			if(cb->terminated!=NULL)
				JS_ValueToBoolean(cx, *vp, (int *)cb->terminated);
			break;
		case PROP_AUTO_TERMINATE:
			JS_ValueToBoolean(cx,*vp,&cb->auto_terminate);
			break;
		case PROP_COUNTER:
			if(!JS_ValueToInt32(cx, *vp, (int32*)&cb->counter))
				return JS_FALSE;
			break;
		case PROP_TIME_LIMIT:
			if(!JS_ValueToInt32(cx, *vp, (int32*)&cb->limit))
				return JS_FALSE;
			break;
		case PROP_GC_INTERVAL:
			if(!JS_ValueToInt32(cx, *vp, (int32*)&cb->gc_interval))
				return JS_FALSE;
			break;
		case PROP_YIELD_INTERVAL:
			if(!JS_ValueToInt32(cx, *vp, (int32*)&cb->yield_interval))
				return JS_FALSE;
			break;
#ifdef jscntxt_h___
		case PROP_MAXBYTES:
			if(!JS_ValueToInt32(cx, *vp, (int32*)&cx->runtime->gcMaxBytes))
				return JS_FALSE;
			break;
#endif
	}

	return(JS_TRUE);
}
예제 #10
0
JSBool
Window_printChar (JSContext* cx, JSObject* object, uintN argc, jsval* argv, jsval* rval)
{
    if (argc < 1) {
        JS_ReportError(cx, "Not enough parameters.");
        return JS_FALSE;
    }

    JS_BeginRequest(cx);
    JS_EnterLocalRootScope(cx);

    WINDOW* win = (WINDOW*) JS_GetPrivate(cx, object);

    jsint ch; JS_ValueToInt32(cx, argv[0], &ch);

    if (argc == 1){
        waddch(win, ch);
    }
    else if (argc == 2) {
        JSObject* options; JS_ValueToObject(cx, argv[1], &options);

        jsval x, y;

        JS_GetProperty(cx, options, "x", &x);
        if (JSVAL_IS_VOID(x) || JSVAL_IS_NULL(x)) {
            JS_GetProperty(cx, options, "X", &x);
        }

        JS_GetProperty(cx, options, "y", &y);
        if (JSVAL_IS_VOID(y) || JSVAL_IS_NULL(y)) {
            JS_GetProperty(cx, options, "Y", &y);
        }

        jsval jsEcho; JS_GetProperty(cx, options, "echo", &jsEcho);
        JSBool echo; JS_ValueToBoolean(cx, jsEcho, &echo);

        __Window_options(cx, win, options, JS_TRUE);
        if (echo) {
            wechochar(win, ch);
        }
        else if (!JSVAL_IS_INT(x) && !JSVAL_IS_INT(y)) {
            waddch(win, ch);
        }
        else {
            mvwaddch(win,
                JSVAL_IS_INT(y) ? JSVAL_TO_INT(y) : 0,
                JSVAL_IS_INT(x) ? JSVAL_TO_INT(x) : 0,
                ch
            );
        }
        __Window_options(cx, win, options, JS_FALSE);
    }

    JS_LeaveLocalRootScope(cx);
    JS_EndRequest(cx);

    return JS_TRUE;
}
예제 #11
0
template<> bool ScriptInterface::FromJSVal<bool>(JSContext* cx, jsval v, bool& out)
{
	JSBool ret;
	WARN_IF_NOT(JSVAL_IS_BOOLEAN(v), v);
	if (!JS_ValueToBoolean(cx, v, &ret))
		return false;
	out = (ret ? true : false);
	return true;
}
예제 #12
0
파일: js.c 프로젝트: dev-life/showtime
JSBool
js_is_prop_true(JSContext *cx, JSObject *o, const char *prop)
{
  jsval val;
  JSBool b;
  if(!JS_GetProperty(cx, o, prop, &val))
    return 0;
  if(!JS_ValueToBoolean(cx, val, &b))
    return 0;
  return b;
}
예제 #13
0
JS_CLASS_METHOD(JsSimpleAudioEngineBinding,StopBackgroundMusic)
{
	if(argc == 1)
	{
		jsval *args = JS_ARGV(context, vp);
		JSBool bReleaseData = false;
		JS_ValueToBoolean(context,args[0],&bReleaseData);
		SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(bReleaseData);
	}
	return JS_TRUE;
}
예제 #14
0
static JSBool 
setEnabled(JSContext *cx, JSObject *obj, jsval idval, jsval *vp)
{ 
  JSBool on;

  if(!JS_ValueToBoolean(cx, *vp, &on))
    return JS_FALSE;
  
  js_service_t *jss = JS_GetPrivate(cx, obj);
  service_set_enabled(jss->jss_s, on);
  return JS_TRUE;
}
예제 #15
0
파일: js_page.c 프로젝트: Bibamaru/showtime
static JSBool 
js_setLoading(JSContext *cx, JSObject *obj, jsval idval, jsval *vp)
{ 
  js_model_t *jm = JS_GetPrivate(cx, obj);
  JSBool on;

  if(!JS_ValueToBoolean(cx, *vp, &on))
    return JS_FALSE;

  prop_set_int(jm->jm_loading, on);
  return JS_TRUE;
}
예제 #16
0
static JSBool js_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
    jsint			tiny;
    js_branch_t*	branch;

    if((branch=(js_branch_t*)JS_GetPrivate(cx,obj))==NULL)
        return(JS_FALSE);

    tiny = JSVAL_TO_INT(id);

    switch(tiny) {
    case PROP_TERMINATED:
        if(branch->terminated!=NULL)
            JS_ValueToBoolean(cx, *vp, branch->terminated);
        break;
    case PROP_AUTO_TERMINATE:
        JS_ValueToBoolean(cx,*vp,&branch->auto_terminate);
        break;
    case PROP_BRANCH_COUNTER:
        JS_ValueToInt32(cx, *vp, (int32*)&branch->counter);
        break;
    case PROP_BRANCH_LIMIT:
        JS_ValueToInt32(cx, *vp, (int32*)&branch->limit);
        break;
    case PROP_GC_INTERVAL:
        JS_ValueToInt32(cx, *vp, (int32*)&branch->gc_interval);
        break;
    case PROP_YIELD_INTERVAL:
        JS_ValueToInt32(cx, *vp, (int32*)&branch->yield_interval);
        break;
#ifdef jscntxt_h___
    case PROP_MAXBYTES:
        JS_ValueToInt32(cx, *vp, (int32*)&cx->runtime->gcMaxBytes);
        break;
#endif
    }

    return(JS_TRUE);
}
예제 #17
0
파일: js.c 프로젝트: stallman/showtime
static JSBool 
jsp_setEnableSearch(JSContext *cx, JSObject *obj, jsval idval, jsval *vp)
{ 
  js_plugin_t *jsp = JS_GetPrivate(cx, obj);
  JSBool on;

  if(!JS_ValueToBoolean(cx, *vp, &on))
    return JS_FALSE;

  jsp->jsp_enable_search = on;

  TRACE(TRACE_DEBUG, "plugins", "Plugin %s %sabled search",
	jsp->jsp_id, on ? "en" : "dis");

  return JS_TRUE;
}
예제 #18
0
  JSBool
  ejsaudio_LTX_onLoad(JSContext* cx, JSObject* module)
  {
    AudioConfig ac;
    jsval val;

#define GET_STRING(prop) do{						\
      if (!ejs_evalExpression(cx,module,"ejs.config.Audio."#prop,&val))	\
	JS_ClearPendingException(cx);					\
      else{								\
	JSString* s=NULL;char *cstr=NULL;				\
	if ((!(s=JS_ValueToString(cx,val)))				\
	    || (!(cstr=JS_GetStringBytes(s)))) return JS_FALSE;		\
	ac.prop=cstr;							\
      }									\
    }while(0)

    GET_STRING(sdriver);
    GET_STRING(sdevice);
    
#define GET_INT32(prop) do{						\
      int32 i;								\
      if (!ejs_evalExpression(cx,module,"ejs.config.Audio."#prop,&val))	\
	JS_ClearPendingException(cx);					\
      else{								\
	if (!JS_ValueToECMAInt32(cx,val,&i)) return JS_FALSE;		\
	ac.prop=i;							\
      }									\
    }while(0)
    
    GET_INT32(srate);
    GET_INT32(sbits);
    GET_INT32(sbuffers);

    if (!ejs_evalExpression(cx,module,"ejs.config.Audio.stereo",&val))
      JS_ClearPendingException(cx);
    else{
      JSBool jsb;
      if (!JS_ValueToBoolean(cx, val, &jsb)) return JS_FALSE;
      ac.stereo=jsb;
    }

    Audio::init(ac);

    if (!JS_DefineFunctions(cx, module, static_methods)) return JS_FALSE;
    return JS_TRUE;
  }
예제 #19
0
static JSBool
jss_set_value(JSContext *cx, JSObject *obj, jsval idval, jsval *vp)
{
  jsval v = *vp;
  js_setting_t *jss = JS_GetPrivate(cx, obj);

  if(jss->jss_freezed)
    return JS_TRUE;

  assert(jss->jss_s != NULL);

  JSBool b;
  int32 i32;
  JSString *str;

  // We need to be a bit more strict about value types here so
  // it's not possible to just use js_prop_set_from_jsval()

  switch(settings_get_type(jss->jss_s)) {
  case SETTING_INT:
    if(!JS_ValueToInt32(cx, v, &i32))
      return JS_FALSE;
    setting_set(jss->jss_s, SETTING_INT, i32);
    break;

  case SETTING_BOOL:
    if(!JS_ValueToBoolean(cx, v, &b))
      return JS_FALSE;
    setting_set(jss->jss_s, SETTING_BOOL, b);
    break;

  case SETTING_STRING:
    str = JS_ValueToString(cx, v);
    if(str == NULL)
      return JS_FALSE;
    setting_set(jss->jss_s, SETTING_STRING, JS_GetStringBytes(str));
    break;

  case SETTING_MULTIOPT:
    str = JS_ValueToString(cx, v);
    if(str == NULL)
      return JS_FALSE;
    setting_set(jss->jss_s, SETTING_STRING, JS_GetStringBytes(str));
    break;
  }
  return JS_TRUE;
}
bool
DOMProxyHandler::delete_(JSContext* cx, JS::Handle<JSObject*> proxy,
                         JS::Handle<jsid> id, bool* bp)
{
  JSBool b = true;

  JSObject* expando;
  if (!xpc::WrapperFactory::IsXrayWrapper(proxy) && (expando = GetExpandoObject(proxy))) {
    Value v;
    if (!JS_DeletePropertyById2(cx, expando, id, &v) || !JS_ValueToBoolean(cx, v, &b)) {
      return false;
    }
  }

  *bp = !!b;
  return true;
}
예제 #21
0
JS_CLASS_METHOD(JsSimpleAudioEngineBinding,PlayEffect)
{
	if(argc >= 1)
	{	jsval *args = JS_ARGV(context, vp);
		JSString *fileNameStr = JS_ValueToString(context,args[0]);
		char *pFileName = JS_EncodeString(context,fileNameStr);
		JSBool bLoop = false;
		if(argc == 2)
		{
			JS_ValueToBoolean(context,args[1],&bLoop);
		}
		if(pFileName)
		{
			SimpleAudioEngine::sharedEngine()->playEffect(pFileName,bLoop);
		}
		JS_free(context,pFileName);
	}
	return JS_TRUE;
}
예제 #22
0
JSBool js_fygui_FYPropCell_setHighlighted(JSContext *cx, uint32_t argc, jsval *vp)
{
	jsval *argv = JS_ARGV(cx, vp);
	JSBool ok = JS_TRUE;
	JSObject *obj = JS_THIS_OBJECT(cx, vp);
	js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
	FYPropCell* cobj = (FYPropCell *)(proxy ? proxy->ptr : NULL);
	JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
	if (argc == 1) {
		JSBool arg0;
		ok &= JS_ValueToBoolean(cx, argv[0], &arg0);
		JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
		cobj->setHighlighted(arg0);
		JS_SET_RVAL(cx, vp, JSVAL_VOID);
		return JS_TRUE;
	}

	JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
	return JS_FALSE;
}
예제 #23
0
static JSBool
js_gc(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    JSBool			forced=JS_TRUE;
    js_branch_t*	branch;

    if((branch=(js_branch_t*)JS_GetPrivate(cx,obj))==NULL)
        return(JS_FALSE);

    if(argc)
        JS_ValueToBoolean(cx,argv[0],&forced);

    if(forced)
        JS_GC(cx);
    else
        JS_MaybeGC(cx);

    branch->gc_attempts++;

    return(JS_TRUE);
}
예제 #24
0
파일: vm.c 프로젝트: wesgarland/gpsee
/** Garbage Collector method for Javascript. 
 *  One optional argument, boolean, whether or not to force the garbage collection.
 */
static JSBool vm_gc(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
  JSBool b;

  if (argc == 0)
  {
    JS_GC(cx);
  }
  else
  {
    if (JS_ValueToBoolean(cx, argv[0], &b) == JS_FALSE)
      return JS_FALSE;

    if (b)
      JS_GC(cx);
    else
      JS_MaybeGC(cx);
  }

  return JS_TRUE;
}
예제 #25
0
  static
  JSBool
  playMusic(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *)
  {
    // sound disabled?
    if (!Audio::audio) return JS_TRUE;
    if((argc<1)||(argc>3)) EJS_THROW_ERROR(cx,obj,"Between 1 and 3 arguments required");

    char* ctype;
    size_t len;
    STRING_TO_CHARVEC(argv[0],ctype,len);

    jsdouble volume=1;
    JSBool repeat=JS_FALSE;
    if (argc>=2)
      if (!JS_ValueToNumber(cx,argv[1],&volume)) return JS_FALSE;
    if (argc>=3)
      if (!JS_ValueToBoolean(cx, argv[2],&repeat)) return JS_FALSE;
    Audio::audio->playMusic(ctype,len,volume,repeat==JS_TRUE);
    return JS_TRUE;
  }
예제 #26
0
파일: controller.cpp 프로젝트: dewn49/FreeJ
/* JSCall function by name, cvalues will be converted
 *
 * deactivates controller if any script errors!
 *
 * format values:
 * case 'b': BOOLEAN_TO_JSVAL((JSBool) va_arg(ap, int));
 * case 'c': INT_TO_JSVAL((uint16) va_arg(ap, unsigned int));
 * case 'i':
 * case 'j': js_NewNumberValue(cx, (jsdouble) va_arg(ap, int32), sp)
 * case 'u': js_NewNumberValue(cx, (jsdouble) va_arg(ap, uint32), sp)
 * case 'd':
 * case 'I': js_NewDoubleValue(cx, va_arg(ap, jsdouble), sp)
 * case 's': JS_NewStringCopyZ(cx, va_arg(ap, char *))
 * case 'W': JS_NewUCStringCopyZ(cx, va_arg(ap, jschar *))
 * case 'S': va_arg(ap, JSString *)
 * case 'o': OBJECT_TO_JSVAL(va_arg(ap, JSObject *)
 * case 'f':
 * fun = va_arg(ap, JSFunction *);
 *       fun ? OBJECT_TO_JSVAL(fun->object) : JSVAL_NULL;
 * case 'v': va_arg(ap, jsval);
 */
bool ControllerListener::call(const char *funcname, int argc, const char *format, ...) {
    va_list ap;
    jsval fval = JSVAL_VOID;
    jsval ret = JSVAL_VOID;
    
    func("%s try calling method %s.%s(argc:%i)", __func__, name, funcname, argc);
    JS_SetContextThread(jsContext);
    JS_BeginRequest(jsContext);
    int res = JS_GetProperty(jsContext, jsObject, funcname, &fval);
    
    if(JSVAL_IS_VOID(fval)) {
        warning("method unresolved by JS_GetProperty");
    } else {
        jsval *argv;
        void *markp;
        
        va_start(ap, format);
        argv = JS_PushArgumentsVA(jsContext, &markp, format, ap);
        va_end(ap);
        
        res = JS_CallFunctionValue(jsContext, jsObject, fval, argc, argv, &ret);
        JS_PopArguments(jsContext, &markp);
        
        if (res) {
            if(!JSVAL_IS_VOID(ret)) {
                JSBool ok;
                JS_ValueToBoolean(jsContext, ret, &ok);
                if (ok) // JSfunc returned 'true', so event is done
                {
                    JS_EndRequest(jsContext);
                    JS_ClearContextThread(jsContext);
                    return true;
                }
            }
        }
    }
    JS_EndRequest(jsContext);
    JS_ClearContextThread(jsContext);
    return false; // no callback, redo on next controller
}
예제 #27
0
static JSBool
js_lock_input(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
	sbbs_t*		sbbs;
	JSBool		lock=TRUE;

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

	if(argc)
		JS_ValueToBoolean(cx, argv[0], &lock);

	if(lock) {
		pthread_mutex_lock(&sbbs->input_thread_mutex);
		sbbs->input_thread_mutex_locked=true;
	} else if(sbbs->input_thread_mutex_locked) {
		pthread_mutex_unlock(&sbbs->input_thread_mutex);
		sbbs->input_thread_mutex_locked=false;
	}

    return(JS_TRUE);
}
예제 #28
0
파일: Output.cpp 프로젝트: mandrake/lulzjs
JSBool
Output_content_set (JSContext *cx, JSObject *obj, jsval idval, jsval *vp)
{
    JS_BeginRequest(cx);
    JS_EnterLocalRootScope(cx);

    jsval     property;
    int       limit;
    JSBool    buffered;
    JSString* string;

    JS_GetProperty(cx, obj, "limit", &property);
    JS_ValueToInt32(cx, property, &limit);
    JS_GetProperty(cx, obj, "buffered", &property);
    JS_ValueToBoolean(cx, property, &buffered);
    string = JS_ValueToString(cx, *vp);

    if (!buffered && JS_GetStringLength(string) > limit) {
        if (!JSVAL_TO_BOOLEAN(JS_EVAL(cx, "Headers.sent"))) {
            JS_EVAL(cx, "Headers.send()");
        }

        FCGX_Stream* out       = ((LCGIData*) JS_GetContextPrivate(cx))->cgi->out;
        char*        cString   = JS_GetStringBytes(string);
        char         size[300] = {NULL};
        sprintf(size, "%x", strlen(cString));

        FCGX_FPrintF(out, "%s\r\n%s\r\n", size, cString);

        property = JS_GetEmptyStringValue(cx);
        JS_SetProperty(cx, obj, "content", &property);
    }

    JS_LeaveLocalRootScope(cx);
    JS_EndRequest(cx);

    return JS_TRUE;
}
예제 #29
0
파일: mainloop.c 프로젝트: sjokkis/gjs
static gboolean
closure_source_func(void *data)
{
    jsval retval;
    GClosure *closure;
    JSBool bool_val;
    JSContext *context;

    closure = data;

    context = gjs_closure_get_context(closure);
    if (context == NULL) {
        /* closure is invalid now */
        return FALSE;
    }
    JS_BeginRequest(context);

    retval = JSVAL_VOID;
    JS_AddRoot(context, &retval);

    gjs_closure_invoke(closure,
                          0, NULL,
                          &retval);

    /* ValueToBoolean pretty much always succeeds, just as
     * JavaScript always makes some sense of any value in
     * an "if (value) {}" context.
     */
    if (!JS_ValueToBoolean(context,
                           retval, &bool_val))
        bool_val = FALSE;

    JS_RemoveRoot(context, &retval);

    JS_EndRequest(context);
    return bool_val;
}
예제 #30
0
static JSBool
js_conio_setfont(JSContext *cx, uintN argc, jsval *arglist)
{
	jsval *argv=JS_ARGV(cx, arglist);
	int32	font;
	int force=JS_FALSE;
	int32 fnum=0;
	jsrefcount	rc;
	uintN arg=0;

	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if(argc > 2)
		return(JS_FALSE);

	if(argc > 0 && JSVAL_IS_NUMBER(argv[arg]) && JS_ValueToInt32(cx,argv[arg],&font)) {
		for(arg=1; arg<argc; arg++) {
			if(JSVAL_IS_NUMBER(argv[arg])) {
				if(!JS_ValueToInt32(cx,argv[arg],&fnum))
					return(JS_FALSE);
			}
			else if(JSVAL_IS_BOOLEAN(argv[arg])) {
				if(!JS_ValueToBoolean(cx, argv[1], &force))
					return(JS_FALSE);
			}
			else
				return(JS_FALSE);
		}
		rc=JS_SUSPENDREQUEST(cx);
		JS_SET_RVAL(cx, arglist,INT_TO_JSVAL(setfont(font, force,fnum)));
		JS_RESUMEREQUEST(cx, rc);
		return(JS_TRUE);
	}

	return(JS_FALSE);
}