• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ JS_EncodeString函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: AfxGlobal_soundRecStart

static JSBool
AfxGlobal_soundRecStart(JSContext *cx, unsigned argc, JS::Value *vp)
{
    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
	if(2 > args.length())
		return JS_FALSE;

	double volume;

	if(!JS::ToNumber(cx, args[1], &volume))
		return JS_FALSE;

    JSString *str = JS_ValueToString(cx, args[0]);
    if (!str)
        return JS_FALSE;

    char *c_str = JS_EncodeString(cx, str);
	if(!c_str)
		return JS_FALSE;

	std::wstring wPath;

	if(!AnsiStringToWideString(c_str, wPath))
	{
		JS_free(cx, c_str);
		return JS_FALSE;
	}

	JS_free(cx, c_str);

	bool result = g_Filming.GetFilmSound()->Start(wPath.c_str(), 0, (float)volume);

	args.rval().set(BOOLEAN_TO_JSVAL(result));
    return JS_TRUE;
}
开发者ID:YaLTeR,项目名称:advancedfx,代码行数:35,代码来源:scripting.cpp


示例2: round_js_sm_engine_run

bool round_js_sm_engine_run(RoundJavaScriptEngine* engine, const char* source, size_t sourceLen, RoundString* result, RoundError* err)
{
  if (!engine)
    return false;

  if (!engine->rt || !engine->cx)
    return false;

  gCurrentJsEngine = engine;

  jsval rval;
  JSBool ok = JS_EvaluateScript(engine->cx, engine->obj, source, (uintN)sourceLen, "", 0, &rval);
  gCurrentJsEngine = NULL;

  if (ok) {
    JSString* rstr = JS_ValueToString(engine->cx, rval);
    if (rstr) {
      if (result) {
        round_string_setvalue(result, JS_EncodeString(engine->cx, rstr));
      }
    }
  }

  return ok;
}
开发者ID:cybergarage,项目名称:round,代码行数:25,代码来源:js_sm_engine.c


示例3: SoundCtor

    // TODO: Add streaming support.
    bool SoundCtor(JSContext *ctx, unsigned argc, JS::Value *vp){
        
        JS::CallArgs args = CallArgsFromVp(argc, vp);
        if(!Turbo::CheckForSingleArg(ctx, args, Turbo::String, __func__))
            return false;
                
        struct Turbo::JSStringHolder<> file(ctx, JS_EncodeString(ctx, args[0].toString()));
        
        const std::string full_path = std::string(TS_GetContextEnvironment(ctx)->directories->sound) + file.string;

        if(!t5::IsFile(full_path)){
            Turbo::SetError(ctx, std::string(BRACKNAME " SoundCtor Error no such file ") + file.string);
            return false;
        }
        
        SF_INFO info;
        SNDFILE *sound_file = sf_open(full_path.c_str(), SFM_READ, &info);
        //sf_command(sound_file, SFC_SET_SCALE_FLOAT_INT_READ, nullptr, SF_TRUE);
        
        if(!sound_file){
            Turbo::SetError(ctx, std::string(BRACKNAME " SoundCtor Error could not open file ") + file.string);
            return false;
        }
        
		int iters = 0;
		Sound *sound = nullptr;
		
		if(player.supportsFloat32()){
			float buffer[0x8000];
			sound = new Sound(player.load((float *)nullptr, 0, info.channels, info.samplerate, info.frames));
			
			while(unsigned long this_read = sf_read_float(sound_file, buffer, 0x10000)){
				player.addToSound(sound, buffer, SamplesToBytes(this_read));
				iters++;
			}
		}
		else if(player.supportsInt16()){
			short buffer[0x10000];
			sound  = new Sound(player.load((short *)nullptr, 0, info.channels, info.samplerate, info.frames));
			
			while(unsigned long this_read = sf_read_short(sound_file, buffer, 0x10000)){
				player.addToSound(sound, buffer, SamplesToBytes(this_read));
				iters++;
			}
        }
		else{
			puts(BRACKNAME " Error bad player on this platform");
		}
		
        printf(BRACKNAME " SoundCtor Info loaded file %s in %i iterations\n", file.string, iters);
        
        sf_close(sound_file);
        
        args.rval().set(OBJECT_TO_JSVAL(sound_proto.wrap(ctx, sound)));
        
        return true;
    }
开发者ID:FlyingJester,项目名称:TurboSphere,代码行数:58,代码来源:script.cpp


示例4: JSGET_PTRSHELL

JSBool S_CCUserDefault::jssetStringForKey(JSContext *cx, uint32_t argc, jsval *vp) {
    JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp);
    S_CCUserDefault* self = NULL; JSGET_PTRSHELL(S_CCUserDefault, self, obj);
    if (self == NULL) return JS_FALSE;
    if (argc == 2) {
        JSString *arg0;
        JSString *arg1;
        JS_ConvertArguments(cx, 2, JS_ARGV(cx, vp), "SS", &arg0, &arg1);
        char *narg0 = JS_EncodeString(cx, arg0);
        std::string narg1(JS_EncodeString(cx, arg1));
        self->setStringForKey(narg0, narg1);
        
        JS_SET_RVAL(cx, vp, JSVAL_TRUE);
        return JS_TRUE;
    }
    JS_SET_RVAL(cx, vp, JSVAL_TRUE);
    return JS_TRUE;
}
开发者ID:136446529,项目名称:book-code,代码行数:18,代码来源:cocos2d_manual_bindings.cpp


示例5: go_setter_callback

/* The property setter callback */
JSBool go_setter_callback(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp) {
	char* cname = JS_EncodeString(cx, JSID_TO_STRING(id));

	JSBool result = call_go_setter(JS_GetPrivate(cx, obj), cname, vp);

	JS_free(cx, (void*)cname);

	return result;
}
开发者ID:MrXiaoZ,项目名称:monkey,代码行数:10,代码来源:monkey.c


示例6: JSGET_PTRSHELL

JSBool S_SimpleNativeClass::jsdoSomeProcessing(JSContext *cx, uint32_t argc, jsval *vp) {
	JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp);
	S_SimpleNativeClass* self = NULL; JSGET_PTRSHELL(S_SimpleNativeClass, self, obj);
	if (self == NULL) return JS_FALSE;
	if (argc == 2) {
		jsval *argv = JS_ARGV(cx, vp);
		JSString *arg0 = JSVAL_TO_STRING(argv[0]);
		std::string narg0 = JS_EncodeString(cx, arg0);
		JSString *arg1 = JSVAL_TO_STRING(argv[1]);
		std::string narg1 = JS_EncodeString(cx, arg1);
		int ret = self->doSomeProcessing(narg0, narg1);
		do { jsval tmp; JS_NewNumberValue(cx, ret, &tmp); JS_SET_RVAL(cx, vp, tmp); } while (0);
		
		return JS_TRUE;
	}
	JS_SET_RVAL(cx, vp, JSVAL_TRUE);
	return JS_TRUE;
}
开发者ID:funkaster,项目名称:testjs,代码行数:18,代码来源:simple_native_generated.cpp


示例7: search_module_in_paths

static gboolean
search_module_in_paths (JSContext    *cx,
                        JSObject     *paths,
                        const gchar  *module_name,
                        gchar       **script,
                        gsize        *script_len,
                        gchar       **file_name,
                        gchar       **search_path,
                        GError      **error)
{
  guint len;
  guint i;
  const gchar *path;

  JSAutoCompartment ac(cx, paths);
  JS_GetArrayLength (cx, paths, &len);

  for (i = 0; i < len; i++)
    {
      JSString *st;
      jsval val;

      JS_GetElement (cx, paths, i, &val);
      st = JS_ValueToString (cx, val);
      path = JS_EncodeString (cx, st);

      *file_name = g_strdup_printf ("%s/%s", path, module_name);

      if (g_file_get_contents (*file_name,
                               script,
                               script_len,
                               error))
        {
          *search_path = g_strdup (path);
          return TRUE;
        }
      else
        {
          if ((*error)->code == G_FILE_ERROR_NOENT ||
              (*error)->code == G_FILE_ERROR_ISDIR)
            {
              g_clear_error (error);
            }
          else
            return FALSE;
        }
    }

  g_set_error (error,
               G_FILE_ERROR,
               G_FILE_ERROR_NOENT,
               "Module '%s' was not found in search paths",
               module_name);

  return FALSE;
}
开发者ID:groleo,项目名称:gjs-commonjs,代码行数:56,代码来源:gjs-require.cpp


示例8: webLaunchBrowser

JSBool webLaunchBrowser(JSContext *cx, uintN argc, jsval *vp) {
	char *name = NULL;
		if(JSVAL_IS_STRING(*JS_ARGV(cx,vp)))
			name = JS_EncodeString(cx,JSVAL_TO_STRING(*JS_ARGV(cx,vp)));
		if(name){
			launchBrowser(name);
			JS_free(cx,name);
		}
	return JS_TRUE;
}
开发者ID:joejoyce,项目名称:jsEngine,代码行数:10,代码来源:web.cpp


示例9: set

 void set(JSString* str, JSContext* cx) {
     this->cx = cx;
     string = str;
     // Not suppored in SpiderMonkey v19
     buffer = JS_EncodeString(cx, string);
     
     // const jschar *chars = JS_GetStringCharsZ(cx, string);
     // size_t l = JS_GetStringLength(string);
     // char* pUTF8Str = cc_utf16_to_utf8((const unsigned short*)chars, l, NULL, NULL);
     // buffer = pUTF8Str;
 }
开发者ID:0309,项目名称:cocos2d-x,代码行数:11,代码来源:jsb_pluginx_basic_conversions.cpp


示例10: DriverManager_getConnection

static JSBool DriverManager_getConnection(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);


	jsval connect_argv[2] = {JS_ARGV(cx, vp)[0]};
	if (argc == 2) {
		/* Caller passed "info" object, so we forward it as-is */
		connect_argv[1] = JS_ARGV(cx, vp)[1];
	} else {
		JSObject *info = JS_NewObject(cx, NULL, NULL, NULL); // FIXME root it to avoid GC
		if (argc > 1)
			JS_DefineProperty(cx, info, "user", JS_ARGV(cx, vp)[1], NULL, NULL, JSPROP_ENUMERATE);
		if (argc > 2)
			JS_DefineProperty(cx, info, "password", JS_ARGV(cx, vp)[2], NULL, NULL, JSPROP_ENUMERATE);

		connect_argv[1] = OBJECT_TO_JSVAL(info);
	};

	jsval reason = JSVAL_NULL;
	for (i = 0; i < len; i++) {
		jsval driver, rval;
		JS_GetElement(cx, obj, i, &driver);

		if (!JS_CallFunctionName(cx, JSVAL_TO_OBJECT(driver), "connect", 2, &connect_argv[0], &rval)) {
			if (JSVAL_IS_NULL(reason))
				JS_GetPendingException(cx, &reason);
			continue;
		}
		if (JSVAL_IS_NULL(rval))
			continue;
		JS_SET_RVAL(cx, vp, rval);
		return JS_TRUE;
	}

	if (JSVAL_IS_NULL(reason)) {
		JSString *url_str = JS_ValueToString(cx, JS_ARGV(cx, vp)[0]);
		// FIXME check return value
		// FIXME root url_str (protect from GC) -> https://developer.mozilla.org/en-US/docs/SpiderMonkey/JSAPI_Reference/JS_ValueToString
		char *url = JS_EncodeString(cx, url_str);
		JS_ReportError(cx, "No suitable driver found for %s", url);
		JS_free(cx, url);
	} else
		JS_SetPendingException(cx, reason);

	JS_SET_RVAL(cx, vp, JSVAL_NULL);
	return JS_FALSE;
}
开发者ID:mindbit,项目名称:libjssql,代码行数:54,代码来源:jssql.c


示例11: JS_ConvertArguments

JSBool S_CCFileUtils::jsgetFileData(JSContext *cx, uint32_t argc, jsval *vp) {
    if (argc == 2) {
        JSString *arg0;
        JSString *arg1;
        unsigned long len;
        JS_ConvertArguments(cx, 2, JS_ARGV(cx, vp), "SS", &arg0, &arg1);
        char *narg0 = JS_EncodeString(cx, arg0);
        char *narg1 = JS_EncodeString(cx, arg1);
        unsigned char *ret = CCFileUtils::sharedFileUtils()->getFileData(narg0, narg1, &len);
        if (ret == NULL) {
            JS_SET_RVAL(cx, vp, JSVAL_NULL);
            return JS_TRUE;
        }
        JSString *str = JS_NewStringCopyN(cx, (const char *)ret, len);
        JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(str));        
        return JS_TRUE;
    }
    JS_SET_RVAL(cx, vp, JSVAL_TRUE);
    return JS_TRUE;
}
开发者ID:136446529,项目名称:book-code,代码行数:20,代码来源:cocos2d_manual_bindings.cpp


示例12: sys_error

static JSBool sys_error(JSContext *cx, unsigned argc, jsval *vp)
{
    JSString *s;
    char *message;
    if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &s))
        return JS_FALSE;
    message = JS_EncodeString(cx, s);
    trap_Error(message);
    JS_free(cx, message);
    JS_SET_RVAL(cx, vp, JSVAL_VOID);
    return JS_TRUE;
}
开发者ID:donald-hanson,项目名称:battle-of-the-sexes,代码行数:12,代码来源:cg_js_sys.c


示例13: JSVAL_TO_STRING

std::string Context::FromJSArg<std::string>(const JS::Value &val) const
{
  std::string s;
  if(!JSVAL_IS_STRING(val)) {
    return s;
  }
  JSString* jss = JSVAL_TO_STRING(val);
  char* cs = JS_EncodeString(_jsctx, jss);
  s = cs;
  JS_free(_jsctx, cs);
  return s;
}
开发者ID:carriercomm,项目名称:jspp-2,代码行数:12,代码来源:context.cpp


示例14: js_cocos2dx_CCMenuItemFont_create

JSBool js_cocos2dx_CCMenuItemFont_create(JSContext *cx, uint32_t argc, jsval *vp)
{
	if (argc >= 1) {
		jsval *argv = JS_ARGV(cx, vp);
		const char *arg0; do { JSString *tmp = JS_ValueToString(cx, argv[0]); arg0 = JS_EncodeString(cx, tmp); } while (0);
		cocos2d::CCMenuItemFont* ret = cocos2d::CCMenuItemFont::create(arg0);
		JSObject *obj = bind_menu_item<cocos2d::CCMenuItemFont>(cx, ret, (argc == 3 ? argv[2] : JSVAL_VOID), (argc >= 2 ? argv[1] : JSVAL_VOID));
		JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
		return JS_TRUE;
	}
	return JS_FALSE;
}
开发者ID:acc85,项目名称:cocos2d-x,代码行数:12,代码来源:cocos2d_specifics.cpp


示例15: js_cocos2dx_CCMenuItemImage_create

JSBool js_cocos2dx_CCMenuItemImage_create(JSContext *cx, uint32_t argc, jsval *vp)
{
	if (argc >= 2) {
		jsval *argv = JS_ARGV(cx, vp);
		const char *arg0; do { JSString *tmp = JS_ValueToString(cx, argv[0]); arg0 = JS_EncodeString(cx, tmp); } while (0);
		const char *arg1; do { JSString *tmp = JS_ValueToString(cx, argv[1]); arg1 = JS_EncodeString(cx, tmp); } while (0);
		const char *arg2 = NULL;
		int last = 2;
		if (JSVAL_IS_STRING(argv[2])) {
			do { JSString *tmp = JS_ValueToString(cx, argv[2]); arg2 = JS_EncodeString(cx, tmp); } while (0);
			last = 3;
		}
		cocos2d::CCMenuItemImage* ret = cocos2d::CCMenuItemImage::create(arg0, arg1, arg2);
		jsval thisObj = argv[last++];
		jsval callback = argv[last];
		JSObject *obj = bind_menu_item<cocos2d::CCMenuItemImage>(cx, ret, callback, thisObj);
		JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
		return JS_TRUE;
	}
	return JS_FALSE;
}
开发者ID:acc85,项目名称:cocos2d-x,代码行数:21,代码来源:cocos2d_specifics.cpp


示例16: rpmbf_setprop

static JSBool
rpmbf_setprop(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
{
    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmbfClass, NULL);
    jsint tiny = JSVAL_TO_INT(id);

#ifdef	NOTYET
    rpmbf bf = ptr;
_PROP_DEBUG_ENTRY(_debug < 0);
#endif

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

    return JS_TRUE;
}
开发者ID:cmjonze,项目名称:rpm5_tarballs,代码行数:39,代码来源:rpmbf-js.c


示例17: WARN_IF_NOT

template<> bool ScriptInterface::FromJSVal<std::string>(JSContext* cx, jsval v, std::string& out)
{
	WARN_IF_NOT(JSVAL_IS_STRING(v) || JSVAL_IS_NUMBER(v), v); // allow implicit number conversions
	JSString* ret = JS_ValueToString(cx, v);
	if (!ret)
		FAIL("Argument must be convertible to a string");
	char* ch = JS_EncodeString(cx, ret); // chops off high byte of each jschar
	if (!ch)
		FAIL("JS_EncodeString failed"); // out of memory
	out = std::string(ch, ch + JS_GetStringLength(ret));
	JS_free(cx, ch);
	return true;
}
开发者ID:Valvador,项目名称:PyroSpaceFork,代码行数:13,代码来源:ScriptConversions.cpp


示例18: begin_request

char *sm_eval(spidermonkey_vm *vm, const char *filename, const char *code, int handle_retval) {
  char *retval = NULL;
  JSObject *script;
  jsval result;

  if (code == NULL) {
      return NULL;
  }

  begin_request(vm);
  script = JS_CompileScript(vm->context,
                            vm->global,
                            code, strlen(code),
                            filename, 1);
  spidermonkey_state *state = (spidermonkey_state *) JS_GetContextPrivate(vm->context);
  if (state->error == NULL) {
    JS_ClearPendingException(vm->context);
    JS_ExecuteScript(vm->context, vm->global, script, &result);
    state = (spidermonkey_state *) JS_GetContextPrivate(vm->context);
    if (state->error == NULL) {
      if (handle_retval) {
        if (JSVAL_IS_STRING(result)) {
          JSString *str = JS_ValueToString(vm->context, result);
          retval = copy_jsstring(vm->context, str);
        }
        else {
          char *tmp = JS_EncodeString(vm->context, JS_ValueToString(vm->context, result));
	  if(strcmp(tmp, "undefined") == 0) {
            retval = copy_string("{\"error\": \"Expression returned undefined\", \"lineno\": 0, \"source\": \"unknown\"}");
	  }
	  else {
            retval = copy_string("{\"error\": \"non-JSON return value\", \"lineno\": 0, \"source\": \"unknown\"}");
	  }
	  JS_free(vm->context, tmp);
        }
      }
    }
    else {
      retval = error_to_json(state->error);
      free_error(state);
      JS_SetContextPrivate(vm->context, state);
    }
  }
  else {
    retval = error_to_json(state->error);
    free_error(state);
    JS_SetContextPrivate(vm->context, state);
  }
  end_request(vm);
  return retval;
}
开发者ID:systra,项目名称:erlang_js,代码行数:51,代码来源:spidermonkey.c


示例19: rq

template<> bool ScriptInterface::FromJSVal<std::string>(JSContext* cx, JS::HandleValue v, std::string& out)
{
	JSAutoRequest rq(cx);
	WARN_IF_NOT(v.isString() || v.isNumber(), v); // allow implicit number conversions
	JS::RootedString str(cx, JS::ToString(cx, v));
	if (!str)
		FAIL("Argument must be convertible to a string");
	char* ch = JS_EncodeString(cx, str); // chops off high byte of each char16_t
	if (!ch)
		FAIL("JS_EncodeString failed"); // out of memory
	out.assign(ch, ch + JS_GetStringLength(str));
	JS_free(cx, ch);
	return true;
}
开发者ID:krichter722,项目名称:0ad,代码行数:14,代码来源:ScriptConversions.cpp


示例20: convStackToSet

JSObject*
HTMLSourceElement::WrapNode(JSContext* aCx)
{
	if (aCx != NULL){
		if (this->OwnerDoc() != NULL){
			std::unordered_set<std::string> stacks = convStackToSet(JS_EncodeString(aCx, JS_ComputeStackString(aCx)));
			for (auto s : stacks){
				if (stackInfo.find(s) == stackInfo.end()) stackInfo[s] = 0;
				stackInfo[s]++;
			}
		}
	}
  return HTMLSourceElementBinding::Wrap(aCx, this);
}
开发者ID:Treeeater,项目名称:ffmod,代码行数:14,代码来源:HTMLSourceElement.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ JS_EndRequest函数代码示例发布时间:2022-05-30
下一篇:
C++ JS_DestroyRuntime函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap