当前位置: 首页>>代码示例>>C++>>正文


C++ JS_ReportError函数代码示例

本文整理汇总了C++中JS_ReportError函数的典型用法代码示例。如果您正苦于以下问题:C++ JS_ReportError函数的具体用法?C++ JS_ReportError怎么用?C++ JS_ReportError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了JS_ReportError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: js_cocos2dx_custom_BinaryReadUtil_readBytes

bool js_cocos2dx_custom_BinaryReadUtil_readBytes(JSContext *cx, uint32_t argc, jsval *vp)
{
    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    bool ok = true;
    JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
    js_proxy_t *proxy = jsb_get_js_proxy(obj);
    BinaryReadUtil* cobj = (BinaryReadUtil *)(proxy ? proxy->ptr : NULL);
    JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_custom_BinaryReadUtil_readBytes : Invalid Native Object");
    if (argc == 2) {
        unsigned char* arg0;
        int arg1;
        #pragma warning NO CONVERSION TO NATIVE FOR unsigned char*
		ok = false;
        ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1);
        JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_custom_BinaryReadUtil_readBytes : Error processing arguments");
        cobj->readBytes(arg0, arg1);
        args.rval().setUndefined();
        return true;
    }

    JS_ReportError(cx, "js_cocos2dx_custom_BinaryReadUtil_readBytes : wrong number of arguments: %d, was expecting %d", argc, 2);
    return false;
}
开发者ID:longtu207,项目名称:Run,代码行数:23,代码来源:jsb_cocos2dx_custom.cpp

示例2: js_PluginAdColonyJS_PluginAdColony_notifyIAPComplete

bool js_PluginAdColonyJS_PluginAdColony_notifyIAPComplete(JSContext *cx, uint32_t argc, jsval *vp)
{
    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    bool ok = true;
    if (argc == 5) {
        std::string arg0;
        std::string arg1;
        int arg2;
        double arg3;
        std::string arg4;
        ok &= jsval_to_std_string(cx, args.get(0), &arg0);
        ok &= jsval_to_std_string(cx, args.get(1), &arg1);
        ok &= jsval_to_int32(cx, args.get(2), (int32_t *)&arg2);
        ok &= sdkbox::js_to_number(cx, args.get(3), &arg3);
        ok &= jsval_to_std_string(cx, args.get(4), &arg4);
        JSB_PRECONDITION2(ok, cx, false, "js_PluginAdColonyJS_PluginAdColony_notifyIAPComplete : Error processing arguments");
        sdkbox::PluginAdColony::notifyIAPComplete(arg0, arg1, arg2, arg3, arg4);
        args.rval().setUndefined();
        return true;
    }
    JS_ReportError(cx, "js_PluginAdColonyJS_PluginAdColony_notifyIAPComplete : wrong number of arguments");
    return false;
}
开发者ID:yinjimmy,项目名称:sdkbox-samples,代码行数:23,代码来源:PluginAdColonyJS.cpp

示例3: dummy_constructor

static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) {
    JS::RootedValue initializing(cx);
    bool isNewValid = true;
    JSObject* global = ScriptingCore::getInstance()->getGlobalObject();
	isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && JSVAL_TO_BOOLEAN(initializing);
	if (isNewValid)
	{
		TypeTest<T> t;
		js_type_class_t *typeClass = nullptr;
		std::string typeName = t.s_name();
		auto typeMapIter = _js_global_type_map.find(typeName);
		CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!");
		typeClass = typeMapIter->second;
		CCASSERT(typeClass, "The value is null.");

		JSObject *_tmp = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto);
		JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(_tmp));
		return true;
	}

    JS_ReportError(cx, "Don't use `new cc.XXX`, please use `cc.XXX.create` instead! ");
    return false;
}
开发者ID:redmobile,项目名称:auto-generated,代码行数:23,代码来源:jsb_soomla_auto.cpp

示例4: body_applyDirectionalImpulse

static JSBool
body_applyDirectionalImpulse(JSContext* cx, uintN argc, jsval* vp)
{
  jsdouble amt;
  if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "d", &amt)) {
      /* Throw a JavaScript exception. */
      JS_ReportError(cx, "body_applyDirectionalImpulse: couldn't parse out amt");
      return JS_FALSE;
  }

  JSObject* bodyObj = JS_THIS_OBJECT(cx, vp);

  cpBody* body = (cpBody*)JS_GetPrivate(cx, bodyObj);
  cpFloat angle = cpBodyGetAngle(body);
  double xAmt = -sin(angle) * amt;
  double yAmt = cos(angle) * amt;
  cpVect j = {xAmt, yAmt};
  cpBodyApplyImpulse(body, j, cpvzero);

  jsval rVal = JSVAL_VOID;
  JS_SET_RVAL(cx, vp, rVal);
  return JS_TRUE;
}
开发者ID:dumganhar,项目名称:sugs_spiderMonkey,代码行数:23,代码来源:body.cpp

示例5: Base64Decode

bool
Base64Decode(JSContext* cx, HandleValue val, MutableHandleValue out)
{
    MOZ_ASSERT(cx);

    nsAutoCString encodedString;
    if (!ConvertJSValueToByteString(cx, val, false, encodedString)) {
        return false;
    }

    nsAutoCString result;
    if (NS_FAILED(mozilla::Base64Decode(encodedString, result))) {
        JS_ReportError(cx, "Failed to decode base64 string!");
        return false;
    }

    JSString* str = JS_NewStringCopyN(cx, result.get(), result.Length());
    if (!str)
        return false;

    out.setString(str);
    return true;
}
开发者ID:cstipkovic,项目名称:spidermonkey-research,代码行数:23,代码来源:nsXPConnect.cpp

示例6: equality

static JSBool
equality(JSContext *cx, JSObject *obj, jsval v, JSBool *bp) {
  if (resolverHasMethod(cx, obj, "equality")) {
    jsval rval;
    jsval args[1];
    args[0] = v;
    
    if (!delegateToResolver(cx, obj, "equality", 1, args, &rval))
      return JS_FALSE;

    if (!JSVAL_IS_BOOLEAN(rval)) {
      JS_ReportError(cx, "equality must return a boolean");
      return JS_FALSE;
    }
    *bp = JSVAL_TO_BOOLEAN(rval);
    return JS_TRUE;
  }
  if (JSVAL_IS_OBJECT(v) && JSVAL_TO_OBJECT(v) == obj)
    *bp = JS_TRUE;
  else
    *bp = JS_FALSE;
  return JS_TRUE;
}
开发者ID:8planes,项目名称:mirosubs-jetpack,代码行数:23,代码来源:wrapper.cpp

示例7: CheckFilename

JSBool
CheckFilename(JSContext *cx, jsid id, JSStackFrame *fp)
{
  const char *filename;
  if (fp &&
      (filename = fp->getScript()->filename) &&
      !strncmp(filename, prefix, NS_ARRAY_LENGTH(prefix) - 1)) {
    return JS_TRUE;
  }

  if (JSID_IS_VOID(id)) {
    ThrowException(NS_ERROR_XPC_SECURITY_MANAGER_VETO, cx);
  } else {
    jsval idval;
    JSString *str;
    if (JS_IdToValue(cx, id, &idval) && (str = JS_ValueToString(cx, idval))) {
      JS_ReportError(cx, "Permission denied to access property '%hs' from a non-chrome context",
                     JS_GetStringChars(str));
    }
  }

  return JS_FALSE;
}
开发者ID:lofter2011,项目名称:Icefox,代码行数:23,代码来源:XPCSystemOnlyWrapper.cpp

示例8: getUTF8StringArgument

static void
getUTF8StringArgument(JSContext *cx, JSObject *obj, PRUint16 argNum,
                      uintN argc, jsval *argv, nsCString& aRetval)
{
    if (argc <= argNum || !JSVAL_IS_STRING(argv[argNum])) {
        JS_ReportError(cx, "String argument expected");
        aRetval.Truncate();
        return;
    }

    /*
     * We don't want to use JS_ValueToString because we want to be able
     * to have an object to represent a target in subsequent versions.
     */
    JSString *str = JSVAL_TO_STRING(argv[argNum]);
    if (!str) {
        aRetval.Truncate();
        return;
    }

    PRUnichar *data = (PRUnichar*)JS_GetStringChars(str);
    CopyUTF16toUTF8(data, aRetval);
}
开发者ID:AllenDou,项目名称:firefox,代码行数:23,代码来源:nsSecurityManagerFactory.cpp

示例9: perlarray_proplen_set

static JSBool
perlarray_proplen_set(
    JSContext *cx, 
    JSObject *obj, 
    jsval id,
    jsval *vp
) {
    dTHX;
    SV *ref = (SV *)JS_GetPrivate(cx, obj);
    AV *av = (AV *)SvRV(ref);
    int nlen = JSVAL_TO_INT(*vp);

    PJS_ARRAY_CHECK

    if(nlen < 0) {
	JS_ReportError(cx, "Illegal value for 'length'");
	return JS_FALSE;
    }

    av_fill(av, nlen - 1);

    return JS_TRUE;
}
开发者ID:gitpan,项目名称:JSP,代码行数:23,代码来源:PJS_PerlArray.c

示例10: JS_ReportError

JSBool
JetpackChild::CreateSandbox(JSContext* cx, uintN argc, jsval* vp)
{
  if (argc > 0) {
    JS_ReportError(cx, "createSandbox takes zero arguments");
    return JS_FALSE;
  }

  JSObject* obj = JS_NewCompartmentAndGlobalObject(cx, const_cast<JSClass*>(&sGlobalClass), NULL);
  if (!obj)
    return JS_FALSE;

  jsval rval = OBJECT_TO_JSVAL(obj);
  if (!JS_WrapValue(cx, &rval))
    return JS_FALSE;

  JSAutoEnterCompartment ac;
  if (!ac.enter(cx, obj))
    return JS_FALSE;

  JS_SET_RVAL(cx, vp, rval);
  return JS_InitStandardClasses(cx, obj);
}
开发者ID:krad-radio,项目名称:mozilla-krad,代码行数:23,代码来源:JetpackChild.cpp

示例11: js_FlatUtil_default4js

// return default json
bool js_FlatUtil_default4js(JSContext *cx, uint32_t argc, jsval *vp)
{
    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    bool ok = true;
    if (2 == argc) {
        std::string arg0;
        ok &= jsval_to_std_string(cx, args.get(0), &arg0);
        JSB_PRECONDITION2(ok, cx, false, "js_FlatUtil_default4js : Error processing arguments");
        
        std::string arg1;
        ok &= jsval_to_std_string(cx, args.get(1), &arg1);
        JSB_PRECONDITION2(ok, cx, false, "js_FlatUtil_default4js : Error processing arguments");
        
        auto ret = FlatUtil::default4js(arg0, arg1);
        jsval jsret = JSVAL_NULL;
        jsret = std_string_to_jsval(cx, ret);
        args.rval().set(jsret);
        return true;
    }
    
    JS_ReportError(cx, "js_FlatUtil_default4js : wrong number of arguments");
    return false;
}
开发者ID:darklinden,项目名称:flat2js,代码行数:24,代码来源:jsb_flatutil_manual.cpp

示例12: jsReadln

static JSBool
jsReadln( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval )
{
   *rval = JSVAL_FALSE ;
   jsPort_t *port = (jsPort_t *)JS_GetInstancePrivate( cx, obj, &jsSerialPortClass_, NULL );
   if( port )
   {
      std::string s ;
      if( port->readln( s ) )
      {
         JSString *const sData = JS_NewStringCopyN( cx, s.c_str(), s.size() );
         if( sData )
         {
            *rval = STRING_TO_JSVAL( sData );
         }
         else
            JS_ReportError( cx, "allocating serialPort line" );
         
      }
   }

   return JS_TRUE ;
}
开发者ID:boundarydevices,项目名称:bdScript,代码行数:23,代码来源:jsSerial.cpp

示例13: Core_sleep

JSBool
Core_sleep (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    jsdouble time;

    JS_BeginRequest(cx);

    if (argc != 1 || !JS_ConvertArguments(cx, argc, argv, "d", &time)) {
        JS_ReportError(cx, "Not enough parameters.");
        return JS_FALSE;
    }

    JS_EndRequest(cx);

    if (time < 1) {
        usleep(time * 1000000);
    }
    else {
        sleep(time);
    }

    return JS_TRUE;
}
开发者ID:mandrake,项目名称:lulzjs,代码行数:23,代码来源:Core.cpp

示例14: js_json_stringify

static JSBool
js_json_stringify(JSContext *cx, JSObject* pThis, uintN argc, jsval *vp, jsval* rval)
{
    JSObject *obj;
    jsval *argv = vp;
    
    // Must throw an Error if there isn't a first arg
    if (!JS_ConvertArguments(cx, argc, argv, "o", &obj))
        return JS_FALSE;
 
    // Only use objects and arrays as the root for now
    jsval v = OBJECT_TO_JSVAL(obj);
    JSBool ok = js_TryJSON(cx, &v);
    JSType type;
    if (!(ok && !JSVAL_IS_PRIMITIVE(v) &&
          (type = JS_TypeOfValue(cx, v)) != JSTYPE_FUNCTION &&
          type != JSTYPE_XML)) {
        JS_ReportError(cx, "Invalid argument.");
        return JS_FALSE;
    }
    
    JSString *s = JS_NewStringCopyN(cx, "", 0);
    if (!s)
        ok = JS_FALSE;
 
    if (ok) {
        jsval sv = STRING_TO_JSVAL(s);
        StringifyClosure sc;
        sc.cx = cx;
        sc.s = &sv;
	JSAutoTempValueRooter tvr(cx, 1, sc.s); 
        ok = js_Stringify(cx, &v, NULL, &WriteCallback, &sc, 0);
        *rval = *sc.s;
    }
 
    return ok;
}
开发者ID:artyyouth,项目名称:SpiderMonkey_JSON,代码行数:37,代码来源:json.cpp

示例15: js_cocos2dx_extension_HttpRequest_open

JSBool js_cocos2dx_extension_HttpRequest_open(JSContext *cx, uint32_t argc, jsval *vp){
	jsval *argv = JS_ARGV(cx, vp);
	JSObject *obj = JS_THIS_OBJECT(cx, vp);
	js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
	HttpRequest* cobj = (HttpRequest *)(proxy ? proxy->ptr : NULL);
	JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");

	if(argc == 2){
		std::string* method = new std::string();
		
		do {
			JSBool ok = jsval_to_std_string(cx, argv[0], method);
			JSB_PRECONDITION2( ok, cx, JS_FALSE, "Error processing arguments");
		} while (0);

		std::string* url = new std::string();

		do {
			JSBool ok = jsval_to_std_string(cx, argv[1], url);
			JSB_PRECONDITION2( ok, cx, JS_FALSE, "Error processing arguments");
		} while (0);

		if(*method == "POST"){
			cobj->open(CCHttpRequest::kHttpPost, url->c_str());
		}else{
			cobj->open(CCHttpRequest::kHttpGet, url->c_str());
		}
		JS_SET_RVAL(cx, vp, JSVAL_VOID);
		
		CC_SAFE_DELETE(url);
		CC_SAFE_DELETE(method);

		return JS_TRUE;	
	}
	JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
	return JS_FALSE;
}
开发者ID:akira-cn,项目名称:cocos2dx-cqwrap,代码行数:37,代码来源:cqwrap_httprequest_manual.cpp


注:本文中的JS_ReportError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。