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


C++ JS_ValueToObject函数代码示例

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


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

示例1: jsval_to_animationInfo

bool jsval_to_animationInfo(JSContext* cx, JS::HandleValue vp, cocostudio::timeline::AnimationInfo* ret)
{
    JS::RootedObject tmp(cx);
    JS::RootedValue jsName(cx);
    JS::RootedValue jsStartId(cx);
    JS::RootedValue jsEndId(cx);
    std::string name;
    double startIndex, endIndex;
    
    bool ok = vp.isObject() &&
    JS_ValueToObject(cx, vp, &tmp) &&
    JS_GetProperty(cx, tmp, "name", &jsName) &&
    JS_GetProperty(cx, tmp, "startIndex", &jsStartId) &&
    JS_GetProperty(cx, tmp, "endIndex", &jsEndId) &&
    JS::ToNumber(cx, jsStartId, &startIndex) &&
    JS::ToNumber(cx, jsEndId, &endIndex) &&
    jsval_to_std_string(cx, jsName, &name) &&
    !std::isnan(startIndex) && !std::isnan(endIndex);
    
    JSB_PRECONDITION3(ok, cx, false, "Error processing arguments");
    
    ret->name = name;
    ret->startIndex = (int)startIndex;
    ret->endIndex = (int)endIndex;
    return true;
}
开发者ID:FenneX,项目名称:FenneXEmptyProject,代码行数:26,代码来源:jsb_cocos2dx_studio_conversions.cpp

示例2: xgg_xdom_getelementsbytagname

static JSBool xgg_xdom_getelementsbytagname(JSContext *pcxa, JSObject *pobja, uintN argc, jsval *pva1, jsval *rval)
{
	JSBool				b1 = JS_TRUE;
	XJSECTX*			pjsectx = (XJSECTX*)JS_GetContextPrivate(pcxa);
	XJSE_XDOMPRIV*		pv1 = (XJSE_XDOMPRIV*)JS_GetPrivate(pcxa, pobja);
	jsval				vrootelem;

	b1 = JS_GetElement(pjsectx->pctx, pv1->ponodelist, 0, &vrootelem);
	if(b1 != JS_TRUE) {
		XJSE_TRACE("(E) JS_GetElement() failed!");
		goto	failed;
	}

	JSObject	*porootelem = 0;
	b1 = JS_ValueToObject(pcxa, vrootelem, &porootelem);
	if(b1 != JS_TRUE || porootelem == 0) {
		XJSE_TRACE("(E) JS_ValueToObject() failed!");
		goto	failed;
	}

	return	xgg_element_getelementsbytagname(
		pcxa, porootelem, argc, pva1, rval);

failed:
	return	JS_FALSE;
}
开发者ID:odistagon,项目名称:cyeonna,代码行数:26,代码来源:xgg_dom.c

示例3: getJsObjOrCreat

    jsval getJsObjOrCreat(JSContext* cx, JSObject* jsObj, const char* name, JSObject** retObj) {
        JSObject* parent = NULL;
        JSObject* tempObj = jsObj;
        jsval tempVal;

        std::stringstream ss(name);
        std::string sub;
        const char* subChar;

        while(getline(ss, sub, '.')) {
            if(sub.empty())continue;

            subChar = sub.c_str();
            parent = tempObj;
            JS_GetProperty(cx, parent, subChar, &tempVal);
            if (tempVal == JSVAL_VOID) {
                tempObj = JS_NewObject(cx, NULL, NULL, NULL);
                tempVal = OBJECT_TO_JSVAL(tempObj);
                JS_SetProperty(cx, parent, subChar, &tempVal);
            } else {
                JS_ValueToObject(cx, tempVal, &tempObj);
            }
        }

        *retObj = tempObj;
        return tempVal;
    }
开发者ID:sdkbox,项目名称:sdkbox-sample-appnext,代码行数:27,代码来源:SDKBoxJSHelper.cpp

示例4: register_pluginx_js_extensions

void register_pluginx_js_extensions(JSContext* cx, JSObject* global)
{
    // first, try to get the ns
    jsval nsval;
    JSObject *ns;
    JS_GetProperty(cx, global, "plugin", &nsval);
    if (nsval == JSVAL_VOID) {
        ns = JS_NewObject(cx, NULL, NULL, NULL);
        nsval = OBJECT_TO_JSVAL(ns);
        JS_SetProperty(cx, global, "plugin", &nsval);
    } else {
        JS_ValueToObject(cx, nsval, &ns);
    }

    JS_DefineFunction(cx, jsb_ProtocolIAP_prototype, "setResultListener", js_pluginx_ProtocolIAP_setResultListener, 1, JSPROP_READONLY | JSPROP_PERMANENT);
    JS_DefineFunction(cx, jsb_ProtocolAds_prototype, "setAdsListener", js_pluginx_ProtocolAds_setAdsListener, 1, JSPROP_READONLY | JSPROP_PERMANENT);
    JS_DefineFunction(cx, jsb_ProtocolShare_prototype, "setResultListener", js_pluginx_ProtocolShare_setResultListener, 1, JSPROP_READONLY | JSPROP_PERMANENT);
    JS_DefineFunction(cx, jsb_PluginProtocol_prototype, "callFuncWithParam", js_pluginx_PluginProtocol_callFuncWithParam, 1, JSPROP_READONLY | JSPROP_PERMANENT);
    JS_DefineFunction(cx, jsb_PluginProtocol_prototype, "callStringFuncWithParam", js_pluginx_PluginProtocol_callStringFuncWithParam, 1, JSPROP_READONLY | JSPROP_PERMANENT);
    JS_DefineFunction(cx, jsb_PluginProtocol_prototype, "callIntFuncWithParam", js_pluginx_PluginProtocol_callIntFuncWithParam, 1, JSPROP_READONLY | JSPROP_PERMANENT);
    JS_DefineFunction(cx, jsb_PluginProtocol_prototype, "callFloatFuncWithParam", js_pluginx_PluginProtocol_callFloatFuncWithParam, 1, JSPROP_READONLY | JSPROP_PERMANENT);
    JS_DefineFunction(cx, jsb_PluginProtocol_prototype, "callBoolFuncWithParam", js_pluginx_PluginProtocol_callBoolFuncWithParam, 1, JSPROP_READONLY | JSPROP_PERMANENT);

    global = ns;
    js_register_pluginx_protocols_PluginParam(cx, global);
}
开发者ID:bassarisse,项目名称:LostInCaves,代码行数:26,代码来源:jsb_pluginx_extension_registration.cpp

示例5: SetContextObj

static JSBool
SetContextObj(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
  nsJSSh* shell;
  if (!GetJSShGlobal(cx, obj, &shell)) return JS_FALSE;

  JSAutoRequest ar(cx);

  if (argc!=1) return JS_FALSE;

  JSObject *arg_obj;
  if (!JS_ValueToObject(cx, argv[0], &arg_obj)) {
    return JS_FALSE;
  }

  if (shell->mContextObj != shell->mGlobal)
    JS_RemoveRoot(cx, &(shell->mContextObj));
  
  shell->mContextObj = arg_obj;
  
  if (shell->mContextObj != shell->mGlobal)
    JS_AddRoot(cx, &(shell->mContextObj));
  
  return JS_TRUE;
}
开发者ID:lofter2011,项目名称:Icefox,代码行数:25,代码来源:nsJSSh.cpp

示例6: jsval_to_opaque

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;
}
开发者ID:dumganhar,项目名称:cocos2dx-watermelon-ios,代码行数:25,代码来源:js_manual_conversions.cpp

示例7: jsval_to_long

// XXX: sizeof(long) == 8 in 64 bits on OS X... apparently on Windows it is 32 bits (???)
JSBool jsval_to_long( JSContext *cx, jsval vp, long *r )
{
#ifdef __LP64__
	// compatibility check
	assert( sizeof(long)==8);
	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(long), "jsb: Invalid Typed Array lenght");
	
	int32_t* arg_array = (int32_t*)JS_GetTypedArrayData( tmp_arg );
	long ret =  arg_array[0];
	ret = ret << 32;
	ret |= arg_array[1];
	
#else
	// compatibility check
	assert( sizeof(int)==4);
	long ret = JSVAL_TO_INT(vp);
#endif
	
	*r = ret;
	return JS_TRUE;
}
开发者ID:dumganhar,项目名称:cocos2dx-watermelon-ios,代码行数:28,代码来源:js_manual_conversions.cpp

示例8: jsval_array_to_string

bool jsval_array_to_string(JSContext *cx, jsval v, std::string* ret)
{
	JS::RootedObject jsobj(cx);
	bool ok = v.isObject() && JS_ValueToObject( cx, JS::RootedValue(cx, v), &jsobj );
	JSB_PRECONDITION2( ok, cx, false, "Error converting value to object");
	JSB_PRECONDITION2( jsobj && JS_IsArrayObject( cx, jsobj), cx, false, "Object must be an array");

	uint32_t len;
	JS_GetArrayLength(cx, jsobj, &len);

	for( uint32_t i=0; i< len;i++ ) {
		JS::RootedValue valarg(cx);
		JS_GetElement(cx, jsobj, i, &valarg);

		std::string temp;
		ok = jsval_to_std_string(cx, valarg, &temp);
		JSB_PRECONDITION2(ok, cx, false, "Error processing arguments");
		if(i != len -1)
			ret->append(temp + ",");
		else
			ret->append(temp);
	}

	return true;
}
开发者ID:TheWindShan,项目名称:HYFish,代码行数:25,代码来源:jsb_pluginx_basic_conversions.cpp

示例9: respond_to_p

/*
 * call-seq:
 *   respond_to?(symbol)
 *
 * Returns <code>true</code> if this JavaScript object responds to the
 * named method.
 */
static VALUE
respond_to_p(int argc, const VALUE* argv, VALUE self)
{
  VALUE sym, priv;

  rb_scan_args(argc, argv, "11", &sym, &priv);

  RubyLandProxy* proxy;
  Data_Get_Struct(self, RubyLandProxy, proxy);

  JSContext * context = johnson_get_current_context(proxy->runtime);
  PREPARE_RUBY_JROOTS(context, 2);
  
  VALUE stringval = rb_funcall(sym, rb_intern("to_s"), 0);
  char* name = StringValuePtr(stringval);
  
  // assignment is always okay
  if (name[strlen(name) - 1] == '=')
    JRETURN_RUBY(Qtrue);
  
  jsval proxy_value;
  JCHECK(get_jsval_for_proxy(proxy, &proxy_value));
  JROOT(proxy_value);

  JSObject *obj;
  JSBool found;
  
  JCHECK(JS_ValueToObject(context, proxy_value, &obj));
  JROOT(obj);

  JCHECK(JS_HasProperty(context, obj, name, &found));

  JRETURN_RUBY(found ? Qtrue : CALL_RUBY_WRAPPER(rb_call_super, argc, argv));
}
开发者ID:aasmith,项目名称:johnson,代码行数:41,代码来源:ruby_land_proxy.c

示例10: fromjs_isTimerValid

JSBool JSJSGlobalObject::fromjs_isTimerValid(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
  // get instance
  JSGlobalObject *object = static_cast<JSGlobalObject *>(reinterpret_cast<JSScriptable *>(JS_GetPrivate(cx, obj)));
  if (!object) {
    JSScriptable::js_throwNullCallException(JSJSGlobalObject::classDescriptor.name, JSJSGlobalObject::functionTable[4].name);
    return JS_FALSE;
  }
  // record context
  object->js_setCurrentContext(cx);
  // JSTimer *timer
  JSObject *p0;
  if (!JS_ValueToObject(cx, argv[0], &p0))
    return JS_FALSE;
  argv[0] = OBJECT_TO_JSVAL(p0);
  JSTimer *p0o = NULL;
  if (p0) {
    JSScriptable *pobj = reinterpret_cast<JSScriptable*>(JS_GetPrivate(cx, p0));
    if (!pobj) {
      object->js_throwNullParamException(0, JSJSGlobalObject::functionTable[4].name, JSJSGlobalObject::classDescriptor.name);
      return JS_FALSE;
    }
    p0o = static_cast<JSTimer *>(pobj->js_getInterface(JS_JSTimer_GUID));
    if (!p0o) {
      object->js_throwParamTypeException(0, JSJSTimer::classDescriptor.name, JSJSGlobalObject::functionTable[4].name, JSJSGlobalObject::classDescriptor.name);
      return JS_FALSE;
    }
  }
  // call method
  ASSERT(object != NULL);
  bool rv = object->isTimerValid(p0o);
  // handle return value
  *rval = BOOLEAN_TO_JSVAL(rv);
  // success
  return JS_TRUE;
}
开发者ID:bizzehdee,项目名称:wasabi,代码行数:35,代码来源:JSJSGlobalObject.cpp

示例11: AfxGlImage_writeBitmap

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

	JSObject * jsObj;
	if(!JS_ValueToObject(cx, args.thisv(), &jsObj))
		return JS_FALSE;

	AfxGlImage *afxGlImage = (AfxGlImage *)JS_GetPrivate(jsObj);

    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 wFileName;

	bool bOk = AnsiStringToWideString(c_str, wFileName);

	JS_free(cx, c_str);

	if(!(bOk
		&& AfxImageUtils::WriteBitmap(afxGlImage, wFileName.c_str())))
		return JS_FALSE;

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

示例12: AfxGlImage_sliceFloatDepthBuffer

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

	JSObject * jsObj;
	if(!JS_ValueToObject(cx, args.thisv(), &jsObj))
		return JS_FALSE;

	AfxGlImage *afxGlImage = (AfxGlImage *)JS_GetPrivate(jsObj);

	GLdouble sliceLo;
	GLdouble sliceHi;
	
	if(!(
		JS::ToNumber(cx, args[0], &sliceLo)
		&& JS::ToNumber(cx, args[1], &sliceHi)
	))
		return JS_FALSE;

	if(!AfxImageUtils::SliceFloatDepthBuffer(afxGlImage, sliceLo, sliceHi))
		return JS_FALSE;

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

示例13: Window_printChar

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;
}
开发者ID:meh,项目名称:lulzjs-ncurses,代码行数:58,代码来源:Window.cpp

示例14: jsval_to_CGPoint

JSBool jsval_to_CGPoint( JSContext *cx, jsval vp, CGPoint *ret )
{
#ifdef JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES
    
	JSObject *jsobj;
	if( ! JS_ValueToObject( cx, vp, &jsobj ) )
		return JS_FALSE;
	
	JSB_PRECONDITION( jsobj, "Not a valid JS object");
    
	jsval valx, valy;
	JSBool ok = JS_TRUE;
	ok &= JS_GetProperty(cx, jsobj, "x", &valx);
	ok &= JS_GetProperty(cx, jsobj, "y", &valy);
    
	if( ! ok )
		return JS_FALSE;
	
	double x, y;
	ok &= JS_ValueToNumber(cx, valx, &x);
	ok &= JS_ValueToNumber(cx, valy, &y);
	
	if( ! ok )
		return JS_FALSE;
	
	ret->x = x;
	ret->y = y;
    
	return JS_TRUE;
    
#else // #! JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES
    
	JSObject *tmp_arg;
	if( ! JS_ValueToObject( cx, vp, &tmp_arg ) )
		return JS_FALSE;
	
	JSB_PRECONDITION( tmp_arg && JS_IsTypedArrayObject( tmp_arg, cx ), "Not a TypedArray object");
	
	JSB_PRECONDITION( JS_GetTypedArrayByteLength( tmp_arg, cx ) == sizeof(CGPoint), "Invalid length");
	
	*ret = *(CGPoint*)JS_GetArrayBufferViewData( tmp_arg, cx );
	
	return JS_TRUE;
#endif // #! JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES
}
开发者ID:dumganhar,项目名称:cocos2dx-watermelon-ios,代码行数:45,代码来源:js_manual_conversions.cpp

示例15: File_constructor

//////////////////////////////////////////////////////////////////////////
// constructor
JSBool File_constructor(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
	File_data * data = (File_data *)malloc(sizeof(File_data));
	memset(data, 0, sizeof(File_data));

	JSObject * propertyMap = 0;
	if(argc==1)	// File(path)   or  File(propertyMap)
	{
		if(!JSVAL_IS_STRING(argv[0]) && !JSVAL_IS_OBJECT(argv[0]))
		{
			JS_ReportError(cx, "File constructor argument #1 has an unexpected type. Expected string or object, got: %s", JS_GetTypeName(cx, JS_TypeOfValue(cx, argv[0])));
			return JS_FALSE;
		}

		if(JSVAL_IS_OBJECT(argv[0]))
			JS_ValueToObject(cx, argv[0], &propertyMap);
		else if(JSVAL_IS_STRING(argv[0]))
			JS_SetProperty(cx, obj, "path", &argv[0]);
	}
	else if(argc==2)	// File(path, propertyMap)
	{
		if(!JSVAL_IS_STRING(argv[0]))
		{
			JS_ReportError(cx, "File constructor argument #1 has an unexpected type. Expected string, got: %s", JS_GetTypeName(cx, JS_TypeOfValue(cx, argv[0])));
			return JS_FALSE;
		}
		else if(!JSVAL_IS_OBJECT(argv[1]))
		{
			JS_ReportError(cx, "File constructor argument #2 has an unexpected type. Expected object, got: %s", JS_GetTypeName(cx, JS_TypeOfValue(cx, argv[1])));
			return JS_FALSE;
		}

		JS_SetProperty(cx, obj, "path", &argv[0]);

		JS_ValueToObject(cx, argv[1], &propertyMap);
	}

	if(propertyMap && !JS_CopyObjectProperties(cx, propertyMap, obj))
		return JS_FALSE;

	JS_SetPrivate(cx, obj, data);

	return JS_TRUE;
}
开发者ID:Alix29,项目名称:piston,代码行数:46,代码来源:File.cpp


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