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; }
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; }
JSBool JsCallFuncBinding::Create(JSContext *context, unsigned int argc, jsval *vp) { if (argc == 1) { JSObject *jsonObj; jsval *args = JS_ARGV(context, vp); JS_ValueToObject(context, args[0], &jsonObj); jsval handlerVal; JS_GetProperty(context, jsonObj, "handler", &handlerVal); if (!JSVAL_IS_VOID(handlerVal)) { JsCallback *pCallFunc = JsCallback::actionWithJsScriptFunc( handlerVal); if (pCallFunc) { jsval dataVal; JS_GetProperty(context, jsonObj, "data", &dataVal); if (!JSVAL_IS_NULL(dataVal)) { pCallFunc->SetCallbackData(dataVal); } JSObject *newObj = JS_NewObject(context, &clz, obj, NULL); JS_SetPrivate(context, newObj, pCallFunc); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(newObj)); } } } return JS_TRUE; }
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; }
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); }
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; }
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; }
JS_CLASS_METHOD(JsMenuItemFontBinding,Create) { if(argc == 1) { jsval *args = JS_ARGV(context, vp); JSObject *jsonObj = NULL; JS_ValueToObject(context, args[0], &jsonObj); jsval titleVal; JS_GetProperty(context, jsonObj, "title", &titleVal); if(!JSVAL_IS_VOID(titleVal)) { JSString *titleStr = JS_ValueToString(context,titleVal); char *title = JS_EncodeString(context, titleStr); jsval handlerVal; JS_GetProperty(context, jsonObj, "handler", &handlerVal); JsMenuItemFont *pMenuItem; if(!JSVAL_IS_NULL(handlerVal)) { pMenuItem = JsMenuItemFont::ItemFromString( handlerVal, title); } else { pMenuItem = JsMenuItemFont::ItemFromString(title); } JS_free(context, title); if (pMenuItem) { JSObject *newObj = JS_NewObject(context, &clz, obj, NULL); JS_SetPrivate(context,newObj, pMenuItem); JS_SET_RVAL(context, vp, OBJECT_TO_JSVAL(newObj)); } } } return JS_TRUE; }
// 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; }
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; }
/* * 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)); }
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; }
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; }
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; }
JSBool JsPointBinding::Create(JSContext *context, unsigned int argc, jsval *vp) { if (argc == 1) { jsval *args = JS_ARGV(context, vp); JSObject *jsonObj; JS_ValueToObject(context, args[0], &jsonObj); jsval xVal; JSBool isContainedX = JS_GetProperty(context, jsonObj, "x", &xVal); jsval yVal; JSBool isContainedY = JS_GetProperty(context, jsonObj, "y", &yVal); if (isContainedX == JS_TRUE && isContainedY == JS_TRUE) { double x = 0; double y = 0; JS_ValueToNumber(context, xVal, &x); JS_ValueToNumber(context, yVal, &y); CCPoint *pPoint = new CCPoint(x, y); if (pPoint == NULL) { JS_ReportOutOfMemory(context); return JS_FALSE; } JSObject *newObj = JS_NewObject(context, &clz, obj, NULL); JS_SetPrivate(context, newObj, pPoint); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(newObj)); } } return JS_TRUE; }
JS_CLASS_METHOD(JsSpriteBatchNodeBinding,Create) { if(argc == 0 ) { jsval *args = JS_ARGV(context, vp); JSObject *jsonObj; JS_ValueToObject(context, args[0], &jsonObj); jsval fileNameVal; JS_GetProperty(context, jsonObj, "fileName", &fileNameVal); jsval capacityVal; JS_GetProperty(context, jsonObj, "capacity", &capacityVal); if(!JSVAL_IS_NULL(fileNameVal) && !JSVAL_IS_NULL(capacityVal)) { JSString *fileNameStr = JS_ValueToString(context, fileNameVal); char * fileName = JS_EncodeString(context,fileNameStr); int capacity = 0; JS_ValueToInt32(context,capacityVal,&capacity); CCSpriteBatchNode *pBatchNode = CCSpriteBatchNode::batchNodeWithFile( fileName, capacity); JS_free(context, fileName); if(pBatchNode) { JSObject *newObj = JS_NewObject(context, &clz, obj, NULL); JS_SetPrivate(context,newObj, pBatchNode); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(newObj)); } } } return JS_TRUE; }
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; }
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 }
////////////////////////////////////////////////////////////////////////// // 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; }
JSBool GetObject(JSContext* cx, JSObject* obj, int index, JSObject** value) { jsval element; if(JS_GetElement(cx, obj, index, &element) == JS_FALSE) return JS_FALSE; if(JS_ValueToObject(cx, element, value) == JS_FALSE) return JS_FALSE; return JS_TRUE; }
JSObject* elixir_get_obj(JSContext *cx, jsval arg) { JSObject *ret = NULL; if (JSVAL_IS_OBJECT(arg)) JS_ValueToObject(cx, arg, &ret); return ret; }
JSObject* getObjectFromNamespace(JSContext* cx, JSObject *ns, const char *name) { jsval out; if (JS_GetProperty(cx, ns, name, &out) == JS_TRUE) { JSObject *obj; if (JS_ValueToObject(cx, out, &obj) == JS_TRUE) { } } return NULL; }
void FFSessionHandler::getStringObjectClass(JSContext* ctx) { jsval str = JS_GetEmptyStringValue(ctx); JSObject* obj = 0; if (!JS_ValueToObject(ctx, str, &obj)) { return; } if (!obj) { return; } stringObjectClass = JS_GET_CLASS(ctx, obj); }
JSBool Core_print (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { JS_BeginRequest(cx); JS_EnterLocalRootScope(cx); char* separator = " "; char* end = "\n"; int fd = fileno(stdout); FILE* fp = NULL; jsval property; JSObject* options; if (argc > 1 && JS_TypeOfValue(cx, argv[argc-1]) == JSTYPE_OBJECT) { JS_ValueToObject(cx, argv[argc-1], &options); argc--; JS_GetProperty(cx, options, "separator", &property); if (JSVAL_IS_VOID(property) || JSVAL_IS_NULL(property)) { JS_GetProperty(cx, options, "sep", &property); } if (JSVAL_IS_STRING(property)) { separator = JS_GetStringBytes(JS_ValueToString(cx, property)); } JS_GetProperty(cx, options, "end", &property); if (JSVAL_IS_STRING(property)) { end = JS_GetStringBytes(JS_ValueToString(cx, property)); } JS_GetProperty(cx, options, "file", &property); if (JSVAL_IS_NUMBER(property)) { fd = JSVAL_TO_INT(property); } } fp = fdopen(fd, "a+"); uintN i; for (i = 0; i < argc; i++) { fprintf(fp, "%s", JS_GetStringBytes(JS_ValueToString(cx, argv[i]))); if (i != argc-1) { fprintf(fp, "%s", separator); } } fprintf(fp, "%s", end); JS_LeaveLocalRootScope(cx); JS_EndRequest(cx); return JS_TRUE; }
static JSBool Object(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { if (argc != 0) { if (!JS_ValueToObject(cx, argv[0], &obj)) return JS_FALSE; if (!obj) return JS_TRUE; } *rval = OBJECT_TO_JSVAL(obj); return JS_TRUE; }
bool convertFrom(JSContext *cx, jsval theValue, pango::JSContext::OWNERPTR & theOwner) { if (JSVAL_IS_OBJECT(theValue)) { JSObject * myArgument; if (JS_ValueToObject(cx, theValue, &myArgument)) { if (JSA_GetClass(cx,myArgument) == JSClassTraits<pango::JSContext::NATIVE>::Class()) { theOwner = pango::JSContext::getJSWrapper(cx, myArgument).getOwner(); return true; } } } return false; }
bool convertFrom(JSContext *cx, jsval theValue, asl::Sphere<Number> & theSphere) { if (JSVAL_IS_OBJECT(theValue)) { JSObject * myArgument; if (JS_ValueToObject(cx, theValue, &myArgument)) { if (JSA_GetClass(cx,myArgument) == JSClassTraits<asl::Sphere<Number> >::Class()) { theSphere = JSClassTraits<asl::Sphere<Number> >::getNativeRef(cx,myArgument); return true; } } } return false; }
JSBool JSB_get_arraybufferview_dataptr( JSContext *cx, jsval vp, GLsizei *count, GLvoid **data ) { JSObject *jsobj; JSBool ok = JS_ValueToObject( cx, vp, &jsobj ); JSB_PRECONDITION2( ok && jsobj, cx, JS_FALSE, "Error converting value to object"); JSB_PRECONDITION2( JS_IsArrayBufferViewObject(jsobj), cx, JS_FALSE, "Not an ArrayBufferView object"); *data = JS_GetArrayBufferViewData(jsobj); *count = JS_GetArrayBufferViewByteLength(jsobj); return JS_TRUE; }
JSBool jsval_to_c_class( JSContext *cx, jsval vp, void **out_native, struct jsb_c_proxy_s **out_proxy) { JSObject *jsobj; JSBool ok = JS_ValueToObject(cx, vp, &jsobj); JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error converting jsval to object"); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsobj); *out_native = proxy->handle; if( out_proxy ) *out_proxy = proxy; return JS_TRUE; }
JSBool Window_getChar (JSContext* cx, JSObject* object, uintN argc, jsval* argv, jsval* rval) { JSObject* options; WINDOW* win = (WINDOW*) JS_GetPrivate(cx, object); JS_BeginRequest(cx); JS_EnterLocalRootScope(cx); if (argc == 0) { *rval = INT_TO_JSVAL(wgetch(win)); } else { JS_ValueToObject(cx, argv[0], &options); if (!options) { JS_ReportError(cx, "Options isn't a valid object."); JS_LeaveLocalRootScope(cx); JS_EndRequest(cx); return JS_FALSE; } 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); } if (!JSVAL_IS_INT(x) || !JSVAL_IS_INT(y)) { JS_ReportError(cx, "An option is missing or isn't an int."); JS_LeaveLocalRootScope(cx); JS_EndRequest(cx); return JS_FALSE; } *rval = INT_TO_JSVAL(mvwgetch(win, JSVAL_TO_INT(y), JSVAL_TO_INT(x))); } JS_LeaveLocalRootScope(cx); JS_EndRequest(cx); return JS_TRUE; }