From 155b9b918c5ff8ef7076842d240f526ab528dd8d Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 3 Jul 2015 11:01:43 +0800 Subject: [PATCH 1/3] Add retain/release for XMLHTTPReqest in JSB --- .../manual/network/XMLHTTPRequest.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp b/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp index 8d215e1f2d..162ec181ef 100644 --- a/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp +++ b/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp @@ -943,6 +943,34 @@ void MinXmlHttpRequest::_notify(JSObject * callback) } } +bool js_MinXmlHttpRequest_retain(JSContext *cx, uint32_t argc, jsval *vp) +{ + JSObject *thisObj = JS_THIS_OBJECT(cx, vp); + if (thisObj) { + js_proxy_t *proxy = jsb_get_js_proxy(thisObj); + if (proxy) { + ((cocos2d::Ref *)proxy->ptr)->retain(); + return true; + } + } + JS_ReportError(cx, "Invalid Native Object."); + return false; +} + +bool js_MinXmlHttpRequest_release(JSContext *cx, uint32_t argc, jsval *vp) +{ + JSObject *thisObj = JS_THIS_OBJECT(cx, vp); + if (thisObj) { + js_proxy_t *proxy = jsb_get_js_proxy(thisObj); + if (proxy) { + ((cocos2d::Ref *)proxy->ptr)->release(); + return true; + } + } + JS_ReportError(cx, "Invalid Native Object."); + return false; +} + /** * @brief Register XMLHttpRequest to be usable in JS and add properties and Mehtods. * @param cx Global Spidermonkey JS Context. @@ -986,6 +1014,8 @@ void MinXmlHttpRequest::_js_register(JSContext *cx, JS::HandleObject global) JS_BINDED_FUNC_FOR_DEF(MinXmlHttpRequest, getAllResponseHeaders), JS_BINDED_FUNC_FOR_DEF(MinXmlHttpRequest, getResponseHeader), JS_BINDED_FUNC_FOR_DEF(MinXmlHttpRequest, overrideMimeType), + JS_FN("retain", js_MinXmlHttpRequest_retain, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("release", js_MinXmlHttpRequest_release, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; From 1f48beee1e4cce2ef60678a62b1126c751f9f086 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 3 Jul 2015 12:55:55 +0800 Subject: [PATCH 2/3] Reorganize code --- .../js-bindings/manual/cocos2d_specifics.hpp | 3 ++ .../jsb_cocos2dx_extension_manual.cpp | 37 ++----------------- .../manual/network/XMLHTTPRequest.cpp | 33 ++--------------- 3 files changed, 10 insertions(+), 63 deletions(-) diff --git a/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp b/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp index 2fc54b6583..fa8c6ff9e9 100644 --- a/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp +++ b/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp @@ -265,6 +265,9 @@ bool js_cocos2dx_Node_onExitTransitionDidStart(JSContext *cx, uint32_t argc, jsv bool js_cocos2dx_Component_onEnter(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Component_onExit(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_retain(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_release(JSContext *cx, uint32_t argc, jsval *vp); + void get_or_create_js_obj(JSContext* cx, JS::HandleObject obj, const std::string &name, JS::MutableHandleObject jsObj); #endif diff --git a/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp b/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp index 597701d0ba..4f72251f72 100644 --- a/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp +++ b/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp @@ -879,35 +879,6 @@ bool js_cocos2dx_ext_AssetsManager_getFailedAssets(JSContext *cx, uint32_t argc, } */ -bool js_cocos2dx_ext_retain(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *thisObj = JS_THIS_OBJECT(cx, vp); - if (thisObj) { - js_proxy_t *proxy = jsb_get_js_proxy(thisObj); - if (proxy) { - ((Ref *)proxy->ptr)->retain(); - return true; - } - } - JS_ReportError(cx, "Invalid Native Object."); - return false; -} - -bool js_cocos2dx_ext_release(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *thisObj = JS_THIS_OBJECT(cx, vp); - if (thisObj) { - js_proxy_t *proxy = jsb_get_js_proxy(thisObj); - if (proxy) { - ((Ref *)proxy->ptr)->release(); - return true; - } - } - JS_ReportError(cx, "Invalid Native Object."); - return false; -} - - __JSDownloaderDelegator::__JSDownloaderDelegator(JSContext *cx, JS::HandleObject obj, const std::string &url, JS::HandleObject callback) : _cx(cx) , _url(url) @@ -1077,11 +1048,11 @@ void register_all_cocos2dx_extension_manual(JSContext* cx, JS::HandleObject glob get_or_create_js_obj(cx, global, "cc", &ccObj); JS::RootedObject am(cx, jsb_cocos2d_extension_AssetsManagerEx_prototype); - JS_DefineFunction(cx, am, "retain", js_cocos2dx_ext_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, am, "release", js_cocos2dx_ext_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, am, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, am, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS::RootedObject manifest(cx, jsb_cocos2d_extension_Manifest_prototype); - JS_DefineFunction(cx, manifest, "retain", js_cocos2dx_ext_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, manifest, "release", js_cocos2dx_ext_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, manifest, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, manifest, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); //JS_DefineFunction(cx, jsb_cocos2d_extension_AssetsManager_prototype, "updateAssets", js_cocos2dx_ext_AssetsManager_updateAssets, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); //JS_DefineFunction(cx, jsb_cocos2d_extension_AssetsManager_prototype, "getFailedAssets", js_cocos2dx_ext_AssetsManager_getFailedAssets, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); diff --git a/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp b/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp index 162ec181ef..402a318874 100644 --- a/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp +++ b/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp @@ -29,6 +29,7 @@ #include "XMLHTTPRequest.h" #include #include +#include "cocos2d_specifics.hpp" using namespace std; @@ -943,34 +944,6 @@ void MinXmlHttpRequest::_notify(JSObject * callback) } } -bool js_MinXmlHttpRequest_retain(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *thisObj = JS_THIS_OBJECT(cx, vp); - if (thisObj) { - js_proxy_t *proxy = jsb_get_js_proxy(thisObj); - if (proxy) { - ((cocos2d::Ref *)proxy->ptr)->retain(); - return true; - } - } - JS_ReportError(cx, "Invalid Native Object."); - return false; -} - -bool js_MinXmlHttpRequest_release(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *thisObj = JS_THIS_OBJECT(cx, vp); - if (thisObj) { - js_proxy_t *proxy = jsb_get_js_proxy(thisObj); - if (proxy) { - ((cocos2d::Ref *)proxy->ptr)->release(); - return true; - } - } - JS_ReportError(cx, "Invalid Native Object."); - return false; -} - /** * @brief Register XMLHttpRequest to be usable in JS and add properties and Mehtods. * @param cx Global Spidermonkey JS Context. @@ -1014,8 +987,8 @@ void MinXmlHttpRequest::_js_register(JSContext *cx, JS::HandleObject global) JS_BINDED_FUNC_FOR_DEF(MinXmlHttpRequest, getAllResponseHeaders), JS_BINDED_FUNC_FOR_DEF(MinXmlHttpRequest, getResponseHeader), JS_BINDED_FUNC_FOR_DEF(MinXmlHttpRequest, overrideMimeType), - JS_FN("retain", js_MinXmlHttpRequest_retain, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("release", js_MinXmlHttpRequest_release, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("retain", js_cocos2dx_retain, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("release", js_cocos2dx_release, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; From 6f3fc302e6c6e7eca8661d1a03973e1d05394319 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Sat, 4 Jul 2015 08:39:49 +0800 Subject: [PATCH 3/3] Fix web view and video player in simulator --- .../frameworks/runtime-src/Classes/js_module_register.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/simulator/frameworks/runtime-src/Classes/js_module_register.h b/tools/simulator/frameworks/runtime-src/Classes/js_module_register.h index 866557a0ed..1eb7d05e35 100644 --- a/tools/simulator/frameworks/runtime-src/Classes/js_module_register.h +++ b/tools/simulator/frameworks/runtime-src/Classes/js_module_register.h @@ -28,7 +28,9 @@ #include "navmesh/jsb_cocos2dx_navmesh_manual.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) +#include "experimental/jsb_cocos2dx_experimental_video_auto.hpp" #include "experimental/jsb_cocos2dx_experimental_video_manual.h" +#include "experimental/jsb_cocos2dx_experimental_webView_auto.hpp" #include "experimental/jsb_cocos2dx_experimental_webView_manual.h" #endif @@ -97,7 +99,9 @@ int js_module_register() #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + sc->addRegisterCallback(register_all_cocos2dx_experimental_video); sc->addRegisterCallback(register_all_cocos2dx_experimental_video_manual); + sc->addRegisterCallback(register_all_cocos2dx_experimental_webView); sc->addRegisterCallback(register_all_cocos2dx_experimental_webView_manual); #endif