diff --git a/jsbindings/auto/jsb_cocos2dx_pluginx_auto.cpp b/jsbindings/auto/jsb_cocos2dx_pluginx_auto.cpp index 6ba16bb6..058789a1 100644 --- a/jsbindings/auto/jsb_cocos2dx_pluginx_auto.cpp +++ b/jsbindings/auto/jsb_cocos2dx_pluginx_auto.cpp @@ -14,6 +14,7 @@ using namespace pluginx; template static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::RootedValue initializing(cx); bool isNewValid = true; if (isNewValid) @@ -26,11 +27,14 @@ static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); - JSObject *_tmp = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + JS::RootedObject proto(cx, typeClass->proto.get()); + JS::RootedObject parent(cx, typeClass->parentProto.get()); + JS::RootedObject _tmp(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + T* cobj = new T(); js_proxy_t *pp = jsb_new_proxy(cobj, _tmp); - JS_AddObjectRoot(cx, &pp->obj); - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(_tmp)); + AddObjectRoot(cx, &pp->obj); + args.rval().set(OBJECT_TO_JSVAL(_tmp)); return true; } @@ -41,9 +45,10 @@ static bool empty_constructor(JSContext *cx, uint32_t argc, jsval *vp) { return false; } -static bool js_is_native_obj(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) +static bool js_is_native_obj(JSContext *cx, uint32_t argc, jsval *vp) { - vp.set(BOOLEAN_TO_JSVAL(true)); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + args.rval().setBoolean(true); return true; } JSClass *jsb_cocos2d_plugin_PluginProtocol_class; @@ -51,7 +56,8 @@ JSObject *jsb_cocos2d_plugin_PluginProtocol_prototype; bool js_pluginx_protocols_PluginProtocol_getPluginName(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::PluginProtocol* cobj = (cocos2d::plugin::PluginProtocol *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_PluginProtocol_getPluginName : Invalid Native Object"); @@ -59,7 +65,7 @@ bool js_pluginx_protocols_PluginProtocol_getPluginName(JSContext *cx, uint32_t a const char* ret = cobj->getPluginName(); jsval jsret = JSVAL_NULL; jsret = c_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -68,7 +74,8 @@ bool js_pluginx_protocols_PluginProtocol_getPluginName(JSContext *cx, uint32_t a } bool js_pluginx_protocols_PluginProtocol_getPluginVersion(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::PluginProtocol* cobj = (cocos2d::plugin::PluginProtocol *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_PluginProtocol_getPluginVersion : Invalid Native Object"); @@ -76,7 +83,7 @@ bool js_pluginx_protocols_PluginProtocol_getPluginVersion(JSContext *cx, uint32_ std::string ret = cobj->getPluginVersion(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -85,7 +92,8 @@ bool js_pluginx_protocols_PluginProtocol_getPluginVersion(JSContext *cx, uint32_ } bool js_pluginx_protocols_PluginProtocol_getSDKVersion(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::PluginProtocol* cobj = (cocos2d::plugin::PluginProtocol *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_PluginProtocol_getSDKVersion : Invalid Native Object"); @@ -93,7 +101,7 @@ bool js_pluginx_protocols_PluginProtocol_getSDKVersion(JSContext *cx, uint32_t a std::string ret = cobj->getSDKVersion(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -102,18 +110,18 @@ bool js_pluginx_protocols_PluginProtocol_getSDKVersion(JSContext *cx, uint32_t a } bool js_pluginx_protocols_PluginProtocol_setDebugMode(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::PluginProtocol* cobj = (cocos2d::plugin::PluginProtocol *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_PluginProtocol_setDebugMode : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(JS::RootedValue(cx, args.get(0))); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_PluginProtocol_setDebugMode : Error processing arguments"); cobj->setDebugMode(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -138,7 +146,7 @@ void js_cocos2d_plugin_PluginProtocol_finalize(JSFreeOp *fop, JSObject *obj) { } } -void js_register_pluginx_protocols_PluginProtocol(JSContext *cx, JSObject *global) { +void js_register_pluginx_protocols_PluginProtocol(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_plugin_PluginProtocol_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_plugin_PluginProtocol_class->name = "PluginProtocol"; jsb_cocos2d_plugin_PluginProtocol_class->addProperty = JS_PropertyStub; @@ -152,8 +160,8 @@ void js_register_pluginx_protocols_PluginProtocol(JSContext *cx, JSObject *globa jsb_cocos2d_plugin_PluginProtocol_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -168,7 +176,7 @@ void js_register_pluginx_protocols_PluginProtocol(JSContext *cx, JSObject *globa jsb_cocos2d_plugin_PluginProtocol_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_plugin_PluginProtocol_class, empty_constructor, 0, properties, @@ -199,18 +207,18 @@ JSObject *jsb_cocos2d_plugin_PluginManager_prototype; bool js_pluginx_protocols_PluginManager_unloadPlugin(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::PluginManager* cobj = (cocos2d::plugin::PluginManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_PluginManager_unloadPlugin : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_PluginManager_unloadPlugin : Error processing arguments"); cobj->unloadPlugin(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -219,15 +227,15 @@ bool js_pluginx_protocols_PluginManager_unloadPlugin(JSContext *cx, uint32_t arg } bool js_pluginx_protocols_PluginManager_loadPlugin(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::PluginManager* cobj = (cocos2d::plugin::PluginManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_PluginManager_loadPlugin : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_PluginManager_loadPlugin : Error processing arguments"); cocos2d::plugin::PluginProtocol* ret = cobj->loadPlugin(arg0); jsval jsret = JSVAL_NULL; @@ -239,7 +247,7 @@ bool js_pluginx_protocols_PluginManager_loadPlugin(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -248,9 +256,10 @@ bool js_pluginx_protocols_PluginManager_loadPlugin(JSContext *cx, uint32_t argc, } bool js_pluginx_protocols_PluginManager_end(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::plugin::PluginManager::end(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_pluginx_protocols_PluginManager_end : wrong number of arguments"); @@ -259,6 +268,7 @@ bool js_pluginx_protocols_PluginManager_end(JSContext *cx, uint32_t argc, jsval bool js_pluginx_protocols_PluginManager_getInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::plugin::PluginManager* ret = cocos2d::plugin::PluginManager::getInstance(); jsval jsret = JSVAL_NULL; @@ -270,7 +280,7 @@ bool js_pluginx_protocols_PluginManager_getInstance(JSContext *cx, uint32_t argc jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_pluginx_protocols_PluginManager_getInstance : wrong number of arguments"); @@ -295,7 +305,7 @@ void js_cocos2d_plugin_PluginManager_finalize(JSFreeOp *fop, JSObject *obj) { } } -void js_register_pluginx_protocols_PluginManager(JSContext *cx, JSObject *global) { +void js_register_pluginx_protocols_PluginManager(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_plugin_PluginManager_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_plugin_PluginManager_class->name = "PluginManager"; jsb_cocos2d_plugin_PluginManager_class->addProperty = JS_PropertyStub; @@ -309,8 +319,8 @@ void js_register_pluginx_protocols_PluginManager(JSContext *cx, JSObject *global jsb_cocos2d_plugin_PluginManager_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -327,7 +337,7 @@ void js_register_pluginx_protocols_PluginManager(JSContext *cx, JSObject *global jsb_cocos2d_plugin_PluginManager_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_plugin_PluginManager_class, empty_constructor, 0, properties, @@ -358,18 +368,18 @@ JSObject *jsb_cocos2d_plugin_ProtocolAnalytics_prototype; bool js_pluginx_protocols_ProtocolAnalytics_logTimedEventBegin(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolAnalytics* cobj = (cocos2d::plugin::ProtocolAnalytics *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolAnalytics_logTimedEventBegin : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolAnalytics_logTimedEventBegin : Error processing arguments"); cobj->logTimedEventBegin(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -378,20 +388,20 @@ bool js_pluginx_protocols_ProtocolAnalytics_logTimedEventBegin(JSContext *cx, ui } bool js_pluginx_protocols_ProtocolAnalytics_logError(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolAnalytics* cobj = (cocos2d::plugin::ProtocolAnalytics *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolAnalytics_logError : Invalid Native Object"); if (argc == 2) { const char* arg0; const char* arg1; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolAnalytics_logError : Error processing arguments"); cobj->logError(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -400,18 +410,18 @@ bool js_pluginx_protocols_ProtocolAnalytics_logError(JSContext *cx, uint32_t arg } bool js_pluginx_protocols_ProtocolAnalytics_setCaptureUncaughtException(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolAnalytics* cobj = (cocos2d::plugin::ProtocolAnalytics *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolAnalytics_setCaptureUncaughtException : Invalid Native Object"); if (argc == 1) { bool arg0; - arg0 = JS::ToBoolean(JS::RootedValue(cx, argv[0])); + arg0 = JS::ToBoolean(JS::RootedValue(cx, args.get(0))); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolAnalytics_setCaptureUncaughtException : Error processing arguments"); cobj->setCaptureUncaughtException(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -420,18 +430,18 @@ bool js_pluginx_protocols_ProtocolAnalytics_setCaptureUncaughtException(JSContex } bool js_pluginx_protocols_ProtocolAnalytics_setSessionContinueMillis(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolAnalytics* cobj = (cocos2d::plugin::ProtocolAnalytics *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolAnalytics_setSessionContinueMillis : Invalid Native Object"); if (argc == 1) { long arg0; - ok &= jsval_to_long(cx, argv[0], &arg0); + ok &= pluginx::jsval_to_long(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolAnalytics_setSessionContinueMillis : Error processing arguments"); cobj->setSessionContinueMillis(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -440,28 +450,28 @@ bool js_pluginx_protocols_ProtocolAnalytics_setSessionContinueMillis(JSContext * } bool js_pluginx_protocols_ProtocolAnalytics_logEvent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolAnalytics* cobj = (cocos2d::plugin::ProtocolAnalytics *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolAnalytics_logEvent : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolAnalytics_logEvent : Error processing arguments"); cobj->logEvent(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { const char* arg0; std::map* arg1; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - std::map arg1_tmp; ok &= jsval_to_std_map_string_string(cx, argv[1], &arg1_tmp); arg1 = &arg1_tmp; + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::map arg1_tmp; ok &= jsval_to_std_map_string_string(cx, args.get(1), &arg1_tmp); arg1 = &arg1_tmp; JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolAnalytics_logEvent : Error processing arguments"); cobj->logEvent(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -470,18 +480,18 @@ bool js_pluginx_protocols_ProtocolAnalytics_logEvent(JSContext *cx, uint32_t arg } bool js_pluginx_protocols_ProtocolAnalytics_startSession(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolAnalytics* cobj = (cocos2d::plugin::ProtocolAnalytics *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolAnalytics_startSession : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolAnalytics_startSession : Error processing arguments"); cobj->startSession(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -490,13 +500,14 @@ bool js_pluginx_protocols_ProtocolAnalytics_startSession(JSContext *cx, uint32_t } bool js_pluginx_protocols_ProtocolAnalytics_stopSession(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolAnalytics* cobj = (cocos2d::plugin::ProtocolAnalytics *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolAnalytics_stopSession : Invalid Native Object"); if (argc == 0) { cobj->stopSession(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -505,18 +516,18 @@ bool js_pluginx_protocols_ProtocolAnalytics_stopSession(JSContext *cx, uint32_t } bool js_pluginx_protocols_ProtocolAnalytics_logTimedEventEnd(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolAnalytics* cobj = (cocos2d::plugin::ProtocolAnalytics *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolAnalytics_logTimedEventEnd : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolAnalytics_logTimedEventEnd : Error processing arguments"); cobj->logTimedEventEnd(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -542,7 +553,7 @@ void js_cocos2d_plugin_ProtocolAnalytics_finalize(JSFreeOp *fop, JSObject *obj) } } -void js_register_pluginx_protocols_ProtocolAnalytics(JSContext *cx, JSObject *global) { +void js_register_pluginx_protocols_ProtocolAnalytics(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_plugin_ProtocolAnalytics_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_plugin_ProtocolAnalytics_class->name = "ProtocolAnalytics"; jsb_cocos2d_plugin_ProtocolAnalytics_class->addProperty = JS_PropertyStub; @@ -556,8 +567,8 @@ void js_register_pluginx_protocols_ProtocolAnalytics(JSContext *cx, JSObject *gl jsb_cocos2d_plugin_ProtocolAnalytics_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -576,7 +587,7 @@ void js_register_pluginx_protocols_ProtocolAnalytics(JSContext *cx, JSObject *gl jsb_cocos2d_plugin_ProtocolAnalytics_prototype = JS_InitClass( cx, global, - jsb_cocos2d_plugin_PluginProtocol_prototype, + JS::RootedObject(cx, jsb_cocos2d_plugin_PluginProtocol_prototype), jsb_cocos2d_plugin_ProtocolAnalytics_class, empty_constructor, 0, properties, @@ -607,20 +618,20 @@ JSObject *jsb_cocos2d_plugin_ProtocolIAP_prototype; bool js_pluginx_protocols_ProtocolIAP_onPayResult(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolIAP* cobj = (cocos2d::plugin::ProtocolIAP *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolIAP_onPayResult : Invalid Native Object"); if (argc == 2) { cocos2d::plugin::PayResultCode arg0; const char* arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolIAP_onPayResult : Error processing arguments"); cobj->onPayResult(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -629,7 +640,8 @@ bool js_pluginx_protocols_ProtocolIAP_onPayResult(JSContext *cx, uint32_t argc, } bool js_pluginx_protocols_ProtocolIAP_getCallback(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolIAP* cobj = (cocos2d::plugin::ProtocolIAP *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolIAP_getCallback : Invalid Native Object"); @@ -637,7 +649,7 @@ bool js_pluginx_protocols_ProtocolIAP_getCallback(JSContext *cx, uint32_t argc, cocos2d::plugin::ProtocolIAP::ProtocolIAPCallback ret = cobj->getCallback(); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR std::function; - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -646,18 +658,18 @@ bool js_pluginx_protocols_ProtocolIAP_getCallback(JSContext *cx, uint32_t argc, } bool js_pluginx_protocols_ProtocolIAP_configDeveloperInfo(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolIAP* cobj = (cocos2d::plugin::ProtocolIAP *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolIAP_configDeveloperInfo : Invalid Native Object"); if (argc == 1) { std::map arg0; - ok &= jsval_to_std_map_string_string(cx, argv[0], &arg0); + ok &= jsval_to_std_map_string_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolIAP_configDeveloperInfo : Error processing arguments"); cobj->configDeveloperInfo(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -683,7 +695,7 @@ void js_cocos2d_plugin_ProtocolIAP_finalize(JSFreeOp *fop, JSObject *obj) { } } -void js_register_pluginx_protocols_ProtocolIAP(JSContext *cx, JSObject *global) { +void js_register_pluginx_protocols_ProtocolIAP(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_plugin_ProtocolIAP_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_plugin_ProtocolIAP_class->name = "ProtocolIAP"; jsb_cocos2d_plugin_ProtocolIAP_class->addProperty = JS_PropertyStub; @@ -697,8 +709,8 @@ void js_register_pluginx_protocols_ProtocolIAP(JSContext *cx, JSObject *global) jsb_cocos2d_plugin_ProtocolIAP_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -712,7 +724,7 @@ void js_register_pluginx_protocols_ProtocolIAP(JSContext *cx, JSObject *global) jsb_cocos2d_plugin_ProtocolIAP_prototype = JS_InitClass( cx, global, - jsb_cocos2d_plugin_PluginProtocol_prototype, + JS::RootedObject(cx, jsb_cocos2d_plugin_PluginProtocol_prototype), jsb_cocos2d_plugin_ProtocolIAP_class, empty_constructor, 0, properties, @@ -743,28 +755,28 @@ JSObject *jsb_cocos2d_plugin_ProtocolAds_prototype; bool js_pluginx_protocols_ProtocolAds_showAds(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolAds_showAds : Invalid Native Object"); if (argc == 1) { std::map arg0; - ok &= jsval_to_std_map_string_string(cx, argv[0], &arg0); + ok &= jsval_to_std_map_string_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolAds_showAds : Error processing arguments"); cobj->showAds(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::map arg0; cocos2d::plugin::ProtocolAds::AdsPos arg1; - ok &= jsval_to_std_map_string_string(cx, argv[0], &arg0); - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_std_map_string_string(cx, args.get(0), &arg0); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolAds_showAds : Error processing arguments"); cobj->showAds(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -773,18 +785,18 @@ bool js_pluginx_protocols_ProtocolAds_showAds(JSContext *cx, uint32_t argc, jsva } bool js_pluginx_protocols_ProtocolAds_hideAds(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolAds_hideAds : Invalid Native Object"); if (argc == 1) { std::map arg0; - ok &= jsval_to_std_map_string_string(cx, argv[0], &arg0); + ok &= jsval_to_std_map_string_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolAds_hideAds : Error processing arguments"); cobj->hideAds(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -793,13 +805,14 @@ bool js_pluginx_protocols_ProtocolAds_hideAds(JSContext *cx, uint32_t argc, jsva } bool js_pluginx_protocols_ProtocolAds_queryPoints(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolAds_queryPoints : Invalid Native Object"); if (argc == 0) { cobj->queryPoints(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -808,7 +821,8 @@ bool js_pluginx_protocols_ProtocolAds_queryPoints(JSContext *cx, uint32_t argc, } bool js_pluginx_protocols_ProtocolAds_getCallback(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolAds_getCallback : Invalid Native Object"); @@ -816,7 +830,7 @@ bool js_pluginx_protocols_ProtocolAds_getCallback(JSContext *cx, uint32_t argc, cocos2d::plugin::ProtocolAds::ProtocolAdsCallback ret = cobj->getCallback(); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR std::function; - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -825,18 +839,18 @@ bool js_pluginx_protocols_ProtocolAds_getCallback(JSContext *cx, uint32_t argc, } bool js_pluginx_protocols_ProtocolAds_spendPoints(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolAds_spendPoints : Invalid Native Object"); if (argc == 1) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolAds_spendPoints : Error processing arguments"); cobj->spendPoints(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -845,18 +859,18 @@ bool js_pluginx_protocols_ProtocolAds_spendPoints(JSContext *cx, uint32_t argc, } bool js_pluginx_protocols_ProtocolAds_configDeveloperInfo(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolAds_configDeveloperInfo : Invalid Native Object"); if (argc == 1) { std::map arg0; - ok &= jsval_to_std_map_string_string(cx, argv[0], &arg0); + ok &= jsval_to_std_map_string_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolAds_configDeveloperInfo : Error processing arguments"); cobj->configDeveloperInfo(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -882,7 +896,7 @@ void js_cocos2d_plugin_ProtocolAds_finalize(JSFreeOp *fop, JSObject *obj) { } } -void js_register_pluginx_protocols_ProtocolAds(JSContext *cx, JSObject *global) { +void js_register_pluginx_protocols_ProtocolAds(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_plugin_ProtocolAds_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_plugin_ProtocolAds_class->name = "ProtocolAds"; jsb_cocos2d_plugin_ProtocolAds_class->addProperty = JS_PropertyStub; @@ -896,8 +910,8 @@ void js_register_pluginx_protocols_ProtocolAds(JSContext *cx, JSObject *global) jsb_cocos2d_plugin_ProtocolAds_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -914,7 +928,7 @@ void js_register_pluginx_protocols_ProtocolAds(JSContext *cx, JSObject *global) jsb_cocos2d_plugin_ProtocolAds_prototype = JS_InitClass( cx, global, - jsb_cocos2d_plugin_PluginProtocol_prototype, + JS::RootedObject(cx, jsb_cocos2d_plugin_PluginProtocol_prototype), jsb_cocos2d_plugin_ProtocolAds_class, empty_constructor, 0, properties, @@ -945,20 +959,20 @@ JSObject *jsb_cocos2d_plugin_ProtocolShare_prototype; bool js_pluginx_protocols_ProtocolShare_onShareResult(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolShare* cobj = (cocos2d::plugin::ProtocolShare *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolShare_onShareResult : Invalid Native Object"); if (argc == 2) { cocos2d::plugin::ShareResultCode arg0; const char* arg1; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolShare_onShareResult : Error processing arguments"); cobj->onShareResult(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -967,7 +981,8 @@ bool js_pluginx_protocols_ProtocolShare_onShareResult(JSContext *cx, uint32_t ar } bool js_pluginx_protocols_ProtocolShare_getCallback(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolShare* cobj = (cocos2d::plugin::ProtocolShare *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolShare_getCallback : Invalid Native Object"); @@ -975,7 +990,7 @@ bool js_pluginx_protocols_ProtocolShare_getCallback(JSContext *cx, uint32_t argc cocos2d::plugin::ProtocolShare::ProtocolShareCallback ret = cobj->getCallback(); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR std::function; - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -984,18 +999,18 @@ bool js_pluginx_protocols_ProtocolShare_getCallback(JSContext *cx, uint32_t argc } bool js_pluginx_protocols_ProtocolShare_configDeveloperInfo(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolShare* cobj = (cocos2d::plugin::ProtocolShare *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolShare_configDeveloperInfo : Invalid Native Object"); if (argc == 1) { std::map arg0; - ok &= jsval_to_std_map_string_string(cx, argv[0], &arg0); + ok &= jsval_to_std_map_string_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolShare_configDeveloperInfo : Error processing arguments"); cobj->configDeveloperInfo(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1021,7 +1036,7 @@ void js_cocos2d_plugin_ProtocolShare_finalize(JSFreeOp *fop, JSObject *obj) { } } -void js_register_pluginx_protocols_ProtocolShare(JSContext *cx, JSObject *global) { +void js_register_pluginx_protocols_ProtocolShare(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_plugin_ProtocolShare_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_plugin_ProtocolShare_class->name = "ProtocolShare"; jsb_cocos2d_plugin_ProtocolShare_class->addProperty = JS_PropertyStub; @@ -1035,8 +1050,8 @@ void js_register_pluginx_protocols_ProtocolShare(JSContext *cx, JSObject *global jsb_cocos2d_plugin_ProtocolShare_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -1050,7 +1065,7 @@ void js_register_pluginx_protocols_ProtocolShare(JSContext *cx, JSObject *global jsb_cocos2d_plugin_ProtocolShare_prototype = JS_InitClass( cx, global, - jsb_cocos2d_plugin_PluginProtocol_prototype, + JS::RootedObject(cx, jsb_cocos2d_plugin_PluginProtocol_prototype), jsb_cocos2d_plugin_ProtocolShare_class, empty_constructor, 0, properties, @@ -1081,18 +1096,18 @@ JSObject *jsb_cocos2d_plugin_ProtocolSocial_prototype; bool js_pluginx_protocols_ProtocolSocial_showLeaderboard(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolSocial* cobj = (cocos2d::plugin::ProtocolSocial *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolSocial_showLeaderboard : Invalid Native Object"); if (argc == 1) { const char* arg0; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolSocial_showLeaderboard : Error processing arguments"); cobj->showLeaderboard(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1101,13 +1116,14 @@ bool js_pluginx_protocols_ProtocolSocial_showLeaderboard(JSContext *cx, uint32_t } bool js_pluginx_protocols_ProtocolSocial_showAchievements(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolSocial* cobj = (cocos2d::plugin::ProtocolSocial *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolSocial_showAchievements : Invalid Native Object"); if (argc == 0) { cobj->showAchievements(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1116,7 +1132,8 @@ bool js_pluginx_protocols_ProtocolSocial_showAchievements(JSContext *cx, uint32_ } bool js_pluginx_protocols_ProtocolSocial_getCallback(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolSocial* cobj = (cocos2d::plugin::ProtocolSocial *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolSocial_getCallback : Invalid Native Object"); @@ -1124,7 +1141,7 @@ bool js_pluginx_protocols_ProtocolSocial_getCallback(JSContext *cx, uint32_t arg std::function &)>& ret = cobj->getCallback(); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR std::function; - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1133,18 +1150,18 @@ bool js_pluginx_protocols_ProtocolSocial_getCallback(JSContext *cx, uint32_t arg } bool js_pluginx_protocols_ProtocolSocial_configDeveloperInfo(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolSocial* cobj = (cocos2d::plugin::ProtocolSocial *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolSocial_configDeveloperInfo : Invalid Native Object"); if (argc == 1) { std::map arg0; - ok &= jsval_to_std_map_string_string(cx, argv[0], &arg0); + ok &= jsval_to_std_map_string_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolSocial_configDeveloperInfo : Error processing arguments"); cobj->configDeveloperInfo(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1170,7 +1187,7 @@ void js_cocos2d_plugin_ProtocolSocial_finalize(JSFreeOp *fop, JSObject *obj) { } } -void js_register_pluginx_protocols_ProtocolSocial(JSContext *cx, JSObject *global) { +void js_register_pluginx_protocols_ProtocolSocial(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_plugin_ProtocolSocial_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_plugin_ProtocolSocial_class->name = "ProtocolSocial"; jsb_cocos2d_plugin_ProtocolSocial_class->addProperty = JS_PropertyStub; @@ -1184,8 +1201,8 @@ void js_register_pluginx_protocols_ProtocolSocial(JSContext *cx, JSObject *globa jsb_cocos2d_plugin_ProtocolSocial_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -1200,7 +1217,7 @@ void js_register_pluginx_protocols_ProtocolSocial(JSContext *cx, JSObject *globa jsb_cocos2d_plugin_ProtocolSocial_prototype = JS_InitClass( cx, global, - jsb_cocos2d_plugin_PluginProtocol_prototype, + JS::RootedObject(cx, jsb_cocos2d_plugin_PluginProtocol_prototype), jsb_cocos2d_plugin_ProtocolSocial_class, empty_constructor, 0, properties, @@ -1231,7 +1248,8 @@ JSObject *jsb_cocos2d_plugin_ProtocolUser_prototype; bool js_pluginx_protocols_ProtocolUser_getCallback(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolUser* cobj = (cocos2d::plugin::ProtocolUser *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolUser_getCallback : Invalid Native Object"); @@ -1239,7 +1257,7 @@ bool js_pluginx_protocols_ProtocolUser_getCallback(JSContext *cx, uint32_t argc, std::function &)>& ret = cobj->getCallback(); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR std::function; - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1248,18 +1266,18 @@ bool js_pluginx_protocols_ProtocolUser_getCallback(JSContext *cx, uint32_t argc, } bool js_pluginx_protocols_ProtocolUser_configDeveloperInfo(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolUser* cobj = (cocos2d::plugin::ProtocolUser *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolUser_configDeveloperInfo : Invalid Native Object"); if (argc == 1) { std::map arg0; - ok &= jsval_to_std_map_string_string(cx, argv[0], &arg0); + ok &= jsval_to_std_map_string_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolUser_configDeveloperInfo : Error processing arguments"); cobj->configDeveloperInfo(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1268,7 +1286,8 @@ bool js_pluginx_protocols_ProtocolUser_configDeveloperInfo(JSContext *cx, uint32 } bool js_pluginx_protocols_ProtocolUser_isLoggedIn(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolUser* cobj = (cocos2d::plugin::ProtocolUser *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolUser_isLoggedIn : Invalid Native Object"); @@ -1276,7 +1295,7 @@ bool js_pluginx_protocols_ProtocolUser_isLoggedIn(JSContext *cx, uint32_t argc, bool ret = cobj->isLoggedIn(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1285,7 +1304,8 @@ bool js_pluginx_protocols_ProtocolUser_isLoggedIn(JSContext *cx, uint32_t argc, } bool js_pluginx_protocols_ProtocolUser_getSessionID(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolUser* cobj = (cocos2d::plugin::ProtocolUser *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolUser_getSessionID : Invalid Native Object"); @@ -1293,7 +1313,7 @@ bool js_pluginx_protocols_ProtocolUser_getSessionID(JSContext *cx, uint32_t argc std::string ret = cobj->getSessionID(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1302,7 +1322,8 @@ bool js_pluginx_protocols_ProtocolUser_getSessionID(JSContext *cx, uint32_t argc } bool js_pluginx_protocols_ProtocolUser_getAccessToken(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolUser* cobj = (cocos2d::plugin::ProtocolUser *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolUser_getAccessToken : Invalid Native Object"); @@ -1310,7 +1331,7 @@ bool js_pluginx_protocols_ProtocolUser_getAccessToken(JSContext *cx, uint32_t ar std::string ret = cobj->getAccessToken(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1336,7 +1357,7 @@ void js_cocos2d_plugin_ProtocolUser_finalize(JSFreeOp *fop, JSObject *obj) { } } -void js_register_pluginx_protocols_ProtocolUser(JSContext *cx, JSObject *global) { +void js_register_pluginx_protocols_ProtocolUser(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_plugin_ProtocolUser_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_plugin_ProtocolUser_class->name = "ProtocolUser"; jsb_cocos2d_plugin_ProtocolUser_class->addProperty = JS_PropertyStub; @@ -1350,8 +1371,8 @@ void js_register_pluginx_protocols_ProtocolUser(JSContext *cx, JSObject *global) jsb_cocos2d_plugin_ProtocolUser_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -1367,7 +1388,7 @@ void js_register_pluginx_protocols_ProtocolUser(JSContext *cx, JSObject *global) jsb_cocos2d_plugin_ProtocolUser_prototype = JS_InitClass( cx, global, - jsb_cocos2d_plugin_PluginProtocol_prototype, + JS::RootedObject(cx, jsb_cocos2d_plugin_PluginProtocol_prototype), jsb_cocos2d_plugin_ProtocolUser_class, empty_constructor, 0, properties, @@ -1398,7 +1419,8 @@ JSObject *jsb_cocos2d_plugin_AgentManager_prototype; bool js_pluginx_protocols_AgentManager_getSocialPlugin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::AgentManager* cobj = (cocos2d::plugin::AgentManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_AgentManager_getSocialPlugin : Invalid Native Object"); @@ -1413,7 +1435,7 @@ bool js_pluginx_protocols_AgentManager_getSocialPlugin(JSContext *cx, uint32_t a jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1422,7 +1444,8 @@ bool js_pluginx_protocols_AgentManager_getSocialPlugin(JSContext *cx, uint32_t a } bool js_pluginx_protocols_AgentManager_getAdsPlugin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::AgentManager* cobj = (cocos2d::plugin::AgentManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_AgentManager_getAdsPlugin : Invalid Native Object"); @@ -1437,7 +1460,7 @@ bool js_pluginx_protocols_AgentManager_getAdsPlugin(JSContext *cx, uint32_t argc jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1446,13 +1469,14 @@ bool js_pluginx_protocols_AgentManager_getAdsPlugin(JSContext *cx, uint32_t argc } bool js_pluginx_protocols_AgentManager_purge(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::AgentManager* cobj = (cocos2d::plugin::AgentManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_AgentManager_purge : Invalid Native Object"); if (argc == 0) { cobj->purge(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1461,7 +1485,8 @@ bool js_pluginx_protocols_AgentManager_purge(JSContext *cx, uint32_t argc, jsval } bool js_pluginx_protocols_AgentManager_getUserPlugin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::AgentManager* cobj = (cocos2d::plugin::AgentManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_AgentManager_getUserPlugin : Invalid Native Object"); @@ -1476,7 +1501,7 @@ bool js_pluginx_protocols_AgentManager_getUserPlugin(JSContext *cx, uint32_t arg jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1485,7 +1510,8 @@ bool js_pluginx_protocols_AgentManager_getUserPlugin(JSContext *cx, uint32_t arg } bool js_pluginx_protocols_AgentManager_getIAPPlugin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::AgentManager* cobj = (cocos2d::plugin::AgentManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_AgentManager_getIAPPlugin : Invalid Native Object"); @@ -1500,7 +1526,7 @@ bool js_pluginx_protocols_AgentManager_getIAPPlugin(JSContext *cx, uint32_t argc jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1509,7 +1535,8 @@ bool js_pluginx_protocols_AgentManager_getIAPPlugin(JSContext *cx, uint32_t argc } bool js_pluginx_protocols_AgentManager_getSharePlugin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::AgentManager* cobj = (cocos2d::plugin::AgentManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_AgentManager_getSharePlugin : Invalid Native Object"); @@ -1524,7 +1551,7 @@ bool js_pluginx_protocols_AgentManager_getSharePlugin(JSContext *cx, uint32_t ar jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1533,7 +1560,8 @@ bool js_pluginx_protocols_AgentManager_getSharePlugin(JSContext *cx, uint32_t ar } bool js_pluginx_protocols_AgentManager_getAnalyticsPlugin(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::AgentManager* cobj = (cocos2d::plugin::AgentManager *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_AgentManager_getAnalyticsPlugin : Invalid Native Object"); @@ -1548,7 +1576,7 @@ bool js_pluginx_protocols_AgentManager_getAnalyticsPlugin(JSContext *cx, uint32_ jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1557,9 +1585,10 @@ bool js_pluginx_protocols_AgentManager_getAnalyticsPlugin(JSContext *cx, uint32_ } bool js_pluginx_protocols_AgentManager_destroyInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::plugin::AgentManager::destroyInstance(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_pluginx_protocols_AgentManager_destroyInstance : wrong number of arguments"); @@ -1568,6 +1597,7 @@ bool js_pluginx_protocols_AgentManager_destroyInstance(JSContext *cx, uint32_t a bool js_pluginx_protocols_AgentManager_getInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::plugin::AgentManager* ret = cocos2d::plugin::AgentManager::getInstance(); jsval jsret = JSVAL_NULL; @@ -1579,7 +1609,7 @@ bool js_pluginx_protocols_AgentManager_getInstance(JSContext *cx, uint32_t argc, jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_pluginx_protocols_AgentManager_getInstance : wrong number of arguments"); @@ -1604,7 +1634,7 @@ void js_cocos2d_plugin_AgentManager_finalize(JSFreeOp *fop, JSObject *obj) { } } -void js_register_pluginx_protocols_AgentManager(JSContext *cx, JSObject *global) { +void js_register_pluginx_protocols_AgentManager(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_plugin_AgentManager_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_plugin_AgentManager_class->name = "AgentManager"; jsb_cocos2d_plugin_AgentManager_class->addProperty = JS_PropertyStub; @@ -1618,8 +1648,8 @@ void js_register_pluginx_protocols_AgentManager(JSContext *cx, JSObject *global) jsb_cocos2d_plugin_AgentManager_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -1641,7 +1671,7 @@ void js_register_pluginx_protocols_AgentManager(JSContext *cx, JSObject *global) jsb_cocos2d_plugin_AgentManager_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_plugin_AgentManager_class, empty_constructor, 0, properties, @@ -1672,13 +1702,14 @@ JSObject *jsb_cocos2d_plugin_FacebookAgent_prototype; bool js_pluginx_protocols_FacebookAgent_activateApp(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::FacebookAgent* cobj = (cocos2d::plugin::FacebookAgent *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_FacebookAgent_activateApp : Invalid Native Object"); if (argc == 0) { cobj->activateApp(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1687,7 +1718,8 @@ bool js_pluginx_protocols_FacebookAgent_activateApp(JSContext *cx, uint32_t argc } bool js_pluginx_protocols_FacebookAgent_getUserID(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::FacebookAgent* cobj = (cocos2d::plugin::FacebookAgent *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_FacebookAgent_getUserID : Invalid Native Object"); @@ -1695,7 +1727,7 @@ bool js_pluginx_protocols_FacebookAgent_getUserID(JSContext *cx, uint32_t argc, std::string ret = cobj->getUserID(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1704,25 +1736,25 @@ bool js_pluginx_protocols_FacebookAgent_getUserID(JSContext *cx, uint32_t argc, } bool js_pluginx_protocols_FacebookAgent_logEvent(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::plugin::FacebookAgent* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::plugin::FacebookAgent *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_FacebookAgent_logEvent : Invalid Native Object"); do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, JS::RootedValue(cx, args.get(1)), &arg1); if (!ok) { ok = true; break; } cobj->logEvent(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -1730,10 +1762,10 @@ bool js_pluginx_protocols_FacebookAgent_logEvent(JSContext *cx, uint32_t argc, j do { if (argc == 1) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } cobj->logEvent(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -1741,13 +1773,13 @@ bool js_pluginx_protocols_FacebookAgent_logEvent(JSContext *cx, uint32_t argc, j do { if (argc == 2) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } std::map arg1; - ok &= jsval_to_std_map_string_string(cx, argv[1], &arg1); + ok &= jsval_to_std_map_string_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cobj->logEvent(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -1755,16 +1787,16 @@ bool js_pluginx_protocols_FacebookAgent_logEvent(JSContext *cx, uint32_t argc, j do { if (argc == 3) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } double arg1; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber( cx, JS::RootedValue(cx, args.get(1)), &arg1); if (!ok) { ok = true; break; } std::map arg2; - ok &= jsval_to_std_map_string_string(cx, argv[2], &arg2); + ok &= jsval_to_std_map_string_string(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } cobj->logEvent(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -1774,13 +1806,14 @@ bool js_pluginx_protocols_FacebookAgent_logEvent(JSContext *cx, uint32_t argc, j } bool js_pluginx_protocols_FacebookAgent_logout(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::FacebookAgent* cobj = (cocos2d::plugin::FacebookAgent *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_FacebookAgent_logout : Invalid Native Object"); if (argc == 0) { cobj->logout(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -1789,7 +1822,8 @@ bool js_pluginx_protocols_FacebookAgent_logout(JSContext *cx, uint32_t argc, jsv } bool js_pluginx_protocols_FacebookAgent_getSDKVersion(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::FacebookAgent* cobj = (cocos2d::plugin::FacebookAgent *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_FacebookAgent_getSDKVersion : Invalid Native Object"); @@ -1797,7 +1831,7 @@ bool js_pluginx_protocols_FacebookAgent_getSDKVersion(JSContext *cx, uint32_t ar std::string ret = cobj->getSDKVersion(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1806,28 +1840,28 @@ bool js_pluginx_protocols_FacebookAgent_getSDKVersion(JSContext *cx, uint32_t ar } bool js_pluginx_protocols_FacebookAgent_logPurchase(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = NULL; + JS::RootedObject obj(cx); cocos2d::plugin::FacebookAgent* cobj = NULL; - obj = JS_THIS_OBJECT(cx, vp); + obj = args.thisv().toObjectOrNull(); js_proxy_t *proxy = jsb_get_js_proxy(obj); cobj = (cocos2d::plugin::FacebookAgent *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_FacebookAgent_logPurchase : Invalid Native Object"); do { if (argc == 3) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, JS::RootedValue(cx, args.get(0)), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } std::map arg2; - ok &= jsval_to_std_map_string_string(cx, argv[2], &arg2); + ok &= jsval_to_std_map_string_string(cx, args.get(2), &arg2); if (!ok) { ok = true; break; } cobj->logPurchase(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -1835,13 +1869,13 @@ bool js_pluginx_protocols_FacebookAgent_logPurchase(JSContext *cx, uint32_t argc do { if (argc == 2) { double arg0; - ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + ok &= JS::ToNumber( cx, JS::RootedValue(cx, args.get(0)), &arg0); if (!ok) { ok = true; break; } std::string arg1; - ok &= jsval_to_std_string(cx, argv[1], &arg1); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); if (!ok) { ok = true; break; } cobj->logPurchase(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -1851,7 +1885,8 @@ bool js_pluginx_protocols_FacebookAgent_logPurchase(JSContext *cx, uint32_t argc } bool js_pluginx_protocols_FacebookAgent_isLoggedIn(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::FacebookAgent* cobj = (cocos2d::plugin::FacebookAgent *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_FacebookAgent_isLoggedIn : Invalid Native Object"); @@ -1859,7 +1894,7 @@ bool js_pluginx_protocols_FacebookAgent_isLoggedIn(JSContext *cx, uint32_t argc, bool ret = cobj->isLoggedIn(); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1868,20 +1903,20 @@ bool js_pluginx_protocols_FacebookAgent_isLoggedIn(JSContext *cx, uint32_t argc, } bool js_pluginx_protocols_FacebookAgent_canPresentDialogWithParams(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::FacebookAgent* cobj = (cocos2d::plugin::FacebookAgent *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_FacebookAgent_canPresentDialogWithParams : Invalid Native Object"); if (argc == 1) { std::map arg0; - ok &= jsval_to_std_map_string_string(cx, argv[0], &arg0); + ok &= jsval_to_std_map_string_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_FacebookAgent_canPresentDialogWithParams : Error processing arguments"); bool ret = cobj->canPresentDialogWithParams(arg0); jsval jsret = JSVAL_NULL; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1890,7 +1925,8 @@ bool js_pluginx_protocols_FacebookAgent_canPresentDialogWithParams(JSContext *cx } bool js_pluginx_protocols_FacebookAgent_getAccessToken(JSContext *cx, uint32_t argc, jsval *vp) { - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::FacebookAgent* cobj = (cocos2d::plugin::FacebookAgent *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_FacebookAgent_getAccessToken : Invalid Native Object"); @@ -1898,7 +1934,7 @@ bool js_pluginx_protocols_FacebookAgent_getAccessToken(JSContext *cx, uint32_t a std::string ret = cobj->getAccessToken(); jsval jsret = JSVAL_NULL; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -1907,9 +1943,10 @@ bool js_pluginx_protocols_FacebookAgent_getAccessToken(JSContext *cx, uint32_t a } bool js_pluginx_protocols_FacebookAgent_destroyInstance(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::plugin::FacebookAgent::destroyInstance(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_pluginx_protocols_FacebookAgent_destroyInstance : wrong number of arguments"); @@ -1918,6 +1955,7 @@ bool js_pluginx_protocols_FacebookAgent_destroyInstance(JSContext *cx, uint32_t bool js_pluginx_protocols_FacebookAgent_getInstanceJs(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc == 0) { cocos2d::plugin::FacebookAgent* ret = cocos2d::plugin::FacebookAgent::getInstanceJs(); jsval jsret = JSVAL_NULL; @@ -1929,7 +1967,7 @@ bool js_pluginx_protocols_FacebookAgent_getInstanceJs(JSContext *cx, uint32_t ar jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "js_pluginx_protocols_FacebookAgent_getInstanceJs : wrong number of arguments"); @@ -1954,7 +1992,7 @@ void js_cocos2d_plugin_FacebookAgent_finalize(JSFreeOp *fop, JSObject *obj) { } } -void js_register_pluginx_protocols_FacebookAgent(JSContext *cx, JSObject *global) { +void js_register_pluginx_protocols_FacebookAgent(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_plugin_FacebookAgent_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_cocos2d_plugin_FacebookAgent_class->name = "FacebookAgent"; jsb_cocos2d_plugin_FacebookAgent_class->addProperty = JS_PropertyStub; @@ -1968,8 +2006,8 @@ void js_register_pluginx_protocols_FacebookAgent(JSContext *cx, JSObject *global jsb_cocos2d_plugin_FacebookAgent_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_PS_END }; static JSFunctionSpec funcs[] = { @@ -1993,7 +2031,7 @@ void js_register_pluginx_protocols_FacebookAgent(JSContext *cx, JSObject *global jsb_cocos2d_plugin_FacebookAgent_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_cocos2d_plugin_FacebookAgent_class, empty_constructor, 0, properties, @@ -2019,29 +2057,29 @@ void js_register_pluginx_protocols_FacebookAgent(JSContext *cx, JSObject *global } } -void register_all_pluginx_protocols(JSContext* cx, JSObject* obj) { +void register_all_pluginx_protocols(JSContext* cx, JS::HandleObject obj) { // first, try to get the ns JS::RootedValue nsval(cx); JS::RootedObject ns(cx); JS_GetProperty(cx, obj, "plugin", &nsval); if (nsval == JSVAL_VOID) { - ns = JS_NewObject(cx, NULL, NULL, NULL); + ns = JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr()); nsval = OBJECT_TO_JSVAL(ns); JS_SetProperty(cx, obj, "plugin", nsval); } else { JS_ValueToObject(cx, nsval, &ns); } - obj = ns; - - js_register_pluginx_protocols_FacebookAgent(cx, obj); - js_register_pluginx_protocols_PluginProtocol(cx, obj); - js_register_pluginx_protocols_ProtocolUser(cx, obj); - js_register_pluginx_protocols_ProtocolShare(cx, obj); - js_register_pluginx_protocols_ProtocolIAP(cx, obj); - js_register_pluginx_protocols_AgentManager(cx, obj); - js_register_pluginx_protocols_ProtocolSocial(cx, obj); - js_register_pluginx_protocols_ProtocolAnalytics(cx, obj); - js_register_pluginx_protocols_ProtocolAds(cx, obj); - js_register_pluginx_protocols_PluginManager(cx, obj); + //obj = ns; + + js_register_pluginx_protocols_FacebookAgent(cx, ns); + js_register_pluginx_protocols_PluginProtocol(cx, ns); + js_register_pluginx_protocols_ProtocolUser(cx, ns); + js_register_pluginx_protocols_ProtocolShare(cx, ns); + js_register_pluginx_protocols_ProtocolIAP(cx, ns); + js_register_pluginx_protocols_AgentManager(cx, ns); + js_register_pluginx_protocols_ProtocolSocial(cx, ns); + js_register_pluginx_protocols_ProtocolAnalytics(cx, ns); + js_register_pluginx_protocols_ProtocolAds(cx, ns); + js_register_pluginx_protocols_PluginManager(cx, ns); } diff --git a/jsbindings/auto/jsb_cocos2dx_pluginx_auto.hpp b/jsbindings/auto/jsb_cocos2dx_pluginx_auto.hpp index f7a61817..3491ac77 100644 --- a/jsbindings/auto/jsb_cocos2dx_pluginx_auto.hpp +++ b/jsbindings/auto/jsb_cocos2dx_pluginx_auto.hpp @@ -10,8 +10,8 @@ extern JSObject *jsb_cocos2d_plugin_PluginProtocol_prototype; bool js_pluginx_protocols_PluginProtocol_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_pluginx_protocols_PluginProtocol_finalize(JSContext *cx, JSObject *obj); -void js_register_pluginx_protocols_PluginProtocol(JSContext *cx, JSObject *global); -void register_all_pluginx_protocols(JSContext* cx, JSObject* obj); +void js_register_pluginx_protocols_PluginProtocol(JSContext *cx, JS::HandleObject global); +void register_all_pluginx_protocols(JSContext* cx, JS::HandleObject obj); bool js_pluginx_protocols_PluginProtocol_getPluginName(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_PluginProtocol_getPluginVersion(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_PluginProtocol_getSDKVersion(JSContext *cx, uint32_t argc, jsval *vp); @@ -22,8 +22,8 @@ extern JSObject *jsb_cocos2d_plugin_PluginManager_prototype; bool js_pluginx_protocols_PluginManager_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_pluginx_protocols_PluginManager_finalize(JSContext *cx, JSObject *obj); -void js_register_pluginx_protocols_PluginManager(JSContext *cx, JSObject *global); -void register_all_pluginx_protocols(JSContext* cx, JSObject* obj); +void js_register_pluginx_protocols_PluginManager(JSContext *cx, JS::HandleObject global); +void register_all_pluginx_protocols(JSContext* cx, JS::HandleObject obj); bool js_pluginx_protocols_PluginManager_unloadPlugin(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_PluginManager_loadPlugin(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_PluginManager_end(JSContext *cx, uint32_t argc, jsval *vp); @@ -34,8 +34,8 @@ extern JSObject *jsb_cocos2d_plugin_ProtocolAnalytics_prototype; bool js_pluginx_protocols_ProtocolAnalytics_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_pluginx_protocols_ProtocolAnalytics_finalize(JSContext *cx, JSObject *obj); -void js_register_pluginx_protocols_ProtocolAnalytics(JSContext *cx, JSObject *global); -void register_all_pluginx_protocols(JSContext* cx, JSObject* obj); +void js_register_pluginx_protocols_ProtocolAnalytics(JSContext *cx, JS::HandleObject global); +void register_all_pluginx_protocols(JSContext* cx, JS::HandleObject obj); bool js_pluginx_protocols_ProtocolAnalytics_logTimedEventBegin(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_ProtocolAnalytics_logError(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_ProtocolAnalytics_setCaptureUncaughtException(JSContext *cx, uint32_t argc, jsval *vp); @@ -50,8 +50,8 @@ extern JSObject *jsb_cocos2d_plugin_ProtocolIAP_prototype; bool js_pluginx_protocols_ProtocolIAP_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_pluginx_protocols_ProtocolIAP_finalize(JSContext *cx, JSObject *obj); -void js_register_pluginx_protocols_ProtocolIAP(JSContext *cx, JSObject *global); -void register_all_pluginx_protocols(JSContext* cx, JSObject* obj); +void js_register_pluginx_protocols_ProtocolIAP(JSContext *cx, JS::HandleObject global); +void register_all_pluginx_protocols(JSContext* cx, JS::HandleObject obj); bool js_pluginx_protocols_ProtocolIAP_onPayResult(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_ProtocolIAP_getCallback(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_ProtocolIAP_configDeveloperInfo(JSContext *cx, uint32_t argc, jsval *vp); @@ -61,8 +61,8 @@ extern JSObject *jsb_cocos2d_plugin_ProtocolAds_prototype; bool js_pluginx_protocols_ProtocolAds_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_pluginx_protocols_ProtocolAds_finalize(JSContext *cx, JSObject *obj); -void js_register_pluginx_protocols_ProtocolAds(JSContext *cx, JSObject *global); -void register_all_pluginx_protocols(JSContext* cx, JSObject* obj); +void js_register_pluginx_protocols_ProtocolAds(JSContext *cx, JS::HandleObject global); +void register_all_pluginx_protocols(JSContext* cx, JS::HandleObject obj); bool js_pluginx_protocols_ProtocolAds_showAds(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_ProtocolAds_hideAds(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_ProtocolAds_queryPoints(JSContext *cx, uint32_t argc, jsval *vp); @@ -75,8 +75,8 @@ extern JSObject *jsb_cocos2d_plugin_ProtocolShare_prototype; bool js_pluginx_protocols_ProtocolShare_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_pluginx_protocols_ProtocolShare_finalize(JSContext *cx, JSObject *obj); -void js_register_pluginx_protocols_ProtocolShare(JSContext *cx, JSObject *global); -void register_all_pluginx_protocols(JSContext* cx, JSObject* obj); +void js_register_pluginx_protocols_ProtocolShare(JSContext *cx, JS::HandleObject global); +void register_all_pluginx_protocols(JSContext* cx, JS::HandleObject obj); bool js_pluginx_protocols_ProtocolShare_onShareResult(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_ProtocolShare_getCallback(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_ProtocolShare_configDeveloperInfo(JSContext *cx, uint32_t argc, jsval *vp); @@ -86,8 +86,8 @@ extern JSObject *jsb_cocos2d_plugin_ProtocolSocial_prototype; bool js_pluginx_protocols_ProtocolSocial_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_pluginx_protocols_ProtocolSocial_finalize(JSContext *cx, JSObject *obj); -void js_register_pluginx_protocols_ProtocolSocial(JSContext *cx, JSObject *global); -void register_all_pluginx_protocols(JSContext* cx, JSObject* obj); +void js_register_pluginx_protocols_ProtocolSocial(JSContext *cx, JS::HandleObject global); +void register_all_pluginx_protocols(JSContext* cx, JS::HandleObject obj); bool js_pluginx_protocols_ProtocolSocial_showLeaderboard(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_ProtocolSocial_showAchievements(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_ProtocolSocial_getCallback(JSContext *cx, uint32_t argc, jsval *vp); @@ -98,8 +98,8 @@ extern JSObject *jsb_cocos2d_plugin_ProtocolUser_prototype; bool js_pluginx_protocols_ProtocolUser_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_pluginx_protocols_ProtocolUser_finalize(JSContext *cx, JSObject *obj); -void js_register_pluginx_protocols_ProtocolUser(JSContext *cx, JSObject *global); -void register_all_pluginx_protocols(JSContext* cx, JSObject* obj); +void js_register_pluginx_protocols_ProtocolUser(JSContext *cx, JS::HandleObject global); +void register_all_pluginx_protocols(JSContext* cx, JS::HandleObject obj); bool js_pluginx_protocols_ProtocolUser_getCallback(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_ProtocolUser_configDeveloperInfo(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_ProtocolUser_isLoggedIn(JSContext *cx, uint32_t argc, jsval *vp); @@ -111,8 +111,8 @@ extern JSObject *jsb_cocos2d_plugin_AgentManager_prototype; bool js_pluginx_protocols_AgentManager_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_pluginx_protocols_AgentManager_finalize(JSContext *cx, JSObject *obj); -void js_register_pluginx_protocols_AgentManager(JSContext *cx, JSObject *global); -void register_all_pluginx_protocols(JSContext* cx, JSObject* obj); +void js_register_pluginx_protocols_AgentManager(JSContext *cx, JS::HandleObject global); +void register_all_pluginx_protocols(JSContext* cx, JS::HandleObject obj); bool js_pluginx_protocols_AgentManager_getSocialPlugin(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_AgentManager_getAdsPlugin(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_AgentManager_purge(JSContext *cx, uint32_t argc, jsval *vp); @@ -128,8 +128,8 @@ extern JSObject *jsb_cocos2d_plugin_FacebookAgent_prototype; bool js_pluginx_protocols_FacebookAgent_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_pluginx_protocols_FacebookAgent_finalize(JSContext *cx, JSObject *obj); -void js_register_pluginx_protocols_FacebookAgent(JSContext *cx, JSObject *global); -void register_all_pluginx_protocols(JSContext* cx, JSObject* obj); +void js_register_pluginx_protocols_FacebookAgent(JSContext *cx, JS::HandleObject global); +void register_all_pluginx_protocols(JSContext* cx, JS::HandleObject obj); bool js_pluginx_protocols_FacebookAgent_activateApp(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_FacebookAgent_getUserID(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_protocols_FacebookAgent_logEvent(JSContext *cx, uint32_t argc, jsval *vp); diff --git a/jsbindings/manual/jsb_pluginx_basic_conversions.cpp b/jsbindings/manual/jsb_pluginx_basic_conversions.cpp index d6dcb8e3..4a154751 100644 --- a/jsbindings/manual/jsb_pluginx_basic_conversions.cpp +++ b/jsbindings/manual/jsb_pluginx_basic_conversions.cpp @@ -43,10 +43,7 @@ class JSStringWrapper // Not suppored in SpiderMonkey v19 //buffer = JS_EncodeString(cx, string); - const jschar *chars = JS_GetStringCharsZ(cx, string); - size_t l = JS_GetStringLength(string); - char* pUTF8Str = cc_utf16_to_utf8((const unsigned short*)chars, l, NULL, NULL); - buffer = pUTF8Str; + buffer = JS_EncodeString(cx, str); } std::string get() { @@ -67,28 +64,28 @@ JSFunctionWrapper::JSFunctionWrapper(JSContext* cx, JSObject *jsthis, jsval fval , _jsthis(jsthis) , _fval(fval) { - JS_AddNamedValueRoot(cx, &this->_fval, "JSFunctionWrapper"); - JS_AddNamedObjectRoot(cx, &this->_jsthis, "JSFunctionWrapper"); + JS::AddNamedValueRoot(cx, &this->_fval, "JSFunctionWrapper"); + JS::AddNamedObjectRoot(cx, &this->_jsthis, "JSFunctionWrapper"); } JSFunctionWrapper::~JSFunctionWrapper() { - JS_RemoveValueRoot(this->_cx, &this->_fval); - JS_RemoveObjectRoot(this->_cx, &this->_jsthis); + JS::RemoveValueRoot(this->_cx, &this->_fval); + JS::RemoveObjectRoot(this->_cx, &this->_jsthis); } -bool JSFunctionWrapper::invoke(unsigned int argc, jsval *argv, jsval &rval) +bool JSFunctionWrapper::invoke(unsigned int argc, jsval *argv, JS::MutableHandleValue rval) { //JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - return JS_CallFunctionValue(this->_cx, this->_jsthis, this->_fval, argc, argv, &rval); + return JS_CallFunctionValue(this->_cx, JS::RootedObject(_cx, this->_jsthis), JS::RootedValue(_cx, this->_fval), JS::HandleValueArray::fromMarkedLocation(argc, argv), rval); } -bool jsval_to_int32( JSContext *cx, jsval vp, int32_t *outval ) +bool jsval_to_int32( JSContext *cx, JS::HandleValue vp, int32_t *outval ) { bool ok = true; double dp; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, vp), &dp); + ok &= JS::ToNumber(cx, vp, &dp); if (!ok) { LOGD("jsval_to_int32: the argument is not a number"); return false; @@ -101,11 +98,11 @@ bool jsval_to_int32( JSContext *cx, jsval vp, int32_t *outval ) return ok; } -bool jsval_to_uint32( JSContext *cx, jsval vp, uint32_t *outval ) +bool jsval_to_uint32( JSContext *cx, JS::HandleValue vp, uint32_t *outval ) { bool ok = true; double dp; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, vp), &dp); + ok &= JS::ToNumber(cx, vp, &dp); if (!ok) { LOGD("jsval_to_uint32: the argument is not a number"); return false; @@ -118,11 +115,11 @@ bool jsval_to_uint32( JSContext *cx, jsval vp, uint32_t *outval ) return ok; } -bool jsval_to_uint16( JSContext *cx, jsval vp, uint16_t *outval ) +bool jsval_to_uint16( JSContext *cx, JS::HandleValue vp, uint16_t *outval ) { bool ok = true; double dp; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, vp), &dp); + ok &= JS::ToNumber(cx, vp, &dp); if (!ok) { LOGD("jsval_to_uint16: the argument is not a number"); return false; @@ -135,9 +132,9 @@ bool jsval_to_uint16( JSContext *cx, jsval vp, uint16_t *outval ) return ok; } -bool jsval_to_long_long(JSContext *cx, jsval vp, long long* r) { +bool jsval_to_long_long(JSContext *cx, JS::HandleValue vp, long long* r) { JS::RootedObject tmp_arg(cx); - bool ok = JS_ValueToObject( cx, JS::RootedValue(cx, vp), &tmp_arg ); + bool ok = JS_ValueToObject( cx, vp, &tmp_arg ); if (!ok) { LOGD("jsval_to_long_long: Error converting value to object"); return false; @@ -155,11 +152,11 @@ bool jsval_to_long_long(JSContext *cx, jsval vp, long long* r) { return true; } -bool jsval_to_long(JSContext *cx, jsval vp, long* ret) +bool jsval_to_long(JSContext *cx, JS::HandleValue vp, long* ret) { bool ok = true; double dp; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, vp), &dp); + ok &= JS::ToNumber(cx, vp, &dp); if (!ok) { LOGD("jsval_to_long: the argument is not a number"); return false; @@ -172,8 +169,8 @@ bool jsval_to_long(JSContext *cx, jsval vp, long* ret) return ok; } -bool jsval_to_std_string(JSContext *cx, jsval v, std::string* ret) { - JSString *tmp = JS::ToString(cx, JS::RootedValue(cx, v)); +bool jsval_to_std_string(JSContext *cx, JS::HandleValue v, std::string* ret) { + JSString *tmp = JS::ToString(cx, v); if (!tmp) { LOGD("jsval_to_std_string: the jsval is not a string."); return false; @@ -184,33 +181,33 @@ bool jsval_to_std_string(JSContext *cx, jsval v, std::string* ret) { return true; } -bool jsval_to_TProductInfo(JSContext *cx, jsval v, TProductInfo* ret) +bool jsval_to_TProductInfo(JSContext *cx, JS::HandleValue v, TProductInfo* ret) { - JSObject* tmp = JSVAL_TO_OBJECT(v); + JS::RootedObject tmp(cx, v.toObjectOrNull()); if (!tmp) { LOGD("jsval_to_TProductInfo: the jsval is not an object."); return false; } - JSObject* it = JS_NewPropertyIterator(cx, tmp); + JS::RootedObject it(cx, JS_NewPropertyIterator(cx, tmp)); while (true) { jsid idp; - jsval key; + JS::RootedValue key(cx); if (! JS_NextProperty(cx, it, &idp) || ! JS_IdToValue(cx, idp, &key)) return false; // error - if (key == JSVAL_VOID) + if (key.isNullOrUndefined()) break; // end of iteration - if (! JSVAL_IS_STRING(key)) + if (! key.isString()) continue; // ignore integer properties JS::RootedValue value(cx); - JS_GetPropertyById(cx, tmp, idp, &value); - if (! JSVAL_IS_STRING(value)) + JS_GetPropertyById(cx, tmp, JS::RootedId(cx, idp), &value); + if (! value.isString()) continue; // ignore integer properties - JSStringWrapper strWrapper(JSVAL_TO_STRING(key), cx); - JSStringWrapper strWrapper2(JSVAL_TO_STRING(value), cx); + JSStringWrapper strWrapper(key.toString(), cx); + JSStringWrapper strWrapper2(value.toString(), cx); (*ret)[strWrapper.get()] = strWrapper2.get(); LOGD("iterate object: key = %s, value = %s", strWrapper.get().c_str(), strWrapper2.get().c_str()); @@ -219,40 +216,40 @@ bool jsval_to_TProductInfo(JSContext *cx, jsval v, TProductInfo* ret) return true; } -bool jsval_to_FBInfo(JSContext *cx, jsval v, StringMap* ret) +bool jsval_to_FBInfo(JSContext *cx, JS::HandleValue v, StringMap* ret) { - JSObject* tmp = JSVAL_TO_OBJECT(v); + JS::RootedObject tmp(cx, v.toObjectOrNull()); if (!tmp) { LOGD("jsval_to_TProductInfo: the jsval is not an object."); return false; } - JSObject* it = JS_NewPropertyIterator(cx, tmp); + JS::RootedObject it(cx, JS_NewPropertyIterator(cx, tmp)); while (true) { jsid idp; - jsval key; + JS::RootedValue key(cx); if (! JS_NextProperty(cx, it, &idp) || ! JS_IdToValue(cx, idp, &key)) return false; // error - if (key == JSVAL_VOID) + if (key.isNullOrUndefined()) break; // end of iteration - if (! JSVAL_IS_STRING(key)) + if (! key.isString()) continue; // ignore integer properties JS::RootedValue value(cx); - JS_GetPropertyById(cx, tmp, idp, &value); + JS_GetPropertyById(cx, tmp, JS::RootedId(cx, idp), &value); // if (! JSVAL_IS_STRING(value)) // continue; // ignore integer properties - if(JSVAL_IS_STRING(value)) + if(value.isString()) { - JSStringWrapper strWrapper(JSVAL_TO_STRING(key), cx); - JSStringWrapper strWrapper2(JSVAL_TO_STRING(value), cx); + JSStringWrapper strWrapper(key.toString(), cx); + JSStringWrapper strWrapper2(value.toString(), cx); ret->insert(std::map::value_type(strWrapper.get(), strWrapper2.get())); } - else if(JSVAL_IS_NUMBER(value)) + else if(value.isNumber()) { double number = 0.0; JS::ToNumber(cx, value, &number); @@ -260,15 +257,15 @@ bool jsval_to_FBInfo(JSContext *cx, jsval v, StringMap* ret) std::stringstream ss; ss << number; - JSStringWrapper strWrapper(JSVAL_TO_STRING(key), cx); + JSStringWrapper strWrapper(key.toString(), cx); //JSStringWrapper strWrapper2(JSVAL_TO_STRING(value), cx); ret->insert(std::map::value_type(strWrapper.get(), ss.str())); } - else if(JSVAL_IS_BOOLEAN(value)) + else if(value.isBoolean()) { bool boolVal = JS::ToBoolean(value); - JSStringWrapper strWrapper(JSVAL_TO_STRING(key), cx); + JSStringWrapper strWrapper(key.toString(), cx); //JSStringWrapper strWrapper2(JSVAL_TO_STRING(value), cx); std::string boolstring = boolVal ? "true" : "false"; ret->insert(std::map::value_type(strWrapper.get(), boolstring)); @@ -278,7 +275,7 @@ bool jsval_to_FBInfo(JSContext *cx, jsval v, StringMap* ret) return true; } -bool jsval_array_to_string(JSContext *cx, jsval v, std::string* ret) +bool jsval_array_to_string(JSContext *cx, JS::HandleValue v, std::string* ret) { JS::RootedObject jsobj(cx); bool ok = v.isObject() && JS_ValueToObject( cx, JS::RootedValue(cx, v), &jsobj ); @@ -304,52 +301,52 @@ bool jsval_array_to_string(JSContext *cx, jsval v, std::string* ret) return true; } -bool jsval_to_TIAPDeveloperInfo(JSContext *cx, jsval v, TIAPDeveloperInfo* ret) +bool jsval_to_TIAPDeveloperInfo(JSContext *cx, JS::HandleValue v, TIAPDeveloperInfo* ret) { return jsval_to_TProductInfo(cx, v, ret); } -bool jsval_to_TAdsDeveloperInfo(JSContext *cx, jsval v, TAdsDeveloperInfo* ret) +bool jsval_to_TAdsDeveloperInfo(JSContext *cx, JS::HandleValue v, TAdsDeveloperInfo* ret) { return jsval_to_TProductInfo(cx, v, ret); } -bool jsval_to_TAdsInfo(JSContext *cx, jsval v, TAdsInfo* ret) +bool jsval_to_TAdsInfo(JSContext *cx, JS::HandleValue v, TAdsInfo* ret) { return jsval_to_TProductInfo(cx, v, ret); } -bool jsval_to_TShareDeveloperInfo(JSContext *cx, jsval v, TShareDeveloperInfo* ret) +bool jsval_to_TShareDeveloperInfo(JSContext *cx, JS::HandleValue v, TShareDeveloperInfo* ret) { return jsval_to_TProductInfo(cx, v, ret); } -bool jsval_to_TShareInfo(JSContext *cx, jsval v, TShareInfo* ret) +bool jsval_to_TShareInfo(JSContext *cx, JS::HandleValue v, TShareInfo* ret) { return jsval_to_TProductInfo(cx, v, ret); } -bool jsval_to_TPaymentInfo(JSContext *cx, jsval v, std::map* ret) +bool jsval_to_TPaymentInfo(JSContext *cx, JS::HandleValue v, std::map* ret) { return jsval_to_TProductInfo(cx, v, ret); } -bool jsval_to_TSocialDeveloperInfo(JSContext *cx, jsval v, TSocialDeveloperInfo* ret) +bool jsval_to_TSocialDeveloperInfo(JSContext *cx, JS::HandleValue v, TSocialDeveloperInfo* ret) { return jsval_to_TProductInfo(cx, v, ret); } -bool jsval_to_TAchievementInfo(JSContext *cx, jsval v, TAchievementInfo* ret) +bool jsval_to_TAchievementInfo(JSContext *cx, JS::HandleValue v, TAchievementInfo* ret) { return jsval_to_TProductInfo(cx, v, ret); } -bool jsval_to_TUserDeveloperInfo(JSContext *cx, jsval v, TUserDeveloperInfo* ret) +bool jsval_to_TUserDeveloperInfo(JSContext *cx, JS::HandleValue v, TUserDeveloperInfo* ret) { return jsval_to_TProductInfo(cx, v, ret); } -bool jsval_to_LogEventParamMap(JSContext *cx, jsval v, LogEventParamMap** ret) +bool jsval_to_LogEventParamMap(JSContext *cx, JS::HandleValue v, LogEventParamMap** ret) { bool jsret = false; if (v.isObject()) @@ -364,49 +361,49 @@ bool jsval_to_LogEventParamMap(JSContext *cx, jsval v, LogEventParamMap** ret) return jsret; } -bool jsval_to_StringMap(JSContext *cx, jsval v, StringMap* ret) +bool jsval_to_StringMap(JSContext *cx, JS::HandleValue v, StringMap* ret) { return jsval_to_TProductInfo(cx, v, ret); } -bool jsval_to_std_map_string_string(JSContext *cx, jsval v, std::map* ret) +bool jsval_to_std_map_string_string(JSContext *cx, JS::HandleValue v, std::map* ret) { - if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) + if (v.isNullOrUndefined()) { return true; } - JSObject* tmp = JSVAL_TO_OBJECT(v); + JS::RootedObject tmp(cx, v.toObjectOrNull()); if (!tmp) { CCLOG("%s", "jsval_to_ccvaluemap: the jsval is not an object."); return false; } - JSObject* it = JS_NewPropertyIterator(cx, tmp); + JS::RootedObject it(cx, JS_NewPropertyIterator(cx, tmp)); while (true) { jsid idp; - jsval key; + JS::RootedValue key(cx); if (! JS_NextProperty(cx, it, &idp) || ! JS_IdToValue(cx, idp, &key)) { return false; // error } - if (key == JSVAL_VOID) { + if (key.isNullOrUndefined()) { break; // end of iteration } - if (!JSVAL_IS_STRING(key)) { + if (!key.isString()) { continue; // ignore integer properties } - JSStringWrapper keyWrapper(JSVAL_TO_STRING(key), cx); + JSStringWrapper keyWrapper(key.toString(), cx); JS::RootedValue value(cx); - JS_GetPropertyById(cx, tmp, idp, &value); + JS_GetPropertyById(cx, tmp, JS::RootedId(cx, idp), &value); if (value.isString()) { - JSStringWrapper valueWapper(JSVAL_TO_STRING(value), cx); + JSStringWrapper valueWapper(value.toString(), cx); ret->insert(std::make_pair(keyWrapper.get(), valueWapper.get())); } else @@ -467,25 +464,25 @@ jsval c_string_to_jsval(JSContext* cx, const char* v, size_t length /* = -1 */) jsval TProductInfo_to_jsval(JSContext *cx, TProductInfo& ret) { - JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); + JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!tmp) return JSVAL_NULL; for (TProductInfo::iterator it = ret.begin(); it != ret.end(); ++it) { - JS_DefineProperty(cx, tmp, it->first.c_str(), std_string_to_jsval(cx, it->second), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineProperty(cx, tmp, it->first.c_str(), JS::RootedValue(cx, std_string_to_jsval(cx, it->second)), JSPROP_ENUMERATE | JSPROP_PERMANENT); } return OBJECT_TO_JSVAL(tmp); } jsval TProductList_to_jsval(JSContext *cx,TProductList list){ - JSObject *tmp = JS_NewArrayObject(cx, 0, NULL); + JS::RootedObject tmp(cx, JS_NewArrayObject(cx, 0)); int i = 0; for(TProductList::iterator it = list.begin();it!=list.end();++it){ JS::RootedValue arrElement(cx); arrElement = TProductInfo_to_jsval(cx, *it); - JS_SetElement(cx, tmp, i, &arrElement); + JS_SetElement(cx, tmp, i, arrElement); ++i; } return OBJECT_TO_JSVAL(tmp); diff --git a/jsbindings/manual/jsb_pluginx_basic_conversions.h b/jsbindings/manual/jsb_pluginx_basic_conversions.h index eee9d469..4153da86 100644 --- a/jsbindings/manual/jsb_pluginx_basic_conversions.h +++ b/jsbindings/manual/jsb_pluginx_basic_conversions.h @@ -20,27 +20,27 @@ using namespace cocos2d::plugin; namespace pluginx { // to native -bool jsval_to_int32( JSContext *cx, jsval vp, int32_t *ret ); -bool jsval_to_uint32( JSContext *cx, jsval vp, uint32_t *ret ); -bool jsval_to_uint16( JSContext *cx, jsval vp, uint16_t *ret ); -bool jsval_to_long(JSContext *cx, jsval v, long* ret); -bool jsval_to_long_long(JSContext *cx, jsval v, long long* ret); -bool jsval_to_std_string(JSContext *cx, jsval v, std::string* ret); -bool jsval_to_TProductInfo(JSContext *cx, jsval v, TProductInfo* ret); -bool jsval_to_TIAPDeveloperInfo(JSContext *cx, jsval v, TIAPDeveloperInfo* ret); -bool jsval_to_TAdsDeveloperInfo(JSContext *cx, jsval v, TAdsDeveloperInfo* ret); -bool jsval_to_TAdsInfo(JSContext *cx, jsval v, TAdsInfo* ret); -bool jsval_to_TShareDeveloperInfo(JSContext *cx, jsval v, TShareDeveloperInfo* ret); -bool jsval_to_TShareInfo(JSContext *cx, jsval v, TShareInfo* ret); -bool jsval_to_TSocialDeveloperInfo(JSContext *cx, jsval v, TSocialDeveloperInfo* ret); -bool jsval_to_TAchievementInfo(JSContext *cx, jsval v, TAchievementInfo* ret); -bool jsval_to_TPaymentInfo(JSContext *cx, jsval v, std::map* ret); -bool jsval_to_TUserDeveloperInfo(JSContext *cx, jsval v, TUserDeveloperInfo* ret); -bool jsval_to_LogEventParamMap(JSContext *cx, jsval v, LogEventParamMap** ret); -bool jsval_to_StringMap(JSContext *cx, jsval v, StringMap* ret); -bool jsval_to_FBInfo(JSContext *cx, jsval v, StringMap* ret); -bool jsval_array_to_string(JSContext *cx, jsval v, std::string* ret); -bool jsval_to_std_map_string_string(JSContext *cx, jsval v, std::map* ret); +bool jsval_to_int32( JSContext *cx, JS::HandleValue vp, int32_t *ret ); +bool jsval_to_uint32( JSContext *cx, JS::HandleValue vp, uint32_t *ret ); +bool jsval_to_uint16( JSContext *cx, JS::HandleValue vp, uint16_t *ret ); +bool jsval_to_long(JSContext *cx, JS::HandleValue v, long* ret); +bool jsval_to_long_long(JSContext *cx, JS::HandleValue v, long long* ret); +bool jsval_to_std_string(JSContext *cx, JS::HandleValue v, std::string* ret); +bool jsval_to_TProductInfo(JSContext *cx, JS::HandleValue v, TProductInfo* ret); +bool jsval_to_TIAPDeveloperInfo(JSContext *cx, JS::HandleValue v, TIAPDeveloperInfo* ret); +bool jsval_to_TAdsDeveloperInfo(JSContext *cx, JS::HandleValue v, TAdsDeveloperInfo* ret); +bool jsval_to_TAdsInfo(JSContext *cx, JS::HandleValue v, TAdsInfo* ret); +bool jsval_to_TShareDeveloperInfo(JSContext *cx, JS::HandleValue v, TShareDeveloperInfo* ret); +bool jsval_to_TShareInfo(JSContext *cx, JS::HandleValue v, TShareInfo* ret); +bool jsval_to_TSocialDeveloperInfo(JSContext *cx, JS::HandleValue v, TSocialDeveloperInfo* ret); +bool jsval_to_TAchievementInfo(JSContext *cx, JS::HandleValue v, TAchievementInfo* ret); +bool jsval_to_TPaymentInfo(JSContext *cx, JS::HandleValue v, std::map* ret); +bool jsval_to_TUserDeveloperInfo(JSContext *cx, JS::HandleValue v, TUserDeveloperInfo* ret); +bool jsval_to_LogEventParamMap(JSContext *cx, JS::HandleValue v, LogEventParamMap** ret); +bool jsval_to_StringMap(JSContext *cx, JS::HandleValue v, StringMap* ret); +bool jsval_to_FBInfo(JSContext *cx, JS::HandleValue v, StringMap* ret); +bool jsval_array_to_string(JSContext *cx, JS::HandleValue v, std::string* ret); +bool jsval_to_std_map_string_string(JSContext *cx, JS::HandleValue v, std::map* ret); // from native jsval int32_to_jsval( JSContext *cx, int32_t l); jsval uint32_to_jsval( JSContext *cx, uint32_t number ); @@ -60,11 +60,11 @@ class JSFunctionWrapper JSFunctionWrapper(JSContext* cx, JSObject *jsthis, jsval fval); ~JSFunctionWrapper(); - bool invoke(unsigned int argc, jsval *argv, jsval &rval); + bool invoke(unsigned int argc, jsval *argv, JS::MutableHandleValue rval); private: JSContext *_cx; - JSObject *_jsthis; - jsval _fval; + JS::Heap _jsthis; + JS::Heap _fval; private: JSFunctionWrapper(const JSFunctionWrapper &); JSFunctionWrapper& operator=(const JSFunctionWrapper &); diff --git a/jsbindings/manual/jsb_pluginx_extension_registration.cpp b/jsbindings/manual/jsb_pluginx_extension_registration.cpp index 078d5b16..e7d2945b 100644 --- a/jsbindings/manual/jsb_pluginx_extension_registration.cpp +++ b/jsbindings/manual/jsb_pluginx_extension_registration.cpp @@ -2,10 +2,11 @@ #include "jsb_pluginx_manual_callback.h" #include "jsb_pluginx_manual_protocols.h" -static jsval anonEvaluate(JSContext *cx, JSObject *thisObj, const char* string) { - jsval out; +static jsval anonEvaluate(JSContext *cx, JS::HandleObject thisObj, const char* string) { + JS::RootedValue out(cx); +// JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET if (JS_EvaluateScript(cx, thisObj, string, strlen(string), "(string)", 1, &out) == true) { - return out; + return out.get(); } return JSVAL_VOID; } @@ -18,47 +19,59 @@ extern JSObject *jsb_cocos2d_plugin_ProtocolSocial_prototype; extern JSObject *jsb_cocos2d_plugin_ProtocolUser_prototype; extern JSObject *jsb_cocos2d_plugin_FacebookAgent_prototype; -void register_pluginx_js_extensions(JSContext* cx, JSObject* global) +void register_pluginx_js_extensions(JSContext* cx, JS::HandleObject global) { // first, try to get the ns JS::RootedValue nsval(cx); JS::RootedObject ns(cx); JS_GetProperty(cx, global, "plugin", &nsval); if (nsval == JSVAL_VOID) { - ns = JS_NewObject(cx, NULL, NULL, NULL); + ns = JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()); nsval = OBJECT_TO_JSVAL(ns); JS_SetProperty(cx, global, "plugin", nsval); } else { JS_ValueToObject(cx, nsval, &ns); } - JS_DefineFunction(cx, jsb_cocos2d_plugin_ProtocolIAP_prototype, "setListener", js_pluginx_ProtocolIAP_setResultListener, 1, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_ProtocolIAP_prototype, "getListener", js_pluginx_ProtocolIAP_getResultListener, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_ProtocolIAP_prototype, "payForProduct", js_pluginx_ProtocolIAP_payForProduct, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_ProtocolAds_prototype, "setListener", js_pluginx_ProtocolAds_setAdsListener, 1, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_ProtocolAds_prototype, "getListener", js_pluginx_ProtocolAds_getAdsListener, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_ProtocolShare_prototype, "setListener", js_pluginx_ProtocolShare_setResultListener, 1, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_ProtocolShare_prototype, "getListener", js_pluginx_ProtocolShare_getResultListener, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_ProtocolShare_prototype, "share", js_pluginx_ProtocolShare_share, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_ProtocolSocial_prototype, "setListener", js_pluginx_ProtocolSocial_setListener, 1, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_ProtocolSocial_prototype, "getListener", js_pluginx_ProtocolSocial_getListener, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_ProtocolSocial_prototype, "submitScore", js_pluginx_ProtocolSocial_submitScore, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_ProtocolSocial_prototype, "unlockAchievement", js_pluginx_ProtocolSocial_unlockAchievement, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_ProtocolUser_prototype, "setActionListener", js_pluginx_ProtocolUser_setActionListener, 1, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_ProtocolUser_prototype, "getActionListener", js_pluginx_ProtocolUser_getActionListener, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_ProtocolUser_prototype, "login", js_pluginx_ProtocolUser_login, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_ProtocolUser_prototype, "logout", js_pluginx_ProtocolUser_logout, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_PluginProtocol_prototype, "callFuncWithParam", js_pluginx_PluginProtocol_callFuncWithParam, 1, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_PluginProtocol_prototype, "callStringFuncWithParam", js_pluginx_PluginProtocol_callStringFuncWithParam, 1, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_PluginProtocol_prototype, "callIntFuncWithParam", js_pluginx_PluginProtocol_callIntFuncWithParam, 1, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_PluginProtocol_prototype, "callFloatFuncWithParam", js_pluginx_PluginProtocol_callFloatFuncWithParam, 1, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_PluginProtocol_prototype, "callBoolFuncWithParam", js_pluginx_PluginProtocol_callBoolFuncWithParam, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS::RootedObject iap(cx, jsb_cocos2d_plugin_ProtocolIAP_prototype); + JS_DefineFunction(cx, iap, "setListener", js_pluginx_ProtocolIAP_setResultListener, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, iap, "getListener", js_pluginx_ProtocolIAP_getResultListener, 0, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, iap, "payForProduct", js_pluginx_ProtocolIAP_payForProduct, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_FacebookAgent_prototype, "login", js_pluginx_FacebookAgent_login, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_FacebookAgent_prototype, "_api", js_pluginx_FacebookAgent_api, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_FacebookAgent_prototype, "appRequest", js_pluginx_FacebookAgent_appRequest, 0, JSPROP_READONLY | JSPROP_PERMANENT); - JS_DefineFunction(cx, jsb_cocos2d_plugin_FacebookAgent_prototype, "dialog", js_pluginx_FacebookAgent_dialog, 0, JSPROP_READONLY | JSPROP_PERMANENT); + JS::RootedObject ads(cx, jsb_cocos2d_plugin_ProtocolAds_prototype); + JS_DefineFunction(cx, ads, "setListener", js_pluginx_ProtocolAds_setAdsListener, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, ads, "getListener", js_pluginx_ProtocolAds_getAdsListener, 0, JSPROP_READONLY | JSPROP_PERMANENT); + + JS::RootedObject share(cx, jsb_cocos2d_plugin_ProtocolShare_prototype); + JS_DefineFunction(cx, share, "setListener", js_pluginx_ProtocolShare_setResultListener, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, share, "getListener", js_pluginx_ProtocolShare_getResultListener, 0, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, share, "share", js_pluginx_ProtocolShare_share, 0, JSPROP_READONLY | JSPROP_PERMANENT); + + JS::RootedObject social(cx, jsb_cocos2d_plugin_ProtocolSocial_prototype); + JS_DefineFunction(cx, social, "setListener", js_pluginx_ProtocolSocial_setListener, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, social, "getListener", js_pluginx_ProtocolSocial_getListener, 0, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, social, "submitScore", js_pluginx_ProtocolSocial_submitScore, 0, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, social, "unlockAchievement", js_pluginx_ProtocolSocial_unlockAchievement, 0, JSPROP_READONLY | JSPROP_PERMANENT); + + JS::RootedObject user(cx, jsb_cocos2d_plugin_ProtocolUser_prototype); + JS_DefineFunction(cx, user, "setActionListener", js_pluginx_ProtocolUser_setActionListener, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, user, "getActionListener", js_pluginx_ProtocolUser_getActionListener, 0, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, user, "login", js_pluginx_ProtocolUser_login, 0, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, user, "logout", js_pluginx_ProtocolUser_logout, 0, JSPROP_READONLY | JSPROP_PERMANENT); + + JS::RootedObject protocol(cx, jsb_cocos2d_plugin_PluginProtocol_prototype); + JS_DefineFunction(cx, protocol, "callFuncWithParam", js_pluginx_PluginProtocol_callFuncWithParam, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, protocol, "callStringFuncWithParam", js_pluginx_PluginProtocol_callStringFuncWithParam, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, protocol, "callIntFuncWithParam", js_pluginx_PluginProtocol_callIntFuncWithParam, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, protocol, "callFloatFuncWithParam", js_pluginx_PluginProtocol_callFloatFuncWithParam, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, protocol, "callBoolFuncWithParam", js_pluginx_PluginProtocol_callBoolFuncWithParam, 1, JSPROP_READONLY | JSPROP_PERMANENT); + + JS::RootedObject facebook(cx, jsb_cocos2d_plugin_FacebookAgent_prototype); + JS_DefineFunction(cx, facebook, "login", js_pluginx_FacebookAgent_login, 0, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, facebook, "_api", js_pluginx_FacebookAgent_api, 0, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, facebook, "appRequest", js_pluginx_FacebookAgent_appRequest, 0, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, facebook, "dialog", js_pluginx_FacebookAgent_dialog, 0, JSPROP_READONLY | JSPROP_PERMANENT); - global = ns; - js_register_pluginx_protocols_PluginParam(cx, global); +// global = ns; + js_register_pluginx_protocols_PluginParam(cx, ns); } diff --git a/jsbindings/manual/jsb_pluginx_extension_registration.h b/jsbindings/manual/jsb_pluginx_extension_registration.h index 446b116b..4ad95dbb 100644 --- a/jsbindings/manual/jsb_pluginx_extension_registration.h +++ b/jsbindings/manual/jsb_pluginx_extension_registration.h @@ -4,6 +4,6 @@ #include "jsapi.h" #include "jsfriendapi.h" -void register_pluginx_js_extensions(JSContext* cx, JSObject* global); +void register_pluginx_js_extensions(JSContext* cx, JS::HandleObject global); #endif /* __JS_EXTENSION_REGISTRATION_H__ */ diff --git a/jsbindings/manual/jsb_pluginx_manual_callback.cpp b/jsbindings/manual/jsb_pluginx_manual_callback.cpp index ed1f6b1a..53633ba8 100644 --- a/jsbindings/manual/jsb_pluginx_manual_callback.cpp +++ b/jsbindings/manual/jsb_pluginx_manual_callback.cpp @@ -23,11 +23,11 @@ class Pluginx_PurchaseResult : public cocos2d::plugin::PayResultListener JSContext* cx = s_cx; - JSObject* obj = _JSDelegate; + JS::RootedObject obj(cx, _JSDelegate); JSAutoCompartment ac(cx, obj); bool hasAction; - jsval retval; + JS::RootedValue retval(cx); JS::RootedValue temp_retval(cx); jsval dataVal[3]; dataVal[0] = INT_TO_JSVAL(ret); @@ -44,8 +44,7 @@ class Pluginx_PurchaseResult : public cocos2d::plugin::PayResultListener return; } - JS_CallFunctionName(cx, obj, "onPayResult", - 3, dataVal, &retval); + JS_CallFunctionName(cx, obj, "onPayResult", JS::HandleValueArray::fromMarkedLocation(3, dataVal), &retval); } } @@ -61,11 +60,11 @@ class Pluginx_PurchaseResult : public cocos2d::plugin::PayResultListener virtual void onRequestProductsResult(cocos2d::plugin::IAPProductRequest ret, cocos2d::plugin::TProductList info){ JSContext* cx = s_cx; - JSObject* obj = _JSDelegate; + JS::RootedObject obj(cx, _JSDelegate); JSAutoCompartment ac(cx, obj); bool hasAction; - jsval retval; + JS::RootedValue retval(cx); JS::RootedValue temp_retval(cx); jsval dataVal[2]; dataVal[0] = INT_TO_JSVAL(ret); @@ -81,19 +80,18 @@ class Pluginx_PurchaseResult : public cocos2d::plugin::PayResultListener return; } - JS_CallFunctionName(cx, obj, "onRequestProductResult", - 2, dataVal, &retval); + JS_CallFunctionName(cx, obj, "onRequestProductResult", JS::HandleValueArray::fromMarkedLocation(2, dataVal), &retval); } } private: - JSObject* _JSDelegate; + JS::Heap _JSDelegate; }; bool js_pluginx_ProtocolIAP_setResultListener(JSContext *cx, uint32_t argc, jsval *vp) { s_cx = cx; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolIAP* cobj = (cocos2d::plugin::ProtocolIAP *)(proxy ? proxy->ptr : NULL); @@ -101,12 +99,12 @@ bool js_pluginx_ProtocolIAP_setResultListener(JSContext *cx, uint32_t argc, jsva if (argc == 1) { // save the delegate - JSObject *jsDelegate = JSVAL_TO_OBJECT(argv[0]); + JSObject *jsDelegate = args.get(0).toObjectOrNull(); Pluginx_PurchaseResult* nativeDelegate = new Pluginx_PurchaseResult(); nativeDelegate->setJSDelegate(jsDelegate); cobj->setResultListener(nativeDelegate); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -116,6 +114,7 @@ bool js_pluginx_ProtocolIAP_setResultListener(JSContext *cx, uint32_t argc, jsva bool js_pluginx_ProtocolIAP_getResultListener(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolIAP* cobj = (cocos2d::plugin::ProtocolIAP *)(proxy ? proxy->ptr : NULL); @@ -131,7 +130,7 @@ bool js_pluginx_ProtocolIAP_getResultListener(JSContext *cx, uint32_t argc, jsva jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().setUndefined(); return true; } @@ -141,7 +140,7 @@ bool js_pluginx_ProtocolIAP_getResultListener(JSContext *cx, uint32_t argc, jsva bool js_pluginx_ProtocolIAP_payForProduct(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -149,28 +148,28 @@ bool js_pluginx_ProtocolIAP_payForProduct(JSContext *cx, uint32_t argc, jsval *v JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolIAP_payForProduct : Invalid Native Object"); if (argc == 1) { cocos2d::plugin::TProductInfo arg0; - ok &= pluginx::jsval_to_TProductInfo(cx, argv[0], &arg0); + ok &= pluginx::jsval_to_TProductInfo(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolIAP_payForProduct : Error processing arguments"); cobj->payForProduct(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if(argc == 2){ cocos2d::plugin::TProductInfo arg0; - ok &= pluginx::jsval_to_TProductInfo(cx, argv[0], &arg0); + ok &= pluginx::jsval_to_TProductInfo(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolIAP_payForProduct : Error processing arguments"); std::function arg1; do { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), args.get(1))); auto lambda = [=](int larg0, std::string& larg1) -> void { JSAutoCompartment ac(cx, obj); jsval largv[2]; largv[0] = int32_to_jsval(cx, larg0); largv[1] = std_string_to_jsval(cx, larg1); - jsval rval; - bool succeed = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool succeed = func->invoke(2, &largv[0], &rval); if (!succeed && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -179,7 +178,7 @@ bool js_pluginx_ProtocolIAP_payForProduct(JSContext *cx, uint32_t argc, jsval *v } while(0); cobj->payForProduct(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -194,11 +193,11 @@ class Pluginx_AdsListener : public cocos2d::plugin::AdsListener virtual void onAdsResult(AdsResultCode code, const char* msg) { JSContext* cx = s_cx; - JSObject* obj = _JSDelegate; + JS::RootedObject obj(cx, _JSDelegate); JSAutoCompartment ac(cx, obj); bool hasAction; - jsval retval; + JS::RootedValue retval(cx); JS::RootedValue temp_retval(cx); jsval dataVal[2]; dataVal[0] = INT_TO_JSVAL(code); @@ -213,19 +212,18 @@ class Pluginx_AdsListener : public cocos2d::plugin::AdsListener if(temp_retval == JSVAL_VOID) { return; } - JS_CallFunctionName(cx, obj, "onAdsResult", - 2, dataVal, &retval); + JS_CallFunctionName(cx, obj, "onAdsResult", JS::HandleValueArray::fromMarkedLocation(2, dataVal), &retval); } } virtual void onPlayerGetPoints(ProtocolAds* pAdsPlugin, int points) { JSContext* cx = s_cx; - JSObject* obj = _JSDelegate; + JS::RootedObject obj(cx, _JSDelegate); JSAutoCompartment ac(cx, obj); bool hasAction; - jsval retval; + JS::RootedValue retval(cx); JS::RootedValue temp_retval(cx); js_proxy_t * p; @@ -245,8 +243,7 @@ class Pluginx_AdsListener : public cocos2d::plugin::AdsListener if(temp_retval == JSVAL_VOID) { return; } - JS_CallFunctionName(cx, obj, "onPlayerGetPoints", - 2, NULL, &retval); + JS_CallFunctionName(cx, obj, "onPlayerGetPoints", JS::HandleValueArray::fromMarkedLocation(2, dataVal), &retval); } } @@ -260,25 +257,25 @@ class Pluginx_AdsListener : public cocos2d::plugin::AdsListener } private: - JSObject* _JSDelegate; + JS::Heap _JSDelegate; }; bool js_pluginx_ProtocolAds_setAdsListener(JSContext *cx, uint32_t argc, jsval *vp) { s_cx = cx; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL); bool ok = true; if (argc == 1) { // save the delegate - JSObject *jsDelegate = JSVAL_TO_OBJECT(argv[0]); + JSObject *jsDelegate = args.get(0).toObjectOrNull(); Pluginx_AdsListener* nativeDelegate = new Pluginx_AdsListener(); nativeDelegate->setJSDelegate(jsDelegate); cobj->setAdsListener(nativeDelegate); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -288,6 +285,7 @@ bool js_pluginx_ProtocolAds_setAdsListener(JSContext *cx, uint32_t argc, jsval * bool js_pluginx_ProtocolAds_getAdsListener(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL); @@ -303,7 +301,7 @@ bool js_pluginx_ProtocolAds_getAdsListener(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -317,11 +315,11 @@ class Pluginx_ShareResult : public cocos2d::plugin::ShareResultListener virtual void onShareResult(cocos2d::plugin::ShareResultCode ret, const char* msg) { JSContext* cx = s_cx; - JSObject* obj = _JSDelegate; + JS::RootedObject obj(cx, _JSDelegate); JSAutoCompartment ac(cx, obj); bool hasAction; - jsval retval; + JS::RootedValue retval(cx); JS::RootedValue temp_retval(cx); jsval dataVal[2]; dataVal[0] = INT_TO_JSVAL(ret); @@ -335,8 +333,7 @@ class Pluginx_ShareResult : public cocos2d::plugin::ShareResultListener if(temp_retval == JSVAL_VOID) { return; } - JS_CallFunctionName(cx, obj, "onShareResult", - 2, dataVal, &retval); + JS_CallFunctionName(cx, obj, "onShareResult", JS::HandleValueArray::fromMarkedLocation(2, dataVal), &retval); } } @@ -351,13 +348,13 @@ class Pluginx_ShareResult : public cocos2d::plugin::ShareResultListener } private: - JSObject* _JSDelegate; + JS::Heap _JSDelegate; }; bool js_pluginx_ProtocolShare_setResultListener(JSContext *cx, uint32_t argc, jsval *vp) { s_cx = cx; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolShare* cobj = (cocos2d::plugin::ProtocolShare *)(proxy ? proxy->ptr : NULL); @@ -365,12 +362,12 @@ bool js_pluginx_ProtocolShare_setResultListener(JSContext *cx, uint32_t argc, js if (argc == 1) { // save the delegate - JSObject *jsDelegate = JSVAL_TO_OBJECT(argv[0]); + JSObject *jsDelegate = args.get(0).toObjectOrNull(); Pluginx_ShareResult* nativeDelegate = new Pluginx_ShareResult(); nativeDelegate->setJSDelegate(jsDelegate); cobj->setResultListener(nativeDelegate); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -380,6 +377,7 @@ bool js_pluginx_ProtocolShare_setResultListener(JSContext *cx, uint32_t argc, js bool js_pluginx_ProtocolShare_getResultListener(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolShare* cobj = (cocos2d::plugin::ProtocolShare *)(proxy ? proxy->ptr : NULL); @@ -395,7 +393,7 @@ bool js_pluginx_ProtocolShare_getResultListener(JSContext *cx, uint32_t argc, js jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -405,7 +403,7 @@ bool js_pluginx_ProtocolShare_getResultListener(JSContext *cx, uint32_t argc, js bool js_pluginx_ProtocolShare_share(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -413,28 +411,28 @@ bool js_pluginx_ProtocolShare_share(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolShare_share : Invalid Native Object"); if (argc == 1) { cocos2d::plugin::TShareInfo arg0; - ok &= pluginx::jsval_to_TShareInfo(cx, argv[0], &arg0); + ok &= pluginx::jsval_to_TShareInfo(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolShare_share : Error processing arguments"); cobj->share(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if(argc == 2){ cocos2d::plugin::TShareInfo arg0; - ok &= pluginx::jsval_to_TShareInfo(cx, argv[0], &arg0); + ok &= pluginx::jsval_to_TShareInfo(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolShare_share : Error processing arguments"); std::function arg1; do { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), args.get(1))); auto lambda = [=](int larg0, std::string& larg1) -> void { JSAutoCompartment ac(cx, obj); jsval largv[2]; largv[0] = int32_to_jsval(cx, larg0); largv[1] = std_string_to_jsval(cx, larg1); - jsval rval; - bool succeed = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool succeed = func->invoke(2, &largv[0], &rval); if (!succeed && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -443,7 +441,7 @@ bool js_pluginx_ProtocolShare_share(JSContext *cx, uint32_t argc, jsval *vp) } while(0); cobj->share(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -457,11 +455,11 @@ class Pluginx_SocialResult : public cocos2d::plugin::SocialListener virtual void onSocialResult(cocos2d::plugin::SocialRetCode ret, const char* msg) { JSContext* cx = s_cx; - JSObject* obj = _JSDelegate; + JS::RootedObject obj(cx, _JSDelegate); JSAutoCompartment ac(cx, obj); bool hasAction; - jsval retval; + JS::RootedValue retval(cx); JS::RootedValue temp_retval(cx); jsval dataVal[2]; dataVal[0] = INT_TO_JSVAL(ret); @@ -475,8 +473,7 @@ class Pluginx_SocialResult : public cocos2d::plugin::SocialListener if(temp_retval == JSVAL_VOID) { return; } - JS_CallFunctionName(cx, obj, "onSocialResult", - 2, dataVal, &retval); + JS_CallFunctionName(cx, obj, "onSocialResult", JS::HandleValueArray::fromMarkedLocation(2, dataVal), &retval); } } @@ -491,13 +488,13 @@ class Pluginx_SocialResult : public cocos2d::plugin::SocialListener } private: - JSObject* _JSDelegate; + JS::Heap _JSDelegate; }; bool js_pluginx_ProtocolSocial_setListener(JSContext *cx, uint32_t argc, jsval *vp) { s_cx = cx; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolSocial* cobj = (cocos2d::plugin::ProtocolSocial *)(proxy ? proxy->ptr : NULL); @@ -505,12 +502,12 @@ bool js_pluginx_ProtocolSocial_setListener(JSContext *cx, uint32_t argc, jsval * if (argc == 1) { // save the delegate - JSObject *jsDelegate = JSVAL_TO_OBJECT(argv[0]); + JSObject *jsDelegate = args.get(0).toObjectOrNull(); Pluginx_SocialResult* nativeDelegate = new Pluginx_SocialResult(); nativeDelegate->setJSDelegate(jsDelegate); cobj->setListener(nativeDelegate); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -520,6 +517,7 @@ bool js_pluginx_ProtocolSocial_setListener(JSContext *cx, uint32_t argc, jsval * bool js_pluginx_ProtocolSocial_getListener(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolSocial* cobj = (cocos2d::plugin::ProtocolSocial *)(proxy ? proxy->ptr : NULL); @@ -535,7 +533,7 @@ bool js_pluginx_ProtocolSocial_getListener(JSContext *cx, uint32_t argc, jsval * jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -545,7 +543,7 @@ bool js_pluginx_ProtocolSocial_getListener(JSContext *cx, uint32_t argc, jsval * bool js_pluginx_ProtocolSocial_submitScore(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -554,31 +552,31 @@ bool js_pluginx_ProtocolSocial_submitScore(JSContext *cx, uint32_t argc, jsval * if (argc == 2) { const char* arg0; long arg1; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - ok &= jsval_to_long(cx, argv[1], (long *)&arg1); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + ok &= jsval_to_long(cx, args.get(1), (long *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolSocial_submitScore : Error processing arguments"); cobj->submitScore(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if(argc == 3){ const char* arg0; long arg1; - std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); - ok &= jsval_to_long(cx, argv[1], (long *)&arg1); + std::string arg0_tmp; ok &= jsval_to_std_string(cx, args.get(0), &arg0_tmp); arg0 = arg0_tmp.c_str(); + ok &= jsval_to_long(cx, args.get(1), (long *)&arg1); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolSocial_submitScore : Error processing arguments"); std::function arg2; do { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[2])); + std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), args.get(2))); auto lambda = [=](int larg0, std::string& larg1) -> void { JSAutoCompartment ac(cx, obj); jsval largv[2]; largv[0] = int32_to_jsval(cx, larg0); largv[1] = std_string_to_jsval(cx, larg1); - jsval rval; - bool succeed = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool succeed = func->invoke(2, &largv[0], &rval); if (!succeed && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -587,7 +585,7 @@ bool js_pluginx_ProtocolSocial_submitScore(JSContext *cx, uint32_t argc, jsval * } while(0); cobj->submitScore(arg0, arg1, arg2); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -597,7 +595,7 @@ bool js_pluginx_ProtocolSocial_submitScore(JSContext *cx, uint32_t argc, jsval * bool js_pluginx_ProtocolSocial_unlockAchievement(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -605,28 +603,28 @@ bool js_pluginx_ProtocolSocial_unlockAchievement(JSContext *cx, uint32_t argc, j JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolSocial_unlockAchievement : Invalid Native Object"); if (argc == 1) { cocos2d::plugin::TAchievementInfo arg0; - ok &= pluginx::jsval_to_TAchievementInfo(cx, argv[0], &arg0); + ok &= pluginx::jsval_to_TAchievementInfo(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolSocial_unlockAchievement : Error processing arguments"); cobj->unlockAchievement(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if(argc ==2){ cocos2d::plugin::TAchievementInfo arg0; - ok &= pluginx::jsval_to_TAchievementInfo(cx, argv[0], &arg0); + ok &= pluginx::jsval_to_TAchievementInfo(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_ProtocolSocial_unlockAchievement : Error processing arguments"); std::function arg1; do { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), args.get(1))); auto lambda = [=](int larg0, std::string& larg1) -> void { JSAutoCompartment ac(cx, obj); jsval largv[2]; largv[0] = int32_to_jsval(cx, larg0); largv[1] = std_string_to_jsval(cx, larg1); - jsval rval; - bool succeed = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool succeed = func->invoke(2, &largv[0], &rval); if (!succeed && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -635,7 +633,7 @@ bool js_pluginx_ProtocolSocial_unlockAchievement(JSContext *cx, uint32_t argc, j } while(0); cobj->unlockAchievement(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -649,11 +647,11 @@ class Pluginx_UserActionListener : public cocos2d::plugin::UserActionListener virtual void onActionResult(ProtocolUser* userPlugin, cocos2d::plugin::UserActionResultCode ret, const char* msg) { JSContext* cx = s_cx; - JSObject* obj = _JSDelegate; + JS::RootedObject obj(cx, _JSDelegate); JSAutoCompartment ac(cx, obj); bool hasAction; - jsval retval; + JS::RootedValue retval(cx); JS::RootedValue temp_retval(cx); js_proxy_t * p; @@ -674,8 +672,7 @@ class Pluginx_UserActionListener : public cocos2d::plugin::UserActionListener if(temp_retval == JSVAL_VOID) { return; } - JS_CallFunctionName(cx, obj, "onActionResult", - 3, dataVal, &retval); + JS_CallFunctionName(cx, obj, "onActionResult", JS::HandleValueArray::fromMarkedLocation(3, dataVal), &retval); } } @@ -690,13 +687,13 @@ class Pluginx_UserActionListener : public cocos2d::plugin::UserActionListener } private: - JSObject* _JSDelegate; + JS::Heap _JSDelegate; }; bool js_pluginx_ProtocolUser_setActionListener(JSContext *cx, uint32_t argc, jsval *vp) { s_cx = cx; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolUser* cobj = (cocos2d::plugin::ProtocolUser *)(proxy ? proxy->ptr : NULL); @@ -704,12 +701,12 @@ bool js_pluginx_ProtocolUser_setActionListener(JSContext *cx, uint32_t argc, jsv if (argc == 1) { // save the delegate - JSObject *jsDelegate = JSVAL_TO_OBJECT(argv[0]); + JSObject *jsDelegate = args.get(0).toObjectOrNull(); Pluginx_UserActionListener* nativeDelegate = new Pluginx_UserActionListener(); nativeDelegate->setJSDelegate(jsDelegate); cobj->setActionListener(nativeDelegate); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -719,6 +716,7 @@ bool js_pluginx_ProtocolUser_setActionListener(JSContext *cx, uint32_t argc, jsv bool js_pluginx_ProtocolUser_getActionListener(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::plugin::ProtocolUser* cobj = (cocos2d::plugin::ProtocolUser *)(proxy ? proxy->ptr : NULL); @@ -734,7 +732,7 @@ bool js_pluginx_ProtocolUser_getActionListener(JSContext *cx, uint32_t argc, jsv jsret = JSVAL_NULL; } } while (0); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } @@ -744,7 +742,7 @@ bool js_pluginx_ProtocolUser_getActionListener(JSContext *cx, uint32_t argc, jsv bool js_pluginx_ProtocolUser_login(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -753,7 +751,7 @@ bool js_pluginx_ProtocolUser_login(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 0) { cobj->login(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -762,14 +760,14 @@ bool js_pluginx_ProtocolUser_login(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 1) { std::function arg0; do { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), args.get(0))); auto lambda = [=](int larg0, std::string& larg1) -> void { JSAutoCompartment ac(cx, obj); jsval largv[2]; largv[0] = int32_to_jsval(cx, larg0); largv[1] = std_string_to_jsval(cx, larg1); - jsval rval; - bool succeed = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool succeed = func->invoke(2, &largv[0], &rval); if (!succeed && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -779,7 +777,7 @@ bool js_pluginx_ProtocolUser_login(JSContext *cx, uint32_t argc, jsval *vp) if (!ok) { ok = true; break; } cobj->login(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -790,7 +788,7 @@ bool js_pluginx_ProtocolUser_login(JSContext *cx, uint32_t argc, jsval *vp) bool js_pluginx_ProtocolUser_logout(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -798,7 +796,7 @@ bool js_pluginx_ProtocolUser_logout(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2( cobj, cx, false, "js_pluginx_protocols_ProtocolUser_logout : Invalid Native Object"); if (argc == 0) { cobj->logout(); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } @@ -806,14 +804,14 @@ bool js_pluginx_ProtocolUser_logout(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 1) { std::function arg0; do { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), args.get(0))); auto lambda = [=](int larg0, std::string& larg1) -> void { JSAutoCompartment ac(cx, obj); jsval largv[2]; largv[0] = int32_to_jsval(cx, larg0); largv[1] = std_string_to_jsval(cx, larg1); - jsval rval; - bool succeed = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool succeed = func->invoke(2, &largv[0], &rval); if (!succeed && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -823,7 +821,7 @@ bool js_pluginx_ProtocolUser_logout(JSContext *cx, uint32_t argc, jsval *vp) if (!ok) { ok = true; break; } cobj->logout(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -835,7 +833,7 @@ bool js_pluginx_ProtocolUser_logout(JSContext *cx, uint32_t argc, jsval *vp) bool js_pluginx_FacebookAgent_login(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -846,20 +844,21 @@ bool js_pluginx_FacebookAgent_login(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 1) { std::function arg0; do { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[0])); + std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), args.get(0))); auto lambda = [=](int larg0, std::string& larg1) -> void { JSAutoCompartment ac(cx, obj); jsval largv[2]; largv[0] = int32_to_jsval(cx, larg0); jsval temp = std_string_to_jsval(cx, larg1); JS::RootedValue outVal(cx); - size_t utf16Count = 0; - const jschar* utf16Buf = JS_GetStringCharsZAndLength(cx, JSVAL_TO_STRING(temp), &utf16Count); - JS_ParseJSON(cx, utf16Buf, static_cast(utf16Count), &outVal); +// size_t utf16Count = 0; +// const jschar* utf16Buf = JS_GetStringCharsZAndLength(cx, JSVAL_TO_STRING(temp), &utf16Count); +// JS_ParseJSON(cx, utf16Buf, static_cast(utf16Count), &outVal); + JS_ParseJSON(cx, JS::RootedString(cx, temp.toString()), &outVal); largv[1] = outVal.get(); - jsval rval; - bool succeed = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool succeed = func->invoke(2, &largv[0], &rval); if (!succeed && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -869,32 +868,33 @@ bool js_pluginx_FacebookAgent_login(JSContext *cx, uint32_t argc, jsval *vp) if (!ok) { ok = true; break; } cobj->login(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } if (argc == 2) { std::string arg0; - ok &= pluginx::jsval_array_to_string(cx, argv[0], &arg0); + ok &= pluginx::jsval_array_to_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_FacebookAgent_login : Error processing arguments"); if (!ok) { ok = true; break; } std::function arg1; do { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), args.get(1))); auto lambda = [=](int larg0, std::string& larg1) -> void { JSAutoCompartment ac(cx, obj); jsval largv[2]; largv[0] = int32_to_jsval(cx, larg0); jsval temp = std_string_to_jsval(cx, larg1); JS::RootedValue outVal(cx); - size_t utf16Count = 0; - const jschar* utf16Buf = JS_GetStringCharsZAndLength(cx, JSVAL_TO_STRING(temp), &utf16Count); - JS_ParseJSON(cx, utf16Buf, static_cast(utf16Count), &outVal); +// size_t utf16Count = 0; +// const jschar* utf16Buf = JS_GetStringCharsZAndLength(cx, JSVAL_TO_STRING(temp), &utf16Count); +// JS_ParseJSON(cx, utf16Buf, static_cast(utf16Count), &outVal); + JS_ParseJSON(cx, JS::RootedString(cx, temp.toString()), &outVal); largv[1] = outVal.get(); - jsval rval; - bool succeed = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool succeed = func->invoke(2, &largv[0], &rval); if (!succeed && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -904,7 +904,7 @@ bool js_pluginx_FacebookAgent_login(JSContext *cx, uint32_t argc, jsval *vp) if (!ok) { ok = true; break; } cobj->login(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -916,7 +916,7 @@ bool js_pluginx_FacebookAgent_login(JSContext *cx, uint32_t argc, jsval *vp) bool js_pluginx_FacebookAgent_api(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -926,27 +926,27 @@ bool js_pluginx_FacebookAgent_api(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 4) { std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); + ok &= jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) { ok = true; break; } int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (!ok) { ok = true; break; } cocos2d::plugin::TShareInfo arg2; - ok &= pluginx::jsval_to_FBInfo(cx, argv[2], &arg2); + ok &= pluginx::jsval_to_FBInfo(cx, args.get(2), &arg2); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_FacebookAgent_api : Error processing arguments"); if (!ok) { ok = true; break; } std::function arg3; do { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[3])); + std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), args.get(3))); auto lambda = [=](int larg0, std::string& larg1) -> void { JSAutoCompartment ac(cx, obj); jsval largv[2]; largv[0] = int32_to_jsval(cx, larg0); largv[1] = std_string_to_jsval(cx, larg1); - jsval rval; - bool succeed = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool succeed = func->invoke(2, &largv[0], &rval); if (!succeed && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -956,7 +956,7 @@ bool js_pluginx_FacebookAgent_api(JSContext *cx, uint32_t argc, jsval *vp) if (!ok) { ok = true; break; } cobj->api(arg0, arg1, arg2, arg3); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -967,7 +967,7 @@ bool js_pluginx_FacebookAgent_api(JSContext *cx, uint32_t argc, jsval *vp) bool js_pluginx_FacebookAgent_appRequest(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -977,26 +977,27 @@ bool js_pluginx_FacebookAgent_appRequest(JSContext *cx, uint32_t argc, jsval *vp do { if (argc == 2) { cocos2d::plugin::TShareInfo arg0; - ok &= pluginx::jsval_to_TShareInfo(cx, argv[0], &arg0); + ok &= pluginx::jsval_to_TShareInfo(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_FacebookAgent_appRequest : Error processing arguments"); if (!ok) { ok = true; break; } std::function arg1; do { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), args.get(1))); auto lambda = [=](int larg0, std::string& larg1) -> void { JSAutoCompartment ac(cx, obj); jsval largv[2]; largv[0] = int32_to_jsval(cx, larg0); jsval temp = std_string_to_jsval(cx, larg1); JS::RootedValue outVal(cx); - size_t utf16Count = 0; - const jschar* utf16Buf = JS_GetStringCharsZAndLength(cx, JSVAL_TO_STRING(temp), &utf16Count); - JS_ParseJSON(cx, utf16Buf, static_cast(utf16Count), &outVal); +// size_t utf16Count = 0; +// const jschar* utf16Buf = JS_GetStringCharsZAndLength(cx, JSVAL_TO_STRING(temp), &utf16Count); +// JS_ParseJSON(cx, utf16Buf, static_cast(utf16Count), &outVal); + JS_ParseJSON(cx, JS::RootedString(cx, temp.toString()), &outVal); largv[1] = outVal.get(); - jsval rval; - bool succeed = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool succeed = func->invoke(2, &largv[0], &rval); if (!succeed && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -1006,7 +1007,7 @@ bool js_pluginx_FacebookAgent_appRequest(JSContext *cx, uint32_t argc, jsval *vp if (!ok) { ok = true; break; } cobj->appRequest(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); @@ -1017,7 +1018,7 @@ bool js_pluginx_FacebookAgent_appRequest(JSContext *cx, uint32_t argc, jsval *vp bool js_pluginx_FacebookAgent_dialog(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -1027,26 +1028,27 @@ bool js_pluginx_FacebookAgent_dialog(JSContext *cx, uint32_t argc, jsval *vp) do { if (argc == 2) { cocos2d::plugin::TShareInfo arg0; - ok &= pluginx::jsval_to_TShareInfo(cx, argv[0], &arg0); + ok &= pluginx::jsval_to_TShareInfo(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_pluginx_protocols_FacebookAgent_dialog : Error processing arguments"); if (!ok) { ok = true; break; } std::function arg1; do { - std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), argv[1])); + std::shared_ptr func(new JSFunctionWrapper(cx, JS_THIS_OBJECT(cx, vp), args.get(1))); auto lambda = [=](int larg0, std::string& larg1) -> void { JSAutoCompartment ac(cx, obj); jsval largv[2]; largv[0] = int32_to_jsval(cx, larg0); jsval temp = std_string_to_jsval(cx, larg1); JS::RootedValue outVal(cx); - size_t utf16Count = 0; - const jschar* utf16Buf = JS_GetStringCharsZAndLength(cx, JSVAL_TO_STRING(temp), &utf16Count); - JS_ParseJSON(cx, utf16Buf, static_cast(utf16Count), &outVal); +// size_t utf16Count = 0; +// const jschar* utf16Buf = JS_GetStringCharsZAndLength(cx, JSVAL_TO_STRING(temp), &utf16Count); +// JS_ParseJSON(cx, utf16Buf, static_cast(utf16Count), &outVal); + JS_ParseJSON(cx, JS::RootedString(cx, temp.toString()), &outVal); largv[1] = outVal.get(); - jsval rval; - bool succeed = func->invoke(2, &largv[0], rval); + JS::RootedValue rval(cx); + bool succeed = func->invoke(2, &largv[0], &rval); if (!succeed && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -1056,7 +1058,7 @@ bool js_pluginx_FacebookAgent_dialog(JSContext *cx, uint32_t argc, jsval *vp) if (!ok) { ok = true; break; } cobj->dialog(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } } while(0); diff --git a/jsbindings/manual/jsb_pluginx_manual_protocols.cpp b/jsbindings/manual/jsb_pluginx_manual_protocols.cpp index 0c642dca..d2d4f726 100644 --- a/jsbindings/manual/jsb_pluginx_manual_protocols.cpp +++ b/jsbindings/manual/jsb_pluginx_manual_protocols.cpp @@ -13,7 +13,7 @@ JSObject *jsb_PluginParam_prototype; bool js_pluginx_protocols_PluginParam_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = NULL; @@ -22,7 +22,7 @@ bool js_pluginx_protocols_PluginParam_constructor(JSContext *cx, uint32_t argc, do { if (argc == 2) { int arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); if (!ok) { ok = true; break; } switch (arg0) @@ -30,14 +30,14 @@ bool js_pluginx_protocols_PluginParam_constructor(JSContext *cx, uint32_t argc, case cocos2d::plugin::PluginParam::kParamTypeInt: { int arg1; - ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1); + ok &= jsval_to_int32(cx, args.get(1), (int32_t *)&arg1); if (ok) { cobj = new cocos2d::plugin::PluginParam(arg1); } } break; case cocos2d::plugin::PluginParam::kParamTypeFloat: { double arg1; - ok &= JS::ToNumber(cx, JS::RootedValue(cx, argv[1]), &arg1); + ok &= JS::ToNumber(cx, args.get(1), &arg1); if (ok) { float tempArg = arg1; cobj = new cocos2d::plugin::PluginParam(tempArg); @@ -46,21 +46,21 @@ bool js_pluginx_protocols_PluginParam_constructor(JSContext *cx, uint32_t argc, break; case cocos2d::plugin::PluginParam::kParamTypeBool: { - bool arg1 = JS::ToBoolean(JS::RootedValue(cx, argv[1])); + bool arg1 = JS::ToBoolean(args.get(1)); cobj = new cocos2d::plugin::PluginParam(arg1); } break; case cocos2d::plugin::PluginParam::kParamTypeString: { const char* arg1; - std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + std::string arg1_tmp; ok &= jsval_to_std_string(cx, args.get(1), &arg1_tmp); arg1 = arg1_tmp.c_str(); if (ok) { cobj = new cocos2d::plugin::PluginParam(arg1); } } break; case cocos2d::plugin::PluginParam::kParamTypeStringMap: { StringMap arg1; - ok &= jsval_to_StringMap(cx, argv[1], &arg1); + ok &= jsval_to_StringMap(cx, args.get(1), &arg1); if (ok) { cobj = new cocos2d::plugin::PluginParam(arg1); } } break; @@ -76,14 +76,14 @@ bool js_pluginx_protocols_PluginParam_constructor(JSContext *cx, uint32_t argc, assert(typeMapIter != _js_global_type_map.end()); typeClass = typeMapIter->second; assert(typeClass); - obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); + obj = JS_NewObject(cx, typeClass->jsclass, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto)); js_proxy_t *proxy; JS_NEW_PROXY(proxy, cobj, obj); } } while (0); if (cobj) { - JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + args.rval().set(OBJECT_TO_JSVAL(obj)); return true; } JS_ReportError(cx, "wrong number of arguments"); @@ -108,15 +108,16 @@ void js_pluginx_protocols_PluginParam_finalize(JSFreeOp *fop, JSObject *obj) { static bool js_pluginx_protocols_PluginParam_ctor(JSContext *cx, uint32_t argc, jsval *vp) { + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); cocos2d::plugin::PluginParam *nobj = new cocos2d::plugin::PluginParam(); js_proxy_t* p; JS_NEW_PROXY(p, nobj, obj); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } -void js_register_pluginx_protocols_PluginParam(JSContext *cx, JSObject *global) { +void js_register_pluginx_protocols_PluginParam(JSContext *cx, JS::HandleObject global) { jsb_PluginParam_class = (JSClass *)calloc(1, sizeof(JSClass)); jsb_PluginParam_class->name = "PluginParam"; jsb_PluginParam_class->addProperty = JS_PropertyStub; @@ -130,7 +131,7 @@ void js_register_pluginx_protocols_PluginParam(JSContext *cx, JSObject *global) jsb_PluginParam_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { - {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + JS_PS_END }; JSFunctionSpec *funcs = NULL; @@ -139,7 +140,7 @@ void js_register_pluginx_protocols_PluginParam(JSContext *cx, JSObject *global) jsb_PluginParam_prototype = JS_InitClass( cx, global, - NULL, // parent proto + JS::NullPtr(), // parent proto jsb_PluginParam_class, js_pluginx_protocols_PluginParam_constructor, 0, // constructor properties, @@ -167,7 +168,7 @@ void js_register_pluginx_protocols_PluginParam(JSContext *cx, JSObject *global) bool js_pluginx_PluginProtocol_callFuncWithParam(JSContext *cx, uint32_t argc, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); @@ -176,11 +177,11 @@ bool js_pluginx_PluginProtocol_callFuncWithParam(JSContext *cx, uint32_t argc, j if (argc > 0) { std::string strName; - ok &= jsval_to_std_string(cx, argv[0], &strName); + ok &= jsval_to_std_string(cx, args.get(0), &strName); std::vector params; uint32_t i = 1; while (i < argc) { - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[i]); + JSObject *tmpObj = args.get(1).toObjectOrNull(); if (tmpObj == NULL) break; @@ -193,7 +194,7 @@ bool js_pluginx_PluginProtocol_callFuncWithParam(JSContext *cx, uint32_t argc, j cobj->callFuncWithParam(strName.c_str(), params); - JS_SET_RVAL(cx, vp, JSVAL_VOID); + args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments"); @@ -203,15 +204,15 @@ bool js_pluginx_PluginProtocol_callFuncWithParam(JSContext *cx, uint32_t argc, j bool js_pluginx_PluginProtocol_callStringFuncWithParam(JSContext *cx, uint32_t argc, jsval *vp) { bool ok = true; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc > 0) { std::string strName; - ok &= jsval_to_std_string(cx, argv[0], &strName); + ok &= jsval_to_std_string(cx, args.get(0), &strName); std::vector params; uint32_t i = 1; while (i < argc) { - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[i]); + JSObject *tmpObj = args.get(i).toObjectOrNull(); if (tmpObj == NULL) break; @@ -228,7 +229,7 @@ bool js_pluginx_PluginProtocol_callStringFuncWithParam(JSContext *cx, uint32_t a std::string ret = cobj->callStringFuncWithParam(strName.c_str(), params); jsval jsret; jsret = std_string_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "wrong number of arguments"); @@ -238,15 +239,15 @@ bool js_pluginx_PluginProtocol_callStringFuncWithParam(JSContext *cx, uint32_t a bool js_pluginx_PluginProtocol_callIntFuncWithParam(JSContext *cx, uint32_t argc, jsval *vp) { bool ok = true; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc > 0) { std::string strName; - ok &= jsval_to_std_string(cx, argv[0], &strName); + ok &= jsval_to_std_string(cx, args.get(0), &strName); std::vector params; uint32_t i = 1; while (i < argc) { - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[i]); + JSObject *tmpObj = args.get(i).toObjectOrNull(); if (tmpObj == NULL) break; @@ -263,7 +264,7 @@ bool js_pluginx_PluginProtocol_callIntFuncWithParam(JSContext *cx, uint32_t argc int ret = cobj->callIntFuncWithParam(strName.c_str(), params); jsval jsret; jsret = int32_to_jsval(cx, ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "wrong number of arguments"); @@ -273,15 +274,15 @@ bool js_pluginx_PluginProtocol_callIntFuncWithParam(JSContext *cx, uint32_t argc bool js_pluginx_PluginProtocol_callFloatFuncWithParam(JSContext *cx, uint32_t argc, jsval *vp) { bool ok = true; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc > 0) { std::string strName; - ok &= jsval_to_std_string(cx, argv[0], &strName); + ok &= jsval_to_std_string(cx, args.get(0), &strName); std::vector params; uint32_t i = 1; while (i < argc) { - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[i]); + JSObject *tmpObj = args.get(i).toObjectOrNull(); if (tmpObj == NULL) break; @@ -298,7 +299,7 @@ bool js_pluginx_PluginProtocol_callFloatFuncWithParam(JSContext *cx, uint32_t ar float ret = cobj->callFloatFuncWithParam(strName.c_str(), params); jsval jsret; jsret = DOUBLE_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "wrong number of arguments"); @@ -308,15 +309,15 @@ bool js_pluginx_PluginProtocol_callFloatFuncWithParam(JSContext *cx, uint32_t ar bool js_pluginx_PluginProtocol_callBoolFuncWithParam(JSContext *cx, uint32_t argc, jsval *vp) { bool ok = true; - jsval *argv = JS_ARGV(cx, vp); + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); if (argc > 0) { std::string strName; - ok &= jsval_to_std_string(cx, argv[0], &strName); + ok &= jsval_to_std_string(cx, args.get(0), &strName); std::vector params; uint32_t i = 1; while (i < argc) { - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[i]); + JSObject *tmpObj = args.get(i).toObjectOrNull(); if (tmpObj == NULL) break; @@ -333,7 +334,7 @@ bool js_pluginx_PluginProtocol_callBoolFuncWithParam(JSContext *cx, uint32_t arg bool ret = cobj->callBoolFuncWithParam(strName.c_str(), params); jsval jsret; jsret = BOOLEAN_TO_JSVAL(ret); - JS_SET_RVAL(cx, vp, jsret); + args.rval().set(jsret); return true; } JS_ReportError(cx, "wrong number of arguments"); diff --git a/jsbindings/manual/jsb_pluginx_manual_protocols.h b/jsbindings/manual/jsb_pluginx_manual_protocols.h index a1ae9b14..ddcbf0aa 100644 --- a/jsbindings/manual/jsb_pluginx_manual_protocols.h +++ b/jsbindings/manual/jsb_pluginx_manual_protocols.h @@ -9,8 +9,8 @@ extern JSObject *jsb_PluginParam_prototype; bool js_pluginx_protocols_PluginParam_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_pluginx_protocols_PluginParam_finalize(JSContext *cx, JSObject *obj); -void js_register_pluginx_protocols_PluginParam(JSContext *cx, JSObject *global); -void register_all_pluginx_protocols(JSContext* cx, JSObject* obj); +void js_register_pluginx_protocols_PluginParam(JSContext *cx, JS::HandleObject global); +void register_all_pluginx_protocols(JSContext* cx, JS::HandleObject obj); bool js_pluginx_protocols_PluginParam_PluginParam(JSContext *cx, uint32_t argc, jsval *vp); bool js_pluginx_PluginProtocol_callFuncWithParam(JSContext *cx, uint32_t argc, jsval *vp); diff --git a/jsbindings/manual/jsb_pluginx_spidermonkey_specifics.h b/jsbindings/manual/jsb_pluginx_spidermonkey_specifics.h index 54ce212f..58633b38 100644 --- a/jsbindings/manual/jsb_pluginx_spidermonkey_specifics.h +++ b/jsbindings/manual/jsb_pluginx_spidermonkey_specifics.h @@ -60,7 +60,7 @@ namespace pluginx { typedef struct js_proxy { void *ptr; - JSObject *obj; + JS::Heap obj; UT_hash_handle hh; } js_proxy_t; @@ -69,8 +69,8 @@ extern js_proxy_t *_js_native_global_ht; typedef struct js_type_class { JSClass *jsclass; - JSObject *proto; - JSObject *parentProto; + JS::Heap proto; + JS::Heap parentProto; } js_type_class_t; extern std::unordered_map _js_global_type_map; @@ -197,12 +197,12 @@ void jsb_remove_proxy(js_proxy_t* nativeProxy, js_proxy_t* jsProxy); //JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - JSObject* js_obj = JS_NewObject(cx, typeProxy->jsclass, typeProxy->proto, typeProxy->parentProto); + JSObject* js_obj = JS_NewObject(cx, typeProxy->jsclass, JS::RootedObject(cx, typeProxy->proto), JS::RootedObject(cx,typeProxy->parentProto)); proxy = jsb_new_proxy(native_obj, js_obj); #ifdef DEBUG - JS_AddNamedObjectRoot(cx, &proxy->obj, typeid(*native_obj).name()); + JS::AddNamedObjectRoot(cx, &proxy->obj, typeid(*native_obj).name()); #else - JS_AddObjectRoot(cx, &proxy->obj); + JS::AddObjectRoot(cx, &proxy->obj); #endif return proxy; } else { diff --git a/plugins/googleplay/Readme.md b/plugins/googleplay/Readme.md index c1295483..7e66bc2b 100644 --- a/plugins/googleplay/Readme.md +++ b/plugins/googleplay/Readme.md @@ -28,27 +28,10 @@ For the to compile correctly you must do the following. ```java // This must be added to the new Cocos2dxActivity.java classes in cocos2d-x 3.0 + recently added - -private static Set onActivityResultListeners = new LinkedHashSet(); - - -public static void addOnActivityResultListener(OnActivityResultListener listener) { - onActivityResultListeners.add(listener); -} - -public static Set getOnActivityResultListeners() { - return onActivityResultListeners; -} - - - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) - { - for (OnActivityResultListener listener : Cocos2dxHelper.getOnActivityResultListeners()) { - listener.onActivityResult(requestCode, resultCode, data); - } - - super.onActivityResult(requestCode, resultCode, data); - } -``` \ No newline at end of file + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) + { + PluginWrapper.onActivityResult(requestCode, resultCode, data); + super.onActivityResult(requestCode, resultCode, data); + } +``` diff --git a/tools/pluginx-bindings-generator/conversions.yaml b/tools/pluginx-bindings-generator/conversions.yaml index fb9b0f63..648ed529 100644 --- a/tools/pluginx-bindings-generator/conversions.yaml +++ b/tools/pluginx-bindings-generator/conversions.yaml @@ -39,7 +39,7 @@ conversions: bool: "${out_value} = JS::ToBoolean(JS::RootedValue(cx, ${in_value}))" float: "ok &= JS::ToNumber( cx, JS::RootedValue(cx, ${in_value}), &${out_value})" double: "ok &= JS::ToNumber( cx, JS::RootedValue(cx, ${in_value}), &${out_value})" - long: "ok &= jsval_to_long(cx, ${in_value}, &${out_value})" + long: "ok &= pluginx::jsval_to_long(cx, ${in_value}, &${out_value})" "unsigned long": "ok &= jsval_to_ulong(cx, ${in_value}, &${out_value})" "ssize_t": "ok &= jsval_to_ssize(cx, ${in_value}, &${out_value})" # jsval has to be a TypedArray, a UInt32Array with 2 elements diff --git a/tools/pluginx-bindings-generator/genbindings.sh b/tools/pluginx-bindings-generator/genbindings.sh index edc2d4f2..64d8911c 100755 --- a/tools/pluginx-bindings-generator/genbindings.sh +++ b/tools/pluginx-bindings-generator/genbindings.sh @@ -38,7 +38,7 @@ fi if [ -z "${CLANG_ROOT+aaa}" ]; then # ... if CLANG_ROOT is not set, use "$NDK_ROOT/toolchains/llvm-3.3/prebuilt/darwin-x86_64" - CLANG_ROOT="$NDK_ROOT/toolchains/llvm-3.3/prebuilt/darwin-x86_64" + CLANG_ROOT="$NDK_ROOT/toolchains/llvm-3.4/prebuilt/darwin-x86_64" fi if [ -z "${PYTHON_BIN+aaa}" ]; then