本文整理汇总了C++中JS_SET_RVAL函数的典型用法代码示例。如果您正苦于以下问题:C++ JS_SET_RVAL函数的具体用法?C++ JS_SET_RVAL怎么用?C++ JS_SET_RVAL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JS_SET_RVAL函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: executeFile
static JSBool executeFile(JSContext *cx, unsigned argc, jsval *vp) {
JSString* str;
JSObject* obj;
if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "So", &str, &obj)) {
return JS_FALSE;
}
char *filename = JS_EncodeString(cx, str);
JSScript* script = JS_CompileUTF8File(cx, JS_THIS_OBJECT(cx, vp), filename);
JS_free(cx, filename);
if (!script) {
return JS_FALSE;
}
jsval result;
if (!JS_ExecuteScript(cx, obj, script, &result)) {
return JS_FALSE;
}
JS_SET_RVAL(cx, vp, result);
return JS_TRUE;
}
开发者ID:bnoordhuis,项目名称:luvmonkey,代码行数:23,代码来源:main.c
示例2: 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
示例3: JS_THIS_OBJECT
JSBool
Library::Close(JSContext* cx, unsigned argc, jsval* vp)
{
JSObject* obj = JS_THIS_OBJECT(cx, vp);
if (!obj)
return JS_FALSE;
if (!IsLibrary(obj)) {
JS_ReportError(cx, "not a library");
return JS_FALSE;
}
if (argc != 0) {
JS_ReportError(cx, "close doesn't take any arguments");
return JS_FALSE;
}
// delete our internal objects
UnloadLibrary(obj);
JS_SetReservedSlot(obj, SLOT_LIBRARY, PRIVATE_TO_JSVAL(NULL));
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
开发者ID:BrunoReX,项目名称:palemoon,代码行数:23,代码来源:Library.cpp
示例4: 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
示例5: 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
示例6: getType_func
static JSBool
getType_func(JSContext *context,
uintN argc,
jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(context, vp);
cairo_surface_t *surface;
cairo_surface_type_t type;
if (argc > 1) {
gjs_throw(context, "Surface.getType() takes no arguments");
return JS_FALSE;
}
surface = gjs_cairo_surface_get_surface(context, obj);
type = cairo_surface_get_type(surface);
if (!gjs_cairo_check_status(context, cairo_surface_status(surface),
"surface"))
return JS_FALSE;
JS_SET_RVAL(context, vp, INT_TO_JSVAL(type));
return JS_TRUE;
}
开发者ID:BabeNovelty,项目名称:glib-win32,代码行数:23,代码来源:cairo-surface-vs10.c
示例7: rpmhdr_fi
static JSBool
rpmhdr_fi(JSContext *cx, uintN argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx , vp);
JSObject *obj = JS_NewObjectForConstructor(cx , vp);
if(!obj) {
JS_ReportError(cx , "Failed to create 'this' object");
return JS_FALSE;
}
void * ptr = JS_GetInstancePrivate(cx, obj, &rpmhdrClass, NULL);
Header h = ptr;
rpmTag tagN = RPMTAG_BASENAMES;
JSBool ok = JS_FALSE;
_METHOD_DEBUG_ENTRY(_debug);
if (!(ok = JS_ConvertArguments(cx, argc, argv, "/u", &tagN)))
goto exit;
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(rpmjs_NewFiObject(cx, h, tagN)));
ok = JS_TRUE;
exit:
return ok;
}
开发者ID:avokhmin,项目名称:RPM5,代码行数:23,代码来源:rpmhdr-js.c
示例8: js_conio_getpass
static JSBool
js_conio_getpass(JSContext *cx, uintN argc, jsval *arglist)
{
jsval *argv=JS_ARGV(cx, arglist);
char * str;
char * pwd;
jsrefcount rc;
if(argc==1) {
JSVALUE_TO_MSTRING(cx, argv[0], str, NULL);
HANDLE_PENDING(cx);
if(str != NULL) {
rc=JS_SUSPENDREQUEST(cx);
pwd=getpass(str);
free(str);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist,STRING_TO_JSVAL(JS_NewStringCopyZ(cx,pwd)));
return(JS_TRUE);
}
}
return(JS_FALSE);
}
开发者ID:kindy,项目名称:synchronet-bbs-1,代码行数:23,代码来源:js_conio.c
示例9: gjs_format_int_alternative_output
static JSBool
gjs_format_int_alternative_output(JSContext *context,
uintN argc,
jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
char *str;
jsval rval;
int intval;
JSBool ret;
if (!gjs_parse_args(context, "format_int_alternative_output", "i", argc, argv,
"intval", &intval))
return JS_FALSE;
str = g_strdup_printf("%Id", intval);
ret = gjs_string_from_utf8(context, str, -1, &rval);
if (ret)
JS_SET_RVAL(context, vp, rval);
g_free (str);
return ret;
}
开发者ID:goizueta,项目名称:gjs,代码行数:23,代码来源:format.c
示例10: Construct
JSBool Construct(JSContext* cx, uintN argc, jsval* vp)
{
UNUSED2(argc);
JSObject *newObj = JS_NewObject(cx, &Class, NULL, NULL);
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(newObj));
int flags=JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT;
#define cfg_ns(_propname, _enum) STMT (\
JSObject *nsobj=g_ScriptingHost.CreateCustomObject("ConfigNamespace"); \
ENSURE(nsobj); \
ConfigNamespace_JS::SetNamespace(cx, nsobj, _enum); \
ENSURE(JS_DefineProperty(cx, newObj, _propname, OBJECT_TO_JSVAL(nsobj), NULL, NULL, flags)); )
cfg_ns("default", CFG_DEFAULT);
cfg_ns("system", CFG_SYSTEM);
cfg_ns("user", CFG_USER);
cfg_ns("mod", CFG_MOD);
#undef cfg_ns
return JS_TRUE;
}
开发者ID:Gallaecio,项目名称:0ad,代码行数:23,代码来源:ConfigDB.cpp
示例11: dummy_constructor
static JSBool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) {
TypeTest<T> t;
T* cobj = new T();
#if not $script_control_cpp
cocos2d::CCObject *_ccobj = dynamic_cast<cocos2d::CCObject *>(cobj);
if (_ccobj) {
_ccobj->autorelease();
}
#end if
js_type_class_t *p;
uint32_t typeId = t.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, p);
assert(p);
JSObject *_tmp = JS_NewObject(cx, p->jsclass, p->proto, p->parentProto);
js_proxy_t *pp;
JS_NEW_PROXY(pp, cobj, _tmp);
#if not $script_control_cpp
JS_AddObjectRoot(cx, &pp->obj);
#end if
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(_tmp));
return JS_TRUE;
}
开发者ID:AlexYanJianhua,项目名称:bindings-generator,代码行数:23,代码来源:layout_head.c
示例12: dummy_constructor
static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) {
JS::RootedValue initializing(cx);
bool isNewValid = true;
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);
T* cobj = new T();
js_proxy_t *pp = jsb_new_proxy(cobj, _tmp);
JS_AddObjectRoot(cx, &pp->obj);
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(_tmp));
return true;
}
return false;
}
开发者ID:jianqiang-411,项目名称:sdkbox-facebook-sample,代码行数:23,代码来源:PluginFacebookJS.cpp
示例13: js_PluginAdColonyJS_PluginAdColony_notifyIAPComplete
JSBool js_PluginAdColonyJS_PluginAdColony_notifyIAPComplete(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSBool ok = JS_TRUE;
if (argc == 5) {
std::string arg0;
std::string arg1;
int arg2;
double arg3;
std::string arg4;
ok &= jsval_to_std_string(cx, argv[0], &arg0);
ok &= jsval_to_std_string(cx, argv[1], &arg1);
ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2);
ok &= sdkbox::js_to_number(cx, argv[3], &arg3);
ok &= jsval_to_std_string(cx, argv[4], &arg4);
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
sdkbox::PluginAdColony::notifyIAPComplete(arg0, arg1, arg2, arg3, arg4);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments");
return JS_FALSE;
}
开发者ID:yinjimmy,项目名称:sdkbox-samples,代码行数:23,代码来源:PluginAdColonyJS.cpp
示例14: setExtend_func
static JSBool
setExtend_func(JSContext *context,
unsigned argc,
jsval *vp)
{
jsval *argv = JS_ARGV(context, vp);
JSObject *obj = JS_THIS_OBJECT(context, vp);
cairo_extend_t extend;
cairo_pattern_t *pattern;
if (!gjs_parse_args(context, "setExtend", "i", argc, argv,
"extend", &extend))
return JS_FALSE;
pattern = gjs_cairo_pattern_get_pattern(context, obj);
cairo_pattern_set_extend(pattern, extend);
if (!gjs_cairo_check_status(context, cairo_pattern_status(pattern), "pattern"))
return JS_FALSE;
JS_SET_RVAL(context, vp, JSVAL_VOID);
return JS_TRUE;
}
开发者ID:3dfxmadscientist,项目名称:cjs,代码行数:23,代码来源:cairo-surface-pattern.cpp
示例15: js_EventListenerTouchOneByOne_create
bool js_EventListenerTouchOneByOne_create(JSContext *cx, uint32_t argc, jsval *vp)
{
if (argc == 0) {
auto ret = EventListenerTouchOneByOne::create();
ret->onTouchBegan = [ret](Touch* touch, Event* event) -> bool {
jsval jsret = JSVAL_NULL;
bool ok = ScriptingCore::getInstance()->handleTouchEvent(ret, EventTouch::EventCode::BEGAN, touch, event, &jsret);
// Not found the method, just return false.
if (!ok)
return false;
CCASSERT(JSVAL_IS_BOOLEAN(jsret), "the return value of onTouchBegan isn't boolean");
return JSVAL_TO_BOOLEAN(jsret);
};
ret->onTouchMoved = [ret](Touch* touch, Event* event) {
ScriptingCore::getInstance()->handleTouchEvent(ret, EventTouch::EventCode::MOVED, touch, event);
};
ret->onTouchEnded = [ret](Touch* touch, Event* event) {
ScriptingCore::getInstance()->handleTouchEvent(ret, EventTouch::EventCode::ENDED, touch, event);
};
ret->onTouchCancelled = [ret](Touch* touch, Event* event) {
ScriptingCore::getInstance()->handleTouchEvent(ret, EventTouch::EventCode::CANCELLED, touch, event);
};
jsval jsret = getJSObject(cx, ret);
JS_SET_RVAL(cx, vp, jsret);
return true;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
return false;
}
开发者ID:071300726,项目名称:cocos2d-js,代码行数:37,代码来源:jsb_event_dispatcher_manual.cpp
示例16: js_cocos2dx_CCSpawn_create
JSBool js_cocos2dx_CCSpawn_create(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
if (argc > 0) {
cocos2d::CCArray* array = cocos2d::CCArray::create();
int i = 0;
while (i < argc) {
js_proxy_t *proxy;
JSObject *tmpObj = JSVAL_TO_OBJECT(argv[i]);
JS_GET_NATIVE_PROXY(proxy, tmpObj);
cocos2d::CCObject *item = (cocos2d::CCObject*)(proxy ? proxy->ptr : NULL);
TEST_NATIVE_OBJECT(cx, item)
array->addObject(item);
i++;
}
cocos2d::CCFiniteTimeAction* ret = cocos2d::CCSpawn::create(array);
jsval jsret;
do {
if (ret) {
js_proxy_t *p;
JS_GET_PROXY(p, ret);
if (p) {
jsret = OBJECT_TO_JSVAL(p->obj);
} else {
// create a new js obj of that class
js_proxy_t *proxy = js_get_or_create_proxy<cocos2d::CCFiniteTimeAction>(cx, ret);
jsret = OBJECT_TO_JSVAL(proxy->obj);
}
} else {
jsret = JSVAL_NULL;
}
} while (0);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
return JS_FALSE;
}
开发者ID:acc85,项目名称:cocos2d-x,代码行数:37,代码来源:cocos2d_specifics.cpp
示例17: 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
示例18: js_skeleton_constructor
JSBool js_skeleton_constructor(JSContext *cx, uint32_t argc, jsval *vp)
{
cocos2d::CCLog("js skeletonanimation constructor ..");
if (argc == 2) {
jsval *argvp = JS_ARGV(cx,vp);
JSBool ok = JS_TRUE;
const char* arg1; const char* arg2;
ok &= jsval_to_charptr(cx, *argvp++, &arg1);
ok &= jsval_to_charptr(cx, *argvp++, &arg2);
JSB_PRECONDITION(ok, "Error processing arguments");
// 调用 C++ 构造函数
cocos2d::extension::CCSkeletonAnimation* cobj =
new cocos2d::extension::CCSkeletonAnimation(arg1, arg2);
cocos2d::CCObject* _ccobj = dynamic_cast<cocos2d::CCObject*>(cobj);
// 默认使用原有的内存管理方式
if (_ccobj){
_ccobj->autorelease();
}
TypeTest<cocos2d::extension::CCSkeletonAnimation> t;
js_type_class_t *typeClass;
uint32_t typeId = t.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, typeClass);
assert(typeClass);
JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto);
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
// 构造 js 端对象,将 cobj 实际对象存入
js_proxy_t* p = jsb_new_proxy(cobj, obj);
JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::CCSkeletonAnimation");
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
return JS_FALSE;
}
开发者ID:zqlgithub,项目名称:spineBinding,代码行数:37,代码来源:skeleton_js_binding.cpp
示例19: js_user_constructor
static JSBool
js_user_constructor(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj;
jsval *argv=JS_ARGV(cx, arglist);
int i;
int32 val=0;
user_t user;
private_t* p;
scfg_t* scfg;
scfg=JS_GetRuntimePrivate(JS_GetRuntime(cx));
obj=JS_NewObject(cx, &js_user_class, NULL, NULL);
JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(obj));
if(argc && (!JS_ValueToInt32(cx,argv[0],&val)))
return JS_FALSE;
user.number=(ushort)val;
if(user.number!=0 && (i=getuserdat(scfg,&user))!=0) {
JS_ReportError(cx,"Error %d reading user number %d",i,val);
return(JS_FALSE);
}
if((p=(private_t*)malloc(sizeof(private_t)))==NULL)
return(JS_FALSE);
memset(p,0,sizeof(private_t));
p->storage = user;
p->user = &p->storage;
p->cached = (user.number==0 ? FALSE : TRUE);
JS_SetPrivate(cx, obj, p);
return(JS_TRUE);
}
开发者ID:mattzorzin,项目名称:synchronet,代码行数:37,代码来源:js_user.c
示例20: error_constructor_value_of
static JSBool
error_constructor_value_of(JSContext *context, uintN argc, jsval *vp)
{
jsval v_self, v_prototype;
Error *priv;
jsval v_out;
v_self = JS_THIS(context, vp);
if (!JSVAL_IS_OBJECT(v_self)) {
/* Lie a bit here... */
gjs_throw(context, "GLib.Error.valueOf() called on a non object");
return JS_FALSE;
}
if (!gjs_object_require_property(context,
JSVAL_TO_OBJECT(v_self),
"constructor",
"prototype",
&v_prototype))
return JS_FALSE;
if (!JSVAL_IS_OBJECT(v_prototype)) {
gjs_throw(context, "GLib.Error.valueOf() called on something that is not"
" a constructor");
return JS_FALSE;
}
priv = priv_from_js(context, JSVAL_TO_OBJECT(v_prototype));
if (priv == NULL)
return JS_FALSE;
v_out = INT_TO_JSVAL(priv->domain);
JS_SET_RVAL(context, vp, v_out);
return TRUE;
}
开发者ID:Cobinja,项目名称:cjs,代码行数:37,代码来源:gerror.c
注:本文中的JS_SET_RVAL函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论