diff --git a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_3d_auto_api.js b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_3d_auto_api.js index bfc87c64f2..319d1a4b8e 100644 --- a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_3d_auto_api.js +++ b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_3d_auto_api.js @@ -56,20 +56,6 @@ getDuration : function ( return 0; }, -/** - * @method create - * @param {String} arg0 - * @param {String} arg1 - * @return {cc.Animation3D} - */ -create : function ( -str, -str -) -{ - return cc.Animation3D; -}, - /** * @method Animation3D * @constructor diff --git a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js index 1bb76c58a2..626f1990b7 100644 --- a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js +++ b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js @@ -4903,6 +4903,32 @@ getElapsed : function ( */ cc.Sequence = { +/** + * @method init + * @param {Array} arg0 + * @return {bool} + */ +init : function ( +array +) +{ + return false; +}, + +/** + * @method initWithTwoActions + * @param {cc.FiniteTimeAction} arg0 + * @param {cc.FiniteTimeAction} arg1 + * @return {bool} + */ +initWithTwoActions : function ( +finitetimeaction, +finitetimeaction +) +{ + return false; +}, + /** * @method Sequence * @constructor @@ -5043,6 +5069,32 @@ RepeatForever : function ( */ cc.Spawn = { +/** + * @method init + * @param {Array} arg0 + * @return {bool} + */ +init : function ( +array +) +{ + return false; +}, + +/** + * @method initWithTwoActions + * @param {cc.FiniteTimeAction} arg0 + * @param {cc.FiniteTimeAction} arg1 + * @return {bool} + */ +initWithTwoActions : function ( +finitetimeaction, +finitetimeaction +) +{ + return false; +}, + /** * @method Spawn * @constructor diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.cpp index b220ac88be..e429e644be 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.cpp @@ -115,38 +115,6 @@ bool js_cocos2dx_3d_Animation3D_getDuration(JSContext *cx, uint32_t argc, jsval JS_ReportError(cx, "js_cocos2dx_3d_Animation3D_getDuration : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_3d_Animation3D_create(JSContext *cx, uint32_t argc, jsval *vp) -{ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - bool ok = true; - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, args.get(0), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animation3D_create : Error processing arguments"); - - auto ret = cocos2d::Animation3D::create(arg0); - js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_autoreleased_create_jsobject(cx, ret, typeClass, "cocos2d::Animation3D")); - args.rval().set(OBJECT_TO_JSVAL(jsret)); - return true; - } - if (argc == 2) { - std::string arg0; - std::string arg1; - ok &= jsval_to_std_string(cx, args.get(0), &arg0); - ok &= jsval_to_std_string(cx, args.get(1), &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animation3D_create : Error processing arguments"); - - auto ret = cocos2d::Animation3D::create(arg0, arg1); - js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_autoreleased_create_jsobject(cx, ret, typeClass, "cocos2d::Animation3D")); - args.rval().set(OBJECT_TO_JSVAL(jsret)); - return true; - } - JS_ReportError(cx, "js_cocos2dx_3d_Animation3D_create : wrong number of arguments"); - return false; -} - bool js_cocos2dx_3d_Animation3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -190,10 +158,7 @@ void js_register_cocos2dx_3d_Animation3D(JSContext *cx, JS::HandleObject global) JS_FS_END }; - static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_3d_Animation3D_create, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; + JSFunctionSpec *st_funcs = NULL; jsb_cocos2d_Animation3D_prototype = JS_InitClass( cx, global, diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.hpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.hpp index 49a39b5fa2..07ee9c6107 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.hpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.hpp @@ -16,7 +16,6 @@ bool js_cocos2dx_3d_Animation3D_initWithFile(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_3d_Animation3D_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_3d_Animation3D_getBoneCurveByName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_3d_Animation3D_getDuration(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_3d_Animation3D_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_3d_Animation3D_Animation3D(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_Animate3D_class; diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp index 6c15a2224e..d8b66fe53e 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp @@ -7635,7 +7635,7 @@ bool js_cocos2dx_Director_getInstance(JSContext *cx, uint32_t argc, jsval *vp) auto ret = cocos2d::Director::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Director")); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Director")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -12214,6 +12214,68 @@ void js_register_cocos2dx_ActionInterval(JSContext *cx, JS::HandleObject global) JSClass *jsb_cocos2d_Sequence_class; JSObject *jsb_cocos2d_Sequence_prototype; +bool js_cocos2dx_Sequence_init(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sequence* cobj = (cocos2d::Sequence *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sequence_init : Invalid Native Object"); + if (argc == 1) { + cocos2d::Vector arg0; + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sequence_init : Error processing arguments"); + bool ret = cobj->init(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Sequence_init : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_Sequence_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sequence* cobj = (cocos2d::Sequence *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sequence_initWithTwoActions : Invalid Native Object"); + if (argc == 2) { + cocos2d::FiniteTimeAction* arg0 = nullptr; + cocos2d::FiniteTimeAction* arg1 = nullptr; + do { + if (args.get(0).isNull()) { arg0 = nullptr; break; } + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + do { + if (args.get(1).isNull()) { arg1 = nullptr; break; } + if (!args.get(1).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JS::RootedObject tmpObj(cx, args.get(1).toObjectOrNull()); + jsProxy = jsb_get_js_proxy(tmpObj); + arg1 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sequence_initWithTwoActions : Error processing arguments"); + bool ret = cobj->initWithTwoActions(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Sequence_initWithTwoActions : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} bool js_cocos2dx_Sequence_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -12266,6 +12328,8 @@ void js_register_cocos2dx_Sequence(JSContext *cx, JS::HandleObject global) { }; static JSFunctionSpec funcs[] = { + JS_FN("init", js_cocos2dx_Sequence_init, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithTwoActions", js_cocos2dx_Sequence_initWithTwoActions, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2dx_Sequence_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -12678,6 +12742,68 @@ void js_register_cocos2dx_RepeatForever(JSContext *cx, JS::HandleObject global) JSClass *jsb_cocos2d_Spawn_class; JSObject *jsb_cocos2d_Spawn_prototype; +bool js_cocos2dx_Spawn_init(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Spawn* cobj = (cocos2d::Spawn *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Spawn_init : Invalid Native Object"); + if (argc == 1) { + cocos2d::Vector arg0; + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Spawn_init : Error processing arguments"); + bool ret = cobj->init(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Spawn_init : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_Spawn_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Spawn* cobj = (cocos2d::Spawn *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Spawn_initWithTwoActions : Invalid Native Object"); + if (argc == 2) { + cocos2d::FiniteTimeAction* arg0 = nullptr; + cocos2d::FiniteTimeAction* arg1 = nullptr; + do { + if (args.get(0).isNull()) { arg0 = nullptr; break; } + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + do { + if (args.get(1).isNull()) { arg1 = nullptr; break; } + if (!args.get(1).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JS::RootedObject tmpObj(cx, args.get(1).toObjectOrNull()); + jsProxy = jsb_get_js_proxy(tmpObj); + arg1 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Spawn_initWithTwoActions : Error processing arguments"); + bool ret = cobj->initWithTwoActions(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Spawn_initWithTwoActions : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} bool js_cocos2dx_Spawn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -12730,6 +12856,8 @@ void js_register_cocos2dx_Spawn(JSContext *cx, JS::HandleObject global) { }; static JSFunctionSpec funcs[] = { + JS_FN("init", js_cocos2dx_Spawn_init, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithTwoActions", js_cocos2dx_Spawn_initWithTwoActions, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2dx_Spawn_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -16726,7 +16854,7 @@ bool js_cocos2dx_Configuration_getInstance(JSContext *cx, uint32_t argc, jsval * auto ret = cocos2d::Configuration::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Configuration")); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Configuration")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -55950,7 +56078,7 @@ bool js_cocos2dx_GLProgramCache_getInstance(JSContext *cx, uint32_t argc, jsval auto ret = cocos2d::GLProgramCache::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::GLProgramCache")); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::GLProgramCache")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -58157,7 +58285,7 @@ bool js_cocos2dx_AnimationCache_getInstance(JSContext *cx, uint32_t argc, jsval auto ret = cocos2d::AnimationCache::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::AnimationCache")); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::AnimationCache")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -59307,7 +59435,7 @@ bool js_cocos2dx_SpriteFrameCache_getInstance(JSContext *cx, uint32_t argc, jsva auto ret = cocos2d::SpriteFrameCache::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::SpriteFrameCache")); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::SpriteFrameCache")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp index 0055f1c107..fb22303582 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp @@ -648,6 +648,8 @@ bool js_cocos2dx_Sequence_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Sequence_finalize(JSContext *cx, JSObject *obj); void js_register_cocos2dx_Sequence(JSContext *cx, JS::HandleObject global); void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_Sequence_init(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Sequence_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sequence_Sequence(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_Repeat_class; @@ -683,6 +685,8 @@ bool js_cocos2dx_Spawn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Spawn_finalize(JSContext *cx, JSObject *obj); void js_register_cocos2dx_Spawn(JSContext *cx, JS::HandleObject global); void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_Spawn_init(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Spawn_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Spawn_Spawn(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_RotateTo_class; diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp index 660f580f1a..3a425d1161 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp @@ -698,7 +698,7 @@ bool js_cocos2dx_studio_ActionManagerEx_getInstance(JSContext *cx, uint32_t argc auto ret = cocostudio::ActionManagerEx::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ActionManagerEx")); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ActionManagerEx")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -5172,7 +5172,7 @@ bool js_cocos2dx_studio_ArmatureDataManager_getInstance(JSContext *cx, uint32_t auto ret = cocostudio::ArmatureDataManager::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ArmatureDataManager")); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ArmatureDataManager")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } diff --git a/cocos/scripting/js-bindings/manual/3d/jsb_cocos2dx_3d_manual.cpp b/cocos/scripting/js-bindings/manual/3d/jsb_cocos2dx_3d_manual.cpp index 0929d7f396..72e6fd78a9 100644 --- a/cocos/scripting/js-bindings/manual/3d/jsb_cocos2dx_3d_manual.cpp +++ b/cocos/scripting/js-bindings/manual/3d/jsb_cocos2dx_3d_manual.cpp @@ -64,8 +64,8 @@ static bool js_cocos2dx_Sprite3D_createAsync(JSContext *cx, uint32_t argc, jsval auto lambda = [=](Sprite3D* larg0, void* larg1) -> void{ jsval largv[2]; - js_proxy_t* proxy = js_get_or_create_proxy(cx, larg0); - largv[0] = proxy ? OBJECT_TO_JSVAL(proxy->obj) : JS::UndefinedValue(); + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + largv[0] = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, larg0)); JSB_HeapValueWrapper* v = (JSB_HeapValueWrapper*)larg1; largv[1] = v->get(); @@ -280,8 +280,7 @@ bool js_cocos2dx_Terrain_create(JSContext *cx, uint32_t argc, jsval *vp) ret = Terrain::create(arg0, arg1); } - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (Terrain*)ret); - args.rval().set(OBJECT_TO_JSVAL(jsProxy->obj)); + args.rval().set(OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, ret))); return true; } JS_ReportError(cx, "wrong number of arguments"); @@ -342,6 +341,42 @@ bool js_cocos2dx_Terrain_getHeightData(JSContext *cx, uint32_t argc, jsval *vp) return false; } +// this code cannot be automated since it must use +// get_or_create_jsobject instead of create_jsobject +// since Animation3D::create() might return an existing copy +// since it caches them +bool js_cocos2dx_3d_Animation3D_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animation3D_create : Error processing arguments"); + + auto ret = cocos2d::Animation3D::create(arg0); + js_type_class_t *typeClass = js_get_type_from_native(ret); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Animation3D")); + args.rval().set(OBJECT_TO_JSVAL(jsret)); + return true; + } + if (argc == 2) { + std::string arg0; + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animation3D_create : Error processing arguments"); + + auto ret = cocos2d::Animation3D::create(arg0, arg1); + js_type_class_t *typeClass = js_get_type_from_native(ret); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Animation3D")); + args.rval().set(OBJECT_TO_JSVAL(jsret)); + return true; + } + JS_ReportError(cx, "js_cocos2dx_3d_Animation3D_create : wrong number of arguments"); + return false; +} + void register_all_cocos2dx_3d_manual(JSContext *cx, JS::HandleObject global) { JS::RootedValue tmpVal(cx); @@ -357,6 +392,10 @@ void register_all_cocos2dx_3d_manual(JSContext *cx, JS::HandleObject global) tmpObj.set(tmpVal.toObjectOrNull()); JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_Terrain_create, 2, JSPROP_READONLY | JSPROP_PERMANENT); + JS_GetProperty(cx, ccObj, "Animation3D", &tmpVal); + tmpObj.set(tmpVal.toObjectOrNull()); + JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_3d_Animation3D_create, 2, JSPROP_READONLY | JSPROP_PERMANENT); + JS_GetProperty(cx, ccObj, "Bundle3D", &tmpVal); tmpObj.set(tmpVal.toObjectOrNull()); JS_DefineFunction(cx, tmpObj, "getTrianglesList", js_cocos2dx_Bundle3D_getTrianglesList, 1, JSPROP_READONLY | JSPROP_PERMANENT); diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp index 6a0acc472c..9c1157028d 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp @@ -2018,16 +2018,6 @@ JSObject* jsb_ref_autoreleased_create_jsobject(JSContext *cx, cocos2d::Ref *ref, return js_obj; } -JSObject* jsb_ref_singleton_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug) -{ - JS::RootedObject proto(cx, typeClass->proto.ref()); - JS::RootedObject parent(cx, typeClass->parentProto.ref()); - JS::RootedObject js_obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); - js_proxy_t* newproxy = jsb_new_proxy(ref, js_obj); - jsb_ref_singleton_init(cx, &newproxy->obj, ref, debug); - return js_obj; -} - // get_or_create JSObject* jsb_ref_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug) { @@ -2038,13 +2028,14 @@ JSObject* jsb_ref_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_ty return jsb_ref_create_jsobject(cx, ref, typeClass, debug); } -JSObject* jsb_ref_singleton_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug) +// get_or_create: REf is already autoreleased (or created) +JSObject* jsb_ref_autoreleased_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug) { auto proxy = jsb_get_native_proxy(ref); if (proxy) return proxy->obj; // else - return jsb_ref_singleton_create_jsobject(cx, ref, typeClass, debug); + return jsb_ref_autoreleased_create_jsobject(cx, ref, typeClass, debug); } // ref_init @@ -2071,34 +2062,22 @@ void jsb_ref_autoreleased_init(JSContext* cx, JS::Heap *obj, Ref* ref (void)obj; ref->_scriptOwned = true; // retain it, since the object is autoreleased - ret->retain(); + ref->retain(); #else // don't autorelease it, since it is already autoreleased JS::AddNamedObjectRoot(cx, obj, debug); #endif } -void jsb_ref_singleton_init(JSContext* cx, JS::Heap *obj, Ref* ref, const char* debug) -{ - // CCLOG("jsb_ref_singleton_init: JSObject address = %p. %s", obj->get(), debug); -#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS - (void)cx; - (void)obj; - ref->_scriptOwned = true; - // don't retain it: it is a singleton -#else - // don't autorelease it: it is a singleton - JS::AddNamedObjectRoot(cx, obj, debug); -#endif -} - // finalize void jsb_ref_finalize(JSFreeOp* fop, JSObject* obj) { #if CC_ENABLE_GC_FOR_NATIVE_OBJECTS js_proxy_t* nproxy; js_proxy_t* jsproxy; - jsproxy = jsb_get_js_proxy(obj); + + JS::RootedObject jsobj(ScriptingCore::getInstance()->getGlobalContext(), obj); + jsproxy = jsb_get_js_proxy(jsobj); if (jsproxy) { auto ref = static_cast(jsproxy->ptr); diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.h b/cocos/scripting/js-bindings/manual/ScriptingCore.h index e5f8587ad6..259ba5962d 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.h +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.h @@ -565,12 +565,6 @@ void jsb_ref_init(JSContext* cx, JS::Heap *obj, cocos2d::Ref* ref, co */ void jsb_ref_autoreleased_init(JSContext* cx, JS::Heap *obj, cocos2d::Ref* ref, const char* debug); -/** - * Generic initialization function for Singletons - * Similar to jsb_ref_init(), but call it to initialize singletons - */ -void jsb_ref_singleton_init(JSContext* cx, JS::Heap *obj, cocos2d::Ref* ref, const char* debug); - /** * Generic finalize used by objects that are subclass of Ref */ @@ -595,12 +589,6 @@ JSObject* jsb_ref_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_clas */ JSObject* jsb_ref_autoreleased_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug); -/** - * Creates a new JSObject of a certain type (typeClass) and creates a proxy associated with and the Singleton (ref) - * Similar to jsb_ref_create_jsobject(), but call it if you know that Ref is a Singleton - */ -JSObject* jsb_ref_singleton_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug); - /** It will try to get the associated JSObjct for ref. If it can't find it, it will create a new one associating it to Ref @@ -611,7 +599,8 @@ JSObject* jsb_ref_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_ty It will try to get the associated JSObjct for ref. If it can't find it, it will create a new one associating it to Ref */ -JSObject* jsb_ref_singleton_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug); +JSObject* jsb_ref_autoreleased_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug); + void removeJSObject(JSContext* cx, void* nativeObj); diff --git a/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp b/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp index 836aadaebe..b4489b1fa8 100644 --- a/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp +++ b/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp @@ -203,10 +203,9 @@ bool js_cocos2dx_EventTouch_getTouches(JSContext *cx, uint32_t argc, jsval *vp) JS::RootedValue arrElement(cx); //First, check whether object is associated with js object. - js_proxy_t* jsproxy = js_get_or_create_proxy(cx, touchObj); - if (jsproxy) { - arrElement = OBJECT_TO_JSVAL(jsproxy->obj); - } + auto jsobj = js_get_or_create_jsobject(cx, touchObj); + if (jsobj) + arrElement = OBJECT_TO_JSVAL(jsobj); if (!JS_SetElement(cx, jsretArr, i, arrElement)) { break; } @@ -4558,8 +4557,7 @@ bool js_PlistParser_getInstance(JSContext *cx, unsigned argc, JS::Value *vp) jsret = OBJECT_TO_JSVAL(p->obj); } else { // create a new js obj of that class - js_proxy_t *proxy = js_get_or_create_proxy(cx, parser); - jsret = OBJECT_TO_JSVAL(proxy->obj); + jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, parser)); } } else { jsret = JSVAL_NULL; @@ -4878,8 +4876,8 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v jsval largv[2]; do { if (larg0) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::RenderTexture*)larg0); - largv[0] = OBJECT_TO_JSVAL(jsProxy->obj); + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + largv[0] = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, (cocos2d::RenderTexture*)larg0)); } else { largv[0] = JSVAL_NULL; } @@ -4949,8 +4947,8 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v jsval largv[2]; do { if (larg0) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::RenderTexture*)larg0); - largv[0] = OBJECT_TO_JSVAL(jsProxy->obj); + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + largv[0] = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, (cocos2d::RenderTexture*)larg0)); } else { largv[0] = JSVAL_NULL; } @@ -5314,17 +5312,10 @@ bool js_cocos2dx_Scene_getPhysics3DWorld(JSContext *cx, uint32_t argc, jsval *vp { cocos2d::Physics3DWorld* ret = cobj->getPhysics3DWorld(); jsval jsret = JSVAL_NULL; - do - { - if (ret) - { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Physics3DWorld*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else - { - jsret = JSVAL_NULL; - } - } while (0); + if (ret) + jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, (cocos2d::Physics3DWorld*)ret)); + else + jsret = JSVAL_NULL; args.rval().set(jsret); return true; } @@ -5400,15 +5391,10 @@ bool js_cocos2dx_Scene_getNavMesh(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 0) { cocos2d::NavMesh* ret = cobj->getNavMesh(); jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::NavMesh*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } - else { - jsret = JSVAL_NULL; - } - } while (0); + if (ret) + jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, (cocos2d::NavMesh*)ret)); + else + jsret = JSVAL_NULL; args.rval().set(jsret); return true; } @@ -5657,14 +5643,11 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments"); cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0)); jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); + if (ret) { + jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, ret)); + } else { + jsret = JSVAL_NULL; + } args.rval().set(jsret); return true; } @@ -5676,14 +5659,11 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments"); cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1)); jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); + if (ret) { + jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, ret)); + } else { + jsret = JSVAL_NULL; + } args.rval().set(jsret); return true; } @@ -5697,14 +5677,11 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments"); cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1, arg2)); jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); + if (ret) { + jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, ret)); + } else { + jsret = JSVAL_NULL; + } args.rval().set(jsret); return true; } @@ -5720,14 +5697,11 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments"); cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1, arg2, arg3)); jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); + if (ret) { + jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, ret)); + } else { + jsret = JSVAL_NULL; + } args.rval().set(jsret); return true; } diff --git a/cocos/scripting/js-bindings/script/jsb_create_apis.js b/cocos/scripting/js-bindings/script/jsb_create_apis.js index 5fe8be19c2..b3f24c3eb8 100644 --- a/cocos/scripting/js-bindings/script/jsb_create_apis.js +++ b/cocos/scripting/js-bindings/script/jsb_create_apis.js @@ -563,19 +563,13 @@ cc.ActionInterval.prototype._ctor = function(d) { }; cc.Sequence.prototype._ctor = function(tempArray) { - var paramArray = (tempArray instanceof Array) ? tempArray : arguments; + var paramArray = (tempArray instanceof Array) ? tempArray : Array.prototype.slice.call(arguments); var last = paramArray.length - 1; if ((last >= 0) && (paramArray[last] == null)) cc.log("parameters should not be ending with null in Javascript"); if (last >= 0) { - var prev = paramArray[0]; - for (var i = 1; i < last; i++) { - if (paramArray[i]) { - prev = cc.Sequence.create(prev, paramArray[i]); - } - } - this.initWithTwoActions(prev, paramArray[last]); + this.init(paramArray); } }; @@ -588,19 +582,13 @@ cc.RepeatForever.prototype._ctor = function(action) { }; cc.Spawn.prototype._ctor = function(tempArray) { - var paramArray = (tempArray instanceof Array) ? tempArray : arguments; + var paramArray = (tempArray instanceof Array) ? tempArray : Array.prototype.slice.call(arguments); var last = paramArray.length - 1; if ((last >= 0) && (paramArray[last] == null)) cc.log("parameters should not be ending with null in Javascript"); if (last >= 0) { - var prev = paramArray[0]; - for (var i = 1; i < last; i++) { - if (paramArray[i]) { - prev = cc.Spawn.create(prev, paramArray[i]); - } - } - this.initWithTwoActions(prev, paramArray[last]); + this.init(paramArray); } }; @@ -1208,4 +1196,4 @@ cc.Menu.create = function(menuItems) { return cc.Menu._create.apply(null, items); }; -cc.TMXLayer.prototype.tileFlagsAt = cc.TMXLayer.prototype.getTileFlagsAt; \ No newline at end of file +cc.TMXLayer.prototype.tileFlagsAt = cc.TMXLayer.prototype.getTileFlagsAt; diff --git a/tools/bindings-generator b/tools/bindings-generator index b940871c1d..522eff18a6 160000 --- a/tools/bindings-generator +++ b/tools/bindings-generator @@ -1 +1 @@ -Subproject commit b940871c1dfff94c0220364539dd9d0583995719 +Subproject commit 522eff18a6c87ee8473d0d9cd05959e374a6d602 diff --git a/tools/tojs/cocos2dx.ini b/tools/tojs/cocos2dx.ini index fb01f08d91..411003cd71 100644 --- a/tools/tojs/cocos2dx.ini +++ b/tools/tojs/cocos2dx.ini @@ -87,8 +87,8 @@ skip = Node::[^setPosition$ setGLServerState description getUserObject .*UserDat Range::[*], NotificationObserver::[*], Image::[initWithString initWithImageData], - Sequence::[create init], - Spawn::[create init], + Sequence::[create], + Spawn::[create], RotateTo::[calculateAngles], GLProgram::[getProgram setUniformLocationWith(1|2|3|4)fv setUniformLocationWith(2|3|4)iv setUniformLocationWithMatrix(2|3|4)fv], GLProgramState::[setUniformVec4 setVertexAttribPointer], diff --git a/tools/tojs/cocos2dx_3d.ini b/tools/tojs/cocos2dx_3d.ini index da874c86c8..a39fbc4829 100644 --- a/tools/tojs/cocos2dx_3d.ini +++ b/tools/tojs/cocos2dx_3d.ini @@ -43,7 +43,7 @@ skip = Skeleton3D::[create], Sprite3D::[getAABB getMeshArrayByName createAsync], Mesh::[create getMeshCommand getAABB getDefaultGLProgram getMeshVertexAttribute draw setTexture getTexture], Sprite3DCache::[addSprite3DData getSpriteData], - Animation3D::[getBoneCurves], + Animation3D::[create getBoneCurves], Animate3D::[getKeyFrameUserInfo], TextureCube::[setTexParameters], Terrain::[getAABB getQuadTree create getHeightData],