JSBool js_cocos2dx_GLNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) { if (argc == 0) { GLNode* cobj = new GLNode(); #ifdef COCOS2D_JAVASCRIPT cocos2d::Object *_ccobj = dynamic_cast<cocos2d::Object *>(cobj); if (_ccobj) { _ccobj->autorelease(); } #endif TypeTest<GLNode> 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)); // link the native object with the javascript object js_proxy_t *p = jsb_new_proxy(cobj, obj); #ifdef COCOS2D_JAVASCRIPT JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::GLNode"); #endif return JS_TRUE; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0); return JS_FALSE; }
inline js_proxy_t *js_get_or_create_proxy(JSContext *cx, T *native_obj) { js_proxy_t *proxy; HASH_FIND_PTR(_native_js_global_ht, &native_obj, proxy); if (!proxy) { js_type_class_t *typeProxy = js_get_type_from_native<T>(native_obj); // Return NULL if can't find its type rather than making an assert. // assert(typeProxy); if (!typeProxy) { CCLOGINFO("Could not find the type of native object."); return NULL; } JSObject* js_obj = JS_NewObject(cx, typeProxy->jsclass, typeProxy->proto, typeProxy->parentProto); proxy = jsb_new_proxy(native_obj, js_obj); #ifdef DEBUG JS_AddNamedObjectRoot(cx, &proxy->obj, typeid(*native_obj).name()); #else JS_AddObjectRoot(cx, &proxy->obj); #endif return proxy; } else { return proxy; } return NULL; }
static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::RootedValue initializing(cx); bool isNewValid = true; #if not $script_control_cpp JSObject* global = ScriptingCore::getInstance()->getGlobalObject(); isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && JSVAL_TO_BOOLEAN(initializing); #end if 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); #if $script_control_cpp T* cobj = new T(); js_proxy_t *pp = jsb_new_proxy(cobj, _tmp); JS_AddObjectRoot(cx, &pp->obj); #end if JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(_tmp)); return true; } #if not $script_control_cpp JS_ReportError(cx, "Don't use `new cc.XXX`, please use `cc.XXX.create` instead! "); #end if return false; }
bool js_cocos2dx_GLNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) { if (argc == 0) { GLNode* cobj = new GLNode(); cocos2d::Ref *_ccobj = dynamic_cast<cocos2d::Ref *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<GLNode> 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 *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t *p = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::GLNode"); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0); return false; }
bool js_cocos2dx_DrawNode3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cocos2d::DrawNode3D* cobj = new (std::nothrow) cocos2d::DrawNode3D(); cobj->init(); cocos2d::Ref *_ccobj = dynamic_cast<cocos2d::Ref *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<cocos2d::DrawNode3D> 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 *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); JS::RootedObject proto(cx, typeClass->proto.get()); JS::RootedObject parent(cx, typeClass->parentProto.get()); JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); AddNamedObjectRoot(cx, &p->obj, "cocos2d::DrawNode3D"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; }
static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, 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."); #if (COCOS2D_VERSION >= 0x00031000) JS::RootedObject proto(cx, typeClass->proto.ref()); JS::RootedObject parent(cx, typeClass->parentProto.ref()); #else JS::RootedObject proto(cx, typeClass->proto.get()); JS::RootedObject parent(cx, typeClass->parentProto.get()); #endif JS::RootedObject _tmp(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); T* cobj = new T(); js_proxy_t *pp = jsb_new_proxy(cobj, _tmp); AddObjectRoot(cx, &pp->obj); args.rval().set(OBJECT_TO_JSVAL(_tmp)); return true; } return false; }
inline js_proxy_t *js_get_or_create_proxy(JSContext *cx, T *native_obj) { auto proxy = jsb_get_native_proxy(native_obj); if (!proxy) { js_type_class_t *typeProxy = js_get_type_from_native<T>(native_obj); // Return NULL if can't find its type rather than making an assert. // assert(typeProxy); if (!typeProxy) { CCLOGINFO("Could not find the type of native object."); return NULL; } JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET JS::RootedObject proto(cx, typeProxy->proto.ref().get()); JS::RootedObject parent(cx, typeProxy->parentProto.ref().get()); JS::RootedObject js_obj(cx, JS_NewObject(cx, typeProxy->jsclass, proto, parent)); proxy = jsb_new_proxy(native_obj, js_obj); #ifdef DEBUG AddNamedObjectRoot(cx, &proxy->obj, typeid(*native_obj).name()); #else AddObjectRoot(cx, &proxy->obj); #endif return proxy; } else { return proxy; } return NULL; }
static JSBool js_jsb_iOSiapWrapper_iOSiapWrapperCallBackClass_ctor(JSContext *cx, uint32_t argc, jsval *vp) { JSObject *obj = JS_THIS_OBJECT(cx, vp); iOSiapWrapperCallBackClass *nobj = new iOSiapWrapperCallBackClass(); js_proxy_t* p = jsb_new_proxy(nobj, obj); JS_SET_RVAL(cx, vp, JSVAL_VOID); return JS_TRUE; }
static bool js_cocos2dx_GLNode_ctor(JSContext *cx, uint32_t argc, jsval *vp) { JSObject *obj = JS_THIS_OBJECT(cx, vp); GLNode *nobj = new GLNode(); js_proxy_t* p = jsb_new_proxy(nobj, obj); nobj->autorelease(); JS_AddNamedObjectRoot(cx, &p->obj, "GLNode"); JS_SET_RVAL(cx, vp, JSVAL_VOID); return true; }
static JSBool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { TypeTest<T> t; T* cobj = new T(); 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 = jsb_new_proxy(cobj, _tmp); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(_tmp)); return JS_TRUE; }
static bool js_coolexp_ErayLayer_ctor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); ErayLayer *nobj = new (std::nothrow) ErayLayer(); auto newproxy = jsb_new_proxy(nobj, obj); jsb_ref_init(cx, &newproxy->obj, nobj, "ErayLayer"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); args.rval().setUndefined(); return true; }
static bool js_es_Button_ctor(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); es::Button *nobj = new es::Button(); if (nobj) { nobj->autorelease(); } js_proxy_t* p = jsb_new_proxy(nobj, obj); JS_AddNamedObjectRoot(cx, &p->obj, "es::Button"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound)) ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); JS_SET_RVAL(cx, vp, JSVAL_VOID); return true; }
// this function copies co to a new object and pass it to js. And this new object will be deleted automatic by GC. jsval CFBFunctionsJS::createJsvalFromCard(const CFBCard& co) { JSAutoCompartment ac(_cx, _go); TypeTest<CFBCard> 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 *obj = JS_NewObject(_cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); jsb_new_proxy(new CFBCard(co), obj); return OBJECT_TO_JSVAL(obj); }
JSBool js_jsb_iOSiapWrapper_iOSiapWrapperCallBackClass_constructor(JSContext *cx, uint32_t argc, jsval *vp) { if (argc == 0) { iOSiapWrapperCallBackClass* cobj = new iOSiapWrapperCallBackClass(); TypeTest<iOSiapWrapperCallBackClass> 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)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); return JS_TRUE; } JS_ReportError(cx, "js_jsb_iOSiapWrapper_iOSiapWrapperCallBackClass_constructor : wrong number of arguments: %d, was expecting %d", argc, 0); return JS_FALSE; }
ComponentJS::ComponentJS(const std::string& scriptFileName) : _scriptFileName(scriptFileName) , _jsObj(nullptr) { ScriptingCore* engine = ScriptingCore::getInstance(); JSContext* cx = engine->getGlobalContext(); // Require script JS::RootedValue classValue(cx); _succeedLoadingScript = engine->requireScript(_scriptFileName.c_str(), &classValue); if (_succeedLoadingScript) { JS::RootedObject classObj(cx, classValue.toObjectOrNull()); const JSClass* theClass = JS_GetClass(classObj); JS::RootedValue protoValue(cx); JS_GetProperty(cx, classObj, "prototype", &protoValue); TypeTest<ComponentJS> 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; mozilla::Maybe<JS::PersistentRootedObject> *jsObj = new (std::nothrow) mozilla::Maybe<JS::PersistentRootedObject>(); JS::RootedObject proto(cx, protoValue.toObjectOrNull()); JS::RootedObject parent(cx, typeClass->proto.ref()); jsObj->construct(cx); JS::RootedObject obj(cx, JS_NewObject(cx, theClass, proto, parent)); jsObj->ref() = obj; // Unbind current proxy binding js_proxy_t* jsproxy = js_get_or_create_proxy<ComponentJS>(cx, this); JS::RemoveObjectRoot(cx, &jsproxy->obj); jsb_remove_proxy(jsproxy); // link the native object with the javascript object jsb_new_proxy(this, jsObj->ref()); _jsObj = jsObj; } }
ComponentJS::ComponentJS(const std::string& scriptFileName) : _scriptFileName(scriptFileName) , _jsObj(nullptr) { ScriptingCore* engine = ScriptingCore::getInstance(); JSContext* cx = engine->getGlobalContext(); // Require script JS::RootedValue classValue(cx); _succeedLoadingScript = engine->requireScript(_scriptFileName.c_str(), &classValue); if (_succeedLoadingScript) { JS::RootedObject classObj(cx, classValue.toObjectOrNull()); const JSClass* theClass = JS_GetClass(classObj); JS::RootedValue protoValue(cx); JS_GetProperty(cx, classObj, "prototype", &protoValue); mozilla::Maybe<JS::PersistentRootedObject> *jsObj = new (std::nothrow) mozilla::Maybe<JS::PersistentRootedObject>(); js_type_class_t *typeClass = js_get_type_from_native<cocos2d::ComponentJS>(this); JS::RootedObject proto(cx, protoValue.toObjectOrNull()); JS::RootedObject parent(cx, typeClass->proto.ref()); jsObj->construct(cx); JS::RootedObject obj(cx, JS_NewObject(cx, theClass, proto, parent)); jsObj->ref() = obj; // Unbind current proxy binding js_proxy_t* nproxy = jsb_get_native_proxy(this); if (nproxy) { #if CC_ENABLE_GC_FOR_NATIVE_OBJECTS JS::RemoveObjectRoot(cx, &nproxy->obj); #endif // CC_ENABLE_GC_FOR_NATIVE_OBJECTS jsb_remove_proxy(nproxy, jsb_get_js_proxy(nproxy->obj)); } // link the native object with the javascript object jsb_new_proxy(this, jsObj->ref()); _jsObj = jsObj; } }
void __JSDownloaderDelegator::onSuccess(const std::string &srcUrl, const std::string &storagePath, const std::string &customId) { Image *image = new Image(); jsval valArr[2]; JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); JSObject *global = ScriptingCore::getInstance()->getGlobalObject(); JSAutoCompartment ac(_cx, _obj); if(image->initWithImageData(_buffer, _size)) { Texture2D *tex = Director::getInstance()->getTextureCache()->addImage(image, srcUrl); valArr[0] = BOOLEAN_TO_JSVAL(true); js_type_class_t *classType = js_get_type_from_native<cocos2d::Texture2D>(tex); assert(classType); JSObject *obj = JS_NewObject(cx, classType->jsclass, classType->proto, classType->parentProto); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(tex, obj); JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::Texture2D"); valArr[1] = OBJECT_TO_JSVAL(p->obj); } else { valArr[0] = BOOLEAN_TO_JSVAL(false); valArr[1] = JSVAL_NULL; } image->release(); if (!JSVAL_IS_NULL(_jsCallback)) { jsval retval; JS_AddValueRoot(cx, valArr); JS_CallFunctionValue(cx, global, _jsCallback, 2, valArr, &retval); JS_RemoveValueRoot(cx, valArr); JS_RemoveValueRoot(cx, &_jsCallback); } this->release(); }
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; }
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; }
static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::RootedValue initializing(cx); bool isNewValid = true; #if not $script_control_cpp JS::RootedObject global(cx, ScriptingCore::getInstance()->getGlobalObject()); isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && initializing.toBoolean(); #end if 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."); JS::RootedObject proto(cx, typeClass->proto.get()); JS::RootedObject parent(cx, typeClass->parentProto.get()); JS::RootedObject _tmp(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); #if $script_control_cpp T* cobj = new T(); js_proxy_t *pp = jsb_new_proxy(cobj, _tmp); AddObjectRoot(cx, &pp->obj); #end if args.rval().set(OBJECT_TO_JSVAL(_tmp)); return true; } #if not $script_control_cpp JS_ReportError(cx, "Constructor for the requested class is not available, please refer to the API reference."); #end if return false; }
JSBool js_cocos2dx_spine_SkeletonAnimation_constructor(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); JSBool ok = JS_TRUE; JSObject *obj = NULL; spine::SkeletonAnimation* cobj = NULL; do { if (argc == 2) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = JS_TRUE; break; } spAtlas* arg1; #pragma warning NO CONVERSION TO NATIVE FOR spAtlas*; if (!ok) { ok = JS_TRUE; break; } cobj = new spine::SkeletonAnimation(arg0, arg1); cocos2d::Object *_ccobj = dynamic_cast<cocos2d::Object *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<spine::SkeletonAnimation> 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."); obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); js_proxy_t* proxy = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &proxy->obj, "spine::SkeletonAnimation"); } } while(0); do { if (argc == 3) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = JS_TRUE; break; } spAtlas* arg1; #pragma warning NO CONVERSION TO NATIVE FOR spAtlas*; if (!ok) { ok = JS_TRUE; break; } double arg2; ok &= JS_ValueToNumber(cx, argv[2], &arg2); if (!ok) { ok = JS_TRUE; break; } cobj = new spine::SkeletonAnimation(arg0, arg1, arg2); cocos2d::Object *_ccobj = dynamic_cast<cocos2d::Object *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<spine::SkeletonAnimation> 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."); obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); js_proxy_t* proxy = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &proxy->obj, "spine::SkeletonAnimation"); } } while(0); do { if (argc == 1) { spSkeletonData* arg0; #pragma warning NO CONVERSION TO NATIVE FOR spSkeletonData*; if (!ok) { ok = JS_TRUE; break; } cobj = new spine::SkeletonAnimation(arg0); cocos2d::Object *_ccobj = dynamic_cast<cocos2d::Object *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<spine::SkeletonAnimation> 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."); obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); js_proxy_t* proxy = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &proxy->obj, "spine::SkeletonAnimation"); } } while(0); do { if (argc == 2) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = JS_TRUE; break; } const char* arg1; std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); if (!ok) { ok = JS_TRUE; break; } cobj = new spine::SkeletonAnimation(arg0, arg1); cocos2d::Object *_ccobj = dynamic_cast<cocos2d::Object *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<spine::SkeletonAnimation> 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."); obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); js_proxy_t* proxy = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &proxy->obj, "spine::SkeletonAnimation"); } } while(0); do { if (argc == 3) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = JS_TRUE; break; } const char* arg1; std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); if (!ok) { ok = JS_TRUE; break; } double arg2; ok &= JS_ValueToNumber(cx, argv[2], &arg2); if (!ok) { ok = JS_TRUE; break; } cobj = new spine::SkeletonAnimation(arg0, arg1, arg2); cocos2d::Object *_ccobj = dynamic_cast<cocos2d::Object *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<spine::SkeletonAnimation> 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."); obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); js_proxy_t* proxy = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &proxy->obj, "spine::SkeletonAnimation"); } } while(0); if (cobj) { JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); return JS_TRUE; } JS_ReportError(cx, "js_cocos2dx_spine_SkeletonAnimation_constructor : wrong number of arguments"); return JS_FALSE; }
JSBool js_cocos2dx_extension_WebSocket_constructor(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); if (argc == 1 || argc == 2) { std::string url; do { JSBool ok = jsval_to_std_string(cx, argv[0], &url); JSB_PRECONDITION2( ok, cx, JS_FALSE, "Error processing arguments"); } while (0); JSObject *obj = JS_NewObject(cx, js_cocos2dx_websocket_class, js_cocos2dx_websocket_prototype, NULL); cocos2d::extension::WebSocket* cobj = new cocos2d::extension::WebSocket(); JSB_WebSocketDelegate* delegate = new JSB_WebSocketDelegate(); delegate->setJSDelegate(obj); if (argc == 2) { std::vector<std::string> protocols; if (JSVAL_IS_STRING(argv[1])) { std::string protocol; do { JSBool ok = jsval_to_std_string(cx, argv[1], &protocol); JSB_PRECONDITION2( ok, cx, JS_FALSE, "Error processing arguments"); } while (0); protocols.push_back(protocol); } else if (argv[1].isObject()) { JSBool ok = JS_TRUE; JSObject* arg2 = JSVAL_TO_OBJECT(argv[1]); JSB_PRECONDITION(JS_IsArrayObject( cx, arg2 ), "Object must be an array"); uint32_t len = 0; JS_GetArrayLength(cx, arg2, &len); for( uint32_t i=0; i< len;i++ ) { jsval valarg; JS_GetElement(cx, arg2, i, &valarg); std::string protocol; do { ok = jsval_to_std_string(cx, valarg, &protocol); JSB_PRECONDITION2( ok, cx, JS_FALSE, "Error processing arguments"); } while (0); protocols.push_back(protocol); } } cobj->init(*delegate, url, &protocols); } else { cobj->init(*delegate, url); } JS_DefineProperty(cx, obj, "URL", argv[0] , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); //protocol not support yet (always return "") JS_DefineProperty(cx, obj, "protocol", c_string_to_jsval(cx, "") , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); // link the native object with the javascript object js_proxy_t *p = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &p->obj, "WebSocket"); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); return JS_TRUE; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0); return JS_FALSE; }
bool js_autogentestbindings_SimpleNativeClass_constructor(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); bool ok = true; JSObject *obj = NULL; SimpleNativeClass* cobj = NULL; do { if (argc == 1) { int arg0; ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); if (!ok) { ok = true; break; } cobj = new SimpleNativeClass(arg0); cocos2d::Ref *_ccobj = dynamic_cast<cocos2d::Ref *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<SimpleNativeClass> 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."); obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); js_proxy_t* p = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &p->obj, "SimpleNativeClass"); } } while(0); do { if (argc == 0) { cobj = new SimpleNativeClass(); cocos2d::Ref *_ccobj = dynamic_cast<cocos2d::Ref *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<SimpleNativeClass> 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."); obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); js_proxy_t* p = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &p->obj, "SimpleNativeClass"); } } while(0); do { if (argc == 2) { int arg0; ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); if (!ok) { ok = true; break; } int arg1; ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); if (!ok) { ok = true; break; } cobj = new SimpleNativeClass(arg0, arg1); cocos2d::Ref *_ccobj = dynamic_cast<cocos2d::Ref *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<SimpleNativeClass> 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."); obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); js_proxy_t* p = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &p->obj, "SimpleNativeClass"); } } while(0); if (cobj) { JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); return true; } JS_ReportError(cx, "js_autogentestbindings_SimpleNativeClass_constructor : wrong number of arguments"); return false; }
bool js_cocos2dx_spine_SkeletonAnimation_constructor(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); bool ok = true; JSObject *obj = NULL; spine::SkeletonAnimation* cobj = NULL; do { if (argc == 2) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = true; break; } spAtlas* arg1; #pragma warning NO CONVERSION TO NATIVE FOR spAtlas* ok = false; if (!ok) { ok = true; break; } cobj = new (std::nothrow) spine::SkeletonAnimation(arg0, arg1); cocos2d::Ref *_ccobj = dynamic_cast<cocos2d::Ref *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<spine::SkeletonAnimation> 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."); obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); js_proxy_t* p = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonAnimation"); } } while(0); do { if (argc == 3) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = true; break; } spAtlas* arg1; #pragma warning NO CONVERSION TO NATIVE FOR spAtlas* ok = false; if (!ok) { ok = true; break; } double arg2; ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); if (!ok) { ok = true; break; } cobj = new (std::nothrow) spine::SkeletonAnimation(arg0, arg1, arg2); cocos2d::Ref *_ccobj = dynamic_cast<cocos2d::Ref *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<spine::SkeletonAnimation> 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."); obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); js_proxy_t* p = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonAnimation"); } } while(0); do { if (argc == 1) { spSkeletonData* arg0; #pragma warning NO CONVERSION TO NATIVE FOR spSkeletonData* ok = false; if (!ok) { ok = true; break; } cobj = new (std::nothrow) spine::SkeletonAnimation(arg0); cocos2d::Ref *_ccobj = dynamic_cast<cocos2d::Ref *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<spine::SkeletonAnimation> 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."); obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); js_proxy_t* p = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonAnimation"); } } while(0); do { if (argc == 2) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = true; break; } const char* arg1; std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); if (!ok) { ok = true; break; } cobj = new (std::nothrow) spine::SkeletonAnimation(arg0, arg1); cocos2d::Ref *_ccobj = dynamic_cast<cocos2d::Ref *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<spine::SkeletonAnimation> 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."); obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); js_proxy_t* p = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonAnimation"); } } while(0); do { if (argc == 3) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = true; break; } const char* arg1; std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); if (!ok) { ok = true; break; } double arg2; ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[2]), &arg2); if (!ok) { ok = true; break; } cobj = new (std::nothrow) spine::SkeletonAnimation(arg0, arg1, arg2); cocos2d::Ref *_ccobj = dynamic_cast<cocos2d::Ref *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<spine::SkeletonAnimation> 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."); obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); js_proxy_t* p = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &p->obj, "spine::SkeletonAnimation"); } } while(0); if (cobj) { if (JS_HasProperty(cx, obj, "_ctor", &ok)) ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", argc, argv); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); return true; } JS_ReportError(cx, "js_cocos2dx_spine_SkeletonAnimation_constructor : wrong number of arguments"); return false; }