Reorganize code

This commit is contained in:
pandamicro 2015-07-03 12:55:55 +08:00
parent 155b9b918c
commit 1f48beee1e
3 changed files with 10 additions and 63 deletions

View File

@ -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

View File

@ -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);

View File

@ -29,6 +29,7 @@
#include "XMLHTTPRequest.h"
#include <string>
#include <algorithm>
#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
};