Skip to content

Commit

Permalink
Adding GC crash fix. Also moving TypeTest class out of spidermonkey_s…
Browse files Browse the repository at this point in the history
…pecifics
  • Loading branch information
rohankuruvilla committed Aug 28, 2012
1 parent 8f3849f commit 18b3058
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
29 changes: 20 additions & 9 deletions targets/spidermonkey/common/ScriptingCore.cpp
Expand Up @@ -395,6 +395,22 @@ JSBool ScriptingCore::log(JSContext* cx, uint32_t argc, jsval *vp)
return JS_TRUE;
}


void ScriptingCore::removeJSObjectByCCObject(void* cobj) {

js_proxy_t* nproxy;
js_proxy_t* jsproxy;
void *ptr = cobj;
JS_GET_PROXY(nproxy, ptr);
if (nproxy) {
JSContext *cx = ScriptingCore::getInstance()->getGlobalContext();
JS_RemoveObjectRoot(cx, &nproxy->obj);
JS_GET_NATIVE_PROXY(jsproxy, nproxy->obj);
JS_REMOVE_PROXY(nproxy, jsproxy);
}
}


JSBool ScriptingCore::setReservedSpot(uint32_t i, JSObject *obj, jsval value) {
JS_SetReservedSlot(obj, i, value);
return JS_TRUE;
Expand Down Expand Up @@ -521,14 +537,6 @@ int ScriptingCore::executeFunctionWithFloatData(int nHandler, float data, CCNode

executeJSFunctionWithName(this->cx, p->obj, "update", dataVal, retval);

// if(data == kCCNodeOnEnter) {
// executeJSFunctionWithName(this->cx, p, "onEnter", dataVal, retval);
// } else if(data == kCCNodeOnExit) {
// executeJSFunctionWithName(this->cx, p, "onExit", dataVal, retval);
// } else if(data == kCCMenuItemActivated) {
// executeJSFunctionFromReservedSpot(this->cx, p, dataVal, retval);
// }

return 1;
}

Expand Down Expand Up @@ -587,8 +595,11 @@ static void getJSTouchObject(JSContext *cx, CCTouch *x, jsval &jsret) {
HASH_FIND_INT(_js_global_type_ht, &typeId, classType);
assert(classType);
JSObject *_tmp = JS_NewObject(cx, classType->jsclass, classType->proto, classType->parentProto);
js_proxy_t *proxy;
js_proxy_t *proxy, *nproxy;
JS_NEW_PROXY(proxy, x, _tmp);
void *ptr = x;
JS_GET_PROXY(nproxy, ptr);
JS_AddNamedObjectRoot(cx, &nproxy->obj, "CCTouch");
jsret = OBJECT_TO_JSVAL(_tmp);
}

Expand Down
5 changes: 3 additions & 2 deletions targets/spidermonkey/common/ScriptingCore.h
Expand Up @@ -45,8 +45,9 @@ class ScriptingCore : public CCScriptEngineProtocol
@brief Remove CCObject from lua state
@param object to remove
*/
virtual void removeCCObjectByID(int nLuaID) {}

virtual void removeCCObjectByID(int n) {}
virtual void removeJSObjectByCCObject(void * cobj);

/**
@brief Remove Lua function handler
*/
Expand Down
3 changes: 1 addition & 2 deletions targets/spidermonkey/common/cocos2d_specifics.cpp
Expand Up @@ -43,8 +43,7 @@ JSObject* bind_menu_item(JSContext *cx, T* nativeObj, jsval callback, jsval this
// bind nativeObj <-> JSObject
js_proxy_t *proxy;
JS_NEW_PROXY(proxy, nativeObj, tmp);
JS_AddNamedObjectRoot(cx, &p->obj, "MenuItem");

JS_AddNamedObjectRoot(cx, &proxy->obj, "MenuItem");
addCallBackAndThis(tmp, callback, thisObj);

return tmp;
Expand Down
2 changes: 1 addition & 1 deletion targets/spidermonkey/common/cocos2d_specifics.hpp
Expand Up @@ -38,7 +38,7 @@ inline js_proxy_t *js_get_or_create_proxy(JSContext *cx, T *native_obj) {
js_type_class_t *typeProxy = js_get_type_from_native<T>(native_obj);
assert(typeProxy);
JSObject* js_obj = JS_NewObject(cx, typeProxy->jsclass, typeProxy->proto, typeProxy->parentProto);
proxy = js_new_proxy(native_obj, js_obj);
JS_NEW_PROXY(proxy, native_obj, js_obj);
#ifdef DEBUG
JS_AddNamedObjectRoot(cx, &proxy->obj, typeid(*native_obj).name());
#else
Expand Down
6 changes: 0 additions & 6 deletions targets/spidermonkey/common/spidermonkey_specifics.h
@@ -1,7 +1,6 @@
#ifndef __SPIDERMONKEY_SPECIFICS_H__
#define __SPIDERMONKEY_SPECIFICS_H__

#include <typeinfo>
#include "jsapi.h"
#include "uthash.h"

Expand Down Expand Up @@ -45,11 +44,6 @@ class TypeTest
}
};

class TypeInfo
{
public:
virtual long getClassTypeInfo() = 0;
};

#define JS_NEW_PROXY(p, native_obj, js_obj) \
do { \
Expand Down

0 comments on commit 18b3058

Please sign in to comment.