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 23375d23e8..0929d7f396 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 @@ -350,22 +350,26 @@ void register_all_cocos2dx_3d_manual(JSContext *cx, JS::HandleObject global) get_or_create_js_obj(cx, global, "jsb", &ccObj); JS_GetProperty(cx, ccObj, "Sprite3D", &tmpVal); - tmpObj = tmpVal.toObjectOrNull(); + tmpObj.set(tmpVal.toObjectOrNull()); JS_DefineFunction(cx, tmpObj, "createAsync", js_cocos2dx_Sprite3D_createAsync, 4, JSPROP_READONLY | JSPROP_PERMANENT); JS_GetProperty(cx, ccObj, "Terrain", &tmpVal); - tmpObj = tmpVal.toObjectOrNull(); + tmpObj.set(tmpVal.toObjectOrNull()); JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_Terrain_create, 2, JSPROP_READONLY | JSPROP_PERMANENT); JS_GetProperty(cx, ccObj, "Bundle3D", &tmpVal); - tmpObj = tmpVal.toObjectOrNull(); + tmpObj.set(tmpVal.toObjectOrNull()); JS_DefineFunction(cx, tmpObj, "getTrianglesList", js_cocos2dx_Bundle3D_getTrianglesList, 1, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Sprite3D_prototype), "getAABB", js_cocos2dx_Sprite3D_getAABB, 0, JSPROP_READONLY | JSPROP_PERMANENT); + tmpObj.set(jsb_cocos2d_Sprite3D_prototype); + JS_DefineFunction(cx, tmpObj, "getAABB", js_cocos2dx_Sprite3D_getAABB, 0, JSPROP_READONLY | JSPROP_PERMANENT); + + tmpObj.set(jsb_cocos2d_Mesh_prototype); + JS_DefineFunction(cx, tmpObj, "getMeshVertexAttribute", js_cocos2dx_Mesh_getMeshVertexAttribute, 1, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Mesh_prototype), "getMeshVertexAttribute", js_cocos2dx_Mesh_getMeshVertexAttribute, 1, JSPROP_READONLY | JSPROP_PERMANENT); + tmpObj.set(jsb_cocos2d_TextureCube_prototype); + JS_DefineFunction(cx, tmpObj, "setTexParameters", js_cocos2dx_CCTextureCube_setTexParameters, 4, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_TextureCube_prototype), "setTexParameters", js_cocos2dx_CCTextureCube_setTexParameters, 4, JSPROP_READONLY | JSPROP_PERMANENT); - - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Terrain_prototype), "getHeightData", js_cocos2dx_Terrain_getHeightData, 0, JSPROP_READONLY | JSPROP_PERMANENT); + tmpObj.set(jsb_cocos2d_Terrain_prototype); + JS_DefineFunction(cx, tmpObj, "getHeightData", js_cocos2dx_Terrain_getHeightData, 0, JSPROP_READONLY | JSPROP_PERMANENT); } diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp index c03e1751e5..cf9a1c7728 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp @@ -101,8 +101,6 @@ static std::vector registrationList; static std::unordered_map filename_script; // port ~> socket map static std::unordered_map ports_sockets; -// name ~> globals -static std::unordered_map globals; static void cc_closesocket(int fd) { @@ -135,7 +133,8 @@ static void executeJSFunctionFromReservedSpot(JSContext *cx, JS::HandleObject ob JS_CallFunctionValue(cx, obj, func, dataVal, retval); } else { assert(!thisObj.isPrimitive()); - JS_CallFunctionValue(cx, JS::RootedObject(cx, thisObj.toObjectOrNull()), func, dataVal, retval); + JS::RootedObject jsthis(cx, thisObj.toObjectOrNull()); + JS_CallFunctionValue(cx, jsthis, func, dataVal, retval); } } @@ -251,7 +250,8 @@ void ScriptingCore::executeJSFunctionWithThisObj(JS::HandleValue thisObj, // So we have to check the availability of 'retVal'. // if (retVal) // { - JS_CallFunctionValue(_cx, JS::RootedObject(_cx, thisObj.toObjectOrNull()), callback, vp, retVal); + JS::RootedObject jsthis(_cx, thisObj.toObjectOrNull()); + JS_CallFunctionValue(_cx, jsthis, callback, vp, retVal); // } // else // { @@ -511,7 +511,8 @@ bool ScriptingCore::evalString(const char *string, jsval *outVal, const char *fi global = _global.ref().get(); JSAutoCompartment ac(cx, global); - return JS_EvaluateScript(cx, JS::RootedObject(cx, global), string, strlen(string), "ScriptingCore::evalString", 1); + JS::RootedObject jsglobal(cx, global); + return JS_EvaluateScript(cx, jsglobal, string, (unsigned)strlen(string), "ScriptingCore::evalString", 1); } void ScriptingCore::start() @@ -643,7 +644,7 @@ JSScript* ScriptingCore::getScript(const char *path) return NULL; } -void ScriptingCore::compileScript(const char *path, JSObject* global, JSContext* cx) +void ScriptingCore::compileScript(const char *path, JS::HandleObject global, JSContext* cx) { if (!path) { return; @@ -655,9 +656,6 @@ void ScriptingCore::compileScript(const char *path, JSObject* global, JSContext* cocos2d::FileUtils *futil = cocos2d::FileUtils::getInstance(); - if (global == NULL) { - global = _global.ref().get(); - } if (cx == NULL) { cx = _cx; } @@ -872,11 +870,15 @@ void ScriptingCore::removeScriptObjectByObject(Ref* pObj) js_proxy_t* jsproxy; void *ptr = (void*)pObj; nproxy = jsb_get_native_proxy(ptr); - if (nproxy) { + if (nproxy) + { JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); jsproxy = jsb_get_js_proxy(nproxy->obj); - RemoveObjectRoot(cx, &jsproxy->obj); - jsb_remove_proxy(nproxy, jsproxy); + if (jsproxy) + { + RemoveObjectRoot(cx, &jsproxy->obj); + jsb_remove_proxy(nproxy, jsproxy); + } } } @@ -890,7 +892,8 @@ bool ScriptingCore::executeScript(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc >= 1) { - JSString* str = JS::ToString(cx, JS::RootedValue(cx, args.get(0))); + JS::RootedValue jsstr(cx, args.get(0)); + JSString* str = JS::ToString(cx, jsstr); JSStringWrapper path(str); bool res = false; if (argc == 2 && args.get(1).isString()) { @@ -1043,7 +1046,8 @@ int ScriptingCore::handleActionEvent(void* data) if (eventType == kActionUpdate) { - if (isFunctionOverridedInJS(JS::RootedObject(_cx, p->obj.get()), "update", js_cocos2dx_Action_update)) + JS::RootedObject jstarget(_cx, p->obj); + if (isFunctionOverridedInJS(jstarget, "update", js_cocos2dx_Action_update)) { jsval dataVal = DOUBLE_TO_JSVAL(*((float *)actionObjectScriptData->param)); ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "update", 1, &dataVal, &retval); @@ -1070,10 +1074,12 @@ int ScriptingCore::handleNodeEvent(void* data) int ret = 0; JS::RootedValue retval(_cx); jsval dataVal = INT_TO_JSVAL(1); + + JS::RootedObject jstarget(_cx, p->obj); if (action == kNodeOnEnter) { - if (isFunctionOverridedInJS(JS::RootedObject(_cx, p->obj.get()), "onEnter", js_cocos2dx_Node_onEnter)) + if (isFunctionOverridedInJS(jstarget, "onEnter", js_cocos2dx_Node_onEnter)) { ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "onEnter", 1, &dataVal, &retval); } @@ -1081,7 +1087,7 @@ int ScriptingCore::handleNodeEvent(void* data) } else if (action == kNodeOnExit) { - if (isFunctionOverridedInJS(JS::RootedObject(_cx, p->obj.get()), "onExit", js_cocos2dx_Node_onExit)) + if (isFunctionOverridedInJS(jstarget, "onExit", js_cocos2dx_Node_onExit)) { ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "onExit", 1, &dataVal, &retval); } @@ -1089,14 +1095,14 @@ int ScriptingCore::handleNodeEvent(void* data) } else if (action == kNodeOnEnterTransitionDidFinish) { - if (isFunctionOverridedInJS(JS::RootedObject(_cx, p->obj.get()), "onEnterTransitionDidFinish", js_cocos2dx_Node_onEnterTransitionDidFinish)) + if (isFunctionOverridedInJS(jstarget, "onEnterTransitionDidFinish", js_cocos2dx_Node_onEnterTransitionDidFinish)) { ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "onEnterTransitionDidFinish", 1, &dataVal, &retval); } } else if (action == kNodeOnExitTransitionDidStart) { - if (isFunctionOverridedInJS(JS::RootedObject(_cx, p->obj.get()), "onExitTransitionDidStart", js_cocos2dx_Node_onExitTransitionDidStart)) + if (isFunctionOverridedInJS(jstarget, "onExitTransitionDidStart", js_cocos2dx_Node_onExitTransitionDidStart)) { ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "onExitTransitionDidStart", 1, &dataVal, &retval); } @@ -1104,7 +1110,7 @@ int ScriptingCore::handleNodeEvent(void* data) else if (action == kNodeOnCleanup) { cleanupSchedulesAndActions(p); - if (isFunctionOverridedInJS(JS::RootedObject(_cx, p->obj.get()), "cleanup", js_cocos2dx_Node_cleanup)) + if (isFunctionOverridedInJS(jstarget, "cleanup", js_cocos2dx_Node_cleanup)) { ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "cleanup", 1, &dataVal, &retval); } @@ -1361,7 +1367,8 @@ bool ScriptingCore::executeFunctionWithOwner(jsval owner, const char *name, cons bool hasAction; JSContext* cx = this->_cx; JS::RootedValue temp_retval(cx); - JS::RootedObject obj(cx, JS::RootedValue(cx, owner).toObjectOrNull()); + JS::RootedValue ownerval(cx, owner); + JS::RootedObject obj(cx, ownerval.toObjectOrNull()); do { @@ -1612,7 +1619,8 @@ void ScriptingCore::debugProcessInput(const std::string& str) jsval argv = STRING_TO_JSVAL(jsstr); JS::RootedValue outval(_cx); - JS_CallFunctionName(_cx, JS::RootedObject(_cx, _debugGlobal.ref()), "processInput", JS::HandleValueArray::fromMarkedLocation(1, &argv), &outval); + JS::RootedObject debugGlobal(_cx, _debugGlobal.ref()); + JS_CallFunctionName(_cx, debugGlobal, "processInput", JS::HandleValueArray::fromMarkedLocation(1, &argv), &outval); } static bool NS_ProcessNextEvent() @@ -1857,14 +1865,14 @@ void ScriptingCore::enableDebugger(unsigned int port) } } -JSObject* NewGlobalObject(JSContext* cx, bool debug) +JS::HandleObject NewGlobalObject(JSContext* cx, bool debug) { JS::CompartmentOptions options; options.setVersion(JSVERSION_LATEST); JS::RootedObject glob(cx, JS_NewGlobalObject(cx, &global_class, &shellTrustedPrincipals, JS::DontFireOnNewGlobalHook, options)); if (!glob) { - return NULL; + return JS::NullPtr(); } JSAutoCompartment ac(cx, glob); bool ok = true; @@ -1874,7 +1882,7 @@ JSObject* NewGlobalObject(JSContext* cx, bool debug) if (ok && debug) ok = JS_DefineDebuggerObject(cx, glob); if (!ok) - return NULL; + return JS::NullPtr(); JS_FireOnNewGlobalObject(cx, glob); diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.h b/cocos/scripting/js-bindings/manual/ScriptingCore.h index 5f472a8f45..f31f425a49 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.h +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.h @@ -248,7 +248,7 @@ public: * @param global @~english The js global object * @param cx @~english The js context */ - void compileScript(const char *path, JSObject* global = NULL, JSContext* cx = NULL); + void compileScript(const char *path, JS::HandleObject global, JSContext* cx = NULL); /**@~english * Run the specified js file @@ -502,11 +502,36 @@ public: void restartVM(); }; -JSObject* NewGlobalObject(JSContext* cx, bool debug = false); +JS::HandleObject NewGlobalObject(JSContext* cx, bool debug = false); bool jsb_set_reserved_slot(JSObject *obj, uint32_t idx, jsval value); bool jsb_get_reserved_slot(JSObject *obj, uint32_t idx, jsval& ret); +template +js_type_class_t *jsb_register_class(JSContext *cx, JSClass *jsClass, JS::HandleObject proto, JS::HandleObject parentProto) +{ + TypeTest t; + js_type_class_t *p = nullptr; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsClass; + if (p->proto.empty()) + { + p->proto.construct(cx); + } + p->proto.ref() = proto; + if (p->parentProto.empty()) + { + p->parentProto.construct(cx); + } + p->parentProto.ref() = parentProto ; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } + return p; +} + js_proxy_t* jsb_new_proxy(void* nativeObj, JSObject* jsObj); js_proxy_t* jsb_get_native_proxy(void* nativeObj); js_proxy_t* jsb_get_js_proxy(JSObject* jsObj); diff --git a/cocos/scripting/js-bindings/manual/chipmunk/js_bindings_chipmunk_auto_classes.cpp b/cocos/scripting/js-bindings/manual/chipmunk/js_bindings_chipmunk_auto_classes.cpp index 45226a0201..153ad73717 100644 --- a/cocos/scripting/js-bindings/manual/chipmunk/js_bindings_chipmunk_auto_classes.cpp +++ b/cocos/scripting/js-bindings/manual/chipmunk/js_bindings_chipmunk_auto_classes.cpp @@ -86,7 +86,8 @@ bool JSB_cpConstraint_getA(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpConstraintGetA((cpConstraint*)arg0 ); - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpBody_object), JSB_cpBody_class, "cpBody" ); + JS::RootedObject bodyProto(cx, JSB_cpBody_object); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, bodyProto, JSB_cpBody_class, "cpBody" ); args.rval().set(ret_jsval); return true; @@ -103,8 +104,9 @@ bool JSB_cpConstraint_getB(JSContext *cx, uint32_t argc, jsval *vp) { cpBody* ret_val = nullptr; ret_val = cpConstraintGetB((cpConstraint*)arg0 ); - - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpBody_object), JSB_cpBody_class, "cpBody" ); + + JS::RootedObject bodyProto(cx, JSB_cpBody_object); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, bodyProto, JSB_cpBody_class, "cpBody" ); args.rval().set(ret_jsval); return true; @@ -182,7 +184,8 @@ bool JSB_cpConstraint_getSpace(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpConstraintGetSpace((cpConstraint*)arg0 ); - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpSpace_object), JSB_cpSpace_class, "cpSpace" ); + JS::RootedObject spaceProto(cx, JSB_cpSpace_object); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, spaceProto, JSB_cpSpace_class, "cpSpace" ); args.rval().set(ret_jsval); return true; @@ -281,9 +284,8 @@ void JSB_cpConstraint_createClass(JSContext *cx, JS::HandleObject globalObj, con JS_FS_END }; - JSB_cpConstraint_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpBase_object), JSB_cpConstraint_class, JSB_cpConstraint_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); + JS::RootedObject baseProto(cx, JSB_cpBase_object); + JSB_cpConstraint_object = JS_InitClass(cx, globalObj, baseProto, JSB_cpConstraint_class, JSB_cpConstraint_constructor,0,properties,funcs,NULL,st_funcs); } /* @@ -298,7 +300,8 @@ JSObject* JSB_cpGrooveJoint_object = NULL; bool JSB_cpGrooveJoint_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==5, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpGrooveJoint_class, JS::RootedObject(cx, JSB_cpGrooveJoint_object), JS::NullPtr()); + JS::RootedObject grooveJointProto(cx, JSB_cpGrooveJoint_object); + JS::RootedObject jsobj(cx, JS_NewObject(cx, JSB_cpGrooveJoint_class, grooveJointProto, JS::NullPtr())); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0 = nullptr; cpBody* arg1 = nullptr; cpVect arg2; cpVect arg3; cpVect arg4; @@ -475,9 +478,8 @@ void JSB_cpGrooveJoint_createClass(JSContext *cx, JS::HandleObject globalObj, co JS_FS_END }; - JSB_cpGrooveJoint_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpGrooveJoint_class, JSB_cpGrooveJoint_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); + JS::RootedObject constraintProto(cx, JSB_cpConstraint_object); + JSB_cpGrooveJoint_object = JS_InitClass(cx, globalObj, constraintProto, JSB_cpGrooveJoint_class, JSB_cpGrooveJoint_constructor,0,properties,funcs,NULL,st_funcs); } /* @@ -492,7 +494,8 @@ JSObject* JSB_cpSimpleMotor_object = NULL; bool JSB_cpSimpleMotor_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==3, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpSimpleMotor_class, JS::RootedObject(cx, JSB_cpSimpleMotor_object), JS::NullPtr()); + JS::RootedObject simpleMotorProto(cx, JSB_cpSimpleMotor_object); + JS::RootedObject jsobj(cx, JS_NewObject(cx, JSB_cpSimpleMotor_class, simpleMotorProto, JS::NullPtr())); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0 = nullptr; cpBody* arg1 = nullptr; double arg2 = 0; @@ -586,9 +589,8 @@ void JSB_cpSimpleMotor_createClass(JSContext *cx, JS::HandleObject globalObj, co JS_FS_END }; - JSB_cpSimpleMotor_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpSimpleMotor_class, JSB_cpSimpleMotor_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); + JS::RootedObject constraintProto(cx, JSB_cpConstraint_object); + JSB_cpSimpleMotor_object = JS_InitClass(cx, globalObj, constraintProto, JSB_cpSimpleMotor_class, JSB_cpSimpleMotor_constructor,0,properties,funcs,NULL,st_funcs); } /* @@ -603,7 +605,8 @@ JSObject* JSB_cpPivotJoint_object = NULL; bool JSB_cpPivotJoint_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==4 || argc==3, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpPivotJoint_class, JS::RootedObject(cx, JSB_cpPivotJoint_object), JS::NullPtr()); + JS::RootedObject pivotJointProto(cx, JSB_cpPivotJoint_object); + JS::RootedObject jsobj(cx, JS_NewObject(cx, JSB_cpPivotJoint_class, pivotJointProto, JS::NullPtr())); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0 = nullptr; cpBody* arg1 = nullptr; cpVect arg2; cpVect arg3; void *ret_val = nullptr; @@ -743,10 +746,9 @@ void JSB_cpPivotJoint_createClass(JSContext *cx, JS::HandleObject globalObj, con static JSFunctionSpec st_funcs[] = { JS_FS_END }; - - JSB_cpPivotJoint_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpPivotJoint_class, JSB_cpPivotJoint_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + JS::RootedObject constraintProto(cx, JSB_cpConstraint_object); + JSB_cpPivotJoint_object = JS_InitClass(cx, globalObj, constraintProto, JSB_cpPivotJoint_class, JSB_cpPivotJoint_constructor,0,properties,funcs,NULL,st_funcs); } /* @@ -761,7 +763,8 @@ JSObject* JSB_cpPinJoint_object = NULL; bool JSB_cpPinJoint_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==4, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpPinJoint_class, JS::RootedObject(cx, JSB_cpPinJoint_object), JS::NullPtr()); + JS::RootedObject pinJointProto(cx, JSB_cpPinJoint_object); + JS::RootedObject jsobj(cx, JS_NewObject(cx, JSB_cpPinJoint_class, pinJointProto, JS::NullPtr())); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0 = nullptr; cpBody* arg1 = nullptr; cpVect arg2; cpVect arg3; @@ -933,10 +936,9 @@ void JSB_cpPinJoint_createClass(JSContext *cx, JS::HandleObject globalObj, const static JSFunctionSpec st_funcs[] = { JS_FS_END }; - - JSB_cpPinJoint_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpPinJoint_class, JSB_cpPinJoint_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + JS::RootedObject constraintProto(cx, JSB_cpConstraint_object); + JSB_cpPinJoint_object = JS_InitClass(cx, globalObj, constraintProto, JSB_cpPinJoint_class, JSB_cpPinJoint_constructor,0,properties,funcs,NULL,st_funcs); } /* @@ -951,7 +953,8 @@ JSObject* JSB_cpSlideJoint_object = NULL; bool JSB_cpSlideJoint_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==6, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpSlideJoint_class, JS::RootedObject(cx, JSB_cpSlideJoint_object), JS::NullPtr()); + JS::RootedObject slideJointProto(cx, JSB_cpSlideJoint_object); + JS::RootedObject jsobj(cx, JS_NewObject(cx, JSB_cpSlideJoint_class, slideJointProto, JS::NullPtr())); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0 = nullptr; cpBody* arg1 = nullptr; cpVect arg2; cpVect arg3; double arg4 = 0; double arg5 = 0; @@ -1161,10 +1164,9 @@ void JSB_cpSlideJoint_createClass(JSContext *cx, JS::HandleObject globalObj, con static JSFunctionSpec st_funcs[] = { JS_FS_END }; - - JSB_cpSlideJoint_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpSlideJoint_class, JSB_cpSlideJoint_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + JS::RootedObject constraintProto(cx, JSB_cpConstraint_object); + JSB_cpSlideJoint_object = JS_InitClass(cx, globalObj, constraintProto, JSB_cpSlideJoint_class, JSB_cpSlideJoint_constructor,0,properties,funcs,NULL,st_funcs); } /* @@ -1179,7 +1181,8 @@ JSObject* JSB_cpGearJoint_object = NULL; bool JSB_cpGearJoint_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==4, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpGearJoint_class, JS::RootedObject(cx, JSB_cpGearJoint_object), JS::NullPtr()); + JS::RootedObject gearJointProto(cx, JSB_cpGearJoint_object); + JS::RootedObject jsobj(cx, JS_NewObject(cx, JSB_cpGearJoint_class, gearJointProto, JS::NullPtr())); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0 = nullptr; cpBody* arg1 = nullptr; double arg2 = 0; double arg3 = 0; @@ -1309,10 +1312,9 @@ void JSB_cpGearJoint_createClass(JSContext *cx, JS::HandleObject globalObj, cons static JSFunctionSpec st_funcs[] = { JS_FS_END }; - - JSB_cpGearJoint_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpGearJoint_class, JSB_cpGearJoint_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + JS::RootedObject constraintProto(cx, JSB_cpConstraint_object); + JSB_cpGearJoint_object = JS_InitClass(cx, globalObj, constraintProto, JSB_cpGearJoint_class, JSB_cpGearJoint_constructor,0,properties,funcs,NULL,st_funcs); } /* @@ -1327,7 +1329,8 @@ JSObject* JSB_cpDampedRotarySpring_object = NULL; bool JSB_cpDampedRotarySpring_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==5, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpDampedRotarySpring_class, JS::RootedObject(cx, JSB_cpDampedRotarySpring_object), JS::NullPtr()); + JS::RootedObject dampedRotarySringProto(cx, JSB_cpDampedRotarySpring_object); + JS::RootedObject jsobj(cx, JS_NewObject(cx, JSB_cpDampedRotarySpring_class, dampedRotarySringProto, JS::NullPtr())); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0 = nullptr; cpBody* arg1 = nullptr; double arg2 = 0; double arg3 = 0; double arg4 = 0; @@ -1494,10 +1497,9 @@ void JSB_cpDampedRotarySpring_createClass(JSContext *cx, JS::HandleObject global static JSFunctionSpec st_funcs[] = { JS_FS_END }; - - JSB_cpDampedRotarySpring_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpDampedRotarySpring_class, JSB_cpDampedRotarySpring_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + JS::RootedObject constraintProto(cx, JSB_cpConstraint_object); + JSB_cpDampedRotarySpring_object = JS_InitClass(cx, globalObj, constraintProto, JSB_cpDampedRotarySpring_class, JSB_cpDampedRotarySpring_constructor,0,properties,funcs,NULL,st_funcs); } /* @@ -1512,7 +1514,8 @@ JSObject* JSB_cpDampedSpring_object = NULL; bool JSB_cpDampedSpring_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==7, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpDampedSpring_class, JS::RootedObject(cx, JSB_cpDampedSpring_object), JS::NullPtr()); + JS::RootedObject dampedSpringProto(cx, JSB_cpDampedSpring_object); + JS::RootedObject jsobj(cx, JS_NewObject(cx, JSB_cpDampedSpring_class, dampedSpringProto, JS::NullPtr())); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0 = nullptr; cpBody* arg1 = nullptr; cpVect arg2; cpVect arg3; double arg4 = 0; double arg5 = 0; double arg6 = 0; @@ -1759,10 +1762,9 @@ void JSB_cpDampedSpring_createClass(JSContext *cx, JS::HandleObject globalObj, c static JSFunctionSpec st_funcs[] = { JS_FS_END }; - - JSB_cpDampedSpring_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpDampedSpring_class, JSB_cpDampedSpring_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + JS::RootedObject constraintProto(cx, JSB_cpConstraint_object); + JSB_cpDampedSpring_object = JS_InitClass(cx, globalObj, constraintProto, JSB_cpDampedSpring_class, JSB_cpDampedSpring_constructor,0,properties,funcs,NULL,st_funcs); } /* @@ -1777,7 +1779,8 @@ JSObject* JSB_cpRatchetJoint_object = NULL; bool JSB_cpRatchetJoint_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==4, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpRatchetJoint_class, JS::RootedObject(cx, JSB_cpRatchetJoint_object), JS::NullPtr()); + JS::RootedObject ratchetJointProto(cx, JSB_cpRatchetJoint_object); + JS::RootedObject jsobj(cx, JS_NewObject(cx, JSB_cpRatchetJoint_class, ratchetJointProto, JS::NullPtr())); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0 = nullptr; cpBody* arg1 = nullptr; double arg2 = 0; double arg3 = 0; @@ -1943,10 +1946,9 @@ void JSB_cpRatchetJoint_createClass(JSContext *cx, JS::HandleObject globalObj, c static JSFunctionSpec st_funcs[] = { JS_FS_END }; - - JSB_cpRatchetJoint_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpRatchetJoint_class, JSB_cpRatchetJoint_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + JS::RootedObject constraintProto(cx, JSB_cpConstraint_object); + JSB_cpRatchetJoint_object = JS_InitClass(cx, globalObj, constraintProto, JSB_cpRatchetJoint_class, JSB_cpRatchetJoint_constructor,0,properties,funcs,NULL,st_funcs); } /* @@ -1961,7 +1963,8 @@ JSObject* JSB_cpRotaryLimitJoint_object = NULL; bool JSB_cpRotaryLimitJoint_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==4, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpRotaryLimitJoint_class, JS::RootedObject(cx, JSB_cpRotaryLimitJoint_object), JS::NullPtr()); + JS::RootedObject rotaryLimitJointProto(cx, JSB_cpRotaryLimitJoint_object); + JS::RootedObject jsobj(cx, JS_NewObject(cx, JSB_cpRotaryLimitJoint_class, rotaryLimitJointProto, JS::NullPtr())); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0 = nullptr; cpBody* arg1 = nullptr; double arg2 = 0; double arg3 = 0; @@ -2091,10 +2094,9 @@ void JSB_cpRotaryLimitJoint_createClass(JSContext *cx, JS::HandleObject globalOb static JSFunctionSpec st_funcs[] = { JS_FS_END }; - - JSB_cpRotaryLimitJoint_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpConstraint_object), JSB_cpRotaryLimitJoint_class, JSB_cpRotaryLimitJoint_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + JS::RootedObject constraintProto(cx, JSB_cpConstraint_object); + JSB_cpRotaryLimitJoint_object = JS_InitClass(cx, globalObj, constraintProto, JSB_cpRotaryLimitJoint_class, JSB_cpRotaryLimitJoint_constructor,0,properties,funcs,NULL,st_funcs); } /* @@ -2501,9 +2503,8 @@ void JSB_cpArbiter_createClass(JSContext *cx, JS::HandleObject globalObj, const JS_FS_END }; - JSB_cpArbiter_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpBase_object), JSB_cpArbiter_class, JSB_cpArbiter_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); + JS::RootedObject baseProto(cx, JSB_cpBase_object); + JSB_cpArbiter_object = JS_InitClass(cx, globalObj, baseProto, JSB_cpArbiter_class, JSB_cpArbiter_constructor,0,properties,funcs,NULL,st_funcs); } /* @@ -2519,7 +2520,8 @@ bool JSB_cpSpace_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==0, cx, false, "Invalid number of arguments"); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JSObject *jsobj = JS_NewObject(cx, JSB_cpSpace_class, JS::RootedObject(cx, JSB_cpSpace_object), JS::NullPtr()); + JS::RootedObject spaceProto(cx, JSB_cpSpace_object); + JS::RootedObject jsobj(cx, JS_NewObject(cx, JSB_cpSpace_class, spaceProto, JS::NullPtr())); void* ret_val = cpSpaceNew( ); jsb_set_jsobject_for_proxy(jsobj, ret_val); @@ -2786,8 +2788,9 @@ bool JSB_cpSpace_getStaticBody(JSContext *cx, uint32_t argc, jsval *vp) { cpBody* ret_val = nullptr; ret_val = cpSpaceGetStaticBody((cpSpace*)arg0 ); - - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpBody_object), JSB_cpBody_class, "cpBody" ); + + JS::RootedObject bodyProto(cx, JSB_cpBody_object); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, bodyProto, JSB_cpBody_class, "cpBody" ); args.rval().set(ret_jsval); return true; @@ -2804,8 +2807,9 @@ bool JSB_cpSpace_init(JSContext *cx, uint32_t argc, jsval *vp) { cpSpace* ret_val = nullptr; ret_val = cpSpaceInit((cpSpace*)arg0 ); - - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpSpace_object), JSB_cpSpace_class, "cpSpace" ); + + JS::RootedObject spaceProto(cx, JSB_cpSpace_object); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, spaceProto, JSB_cpSpace_class, "cpSpace" ); args.rval().set(ret_jsval); return true; @@ -2846,7 +2850,8 @@ bool JSB_cpSpace_pointQueryFirst(JSContext *cx, uint32_t argc, jsval *vp) { ret_val = cpSpacePointQueryFirst((cpSpace*)arg0 , (cpVect)arg1 , (cpLayers)arg2 , (cpGroup)arg3 ); if(ret_val) { - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpShape_object), JSB_cpShape_class, "cpShape" ); + JS::RootedObject shapeProto(cx, JSB_cpShape_object); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, shapeProto, JSB_cpShape_class, "cpShape" ); args.rval().set(ret_jsval); } else { args.rval().set(JSVAL_NULL); @@ -3188,10 +3193,9 @@ void JSB_cpSpace_createClass(JSContext *cx, JS::HandleObject globalObj, const ch static JSFunctionSpec st_funcs[] = { JS_FS_END }; - - JSB_cpSpace_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpBase_object), JSB_cpSpace_class, JSB_cpSpace_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + JS::RootedObject baseProto(cx, JSB_cpBase_object); + JSB_cpSpace_object = JS_InitClass(cx, globalObj, baseProto, JSB_cpSpace_class, JSB_cpSpace_constructor,0,properties,funcs,NULL,st_funcs); } /* @@ -3445,8 +3449,9 @@ bool JSB_cpBody_getSpace(JSContext *cx, uint32_t argc, jsval *vp) { cpSpace* ret_val = nullptr; ret_val = cpBodyGetSpace((cpBody*)arg0 ); - - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpSpace_object), JSB_cpSpace_class, "cpSpace" ); + + JS::RootedObject spaceProto(cx, JSB_cpSpace_object); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, spaceProto, JSB_cpSpace_class, "cpSpace" ); args.rval().set(ret_jsval); return true; @@ -3563,8 +3568,9 @@ bool JSB_cpBody_init(JSContext *cx, uint32_t argc, jsval *vp) { cpBody* ret_val = nullptr; ret_val = cpBodyInit((cpBody*)arg0 , (cpFloat)arg1 , (cpFloat)arg2 ); - - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpBody_object), JSB_cpBody_class, "cpBody" ); + + JS::RootedObject bodyProto(cx, JSB_cpBody_object); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, bodyProto, JSB_cpBody_class, "cpBody" ); args.rval().set(ret_jsval); return true; @@ -3581,8 +3587,9 @@ bool JSB_cpBody_initStatic(JSContext *cx, uint32_t argc, jsval *vp) { cpBody* ret_val = nullptr; ret_val = cpBodyInitStatic((cpBody*)arg0 ); - - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpBody_object), JSB_cpBody_class, "cpBody" ); + + JS::RootedObject bodyProto(cx, JSB_cpBody_object); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, bodyProto, JSB_cpBody_class, "cpBody" ); args.rval().set(ret_jsval); return true; @@ -4081,10 +4088,9 @@ void JSB_cpBody_createClass(JSContext *cx, JS::HandleObject globalObj, const cha static JSFunctionSpec st_funcs[] = { JS_FS_END }; - - JSB_cpBody_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpBase_object), JSB_cpBody_class, JSB_cpBody_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + JS::RootedObject baseProto(cx, JSB_cpBase_object); + JSB_cpBody_object = JS_InitClass(cx, globalObj, baseProto, JSB_cpBody_class, JSB_cpBody_constructor,0,properties,funcs,NULL,st_funcs); } /* @@ -4181,8 +4187,9 @@ bool JSB_cpShape_getBody(JSContext *cx, uint32_t argc, jsval *vp) { cpBody* ret_val = nullptr; ret_val = cpShapeGetBody((cpShape*)arg0 ); - - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpBody_object), JSB_cpBody_class, "cpBody" ); + + JS::RootedObject bodyProto(cx, JSB_cpBody_object); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, bodyProto, JSB_cpBody_class, "cpBody" ); args.rval().set(ret_jsval); return true; @@ -4295,8 +4302,9 @@ bool JSB_cpShape_getSpace(JSContext *cx, uint32_t argc, jsval *vp) { cpSpace* ret_val = nullptr; ret_val = cpShapeGetSpace((cpShape*)arg0 ); - - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpSpace_object), JSB_cpSpace_class, "cpSpace" ); + + JS::RootedObject spaceProto(cx, JSB_cpSpace_object); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, spaceProto, JSB_cpSpace_class, "cpSpace" ); args.rval().set(ret_jsval); return true; @@ -4545,7 +4553,8 @@ bool JSB_cpShape_nearestPointQuery(JSContext *cx, uint32_t argc, jsval *vp) cpNearestPointQueryInfo* info = new cpNearestPointQueryInfo(); cpShapeNearestPointQuery(shape, p, info); - JSObject *jsobj = JS_NewObject(cx, JSB_cpNearestPointQueryInfo_class, JS::RootedObject(cx, JSB_cpNearestPointQueryInfo_object), JS::NullPtr()); + JS::RootedObject nearestPointQueryInfoProto(cx, JSB_cpNearestPointQueryInfo_object); + JS::RootedObject jsobj(cx, JS_NewObject(cx, JSB_cpNearestPointQueryInfo_class, nearestPointQueryInfoProto, JS::NullPtr())); jsb_set_jsobject_for_proxy(jsobj, info); jsb_set_c_proxy_for_jsobject(jsobj, info, JSB_C_FLAG_CALL_FREE); args.rval().set(OBJECT_TO_JSVAL(jsobj)); @@ -4570,7 +4579,8 @@ bool JSB_cpShape_segmentQuery(JSContext *cx, uint32_t argc, jsval *vp) cpSegmentQueryInfo* info = new cpSegmentQueryInfo(); if(cpShapeSegmentQuery(shape, a, b, info)) { - JSObject* jsobj = JS_NewObject(cx, JSB_cpSegmentQueryInfo_class, JS::RootedObject(cx, JSB_cpSegmentQueryInfo_object), JS::NullPtr()); + JS::RootedObject segmentQueryInfoProto(cx, JSB_cpSegmentQueryInfo_object); + JSObject* jsobj = JS_NewObject(cx, JSB_cpSegmentQueryInfo_class, segmentQueryInfoProto, JS::NullPtr()); jsb_set_jsobject_for_proxy(jsobj, info); jsb_set_c_proxy_for_jsobject(jsobj, info, JSB_C_FLAG_CALL_FREE); args.rval().set(OBJECT_TO_JSVAL(jsobj)); @@ -4698,10 +4708,9 @@ void JSB_cpShape_createClass(JSContext *cx, JS::HandleObject globalObj, const ch static JSFunctionSpec st_funcs[] = { JS_FS_END }; - - JSB_cpShape_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpBase_object), JSB_cpShape_class, JSB_cpShape_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + JS::RootedObject baseProto(cx, JSB_cpBase_object); + JSB_cpShape_object = JS_InitClass(cx, globalObj, baseProto, JSB_cpShape_class, JSB_cpShape_constructor,0,properties,funcs,NULL,st_funcs); } /* @@ -4716,7 +4725,8 @@ JSObject* JSB_cpCircleShape_object = NULL; bool JSB_cpCircleShape_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==3, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpCircleShape_class, JS::RootedObject(cx, JSB_cpCircleShape_object), JS::NullPtr()); + JS::RootedObject circleShapeProto(cx, JSB_cpCircleShape_object); + JS::RootedObject jsobj(cx, JS_NewObject(cx, JSB_cpCircleShape_class, circleShapeProto, JS::NullPtr())); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0 = nullptr; double arg1 = 0; cpVect arg2; @@ -4808,10 +4818,9 @@ void JSB_cpCircleShape_createClass(JSContext *cx, JS::HandleObject globalObj, co static JSFunctionSpec st_funcs[] = { JS_FS_END }; - - JSB_cpCircleShape_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpShape_object), JSB_cpCircleShape_class, JSB_cpCircleShape_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + JS::RootedObject shapeProto(cx, JSB_cpShape_object); + JSB_cpCircleShape_object = JS_InitClass(cx, globalObj, shapeProto, JSB_cpCircleShape_class, JSB_cpCircleShape_constructor,0,properties,funcs,NULL,st_funcs); } /* @@ -4826,7 +4835,8 @@ JSObject* JSB_cpSegmentShape_object = NULL; bool JSB_cpSegmentShape_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==4, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpSegmentShape_class, JS::RootedObject(cx, JSB_cpSegmentShape_object), JS::NullPtr()); + JS::RootedObject segmentShapeProto(cx, JSB_cpSegmentShape_object); + JS::RootedObject jsobj(cx, JS_NewObject(cx, JSB_cpSegmentShape_class, segmentShapeProto, JS::NullPtr())); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* arg0 = nullptr; cpVect arg1; cpVect arg2; double arg3 = 0; @@ -5002,10 +5012,9 @@ void JSB_cpSegmentShape_createClass(JSContext *cx, JS::HandleObject globalObj, c static JSFunctionSpec st_funcs[] = { JS_FS_END }; - - JSB_cpSegmentShape_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpShape_object), JSB_cpSegmentShape_class, JSB_cpSegmentShape_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + JS::RootedObject shapeProto(cx, JSB_cpShape_object); + JSB_cpSegmentShape_object = JS_InitClass(cx, globalObj, shapeProto, JSB_cpSegmentShape_class, JSB_cpSegmentShape_constructor,0,properties,funcs,NULL,st_funcs); } /* @@ -5109,10 +5118,11 @@ static bool js_get_cpPolyShape_planes(JSContext *cx, uint32_t argc, jsval *vp) cpSplittingPlane *plane = planes + i; JS::RootedValue elem(cx); - JSObject *jsobj = jsb_get_jsobject_for_proxy(plane); + JS::RootedObject jsobj(cx, jsb_get_jsobject_for_proxy(plane)); if(!jsobj) { - jsobj = JS_NewObject(cx, JSB_cpSplittingPlane_class, JS::RootedObject(cx, JSB_cpSplittingPlane_object), JS::NullPtr()); + JS::RootedObject splittingPlaneProto(cx, JSB_cpSplittingPlane_object); + jsobj = JS_NewObject(cx, JSB_cpSplittingPlane_class, splittingPlaneProto, JS::NullPtr()); jsb_set_jsobject_for_proxy(jsobj, plane); jsb_set_c_proxy_for_jsobject(jsobj, plane, JSB_C_FLAG_DO_NOT_CALL_FREE); } @@ -5152,10 +5162,9 @@ void JSB_cpPolyShape_createClass(JSContext *cx, JS::HandleObject globalObj, cons static JSFunctionSpec st_funcs[] = { JS_FS_END }; - - JSB_cpPolyShape_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, JSB_cpShape_object), JSB_cpPolyShape_class, JSB_cpPolyShape_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + JS::RootedObject shapeProto(cx, JSB_cpShape_object); + JSB_cpPolyShape_object = JS_InitClass(cx, globalObj, shapeProto, JSB_cpPolyShape_class, JSB_cpPolyShape_constructor,0,properties,funcs,NULL,st_funcs); } // SplittingPlane @@ -5293,7 +5302,8 @@ bool js_get_cpSegmentQueryInfo_shape(JSContext *cx, uint32_t argc, jsval *vp) cpShape* shape = info->shape; if(shape){ - JSObject *jsobj = JS_NewObject(cx, JSB_cpShape_class, JS::RootedObject(cx, JSB_cpShape_object), JS::NullPtr()); + JS::RootedObject shapeProto(cx, JSB_cpShape_object); + JS::RootedObject jsobj(cx, JS_NewObject(cx, JSB_cpShape_class, shapeProto, JS::NullPtr())); //jsb_set_jsobject_for_proxy(jsobj, shape); jsb_set_c_proxy_for_jsobject(jsobj, shape, JSB_C_FLAG_DO_NOT_CALL_FREE); args.rval().set(OBJECT_TO_JSVAL(jsobj)); @@ -5387,8 +5397,6 @@ void JSB_cpSegmentQueryInfo_createClass(JSContext *cx, JS::HandleObject globalOb }; JSB_cpSegmentQueryInfo_object = JS_InitClass(cx, globalObj, JS::NullPtr(), JSB_cpSegmentQueryInfo_class, NULL,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } bool js_get_cpNearestPointQueryInfo_shape(JSContext *cx, uint32_t argc, jsval *vp) @@ -5399,7 +5407,8 @@ bool js_get_cpNearestPointQueryInfo_shape(JSContext *cx, uint32_t argc, jsval *v cpShape* shape = info->shape; if(shape){ - JSObject *jsobj = JS_NewObject(cx, JSB_cpShape_class, JS::RootedObject(cx, JSB_cpShape_object), JS::NullPtr()); + JS::RootedObject shapeProto(cx, JSB_cpShape_object); + JS::RootedObject jsobj(cx, JS_NewObject(cx, JSB_cpShape_class, shapeProto, JS::NullPtr())); //jsb_set_jsobject_for_proxy(jsobj, shape); jsb_set_c_proxy_for_jsobject(jsobj, shape, JSB_C_FLAG_DO_NOT_CALL_FREE); args.rval().set(OBJECT_TO_JSVAL(jsobj)); diff --git a/cocos/scripting/js-bindings/manual/chipmunk/js_bindings_chipmunk_manual.cpp b/cocos/scripting/js-bindings/manual/chipmunk/js_bindings_chipmunk_manual.cpp index 80bc51c49c..1780684783 100644 --- a/cocos/scripting/js-bindings/manual/chipmunk/js_bindings_chipmunk_manual.cpp +++ b/cocos/scripting/js-bindings/manual/chipmunk/js_bindings_chipmunk_manual.cpp @@ -48,7 +48,9 @@ static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { p = typeMapIter->second; CCASSERT(p, "The value is null."); - JSObject *_tmp = JS_NewObject(cx, p->jsclass, JS::RootedObject(cx, p->proto), JS::RootedObject(cx, p->parentProto)); + JS::RootedObject proto(cx, p->proto.ref()); + JS::RootedObject parentProto(cx, p->parentProto.ref()); + JS::RootedObject _tmp(cx, JS_NewObject(cx, p->jsclass, proto, parentProto)); js_proxy_t *pp = jsb_new_proxy(cobj, _tmp); JS::AddObjectRoot(cx, &pp->obj); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -101,7 +103,8 @@ bool JSPROXY_CCPhysicsSprite_getCPBody(JSContext *cx, uint32_t argc, jsval *vp) cpBody* ret_val = nullptr; ret_val = real->getCPBody(); - jsval ret_jsval = c_class_to_jsval( cx, ret_val, JS::RootedObject(cx, JSB_cpBody_object), JSB_cpBody_class, "cpBody" ); + JS::RootedObject bodyProto(cx, JSB_cpBody_object); + jsval ret_jsval = c_class_to_jsval( cx, ret_val, bodyProto, JSB_cpBody_class, "cpBody" ); args.rval().set(ret_jsval); return true; @@ -200,7 +203,9 @@ bool JSB_CCPhysicsDebugNode_debugNodeForCPSpace__static(JSContext *cx, uint32_t typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto)); + JS::RootedObject proto(cx, typeClass->proto.ref()); + JS::RootedObject parentProto(cx, typeClass->parentProto.ref()); + JSObject *obj = JS_NewObject(cx, typeClass->jsclass, proto, parentProto); jsret = OBJECT_TO_JSVAL(obj); js_proxy_t *p = jsb_new_proxy(ret, obj); JS::AddNamedObjectRoot(cx, &p->obj, "CCDebugNode"); @@ -267,8 +272,9 @@ bool JSB_CCPhysicsDebugNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - //JS::RootedObject obj(cx, JS_NewObjectForConstructor(cx, typeClass->jsclass, args)); - JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto))); + JS::RootedObject proto(cx, typeClass->proto.ref()); + JS::RootedObject parentProto(cx, typeClass->parentProto.ref()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parentProto)); args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); @@ -313,21 +319,12 @@ void JSB_CCPhysicsDebugNode_createClass(JSContext *cx, JS::HandleObject globalOb CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - - JSB_CCPhysicsDebugNode_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, typeClass->proto), JSB_CCPhysicsDebugNode_class, JSB_CCPhysicsDebugNode_constructor, 0,properties,funcs,NULL,st_funcs); - - TypeTest t; - js_type_class_t *p; - typeName = t.s_name(); - if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) - { - p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = JSB_CCPhysicsDebugNode_class; - p->proto = JSB_CCPhysicsDebugNode_object; - p->parentProto = typeClass->proto; - _js_global_type_map.insert(std::make_pair(typeName, p)); - } + JS::RootedObject parentProto(cx, typeClass->proto.ref()); + JSB_CCPhysicsDebugNode_object = JS_InitClass(cx, globalObj, parentProto, JSB_CCPhysicsDebugNode_class, JSB_CCPhysicsDebugNode_constructor, 0,properties,funcs,NULL,st_funcs); + + JS::RootedObject proto(cx, JSB_CCPhysicsDebugNode_object); + jsb_register_class(cx, JSB_CCPhysicsDebugNode_class, proto, parentProto); } // Arguments: NSString*, CGRect @@ -356,7 +353,9 @@ bool JSPROXY_CCPhysicsSprite_spriteWithFile_rect__static(JSContext *cx, uint32_t typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto)); + JS::RootedObject proto(cx, typeClass->proto.ref()); + JS::RootedObject parentProto(cx, typeClass->parentProto.ref()); + JSObject *obj = JS_NewObject(cx, typeClass->jsclass, proto, parentProto); jsret = OBJECT_TO_JSVAL(obj); js_proxy_t *p = jsb_new_proxy(ret, obj); JS::AddNamedObjectRoot(cx, &p->obj, "CCPhysicsSprite"); @@ -384,7 +383,9 @@ bool JSPROXY_CCPhysicsSprite_spriteWithFile_rect__static(JSContext *cx, uint32_t 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, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto)); + JS::RootedObject proto(cx, typeClass->proto.ref()); + JS::RootedObject parentProto(cx, typeClass->parentProto.ref()); + JSObject *obj = JS_NewObject(cx, typeClass->jsclass, proto, parentProto); jsret = OBJECT_TO_JSVAL(obj); js_proxy_t *p = jsb_new_proxy(ret, obj); JS::AddNamedObjectRoot(cx, &p->obj, "CCPhysicsSprite"); @@ -425,7 +426,9 @@ bool JSPROXY_CCPhysicsSprite_spriteWithSpriteFrame__static(JSContext *cx, uint32 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, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto)); + JS::RootedObject proto(cx, typeClass->proto.ref()); + JS::RootedObject parentProto(cx, typeClass->parentProto.ref()); + JSObject *obj = JS_NewObject(cx, typeClass->jsclass, proto, parentProto); jsret = OBJECT_TO_JSVAL(obj); js_proxy_t *p = jsb_new_proxy(ret, obj); JS::AddNamedObjectRoot(cx, &p->obj, "CCPhysicsSprite"); @@ -459,7 +462,9 @@ bool JSPROXY_CCPhysicsSprite_spriteWithSpriteFrameName__static(JSContext *cx, ui 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, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto)); + JS::RootedObject proto(cx, typeClass->proto.ref()); + JS::RootedObject parentProto(cx, typeClass->parentProto.ref()); + JSObject *obj = JS_NewObject(cx, typeClass->jsclass, proto, parentProto); jsret = OBJECT_TO_JSVAL(obj); js_proxy_t *p = jsb_new_proxy(ret, obj); JS::AddNamedObjectRoot(cx, &p->obj, "CCPhysicsSprite"); @@ -490,8 +495,9 @@ bool JSPROXY_CCPhysicsSprite_constructor(JSContext *cx, uint32_t argc, jsval *vp CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - //JS::RootedObject obj(cx, JS_NewObjectForConstructor(cx, typeClass->jsclass, args)); - JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto))); + JS::RootedObject proto(cx, typeClass->proto.ref()); + JS::RootedObject parentProto(cx, typeClass->parentProto.ref()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parentProto)); args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); @@ -558,20 +564,12 @@ void JSPROXY_CCPhysicsSprite_createClass(JSContext *cx, JS::HandleObject globalO CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - - JSPROXY_CCPhysicsSprite_object = JS_InitClass(cx, globalObj, JS::RootedObject(cx, typeClass->proto), JSPROXY_CCPhysicsSprite_class,/* dummy_constructor*/JSPROXY_CCPhysicsSprite_constructor, 0,properties,funcs,NULL,st_funcs); - - TypeTest t; - js_type_class_t *p; - typeName = t.s_name(); - if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) - { - p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = JSPROXY_CCPhysicsSprite_class; - p->proto = JSPROXY_CCPhysicsSprite_object; - p->parentProto = typeClass->proto; - _js_global_type_map.insert(std::make_pair(typeName, p)); - } + + JS::RootedObject parentProto(cx, typeClass->proto.ref()); + JSPROXY_CCPhysicsSprite_object = JS_InitClass(cx, globalObj, parentProto, JSPROXY_CCPhysicsSprite_class, JSPROXY_CCPhysicsSprite_constructor, 0,properties,funcs,NULL,st_funcs); + + JS::RootedObject proto(cx, JSPROXY_CCPhysicsSprite_object); + jsb_register_class(cx, JSPROXY_CCPhysicsSprite_class, proto, parentProto); anonEvaluate(cx, globalObj, "(function () { cc.PhysicsSprite.extend = cc.Class.extend; })()"); } @@ -592,7 +590,8 @@ void register_CCPhysicsDebugNode(JSContext *cx, JS::HandleObject obj) { bool jsval_to_cpBB( JSContext *cx, jsval vp, cpBB *ret ) { JS::RootedObject jsobj(cx); - bool ok = JS_ValueToObject( cx, JS::RootedValue(cx, vp), &jsobj ); + JS::RootedValue jsv(cx, vp); + bool ok = JS_ValueToObject(cx, jsv, &jsobj); JSB_PRECONDITION( ok, "Error converting value to object"); JSB_PRECONDITION( jsobj, "Not a valid JS object"); @@ -645,7 +644,8 @@ bool jsval_to_array_of_cpvect( JSContext *cx, jsval vp, cpVect**verts, int *numV { // Parsing sequence JS::RootedObject jsobj(cx); - bool ok = JS_ValueToObject( cx, JS::RootedValue(cx, vp), &jsobj ); + JS::RootedValue jsv(cx, vp); + bool ok = JS_ValueToObject(cx, jsv, &jsobj); JSB_PRECONDITION( ok, "Error converting value to object"); JSB_PRECONDITION( jsobj && JS_IsArrayObject( cx, jsobj), "Object must be an array"); @@ -683,7 +683,8 @@ bool jsval_to_cpVect( JSContext *cx, jsval vp, cpVect *ret ) #ifdef JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES JS::RootedObject jsobj(cx); - if( ! JS_ValueToObject( cx, JS::RootedValue(cx, vp), &jsobj ) ) + JS::RootedValue jsv(cx, vp); + if( !JS_ValueToObject(cx, jsv, &jsobj) ) return false; JSB_PRECONDITION( jsobj, "Not a valid JS object"); @@ -797,8 +798,10 @@ static cpBool myCollisionBegin(cpArbiter *arb, cpSpace *space, void *data) jsval args[2]; if( handler->is_oo ) { - args[0] = c_class_to_jsval(handler->cx, arb, JS::RootedObject(handler->cx, JSB_cpArbiter_object), JSB_cpArbiter_class, "cpArbiter"); - args[1] = c_class_to_jsval(handler->cx, space, JS::RootedObject(handler->cx, JSB_cpSpace_object), JSB_cpSpace_class, "cpArbiter"); + JS::RootedObject arbiterProto(handler->cx, JSB_cpArbiter_object); + JS::RootedObject spaceProto(handler->cx, JSB_cpSpace_object); + args[0] = c_class_to_jsval(handler->cx, arb, arbiterProto, JSB_cpArbiter_class, "cpArbiter"); + args[1] = c_class_to_jsval(handler->cx, space, spaceProto, JSB_cpSpace_class, "cpArbiter"); } else { args[0] = opaque_to_jsval( handler->cx, arb); args[1] = opaque_to_jsval( handler->cx, space ); @@ -807,7 +810,9 @@ static cpBool myCollisionBegin(cpArbiter *arb, cpSpace *space, void *data) JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET JS::RootedValue rval(handler->cx); - bool ok = JS_CallFunctionValue( handler->cx, JS::RootedObject(handler->cx, handler->jsthis), JS::RootedValue(handler->cx, OBJECT_TO_JSVAL(handler->begin)), JS::HandleValueArray::fromMarkedLocation(2, args), &rval); + JS::RootedObject jsthis(handler->cx, handler->jsthis); + JS::RootedValue jsbegin(handler->cx, OBJECT_TO_JSVAL(handler->begin)); + bool ok = JS_CallFunctionValue( handler->cx, jsthis, jsbegin, JS::HandleValueArray::fromMarkedLocation(2, args), &rval); JSB_PRECONDITION2(ok, handler->cx, cpFalse, "Error calling collision callback: begin"); if( rval.isBoolean() ) { @@ -823,8 +828,10 @@ static cpBool myCollisionPre(cpArbiter *arb, cpSpace *space, void *data) jsval args[2]; if( handler->is_oo ) { - args[0] = c_class_to_jsval(handler->cx, arb, JS::RootedObject(handler->cx, JSB_cpArbiter_object), JSB_cpArbiter_class, "cpArbiter"); - args[1] = c_class_to_jsval(handler->cx, space, JS::RootedObject(handler->cx, JSB_cpSpace_object), JSB_cpSpace_class, "cpArbiter"); + JS::RootedObject arbiterProto(handler->cx, JSB_cpArbiter_object); + JS::RootedObject spaceProto(handler->cx, JSB_cpSpace_object); + args[0] = c_class_to_jsval(handler->cx, arb, arbiterProto, JSB_cpArbiter_class, "cpArbiter"); + args[1] = c_class_to_jsval(handler->cx, space, spaceProto, JSB_cpSpace_class, "cpArbiter"); } else { args[0] = opaque_to_jsval( handler->cx, arb); args[1] = opaque_to_jsval( handler->cx, space ); @@ -833,7 +840,9 @@ static cpBool myCollisionPre(cpArbiter *arb, cpSpace *space, void *data) JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET JS::RootedValue rval(handler->cx); - bool ok = JS_CallFunctionValue( handler->cx, JS::RootedObject(handler->cx, handler->jsthis), JS::RootedValue(handler->cx, OBJECT_TO_JSVAL(handler->pre)), JS::HandleValueArray::fromMarkedLocation(2, args), &rval); + JS::RootedObject jsthis(handler->cx, handler->jsthis); + JS::RootedValue jspre(handler->cx, OBJECT_TO_JSVAL(handler->pre)); + bool ok = JS_CallFunctionValue( handler->cx, jsthis, jspre, JS::HandleValueArray::fromMarkedLocation(2, args), &rval); JSB_PRECONDITION2(ok, handler->cx, false, "Error calling collision callback: pre"); if( rval.isBoolean() ) { @@ -850,8 +859,10 @@ static void myCollisionPost(cpArbiter *arb, cpSpace *space, void *data) jsval args[2]; if( handler->is_oo ) { - args[0] = c_class_to_jsval(handler->cx, arb, JS::RootedObject(handler->cx, JSB_cpArbiter_object), JSB_cpArbiter_class, "cpArbiter"); - args[1] = c_class_to_jsval(handler->cx, space, JS::RootedObject(handler->cx, JSB_cpSpace_object), JSB_cpSpace_class, "cpArbiter"); + JS::RootedObject arbiterProto(handler->cx, JSB_cpArbiter_object); + JS::RootedObject spaceProto(handler->cx, JSB_cpSpace_object); + args[0] = c_class_to_jsval(handler->cx, arb, arbiterProto, JSB_cpArbiter_class, "cpArbiter"); + args[1] = c_class_to_jsval(handler->cx, space, spaceProto, JSB_cpSpace_class, "cpArbiter"); } else { args[0] = opaque_to_jsval( handler->cx, arb); args[1] = opaque_to_jsval( handler->cx, space ); @@ -860,7 +871,9 @@ static void myCollisionPost(cpArbiter *arb, cpSpace *space, void *data) JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET JS::RootedValue ignore(handler->cx); - bool ok = JS_CallFunctionValue( handler->cx, JS::RootedObject(handler->cx, handler->jsthis), JS::RootedValue(handler->cx, OBJECT_TO_JSVAL(handler->post)), JS::HandleValueArray::fromMarkedLocation(2, args), &ignore); + JS::RootedObject jsthis(handler->cx, handler->jsthis); + JS::RootedValue jspost(handler->cx, OBJECT_TO_JSVAL(handler->post)); + bool ok = JS_CallFunctionValue( handler->cx, jsthis, jspost, JS::HandleValueArray::fromMarkedLocation(2, args), &ignore); JSB_PRECONDITION2(ok, handler->cx, , "Error calling collision callback: Post"); } @@ -872,8 +885,10 @@ static void myCollisionSeparate(cpArbiter *arb, cpSpace *space, void *data) jsval args[2]; if( handler->is_oo ) { - args[0] = c_class_to_jsval(handler->cx, arb, JS::RootedObject(handler->cx, JSB_cpArbiter_object), JSB_cpArbiter_class, "cpArbiter"); - args[1] = c_class_to_jsval(handler->cx, space, JS::RootedObject(handler->cx, JSB_cpSpace_object), JSB_cpSpace_class, "cpArbiter"); + JS::RootedObject arbiterProto(handler->cx, JSB_cpArbiter_object); + JS::RootedObject spaceProto(handler->cx, JSB_cpSpace_object); + args[0] = c_class_to_jsval(handler->cx, arb, arbiterProto, JSB_cpArbiter_class, "cpArbiter"); + args[1] = c_class_to_jsval(handler->cx, space, spaceProto, JSB_cpSpace_class, "cpArbiter"); } else { args[0] = opaque_to_jsval( handler->cx, arb); args[1] = opaque_to_jsval( handler->cx, space ); @@ -882,7 +897,9 @@ static void myCollisionSeparate(cpArbiter *arb, cpSpace *space, void *data) JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET JS::RootedValue ignore(handler->cx); - bool ok = JS_CallFunctionValue( handler->cx, JS::RootedObject(handler->cx, handler->jsthis), JS::RootedValue(handler->cx, OBJECT_TO_JSVAL(handler->separate)), JS::HandleValueArray::fromMarkedLocation(2, args), &ignore); + JS::RootedObject jsthis(handler->cx, handler->jsthis); + JS::RootedValue jssep(handler->cx, OBJECT_TO_JSVAL(handler->separate)); + bool ok = JS_CallFunctionValue( handler->cx, jsthis, jssep, JS::HandleValueArray::fromMarkedLocation(2, args), &ignore); JSB_PRECONDITION2(ok, handler->cx, , "Error calling collision callback: Separate");} #pragma mark - cpSpace @@ -947,8 +964,10 @@ bool __jsb_cpSpace_addCollisionHandler(JSContext *cx, jsval *vp, jsval *argvp, c bool ok = true; // args - ok &= jsval_to_int(cx, JS::RootedValue(cx, *argvp++), (int32_t*) &handler->typeA ); - ok &= jsval_to_int(cx, JS::RootedValue(cx, *argvp++), (int32_t*) &handler->typeB ); + JS::RootedValue jstypeA(cx, *argvp++); + JS::RootedValue jstypeB(cx, *argvp++); + ok &= jsval_to_int(cx, jstypeA, (int32_t*) &handler->typeA ); + ok &= jsval_to_int(cx, jstypeB, (int32_t*) &handler->typeB ); handler->begin = argvp->toObjectOrNull(); argvp++; @@ -1014,7 +1033,8 @@ bool JSB_cpSpaceAddCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp) // args cpSpace *space = nullptr; jsval* argvp = args.array(); - bool ok = jsval_to_opaque( cx, JS::RootedValue(cx, *argvp++), (void**)&space); + JS::RootedValue jsarg(cx, *argvp++); + bool ok = jsval_to_opaque(cx, jsarg, (void**)&space); JSB_PRECONDITION(ok, "Error parsing arguments"); return __jsb_cpSpace_addCollisionHandler(cx, vp, argvp, space, 0); @@ -1115,8 +1135,10 @@ bool __jsb_cpSpace_removeCollisionHandler(JSContext *cx, jsval *vp, jsval *argvp cpCollisionType typeA = 0; cpCollisionType typeB = 0; - ok &= jsval_to_int(cx, JS::RootedValue(cx, *argvp++), (int32_t*) &typeA ); - ok &= jsval_to_int(cx, JS::RootedValue(cx, *argvp++), (int32_t*) &typeB ); + JS::RootedValue jstypeA(cx, *argvp++); + JS::RootedValue jstypeB(cx, *argvp++); + ok &= jsval_to_int(cx, jstypeA, (int32_t*) &typeA); + ok &= jsval_to_int(cx, jstypeB, (int32_t*) &typeB); JSB_PRECONDITION(ok, "Error parsing arguments"); @@ -1154,7 +1176,8 @@ bool JSB_cpSpaceRemoveCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp) cpSpace* space = nullptr; jsval* argvp = args.array(); - bool ok = jsval_to_opaque( cx, JS::RootedValue(cx, *argvp++), (void**)&space); + JS::RootedValue jsarg(cx, *argvp++); + bool ok = jsval_to_opaque( cx, jsarg, (void**)&space); JSB_PRECONDITION(ok, "Error parsing arguments"); @@ -1395,7 +1418,8 @@ bool JSB_cpSpace_segmentQueryFirst(JSContext *cx, uint32_t argc, jsval *vp){ if(target) { - JSObject *jsobj = JS_NewObject(cx, JSB_cpSegmentQueryInfo_class, JS::RootedObject(cx, JSB_cpSegmentQueryInfo_object), JS::NullPtr()); + JS::RootedObject segmentQueryInfoProto(cx, JSB_cpSegmentQueryInfo_object); + JSObject *jsobj = JS_NewObject(cx, JSB_cpSegmentQueryInfo_class, segmentQueryInfoProto, JS::NullPtr()); jsb_set_jsobject_for_proxy(jsobj, out); jsb_set_c_proxy_for_jsobject(jsobj, out, JSB_C_FLAG_CALL_FREE); args.rval().set(OBJECT_TO_JSVAL(jsobj)); @@ -1432,7 +1456,8 @@ bool JSB_cpSpace_nearestPointQueryNearest(JSContext *cx, uint32_t argc, jsval *v if(target) { - JSObject *jsobj = JS_NewObject(cx, JSB_cpNearestPointQueryInfo_class, JS::RootedObject(cx, JSB_cpNearestPointQueryInfo_object), JS::NullPtr()); + JS::RootedObject nearestPointQueryInfoProto(cx, JSB_cpNearestPointQueryInfo_object); + JSObject *jsobj = JS_NewObject(cx, JSB_cpNearestPointQueryInfo_class, nearestPointQueryInfoProto, JS::NullPtr()); jsb_set_jsobject_for_proxy(jsobj, info); jsb_set_c_proxy_for_jsobject(jsobj, info, JSB_C_FLAG_CALL_FREE); args.rval().set(OBJECT_TO_JSVAL(jsobj)); @@ -1457,12 +1482,12 @@ void JSB_cpSpace_pointQuery_func(cpShape *shape, void *data) if(jsCpObject) { JSContext* cx = ((JSB_cp_each_UserData*)data)->cx; - jsval* func = ((JSB_cp_each_UserData*)data)->func; + JS::RootedValue func(cx, *((JSB_cp_each_UserData*)data)->func); JS::RootedValue rval(cx); jsval argv = OBJECT_TO_JSVAL(jsCpObject); JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - JS_CallFunctionValue(cx, JS::NullPtr(), JS::RootedValue(cx, *func), JS::HandleValueArray::fromMarkedLocation(1, &argv), &rval); + JS_CallFunctionValue(cx, JS::NullPtr(), func, JS::HandleValueArray::fromMarkedLocation(1, &argv), &rval); } } @@ -1506,7 +1531,7 @@ void JSB_cpSpace_nearestPointQuery_func(cpShape *shape, cpFloat distance, cpVect if(jsCpObject) { JSContext* cx = ((JSB_cp_each_UserData*)data)->cx; - jsval* func = ((JSB_cp_each_UserData*)data)->func; + JS::RootedValue func(cx, *((JSB_cp_each_UserData*)data)->func); JS::RootedValue rval(cx); jsval argv[3]; argv[0] = OBJECT_TO_JSVAL(jsCpObject); @@ -1514,7 +1539,7 @@ void JSB_cpSpace_nearestPointQuery_func(cpShape *shape, cpFloat distance, cpVect argv[2] = cpVect_to_jsval(cx, point); JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - JS_CallFunctionValue(cx, JS::NullPtr(), JS::RootedValue(cx, *func), JS::HandleValueArray::fromMarkedLocation(3, argv), &rval); + JS_CallFunctionValue(cx, JS::NullPtr(), func, JS::HandleValueArray::fromMarkedLocation(3, argv), &rval); } } @@ -1559,7 +1584,7 @@ void JSB_cpSpace_segmentQuery_func(cpShape *shape, cpFloat t, cpVect n, void *da if(jsCpObject) { JSContext* cx = ((JSB_cp_each_UserData*)data)->cx; - jsval* func = ((JSB_cp_each_UserData*)data)->func; + JS::RootedValue func(cx, *((JSB_cp_each_UserData*)data)->func); JS::RootedValue rval(cx); jsval argv[3]; argv[0] = OBJECT_TO_JSVAL(jsCpObject); @@ -1567,7 +1592,7 @@ void JSB_cpSpace_segmentQuery_func(cpShape *shape, cpFloat t, cpVect n, void *da argv[2] = cpVect_to_jsval(cx, n); JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - JS_CallFunctionValue(cx, JS::NullPtr(), JS::RootedValue(cx, *func), JS::HandleValueArray::fromMarkedLocation(3, argv), &rval); + JS_CallFunctionValue(cx, JS::NullPtr(), func, JS::HandleValueArray::fromMarkedLocation(3, argv), &rval); } } @@ -1577,7 +1602,7 @@ bool JSB_cpSpace_segmentQuery(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2(argc == 5, cx, false, "Invalid number of arguments"); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JSObject* jsthis = args.thisv().toObjectOrNull(); + JS::RootedObject jsthis(cx, args.thisv().toObjectOrNull()); struct jsb_c_proxy_s* proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* space = (cpSpace*) proxy->handle; @@ -1650,11 +1675,11 @@ void JSB_cpSpace_each_func(T* cpObject, void *data) if(jsCpObject) { JSContext* cx = ((JSB_cp_each_UserData*)data)->cx; - jsval* func = ((JSB_cp_each_UserData*)data)->func; + JS::RootedValue func(cx, *((JSB_cp_each_UserData*)data)->func); JS::RootedValue rval(cx); jsval argv = OBJECT_TO_JSVAL(jsCpObject); - JS_CallFunctionValue(cx, JS::NullPtr(), JS::RootedValue(cx, *func), JS::HandleValueArray::fromMarkedLocation(1, &argv), &rval); + JS_CallFunctionValue(cx, JS::NullPtr(), func, JS::HandleValueArray::fromMarkedLocation(1, &argv), &rval); } } @@ -1768,11 +1793,11 @@ void JSB_cpBody_each_func(cpBody* body, T* cpObject, void* data) if(jsCpObject) { JSContext* cx = ((JSB_cp_each_UserData*)data)->cx; - jsval* func = ((JSB_cp_each_UserData*)data)->func; + JS::RootedValue func(cx, *((JSB_cp_each_UserData*)data)->func); JS::RootedValue rval(cx); jsval argv = OBJECT_TO_JSVAL(jsCpObject); - JS_CallFunctionValue(cx, JS::NullPtr(), JS::RootedValue(cx, *func), JS::HandleValueArray::fromMarkedLocation(1, &argv), &rval); + JS_CallFunctionValue(cx, JS::NullPtr(), func, JS::HandleValueArray::fromMarkedLocation(1, &argv), &rval); } } @@ -1850,8 +1875,9 @@ bool __jsb_cpArbiter_getBodies(JSContext *cx, const JS::CallArgs& args, cpArbite JS::RootedValue valA(cx); JS::RootedValue valB(cx); if( is_oo ) { - valA = c_class_to_jsval(cx, bodyA, JS::RootedObject(cx, JSB_cpBody_object), JSB_cpBody_class, "cpArbiter"); - valB = c_class_to_jsval(cx, bodyB, JS::RootedObject(cx, JSB_cpBody_object), JSB_cpBody_class, "cpArbiter"); + JS::RootedObject bodyProto(cx, JSB_cpBody_object); + valA = c_class_to_jsval(cx, bodyA, bodyProto, JSB_cpBody_class, "cpArbiter"); + valB = c_class_to_jsval(cx, bodyB, bodyProto, JSB_cpBody_class, "cpArbiter"); } else { valA = opaque_to_jsval(cx, bodyA); valB = opaque_to_jsval(cx, bodyB); @@ -1905,8 +1931,9 @@ bool __jsb_cpArbiter_getShapes(JSContext *cx, const JS::CallArgs& args, cpArbite JS::RootedValue valA(cx); JS::RootedValue valB(cx); if( is_oo ) { - valA = c_class_to_jsval(cx, shapeA, JS::RootedObject(cx, JSB_cpShape_object), JSB_cpShape_class, "cpShape"); - valB = c_class_to_jsval(cx, shapeB, JS::RootedObject(cx, JSB_cpShape_object), JSB_cpShape_class, "cpShape"); + JS::RootedObject shapeProto(cx, JSB_cpShape_object); + valA = c_class_to_jsval(cx, shapeA, shapeProto, JSB_cpShape_class, "cpShape"); + valB = c_class_to_jsval(cx, shapeB, shapeProto, JSB_cpShape_class, "cpShape"); } else { valA = opaque_to_jsval(cx, shapeA); valB = opaque_to_jsval(cx, shapeB); @@ -1956,7 +1983,8 @@ bool JSB_cpArbiter_getShapes(JSContext *cx, uint32_t argc, jsval *vp) bool JSB_cpBody_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==2, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpBody_class, JS::RootedObject(cx, JSB_cpBody_object), JS::NullPtr()); + JS::RootedObject bodyProto(cx, JSB_cpBody_object); + JSObject *jsobj = JS_NewObject(cx, JSB_cpBody_class, bodyProto, JS::NullPtr()); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; double m = 0; double i = 0; @@ -2028,8 +2056,8 @@ static bool __jsb_cpBody_setUserData(JSContext *cx, jsval *vp, jsval *argvp, cpBody *body) { JS::RootedObject jsobj(cx); - - bool ok = JS_ValueToObject(cx, JS::RootedValue(cx, *argvp), &jsobj); + JS::RootedValue jsv(cx, *argvp); + bool ok = JS_ValueToObject(cx, jsv, &jsobj); JSB_PRECONDITION(ok, "Error parsing arguments"); @@ -2046,7 +2074,8 @@ bool JSB_cpBodySetUserData(JSContext *cx, uint32_t argc, jsval *vp) JS::CallArgs args = JS::CallArgsFromVp(argc, vp); cpBody *body = nullptr; jsval* argvp = args.array(); - bool ok = jsval_to_opaque( cx, JS::RootedValue(cx, *argvp++), (void**) &body ); + JS::RootedValue jsarg(cx, *argvp++); + bool ok = jsval_to_opaque(cx, jsarg, (void**) &body); JSB_PRECONDITION(ok, "Error parsing arguments"); return __jsb_cpBody_setUserData(cx, vp, argvp, body); } @@ -2150,8 +2179,8 @@ JSObject* JSB_cpBase_object = NULL; bool JSB_cpBase_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc==1, cx, false, "Invalid arguments. Expecting 1"); - - JSObject *jsobj = JS_NewObject(cx, JSB_cpBase_class, JS::RootedObject(cx, JSB_cpBase_object), JS::NullPtr()); + JS::RootedObject baseProto(cx, JSB_cpBase_object); + JSObject *jsobj = JS_NewObject(cx, JSB_cpBase_class, baseProto, JS::NullPtr()); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; @@ -2238,8 +2267,6 @@ void JSB_cpBase_createClass(JSContext *cx, JS::HandleObject globalObj, const cha }; JSB_cpBase_object = JS_InitClass(cx, globalObj, JS::NullPtr(), JSB_cpBase_class, JSB_cpBase_constructor,0,properties,funcs,NULL,st_funcs); -// bool found; -// JS_SetPropertyAttributes(cx, globalObj, name, JSPROP_ENUMERATE | JSPROP_READONLY, &found); } // Manual "methods" @@ -2247,7 +2274,8 @@ void JSB_cpBase_createClass(JSContext *cx, JS::HandleObject globalObj, const cha bool JSB_cpPolyShape_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2(argc==3, cx, false, "Invalid number of arguments"); - JSObject *jsobj = JS_NewObject(cx, JSB_cpPolyShape_class, JS::RootedObject(cx, JSB_cpPolyShape_object), JS::NullPtr()); + JS::RootedObject polyShapeProto(cx, JSB_cpPolyShape_object); + JSObject *jsobj = JS_NewObject(cx, JSB_cpPolyShape_class, polyShapeProto, JS::NullPtr()); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; cpBody* body = nullptr; cpVect *verts = nullptr; cpVect offset; diff --git a/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp b/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp index 7269841548..36e11f4378 100644 --- a/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp +++ b/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp @@ -334,7 +334,8 @@ bool js_cocos2dx_CCSequence_create(JSContext *cx, uint32_t argc, jsval *vp) JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc > 0) { Vector array; - if (argc == 1 && JS_IsArrayObject(cx, JS::RootedObject(cx, args.get(0).toObjectOrNull()))) { + JS::RootedObject actions(cx, args.get(0).toObjectOrNull()); + if (argc == 1 && JS_IsArrayObject(cx, actions)) { bool ok = true; ok &= jsval_to_ccvector(cx, args.get(0), &array); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); @@ -378,7 +379,8 @@ bool js_cocos2dx_CCSpawn_create(JSContext *cx, uint32_t argc, jsval *vp) JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc > 0) { Vector array; - if (argc == 1 && JS_IsArrayObject(cx, JS::RootedObject(cx, args.get(0).toObjectOrNull()))) { + JS::RootedObject actions(cx, args.get(0).toObjectOrNull()); + if (argc == 1 && JS_IsArrayObject(cx, actions)) { bool ok = true; ok &= jsval_to_ccvector(cx, args.get(0), &array); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); @@ -468,7 +470,8 @@ bool js_cocos2dx_CCAnimation_create(JSContext *cx, uint32_t argc, jsval *vp) ok &= jsval_to_ccvector(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); } - ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(1)), &arg1); + JS::RootedValue jsarg1(cx, args.get(1)); + ok &= JS::ToNumber(cx, jsarg1, &arg1); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); ret = cocos2d::Animation::createWithSpriteFrames(arg0, arg1); } else if (argc == 3) { @@ -478,7 +481,8 @@ bool js_cocos2dx_CCAnimation_create(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); } unsigned int loops; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(1)), &arg1); + JS::RootedValue jsarg1(cx, args.get(1)); + ok &= JS::ToNumber(cx, jsarg1, &arg1); ok &= jsval_to_uint32(cx, args.get(2), &loops); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); ret = cocos2d::Animation::create(arg0, arg1, loops); @@ -1248,7 +1252,8 @@ bool js_CCNode_scheduleOnce(JSContext *cx, uint32_t argc, jsval *vp) // double delay; if( argc >= 2 ) { - ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(1)), &delay ); + JS::RootedValue jsdelay(cx, args.get(1)); + ok &= JS::ToNumber(cx, jsdelay, &delay); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); } @@ -1324,7 +1329,8 @@ bool js_CCNode_schedule(JSContext *cx, uint32_t argc, jsval *vp) double interval = 0.0; if( argc >= 2 ) { - ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(1)), &interval ); + JS::RootedValue jsinterval(cx, args.get(1)); + ok &= JS::ToNumber(cx, jsinterval, &interval); } // @@ -1332,7 +1338,8 @@ bool js_CCNode_schedule(JSContext *cx, uint32_t argc, jsval *vp) // double repeat = 0.0; if( argc >= 3 ) { - ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(2)), &repeat ); + JS::RootedValue jsrepeat(cx, args.get(2)); + ok &= JS::ToNumber(cx, jsrepeat, &repeat); } // @@ -1340,7 +1347,8 @@ bool js_CCNode_schedule(JSContext *cx, uint32_t argc, jsval *vp) // double delay = 0.0; if( argc >= 4 ) { - ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(3)), &delay ); + JS::RootedValue jsdelay(cx, args.get(3)); + ok &= JS::ToNumber(cx, jsdelay, &delay); } JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); @@ -1629,7 +1637,8 @@ bool js_CCScheduler_scheduleUpdateForTarget(JSContext *cx, uint32_t argc, jsval bool paused = false; if( argc >= 3 ) { - paused = JS::ToBoolean(JS::RootedValue(cx, args.get(2))); + JS::RootedValue jspaused(cx, args.get(2)); + paused = JS::ToBoolean(jspaused); } JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); @@ -1729,7 +1738,8 @@ bool js_CCScheduler_scheduleCallbackForTarget(JSContext *cx, uint32_t argc, jsva double interval = 0; if( argc >= 3 ) { - ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(2)), &interval ); + JS::RootedValue jsinterval(cx, args.get(2)); + ok &= JS::ToNumber(cx, jsinterval, &interval); } // @@ -1737,7 +1747,8 @@ bool js_CCScheduler_scheduleCallbackForTarget(JSContext *cx, uint32_t argc, jsva // double repeat = kRepeatForever; if( argc >= 4 ) { - ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(3)), &repeat ); + JS::RootedValue jsrepeat(cx, args.get(3)); + ok &= JS::ToNumber(cx, jsrepeat, &repeat); } // @@ -1745,13 +1756,15 @@ bool js_CCScheduler_scheduleCallbackForTarget(JSContext *cx, uint32_t argc, jsva // double delay = 0; if( argc >= 5 ) { - ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(4)), &delay ); + JS::RootedValue jsdelay(cx, args.get(4)); + ok &= JS::ToNumber(cx, jsdelay, &delay); } bool paused = false; if( argc >= 6 ) { - paused = JS::ToBoolean(JS::RootedValue(cx, args.get(5))); + JS::RootedValue jspaused(cx, args.get(5)); + paused = JS::ToBoolean(jspaused); } JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); @@ -1841,7 +1854,8 @@ bool js_CCScheduler_schedule(JSContext *cx, uint32_t argc, jsval *vp) double interval = 0; if( argc >= 3 ) { - ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(2)), &interval ); + JS::RootedValue jsinterval(cx, args.get(2)); + ok &= JS::ToNumber(cx, jsinterval, &interval); } // @@ -1849,7 +1863,8 @@ bool js_CCScheduler_schedule(JSContext *cx, uint32_t argc, jsval *vp) // double repeat = kRepeatForever; if( argc >= 4 ) { - ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(3)), &repeat ); + JS::RootedValue jsrepeat(cx, args.get(3)); + ok &= JS::ToNumber(cx, jsrepeat, &repeat); } // @@ -1857,7 +1872,8 @@ bool js_CCScheduler_schedule(JSContext *cx, uint32_t argc, jsval *vp) // double delay = 0; if( argc >= 5 ) { - ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(4)), &delay ); + JS::RootedValue jsdelay(cx, args.get(4)); + ok &= JS::ToNumber(cx, jsdelay, &delay); } // @@ -1865,7 +1881,8 @@ bool js_CCScheduler_schedule(JSContext *cx, uint32_t argc, jsval *vp) // bool paused = false; if( argc >= 6 ) { - paused = JS::ToBoolean(JS::RootedValue(cx, args.get(5))); + JS::RootedValue jspaused(cx, args.get(5)); + paused = JS::ToBoolean(jspaused); } // @@ -2177,9 +2194,11 @@ bool js_cocos2dx_CCNode_setPosition(JSContext *cx, uint32_t argc, jsval *vp) return true; } if (argc == 2) { double x; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(0)), &x ); + JS::RootedValue jsx(cx, args.get(0)); + ok &= JS::ToNumber(cx, jsx, &x); double y; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(1)), &y ); + JS::RootedValue jsy(cx, args.get(1)); + ok &= JS::ToNumber(cx, jsy, &y); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cobj->setPosition(Point(x,y)); @@ -2209,9 +2228,11 @@ bool js_cocos2dx_CCNode_setContentSize(JSContext *cx, uint32_t argc, jsval *vp) return true; } if (argc == 2) { double width; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(0)), &width ); + JS::RootedValue jsw(cx, args.get(0)); + ok &= JS::ToNumber(cx, jsw, &width); double height; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, args.get(1)), &height ); + JS::RootedValue jsh(cx, args.get(1)); + ok &= JS::ToNumber(cx, jsh, &height); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); cobj->setContentSize(Size(width,height)); @@ -2769,7 +2790,8 @@ bool js_BezierActions_initWithDuration(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 2) { double arg0; cocos2d::_ccBezierConfig arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, args.get(0)), &arg0); + JS::RootedValue jsarg0(cx, args.get(0)); + ok &= JS::ToNumber( cx, jsarg0, &arg0); int num; cocos2d::Vec2 *arr; @@ -2901,7 +2923,8 @@ bool js_CatmullRomActions_initWithDuration(JSContext *cx, uint32_t argc, jsval * JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_CatmullRom_initWithDuration : Invalid Native Object"); if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, args.get(0)), &arg0); + JS::RootedValue jsarg0(cx, args.get(0)); + ok &= JS::ToNumber(cx, jsarg0, &arg0); int num; Point *arr; @@ -2962,9 +2985,9 @@ bool js_cocos2dx_CardinalSplineTo_initWithDuration(JSContext *cx, uint32_t argc, JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_CardinalSplineTo_initWithDuration : Invalid Native Object"); if (argc == 3) { double arg0; - double arg2; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, args.get(0)), &arg0); + JS::RootedValue jsarg0(cx, args.get(0)); + ok &= JS::ToNumber(cx, jsarg0, &arg0); int num; Point *arr; @@ -2973,8 +2996,9 @@ bool js_cocos2dx_CardinalSplineTo_initWithDuration(JSContext *cx, uint32_t argc, for( int i=0; i < num;i++) { arg1->addControlPoint(arr[i]); } - - ok &= JS::ToNumber( cx, JS::RootedValue(cx, args.get(2)), &arg2); + + JS::RootedValue jsarg2(cx, args.get(2)); + ok &= JS::ToNumber(cx, jsarg2, &arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_CardinalSplineTo_initWithDuration : Error processing arguments"); bool ret = cobj->initWithDuration(arg0, arg1, arg2); @@ -3939,7 +3963,8 @@ bool js_cocos2dx_CCTMXLayer_getTileFlagsAt(JSContext *cx, uint32_t argc, jsval * static bool jsval_to_string_vector(JSContext* cx, jsval v, std::vector& ret) { JS::RootedObject jsobj(cx); - bool ok = JS_ValueToObject( cx, JS::RootedValue(cx, v), &jsobj ); + JS::RootedValue jsv(cx, v); + bool ok = JS_ValueToObject(cx, jsv, &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"); @@ -4542,7 +4567,8 @@ bool js_PlistParser_parse(JSContext *cx, unsigned argc, JS::Value *vp) { //JS_GetStringCharsZ was removed in SpiderMonkey 33 //ok = JS_ParseJSON(cx, JS_GetStringCharsZ(cx, strVal), static_cast(JS_GetStringEncodingLength(JSVAL_TO_STRING(strVal))), &outVal); - ok = JS_ParseJSON(cx, JS::RootedString(cx, strVal.toString()), &outVal); + JS::RootedString jsout(cx, strVal.toString()); + ok = JS_ParseJSON(cx, jsout, &outVal); if (ok) args.rval().set(outVal); @@ -4655,8 +4681,9 @@ bool jsval_to_TTFConfig(JSContext *cx, jsval v, TTFConfig* ret) { std::string fontFilePath,customGlyphs; double fontSize, glyphs, outlineSize; - bool ok = v.isObject() && - JS_ValueToObject(cx, JS::RootedValue(cx, v), &tmp) && + JS::RootedValue jsv(cx, v); + bool ok = jsv.isObject() && + JS_ValueToObject(cx, jsv, &tmp) && JS_GetProperty(cx, tmp, "fontFilePath", &js_fontFilePath) && JS_GetProperty(cx, tmp, "fontSize", &js_fontSize) && JS_GetProperty(cx, tmp, "outlineSize", &js_outlineSize) && @@ -4805,7 +4832,8 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, args.get(2))); + JS::RootedValue jsarg2(cx, args.get(2)); + arg2 = JS::ToBoolean(jsarg2); bool ret = cobj->saveToFile(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); @@ -4823,7 +4851,8 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } bool arg2; - arg2 = JS::ToBoolean(JS::RootedValue(cx, args.get(2))); + JS::RootedValue jsarg2(cx, args.get(2)); + arg2 = JS::ToBoolean(jsarg2); std::function &)> arg3; do { std::shared_ptr func(new JSFunctionWrapper(cx, obj, args.get(3))); @@ -4877,7 +4906,8 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } bool arg1; - arg1 = JS::ToBoolean(JS::RootedValue(cx, args.get(1))); + JS::RootedValue jsarg1(cx, args.get(1)); + arg1 = JS::ToBoolean(jsarg1); bool ret = cobj->saveToFile(arg0, arg1); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); @@ -4892,7 +4922,8 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } bool arg1; - arg1 = JS::ToBoolean(JS::RootedValue(cx, args.get(1))); + JS::RootedValue jsarg1(cx, args.get(1)); + arg1 = JS::ToBoolean(jsarg1); std::function &)> arg2; do { std::shared_ptr func(new JSFunctionWrapper(cx, obj, args.get(2))); @@ -4972,14 +5003,15 @@ bool js_cocos2dx_Camera_isVisibleInFrustum(JSContext *cx, uint32_t argc, jsval * cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_isVisibleInFrustum : Invalid Native Object"); if (argc == 1) { - cocos2d::Vec3 min; + cocos2d::Vec3 min; JS::RootedValue jsmin(cx); - ok &= JS_GetProperty(cx, JS::RootedObject(cx, args.get(0).toObjectOrNull()), "min", &jsmin); + JS::RootedObject jsarg0(cx, args.get(0).toObjectOrNull()); + ok &= JS_GetProperty(cx, jsarg0, "min", &jsmin); ok &= jsval_to_vector3(cx, jsmin, &min); cocos2d::Vec3 max; JS::RootedValue jsmax(cx); - ok &= JS_GetProperty(cx, JS::RootedObject(cx, args.get(0).toObjectOrNull()), "max", &jsmax); + ok &= JS_GetProperty(cx, jsarg0, "max", &jsmax); ok &= jsval_to_vector3(cx, jsmax, &max); cocos2d::AABB aabb(min, max); @@ -5088,7 +5120,8 @@ bool js_cocos2dx_EventKeyboard_constructor(JSContext *cx, uint32_t argc, jsval * ok &= jsval_to_int32(cx, retVal, (int32_t *)&arg0); bool arg1; - arg1 = JS::ToBoolean(JS::RootedValue(cx, args.get(1))); + JS::RootedValue jsarg1(cx, args.get(1)); + arg1 = JS::ToBoolean(jsarg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventKeyboard_constructor : Error processing arguments"); @@ -5104,8 +5137,11 @@ bool js_cocos2dx_EventKeyboard_constructor(JSContext *cx, uint32_t argc, jsval * 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, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto)); - args.rval().set( OBJECT_TO_JSVAL(obj)); + JS::RootedObject proto(cx, typeClass->proto.ref()); + JS::RootedObject parentProto(cx, typeClass->parentProto.ref()); + JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parentProto)); + JS::RootedValue objVal(cx, OBJECT_TO_JSVAL(obj)); + args.rval().set(objVal); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); JS::AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventKeyboard"); @@ -5150,32 +5186,20 @@ void js_register_cocos2dx_EventKeyboard(JSContext *cx, JS::HandleObject global) JSFunctionSpec *st_funcs = NULL; + JS::RootedObject parentProto(cx, jsb_cocos2d_Event_prototype); jsb_cocos2d_EventKeyboard_prototype = JS_InitClass( cx, global, - JS::RootedObject(cx, jsb_cocos2d_Event_prototype), + parentProto, jsb_cocos2d_EventKeyboard_class, js_cocos2dx_EventKeyboard_constructor, 0, // constructor properties, funcs, NULL, // no static properties st_funcs); - // make the class enumerable in the registered namespace - // bool found; - //FIXME: Removed in Firefox v27 - // JS_SetPropertyAttributes(cx, global, "EventKeyboard", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table - TypeTest t; - js_type_class_t *p; - std::string typeName = t.s_name(); - if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) - { - p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_EventKeyboard_class; - p->proto = jsb_cocos2d_EventKeyboard_prototype; - p->parentProto = jsb_cocos2d_Event_prototype; - _js_global_type_map.insert(std::make_pair(typeName, p)); - } + JS::RootedObject proto(cx, jsb_cocos2d_EventKeyboard_prototype); + jsb_register_class(cx, jsb_cocos2d_EventKeyboard_class, proto, parentProto); } // console.log("Message"); @@ -5525,8 +5549,8 @@ bool js_cocos2dx_PolygonInfo_constructor(JSContext *cx, uint32_t argc, jsval *vp 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 proto(cx, typeClass->proto.ref()); + JS::RootedObject parent(cx, typeClass->parentProto.ref()); 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 @@ -5596,17 +5620,8 @@ void js_register_cocos2dx_PolygonInfo(JSContext *cx, JS::HandleObject global) st_funcs); // add the proto and JSClass to the type->js info hash table - TypeTest t; - js_type_class_t *p; - std::string typeName = t.s_name(); - if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) - { - p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_PolygonInfo_class; - p->proto = jsb_cocos2d_PolygonInfo_prototype; - p->parentProto = NULL; - _js_global_type_map.insert(std::make_pair(typeName, p)); - } + JS::RootedObject proto(cx, jsb_cocos2d_PolygonInfo_prototype); + jsb_register_class(cx, jsb_cocos2d_PolygonInfo_class, proto, JS::NullPtr()); } JSClass *jsb_cocos2d_AutoPolygon_class; @@ -5715,8 +5730,8 @@ bool js_cocos2dx_AutoPolygon_constructor(JSContext *cx, uint32_t argc, jsval *vp 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 proto(cx, typeClass->proto.ref()); + JS::RootedObject parent(cx, typeClass->parentProto.ref()); 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 @@ -5778,23 +5793,10 @@ void js_register_cocos2dx_AutoPolygon(JSContext *cx, JS::HandleObject global) { funcs, NULL, // no static properties st_funcs); - // make the class enumerable in the registered namespace - // bool found; - //FIXME: Removed in Firefox v27 - // JS_SetPropertyAttributes(cx, global, "AutoPolygon", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table - TypeTest t; - js_type_class_t *p; - std::string typeName = t.s_name(); - if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) - { - p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_AutoPolygon_class; - p->proto = jsb_cocos2d_AutoPolygon_prototype; - p->parentProto = NULL; - _js_global_type_map.insert(std::make_pair(typeName, p)); - } + JS::RootedObject proto(cx, jsb_cocos2d_AutoPolygon_prototype); + jsb_register_class(cx, jsb_cocos2d_AutoPolygon_class, proto, JS::NullPtr()); } bool js_cocos2dx_ComponentJS_getScriptObject(JSContext *cx, uint32_t argc, jsval *vp) diff --git a/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp b/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp index 8bd306404d..209f313ae8 100644 --- a/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp +++ b/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp @@ -100,8 +100,8 @@ inline js_proxy_t *js_get_or_create_proxy(JSContext *cx, T *native_obj) { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - JS::RootedObject proto(cx, const_cast(typeProxy->proto.get())); - JS::RootedObject parent(cx, const_cast(typeProxy->parentProto.get())); + 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 diff --git a/cocos/scripting/js-bindings/manual/cocosbuilder/cocosbuilder_specifics.hpp b/cocos/scripting/js-bindings/manual/cocosbuilder/cocosbuilder_specifics.hpp index d3fb9a0da0..3937486b55 100644 --- a/cocos/scripting/js-bindings/manual/cocosbuilder/cocosbuilder_specifics.hpp +++ b/cocos/scripting/js-bindings/manual/cocosbuilder/cocosbuilder_specifics.hpp @@ -44,7 +44,9 @@ public: JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - JS_CallFunctionValue(cx, JS::RootedObject(cx, thisObj.toObjectOrNull()), JS::RootedValue(cx, callback), JS::HandleValueArray::empty(), &retval); + JS::RootedObject jsThis(cx, thisObj.toObjectOrNull()); + JS::RootedValue jsCallback(cx, callback); + JS_CallFunctionValue(cx, jsThis, jsCallback, JS::HandleValueArray::empty(), &retval); } } diff --git a/cocos/scripting/js-bindings/manual/cocosbuilder/js_bindings_ccbreader.cpp b/cocos/scripting/js-bindings/manual/cocosbuilder/js_bindings_ccbreader.cpp index 3f41693eb5..efdcb743e5 100644 --- a/cocos/scripting/js-bindings/manual/cocosbuilder/js_bindings_ccbreader.cpp +++ b/cocos/scripting/js-bindings/manual/cocosbuilder/js_bindings_ccbreader.cpp @@ -325,6 +325,8 @@ void register_CCBuilderReader(JSContext *cx, JS::HandleObject global) JS_DefineFunction(cx, tmpObj, "create", js_CocosBuilder_create, 2, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx, tmpObj, "loadScene", js_cocos2dx_CCBReader_createSceneWithNodeGraphFromFile, 2, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocosbuilder_CCBReader_prototype), "load", js_cocos2dx_CCBReader_readNodeGraphFromFile, 2, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocosbuilder_CCBAnimationManager_prototype), "setCompletedAnimationCallback", js_cocos2dx_CCBAnimationManager_animationCompleteCallback, 2, JSPROP_READONLY | JSPROP_PERMANENT); + tmpObj.set(jsb_cocosbuilder_CCBReader_prototype); + JS_DefineFunction(cx, tmpObj, "load", js_cocos2dx_CCBReader_readNodeGraphFromFile, 2, JSPROP_READONLY | JSPROP_PERMANENT); + tmpObj.set(jsb_cocosbuilder_CCBAnimationManager_prototype); + JS_DefineFunction(cx, tmpObj, "setCompletedAnimationCallback", js_cocos2dx_CCBAnimationManager_animationCompleteCallback, 2, JSPROP_READONLY | JSPROP_PERMANENT); } diff --git a/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_conversions.cpp b/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_conversions.cpp index f996404c8c..8ad8a10f6e 100644 --- a/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_conversions.cpp +++ b/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_conversions.cpp @@ -29,7 +29,8 @@ jsval animationInfo_to_jsval(JSContext* cx, const cocostudio::timeline::Animatio { JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "name", JS::RootedValue(cx, std_string_to_jsval(cx, v.name)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS::RootedValue jsname(cx, std_string_to_jsval(cx, v.name)); + bool ok = JS_DefineProperty(cx, tmp, "name", jsname, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "startIndex", v.startIndex, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "endIndex", v.endIndex, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { diff --git a/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp b/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp index 20f7fc1822..841409e802 100644 --- a/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp +++ b/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp @@ -217,8 +217,6 @@ static bool jsb_Animation_addArmatureFileInfoAsyncCallFunc(JSContext *cx, uint32 } if(argc == 5){ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JSArmatureWrapper *tmpObj = new JSArmatureWrapper(); tmpObj->autorelease(); @@ -747,7 +745,8 @@ bool js_set_AnimationData_name(JSContext *cx, JS::HandleObject obj, JS::HandleId cocostudio::AnimationData* cobj = (cocostudio::AnimationData*)JS_GetPrivate(obj); if (cobj) { std::string name; - bool ok = jsval_to_std_string(cx, JS::RootedValue(cx, vp.get()), &name); + JS::RootedValue jsname(cx, vp.get()); + bool ok = jsval_to_std_string(cx, jsname, &name); JSB_PRECONDITION2(ok, cx, false, "js_set_AnimationData_name : Error processing arguments"); cobj->name = name; return true; @@ -776,7 +775,8 @@ bool js_set_AnimationData_movementNames(JSContext *cx, JS::HandleObject obj, JS: cocostudio::AnimationData* cobj = (cocostudio::AnimationData*)JS_GetPrivate(obj); if (cobj) { std::vector movementNames; - bool ok = jsval_to_std_vector_string(cx, JS::RootedValue(cx, vp.get()), &movementNames); + JS::RootedValue jsmovementNames(cx, vp.get()); + bool ok = jsval_to_std_vector_string(cx, jsmovementNames, &movementNames); JSB_PRECONDITION2(ok, cx, false, "js_set_AnimationData_movementNames : Error processing arguments."); cobj->movementNames.clear(); cobj->movementNames = movementNames; @@ -901,7 +901,8 @@ bool js_set_MovementData_name(JSContext *cx, JS::HandleObject obj, JS::HandleId cocostudio::MovementData* cobj = (cocostudio::MovementData*)JS_GetPrivate(obj); if (cobj) { std::string name; - bool ok = jsval_to_std_string(cx, JS::RootedValue(cx, vp.get()), &name); + JS::RootedValue jsname(cx, vp.get()); + bool ok = jsval_to_std_string(cx, jsname, &name); JSB_PRECONDITION2(ok, cx, false, "js_set_MovementData_name : Error processing arguments"); cobj->name = name; return true; @@ -1375,7 +1376,8 @@ bool js_set_TextureData_name(JSContext *cx, JS::HandleObject obj, JS::HandleId i cocostudio::TextureData* cobj = (cocostudio::TextureData*)(proxy ? proxy->ptr : NULL); if (cobj) { std::string name; - bool ok = jsval_to_std_string(cx, JS::RootedValue(cx, vp.get()), &name); + JS::RootedValue jsname(cx, vp.get()); + bool ok = jsval_to_std_string(cx, jsname, &name); JSB_PRECONDITION2(ok, cx, false, "js_set_TextureData_name : Error processing arguments"); cobj->name = name; return true; @@ -1398,15 +1400,18 @@ extern JSObject* jsb_cocostudio_timeline_Frame_prototype; void register_all_cocos2dx_studio_manual(JSContext* cx, JS::HandleObject global) { - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocostudio_ColliderBody_prototype), "getCalculatedVertexList", js_cocos2dx_studio_ColliderBody_getCalculatedVertexList, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS::RootedObject proto(cx, jsb_cocostudio_ColliderBody_prototype); + JS_DefineFunction(cx, proto, "getCalculatedVertexList", js_cocos2dx_studio_ColliderBody_getCalculatedVertexList, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocostudio_ArmatureAnimation_prototype), "setMovementEventCallFunc", js_cocos2dx_ArmatureAnimation_setMovementEventCallFunc, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocostudio_ArmatureAnimation_prototype), "setFrameEventCallFunc", js_cocos2dx_ArmatureAnimation_setFrameEventCallFunc, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocostudio_ArmatureDataManager_prototype), "addArmatureFileInfoAsync", jsb_Animation_addArmatureFileInfoAsyncCallFunc, 3, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocostudio_ActionManagerEx_prototype), "initWithDictionaryEx", js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE); + proto.set(jsb_cocostudio_ArmatureAnimation_prototype); + JS_DefineFunction(cx, proto, "setMovementEventCallFunc", js_cocos2dx_ArmatureAnimation_setMovementEventCallFunc, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, proto, "setFrameEventCallFunc", js_cocos2dx_ArmatureAnimation_setFrameEventCallFunc, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + proto.set(jsb_cocostudio_ArmatureDataManager_prototype); + JS_DefineFunction(cx, proto, "addArmatureFileInfoAsync", jsb_Animation_addArmatureFileInfoAsyncCallFunc, 3, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + proto.set(jsb_cocostudio_ActionManagerEx_prototype); + JS_DefineFunction(cx, proto, "initWithDictionaryEx", js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE); JS::RootedObject frame(cx, jsb_cocostudio_timeline_Frame_prototype); JS_DefineFunction(cx, frame, "setEasingParams", js_cocos2dx_studio_Frame_setEasingParams, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE); @@ -1442,7 +1447,8 @@ void register_all_cocos2dx_studio_manual(JSContext* cx, JS::HandleObject global) JS_DefineProperty(cx, movementData, "loop", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_MovementData_loop, js_set_MovementData_loop); JS_DefineProperty(cx, movementData, "tweenEasing", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_MovementData_tweenEasing, js_set_MovementData_tweenEasing); - JS_DefineProperty(cx, JS::RootedObject(cx, jsb_cocostudio_ContourData_prototype), "vertextList", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_ContourData_vertexList, js_set_ContourData_vertexList); + proto.set(jsb_cocostudio_ContourData_prototype); + JS_DefineProperty(cx, proto, "vertextList", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_ContourData_vertexList, js_set_ContourData_vertexList); JS::RootedObject textureData(cx, jsb_cocostudio_TextureData_prototype); JS_DefineProperty(cx, textureData, "contourDataList", JS::UndefinedHandleValue, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, js_get_TextureData_contourDataList, js_set_TextureData_contourDataList); diff --git a/cocos/scripting/js-bindings/manual/component/CCComponentJS.cpp b/cocos/scripting/js-bindings/manual/component/CCComponentJS.cpp index 643a3abde3..a8d81732f4 100644 --- a/cocos/scripting/js-bindings/manual/component/CCComponentJS.cpp +++ b/cocos/scripting/js-bindings/manual/component/CCComponentJS.cpp @@ -61,10 +61,10 @@ ComponentJS::ComponentJS(const std::string& scriptFileName) if (_succeedLoadingScript) { - JSObject* classObj = classValue.toObjectOrNull(); + JS::RootedObject classObj(cx, classValue.toObjectOrNull()); const JSClass* theClass = JS_GetClass(classObj); JS::RootedValue protoValue(cx); - JS_GetProperty(cx, JS::RootedObject(cx, classObj), "prototype", &protoValue); + JS_GetProperty(cx, classObj, "prototype", &protoValue); TypeTest t; js_type_class_t *typeClass = nullptr; diff --git a/cocos/scripting/js-bindings/manual/experimental/jsb_cocos2dx_experimental_video_manual.cpp b/cocos/scripting/js-bindings/manual/experimental/jsb_cocos2dx_experimental_video_manual.cpp index d46c0bc9a6..7f3f343ad5 100644 --- a/cocos/scripting/js-bindings/manual/experimental/jsb_cocos2dx_experimental_video_manual.cpp +++ b/cocos/scripting/js-bindings/manual/experimental/jsb_cocos2dx_experimental_video_manual.cpp @@ -43,7 +43,8 @@ extern JSObject* jsb_cocos2d_experimental_ui_VideoPlayer_prototype; void register_all_cocos2dx_experimental_video_manual(JSContext* cx, JS::HandleObject global) { - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_experimental_ui_VideoPlayer_prototype), "addEventListener", jsb_cocos2dx_experimental_ui_VideoPlayer_addEventListener, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS::RootedObject proto(cx, jsb_cocos2d_experimental_ui_VideoPlayer_prototype); + JS_DefineFunction(cx, proto, "addEventListener", jsb_cocos2dx_experimental_ui_VideoPlayer_addEventListener, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); } #endif diff --git a/cocos/scripting/js-bindings/manual/experimental/jsb_cocos2dx_experimental_webView_manual.cpp b/cocos/scripting/js-bindings/manual/experimental/jsb_cocos2dx_experimental_webView_manual.cpp index e58790c37a..08b0e37cac 100644 --- a/cocos/scripting/js-bindings/manual/experimental/jsb_cocos2dx_experimental_webView_manual.cpp +++ b/cocos/scripting/js-bindings/manual/experimental/jsb_cocos2dx_experimental_webView_manual.cpp @@ -145,10 +145,11 @@ extern JSObject* jsb_cocos2d_experimental_ui_WebView_prototype; void register_all_cocos2dx_experimental_webView_manual(JSContext* cx, JS::HandleObject global) { - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_experimental_ui_WebView_prototype), "setOnShouldStartLoading", jsb_cocos2dx_experimental_webView_setOnShouldStartLoading, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_experimental_ui_WebView_prototype), "setOnDidFinishLoading", jsb_cocos2dx_experimental_webView_setOnDidFinishLoading, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_experimental_ui_WebView_prototype), "setOnDidFailLoading", jsb_cocos2dx_experimental_webView_setOnDidFailLoading, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_experimental_ui_WebView_prototype), "setOnJSCallback", jsb_cocos2dx_experimental_webView_setOnJSCallback, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS::RootedObject proto(cx, jsb_cocos2d_experimental_ui_WebView_prototype); + JS_DefineFunction(cx, proto, "setOnShouldStartLoading", jsb_cocos2dx_experimental_webView_setOnShouldStartLoading, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, proto, "setOnDidFinishLoading", jsb_cocos2dx_experimental_webView_setOnDidFinishLoading, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, proto, "setOnDidFailLoading", jsb_cocos2dx_experimental_webView_setOnDidFailLoading, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, proto, "setOnJSCallback", jsb_cocos2dx_experimental_webView_setOnJSCallback, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); } #endif diff --git a/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp b/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp index 3b2df42968..b3411b3752 100644 --- a/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp +++ b/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp @@ -377,7 +377,8 @@ static bool js_cocos2dx_CCTableView_setDataSource(JSContext *cx, uint32_t argc, if (argc == 1) { JSB_TableViewDataSource* pNativeSource = new JSB_TableViewDataSource(); - pNativeSource->setTableViewDataSource(JS::RootedObject(cx, args.get(0).toObjectOrNull())); + JS::RootedObject jsdata(cx, args.get(0).toObjectOrNull()); + pNativeSource->setTableViewDataSource(jsdata); __Dictionary* userDict = static_cast<__Dictionary*>(cobj->getUserObject()); if (NULL == userDict) @@ -409,7 +410,8 @@ static bool js_cocos2dx_CCTableView_create(JSContext *cx, uint32_t argc, jsval * { JSB_TableViewDataSource* pNativeSource = new JSB_TableViewDataSource(); - pNativeSource->setTableViewDataSource(JS::RootedObject(cx, args.get(0).toObjectOrNull())); + JS::RootedObject jsdata(cx, args.get(0).toObjectOrNull()); + pNativeSource->setTableViewDataSource(jsdata); cocos2d::Size arg1; ok &= jsval_to_ccsize(cx, args.get(1), &arg1); @@ -479,7 +481,8 @@ static bool js_cocos2dx_CCTableView_init(JSContext *cx, uint32_t argc, jsval *vp { JSB_TableViewDataSource* pNativeSource = new JSB_TableViewDataSource(); - pNativeSource->setTableViewDataSource(JS::RootedObject(cx, args.get(0).toObjectOrNull())); + JS::RootedObject jsdata(cx, args.get(0).toObjectOrNull()); + pNativeSource->setTableViewDataSource(jsdata); cobj->setDataSource(pNativeSource); cocos2d::Size arg1; @@ -630,7 +633,8 @@ static bool js_cocos2dx_CCControl_addTargetWithActionForControlEvents(JSContext // save the delegate JSB_ControlButtonTarget* nativeDelegate = new JSB_ControlButtonTarget(); - nativeDelegate->setJSCallback(args.get(1), JS::RootedObject(cx, jsDelegate)); + JS::RootedObject jscb(cx, jsDelegate); + nativeDelegate->setJSCallback(args.get(1), jscb); nativeDelegate->setEventType(arg2); __Array* nativeDelegateArray = static_cast<__Array*>(cobj->getUserObject()); @@ -997,17 +1001,18 @@ void register_all_cocos2dx_extension_manual(JSContext* cx, JS::HandleObject glob JS::RootedObject tmpObj(cx); get_or_create_js_obj(cx, global, "cc", &ccObj); - JS::RootedObject am(cx, jsb_cocos2d_extension_AssetsManagerEx_prototype); - JS_DefineFunction(cx, am, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, am, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS::RootedObject manifest(cx, jsb_cocos2d_extension_Manifest_prototype); - JS_DefineFunction(cx, manifest, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, manifest, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + tmpObj.set(jsb_cocos2d_extension_AssetsManagerEx_prototype); + JS_DefineFunction(cx, tmpObj, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + tmpObj.set(jsb_cocos2d_extension_Manifest_prototype); + JS_DefineFunction(cx, tmpObj, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); //JS_DefineFunction(cx, jsb_cocos2d_extension_AssetsManager_prototype, "updateAssets", js_cocos2dx_ext_AssetsManager_updateAssets, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); //JS_DefineFunction(cx, jsb_cocos2d_extension_AssetsManager_prototype, "getFailedAssets", js_cocos2dx_ext_AssetsManager_getFailedAssets, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_extension_ScrollView_prototype), "setDelegate", js_cocos2dx_CCScrollView_setDelegate, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + tmpObj.set(jsb_cocos2d_extension_ScrollView_prototype); + JS_DefineFunction(cx, tmpObj, "setDelegate", js_cocos2dx_CCScrollView_setDelegate, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS::RootedObject tableview(cx, jsb_cocos2d_extension_TableView_prototype); JS_DefineFunction(cx, tableview, "setDelegate", js_cocos2dx_CCTableView_setDelegate, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS_DefineFunction(cx, tableview, "setDataSource", js_cocos2dx_CCTableView_setDataSource, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); @@ -1017,7 +1022,7 @@ void register_all_cocos2dx_extension_manual(JSContext* cx, JS::HandleObject glob JS_DefineFunction(cx, control, "removeTargetWithActionForControlEvents", js_cocos2dx_CCControl_removeTargetWithActionForControlEvents, 3, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS_GetProperty(cx, ccObj, "TableView", &tmpVal); - tmpObj = tmpVal.toObjectOrNull(); + tmpObj.set(tmpVal.toObjectOrNull()); JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_CCTableView_create, 3, JSPROP_READONLY | JSPROP_PERMANENT); JS::RootedObject jsbObj(cx); diff --git a/cocos/scripting/js-bindings/manual/js_bindings_opengl.cpp b/cocos/scripting/js-bindings/manual/js_bindings_opengl.cpp index 9b7a9663b0..3b6251b5c1 100644 --- a/cocos/scripting/js-bindings/manual/js_bindings_opengl.cpp +++ b/cocos/scripting/js-bindings/manual/js_bindings_opengl.cpp @@ -85,7 +85,9 @@ bool js_cocos2dx_GLNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *obj = JS_NewObject(cx, typeClass->jsclass, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto)); + JS::RootedObject proto(cx, typeClass->proto.ref()); + JS::RootedObject parentProto(cx, typeClass->parentProto.ref()); + JSObject *obj = JS_NewObject(cx, typeClass->jsclass, proto, parentProto); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object @@ -159,32 +161,21 @@ void js_register_cocos2dx_GLNode(JSContext *cx, JS::HandleObject global) { JS_FN("create", js_cocos2dx_GLNode_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; - + + JS::RootedObject parentProto(cx, jsb_cocos2d_Node_prototype); js_cocos2dx_GLNode_prototype = JS_InitClass( cx, global, - JS::RootedObject(cx, jsb_cocos2d_Node_prototype), + parentProto, js_cocos2dx_GLNode_class, js_cocos2dx_GLNode_constructor, 0, // constructor properties, funcs, NULL, // no static properties st_funcs); - // make the class enumerable in the registered namespace -// bool found; -// JS_SetPropertyAttributes(cx, global, "GLNode", JSPROP_ENUMERATE | JSPROP_READONLY, &found); - - // add the proto and JSClass to the type->js info hash table - TypeTest t; - js_type_class_t *p; - std::string typeName = t.s_name(); - if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) - { - p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = js_cocos2dx_GLNode_class; - p->proto = js_cocos2dx_GLNode_prototype; - p->parentProto = jsb_cocos2d_Node_prototype; - _js_global_type_map.insert(std::make_pair(typeName, p)); - } + // add the proto and JSClass to the type->js info hash table + JS::RootedObject proto(cx, js_cocos2dx_GLNode_prototype); + jsb_register_class(cx, js_cocos2dx_GLNode_class, proto, parentProto); + anonEvaluate(cx, global, "(function () { cc.GLNode.extend = cc.Class.extend; })()"); } diff --git a/cocos/scripting/js-bindings/manual/js_manual_conversions.cpp b/cocos/scripting/js-bindings/manual/js_manual_conversions.cpp index a2645181c1..1214e32f89 100644 --- a/cocos/scripting/js-bindings/manual/js_manual_conversions.cpp +++ b/cocos/scripting/js-bindings/manual/js_manual_conversions.cpp @@ -73,15 +73,8 @@ void JSStringWrapper::set(JSString* str, JSContext* cx) { cx = ScriptingCore::getInstance()->getGlobalContext(); } - // JS_EncodeString isn't supported in SpiderMonkey ff19.0. - //buffer = JS_EncodeString(cx, string); - - //JS_GetStringCharsZ is removed in SpiderMonkey 33 -// unsigned short* pStrUTF16 = (unsigned short*)JS_GetStringCharsZ(cx, str); - -// _buffer = cc_utf16_to_utf8(pStrUTF16, -1, NULL, NULL); - - _buffer = JS_EncodeStringToUTF8(cx, JS::RootedString(cx, str)); + JS::RootedString jsstr(cx, str); + _buffer = JS_EncodeStringToUTF8(cx, jsstr); } const char* JSStringWrapper::get() @@ -315,7 +308,7 @@ bool jsval_to_charptr( JSContext *cx, JS::HandleValue vp, const char **ret ) JSStringWrapper strWrapper(jsstr); // XXX: It is converted to String and then back to char* to autorelease the created object. - __String *tmp = String::create(strWrapper.get()); + __String *tmp = __String::create(strWrapper.get()); JSB_PRECONDITION2( tmp, cx, false, "Error creating string from UTF8"); @@ -696,27 +689,28 @@ bool jsval_to_ray(JSContext *cx, JS::HandleValue v, cocos2d::Ray* ret) bool jsvals_variadic_to_ccarray( JSContext *cx, jsval *vp, int argc, __Array** ret) { bool ok = true; - __Array* pArray = Array::create(); + __Array* pArray = __Array::create(); for( int i=0; i < argc; i++ ) { double num = 0.0; // optimization: JS::ToNumber is expensive. And can convert an string like "12" to a number - if (vp->isNumber()) { - ok &= JS::ToNumber(cx, JS::RootedValue(cx, *vp), &num ); + JS::RootedValue jsv(cx, *vp); + if (jsv.isNumber()) { + ok &= JS::ToNumber(cx, jsv, &num ); if (!ok) { break; } - pArray->addObject(Integer::create((int)num)); + pArray->addObject(__Integer::create((int)num)); } - else if (vp->isString()) + else if (jsv.isString()) { - JSStringWrapper str(vp->toString(), cx); - pArray->addObject(String::create(str.get())); + JSStringWrapper str(jsv, cx); + pArray->addObject(__String::create(str.get())); } else { js_proxy_t* p; - JSObject* obj = vp->toObjectOrNull(); + JS::RootedObject obj(cx, jsv.toObjectOrNull()); p = jsb_get_js_proxy(obj); if (p) { pArray->addObject((Ref*)p->ptr); @@ -1003,20 +997,20 @@ bool jsval_to_ccarray(JSContext* cx, JS::HandleValue v, __Array** ret) } else if (value.isString()) { JSStringWrapper valueWapper(value.toString(), cx); - arr->addObject(String::create(valueWapper.get())); + arr->addObject(__String::create(valueWapper.get())); // CCLOG("iterate array: value = %s", valueWapper.get().c_str()); } else if (value.isNumber()) { double number = 0.0; ok = JS::ToNumber(cx, value, &number); if (ok) { - arr->addObject(Double::create(number)); + arr->addObject(__Double::create(number)); // CCLOG("iterate array: value = %lf", number); } } else if (value.isBoolean()) { bool boolVal = JS::ToBoolean(value); - arr->addObject(Bool::create(boolVal)); + arr->addObject(__Bool::create(boolVal)); // CCLOG("iterate object: value = %d", boolVal); } else { @@ -1928,20 +1922,20 @@ bool jsval_to_ccdictionary(JSContext* cx, JS::HandleValue v, __Dictionary** ret) } else if (value.isString()) { JSStringWrapper valueWapper(value.toString(), cx); - dict->setObject(String::create(valueWapper.get()), keyWrapper.get()); + dict->setObject(__String::create(valueWapper.get()), keyWrapper.get()); // CCLOG("iterate object: key = %s, value = %s", keyWrapper.get().c_str(), valueWapper.get().c_str()); } else if (value.isNumber()) { double number = 0.0; bool ok = JS::ToNumber(cx, value, &number); if (ok) { - dict->setObject(Double::create(number), keyWrapper.get()); + dict->setObject(__Double::create(number), keyWrapper.get()); // CCLOG("iterate object: key = %s, value = %lf", keyWrapper.get().c_str(), number); } } else if (value.isBoolean()) { bool boolVal = JS::ToBoolean(value); - dict->setObject(Bool::create(boolVal), keyWrapper.get()); + dict->setObject(__Bool::create(boolVal), keyWrapper.get()); // CCLOG("iterate object: key = %s, value = %d", keyWrapper.get().c_str(), boolVal); } else { @@ -2184,10 +2178,11 @@ jsval uniform_to_jsval(JSContext* cx, const cocos2d::Uniform* uniform) { JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if(!tmp) return JSVAL_NULL; + JS::RootedValue jsname(cx, std_string_to_jsval(cx, uniform->name)); bool ok = JS_DefineProperty(cx, tmp, "location", uniform->location, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "size", uniform->size, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "type", uniform->type, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "name", JS::RootedValue(cx, std_string_to_jsval(cx, uniform->name)), JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineProperty(cx, tmp, "name", jsname, JSPROP_ENUMERATE | JSPROP_PERMANENT); if(ok) return OBJECT_TO_JSVAL(tmp); @@ -2214,39 +2209,33 @@ jsval FontDefinition_to_jsval(JSContext* cx, const FontDefinition& t) JS::RootedObject proto(cx); JS::RootedObject parent(cx); JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, proto, parent)); -// if (!tmp) return JSVAL_NULL; + JS::RootedValue prop(cx); + bool ok = true; - - ok &= JS_DefineProperty(cx, tmp, "fontName", JS::RootedValue(cx, std_string_to_jsval(cx, t._fontName)), JSPROP_ENUMERATE | JSPROP_PERMANENT); + prop.set(std_string_to_jsval(cx, t._fontName)); + ok &= JS_DefineProperty(cx, tmp, "fontName", prop, JSPROP_ENUMERATE | JSPROP_PERMANENT); ok &= JS_DefineProperty(cx, tmp, "fontSize", t._fontSize, JSPROP_ENUMERATE | JSPROP_PERMANENT); - ok &= JS_DefineProperty(cx, tmp, "textAlign", (int32_t)t._alignment, JSPROP_ENUMERATE | JSPROP_PERMANENT); - ok &= JS_DefineProperty(cx, tmp, "verticalAlign", (int32_t)t._vertAlignment, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - ok &= JS_DefineProperty(cx, tmp, "fillStyle", JS::RootedValue(cx, cccolor3b_to_jsval(cx, t._fontFillColor)), JSPROP_ENUMERATE | JSPROP_PERMANENT); - + prop.set(cccolor3b_to_jsval(cx, t._fontFillColor)); + ok &= JS_DefineProperty(cx, tmp, "fillStyle", prop, JSPROP_ENUMERATE | JSPROP_PERMANENT); ok &= JS_DefineProperty(cx, tmp, "boundingWidth", t._dimensions.width, JSPROP_ENUMERATE | JSPROP_PERMANENT); - ok &= JS_DefineProperty(cx, tmp, "boundingHeight", t._dimensions.height, JSPROP_ENUMERATE | JSPROP_PERMANENT); // Shadow - ok &= JS_DefineProperty(cx, tmp, "shadowEnabled", JS::RootedValue(cx, BOOLEAN_TO_JSVAL(t._shadow._shadowEnabled)), JSPROP_ENUMERATE | JSPROP_PERMANENT); - + prop.set(BOOLEAN_TO_JSVAL(t._shadow._shadowEnabled)); + ok &= JS_DefineProperty(cx, tmp, "shadowEnabled", prop, JSPROP_ENUMERATE | JSPROP_PERMANENT); ok &= JS_DefineProperty(cx, tmp, "shadowOffsetX", t._shadow._shadowOffset.width, JSPROP_ENUMERATE | JSPROP_PERMANENT); - ok &= JS_DefineProperty(cx, tmp, "shadowOffsetY", t._shadow._shadowOffset.height, JSPROP_ENUMERATE | JSPROP_PERMANENT); - ok &= JS_DefineProperty(cx, tmp, "shadowBlur", t._shadow._shadowBlur, JSPROP_ENUMERATE | JSPROP_PERMANENT); - ok &= JS_DefineProperty(cx, tmp, "shadowOpacity", t._shadow._shadowOpacity, JSPROP_ENUMERATE | JSPROP_PERMANENT); // Stroke - ok &= JS_DefineProperty(cx, tmp, "strokeEnabled", JS::RootedValue(cx, BOOLEAN_TO_JSVAL(t._stroke._strokeEnabled)), JSPROP_ENUMERATE | JSPROP_PERMANENT); - - ok &= JS_DefineProperty(cx, tmp, "strokeStyle", JS::RootedValue(cx, cccolor3b_to_jsval(cx, t._stroke._strokeColor)), JSPROP_ENUMERATE | JSPROP_PERMANENT); - + prop.set(BOOLEAN_TO_JSVAL(t._stroke._strokeEnabled)); + ok &= JS_DefineProperty(cx, tmp, "strokeEnabled", prop, JSPROP_ENUMERATE | JSPROP_PERMANENT); + prop.set(cccolor3b_to_jsval(cx, t._stroke._strokeColor)); + ok &= JS_DefineProperty(cx, tmp, "strokeStyle", prop, JSPROP_ENUMERATE | JSPROP_PERMANENT); ok &= JS_DefineProperty(cx, tmp, "lineWidth", t._stroke._strokeSize, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { @@ -2343,7 +2332,8 @@ bool jsval_to_FontDefinition( JSContext *cx, JS::HandleValue vp, FontDefinition JS_GetProperty(cx, jsobj, "fillStyle", &jsr); JS::RootedObject jsobjColor(cx); - if (!JS_ValueToObject( cx, JS::RootedValue(cx, jsr), &jsobjColor ) ) + JS::RootedValue jsvalColor(cx, jsr); + if (!JS_ValueToObject( cx, jsvalColor, &jsobjColor ) ) return false; out->_fontFillColor = getColorFromJSObject(cx, jsobjColor); diff --git a/cocos/scripting/js-bindings/manual/js_manual_conversions.h b/cocos/scripting/js-bindings/manual/js_manual_conversions.h index 646348ff85..738ab0a337 100644 --- a/cocos/scripting/js-bindings/manual/js_manual_conversions.h +++ b/cocos/scripting/js-bindings/manual/js_manual_conversions.h @@ -123,14 +123,13 @@ bool jsvals_variadic_to_ccvector( JSContext *cx, /*jsval *vp, int argc,*/const J for (int i = 0; i < args.length(); i++) { js_proxy_t* p; - JSObject* obj = JS::RootedValue(cx, args.get(i)).toObjectOrNull(); + JS::RootedObject obj(cx, args.get(i).toObjectOrNull()); p = jsb_get_js_proxy(obj); CCASSERT(p, "Native object not found!"); if (p) { ret->pushBack((T)p->ptr); } - } JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); diff --git a/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp b/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp index c960160cca..eb8f4edd0c 100644 --- a/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp +++ b/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp @@ -273,9 +273,10 @@ bool JSB_glGetActiveAttrib(JSContext *cx, uint32_t argc, jsval *vp) JS::RootedObject object(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr() )); JSB_PRECONDITION2(ok, cx, false, "Error creating JS Object"); + JS::RootedValue jsname(cx, charptr_to_jsval(cx, buffer)); if (!JS_DefineProperty(cx, object, "size", (int32_t)size, JSPROP_ENUMERATE | JSPROP_PERMANENT) || !JS_DefineProperty(cx, object, "type", (int32_t)type, JSPROP_ENUMERATE | JSPROP_PERMANENT) || - !JS_DefineProperty(cx, object, "name", JS::RootedValue(cx, charptr_to_jsval(cx, buffer)), JSPROP_ENUMERATE | JSPROP_PERMANENT) ) + !JS_DefineProperty(cx, object, "name", jsname, JSPROP_ENUMERATE | JSPROP_PERMANENT) ) return false; retval = OBJECT_TO_JSVAL(object); @@ -317,9 +318,10 @@ bool JSB_glGetActiveUniform(JSContext *cx, uint32_t argc, jsval *vp) JS::RootedObject object(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr() )); JSB_PRECONDITION2(ok, cx, false, "Error creating JS Object"); + JS::RootedValue jsname(cx, charptr_to_jsval(cx, buffer)); if (!JS_DefineProperty(cx, object, "size", (int32_t)size, JSPROP_ENUMERATE | JSPROP_PERMANENT) || !JS_DefineProperty(cx, object, "type", (int32_t)type, JSPROP_ENUMERATE | JSPROP_PERMANENT) || - !JS_DefineProperty(cx, object, "name", JS::RootedValue(cx, charptr_to_jsval(cx, buffer)), JSPROP_ENUMERATE | JSPROP_PERMANENT) ) + !JS_DefineProperty(cx, object, "name", jsname, JSPROP_ENUMERATE | JSPROP_PERMANENT) ) return false; retval = OBJECT_TO_JSVAL(object); diff --git a/cocos/scripting/js-bindings/manual/localstorage/js_bindings_system_registration.cpp b/cocos/scripting/js-bindings/manual/localstorage/js_bindings_system_registration.cpp index 6474c62a32..4bb4edf400 100644 --- a/cocos/scripting/js-bindings/manual/localstorage/js_bindings_system_registration.cpp +++ b/cocos/scripting/js-bindings/manual/localstorage/js_bindings_system_registration.cpp @@ -37,23 +37,22 @@ void jsb_register_system( JSContext *_cx, JS::HandleObject object) // JS::RootedObject proto(_cx); JS::RootedObject parent(_cx); - JSObject *sys = JS_NewObject(_cx, nullptr, proto, parent); + JS::RootedObject sys(_cx, JS_NewObject(_cx, nullptr, proto, parent)); JS::RootedValue systemVal(_cx); - systemVal = OBJECT_TO_JSVAL(sys); + systemVal.set(OBJECT_TO_JSVAL(sys)); JS_SetProperty(_cx, object, "sys", systemVal); // sys.localStorage JSObject *ls = JS_NewObject(_cx, nullptr, proto, parent); JS::RootedValue lsVal(_cx); - lsVal = OBJECT_TO_JSVAL(ls); - JS_SetProperty(_cx, JS::RootedObject(_cx, sys), "localStorage", lsVal); + lsVal.set(OBJECT_TO_JSVAL(ls)); + JS_SetProperty(_cx, sys, "localStorage", lsVal); // sys.localStorage functions JS::RootedObject system(_cx, ls); #include "js_bindings_system_functions_registration.h" - // Init DB with full path //NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; //NSString *fullpath = [path stringByAppendingPathComponent:@"jsb.sqlite"]; diff --git a/cocos/scripting/js-bindings/manual/navmesh/jsb_cocos2dx_navmesh_conversions.cpp b/cocos/scripting/js-bindings/manual/navmesh/jsb_cocos2dx_navmesh_conversions.cpp index 6d8500e015..f952c33f62 100644 --- a/cocos/scripting/js-bindings/manual/navmesh/jsb_cocos2dx_navmesh_conversions.cpp +++ b/cocos/scripting/js-bindings/manual/navmesh/jsb_cocos2dx_navmesh_conversions.cpp @@ -84,8 +84,10 @@ jsval offMeshLinkData_to_jsval(JSContext* cx, const cocos2d::OffMeshLinkData& v) JS::RootedObject parent(cx); JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, proto, parent)); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "startPosition", JS::RootedValue(cx, vector3_to_jsval(cx, v.startPosition)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "endPosition", JS::RootedValue(cx, vector3_to_jsval(cx, v.endPosition)), JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS::RootedValue jsstartPos(cx, vector3_to_jsval(cx, v.startPosition)); + JS::RootedValue jsendPos(cx, vector3_to_jsval(cx, v.endPosition)); + bool ok = JS_DefineProperty(cx, tmp, "startPosition", jsstartPos, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "endPosition", jsendPos, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { return OBJECT_TO_JSVAL(tmp); } diff --git a/cocos/scripting/js-bindings/manual/navmesh/jsb_cocos2dx_navmesh_manual.cpp b/cocos/scripting/js-bindings/manual/navmesh/jsb_cocos2dx_navmesh_manual.cpp index 313cee7be4..64bbfaaf32 100644 --- a/cocos/scripting/js-bindings/manual/navmesh/jsb_cocos2dx_navmesh_manual.cpp +++ b/cocos/scripting/js-bindings/manual/navmesh/jsb_cocos2dx_navmesh_manual.cpp @@ -83,6 +83,7 @@ extern JSObject *jsb_cocos2d_NavMeshAgent_prototype; void register_all_cocos2dx_navmesh_manual(JSContext *cx, JS::HandleObject global) { - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_NavMeshAgent_prototype), "move", jsb_cocos2dx_navmesh_NavMeshAgent_move, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS::RootedObject proto(cx, jsb_cocos2d_NavMeshAgent_prototype); + JS_DefineFunction(cx, proto, "move", jsb_cocos2dx_navmesh_NavMeshAgent_move, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); } #endif //#if CC_USE_NAVMESH diff --git a/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp b/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp index 29008bffe7..b71eb88b94 100644 --- a/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp +++ b/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp @@ -341,7 +341,9 @@ JS_BINDED_CONSTRUCTOR_IMPL(MinXmlHttpRequest) js_proxy_t *p; jsval out; - JSObject *obj = JS_NewObject(cx, &MinXmlHttpRequest::js_class, JS::RootedObject(cx, MinXmlHttpRequest::js_proto), JS::RootedObject(cx, MinXmlHttpRequest::js_parent)); + JS::RootedObject proto(cx, MinXmlHttpRequest::js_proto); + JS::RootedObject parentProto(cx, MinXmlHttpRequest::js_parent); + JSObject *obj = JS_NewObject(cx, &MinXmlHttpRequest::js_class, proto, parentProto); if (obj) { JS_SetPrivate(obj, req); @@ -519,7 +521,7 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, readyState) */ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, status) { - args.rval().set(INT_TO_JSVAL(_status)); + args.rval().set(INT_TO_JSVAL((int)_status)); return true; } @@ -621,7 +623,8 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, response) //size_t utf16Count = 0; //const jschar* utf16Buf = JS_GetStringCharsZAndLength(cx, JSVAL_TO_STRING(strVal), &utf16Count); //bool ok = JS_ParseJSON(cx, utf16Buf, static_cast(utf16Count), &outVal); - bool ok = JS_ParseJSON(cx, JS::RootedString(cx, strVal.toString()), &outVal); + JS::RootedString jsstr(cx, strVal.toString()); + bool ok = JS_ParseJSON(cx, jsstr, &outVal); if (ok) { diff --git a/cocos/scripting/js-bindings/manual/network/jsb_socketio.cpp b/cocos/scripting/js-bindings/manual/network/jsb_socketio.cpp index 309f09b0ac..0714054adf 100644 --- a/cocos/scripting/js-bindings/manual/network/jsb_socketio.cpp +++ b/cocos/scripting/js-bindings/manual/network/jsb_socketio.cpp @@ -169,9 +169,11 @@ bool js_cocos2dx_SocketIO_connect(JSContext* cx, uint32_t argc, jsval* vp) if(!p) { //previous connection not found, create a new one - JSObject *obj = JS_NewObject(cx, js_cocos2dx_socketio_class, JS::RootedObject(cx, js_cocos2dx_socketio_prototype), JS::NullPtr()); + JS::RootedObject proto(cx, js_cocos2dx_socketio_prototype); + JSObject *obj = JS_NewObject(cx, js_cocos2dx_socketio_class, proto, JS::NullPtr()); p = jsb_new_proxy(ret, obj); - siodelegate->setJSDelegate(JS::RootedObject(cx, p->obj)); + JS::RootedObject jsdelegate(cx, p->obj); + siodelegate->setJSDelegate(jsdelegate); } jsret = OBJECT_TO_JSVAL(p->obj); } diff --git a/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp b/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp index 4e293e4da8..bc4229416e 100644 --- a/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp +++ b/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp @@ -263,7 +263,8 @@ bool js_cocos2dx_extension_WebSocket_constructor(JSContext *cx, uint32_t argc, j JSB_PRECONDITION2( ok, cx, false, "Error processing arguments"); } while (0); - JS::RootedObject obj(cx, JS_NewObject(cx, js_cocos2dx_websocket_class, JS::RootedObject(cx, js_cocos2dx_websocket_prototype), JS::NullPtr())); + JS::RootedObject proto(cx, js_cocos2dx_websocket_prototype); + JS::RootedObject obj(cx, JS_NewObject(cx, js_cocos2dx_websocket_class, proto, JS::NullPtr())); //JS::RootedObject obj(cx, JS_NewObjectForConstructor(cx, js_cocos2dx_websocket_class, args)); WebSocket* cobj = new WebSocket(); @@ -316,7 +317,8 @@ bool js_cocos2dx_extension_WebSocket_constructor(JSContext *cx, uint32_t argc, j JS_DefineProperty(cx, obj, "URL", args.get(0), JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); //protocol not support yet (always return "") - JS_DefineProperty(cx, obj, "protocol", JS::RootedValue(cx, c_string_to_jsval(cx, "")), JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); + JS::RootedValue jsprotocol(cx, c_string_to_jsval(cx, "")); + JS_DefineProperty(cx, obj, "protocol", jsprotocol, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); // link the native object with the javascript object js_proxy_t *p = jsb_new_proxy(cobj, obj); @@ -392,10 +394,6 @@ void register_jsb_websocket(JSContext *cx, JS::HandleObject global) { JS_DefineProperty(cx, jsclassObj, "OPEN", (int)WebSocket::State::OPEN, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); JS_DefineProperty(cx, jsclassObj, "CLOSING", (int)WebSocket::State::CLOSING, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); JS_DefineProperty(cx, jsclassObj, "CLOSED", (int)WebSocket::State::CLOSED, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); - - // make the class enumerable in the registered namespace -//FIXME: bool found; -// JS_SetPropertyAttributes(cx, global, "WebSocket", JSPROP_ENUMERATE | JSPROP_READONLY, &found); } diff --git a/cocos/scripting/js-bindings/manual/physics3d/jsb_cocos2dx_physics3d_manual.cpp b/cocos/scripting/js-bindings/manual/physics3d/jsb_cocos2dx_physics3d_manual.cpp index 203e94c50b..4a96368d95 100644 --- a/cocos/scripting/js-bindings/manual/physics3d/jsb_cocos2dx_physics3d_manual.cpp +++ b/cocos/scripting/js-bindings/manual/physics3d/jsb_cocos2dx_physics3d_manual.cpp @@ -222,11 +222,16 @@ jsval physics3d_collisionPoint_to_jsval(JSContext*cx, const Physics3DCollisionIn { JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); - JS_DefineProperty(cx, tmp, "localPositionOnA", JS::RootedValue(cx, vector3_to_jsval(cx, point.localPositionOnA)), JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineProperty(cx, tmp, "localPositionOnB", JS::RootedValue(cx, vector3_to_jsval(cx, point.localPositionOnB)), JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineProperty(cx, tmp, "worldPositionOnA", JS::RootedValue(cx, vector3_to_jsval(cx, point.worldPositionOnA)), JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineProperty(cx, tmp, "worldPositionOnB", JS::RootedValue(cx, vector3_to_jsval(cx, point.worldPositionOnB)), JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineProperty(cx, tmp, "worldNormalOnB", JS::RootedValue(cx, vector3_to_jsval(cx, point.worldNormalOnB)), JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS::RootedValue prop(cx, vector3_to_jsval(cx, point.localPositionOnA)); + JS_DefineProperty(cx, tmp, "localPositionOnA", prop, JSPROP_ENUMERATE | JSPROP_PERMANENT); + prop.set(vector3_to_jsval(cx, point.localPositionOnB)); + JS_DefineProperty(cx, tmp, "localPositionOnB", prop, JSPROP_ENUMERATE | JSPROP_PERMANENT); + prop.set(vector3_to_jsval(cx, point.worldPositionOnA)); + JS_DefineProperty(cx, tmp, "worldPositionOnA", prop, JSPROP_ENUMERATE | JSPROP_PERMANENT); + prop.set(vector3_to_jsval(cx, point.worldPositionOnB)); + JS_DefineProperty(cx, tmp, "worldPositionOnB", prop, JSPROP_ENUMERATE | JSPROP_PERMANENT); + prop.set(vector3_to_jsval(cx, point.worldNormalOnB)); + JS_DefineProperty(cx, tmp, "worldNormalOnB", prop, JSPROP_ENUMERATE | JSPROP_PERMANENT); return OBJECT_TO_JSVAL(tmp); } @@ -236,10 +241,12 @@ jsval physics3d_collisioninfo_to_jsval(JSContext* cx, const Physics3DCollisionIn JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); js_proxy_t* proxy = js_get_or_create_proxy(cx, ci.objA); - JS_DefineProperty(cx, tmp, "objA", JS::RootedValue(cx, OBJECT_TO_JSVAL(proxy->obj)), JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS::RootedValue prop(cx, OBJECT_TO_JSVAL(proxy->obj)); + JS_DefineProperty(cx, tmp, "objA", prop, JSPROP_ENUMERATE | JSPROP_PERMANENT); proxy = js_get_or_create_proxy(cx, ci.objB); - JS_DefineProperty(cx, tmp, "objB", JS::RootedValue(cx, OBJECT_TO_JSVAL(proxy->obj)), JSPROP_ENUMERATE | JSPROP_PERMANENT); + prop.set(OBJECT_TO_JSVAL(proxy->obj)); + JS_DefineProperty(cx, tmp, "objB", prop, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS::RootedObject jsarr(cx, JS_NewArrayObject(cx, ci.collisionPointList.size())); uint32_t i = 0; @@ -248,7 +255,8 @@ jsval physics3d_collisioninfo_to_jsval(JSContext* cx, const Physics3DCollisionIn JS::RootedValue element(cx, physics3d_collisionPoint_to_jsval(cx, *iter)); JS_SetElement(cx, jsarr, i++, element); } - JS_DefineProperty(cx, tmp, "collisionPointList", JS::RootedValue(cx, OBJECT_TO_JSVAL(jsarr)), JSPROP_ENUMERATE | JSPROP_PERMANENT); + prop.set(OBJECT_TO_JSVAL(jsarr)); + JS_DefineProperty(cx, tmp, "collisionPointList", prop, JSPROP_ENUMERATE | JSPROP_PERMANENT); return OBJECT_TO_JSVAL(tmp); } @@ -265,7 +273,8 @@ bool jsb_cocos2d_Physics3DObject_setCollisionCallback(JSContext *cx, uint32_t ar JSB_PRECONDITION2( cobj, cx, false, "jsb_cocos2d_Physics3DObject_setCollisionCallback : Invalid Native Object"); std::function arg0; - std::shared_ptr func(new JSFunctionWrapper(cx, JS::RootedObject(cx, args.get(1).toObjectOrNull()), args.get(0))); + JS::RootedObject jstarget(cx, args.get(1).toObjectOrNull()); + std::shared_ptr func(new JSFunctionWrapper(cx, jstarget, args.get(0))); auto lambda = [=](const Physics3DCollisionInfo &ci) -> void { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET @@ -473,20 +482,23 @@ void register_all_cocos2dx_physics3d_manual(JSContext *cx, JS::HandleObject glob JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_PhysicsSprite3D_create, 2, JSPROP_READONLY | JSPROP_PERMANENT); JS_GetProperty(cx, ccObj, "Physics3DRigidBody", &tmpVal); - tmpObj = tmpVal.toObjectOrNull(); + tmpObj.set(tmpVal.toObjectOrNull()); JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_physics3d_Physics3DRigidBody_create, 1, JSPROP_READONLY | JSPROP_PERMANENT); JS_GetProperty(cx, ccObj, "Physics3DShape", &tmpVal); - tmpObj = tmpVal.toObjectOrNull(); + tmpObj.set(tmpVal.toObjectOrNull()); JS_DefineFunction(cx, tmpObj, "createMesh", js_cocos2dx_physics3d_Physics3dShape_createMesh, 2, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx, tmpObj, "createHeightfield", js_cocos2dx_physics3d_Physics3dShape_createHeightfield, 8, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Physics3DShape_prototype), "initMesh", js_cocos2dx_physics3d_Physics3dShape_initMesh, 2, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Physics3DShape_prototype), "initHeightfield", js_cocos2dx_physics3d_Physics3dShape_initHeightfield, 8, JSPROP_READONLY | JSPROP_PERMANENT); + tmpObj.set(jsb_cocos2d_Physics3DShape_prototype); + JS_DefineFunction(cx, tmpObj, "initMesh", js_cocos2dx_physics3d_Physics3dShape_initMesh, 2, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, tmpObj, "initHeightfield", js_cocos2dx_physics3d_Physics3dShape_initHeightfield, 8, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Physics3DObject_prototype), "setCollisionCallback", jsb_cocos2d_Physics3DObject_setCollisionCallback, 2, JSPROP_READONLY | JSPROP_PERMANENT); + tmpObj.set(jsb_cocos2d_Physics3DObject_prototype); + JS_DefineFunction(cx, tmpObj, "setCollisionCallback", jsb_cocos2d_Physics3DObject_setCollisionCallback, 2, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Physics3DWorld_prototype), "rayCast", js_cocos2dx_physics3d_Physics3DWorld_rayCast, 2, JSPROP_READONLY | JSPROP_PERMANENT); + tmpObj.set(jsb_cocos2d_Physics3DWorld_prototype); + JS_DefineFunction(cx, tmpObj, "rayCast", js_cocos2dx_physics3d_Physics3DWorld_rayCast, 2, JSPROP_READONLY | JSPROP_PERMANENT); } #endif //CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION diff --git a/cocos/scripting/js-bindings/manual/platform/ios/JavaScriptObjCBridge.mm b/cocos/scripting/js-bindings/manual/platform/ios/JavaScriptObjCBridge.mm index 49dd7ee51b..daf362021b 100644 --- a/cocos/scripting/js-bindings/manual/platform/ios/JavaScriptObjCBridge.mm +++ b/cocos/scripting/js-bindings/manual/platform/ios/JavaScriptObjCBridge.mm @@ -48,6 +48,8 @@ JS::Value JavaScriptObjCBridge::convertReturnValue(JSContext *cx, ReturnValue re return BOOLEAN_TO_JSVAL(retValue.boolValue); case TypeString: return c_string_to_jsval(cx, retValue.stringValue->c_str(),retValue.stringValue->size()); + default: + break; } return ret; @@ -74,11 +76,13 @@ bool JavaScriptObjCBridge::CallInfo::execute(JSContext *cx,jsval *argv,unsigned [m_dic setObject:[NSString stringWithCString:valueWapper.get() encoding:NSUTF8StringEncoding] forKey:key]; }else if(arg.isNumber()){ double a; - ok &= JS::ToNumber(cx, JS::RootedValue(cx,arg), &a); + JS::RootedValue jsa(cx,arg); + ok &= JS::ToNumber(cx, jsa, &a); [m_dic setObject:[NSNumber numberWithFloat:a] forKey:key]; }else if(arg.isBoolean()){ - bool a = JS::ToBoolean(JS::RootedValue(cx,arg)); + JS::RootedValue jsa(cx,arg); + bool a = JS::ToBoolean(jsa); [m_dic setObject:[NSNumber numberWithBool:a] forKey:key]; } } @@ -233,7 +237,9 @@ JS_BINDED_CONSTRUCTOR_IMPL(JavaScriptObjCBridge) js_proxy_t *p; jsval out; - JSObject *obj = JS_NewObject(cx, &JavaScriptObjCBridge::js_class, JS::RootedObject(cx, JavaScriptObjCBridge::js_proto), JS::RootedObject(cx, JavaScriptObjCBridge::js_parent)); + JS::RootedObject proto(cx, JavaScriptObjCBridge::js_proto); + JS::RootedObject parentProto(cx, JavaScriptObjCBridge::js_parent); + JSObject *obj = JS_NewObject(cx, &JavaScriptObjCBridge::js_class, proto, parentProto); if (obj) { JS_SetPrivate(obj, jsj); diff --git a/cocos/scripting/js-bindings/manual/spidermonkey_specifics.h b/cocos/scripting/js-bindings/manual/spidermonkey_specifics.h index 90adaadc81..535752474a 100644 --- a/cocos/scripting/js-bindings/manual/spidermonkey_specifics.h +++ b/cocos/scripting/js-bindings/manual/spidermonkey_specifics.h @@ -26,6 +26,7 @@ #include "jsapi.h" #include "jsfriendapi.h" #include "uthash.h" +#include "mozilla/Maybe.h" #include typedef struct js_proxy { @@ -39,8 +40,8 @@ extern js_proxy_t *_js_native_global_ht; typedef struct js_type_class { JSClass *jsclass; - JS::Heap proto; - JS::Heap parentProto; + mozilla::Maybe proto; + mozilla::Maybe parentProto; } js_type_class_t; extern std::unordered_map _js_global_type_map; diff --git a/cocos/scripting/js-bindings/manual/spine/jsb_cocos2dx_spine_manual.cpp b/cocos/scripting/js-bindings/manual/spine/jsb_cocos2dx_spine_manual.cpp index 79147fce85..bee3f344a3 100644 --- a/cocos/scripting/js-bindings/manual/spine/jsb_cocos2dx_spine_manual.cpp +++ b/cocos/scripting/js-bindings/manual/spine/jsb_cocos2dx_spine_manual.cpp @@ -32,10 +32,12 @@ jsval speventdata_to_jsval(JSContext* cx, spEventData& v) { JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "name", JS::RootedValue(cx, c_string_to_jsval(cx, v.name)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS::RootedValue jsname(cx, c_string_to_jsval(cx, v.name)); + JS::RootedValue jsstr(cx, c_string_to_jsval(cx, v.stringValue)); + bool ok = JS_DefineProperty(cx, tmp, "name", jsname, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "intValue", v.intValue, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "floatValue", v.floatValue, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "stringValue", JS::RootedValue(cx, c_string_to_jsval(cx, v.stringValue)), JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineProperty(cx, tmp, "stringValue", jsstr, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { @@ -49,10 +51,12 @@ jsval spevent_to_jsval(JSContext* cx, spEvent& v) JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "data", JS::RootedValue(cx, speventdata_to_jsval(cx, *v.data)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS::RootedValue jsdata(cx, speventdata_to_jsval(cx, *v.data)); + JS::RootedValue jsstr(cx, c_string_to_jsval(cx, v.stringValue)); + bool ok = JS_DefineProperty(cx, tmp, "data", jsdata, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "intValue", v.intValue, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "floatValue", v.floatValue, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "stringValue", JS::RootedValue(cx, c_string_to_jsval(cx, v.stringValue)), JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineProperty(cx, tmp, "stringValue", jsstr, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { @@ -72,7 +76,8 @@ jsval spbonedata_to_jsval(JSContext* cx, const spBoneData* v) if (strcmp(v->name, "root") && v->parent) parentVal = spbonedata_to_jsval(cx, v->parent); - bool ok = JS_DefineProperty(cx, tmp, "name", JS::RootedValue(cx, c_string_to_jsval(cx, v->name)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS::RootedValue jsname(cx, c_string_to_jsval(cx, v->name)); + bool ok = JS_DefineProperty(cx, tmp, "name", jsname, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "parent", parentVal,JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "length", v->length, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "x", v->x, JSPROP_ENUMERATE | JSPROP_PERMANENT) && @@ -101,7 +106,8 @@ jsval spbone_to_jsval(JSContext* cx, spBone& v) if (strcmp(v.data->name, "root") && v.parent) parentVal = spbone_to_jsval(cx, *v.parent); - bool ok = JS_DefineProperty(cx, tmp, "data", JS::RootedValue(cx, spbonedata_to_jsval(cx, v.data)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS::RootedValue jsdata(cx, spbonedata_to_jsval(cx, v.data)); + bool ok = JS_DefineProperty(cx, tmp, "data", jsdata, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "parent", parentVal, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "x", v.x, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "y", v.y, JSPROP_ENUMERATE | JSPROP_PERMANENT) && @@ -152,7 +158,8 @@ jsval spattachment_to_jsval(JSContext* cx, spAttachment& v) JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "name", JS::RootedValue(cx, c_string_to_jsval(cx, v.name)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS::RootedValue jsname(cx, c_string_to_jsval(cx, v.name)); + bool ok = JS_DefineProperty(cx, tmp, "name", jsname, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "type", v.type, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) @@ -168,14 +175,17 @@ jsval spslotdata_to_jsval(JSContext* cx, spSlotData& v) JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; - bool ok = JS_DefineProperty(cx, tmp, "name", JS::RootedValue(cx, c_string_to_jsval(cx, v.name)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "attachmentName", JS::RootedValue(cx, c_string_to_jsval(cx, v.attachmentName)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS::RootedValue jsname(cx, c_string_to_jsval(cx, v.name)); + JS::RootedValue jsattachmentName(cx, c_string_to_jsval(cx, v.attachmentName)); + JS::RootedValue jsboneData(cx, spbonedata_to_jsval(cx, v.boneData)); + bool ok = JS_DefineProperty(cx, tmp, "name", jsname, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "attachmentName", jsattachmentName, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "r", v.r, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "g", v.g, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "b", v.b, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "a", v.a, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "blendMode", v.blendMode, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "boneData", JS::RootedValue(cx, spbonedata_to_jsval(cx, v.boneData)), JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineProperty(cx, tmp, "boneData", jsboneData, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { @@ -190,14 +200,17 @@ jsval spslot_to_jsval(JSContext* cx, spSlot& v) JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; + JS::RootedValue jsbone(cx, spbone_to_jsval(cx, *v.bone)); + JS::RootedValue jsattachment(cx, spattachment_to_jsval(cx, *v.attachment)); + JS::RootedValue jsdata(cx, spslotdata_to_jsval(cx, *v.data)); bool ok = JS_DefineProperty(cx, tmp, "r", v.r, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "g", v.g, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "b", v.b, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "a", v.a, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "bone", JS::RootedValue(cx, spbone_to_jsval(cx, *v.bone)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "bone", jsbone, JSPROP_ENUMERATE | JSPROP_PERMANENT) && //JS_DefineProperty(cx, tmp, "skeleton", spskeleton_to_jsval(cx, *v.skeleton), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "attachment", JS::RootedValue(cx, spattachment_to_jsval(cx, *v.attachment)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "data", JS::RootedValue(cx, spslotdata_to_jsval(cx, *v.data)), JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineProperty(cx, tmp, "attachment", jsattachment, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "data", jsdata, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { @@ -243,10 +256,12 @@ jsval spanimation_to_jsval(JSContext* cx, spAnimation& v) JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; + JS::RootedValue jsname(cx, c_string_to_jsval(cx, v.name)); + JS::RootedValue jstimelines(cx, sptimeline_to_jsval(cx, **v.timelines)); bool ok = JS_DefineProperty(cx, tmp, "duration", v.duration, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "timelineCount", v.timelinesCount, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "name", JS::RootedValue(cx, c_string_to_jsval(cx, v.name)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "timelines", JS::RootedValue(cx, sptimeline_to_jsval(cx, **v.timelines)), JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineProperty(cx, tmp, "name", jsname, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "timelines", jstimelines, JSPROP_ENUMERATE | JSPROP_PERMANENT); if (ok) { @@ -269,6 +284,7 @@ jsval sptrackentry_to_jsval(JSContext* cx, spTrackEntry& v) if (v.previous) previousVal = sptrackentry_to_jsval(cx, *v.previous); + JS::RootedValue jsanimation(cx, spanimation_to_jsval(cx, *v.animation)); bool ok = JS_DefineProperty(cx, tmp, "delay", v.delay, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "time", v.time, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "lastTime", v.lastTime, JSPROP_ENUMERATE | JSPROP_PERMANENT) && @@ -276,7 +292,7 @@ jsval sptrackentry_to_jsval(JSContext* cx, spTrackEntry& v) JS_DefineProperty(cx, tmp, "timeScale", v.timeScale, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "mixTime", v.mixTime, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "mixDuration", v.mixDuration, JSPROP_ENUMERATE | JSPROP_PERMANENT) && - JS_DefineProperty(cx, tmp, "animation", JS::RootedValue(cx, spanimation_to_jsval(cx, *v.animation)), JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "animation", jsanimation, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "next", nextVal, JSPROP_ENUMERATE | JSPROP_PERMANENT) && JS_DefineProperty(cx, tmp, "previous", previousVal, JSPROP_ENUMERATE | JSPROP_PERMANENT); @@ -472,7 +488,7 @@ bool jsb_cocos2dx_spine_setAnimation(JSContext *cx, uint32_t argc, jsval *vp) const char* arg1; std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); - bool arg2 = JS::ToBoolean(JS::RootedValue(cx, args.get(2))); + bool arg2 = JS::ToBoolean(args.get(2)); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); spTrackEntry* ret = cobj->setAnimation(arg0, arg1, arg2); diff --git a/cocos/scripting/js-bindings/manual/ui/jsb_cocos2dx_ui_manual.cpp b/cocos/scripting/js-bindings/manual/ui/jsb_cocos2dx_ui_manual.cpp index e63f5ba13d..c8836a4a4f 100755 --- a/cocos/scripting/js-bindings/manual/ui/jsb_cocos2dx_ui_manual.cpp +++ b/cocos/scripting/js-bindings/manual/ui/jsb_cocos2dx_ui_manual.cpp @@ -61,10 +61,14 @@ static bool js_cocos2dx_LayoutParameter_setMargin(JSContext *cx, uint32_t argc, else if (argc == 4) { bool ok = true; double left, top,right,bottom; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, args[0]), &left); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, args[1]), &top); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, args[2]), &right); - ok &= JS::ToNumber( cx, JS::RootedValue(cx, args[3]), &bottom); + JS::RootedValue jsv(cx, args[0]); + ok &= JS::ToNumber( cx, jsv, &left); + jsv.set(args[1]); + ok &= JS::ToNumber( cx, jsv, &top); + jsv.set(args[2]); + ok &= JS::ToNumber( cx, jsv, &right); + jsv.set(args[3]); + ok &= JS::ToNumber( cx, jsv, &bottom); JSB_PRECONDITION3(ok, cx, false, "Error processing arguments"); @@ -200,7 +204,10 @@ extern JSObject* jsb_cocos2d_ui_EditBox_prototype; void register_all_cocos2dx_ui_manual(JSContext* cx, JS::HandleObject global) { - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_ui_LayoutParameter_prototype), "setMargin", js_cocos2dx_LayoutParameter_setMargin, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_ui_LayoutParameter_prototype), "getMargin", js_cocos2dx_LayoutParameter_getMargin, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_ui_EditBox_prototype), "setDelegate", js_cocos2dx_CCEditBox_setDelegate, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS::RootedObject proto(cx, jsb_cocos2d_ui_LayoutParameter_prototype); + JS_DefineFunction(cx, proto, "setMargin", js_cocos2dx_LayoutParameter_setMargin, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, proto, "getMargin", js_cocos2dx_LayoutParameter_getMargin, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + proto.set(jsb_cocos2d_ui_EditBox_prototype); + JS_DefineFunction(cx, proto, "setDelegate", js_cocos2dx_CCEditBox_setDelegate, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); } diff --git a/tests/js-tests/project/Classes/js_DrawNode3D_bindings.cpp b/tests/js-tests/project/Classes/js_DrawNode3D_bindings.cpp index 9618fb9926..10320ee135 100644 --- a/tests/js-tests/project/Classes/js_DrawNode3D_bindings.cpp +++ b/tests/js-tests/project/Classes/js_DrawNode3D_bindings.cpp @@ -557,32 +557,20 @@ void js_register_cocos2dx_DrawNode3D(JSContext *cx, JS::HandleObject global) { JS_FS_END }; - jsb_cocos2d_DrawNode3D_prototype = JS_InitClass( + JS::RootedObject parentProto(cx, jsb_cocos2d_Node_prototype); + JS::RootedObject proto(cx, JS_InitClass( cx, global, - JS::RootedObject(cx, jsb_cocos2d_Node_prototype), + parentProto, jsb_cocos2d_DrawNode3D_class, js_cocos2dx_DrawNode3D_constructor, 0, // constructor properties, funcs, NULL, // no static properties - st_funcs); - // make the class enumerable in the registered namespace -// bool found; -//FIXME: Removed in Firefox v27 -// JS_SetPropertyAttributes(cx, global, "DrawNode3D", JSPROP_ENUMERATE | JSPROP_READONLY, &found); - + st_funcs)); + + jsb_cocos2d_DrawNode3D_prototype = proto.get(); // add the proto and JSClass to the type->js info hash table - TypeTest t; - js_type_class_t *p; - std::string typeName = t.s_name(); - if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) - { - p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_cocos2d_DrawNode3D_class; - p->proto = jsb_cocos2d_DrawNode3D_prototype; - p->parentProto = jsb_cocos2d_Node_prototype; - _js_global_type_map.insert(std::make_pair(typeName, p)); - } + jsb_register_class(cx, jsb_cocos2d_DrawNode3D_class, proto, parentProto); } void register_DrawNode3D_bindings(JSContext *cx, JS::HandleObject global) diff --git a/tests/js-tests/project/Classes/js_Effect3D_bindings.cpp b/tests/js-tests/project/Classes/js_Effect3D_bindings.cpp index b4de7b6830..f3a4d760fd 100644 --- a/tests/js-tests/project/Classes/js_Effect3D_bindings.cpp +++ b/tests/js-tests/project/Classes/js_Effect3D_bindings.cpp @@ -525,32 +525,20 @@ void js_register_cocos2dx_Effect3DOutline(JSContext *cx, JS::HandleObject global JS_FS_END }; + JS::RootedObject parentProto(cx, jsb_Effect3D_prototype); jsb_Effect3DOutline_prototype = JS_InitClass( cx, global, - JS::RootedObject(cx, jsb_Effect3D_prototype), + parentProto, jsb_Effect3DOutline_class, jsb_Effect3DOutline_constructor, 0, properties, funcs, NULL, // no static properties st_funcs); - // make the class enumerable in the registered namespace - // bool found; - //FIXME: Removed in Firefox v27 - // JS_SetPropertyAttributes(cx, global, "Effect3DOutline", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table - TypeTest t; - js_type_class_t *p; - std::string typeName = t.s_name(); - if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) - { - p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_Effect3DOutline_class; - p->proto = jsb_Effect3DOutline_prototype; - p->parentProto = jsb_Effect3D_prototype; - _js_global_type_map.insert(std::make_pair(typeName, p)); - } + JS::RootedObject proto(cx, jsb_Effect3DOutline_prototype); + jsb_register_class(cx, jsb_Effect3DOutline_class, proto, parentProto); } @@ -740,32 +728,20 @@ void js_register_cocos2dx_EffectSprite3D(JSContext *cx, JS::HandleObject global) JS_FS_END }; + JS::RootedObject parentProto(cx, jsb_cocos2d_Sprite3D_prototype); jsb_EffectSprite3D_prototype = JS_InitClass( cx, global, - JS::RootedObject(cx, jsb_cocos2d_Sprite3D_prototype), + parentProto, jsb_EffectSprite3D_class, jsb_EffectSprite3D_constructor, 1, properties, funcs, NULL, // no static properties st_funcs); - // make the class enumerable in the registered namespace - // bool found; - //FIXME: Removed in Firefox v27 - // JS_SetPropertyAttributes(cx, global, "EffectSprite3D", JSPROP_ENUMERATE | JSPROP_READONLY, &found); // add the proto and JSClass to the type->js info hash table - TypeTest t; - js_type_class_t *p; - std::string typeName = t.s_name(); - if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) - { - p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); - p->jsclass = jsb_EffectSprite3D_class; - p->proto = jsb_EffectSprite3D_prototype; - p->parentProto = jsb_cocos2d_Sprite3D_prototype; - _js_global_type_map.insert(std::make_pair(typeName, p)); - } + JS::RootedObject proto(cx, jsb_EffectSprite3D_prototype); + jsb_register_class(cx, jsb_EffectSprite3D_class, proto, parentProto); } void register_Effect3D_bindings(JSContext *cx, JS::HandleObject global) diff --git a/tools/bindings-generator b/tools/bindings-generator index 4ecd2f4536..3dd232b790 160000 --- a/tools/bindings-generator +++ b/tools/bindings-generator @@ -1 +1 @@ -Subproject commit 4ecd2f4536bd57d42b4b370a6a4fc7c7420f5404 +Subproject commit 3dd232b790e85b2cc4a0a0a0e2fb1fc103f57249