mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
Merge pull request #764 from dumganhar/jsb2.0
[JSB 2.0] More fixes and cleanup
This commit is contained in:
@@ -4,12 +4,26 @@
|
||||
using namespace cocos2d;
|
||||
|
||||
namespace creator {
|
||||
|
||||
PhysicsContactListener::PhysicsContactListener()
|
||||
|
||||
std::vector<PhysicsContactListener*> PhysicsContactListener::__allInstances;
|
||||
|
||||
const std::vector<PhysicsContactListener*>& PhysicsContactListener::getAllInstances()
|
||||
{
|
||||
return __allInstances;
|
||||
}
|
||||
|
||||
PhysicsContactListener::~PhysicsContactListener() {
|
||||
PhysicsContactListener::PhysicsContactListener()
|
||||
{
|
||||
__allInstances.push_back(this);
|
||||
}
|
||||
|
||||
PhysicsContactListener::~PhysicsContactListener()
|
||||
{
|
||||
auto iter = std::find(__allInstances.begin(), __allInstances.end(), this);
|
||||
if (iter != __allInstances.end())
|
||||
{
|
||||
__allInstances.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsContactListener::setBeginContact(const std::function<void(b2Contact* contact)>& callback)
|
||||
|
||||
@@ -38,6 +38,9 @@ namespace creator {
|
||||
class CC_DLL PhysicsContactListener : public b2ContactListener
|
||||
{
|
||||
public:
|
||||
|
||||
static const std::vector<PhysicsContactListener*>& getAllInstances();
|
||||
|
||||
PhysicsContactListener();
|
||||
virtual ~PhysicsContactListener();
|
||||
|
||||
@@ -65,6 +68,8 @@ protected:
|
||||
PhysicsContactImpulse _impulse;
|
||||
|
||||
std::unordered_map<b2Contact*, bool> _contactMap;
|
||||
|
||||
static std::vector<PhysicsContactListener*> __allInstances;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -682,7 +682,7 @@ static bool js_box2dclasses_b2CircleShape_constructor(se::State& s)
|
||||
{
|
||||
b2CircleShape* cobj = new (std::nothrow) b2CircleShape();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.emplace(cobj, true);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_box2dclasses_b2CircleShape_constructor, __jsb_b2CircleShape_class, js_b2CircleShape_finalize)
|
||||
@@ -694,10 +694,10 @@ extern se::Object* __jsb_b2Shape_proto;
|
||||
static bool js_b2CircleShape_finalize(se::State& s)
|
||||
{
|
||||
cocos2d::log("jsbindings: finalizing JS object %p (b2CircleShape)", s.nativeThisObject());
|
||||
auto iter = se::__nonRefNativeObjectCreatedByCtorMap.find(s.nativeThisObject());
|
||||
if (iter != se::__nonRefNativeObjectCreatedByCtorMap.end())
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.erase(iter);
|
||||
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
|
||||
b2CircleShape* cobj = (b2CircleShape*)s.nativeThisObject();
|
||||
delete cobj;
|
||||
}
|
||||
@@ -900,7 +900,7 @@ static bool js_box2dclasses_b2EdgeShape_constructor(se::State& s)
|
||||
{
|
||||
b2EdgeShape* cobj = new (std::nothrow) b2EdgeShape();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.emplace(cobj, true);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_box2dclasses_b2EdgeShape_constructor, __jsb_b2EdgeShape_class, js_b2EdgeShape_finalize)
|
||||
@@ -912,10 +912,10 @@ extern se::Object* __jsb_b2Shape_proto;
|
||||
static bool js_b2EdgeShape_finalize(se::State& s)
|
||||
{
|
||||
cocos2d::log("jsbindings: finalizing JS object %p (b2EdgeShape)", s.nativeThisObject());
|
||||
auto iter = se::__nonRefNativeObjectCreatedByCtorMap.find(s.nativeThisObject());
|
||||
if (iter != se::__nonRefNativeObjectCreatedByCtorMap.end())
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.erase(iter);
|
||||
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
|
||||
b2EdgeShape* cobj = (b2EdgeShape*)s.nativeThisObject();
|
||||
delete cobj;
|
||||
}
|
||||
@@ -1168,7 +1168,7 @@ static bool js_box2dclasses_b2ChainShape_constructor(se::State& s)
|
||||
{
|
||||
b2ChainShape* cobj = new (std::nothrow) b2ChainShape();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.emplace(cobj, true);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_box2dclasses_b2ChainShape_constructor, __jsb_b2ChainShape_class, js_b2ChainShape_finalize)
|
||||
@@ -1180,10 +1180,10 @@ extern se::Object* __jsb_b2Shape_proto;
|
||||
static bool js_b2ChainShape_finalize(se::State& s)
|
||||
{
|
||||
cocos2d::log("jsbindings: finalizing JS object %p (b2ChainShape)", s.nativeThisObject());
|
||||
auto iter = se::__nonRefNativeObjectCreatedByCtorMap.find(s.nativeThisObject());
|
||||
if (iter != se::__nonRefNativeObjectCreatedByCtorMap.end())
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.erase(iter);
|
||||
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
|
||||
b2ChainShape* cobj = (b2ChainShape*)s.nativeThisObject();
|
||||
delete cobj;
|
||||
}
|
||||
@@ -1422,7 +1422,7 @@ static bool js_box2dclasses_b2PolygonShape_constructor(se::State& s)
|
||||
{
|
||||
b2PolygonShape* cobj = new (std::nothrow) b2PolygonShape();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.emplace(cobj, true);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_box2dclasses_b2PolygonShape_constructor, __jsb_b2PolygonShape_class, js_b2PolygonShape_finalize)
|
||||
@@ -1434,10 +1434,10 @@ extern se::Object* __jsb_b2Shape_proto;
|
||||
static bool js_b2PolygonShape_finalize(se::State& s)
|
||||
{
|
||||
cocos2d::log("jsbindings: finalizing JS object %p (b2PolygonShape)", s.nativeThisObject());
|
||||
auto iter = se::__nonRefNativeObjectCreatedByCtorMap.find(s.nativeThisObject());
|
||||
if (iter != se::__nonRefNativeObjectCreatedByCtorMap.end())
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.erase(iter);
|
||||
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
|
||||
b2PolygonShape* cobj = (b2PolygonShape*)s.nativeThisObject();
|
||||
delete cobj;
|
||||
}
|
||||
@@ -3907,7 +3907,7 @@ static bool js_box2dclasses_b2World_constructor(se::State& s)
|
||||
SE_PRECONDITION2(ok, false, "js_box2dclasses_b2World_constructor : Error processing arguments");
|
||||
b2World* cobj = new (std::nothrow) b2World(arg0);
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.emplace(cobj, true);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_box2dclasses_b2World_constructor, __jsb_b2World_class, js_b2World_finalize)
|
||||
@@ -3918,10 +3918,10 @@ SE_BIND_CTOR(js_box2dclasses_b2World_constructor, __jsb_b2World_class, js_b2Worl
|
||||
static bool js_b2World_finalize(se::State& s)
|
||||
{
|
||||
cocos2d::log("jsbindings: finalizing JS object %p (b2World)", s.nativeThisObject());
|
||||
auto iter = se::__nonRefNativeObjectCreatedByCtorMap.find(s.nativeThisObject());
|
||||
if (iter != se::__nonRefNativeObjectCreatedByCtorMap.end())
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.erase(iter);
|
||||
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
|
||||
b2World* cobj = (b2World*)s.nativeThisObject();
|
||||
delete cobj;
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ static bool js_cocos2dx_audioengine_AudioProfile_constructor(se::State& s)
|
||||
{
|
||||
cocos2d::experimental::AudioProfile* cobj = new (std::nothrow) cocos2d::experimental::AudioProfile();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.emplace(cobj, true);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_cocos2dx_audioengine_AudioProfile_constructor, __jsb_cocos2d_experimental_AudioProfile_class, js_cocos2d_experimental_AudioProfile_finalize)
|
||||
@@ -107,10 +107,10 @@ SE_BIND_CTOR(js_cocos2dx_audioengine_AudioProfile_constructor, __jsb_cocos2d_exp
|
||||
static bool js_cocos2d_experimental_AudioProfile_finalize(se::State& s)
|
||||
{
|
||||
cocos2d::log("jsbindings: finalizing JS object %p (cocos2d::experimental::AudioProfile)", s.nativeThisObject());
|
||||
auto iter = se::__nonRefNativeObjectCreatedByCtorMap.find(s.nativeThisObject());
|
||||
if (iter != se::__nonRefNativeObjectCreatedByCtorMap.end())
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.erase(iter);
|
||||
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
|
||||
cocos2d::experimental::AudioProfile* cobj = (cocos2d::experimental::AudioProfile*)s.nativeThisObject();
|
||||
delete cobj;
|
||||
}
|
||||
|
||||
@@ -4860,7 +4860,7 @@ static bool js_cocos2dx_dragonbones_CCFactory_constructor(se::State& s)
|
||||
{
|
||||
dragonBones::CCFactory* cobj = new (std::nothrow) dragonBones::CCFactory();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.emplace(cobj, true);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_cocos2dx_dragonbones_CCFactory_constructor, __jsb_dragonBones_CCFactory_class, js_dragonBones_CCFactory_finalize)
|
||||
@@ -4872,10 +4872,10 @@ extern se::Object* __jsb_dragonBones_BaseFactory_proto;
|
||||
static bool js_dragonBones_CCFactory_finalize(se::State& s)
|
||||
{
|
||||
cocos2d::log("jsbindings: finalizing JS object %p (dragonBones::CCFactory)", s.nativeThisObject());
|
||||
auto iter = se::__nonRefNativeObjectCreatedByCtorMap.find(s.nativeThisObject());
|
||||
if (iter != se::__nonRefNativeObjectCreatedByCtorMap.end())
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.erase(iter);
|
||||
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
|
||||
dragonBones::CCFactory* cobj = (dragonBones::CCFactory*)s.nativeThisObject();
|
||||
delete cobj;
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ static bool js_cocos2dx_network_Downloader_constructor(se::State& s)
|
||||
if (!ok) { ok = true; break; }
|
||||
cocos2d::network::Downloader* cobj = new (std::nothrow) cocos2d::network::Downloader(arg0);
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.emplace(cobj, true);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
} while(false);
|
||||
@@ -213,7 +213,7 @@ static bool js_cocos2dx_network_Downloader_constructor(se::State& s)
|
||||
if (argc == 0) {
|
||||
cocos2d::network::Downloader* cobj = new (std::nothrow) cocos2d::network::Downloader();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.emplace(cobj, true);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
} while(false);
|
||||
@@ -228,10 +228,10 @@ SE_BIND_CTOR(js_cocos2dx_network_Downloader_constructor, __jsb_cocos2d_network_D
|
||||
static bool js_cocos2d_network_Downloader_finalize(se::State& s)
|
||||
{
|
||||
cocos2d::log("jsbindings: finalizing JS object %p (cocos2d::network::Downloader)", s.nativeThisObject());
|
||||
auto iter = se::__nonRefNativeObjectCreatedByCtorMap.find(s.nativeThisObject());
|
||||
if (iter != se::__nonRefNativeObjectCreatedByCtorMap.end())
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.erase(iter);
|
||||
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
|
||||
cocos2d::network::Downloader* cobj = (cocos2d::network::Downloader*)s.nativeThisObject();
|
||||
delete cobj;
|
||||
}
|
||||
|
||||
@@ -1584,7 +1584,7 @@ static bool js_creator_PhysicsDebugDraw_constructor(se::State& s)
|
||||
{
|
||||
creator::PhysicsDebugDraw* cobj = new (std::nothrow) creator::PhysicsDebugDraw();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.emplace(cobj, true);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_creator_PhysicsDebugDraw_constructor, __jsb_creator_PhysicsDebugDraw_class, js_creator_PhysicsDebugDraw_finalize)
|
||||
@@ -1596,10 +1596,10 @@ extern se::Object* __jsb_b2Draw_proto;
|
||||
static bool js_creator_PhysicsDebugDraw_finalize(se::State& s)
|
||||
{
|
||||
cocos2d::log("jsbindings: finalizing JS object %p (creator::PhysicsDebugDraw)", s.nativeThisObject());
|
||||
auto iter = se::__nonRefNativeObjectCreatedByCtorMap.find(s.nativeThisObject());
|
||||
if (iter != se::__nonRefNativeObjectCreatedByCtorMap.end())
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.erase(iter);
|
||||
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
|
||||
creator::PhysicsDebugDraw* cobj = (creator::PhysicsDebugDraw*)s.nativeThisObject();
|
||||
delete cobj;
|
||||
}
|
||||
@@ -1751,7 +1751,7 @@ static bool js_creator_PhysicsWorldManifoldWrapper_constructor(se::State& s)
|
||||
{
|
||||
creator::PhysicsWorldManifoldWrapper* cobj = new (std::nothrow) creator::PhysicsWorldManifoldWrapper();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.emplace(cobj, true);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_creator_PhysicsWorldManifoldWrapper_constructor, __jsb_creator_PhysicsWorldManifoldWrapper_class, js_creator_PhysicsWorldManifoldWrapper_finalize)
|
||||
@@ -1988,7 +1988,7 @@ static bool js_creator_PhysicsManifoldWrapper_constructor(se::State& s)
|
||||
{
|
||||
creator::PhysicsManifoldWrapper* cobj = new (std::nothrow) creator::PhysicsManifoldWrapper();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.emplace(cobj, true);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_creator_PhysicsManifoldWrapper_constructor, __jsb_creator_PhysicsManifoldWrapper_class, js_creator_PhysicsManifoldWrapper_finalize)
|
||||
@@ -2128,7 +2128,7 @@ static bool js_creator_PhysicsUtils_constructor(se::State& s)
|
||||
{
|
||||
creator::PhysicsUtils* cobj = new (std::nothrow) creator::PhysicsUtils();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.emplace(cobj, true);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_creator_PhysicsUtils_constructor, __jsb_creator_PhysicsUtils_class, js_creator_PhysicsUtils_finalize)
|
||||
@@ -2139,10 +2139,10 @@ SE_BIND_CTOR(js_creator_PhysicsUtils_constructor, __jsb_creator_PhysicsUtils_cla
|
||||
static bool js_creator_PhysicsUtils_finalize(se::State& s)
|
||||
{
|
||||
cocos2d::log("jsbindings: finalizing JS object %p (creator::PhysicsUtils)", s.nativeThisObject());
|
||||
auto iter = se::__nonRefNativeObjectCreatedByCtorMap.find(s.nativeThisObject());
|
||||
if (iter != se::__nonRefNativeObjectCreatedByCtorMap.end())
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.erase(iter);
|
||||
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
|
||||
creator::PhysicsUtils* cobj = (creator::PhysicsUtils*)s.nativeThisObject();
|
||||
delete cobj;
|
||||
}
|
||||
@@ -2239,7 +2239,7 @@ static bool js_creator_PhysicsContactImpulse_constructor(se::State& s)
|
||||
{
|
||||
creator::PhysicsContactImpulse* cobj = new (std::nothrow) creator::PhysicsContactImpulse();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.emplace(cobj, true);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_creator_PhysicsContactImpulse_constructor, __jsb_creator_PhysicsContactImpulse_class, js_creator_PhysicsContactImpulse_finalize)
|
||||
@@ -2319,7 +2319,7 @@ static bool js_creator_PhysicsContactListener_constructor(se::State& s)
|
||||
{
|
||||
creator::PhysicsContactListener* cobj = new (std::nothrow) creator::PhysicsContactListener();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.emplace(cobj, true);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_creator_PhysicsContactListener_constructor, __jsb_creator_PhysicsContactListener_class, js_creator_PhysicsContactListener_finalize)
|
||||
@@ -2331,10 +2331,10 @@ extern se::Object* __jsb_b2ContactListener_proto;
|
||||
static bool js_creator_PhysicsContactListener_finalize(se::State& s)
|
||||
{
|
||||
cocos2d::log("jsbindings: finalizing JS object %p (creator::PhysicsContactListener)", s.nativeThisObject());
|
||||
auto iter = se::__nonRefNativeObjectCreatedByCtorMap.find(s.nativeThisObject());
|
||||
if (iter != se::__nonRefNativeObjectCreatedByCtorMap.end())
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.erase(iter);
|
||||
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
|
||||
creator::PhysicsContactListener* cobj = (creator::PhysicsContactListener*)s.nativeThisObject();
|
||||
delete cobj;
|
||||
}
|
||||
@@ -2415,7 +2415,7 @@ static bool js_creator_PhysicsAABBQueryCallback_constructor(se::State& s)
|
||||
{
|
||||
creator::PhysicsAABBQueryCallback* cobj = new (std::nothrow) creator::PhysicsAABBQueryCallback();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.emplace(cobj, true);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_creator_PhysicsAABBQueryCallback_constructor, __jsb_creator_PhysicsAABBQueryCallback_class, js_creator_PhysicsAABBQueryCallback_finalize)
|
||||
@@ -2427,10 +2427,10 @@ extern se::Object* __jsb_b2QueryCallback_proto;
|
||||
static bool js_creator_PhysicsAABBQueryCallback_finalize(se::State& s)
|
||||
{
|
||||
cocos2d::log("jsbindings: finalizing JS object %p (creator::PhysicsAABBQueryCallback)", s.nativeThisObject());
|
||||
auto iter = se::__nonRefNativeObjectCreatedByCtorMap.find(s.nativeThisObject());
|
||||
if (iter != se::__nonRefNativeObjectCreatedByCtorMap.end())
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.erase(iter);
|
||||
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
|
||||
creator::PhysicsAABBQueryCallback* cobj = (creator::PhysicsAABBQueryCallback*)s.nativeThisObject();
|
||||
delete cobj;
|
||||
}
|
||||
@@ -2519,7 +2519,7 @@ static bool js_creator_PhysicsRayCastCallback_constructor(se::State& s)
|
||||
{
|
||||
creator::PhysicsRayCastCallback* cobj = new (std::nothrow) creator::PhysicsRayCastCallback();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.emplace(cobj, true);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_creator_PhysicsRayCastCallback_constructor, __jsb_creator_PhysicsRayCastCallback_class, js_creator_PhysicsRayCastCallback_finalize)
|
||||
@@ -2531,10 +2531,10 @@ extern se::Object* __jsb_b2RayCastCallback_proto;
|
||||
static bool js_creator_PhysicsRayCastCallback_finalize(se::State& s)
|
||||
{
|
||||
cocos2d::log("jsbindings: finalizing JS object %p (creator::PhysicsRayCastCallback)", s.nativeThisObject());
|
||||
auto iter = se::__nonRefNativeObjectCreatedByCtorMap.find(s.nativeThisObject());
|
||||
if (iter != se::__nonRefNativeObjectCreatedByCtorMap.end())
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
se::__nonRefNativeObjectCreatedByCtorMap.erase(iter);
|
||||
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
|
||||
creator::PhysicsRayCastCallback* cobj = (creator::PhysicsRayCastCallback*)s.nativeThisObject();
|
||||
delete cobj;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
//
|
||||
// MappingUtils.cpp
|
||||
// cocos2d_js_bindings
|
||||
//
|
||||
// Created by James Chen on 8/17/17.
|
||||
//
|
||||
//
|
||||
|
||||
#include "MappingUtils.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
// NativePtrToObjectMap
|
||||
NativePtrToObjectMap::Map* NativePtrToObjectMap::__nativePtrToObjectMap = nullptr;
|
||||
|
||||
bool NativePtrToObjectMap::init()
|
||||
{
|
||||
if (__nativePtrToObjectMap == nullptr)
|
||||
__nativePtrToObjectMap = new (std::nothrow) NativePtrToObjectMap::Map();
|
||||
|
||||
return __nativePtrToObjectMap != nullptr;
|
||||
}
|
||||
|
||||
void NativePtrToObjectMap::destroy()
|
||||
{
|
||||
if (__nativePtrToObjectMap != nullptr)
|
||||
{
|
||||
delete __nativePtrToObjectMap;
|
||||
__nativePtrToObjectMap = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void NativePtrToObjectMap::emplace(void* nativeObj, Object* seObj)
|
||||
{
|
||||
__nativePtrToObjectMap->emplace(nativeObj, seObj);
|
||||
}
|
||||
|
||||
NativePtrToObjectMap::Map::iterator NativePtrToObjectMap::find(void* nativeObj)
|
||||
{
|
||||
return __nativePtrToObjectMap->find(nativeObj);
|
||||
}
|
||||
|
||||
NativePtrToObjectMap::Map::iterator NativePtrToObjectMap::erase(Map::iterator iter)
|
||||
{
|
||||
return __nativePtrToObjectMap->erase(iter);
|
||||
}
|
||||
|
||||
void NativePtrToObjectMap::erase(void* nativeObj)
|
||||
{
|
||||
__nativePtrToObjectMap->erase(nativeObj);
|
||||
}
|
||||
|
||||
void NativePtrToObjectMap::clear()
|
||||
{
|
||||
__nativePtrToObjectMap->clear();
|
||||
}
|
||||
|
||||
size_t NativePtrToObjectMap::size()
|
||||
{
|
||||
return __nativePtrToObjectMap->size();
|
||||
}
|
||||
|
||||
const NativePtrToObjectMap::Map& NativePtrToObjectMap::instance()
|
||||
{
|
||||
return *__nativePtrToObjectMap;
|
||||
}
|
||||
|
||||
NativePtrToObjectMap::Map::iterator NativePtrToObjectMap::begin()
|
||||
{
|
||||
return __nativePtrToObjectMap->begin();
|
||||
}
|
||||
|
||||
NativePtrToObjectMap::Map::iterator NativePtrToObjectMap::end()
|
||||
{
|
||||
return __nativePtrToObjectMap->end();
|
||||
}
|
||||
|
||||
// NonRefNativePtrCreatedByCtorMap
|
||||
|
||||
NonRefNativePtrCreatedByCtorMap::Map* NonRefNativePtrCreatedByCtorMap::__nonRefNativeObjectCreatedByCtorMap = nullptr;
|
||||
|
||||
bool NonRefNativePtrCreatedByCtorMap::init()
|
||||
{
|
||||
if (__nonRefNativeObjectCreatedByCtorMap == nullptr)
|
||||
__nonRefNativeObjectCreatedByCtorMap = new (std::nothrow) NonRefNativePtrCreatedByCtorMap::Map();
|
||||
|
||||
return __nonRefNativeObjectCreatedByCtorMap != nullptr;
|
||||
}
|
||||
|
||||
void NonRefNativePtrCreatedByCtorMap::destroy()
|
||||
{
|
||||
if (__nonRefNativeObjectCreatedByCtorMap != nullptr)
|
||||
{
|
||||
delete __nonRefNativeObjectCreatedByCtorMap;
|
||||
__nonRefNativeObjectCreatedByCtorMap = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void NonRefNativePtrCreatedByCtorMap::emplace(void* nativeObj)
|
||||
{
|
||||
__nonRefNativeObjectCreatedByCtorMap->emplace(nativeObj, true);
|
||||
}
|
||||
|
||||
NonRefNativePtrCreatedByCtorMap::Map::iterator NonRefNativePtrCreatedByCtorMap::find(void* nativeObj)
|
||||
{
|
||||
return __nonRefNativeObjectCreatedByCtorMap->find(nativeObj);
|
||||
}
|
||||
|
||||
NonRefNativePtrCreatedByCtorMap::Map::iterator NonRefNativePtrCreatedByCtorMap::erase(Map::iterator iter)
|
||||
{
|
||||
return __nonRefNativeObjectCreatedByCtorMap->erase(iter);
|
||||
}
|
||||
|
||||
void NonRefNativePtrCreatedByCtorMap::erase(void* nativeObj)
|
||||
{
|
||||
__nonRefNativeObjectCreatedByCtorMap->erase(nativeObj);
|
||||
}
|
||||
|
||||
void NonRefNativePtrCreatedByCtorMap::clear()
|
||||
{
|
||||
__nonRefNativeObjectCreatedByCtorMap->clear();
|
||||
}
|
||||
|
||||
size_t NonRefNativePtrCreatedByCtorMap::size()
|
||||
{
|
||||
return __nonRefNativeObjectCreatedByCtorMap->size();
|
||||
}
|
||||
|
||||
const NonRefNativePtrCreatedByCtorMap::Map& NonRefNativePtrCreatedByCtorMap::instance()
|
||||
{
|
||||
return *__nonRefNativeObjectCreatedByCtorMap;
|
||||
}
|
||||
|
||||
NonRefNativePtrCreatedByCtorMap::Map::iterator NonRefNativePtrCreatedByCtorMap::begin()
|
||||
{
|
||||
return __nonRefNativeObjectCreatedByCtorMap->begin();
|
||||
}
|
||||
|
||||
NonRefNativePtrCreatedByCtorMap::Map::iterator NonRefNativePtrCreatedByCtorMap::end()
|
||||
{
|
||||
return __nonRefNativeObjectCreatedByCtorMap->end();
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace se {
|
||||
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace se {
|
||||
|
||||
class Object;
|
||||
|
||||
class NativePtrToObjectMap
|
||||
{
|
||||
public:
|
||||
// key: native ptr, value: se::Object
|
||||
using Map = std::unordered_map<void*, Object*>;
|
||||
|
||||
static bool init();
|
||||
static void destroy();
|
||||
|
||||
static Map::iterator find(void* nativeObj);
|
||||
static Map::iterator erase(Map::iterator iter);
|
||||
static void erase(void* nativeObj);
|
||||
static void clear();
|
||||
static size_t size();
|
||||
|
||||
static const Map& instance();
|
||||
|
||||
static Map::iterator begin();
|
||||
static Map::iterator end();
|
||||
|
||||
private:
|
||||
static void emplace(void* nativeObj, Object* seObj);
|
||||
static Map* __nativePtrToObjectMap;
|
||||
|
||||
friend class Object;
|
||||
};
|
||||
|
||||
class NonRefNativePtrCreatedByCtorMap
|
||||
{
|
||||
public:
|
||||
// key: native ptr, value: non-ref object created by ctor
|
||||
using Map = std::unordered_map<void*, bool>;
|
||||
|
||||
static bool init();
|
||||
static void destroy();
|
||||
|
||||
static void emplace(void* nativeObj);
|
||||
static Map::iterator find(void* nativeObj);
|
||||
static Map::iterator erase(Map::iterator iter);
|
||||
static void erase(void* nativeObj);
|
||||
static void clear();
|
||||
static size_t size();
|
||||
|
||||
static const Map& instance();
|
||||
|
||||
static Map::iterator begin();
|
||||
static Map::iterator end();
|
||||
|
||||
private:
|
||||
static Map* __nonRefNativeObjectCreatedByCtorMap;
|
||||
};
|
||||
|
||||
} // namespace se {
|
||||
@@ -22,3 +22,4 @@
|
||||
#include "Object.hpp"
|
||||
#include "State.hpp"
|
||||
#include "HandleObject.hpp"
|
||||
#include "MappingUtils.hpp"
|
||||
|
||||
@@ -32,13 +32,6 @@
|
||||
se::State state(nativeThisObject, args); \
|
||||
ret = funcName(state); \
|
||||
se::internal::seToJsValue(state.rval(), &_jsRet); \
|
||||
for (auto& v : args) \
|
||||
{ \
|
||||
if (v.isObject()) \
|
||||
{ \
|
||||
v.toObject()->unroot(); \
|
||||
} \
|
||||
} \
|
||||
return _jsRet; \
|
||||
}
|
||||
|
||||
@@ -82,13 +75,6 @@
|
||||
_found = thisObject->getProperty("_ctor", &_property); \
|
||||
if (_found) _property.toObject()->call(args, thisObject); \
|
||||
} \
|
||||
for (auto& v : args) \
|
||||
{ \
|
||||
if (v.isObject()) \
|
||||
{ \
|
||||
v.toObject()->unroot(); \
|
||||
} \
|
||||
} \
|
||||
return _jsRet; \
|
||||
}
|
||||
|
||||
@@ -112,13 +98,6 @@
|
||||
_found = thisObject->getProperty("_ctor", &_property); \
|
||||
if (_found) _property.toObject()->call(args, thisObject); \
|
||||
} \
|
||||
for (auto& v : args) \
|
||||
{ \
|
||||
if (v.isObject()) \
|
||||
{ \
|
||||
v.toObject()->unroot(); \
|
||||
} \
|
||||
} \
|
||||
return _jsRet; \
|
||||
}
|
||||
|
||||
@@ -149,10 +128,6 @@
|
||||
args.push_back(std::move(data)); \
|
||||
se::State state(nativeThisObject, args); \
|
||||
ret = funcName(state); \
|
||||
if (args[0].isObject() && args[0].toObject()->isRooted()) \
|
||||
{ \
|
||||
args[0].toObject()->unroot(); \
|
||||
} \
|
||||
return JS_INVALID_REFERENCE; \
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
#include "Object.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "Class.hpp"
|
||||
#include "ScriptEngine.hpp"
|
||||
|
||||
#ifdef SCRIPT_ENGINE_CHAKRACORE
|
||||
|
||||
#include "Utils.hpp"
|
||||
#include "Class.hpp"
|
||||
#include "ScriptEngine.hpp"
|
||||
#include "../MappingUtils.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
// key: native ptr, value: se::Object
|
||||
std::unordered_map<void*, Object*> __nativePtrToObjectMap;
|
||||
// key: native ptr, value: non-ref object created by ctor
|
||||
std::unordered_map<void*, bool> __nonRefNativeObjectCreatedByCtorMap;
|
||||
|
||||
Object::Object()
|
||||
: _cls(nullptr)
|
||||
, _obj(JS_INVALID_REFERENCE)
|
||||
@@ -105,8 +102,8 @@ namespace se {
|
||||
Object* Object::getObjectWithPtr(void* ptr)
|
||||
{
|
||||
Object* obj = nullptr;
|
||||
auto iter = __nativePtrToObjectMap.find(ptr);
|
||||
if (iter != __nativePtrToObjectMap.end())
|
||||
auto iter = NativePtrToObjectMap::find(ptr);
|
||||
if (iter != NativePtrToObjectMap::end())
|
||||
{
|
||||
obj = iter->second;
|
||||
obj->addRef();
|
||||
@@ -156,10 +153,10 @@ namespace se {
|
||||
|
||||
if (nativeObject != nullptr)
|
||||
{
|
||||
auto iter = __nativePtrToObjectMap.find(nativeObject);
|
||||
if (iter != __nativePtrToObjectMap.end())
|
||||
auto iter = NativePtrToObjectMap::find(nativeObject);
|
||||
if (iter != NativePtrToObjectMap::end())
|
||||
{
|
||||
__nativePtrToObjectMap.erase(iter);
|
||||
NativePtrToObjectMap::erase(iter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,8 +179,13 @@ namespace se {
|
||||
void Object::cleanup()
|
||||
{
|
||||
ScriptEngine::getInstance()->addAfterCleanupHook([](){
|
||||
__nativePtrToObjectMap.clear();
|
||||
__nonRefNativeObjectCreatedByCtorMap.clear();
|
||||
const auto& instance = NativePtrToObjectMap::instance();
|
||||
for (const auto& e : instance)
|
||||
{
|
||||
e.second->release();
|
||||
}
|
||||
NativePtrToObjectMap::clear();
|
||||
NonRefNativePtrCreatedByCtorMap::clear();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -524,9 +526,9 @@ namespace se {
|
||||
void Object::setPrivateData(void* data)
|
||||
{
|
||||
assert(_privateData == nullptr);
|
||||
assert(__nativePtrToObjectMap.find(data) == __nativePtrToObjectMap.end());
|
||||
assert(NativePtrToObjectMap::find(data) == NativePtrToObjectMap::end());
|
||||
internal::setPrivate(_obj, data, _finalizeCb);
|
||||
__nativePtrToObjectMap.emplace(data, this);
|
||||
NativePtrToObjectMap::emplace(data, this);
|
||||
_privateData = data;
|
||||
}
|
||||
|
||||
@@ -535,7 +537,7 @@ namespace se {
|
||||
if (_privateData != nullptr)
|
||||
{
|
||||
void* data = getPrivateData();
|
||||
__nativePtrToObjectMap.erase(data);
|
||||
NativePtrToObjectMap::erase(data);
|
||||
internal::clearPrivate(_obj);
|
||||
_privateData = nullptr;
|
||||
}
|
||||
@@ -568,8 +570,12 @@ namespace se {
|
||||
--_rootCount;
|
||||
if (_rootCount == 0)
|
||||
{
|
||||
unsigned int count = 0;
|
||||
_CHECK(JsRelease(_obj, &count));
|
||||
// Don't unprotect if it's in cleanup, otherwise, it will trigger crash.
|
||||
if (!ScriptEngine::getInstance()->_isInCleanup)
|
||||
{
|
||||
unsigned int count = 0;
|
||||
_CHECK(JsRelease(_obj, &count));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,12 +83,6 @@ namespace se {
|
||||
friend class ScriptEngine;
|
||||
};
|
||||
|
||||
|
||||
// key: native ptr, value: se::Object
|
||||
extern std::unordered_map<void*, Object*> __nativePtrToObjectMap;
|
||||
// key: native ptr, value: non-ref object created by ctor
|
||||
extern std::unordered_map<void*, bool> __nonRefNativeObjectCreatedByCtorMap;
|
||||
|
||||
} // namespace se {
|
||||
|
||||
#endif // SCRIPT_ENGINE_CHAKRACORE
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#include "ScriptEngine.hpp"
|
||||
|
||||
#ifdef SCRIPT_ENGINE_CHAKRACORE
|
||||
|
||||
#include "Object.hpp"
|
||||
#include "Class.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
#ifdef SCRIPT_ENGINE_CHAKRACORE
|
||||
#include "../MappingUtils.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
@@ -54,11 +55,6 @@ namespace se {
|
||||
if (__instance == nullptr)
|
||||
{
|
||||
__instance = new ScriptEngine();
|
||||
if (!__instance->init())
|
||||
{
|
||||
delete __instance;
|
||||
__instance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return __instance;
|
||||
@@ -83,12 +79,22 @@ namespace se {
|
||||
|
||||
bool ScriptEngine::init()
|
||||
{
|
||||
cleanup();
|
||||
LOGD("Initializing ChakraCore ... \n");
|
||||
|
||||
for (const auto& hook : _beforeInitHookArray)
|
||||
{
|
||||
hook();
|
||||
}
|
||||
_beforeInitHookArray.clear();
|
||||
|
||||
_CHECK(JsCreateRuntime(JsRuntimeAttributeNone, nullptr, &_rt));
|
||||
_CHECK(JsCreateContext(_rt, &_cx));
|
||||
_CHECK(JsSetCurrentContext(_cx));
|
||||
|
||||
NativePtrToObjectMap::init();
|
||||
NonRefNativePtrCreatedByCtorMap::init();
|
||||
|
||||
// Set up ES6 Promise
|
||||
// if (JsSetPromiseContinuationCallback(PromiseContinuationCallback, &taskQueue) != JsNoError)
|
||||
|
||||
@@ -109,6 +115,12 @@ namespace se {
|
||||
|
||||
_isValid = true;
|
||||
|
||||
for (const auto& hook : _afterInitHookArray)
|
||||
{
|
||||
hook();
|
||||
}
|
||||
_afterInitHookArray.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -150,6 +162,9 @@ namespace se {
|
||||
}
|
||||
_afterCleanupHookArray.clear();
|
||||
_isInCleanup = false;
|
||||
|
||||
NativePtrToObjectMap::destroy();
|
||||
NonRefNativePtrCreatedByCtorMap::destroy();
|
||||
}
|
||||
|
||||
std::string ScriptEngine::formatException(JsValueRef exception)
|
||||
@@ -210,6 +225,16 @@ namespace se {
|
||||
return _globalObj;
|
||||
}
|
||||
|
||||
void ScriptEngine::addBeforeInitHook(const std::function<void()>& hook)
|
||||
{
|
||||
_beforeInitHookArray.push_back(hook);
|
||||
}
|
||||
|
||||
void ScriptEngine::addAfterInitHook(const std::function<void()>& hook)
|
||||
{
|
||||
_afterInitHookArray.push_back(hook);
|
||||
}
|
||||
|
||||
void ScriptEngine::addBeforeCleanupHook(const std::function<void()>& hook)
|
||||
{
|
||||
_beforeCleanupHookArray.push_back(hook);
|
||||
@@ -228,6 +253,9 @@ namespace se {
|
||||
|
||||
bool ScriptEngine::start()
|
||||
{
|
||||
if (!init())
|
||||
return false;
|
||||
|
||||
bool ok = false;
|
||||
_startTime = std::chrono::steady_clock::now();
|
||||
|
||||
@@ -256,9 +284,9 @@ namespace se {
|
||||
|
||||
void ScriptEngine::gc()
|
||||
{
|
||||
LOGD("GC begin ..., (Native -> JS map) count: %d\n", (int)__nativePtrToObjectMap.size());
|
||||
LOGD("GC begin ..., (Native -> JS map) count: %d\n", (int)NativePtrToObjectMap::size());
|
||||
_CHECK(JsCollectGarbage(_rt));
|
||||
LOGD("GC end ..., (Native -> JS map) count: %d\n", (int)__nativePtrToObjectMap.size());
|
||||
LOGD("GC end ..., (Native -> JS map) count: %d\n", (int)NativePtrToObjectMap::size());
|
||||
}
|
||||
|
||||
void ScriptEngine::clearException()
|
||||
@@ -324,14 +352,14 @@ namespace se {
|
||||
|
||||
void ScriptEngine::_retainScriptObject(void* owner, void* target)
|
||||
{
|
||||
auto iterOwner = __nativePtrToObjectMap.find(owner);
|
||||
if (iterOwner == __nativePtrToObjectMap.end())
|
||||
auto iterOwner = NativePtrToObjectMap::find(owner);
|
||||
if (iterOwner == NativePtrToObjectMap::end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto iterTarget = __nativePtrToObjectMap.find(target);
|
||||
if (iterTarget == __nativePtrToObjectMap.end())
|
||||
auto iterTarget = NativePtrToObjectMap::find(target);
|
||||
if (iterTarget == NativePtrToObjectMap::end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -342,14 +370,14 @@ namespace se {
|
||||
|
||||
void ScriptEngine::_releaseScriptObject(void* owner, void* target)
|
||||
{
|
||||
auto iterOwner = __nativePtrToObjectMap.find(owner);
|
||||
if (iterOwner == __nativePtrToObjectMap.end())
|
||||
auto iterOwner = NativePtrToObjectMap::find(owner);
|
||||
if (iterOwner == NativePtrToObjectMap::end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto iterTarget = __nativePtrToObjectMap.find(target);
|
||||
if (iterTarget == __nativePtrToObjectMap.end())
|
||||
auto iterTarget = NativePtrToObjectMap::find(target);
|
||||
if (iterTarget == NativePtrToObjectMap::end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,21 @@ namespace se {
|
||||
|
||||
bool init();
|
||||
void cleanup();
|
||||
|
||||
/**
|
||||
* @brief Adds a hook function before initializing script engine.
|
||||
* @param[in] hook A hook function to be invoked before initializing script engine.
|
||||
* @note Multiple hook functions could be added, they will be invoked by the order of adding.
|
||||
*/
|
||||
void addBeforeInitHook(const std::function<void()>& hook);
|
||||
|
||||
/**
|
||||
* @brief Adds a hook function after initializing script engine.
|
||||
* @param[in] hook A hook function to be invoked before initializing script engine.
|
||||
* @note Multiple hook functions could be added, they will be invoked by the order of adding.
|
||||
*/
|
||||
void addAfterInitHook(const std::function<void()>& hook);
|
||||
|
||||
void addBeforeCleanupHook(const std::function<void()>& hook);
|
||||
void addAfterCleanupHook(const std::function<void()>& hook);
|
||||
|
||||
@@ -53,6 +68,7 @@ namespace se {
|
||||
bool isValid() { return _isValid; }
|
||||
|
||||
void clearException();
|
||||
const std::chrono::steady_clock::time_point& getStartTime() const { return _startTime; }
|
||||
|
||||
void _retainScriptObject(void* owner, void* target);
|
||||
void _releaseScriptObject(void* owner, void* target);
|
||||
@@ -86,6 +102,10 @@ namespace se {
|
||||
|
||||
std::vector<RegisterCallback> _registerCallbackArray;
|
||||
std::chrono::steady_clock::time_point _startTime;
|
||||
|
||||
std::vector<std::function<void()>> _beforeInitHookArray;
|
||||
std::vector<std::function<void()>> _afterInitHookArray;
|
||||
|
||||
std::vector<std::function<void()>> _beforeCleanupHookArray;
|
||||
std::vector<std::function<void()>> _afterCleanupHookArray;
|
||||
|
||||
|
||||
@@ -126,8 +126,7 @@ namespace se {
|
||||
{
|
||||
obj = Object::_createJSObject(nullptr, jsValue);
|
||||
}
|
||||
obj->root(); // Root it here since it will be unrooted in at the end of SE_BIND_FUNC
|
||||
data->setObject(obj);
|
||||
data->setObject(obj, true);
|
||||
obj->release();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
//#define SCRIPT_ENGINE_SM
|
||||
//#define SCRIPT_ENGINE_V8
|
||||
#define SCRIPT_ENGINE_JSC
|
||||
#define SCRIPT_ENGINE_V8
|
||||
//#define SCRIPT_ENGINE_JSC
|
||||
//#define SCRIPT_ENGINE_CHAKRACORE
|
||||
|
||||
#define SE_ENABLE_INSPECTOR 0
|
||||
|
||||
@@ -33,13 +33,6 @@
|
||||
se::State state(nativeThisObject, args); \
|
||||
ret = funcName(state); \
|
||||
se::internal::seToJsValue(_cx, state.rval(), &_jsRet); \
|
||||
for (auto& v : args) \
|
||||
{ \
|
||||
if (v.isObject()) \
|
||||
{ \
|
||||
v.toObject()->unroot(); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
return _jsRet; \
|
||||
}
|
||||
@@ -85,13 +78,6 @@
|
||||
_found = thisObject->getProperty("_ctor", &_property); \
|
||||
if (_found) _property.toObject()->call(args, thisObject); \
|
||||
} \
|
||||
for (auto& v : args) \
|
||||
{ \
|
||||
if (v.isObject()) \
|
||||
{ \
|
||||
v.toObject()->unroot(); \
|
||||
} \
|
||||
} \
|
||||
return JSValueToObject(_cx, _jsRet, nullptr); \
|
||||
}
|
||||
|
||||
@@ -114,13 +100,6 @@
|
||||
_found = thisObject->getProperty("_ctor", &_property); \
|
||||
if (_found) _property.toObject()->call(args, thisObject); \
|
||||
} \
|
||||
for (auto& v : args) \
|
||||
{ \
|
||||
if (v.isObject()) \
|
||||
{ \
|
||||
v.toObject()->unroot(); \
|
||||
} \
|
||||
} \
|
||||
return _jsRet; \
|
||||
}
|
||||
|
||||
@@ -158,10 +137,6 @@
|
||||
args.push_back(std::move(data)); \
|
||||
se::State state(nativeThisObject, args); \
|
||||
ret = funcName(state); \
|
||||
if (args[0].isObject() && args[0].toObject()->isRooted()) \
|
||||
{ \
|
||||
args[0].toObject()->unroot(); \
|
||||
} \
|
||||
} \
|
||||
return _jsRet; \
|
||||
}
|
||||
|
||||
@@ -5,14 +5,10 @@
|
||||
#include "Utils.hpp"
|
||||
#include "Class.hpp"
|
||||
#include "ScriptEngine.hpp"
|
||||
#include "../MappingUtils.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
// key: native ptr, value: se::Object
|
||||
std::unordered_map<void*, Object*> __nativePtrToObjectMap;
|
||||
// key: native ptr, value: non-ref object created by ctor
|
||||
std::unordered_map<void*, bool> __nonRefNativeObjectCreatedByCtorMap;
|
||||
|
||||
namespace {
|
||||
JSContextRef __cx = nullptr;
|
||||
}
|
||||
@@ -109,8 +105,8 @@ namespace se {
|
||||
Object* Object::getObjectWithPtr(void* ptr)
|
||||
{
|
||||
Object* obj = nullptr;
|
||||
auto iter = __nativePtrToObjectMap.find(ptr);
|
||||
if (iter != __nativePtrToObjectMap.end())
|
||||
auto iter = NativePtrToObjectMap::find(ptr);
|
||||
if (iter != NativePtrToObjectMap::end())
|
||||
{
|
||||
obj = iter->second;
|
||||
obj->addRef();
|
||||
@@ -158,10 +154,10 @@ namespace se {
|
||||
|
||||
if (nativeObj != nullptr)
|
||||
{
|
||||
auto iter = __nativePtrToObjectMap.find(nativeObj);
|
||||
if (iter != __nativePtrToObjectMap.end())
|
||||
auto iter = NativePtrToObjectMap::find(nativeObj);
|
||||
if (iter != NativePtrToObjectMap::end())
|
||||
{
|
||||
__nativePtrToObjectMap.erase(iter);
|
||||
NativePtrToObjectMap::erase(iter);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -489,9 +485,9 @@ namespace se {
|
||||
void Object::setPrivateData(void* data)
|
||||
{
|
||||
assert(_privateData == nullptr);
|
||||
assert(__nativePtrToObjectMap.find(data) == __nativePtrToObjectMap.end());
|
||||
assert(NativePtrToObjectMap::find(data) == NativePtrToObjectMap::end());
|
||||
internal::setPrivate(_obj, data, _finalizeCb);
|
||||
__nativePtrToObjectMap.emplace(data, this);
|
||||
NativePtrToObjectMap::emplace(data, this);
|
||||
_privateData = data;
|
||||
}
|
||||
|
||||
@@ -500,7 +496,7 @@ namespace se {
|
||||
if (_privateData != nullptr)
|
||||
{
|
||||
void* data = getPrivateData();
|
||||
__nativePtrToObjectMap.erase(data);
|
||||
NativePtrToObjectMap::erase(data);
|
||||
internal::clearPrivate(_obj);
|
||||
_privateData = nullptr;
|
||||
}
|
||||
@@ -514,8 +510,13 @@ namespace se {
|
||||
void Object::cleanup()
|
||||
{
|
||||
ScriptEngine::getInstance()->addAfterCleanupHook([](){
|
||||
__nativePtrToObjectMap.clear();
|
||||
__nonRefNativeObjectCreatedByCtorMap.clear();
|
||||
const auto& instance = NativePtrToObjectMap::instance();
|
||||
for (const auto& e : instance)
|
||||
{
|
||||
e.second->release();
|
||||
}
|
||||
NativePtrToObjectMap::clear();
|
||||
NonRefNativePtrCreatedByCtorMap::clear();
|
||||
__cx = nullptr;
|
||||
});
|
||||
}
|
||||
@@ -546,7 +547,9 @@ namespace se {
|
||||
--_rootCount;
|
||||
if (_rootCount == 0)
|
||||
{
|
||||
JSValueUnprotect(__cx, _obj);
|
||||
// Don't unprotect if it's in cleanup, otherwise, it will trigger crash.
|
||||
if (!ScriptEngine::getInstance()->_isInCleanup)
|
||||
JSValueUnprotect(__cx, _obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,11 +318,6 @@ namespace se {
|
||||
friend class AutoHandleScope;
|
||||
};
|
||||
|
||||
// key: native ptr, value: se::Object
|
||||
extern std::unordered_map<void*, Object*> __nativePtrToObjectMap;
|
||||
// key: native ptr, value: non-ref object created by ctor
|
||||
extern std::unordered_map<void*, bool> __nonRefNativeObjectCreatedByCtorMap;
|
||||
|
||||
} // namespace se {
|
||||
|
||||
#endif // SCRIPT_ENGINE_JSC
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "Object.hpp"
|
||||
#include "Class.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "../MappingUtils.hpp"
|
||||
|
||||
extern "C" JS_EXPORT void JSSynchronousGarbageCollectForDebugging(JSContextRef);
|
||||
|
||||
@@ -29,10 +30,10 @@ namespace se {
|
||||
JSValueRef __forceGC(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
|
||||
size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
|
||||
{
|
||||
LOGD("GC begin ..., (Native -> JS map) count: %d\n", (int)__nativePtrToObjectMap.size());
|
||||
LOGD("GC begin ..., (Native -> JS map) count: %d\n", (int)NativePtrToObjectMap::size());
|
||||
// JSGarbageCollect(ctx);
|
||||
JSSynchronousGarbageCollectForDebugging(ctx);
|
||||
LOGD("GC end ..., (Native -> JS map) count: %d\n", (int)__nativePtrToObjectMap.size());
|
||||
LOGD("GC end ..., (Native -> JS map) count: %d\n", (int)NativePtrToObjectMap::size());
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
@@ -68,11 +69,6 @@ namespace se {
|
||||
if (__instance == nullptr)
|
||||
{
|
||||
__instance = new ScriptEngine();
|
||||
if (!__instance->init())
|
||||
{
|
||||
delete __instance;
|
||||
__instance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return __instance;
|
||||
@@ -98,6 +94,12 @@ namespace se {
|
||||
cleanup();
|
||||
LOGD("Initializing JavaScriptCore \n");
|
||||
|
||||
for (const auto& hook : _beforeInitHookArray)
|
||||
{
|
||||
hook();
|
||||
}
|
||||
_beforeInitHookArray.clear();
|
||||
|
||||
_cx = JSGlobalContextCreate(nullptr);
|
||||
|
||||
if (nullptr == _cx)
|
||||
@@ -107,6 +109,9 @@ namespace se {
|
||||
JSGlobalContextSetName(_cx, ctxName);
|
||||
JSStringRelease(ctxName);
|
||||
|
||||
NativePtrToObjectMap::init();
|
||||
NonRefNativePtrCreatedByCtorMap::init();
|
||||
|
||||
internal::setContext(_cx);
|
||||
Class::setContext(_cx);
|
||||
Object::setContext(_cx);
|
||||
@@ -118,6 +123,7 @@ namespace se {
|
||||
|
||||
_globalObj = Object::_createJSObject(nullptr, globalObj);
|
||||
_globalObj->root();
|
||||
_globalObj->setProperty("window", se::Value(_globalObj));
|
||||
|
||||
JSStringRef propertyName = JSStringCreateWithUTF8CString("log");
|
||||
JSObjectSetProperty(_cx, globalObj, propertyName, JSObjectMakeFunctionWithCallback(_cx, propertyName, __log), kJSPropertyAttributeReadOnly, nullptr);
|
||||
@@ -133,6 +139,12 @@ namespace se {
|
||||
|
||||
_isValid = true;
|
||||
|
||||
for (const auto& hook : _afterInitHookArray)
|
||||
{
|
||||
hook();
|
||||
}
|
||||
_afterInitHookArray.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -174,7 +186,10 @@ namespace se {
|
||||
}
|
||||
_afterCleanupHookArray.clear();
|
||||
_isInCleanup = false;
|
||||
LOGD("ScriptEngine::cleanup end ...");
|
||||
|
||||
NativePtrToObjectMap::destroy();
|
||||
NonRefNativePtrCreatedByCtorMap::destroy();
|
||||
LOGD("ScriptEngine::cleanup end ...\n");
|
||||
}
|
||||
|
||||
std::string ScriptEngine::_formatException(JSValueRef exception)
|
||||
@@ -243,6 +258,16 @@ namespace se {
|
||||
return _globalObj;
|
||||
}
|
||||
|
||||
void ScriptEngine::addBeforeInitHook(const std::function<void()>& hook)
|
||||
{
|
||||
_beforeInitHookArray.push_back(hook);
|
||||
}
|
||||
|
||||
void ScriptEngine::addAfterInitHook(const std::function<void()>& hook)
|
||||
{
|
||||
_afterInitHookArray.push_back(hook);
|
||||
}
|
||||
|
||||
void ScriptEngine::addBeforeCleanupHook(const std::function<void()>& hook)
|
||||
{
|
||||
_beforeCleanupHookArray.push_back(hook);
|
||||
@@ -261,6 +286,9 @@ namespace se {
|
||||
|
||||
bool ScriptEngine::start()
|
||||
{
|
||||
if (!init())
|
||||
return false;
|
||||
|
||||
bool ok = false;
|
||||
_startTime = std::chrono::steady_clock::now();
|
||||
|
||||
@@ -279,10 +307,10 @@ namespace se {
|
||||
|
||||
void ScriptEngine::gc()
|
||||
{
|
||||
LOGD("GC begin ..., (Native -> JS map) count: %d\n", (int)__nativePtrToObjectMap.size());
|
||||
LOGD("GC begin ..., (Native -> JS map) count: %d\n", (int)NativePtrToObjectMap::size());
|
||||
// JSGarbageCollect(_cx);
|
||||
JSSynchronousGarbageCollectForDebugging(_cx);
|
||||
LOGD("GC end ..., (Native -> JS map) count: %d\n", (int)__nativePtrToObjectMap.size());
|
||||
LOGD("GC end ..., (Native -> JS map) count: %d\n", (int)NativePtrToObjectMap::size());
|
||||
}
|
||||
|
||||
bool ScriptEngine::executeScriptBuffer(const char *script, ssize_t length, Value *data, const char *fileName)
|
||||
@@ -344,14 +372,14 @@ namespace se {
|
||||
|
||||
void ScriptEngine::_retainScriptObject(void* owner, void* target)
|
||||
{
|
||||
auto iterOwner = __nativePtrToObjectMap.find(owner);
|
||||
if (iterOwner == __nativePtrToObjectMap.end())
|
||||
auto iterOwner = NativePtrToObjectMap::find(owner);
|
||||
if (iterOwner == NativePtrToObjectMap::end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto iterTarget = __nativePtrToObjectMap.find(target);
|
||||
if (iterTarget == __nativePtrToObjectMap.end())
|
||||
auto iterTarget = NativePtrToObjectMap::find(target);
|
||||
if (iterTarget == NativePtrToObjectMap::end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -362,14 +390,14 @@ namespace se {
|
||||
|
||||
void ScriptEngine::_releaseScriptObject(void* owner, void* target)
|
||||
{
|
||||
auto iterOwner = __nativePtrToObjectMap.find(owner);
|
||||
if (iterOwner == __nativePtrToObjectMap.end())
|
||||
auto iterOwner = NativePtrToObjectMap::find(owner);
|
||||
if (iterOwner == NativePtrToObjectMap::end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto iterTarget = __nativePtrToObjectMap.find(target);
|
||||
if (iterTarget == __nativePtrToObjectMap.end())
|
||||
auto iterTarget = NativePtrToObjectMap::find(target);
|
||||
if (iterTarget == NativePtrToObjectMap::end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -76,6 +76,20 @@ namespace se {
|
||||
*/
|
||||
bool init();
|
||||
|
||||
/**
|
||||
* @brief Adds a hook function before initializing script engine.
|
||||
* @param[in] hook A hook function to be invoked before initializing script engine.
|
||||
* @note Multiple hook functions could be added, they will be invoked by the order of adding.
|
||||
*/
|
||||
void addBeforeInitHook(const std::function<void()>& hook);
|
||||
|
||||
/**
|
||||
* @brief Adds a hook function after initializing script engine.
|
||||
* @param[in] hook A hook function to be invoked before initializing script engine.
|
||||
* @note Multiple hook functions could be added, they will be invoked by the order of adding.
|
||||
*/
|
||||
void addAfterInitHook(const std::function<void()>& hook);
|
||||
|
||||
/**
|
||||
* @brief Cleanups script engine.
|
||||
* @note This method will removes all objects in JavaScript VM even whose are rooted, then shutdown JavaScript VMf.
|
||||
@@ -128,6 +142,11 @@ namespace se {
|
||||
*/
|
||||
void clearException();
|
||||
|
||||
/**
|
||||
* @brief Gets the start time of script engine.
|
||||
*/
|
||||
const std::chrono::steady_clock::time_point& getStartTime() const { return _startTime; }
|
||||
|
||||
// Private API used in wrapper
|
||||
void _retainScriptObject(void* owner, void* target);
|
||||
void _releaseScriptObject(void* owner, void* target);
|
||||
@@ -167,6 +186,10 @@ namespace se {
|
||||
|
||||
std::vector<RegisterCallback> _registerCallbackArray;
|
||||
std::chrono::steady_clock::time_point _startTime;
|
||||
|
||||
std::vector<std::function<void()>> _beforeInitHookArray;
|
||||
std::vector<std::function<void()>> _afterInitHookArray;
|
||||
|
||||
std::vector<std::function<void()>> _beforeCleanupHookArray;
|
||||
std::vector<std::function<void()>> _afterCleanupHookArray;
|
||||
|
||||
|
||||
@@ -159,8 +159,7 @@ namespace se {
|
||||
{
|
||||
obj = Object::_createJSObject(nullptr, jsobj);
|
||||
}
|
||||
obj->root(); // Root it here since it will be unrooted in at the end of SE_BIND_FUNC
|
||||
data->setObject(obj);
|
||||
data->setObject(obj, true);
|
||||
obj->release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,13 +26,6 @@
|
||||
se::State state(nativeThisObject, args); \
|
||||
ret = funcName(state); \
|
||||
se::internal::setReturnValue(_cx, state.rval(), _argv); \
|
||||
for (auto& v : args) \
|
||||
{ \
|
||||
if (v.isObject()) \
|
||||
{ \
|
||||
v.toObject()->unroot(); \
|
||||
} \
|
||||
} \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
@@ -69,13 +62,6 @@
|
||||
_found = thisObject->getProperty("_ctor", &_property); \
|
||||
if (_found) _property.toObject()->call(args, thisObject); \
|
||||
} \
|
||||
for (auto& v : args) \
|
||||
{ \
|
||||
if (v.isObject()) \
|
||||
{ \
|
||||
v.toObject()->unroot(); \
|
||||
} \
|
||||
} \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
@@ -99,13 +85,6 @@
|
||||
_found = thisObject->getProperty("_ctor", &_property); \
|
||||
if (_found) _property.toObject()->call(args, thisObject); \
|
||||
} \
|
||||
for (auto& v : args) \
|
||||
{ \
|
||||
if (v.isObject()) \
|
||||
{ \
|
||||
v.toObject()->unroot(); \
|
||||
} \
|
||||
} \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
@@ -139,10 +118,6 @@
|
||||
args.push_back(std::move(data)); \
|
||||
se::State state(nativeThisObject, args); \
|
||||
ret = funcName(state); \
|
||||
if (args[0].isObject() && args[0].toObject()->isRooted()) \
|
||||
{ \
|
||||
args[0].toObject()->unroot(); \
|
||||
} \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
#include "Object.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "Class.hpp"
|
||||
#include "ScriptEngine.hpp"
|
||||
|
||||
#ifdef SCRIPT_ENGINE_SM
|
||||
|
||||
#include "Utils.hpp"
|
||||
#include "Class.hpp"
|
||||
#include "ScriptEngine.hpp"
|
||||
#include "../MappingUtils.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
// key: native ptr, value: se::Object
|
||||
std::unordered_map<void*, Object*> __nativePtrToObjectMap;
|
||||
// key: native ptr, value: non-ref object created by ctor
|
||||
std::unordered_map<void*, bool> __nonRefNativeObjectCreatedByCtorMap;
|
||||
std::unordered_map<Object*, void*> __objectMap; // Currently, the value `void*` is always nullptr
|
||||
|
||||
namespace {
|
||||
@@ -94,8 +92,8 @@ namespace se {
|
||||
Object* Object::getObjectWithPtr(void* ptr)
|
||||
{
|
||||
Object* obj = nullptr;
|
||||
auto iter = __nativePtrToObjectMap.find(ptr);
|
||||
if (iter != __nativePtrToObjectMap.end())
|
||||
auto iter = NativePtrToObjectMap::find(ptr);
|
||||
if (iter != NativePtrToObjectMap::end())
|
||||
{
|
||||
obj = iter->second;
|
||||
obj->addRef();
|
||||
@@ -374,12 +372,12 @@ namespace se {
|
||||
void Object::setPrivateData(void* data)
|
||||
{
|
||||
assert(_privateData == nullptr);
|
||||
assert(__nativePtrToObjectMap.find(data) == __nativePtrToObjectMap.end());
|
||||
assert(NativePtrToObjectMap::find(data) == NativePtrToObjectMap::end());
|
||||
assert(_cls != nullptr);
|
||||
JS::RootedObject obj(__cx, _getJSObject());
|
||||
internal::setPrivate(__cx, obj, data, _finalizeCb);
|
||||
|
||||
__nativePtrToObjectMap.emplace(data, this);
|
||||
NativePtrToObjectMap::emplace(data, this);
|
||||
_privateData = data;
|
||||
}
|
||||
|
||||
@@ -388,7 +386,7 @@ namespace se {
|
||||
if (_privateData != nullptr)
|
||||
{
|
||||
void* data = getPrivateData();
|
||||
__nativePtrToObjectMap.erase(data);
|
||||
NativePtrToObjectMap::erase(data);
|
||||
JS::RootedObject obj(__cx, _getJSObject());
|
||||
internal::clearPrivate(__cx, obj);
|
||||
_privateData = nullptr;
|
||||
@@ -410,8 +408,13 @@ namespace se {
|
||||
|
||||
ScriptEngine::getInstance()->addAfterCleanupHook([](){
|
||||
__objectMap.clear();
|
||||
__nativePtrToObjectMap.clear();
|
||||
__nonRefNativeObjectCreatedByCtorMap.clear();
|
||||
const auto& instance = NativePtrToObjectMap::instance();
|
||||
for (const auto& e : instance)
|
||||
{
|
||||
e.second->release();
|
||||
}
|
||||
NativePtrToObjectMap::clear();
|
||||
NonRefNativePtrCreatedByCtorMap::clear();
|
||||
__cx = nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -93,11 +93,6 @@ namespace se {
|
||||
friend class ScriptEngine;
|
||||
};
|
||||
|
||||
|
||||
// key: native ptr, value: se::Object
|
||||
extern std::unordered_map<void*, Object*> __nativePtrToObjectMap;
|
||||
// key: native ptr, value: non-ref object created by ctor
|
||||
extern std::unordered_map<void*, bool> __nonRefNativeObjectCreatedByCtorMap;
|
||||
extern std::unordered_map<Object*, void*> __objectMap; // Currently, the value `void*` is always nullptr
|
||||
|
||||
} // namespace se {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#include "ScriptEngine.hpp"
|
||||
|
||||
#ifdef SCRIPT_ENGINE_SM
|
||||
|
||||
#include "Object.hpp"
|
||||
#include "Class.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
#ifdef SCRIPT_ENGINE_SM
|
||||
#include "../MappingUtils.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
@@ -98,11 +99,11 @@ namespace se {
|
||||
if (status == JSGC_BEGIN)
|
||||
{
|
||||
ScriptEngine::getInstance()->_setInGC(true);
|
||||
LOGD("on_garbage_collect: begin, Native -> JS map count: %d, all objects: %d\n", (int)__nativePtrToObjectMap.size(), (int)__objectMap.size());
|
||||
LOGD("on_garbage_collect: begin, Native -> JS map count: %d, all objects: %d\n", (int)NativePtrToObjectMap::size(), (int)__objectMap.size());
|
||||
}
|
||||
else if (status == JSGC_END)
|
||||
{
|
||||
LOGD("on_garbage_collect: end, Native -> JS map count: %d, all objects: %d\n", (int)__nativePtrToObjectMap.size(), (int)__objectMap.size());
|
||||
LOGD("on_garbage_collect: end, Native -> JS map count: %d, all objects: %d\n", (int)NativePtrToObjectMap::size(), (int)__objectMap.size());
|
||||
ScriptEngine::getInstance()->_setInGC(false);
|
||||
}
|
||||
}
|
||||
@@ -190,11 +191,6 @@ namespace se {
|
||||
if (__instance == nullptr)
|
||||
{
|
||||
__instance = new ScriptEngine();
|
||||
if (!__instance->init())
|
||||
{
|
||||
delete __instance;
|
||||
__instance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return __instance;
|
||||
@@ -231,8 +227,8 @@ namespace se {
|
||||
bool isInCleanup = getInstance()->_isInCleanup;
|
||||
bool isIterUpdated = false;
|
||||
Object* obj = nullptr;
|
||||
auto iter = __nativePtrToObjectMap.begin();
|
||||
while (iter != __nativePtrToObjectMap.end())
|
||||
auto iter = NativePtrToObjectMap::begin();
|
||||
while (iter != NativePtrToObjectMap::end())
|
||||
{
|
||||
obj = iter->second;
|
||||
isIterUpdated = false;
|
||||
@@ -241,7 +237,7 @@ namespace se {
|
||||
if (obj->updateAfterGC(data))
|
||||
{
|
||||
obj->release();
|
||||
iter = __nativePtrToObjectMap.erase(iter);
|
||||
iter = NativePtrToObjectMap::erase(iter);
|
||||
isIterUpdated = true;
|
||||
}
|
||||
}
|
||||
@@ -249,7 +245,7 @@ namespace se {
|
||||
{
|
||||
obj->unprotect();
|
||||
obj->release();
|
||||
iter = __nativePtrToObjectMap.erase(iter);
|
||||
iter = NativePtrToObjectMap::erase(iter);
|
||||
isIterUpdated = true;
|
||||
}
|
||||
|
||||
@@ -260,13 +256,23 @@ namespace se {
|
||||
|
||||
bool ScriptEngine::init()
|
||||
{
|
||||
cleanup();
|
||||
LOGD("Initializing SpiderMonkey \n");
|
||||
|
||||
for (const auto& hook : _beforeInitHookArray)
|
||||
{
|
||||
hook();
|
||||
}
|
||||
_beforeInitHookArray.clear();
|
||||
|
||||
_cx = JS_NewContext(JS::DefaultHeapMaxBytes);
|
||||
|
||||
if (nullptr == _cx)
|
||||
return false;
|
||||
|
||||
NativePtrToObjectMap::init();
|
||||
NonRefNativePtrCreatedByCtorMap::init();
|
||||
|
||||
Class::setContext(_cx);
|
||||
Object::setContext(_cx);
|
||||
|
||||
@@ -346,6 +352,12 @@ namespace se {
|
||||
|
||||
_isValid = true;
|
||||
|
||||
for (const auto& hook : _afterInitHookArray)
|
||||
{
|
||||
hook();
|
||||
}
|
||||
_afterInitHookArray.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -401,6 +413,10 @@ namespace se {
|
||||
}
|
||||
_afterCleanupHookArray.clear();
|
||||
_isInCleanup = false;
|
||||
|
||||
|
||||
NativePtrToObjectMap::destroy();
|
||||
NonRefNativePtrCreatedByCtorMap::destroy();
|
||||
}
|
||||
|
||||
void ScriptEngine::addBeforeCleanupHook(const std::function<void()>& hook)
|
||||
@@ -413,6 +429,16 @@ namespace se {
|
||||
_afterCleanupHookArray.push_back(hook);
|
||||
}
|
||||
|
||||
void ScriptEngine::addBeforeInitHook(const std::function<void()>& hook)
|
||||
{
|
||||
_beforeInitHookArray.push_back(hook);
|
||||
}
|
||||
|
||||
void ScriptEngine::addAfterInitHook(const std::function<void()>& hook)
|
||||
{
|
||||
_afterInitHookArray.push_back(hook);
|
||||
}
|
||||
|
||||
bool ScriptEngine::isInGC()
|
||||
{
|
||||
return _isInGC;
|
||||
@@ -436,6 +462,9 @@ namespace se {
|
||||
|
||||
bool ScriptEngine::start()
|
||||
{
|
||||
if (!init())
|
||||
return false;
|
||||
|
||||
bool ok = false;
|
||||
_startTime = std::chrono::steady_clock::now();
|
||||
|
||||
@@ -483,14 +512,14 @@ namespace se {
|
||||
|
||||
void ScriptEngine::_retainScriptObject(void* owner, void* target)
|
||||
{
|
||||
auto iterOwner = __nativePtrToObjectMap.find(owner);
|
||||
if (iterOwner == __nativePtrToObjectMap.end())
|
||||
auto iterOwner = NativePtrToObjectMap::find(owner);
|
||||
if (iterOwner == NativePtrToObjectMap::end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto iterTarget = __nativePtrToObjectMap.find(target);
|
||||
if (iterTarget == __nativePtrToObjectMap.end())
|
||||
auto iterTarget = NativePtrToObjectMap::find(target);
|
||||
if (iterTarget == NativePtrToObjectMap::end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -501,14 +530,14 @@ namespace se {
|
||||
|
||||
void ScriptEngine::_releaseScriptObject(void* owner, void* target)
|
||||
{
|
||||
auto iterOwner = __nativePtrToObjectMap.find(owner);
|
||||
if (iterOwner == __nativePtrToObjectMap.end())
|
||||
auto iterOwner = NativePtrToObjectMap::find(owner);
|
||||
if (iterOwner == NativePtrToObjectMap::end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto iterTarget = __nativePtrToObjectMap.find(target);
|
||||
if (iterTarget == __nativePtrToObjectMap.end())
|
||||
auto iterTarget = NativePtrToObjectMap::find(target);
|
||||
if (iterTarget == NativePtrToObjectMap::end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,20 @@ namespace se {
|
||||
|
||||
bool init();
|
||||
void cleanup();
|
||||
/**
|
||||
* @brief Adds a hook function before initializing script engine.
|
||||
* @param[in] hook A hook function to be invoked before initializing script engine.
|
||||
* @note Multiple hook functions could be added, they will be invoked by the order of adding.
|
||||
*/
|
||||
void addBeforeInitHook(const std::function<void()>& hook);
|
||||
|
||||
/**
|
||||
* @brief Adds a hook function after initializing script engine.
|
||||
* @param[in] hook A hook function to be invoked before initializing script engine.
|
||||
* @note Multiple hook functions could be added, they will be invoked by the order of adding.
|
||||
*/
|
||||
void addAfterInitHook(const std::function<void()>& hook);
|
||||
|
||||
void addBeforeCleanupHook(const std::function<void()>& hook);
|
||||
void addAfterCleanupHook(const std::function<void()>& hook);
|
||||
|
||||
@@ -57,6 +71,8 @@ namespace se {
|
||||
|
||||
void clearException();
|
||||
|
||||
const std::chrono::steady_clock::time_point& getStartTime() const { return _startTime; }
|
||||
|
||||
void _retainScriptObject(void* owner, void* target);
|
||||
void _releaseScriptObject(void* owner, void* target);
|
||||
|
||||
@@ -89,6 +105,10 @@ namespace se {
|
||||
|
||||
std::vector<RegisterCallback> _registerCallbackArray;
|
||||
std::chrono::steady_clock::time_point _startTime;
|
||||
|
||||
std::vector<std::function<void()>> _beforeInitHookArray;
|
||||
std::vector<std::function<void()>> _afterInitHookArray;
|
||||
|
||||
std::vector<std::function<void()>> _beforeCleanupHookArray;
|
||||
std::vector<std::function<void()>> _afterCleanupHookArray;
|
||||
};
|
||||
|
||||
@@ -136,8 +136,7 @@ namespace se {
|
||||
{
|
||||
object = Object::_createJSObject(nullptr, jsval.toObjectOrNull());
|
||||
}
|
||||
object->root(); // Root it here since it will be unrooted in at the end of SE_BIND_FUNC
|
||||
v->setObject(object);
|
||||
v->setObject(object, true);
|
||||
object->release();
|
||||
}
|
||||
else if (jsval.isNull())
|
||||
|
||||
@@ -32,13 +32,6 @@
|
||||
se::State state(nativeThisObject, args); \
|
||||
ret = funcName(state); \
|
||||
se::internal::setReturnValue(state.rval(), _v8args); \
|
||||
for (auto& v : args) \
|
||||
{ \
|
||||
if (v.isObject()) \
|
||||
{ \
|
||||
v.toObject()->unroot(); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define SE_BIND_FINALIZE_FUNC(funcName) \
|
||||
@@ -73,13 +66,6 @@
|
||||
bool _found = false; \
|
||||
_found = thisObject->getProperty("_ctor", &_property); \
|
||||
if (_found) _property.toObject()->call(args, thisObject); \
|
||||
for (auto& v : args) \
|
||||
{ \
|
||||
if (v.isObject()) \
|
||||
{ \
|
||||
v.toObject()->unroot(); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define SE_BIND_SUB_CLS_CTOR SE_BIND_CTOR
|
||||
@@ -111,10 +97,6 @@
|
||||
args.push_back(std::move(data)); \
|
||||
se::State state(nativeThisObject, args); \
|
||||
ret = funcName(state); \
|
||||
if (args[0].isObject() && args[0].toObject()->isRooted()) \
|
||||
{ \
|
||||
args[0].toObject()->unroot(); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,13 +4,10 @@
|
||||
#include "Utils.hpp"
|
||||
#include "Class.hpp"
|
||||
#include "ScriptEngine.hpp"
|
||||
#include "../MappingUtils.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
// key: native ptr, value: se::Object
|
||||
std::unordered_map<void*, Object*> __nativePtrToObjectMap;
|
||||
// key: native ptr, value: non-ref object created by ctor
|
||||
std::unordered_map<void*, bool> __nonRefNativeObjectCreatedByCtorMap;
|
||||
std::unordered_map<Object*, void*> __objectMap; // Currently, the value `void*` is always nullptr
|
||||
|
||||
namespace {
|
||||
@@ -46,8 +43,8 @@ namespace se {
|
||||
if (nativeObj == nullptr)
|
||||
return;
|
||||
|
||||
auto iter = __nativePtrToObjectMap.find(nativeObj);
|
||||
if (iter != __nativePtrToObjectMap.end())
|
||||
auto iter = NativePtrToObjectMap::find(nativeObj);
|
||||
if (iter != NativePtrToObjectMap::end())
|
||||
{
|
||||
Object* obj = iter->second;
|
||||
if (obj->_finalizeCb != nullptr)
|
||||
@@ -61,7 +58,7 @@ namespace se {
|
||||
obj->_getClass()->_finalizeFunc(nativeObj);
|
||||
}
|
||||
obj->release();
|
||||
__nativePtrToObjectMap.erase(iter);
|
||||
NativePtrToObjectMap::erase(iter);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -82,7 +79,8 @@ namespace se {
|
||||
Object* obj = nullptr;
|
||||
Class* cls = nullptr;
|
||||
|
||||
for (const auto& e : __nativePtrToObjectMap)
|
||||
const auto& nativePtrToObjectMap = NativePtrToObjectMap::instance();
|
||||
for (const auto& e : nativePtrToObjectMap)
|
||||
{
|
||||
nativeObj = e.first;
|
||||
obj = e.second;
|
||||
@@ -110,8 +108,8 @@ namespace se {
|
||||
obj->release();
|
||||
}
|
||||
|
||||
__nativePtrToObjectMap.clear();
|
||||
__nonRefNativeObjectCreatedByCtorMap.clear();
|
||||
NativePtrToObjectMap::clear();
|
||||
NonRefNativePtrCreatedByCtorMap::clear();
|
||||
|
||||
std::vector<Object*> toReleaseObjects;
|
||||
for (const auto& e : __objectMap)
|
||||
@@ -146,8 +144,8 @@ namespace se {
|
||||
Object* Object::getObjectWithPtr(void* ptr)
|
||||
{
|
||||
Object* obj = nullptr;
|
||||
auto iter = __nativePtrToObjectMap.find(ptr);
|
||||
if (iter != __nativePtrToObjectMap.end())
|
||||
auto iter = NativePtrToObjectMap::find(ptr);
|
||||
if (iter != NativePtrToObjectMap::end())
|
||||
{
|
||||
obj = iter->second;
|
||||
obj->addRef();
|
||||
@@ -340,9 +338,9 @@ namespace se {
|
||||
void Object::setPrivateData(void* data)
|
||||
{
|
||||
assert(_privateData == nullptr);
|
||||
assert(__nativePtrToObjectMap.find(data) == __nativePtrToObjectMap.end());
|
||||
assert(NativePtrToObjectMap::find(data) == NativePtrToObjectMap::end());
|
||||
internal::setPrivate(__isolate, _obj, data, &_internalData);
|
||||
__nativePtrToObjectMap.emplace(data, this);
|
||||
NativePtrToObjectMap::emplace(data, this);
|
||||
_privateData = data;
|
||||
}
|
||||
|
||||
@@ -360,7 +358,7 @@ namespace se {
|
||||
if (_privateData != nullptr)
|
||||
{
|
||||
void* data = getPrivateData();
|
||||
__nativePtrToObjectMap.erase(data);
|
||||
NativePtrToObjectMap::erase(data);
|
||||
internal::clearPrivate(__isolate, _obj);
|
||||
_privateData = nullptr;
|
||||
}
|
||||
|
||||
@@ -95,10 +95,6 @@ namespace se {
|
||||
friend class ScriptEngine;
|
||||
};
|
||||
|
||||
// key: native ptr, value: se::Object
|
||||
extern std::unordered_map<void*, Object*> __nativePtrToObjectMap;
|
||||
// key: native ptr, value: non-ref object created by ctor
|
||||
extern std::unordered_map<void*, bool> __nonRefNativeObjectCreatedByCtorMap;
|
||||
extern std::unordered_map<Object*, void*> __objectMap; // Currently, the value `void*` is always nullptr
|
||||
|
||||
} // namespace se {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "Object.hpp"
|
||||
#include "Class.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "../MappingUtils.hpp"
|
||||
|
||||
#if SE_ENABLE_INSPECTOR
|
||||
#include "inspector_agent.h"
|
||||
@@ -95,11 +96,6 @@ namespace se {
|
||||
if (__instance == nullptr)
|
||||
{
|
||||
__instance = new ScriptEngine();
|
||||
if (!__instance->init())
|
||||
{
|
||||
delete __instance;
|
||||
__instance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return __instance;
|
||||
@@ -143,8 +139,15 @@ namespace se {
|
||||
|
||||
bool ScriptEngine::init()
|
||||
{
|
||||
cleanup();
|
||||
LOGD("Initializing V8\n");
|
||||
|
||||
for (const auto& hook : _beforeInitHookArray)
|
||||
{
|
||||
hook();
|
||||
}
|
||||
_beforeInitHookArray.clear();
|
||||
|
||||
assert(_allocator == nullptr);
|
||||
_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator();
|
||||
// Create a new Isolate and make it the current one.
|
||||
@@ -162,6 +165,9 @@ namespace se {
|
||||
_context.Reset(_isolate, v8::Context::New(_isolate));
|
||||
_context.Get(_isolate)->Enter();
|
||||
|
||||
NativePtrToObjectMap::init();
|
||||
NonRefNativePtrCreatedByCtorMap::init();
|
||||
|
||||
Class::setIsolate(_isolate);
|
||||
Object::setIsolate(_isolate);
|
||||
|
||||
@@ -193,6 +199,12 @@ namespace se {
|
||||
|
||||
_isValid = true;
|
||||
|
||||
for (const auto& hook : _afterInitHookArray)
|
||||
{
|
||||
hook();
|
||||
}
|
||||
_afterInitHookArray.clear();
|
||||
|
||||
return _isValid;
|
||||
}
|
||||
|
||||
@@ -242,6 +254,10 @@ namespace se {
|
||||
hook();
|
||||
}
|
||||
_afterCleanupHookArray.clear();
|
||||
|
||||
|
||||
NativePtrToObjectMap::destroy();
|
||||
NonRefNativePtrCreatedByCtorMap::destroy();
|
||||
}
|
||||
|
||||
Object* ScriptEngine::getGlobalObject() const
|
||||
@@ -249,6 +265,16 @@ namespace se {
|
||||
return _globalObj;
|
||||
}
|
||||
|
||||
void ScriptEngine::addBeforeInitHook(const std::function<void()>& hook)
|
||||
{
|
||||
_beforeInitHookArray.push_back(hook);
|
||||
}
|
||||
|
||||
void ScriptEngine::addAfterInitHook(const std::function<void()>& hook)
|
||||
{
|
||||
_afterInitHookArray.push_back(hook);
|
||||
}
|
||||
|
||||
void ScriptEngine::addBeforeCleanupHook(const std::function<void()>& hook)
|
||||
{
|
||||
_beforeCleanupHookArray.push_back(hook);
|
||||
@@ -267,6 +293,10 @@ namespace se {
|
||||
|
||||
bool ScriptEngine::start()
|
||||
{
|
||||
if (!init())
|
||||
return false;
|
||||
|
||||
se::AutoHandleScope hs;
|
||||
bool ok = false;
|
||||
_startTime = std::chrono::steady_clock::now();
|
||||
|
||||
@@ -286,7 +316,7 @@ namespace se {
|
||||
|
||||
void ScriptEngine::gc()
|
||||
{
|
||||
LOGD("GC begin ..., (js->native map) size: %d, all objects: %d\n", (int)__nativePtrToObjectMap.size(), (int)__objectMap.size());
|
||||
LOGD("GC begin ..., (js->native map) size: %d, all objects: %d\n", (int)NativePtrToObjectMap::size(), (int)__objectMap.size());
|
||||
const double kLongIdlePauseInSeconds = 1.0;
|
||||
_isolate->ContextDisposedNotification();
|
||||
_isolate->IdleNotificationDeadline(_platform->MonotonicallyIncreasingTime() + kLongIdlePauseInSeconds);
|
||||
@@ -294,7 +324,7 @@ namespace se {
|
||||
// garbage and will therefore also invoke all weak callbacks of actually
|
||||
// unreachable persistent handles.
|
||||
_isolate->LowMemoryNotification();
|
||||
LOGD("GC end ..., (js->native map) size: %d, all objects: %d\n", (int)__nativePtrToObjectMap.size(), (int)__objectMap.size());
|
||||
LOGD("GC end ..., (js->native map) size: %d, all objects: %d\n", (int)NativePtrToObjectMap::size(), (int)__objectMap.size());
|
||||
}
|
||||
|
||||
bool ScriptEngine::isInGC()
|
||||
@@ -352,20 +382,20 @@ namespace se {
|
||||
}
|
||||
}
|
||||
|
||||
assert(success);
|
||||
// assert(success);
|
||||
return success;
|
||||
}
|
||||
|
||||
void ScriptEngine::_retainScriptObject(void* owner, void* target)
|
||||
{
|
||||
auto iterOwner = __nativePtrToObjectMap.find(owner);
|
||||
if (iterOwner == __nativePtrToObjectMap.end())
|
||||
auto iterOwner = NativePtrToObjectMap::find(owner);
|
||||
if (iterOwner == NativePtrToObjectMap::end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto iterTarget = __nativePtrToObjectMap.find(target);
|
||||
if (iterTarget == __nativePtrToObjectMap.end())
|
||||
auto iterTarget = NativePtrToObjectMap::find(target);
|
||||
if (iterTarget == NativePtrToObjectMap::end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -377,14 +407,14 @@ namespace se {
|
||||
|
||||
void ScriptEngine::_releaseScriptObject(void* owner, void* target)
|
||||
{
|
||||
auto iterOwner = __nativePtrToObjectMap.find(owner);
|
||||
if (iterOwner == __nativePtrToObjectMap.end())
|
||||
auto iterOwner = NativePtrToObjectMap::find(owner);
|
||||
if (iterOwner == NativePtrToObjectMap::end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto iterTarget = __nativePtrToObjectMap.find(target);
|
||||
if (iterTarget == __nativePtrToObjectMap.end())
|
||||
auto iterTarget = NativePtrToObjectMap::find(target);
|
||||
if (iterTarget == NativePtrToObjectMap::end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,6 +60,21 @@ namespace se {
|
||||
|
||||
bool init();
|
||||
void cleanup();
|
||||
|
||||
/**
|
||||
* @brief Adds a hook function before initializing script engine.
|
||||
* @param[in] hook A hook function to be invoked before initializing script engine.
|
||||
* @note Multiple hook functions could be added, they will be invoked by the order of adding.
|
||||
*/
|
||||
void addBeforeInitHook(const std::function<void()>& hook);
|
||||
|
||||
/**
|
||||
* @brief Adds a hook function after initializing script engine.
|
||||
* @param[in] hook A hook function to be invoked before initializing script engine.
|
||||
* @note Multiple hook functions could be added, they will be invoked by the order of adding.
|
||||
*/
|
||||
void addAfterInitHook(const std::function<void()>& hook);
|
||||
|
||||
void addBeforeCleanupHook(const std::function<void()>& hook);
|
||||
void addAfterCleanupHook(const std::function<void()>& hook);
|
||||
|
||||
@@ -74,6 +89,8 @@ namespace se {
|
||||
|
||||
void clearException();
|
||||
|
||||
const std::chrono::steady_clock::time_point& getStartTime() const { return _startTime; }
|
||||
|
||||
void _retainScriptObject(void* owner, void* target);
|
||||
void _releaseScriptObject(void* owner, void* target);
|
||||
|
||||
@@ -111,6 +128,10 @@ namespace se {
|
||||
|
||||
std::vector<RegisterCallback> _registerCallbackArray;
|
||||
std::chrono::steady_clock::time_point _startTime;
|
||||
|
||||
std::vector<std::function<void()>> _beforeInitHookArray;
|
||||
std::vector<std::function<void()>> _afterInitHookArray;
|
||||
|
||||
std::vector<std::function<void()>> _beforeCleanupHookArray;
|
||||
std::vector<std::function<void()>> _afterCleanupHookArray;
|
||||
|
||||
|
||||
@@ -108,8 +108,7 @@ namespace se {
|
||||
{
|
||||
obj = Object::_createJSObject(nullptr, jsObj.ToLocalChecked());
|
||||
}
|
||||
obj->root(); // Root it here since it will be unrooted in at the end of SE_BIND_FUNC
|
||||
v->setObject(obj);
|
||||
v->setObject(obj, true);
|
||||
obj->release();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -194,6 +194,5 @@ int ScriptingCore::handleNodeEvent(void* data)
|
||||
void ScriptingCore::restartVM()
|
||||
{
|
||||
se::ScriptEngine::getInstance()->cleanup();
|
||||
se::ScriptEngine::getInstance()->init();
|
||||
Application::getInstance()->applicationDidFinishLaunching();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include "cocos/scripting/js-bindings/manual/jsb_helper.hpp"
|
||||
#include "cocos/scripting/js-bindings/auto/jsb_box2d_auto.hpp"
|
||||
|
||||
#include "cocos/editor-support/creator/physics/CCPhysicsContactListener.h"
|
||||
|
||||
bool seval_to_b2BodyDef(const se::Value& v, b2BodyDef* ret)
|
||||
{
|
||||
static b2BodyDef ZERO;
|
||||
@@ -540,7 +542,7 @@ bool array_of_b2Fixture_to_seval(const std::vector<b2Fixture*>& fixtures, se::Va
|
||||
|
||||
se::Value tmp;
|
||||
int i = 0;
|
||||
bool ok = false;
|
||||
bool ok = true;
|
||||
for (const auto& e : fixtures)
|
||||
{
|
||||
ok = native_ptr_to_rooted_seval<b2Fixture>(e, &tmp);
|
||||
@@ -553,11 +555,11 @@ bool array_of_b2Fixture_to_seval(const std::vector<b2Fixture*>& fixtures, se::Va
|
||||
}
|
||||
|
||||
if (ok)
|
||||
ret->setObject(obj);
|
||||
ret->setObject(obj, true);
|
||||
else
|
||||
ret->setUndefined();
|
||||
|
||||
return true;
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool array_of_b2Vec2_to_seval(const std::vector<b2Vec2>& vs, se::Value* ret)
|
||||
@@ -566,7 +568,7 @@ bool array_of_b2Vec2_to_seval(const std::vector<b2Vec2>& vs, se::Value* ret)
|
||||
|
||||
se::Value tmp;
|
||||
int i = 0;
|
||||
bool ok = false;
|
||||
bool ok = true;
|
||||
for (const auto& e : vs)
|
||||
{
|
||||
ok = b2Vec2_to_seval(e, &tmp);
|
||||
@@ -579,11 +581,11 @@ bool array_of_b2Vec2_to_seval(const std::vector<b2Vec2>& vs, se::Value* ret)
|
||||
}
|
||||
|
||||
if (ok)
|
||||
ret->setObject(obj);
|
||||
ret->setObject(obj, true);
|
||||
else
|
||||
ret->setUndefined();
|
||||
|
||||
return true;
|
||||
return ok;
|
||||
}
|
||||
|
||||
static bool js_box2dclasses_b2Shape_SetRadius(se::State& s)
|
||||
@@ -841,8 +843,8 @@ static bool js_box2dclasses_b2Body_GetUserData(se::State& s)
|
||||
b2Body* cobj = (b2Body *)s.nativeThisObject();
|
||||
void* data = cobj->GetUserData();
|
||||
|
||||
auto iter = se::__nativePtrToObjectMap.find(data);
|
||||
if (iter != se::__nativePtrToObjectMap.end())
|
||||
auto iter = se::NativePtrToObjectMap::find(data);
|
||||
if (iter != se::NativePtrToObjectMap::end())
|
||||
{
|
||||
s.rval().setObject(iter->second);
|
||||
}
|
||||
@@ -1077,17 +1079,21 @@ bool register_all_box2d_manual(se::Object* obj)
|
||||
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
|
||||
b2SetObjectDestroyNotifier([](void* obj, const char* type){
|
||||
b2SetObjectDestroyNotifier([](void* obj, b2ObjectType type, const char* typeName){
|
||||
|
||||
std::string typeNameStr = typeName;
|
||||
auto cleanup = [obj, typeNameStr](){
|
||||
|
||||
if (!se::ScriptEngine::getInstance()->isValid())
|
||||
return;
|
||||
|
||||
std::string typeName = type;
|
||||
auto cleanup = [=](){
|
||||
se::AutoHandleScope hs;
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
|
||||
auto iter = se::__nativePtrToObjectMap.find(obj);
|
||||
if (iter != se::__nativePtrToObjectMap.end())
|
||||
auto iter = se::NativePtrToObjectMap::find(obj);
|
||||
if (iter != se::NativePtrToObjectMap::end())
|
||||
{
|
||||
// CCLOG("%s, %p was recycled!", typeName.c_str(), obj);
|
||||
// CCLOG("%s, %p was recycled!", typeNameStr.c_str(), obj);
|
||||
se::Object* seObj = iter->second;
|
||||
seObj->clearPrivateData();
|
||||
seObj->unroot();
|
||||
@@ -1095,7 +1101,7 @@ bool register_all_box2d_manual(se::Object* obj)
|
||||
}
|
||||
else
|
||||
{
|
||||
// CCLOG("Didn't find %s, %p in map", typeName.c_str(), obj);
|
||||
// CCLOG("Didn't find %s, %p in map", typeNameStr.c_str(), obj);
|
||||
// assert(false);
|
||||
}
|
||||
};
|
||||
@@ -1108,6 +1114,15 @@ bool register_all_box2d_manual(se::Object* obj)
|
||||
{
|
||||
CleanupTask::pushTaskToAutoReleasePool(cleanup);
|
||||
}
|
||||
|
||||
if (type == b2ObjectType::FIXTURE)
|
||||
{
|
||||
const auto& instances = creator::PhysicsContactListener::getAllInstances();
|
||||
for (auto listener : instances)
|
||||
{
|
||||
listener->unregisterContactFixture(reinterpret_cast<b2Fixture*>(obj));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
#include "jsb_classtype.hpp"
|
||||
|
||||
std::unordered_map<std::string, se::Class*> JSBClassType::__jsbClassTypeMap;
|
||||
JSBClassType::Map* JSBClassType::__jsbClassTypeMap = nullptr;
|
||||
|
||||
bool JSBClassType::init()
|
||||
{
|
||||
if (__jsbClassTypeMap == nullptr)
|
||||
__jsbClassTypeMap = new (std::nothrow) Map();
|
||||
|
||||
return __jsbClassTypeMap != nullptr;
|
||||
}
|
||||
|
||||
void JSBClassType::destroy()
|
||||
{
|
||||
if (__jsbClassTypeMap != nullptr)
|
||||
{
|
||||
delete __jsbClassTypeMap;
|
||||
__jsbClassTypeMap = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void JSBClassType::cleanup()
|
||||
{
|
||||
__jsbClassTypeMap.clear();
|
||||
__jsbClassTypeMap->clear();
|
||||
}
|
||||
|
||||
@@ -7,12 +7,15 @@
|
||||
class JSBClassType
|
||||
{
|
||||
public:
|
||||
static bool init();
|
||||
static void destroy();
|
||||
|
||||
template<typename T>
|
||||
static void registerClass(se::Class* cls)
|
||||
{
|
||||
const char* typeName = typeid(T).name();
|
||||
assert(__jsbClassTypeMap.find(typeName) == __jsbClassTypeMap.end());
|
||||
__jsbClassTypeMap.emplace(typeName, cls);
|
||||
assert(__jsbClassTypeMap->find(typeName) == __jsbClassTypeMap->end());
|
||||
__jsbClassTypeMap->emplace(typeName, cls);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -20,12 +23,12 @@ public:
|
||||
{
|
||||
bool found = false;
|
||||
std::string typeName = typeid(*nativeObj).name();
|
||||
auto iter = __jsbClassTypeMap.find(typeName);
|
||||
if (iter == __jsbClassTypeMap.end())
|
||||
auto iter = __jsbClassTypeMap->find(typeName);
|
||||
if (iter == __jsbClassTypeMap->end())
|
||||
{
|
||||
typeName = typeid(T).name();
|
||||
iter = __jsbClassTypeMap.find(typeName);
|
||||
if (iter != __jsbClassTypeMap.end())
|
||||
iter = __jsbClassTypeMap->find(typeName);
|
||||
if (iter != __jsbClassTypeMap->end())
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
@@ -40,5 +43,6 @@ public:
|
||||
static void cleanup();
|
||||
|
||||
private:
|
||||
static std::unordered_map<std::string, se::Class*> __jsbClassTypeMap;
|
||||
using Map = std::unordered_map<std::string, se::Class*>;
|
||||
static Map* __jsbClassTypeMap;
|
||||
};
|
||||
|
||||
@@ -338,7 +338,7 @@ static bool invokeJSMouseCallback(EventListenerMouse* listener, const char* func
|
||||
SE_PRECONDITION2(ok, false, "invokeJSMouseCallback convert arg1 failed!");
|
||||
argArr.push_back(std::move(arg1Val));
|
||||
|
||||
assert(se::__nativePtrToObjectMap.find(arg1) != se::__nativePtrToObjectMap.end());
|
||||
assert(se::NativePtrToObjectMap::find(arg1) != se::NativePtrToObjectMap::end());
|
||||
|
||||
ok = funcVal.toObject()->call(argArr, listenerObj, retVal);
|
||||
SE_PRECONDITION2(ok, false, "invokeJSMouseCallback call function failed!");
|
||||
@@ -447,8 +447,8 @@ static bool invokeJSTouchOneByOneCallback(EventListenerTouchOneByOne* listener,
|
||||
SE_PRECONDITION_ERROR_BREAK(ok, "invokeJSTouchOneByOneCallback convert arg2 failed!");
|
||||
argArr.push_back(std::move(arg2Val));
|
||||
|
||||
assert(se::__nativePtrToObjectMap.find(touch) != se::__nativePtrToObjectMap.end());
|
||||
assert(se::__nativePtrToObjectMap.find(event) != se::__nativePtrToObjectMap.end());
|
||||
assert(se::NativePtrToObjectMap::find(touch) != se::NativePtrToObjectMap::end());
|
||||
assert(se::NativePtrToObjectMap::find(event) != se::NativePtrToObjectMap::end());
|
||||
|
||||
ok = funcVal.toObject()->call(argArr, listenerObj, retVal);
|
||||
SE_PRECONDITION_ERROR_BREAK(ok, "invokeJSTouchOneByOneCallback call function failed!");
|
||||
@@ -779,7 +779,7 @@ static bool js_EventListenerCustom_create(se::State& s)
|
||||
|
||||
ret->init(eventName, [ret, funcVal](EventCustom* event){
|
||||
|
||||
if (se::__nativePtrToObjectMap.find(ret) == se::__nativePtrToObjectMap.end())
|
||||
if (se::NativePtrToObjectMap::find(ret) == se::NativePtrToObjectMap::end())
|
||||
{
|
||||
CCLOGERROR("can't find se::Object with native ptr: %p", ret);
|
||||
return;
|
||||
|
||||
@@ -209,8 +209,8 @@ bool recreate_seval_by_native_ptr(typename std::enable_if<!std::is_base_of<cocos
|
||||
return true;
|
||||
}
|
||||
|
||||
auto iter = se::__nativePtrToObjectMap.find(v);
|
||||
if (iter != se::__nativePtrToObjectMap.end())
|
||||
auto iter = se::NativePtrToObjectMap::find(v);
|
||||
if (iter != se::NativePtrToObjectMap::end())
|
||||
{
|
||||
se::Object* seObj = iter->second;
|
||||
seObj->clearPrivateData();
|
||||
@@ -235,8 +235,8 @@ bool native_ptr_to_seval(typename std::enable_if<!std::is_base_of<cocos2d::Ref,T
|
||||
}
|
||||
|
||||
se::Object* obj = nullptr;
|
||||
auto iter = se::__nativePtrToObjectMap.find(v);
|
||||
if (iter == se::__nativePtrToObjectMap.end())
|
||||
auto iter = se::NativePtrToObjectMap::find(v);
|
||||
if (iter == se::NativePtrToObjectMap::end())
|
||||
{ // If we couldn't find native object in map, then the native object is created from native code. e.g. TMXLayer::getTileAt
|
||||
// CCLOGWARN("WARNING: non-Ref type: (%s) isn't catched!", typeid(*v).name());
|
||||
se::Class* cls = JSBClassType::findClass<T>(v);
|
||||
@@ -273,8 +273,8 @@ bool native_ptr_to_rooted_seval(typename std::enable_if<!std::is_base_of<cocos2d
|
||||
}
|
||||
|
||||
se::Object* obj = nullptr;
|
||||
auto iter = se::__nativePtrToObjectMap.find(v);
|
||||
if (iter == se::__nativePtrToObjectMap.end())
|
||||
auto iter = se::NativePtrToObjectMap::find(v);
|
||||
if (iter == se::NativePtrToObjectMap::end())
|
||||
{ // If we couldn't find native object in map, then the native object is created from native code. e.g. TMXLayer::getTileAt
|
||||
se::Class* cls = JSBClassType::findClass<T>(v);
|
||||
assert(cls != nullptr);
|
||||
@@ -314,10 +314,10 @@ bool native_ptr_to_seval(typename std::enable_if<!std::is_base_of<cocos2d::Ref,T
|
||||
}
|
||||
|
||||
se::Object* obj = nullptr;
|
||||
auto iter = se::__nativePtrToObjectMap.find(v);
|
||||
if (iter == se::__nativePtrToObjectMap.end())
|
||||
auto iter = se::NativePtrToObjectMap::find(v);
|
||||
if (iter == se::NativePtrToObjectMap::end())
|
||||
{ // If we couldn't find native object in map, then the native object is created from native code. e.g. TMXLayer::getTileAt
|
||||
// CCLOGWARN("WARNING: Ref type: (%s) isn't catched!", typeid(*v).name());
|
||||
// CCLOGWARN("WARNING: Ref type: (%s) isn't catched!", typeid(*v).name());
|
||||
assert(cls != nullptr);
|
||||
obj = se::Object::createObjectWithClass(cls);
|
||||
ret->setObject(obj, true);
|
||||
@@ -352,8 +352,8 @@ bool native_ptr_to_rooted_seval(typename std::enable_if<!std::is_base_of<cocos2d
|
||||
}
|
||||
|
||||
se::Object* obj = nullptr;
|
||||
auto iter = se::__nativePtrToObjectMap.find(v);
|
||||
if (iter == se::__nativePtrToObjectMap.end())
|
||||
auto iter = se::NativePtrToObjectMap::find(v);
|
||||
if (iter == se::NativePtrToObjectMap::end())
|
||||
{ // If we couldn't find native object in map, then the native object is created from native code. e.g. TMXLayer::getTileAt
|
||||
assert(cls != nullptr);
|
||||
obj = se::Object::createObjectWithClass(cls);
|
||||
@@ -392,10 +392,10 @@ bool native_ptr_to_seval(typename std::enable_if<std::is_base_of<cocos2d::Ref,T>
|
||||
}
|
||||
|
||||
se::Object* obj = nullptr;
|
||||
auto iter = se::__nativePtrToObjectMap.find(v);
|
||||
if (iter == se::__nativePtrToObjectMap.end())
|
||||
auto iter = se::NativePtrToObjectMap::find(v);
|
||||
if (iter == se::NativePtrToObjectMap::end())
|
||||
{ // If we couldn't find native object in map, then the native object is created from native code. e.g. TMXLayer::getTileAt
|
||||
// CCLOGWARN("WARNING: Ref type: (%s) isn't catched!", typeid(*v).name());
|
||||
// CCLOGWARN("WARNING: Ref type: (%s) isn't catched!", typeid(*v).name());
|
||||
se::Class* cls = JSBClassType::findClass<T>(v);
|
||||
assert(cls != nullptr);
|
||||
obj = se::Object::createObjectWithClass(cls);
|
||||
@@ -432,10 +432,10 @@ bool native_ptr_to_seval(typename std::enable_if<std::is_base_of<cocos2d::Ref,T>
|
||||
}
|
||||
|
||||
se::Object* obj = nullptr;
|
||||
auto iter = se::__nativePtrToObjectMap.find(v);
|
||||
if (iter == se::__nativePtrToObjectMap.end())
|
||||
auto iter = se::NativePtrToObjectMap::find(v);
|
||||
if (iter == se::NativePtrToObjectMap::end())
|
||||
{ // If we couldn't find native object in map, then the native object is created from native code. e.g. TMXLayer::getTileAt
|
||||
// CCLOGWARN("WARNING: Ref type: (%s) isn't catched!", typeid(*v).name());
|
||||
// CCLOGWARN("WARNING: Ref type: (%s) isn't catched!", typeid(*v).name());
|
||||
assert(cls != nullptr);
|
||||
obj = se::Object::createObjectWithClass(cls);
|
||||
ret->setObject(obj, true);
|
||||
|
||||
@@ -423,8 +423,8 @@ bool register_all_dragonbones_manual(se::Object* obj)
|
||||
se::AutoHandleScope hs;
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
|
||||
auto iter = se::__nativePtrToObjectMap.find(obj);
|
||||
if (iter != se::__nativePtrToObjectMap.end())
|
||||
auto iter = se::NativePtrToObjectMap::find(obj);
|
||||
if (iter != se::NativePtrToObjectMap::end())
|
||||
{
|
||||
// CCLOG("%s: %p was recycled!", typeName.c_str(), obj);
|
||||
se::Object* seObj = iter->second;
|
||||
|
||||
@@ -441,7 +441,7 @@ SE_BIND_FUNC(jsc_garbageCollect)
|
||||
|
||||
static bool jsc_dumpNativePtrToSeObjectMap(se::State& s)
|
||||
{
|
||||
cocos2d::log(">>> total: %d, Dump (native -> jsobj) map begin", (int)se::__nativePtrToObjectMap.size());
|
||||
cocos2d::log(">>> total: %d, Dump (native -> jsobj) map begin", (int)se::NativePtrToObjectMap::size());
|
||||
|
||||
struct NamePtrStruct
|
||||
{
|
||||
@@ -451,7 +451,7 @@ static bool jsc_dumpNativePtrToSeObjectMap(se::State& s)
|
||||
|
||||
std::vector<NamePtrStruct> namePtrArray;
|
||||
|
||||
for (const auto& e : se::__nativePtrToObjectMap)
|
||||
for (const auto& e : se::NativePtrToObjectMap::instance())
|
||||
{
|
||||
se::Object* jsobj = e.second;
|
||||
assert(jsobj->_getClass() != nullptr);
|
||||
@@ -478,7 +478,7 @@ static bool jsc_dumpNativePtrToSeObjectMap(se::State& s)
|
||||
{
|
||||
cocos2d::log("%s: %p", e.name, e.ptr);
|
||||
}
|
||||
cocos2d::log(">>> total: %d, Dump (native -> jsobj) map end", (int)se::__nativePtrToObjectMap.size());
|
||||
cocos2d::log(">>> total: %d, nonRefMap: %d, Dump (native -> jsobj) map end", (int)se::NativePtrToObjectMap::size(), (int)se::NonRefNativePtrCreatedByCtorMap::size());
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(jsc_dumpNativePtrToSeObjectMap)
|
||||
@@ -598,7 +598,8 @@ static bool JSB_isObjectValid(se::State& s)
|
||||
{
|
||||
void* nativePtr = nullptr;
|
||||
seval_to_native_ptr(args[0], &nativePtr);
|
||||
return nativePtr != nullptr;
|
||||
s.rval().setBoolean(nativePtr != nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
SE_REPORT_ERROR("Invalid number of arguments: %d. Expecting: 1", argc);
|
||||
@@ -628,8 +629,9 @@ static bool getOrCreatePlainObject_r(const char* name, se::Object* parent, se::O
|
||||
|
||||
static bool js_performance_now(se::State& s)
|
||||
{
|
||||
assert(false);
|
||||
//FIXME:
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
auto micro = std::chrono::duration_cast<std::chrono::microseconds>(now - se::ScriptEngine::getInstance()->getStartTime()).count();
|
||||
s.rval().setNumber((double)micro * 0.001);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(js_performance_now)
|
||||
|
||||
@@ -48,6 +48,7 @@ using namespace cocos2d;
|
||||
|
||||
bool jsb_run_script(const std::string& filePath)
|
||||
{
|
||||
se::AutoHandleScope hs;
|
||||
Data data = FileUtils::getInstance()->getDataFromFile(filePath);
|
||||
if (data.isNull())
|
||||
return false;
|
||||
@@ -70,12 +71,16 @@ static bool run_boot_script(se::Object* global)
|
||||
bool jsb_register_all_modules()
|
||||
{
|
||||
se::ScriptEngine* se = se::ScriptEngine::getInstance();
|
||||
|
||||
se->addBeforeInitHook([](){
|
||||
JSBClassType::init();
|
||||
});
|
||||
|
||||
se->addBeforeCleanupHook([se](){
|
||||
se->gc();
|
||||
PoolManager::getInstance()->getCurrentPool()->clear();
|
||||
se->gc();
|
||||
PoolManager::getInstance()->getCurrentPool()->clear();
|
||||
CCLOG("test");
|
||||
});
|
||||
|
||||
se->addRegisterCallback(jsb_register_global_variables);
|
||||
@@ -128,8 +133,8 @@ bool jsb_register_all_modules()
|
||||
se->addRegisterCallback(run_boot_script);
|
||||
|
||||
se->addAfterCleanupHook([](){
|
||||
JSBClassType::cleanup();
|
||||
PoolManager::getInstance()->getCurrentPool()->clear();
|
||||
JSBClassType::destroy();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1258,8 +1258,8 @@ static void cleanupAllSchedulesForTarget(Node* node, se::Object* jsThis)
|
||||
|
||||
static bool onReceiveNodeEvent(void* node, se::ScriptEngine::NodeEventType type)
|
||||
{
|
||||
auto iter = se::__nativePtrToObjectMap.find(node);
|
||||
if (iter == se::__nativePtrToObjectMap.end())
|
||||
auto iter = se::NativePtrToObjectMap::find(node);
|
||||
if (iter == se::NativePtrToObjectMap::end())
|
||||
return false;
|
||||
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
|
||||
@@ -60,8 +60,8 @@ public:
|
||||
if (cocos2d::Director::getInstance() == nullptr || cocos2d::ScriptEngineManager::getInstance() == nullptr)
|
||||
return;
|
||||
|
||||
auto iter = se::__nativePtrToObjectMap.find(client); //FIXME: client probably be a new value with the same address as the old one, it may cause undefined result.
|
||||
if (iter == se::__nativePtrToObjectMap.end())
|
||||
auto iter = se::NativePtrToObjectMap::find(client); //FIXME: client probably be a new value with the same address as the old one, it may cause undefined result.
|
||||
if (iter == se::NativePtrToObjectMap::end())
|
||||
return;
|
||||
|
||||
se::Value dataVal;
|
||||
|
||||
@@ -62,8 +62,8 @@ public:
|
||||
if (cocos2d::Director::getInstance() == nullptr || cocos2d::ScriptEngineManager::getInstance() == nullptr)
|
||||
return;
|
||||
|
||||
auto iter = se::__nativePtrToObjectMap.find(ws);
|
||||
if (iter == se::__nativePtrToObjectMap.end())
|
||||
auto iter = se::NativePtrToObjectMap::find(ws);
|
||||
if (iter == se::NativePtrToObjectMap::end())
|
||||
return;
|
||||
|
||||
se::Object* wsObj = iter->second;
|
||||
@@ -93,8 +93,8 @@ public:
|
||||
if (cocos2d::Director::getInstance() == nullptr || cocos2d::ScriptEngineManager::getInstance() == nullptr)
|
||||
return;
|
||||
|
||||
auto iter = se::__nativePtrToObjectMap.find(ws);
|
||||
if (iter == se::__nativePtrToObjectMap.end())
|
||||
auto iter = se::NativePtrToObjectMap::find(ws);
|
||||
if (iter == se::NativePtrToObjectMap::end())
|
||||
return;
|
||||
|
||||
se::Object* wsObj = iter->second;
|
||||
@@ -152,10 +152,10 @@ public:
|
||||
if (cocos2d::Director::getInstance() == nullptr || cocos2d::ScriptEngineManager::getInstance() == nullptr)
|
||||
return;
|
||||
|
||||
auto iter = se::__nativePtrToObjectMap.find(ws);
|
||||
auto iter = se::NativePtrToObjectMap::find(ws);
|
||||
do
|
||||
{
|
||||
if (iter == se::__nativePtrToObjectMap.end())
|
||||
if (iter == se::NativePtrToObjectMap::end())
|
||||
{
|
||||
CCLOGINFO("WebSocket js instance was destroyted, don't need to invoke onclose callback!");
|
||||
break;
|
||||
@@ -192,8 +192,8 @@ public:
|
||||
if (cocos2d::Director::getInstance() == nullptr || cocos2d::ScriptEngineManager::getInstance() == nullptr)
|
||||
return;
|
||||
|
||||
auto iter = se::__nativePtrToObjectMap.find(ws);
|
||||
if (iter == se::__nativePtrToObjectMap.end())
|
||||
auto iter = se::NativePtrToObjectMap::find(ws);
|
||||
if (iter == se::NativePtrToObjectMap::end())
|
||||
return;
|
||||
|
||||
se::Object* wsObj = iter->second;
|
||||
|
||||
@@ -12,6 +12,7 @@ LOCAL_SRC_FILES := \
|
||||
../jswrapper/State.cpp \
|
||||
../jswrapper/Value.cpp \
|
||||
../jswrapper/HandleObject.cpp \
|
||||
../jswrapper/MappingUtils.cpp \
|
||||
../jswrapper/sm/Class.cpp \
|
||||
../jswrapper/sm/ScriptEngine.cpp \
|
||||
../jswrapper/sm/Object.cpp \
|
||||
@@ -42,6 +43,7 @@ LOCAL_SRC_FILES := \
|
||||
../auto/jsb_cocos2dx_spine_auto.cpp \
|
||||
../auto/jsb_cocos2dx_ui_auto.cpp \
|
||||
../auto/jsb_creator_auto.cpp \
|
||||
../manual/BaseJSAction.cpp \
|
||||
../manual/JavaScriptJavaBridge.cpp \
|
||||
../manual/ScriptingCore.cpp \
|
||||
../manual/jsb_helper.cpp \
|
||||
@@ -89,8 +91,8 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../manual \
|
||||
LOCAL_EXPORT_LDLIBS := -lz
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := cocos2dx_static
|
||||
LOCAL_STATIC_LIBRARIES += spidermonkey_static spidermonkey_glue_static
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES += v8_base_static v8_inspector_static v8_libplatform_static v8_libbase_static v8_libsampler_static v8_nosnapshot_static v8_builtins_setup_static v8_builtins_generators_static uv_static
|
||||
# LOCAL_STATIC_LIBRARIES += spidermonkey_static
|
||||
LOCAL_STATIC_LIBRARIES += v8_static
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
#==============================================================
|
||||
|
||||
+28
-64
@@ -23,6 +23,14 @@
|
||||
1A159D511F13216F00558E38 /* jsb_socketio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A159D4E1F13216F00558E38 /* jsb_socketio.cpp */; };
|
||||
1A159D521F13216F00558E38 /* jsb_socketio.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1A159D4F1F13216F00558E38 /* jsb_socketio.hpp */; };
|
||||
1A159D531F13216F00558E38 /* jsb_socketio.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1A159D4F1F13216F00558E38 /* jsb_socketio.hpp */; };
|
||||
1A210D941F456821006CCBAE /* MappingUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A210D921F456821006CCBAE /* MappingUtils.cpp */; };
|
||||
1A210D951F456821006CCBAE /* MappingUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A210D921F456821006CCBAE /* MappingUtils.cpp */; };
|
||||
1A210D961F456821006CCBAE /* MappingUtils.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1A210D931F456821006CCBAE /* MappingUtils.hpp */; };
|
||||
1A210D971F456821006CCBAE /* MappingUtils.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1A210D931F456821006CCBAE /* MappingUtils.hpp */; };
|
||||
1A210DE01F46C2D3006CCBAE /* libjs_static.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A210DDE1F46C2D3006CCBAE /* libjs_static.a */; };
|
||||
1A210DE11F46C2D3006CCBAE /* libmozglue.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A210DDF1F46C2D3006CCBAE /* libmozglue.a */; };
|
||||
1A210DE41F46C2DF006CCBAE /* libjs_static.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A210DE21F46C2DF006CCBAE /* libjs_static.a */; };
|
||||
1A210DE51F46C2DF006CCBAE /* libmozglue.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A210DE31F46C2DF006CCBAE /* libmozglue.a */; };
|
||||
1A5F228A1F0DDD6B0008BF09 /* jsb_dragonbones_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A5F22881F0DDD6B0008BF09 /* jsb_dragonbones_manual.cpp */; };
|
||||
1A5F228B1F0DDD6B0008BF09 /* jsb_dragonbones_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A5F22881F0DDD6B0008BF09 /* jsb_dragonbones_manual.cpp */; };
|
||||
1A5F228C1F0DDD6B0008BF09 /* jsb_dragonbones_manual.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1A5F22891F0DDD6B0008BF09 /* jsb_dragonbones_manual.hpp */; };
|
||||
@@ -77,8 +85,6 @@
|
||||
1AB5E62C18D05BC80088DAA4 /* jsb_cocos2dx_ui_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AB5E62918D05BC80088DAA4 /* jsb_cocos2dx_ui_auto.cpp */; };
|
||||
1AB5E62D18D05BC80088DAA4 /* jsb_cocos2dx_ui_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1AB5E62A18D05BC80088DAA4 /* jsb_cocos2dx_ui_auto.hpp */; };
|
||||
1AB5E62E18D05BC80088DAA4 /* jsb_cocos2dx_ui_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1AB5E62A18D05BC80088DAA4 /* jsb_cocos2dx_ui_auto.hpp */; };
|
||||
1AC0650A1F00A62A009EC214 /* libmozglue.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AC065091F00A62A009EC214 /* libmozglue.a */; };
|
||||
1AC0650C1F00A926009EC214 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AC0650B1F00A926009EC214 /* JavaScriptCore.framework */; };
|
||||
1AD4AE671F0F920700A823D8 /* jsb_websocket.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AD4AE651F0F920700A823D8 /* jsb_websocket.cpp */; };
|
||||
1AD4AE681F0F920700A823D8 /* jsb_websocket.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AD4AE651F0F920700A823D8 /* jsb_websocket.cpp */; };
|
||||
1AD4AE691F0F920700A823D8 /* jsb_websocket.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1AD4AE661F0F920700A823D8 /* jsb_websocket.hpp */; };
|
||||
@@ -261,9 +267,6 @@
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
1A1051061F14C0B600D4322C /* libjs_static.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libjs_static.a; path = "../../../../../SpiderMonkey/build-osx/release-dist/sdk/lib/libjs_static.a"; sourceTree = "<group>"; };
|
||||
1A1051071F14C0B600D4322C /* libmozglue.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libmozglue.a; path = "../../../../../SpiderMonkey/build-osx/release-dist/sdk/lib/libmozglue.a"; sourceTree = "<group>"; };
|
||||
1A10510D1F14CB4000D4322C /* libjs_static.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libjs_static.a; path = ../../../../external/mac/libs/libjs_static.a; sourceTree = "<group>"; };
|
||||
1A119E2F18BDF19200352BAA /* jsb_cocos2dx_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_cocos2dx_auto.cpp; sourceTree = "<group>"; };
|
||||
1A119E3018BDF19200352BAA /* jsb_cocos2dx_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_cocos2dx_auto.hpp; sourceTree = "<group>"; };
|
||||
1A119E3518BDF19200352BAA /* jsb_cocos2dx_extension_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_cocos2dx_extension_auto.cpp; sourceTree = "<group>"; };
|
||||
@@ -272,8 +275,12 @@
|
||||
1A119E3C18BDF19200352BAA /* jsb_cocos2dx_spine_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_cocos2dx_spine_auto.hpp; sourceTree = "<group>"; };
|
||||
1A159D4E1F13216F00558E38 /* jsb_socketio.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_socketio.cpp; sourceTree = "<group>"; };
|
||||
1A159D4F1F13216F00558E38 /* jsb_socketio.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_socketio.hpp; sourceTree = "<group>"; };
|
||||
1A4E8E801F00CB0200F30872 /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
|
||||
1A4E8E821F00E84C00F30872 /* libChakraCoreStatic.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libChakraCoreStatic.a; path = ../../../../../ChakraCore/out/Debug/lib/libChakraCoreStatic.a; sourceTree = "<group>"; };
|
||||
1A210D921F456821006CCBAE /* MappingUtils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MappingUtils.cpp; sourceTree = "<group>"; };
|
||||
1A210D931F456821006CCBAE /* MappingUtils.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = MappingUtils.hpp; sourceTree = "<group>"; };
|
||||
1A210DDE1F46C2D3006CCBAE /* libjs_static.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libjs_static.a; path = ../../../../external/ios/libs/libjs_static.a; sourceTree = "<group>"; };
|
||||
1A210DDF1F46C2D3006CCBAE /* libmozglue.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libmozglue.a; path = ../../../../external/ios/libs/libmozglue.a; sourceTree = "<group>"; };
|
||||
1A210DE21F46C2DF006CCBAE /* libjs_static.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libjs_static.a; path = ../../../../external/mac/libs/libjs_static.a; sourceTree = "<group>"; };
|
||||
1A210DE31F46C2DF006CCBAE /* libmozglue.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libmozglue.a; path = ../../../../external/mac/libs/libmozglue.a; sourceTree = "<group>"; };
|
||||
1A5410A418B785A10016A3AF /* libjscocos2d Mac.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libjscocos2d Mac.a"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
1A5410A518B785A10016A3AF /* libjscocos2d iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libjscocos2d iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
1A5F22881F0DDD6B0008BF09 /* jsb_dragonbones_manual.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_dragonbones_manual.cpp; sourceTree = "<group>"; };
|
||||
@@ -284,14 +291,6 @@
|
||||
1A5F229B1F0E37B20008BF09 /* jsb_creator_manual.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_creator_manual.hpp; sourceTree = "<group>"; };
|
||||
1A6293EE1F44128300A07B77 /* BaseJSAction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BaseJSAction.cpp; sourceTree = "<group>"; };
|
||||
1A6293EF1F44128300A07B77 /* BaseJSAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseJSAction.h; sourceTree = "<group>"; };
|
||||
1A62FCAA1F282DDA0002E38C /* libbmalloc.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libbmalloc.a; path = "../../../../../JavaScriptCore/build-osx/lib/libbmalloc.a"; sourceTree = "<group>"; };
|
||||
1A62FCAB1F282DDA0002E38C /* libJavaScriptCore.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libJavaScriptCore.a; path = "../../../../../JavaScriptCore/build-osx/lib/libJavaScriptCore.a"; sourceTree = "<group>"; };
|
||||
1A62FCAC1F282DDA0002E38C /* libWTF.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libWTF.a; path = "../../../../../JavaScriptCore/build-osx/lib/libWTF.a"; sourceTree = "<group>"; };
|
||||
1A62FCAD1F282DDA0002E38C /* libbmalloc.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libbmalloc.a; path = "../../../../../JavaScriptCore/build-osx/lib/libbmalloc.a"; sourceTree = "<group>"; };
|
||||
1A62FCAE1F282DDA0002E38C /* libJavaScriptCore.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libJavaScriptCore.a; path = "../../../../../JavaScriptCore/build-osx/lib/libJavaScriptCore.a"; sourceTree = "<group>"; };
|
||||
1A62FCAF1F282DDA0002E38C /* libWTF.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libWTF.a; path = "../../../../../JavaScriptCore/build-osx/lib/libWTF.a"; sourceTree = "<group>"; };
|
||||
1A62FCB01F282DDB0002E38C /* libJavaScriptCore.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libJavaScriptCore.a; path = "../../../../../JavaScriptCore/build-osx/lib/libJavaScriptCore.a"; sourceTree = "<group>"; };
|
||||
1A62FCB11F282DDB0002E38C /* libbmalloc.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libbmalloc.a; path = "../../../../../JavaScriptCore/build-osx/lib/libbmalloc.a"; sourceTree = "<group>"; };
|
||||
1A6B8FB11F3BF7E800BC83DC /* SHA1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SHA1.cpp; sourceTree = "<group>"; };
|
||||
1A6B8FB21F3BF7E800BC83DC /* SHA1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SHA1.h; sourceTree = "<group>"; };
|
||||
1A7759C11F340FB10012A210 /* inspector_agent.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = inspector_agent.cc; sourceTree = "<group>"; };
|
||||
@@ -314,30 +313,14 @@
|
||||
1A7759F41F3421B90012A210 /* node.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = node.cc; sourceTree = "<group>"; };
|
||||
1A7759F51F3421B90012A210 /* node.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = node.h; sourceTree = "<group>"; };
|
||||
1A7759FA1F3460BB0012A210 /* node_mutex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = node_mutex.h; sourceTree = "<group>"; };
|
||||
1A7759FD1F3467990012A210 /* libuv.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libuv.a; path = ../../../../external/mac/libs/libuv.a; sourceTree = "<group>"; };
|
||||
1A7759FF1F346A090012A210 /* libinspector.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libinspector.a; path = ../../../../external/mac/libs/libinspector.a; sourceTree = "<group>"; };
|
||||
1A81B41C1F137BFE008C38F8 /* JavaScriptObjCBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaScriptObjCBridge.h; sourceTree = "<group>"; };
|
||||
1A81B41D1F137BFE008C38F8 /* JavaScriptObjCBridge.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = JavaScriptObjCBridge.mm; sourceTree = "<group>"; };
|
||||
1A81B4221F149E7B008C38F8 /* jsb_module_register.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_module_register.cpp; sourceTree = "<group>"; };
|
||||
1A81B4231F149E7B008C38F8 /* jsb_module_register.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_module_register.hpp; sourceTree = "<group>"; };
|
||||
1A8D25531F3AB432002CC0A8 /* libv8_builtins_generators.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libv8_builtins_generators.a; path = ../../../../external/mac/libs/libv8_builtins_generators.a; sourceTree = "<group>"; };
|
||||
1A8D25541F3AB432002CC0A8 /* libv8_builtins_setup.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libv8_builtins_setup.a; path = ../../../../external/mac/libs/libv8_builtins_setup.a; sourceTree = "<group>"; };
|
||||
1A9F0F9B1F30235C00A499E1 /* jsb_helper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_helper.cpp; sourceTree = "<group>"; };
|
||||
1A9F0F9C1F30235C00A499E1 /* jsb_helper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_helper.hpp; sourceTree = "<group>"; };
|
||||
1AB064771EF9647F0061E1AF /* libbmalloc.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libbmalloc.a; path = ../../../../../JavaScriptCore/build/lib/libbmalloc.a; sourceTree = "<group>"; };
|
||||
1AB064781EF9647F0061E1AF /* libJavaScriptCore.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libJavaScriptCore.a; path = ../../../../../JavaScriptCore/build/lib/libJavaScriptCore.a; sourceTree = "<group>"; };
|
||||
1AB064791EF9647F0061E1AF /* libWTF.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libWTF.a; path = ../../../../../JavaScriptCore/build/lib/libWTF.a; sourceTree = "<group>"; };
|
||||
1AB5E62918D05BC80088DAA4 /* jsb_cocos2dx_ui_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_cocos2dx_ui_auto.cpp; sourceTree = "<group>"; };
|
||||
1AB5E62A18D05BC80088DAA4 /* jsb_cocos2dx_ui_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_cocos2dx_ui_auto.hpp; sourceTree = "<group>"; };
|
||||
1AB649FC1F035628000C28A7 /* libv8_base.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libv8_base.a; path = ../../../../external/mac/libs/libv8_base.a; sourceTree = "<group>"; };
|
||||
1AB649FD1F035628000C28A7 /* libv8_libbase.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libv8_libbase.a; path = ../../../../external/mac/libs/libv8_libbase.a; sourceTree = "<group>"; };
|
||||
1AB649FE1F035628000C28A7 /* libv8_libplatform.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libv8_libplatform.a; path = ../../../../external/mac/libs/libv8_libplatform.a; sourceTree = "<group>"; };
|
||||
1AB649FF1F035628000C28A7 /* libv8_libsampler.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libv8_libsampler.a; path = ../../../../external/mac/libs/libv8_libsampler.a; sourceTree = "<group>"; };
|
||||
1AB64A001F035628000C28A7 /* libv8_nosnapshot.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libv8_nosnapshot.a; path = ../../../../external/mac/libs/libv8_nosnapshot.a; sourceTree = "<group>"; };
|
||||
1AC065091F00A62A009EC214 /* libmozglue.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libmozglue.a; path = ../../../../external/ios/libs/libmozglue.a; sourceTree = "<group>"; };
|
||||
1AC0650B1F00A926009EC214 /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.3.sdk/System/Library/Frameworks/JavaScriptCore.framework; sourceTree = DEVELOPER_DIR; };
|
||||
1AD4AE5F1F0F88E400A823D8 /* libicui18n.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libicui18n.a; path = ../../../../../../../../usr/local/Cellar/icu4c/58.2/lib/libicui18n.a; sourceTree = "<group>"; };
|
||||
1AD4AE601F0F88E400A823D8 /* libicuuc.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libicuuc.a; path = ../../../../../../../../usr/local/Cellar/icu4c/58.2/lib/libicuuc.a; sourceTree = "<group>"; };
|
||||
1AD4AE651F0F920700A823D8 /* jsb_websocket.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_websocket.cpp; sourceTree = "<group>"; };
|
||||
1AD4AE661F0F920700A823D8 /* jsb_websocket.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_websocket.hpp; sourceTree = "<group>"; };
|
||||
1AF82D411F2EE1C20002C5A0 /* HandleObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HandleObject.cpp; sourceTree = "<group>"; };
|
||||
@@ -415,7 +398,6 @@
|
||||
1AFD36BF1EF116190097DBB1 /* jsb_xmlhttprequest.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_xmlhttprequest.hpp; sourceTree = "<group>"; };
|
||||
1AFD36C01EF116190097DBB1 /* ScriptingCore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptingCore.cpp; sourceTree = "<group>"; };
|
||||
1AFD36C11EF116190097DBB1 /* ScriptingCore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptingCore.h; sourceTree = "<group>"; };
|
||||
1AFD37031EF116CB0097DBB1 /* libmozglue.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libmozglue.a; path = ../../../../external/mac/libs/libmozglue.a; sourceTree = "<group>"; };
|
||||
4BE089E01ADF965E00D65D4B /* jsb_cocos2dx_experimental_webView_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_cocos2dx_experimental_webView_auto.cpp; sourceTree = "<group>"; };
|
||||
4BE089E11ADF965E00D65D4B /* jsb_cocos2dx_experimental_webView_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_cocos2dx_experimental_webView_auto.hpp; sourceTree = "<group>"; };
|
||||
4BE089EA1ADF967400D65D4B /* jsb_cocos2dx_experimental_webView_manual.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jsb_cocos2dx_experimental_webView_manual.h; sourceTree = "<group>"; };
|
||||
@@ -438,6 +420,8 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
1A210DE41F46C2DF006CCBAE /* libjs_static.a in Frameworks */,
|
||||
1A210DE51F46C2DF006CCBAE /* libmozglue.a in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -445,8 +429,8 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
1AC0650C1F00A926009EC214 /* JavaScriptCore.framework in Frameworks */,
|
||||
1AC0650A1F00A62A009EC214 /* libmozglue.a in Frameworks */,
|
||||
1A210DE01F46C2D3006CCBAE /* libjs_static.a in Frameworks */,
|
||||
1A210DE11F46C2D3006CCBAE /* libmozglue.a in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -557,6 +541,8 @@
|
||||
1AFD36331EF115100097DBB1 /* Value.hpp */,
|
||||
1AF82D411F2EE1C20002C5A0 /* HandleObject.cpp */,
|
||||
1AF82D421F2EE1C20002C5A0 /* HandleObject.hpp */,
|
||||
1A210D921F456821006CCBAE /* MappingUtils.cpp */,
|
||||
1A210D931F456821006CCBAE /* MappingUtils.hpp */,
|
||||
);
|
||||
name = jswrapper;
|
||||
path = ../jswrapper;
|
||||
@@ -661,36 +647,10 @@
|
||||
1AFD37021EF116CA0097DBB1 /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
1A8D25531F3AB432002CC0A8 /* libv8_builtins_generators.a */,
|
||||
1A8D25541F3AB432002CC0A8 /* libv8_builtins_setup.a */,
|
||||
1A7759FF1F346A090012A210 /* libinspector.a */,
|
||||
1A7759FD1F3467990012A210 /* libuv.a */,
|
||||
1A62FCB11F282DDB0002E38C /* libbmalloc.a */,
|
||||
1A62FCB01F282DDB0002E38C /* libJavaScriptCore.a */,
|
||||
1A62FCAD1F282DDA0002E38C /* libbmalloc.a */,
|
||||
1A62FCAE1F282DDA0002E38C /* libJavaScriptCore.a */,
|
||||
1A62FCAF1F282DDA0002E38C /* libWTF.a */,
|
||||
1A62FCAA1F282DDA0002E38C /* libbmalloc.a */,
|
||||
1A62FCAB1F282DDA0002E38C /* libJavaScriptCore.a */,
|
||||
1A62FCAC1F282DDA0002E38C /* libWTF.a */,
|
||||
1A10510D1F14CB4000D4322C /* libjs_static.a */,
|
||||
1A1051061F14C0B600D4322C /* libjs_static.a */,
|
||||
1A1051071F14C0B600D4322C /* libmozglue.a */,
|
||||
1AD4AE5F1F0F88E400A823D8 /* libicui18n.a */,
|
||||
1AD4AE601F0F88E400A823D8 /* libicuuc.a */,
|
||||
1AB649FC1F035628000C28A7 /* libv8_base.a */,
|
||||
1AB649FD1F035628000C28A7 /* libv8_libbase.a */,
|
||||
1AB649FE1F035628000C28A7 /* libv8_libplatform.a */,
|
||||
1AB649FF1F035628000C28A7 /* libv8_libsampler.a */,
|
||||
1AB64A001F035628000C28A7 /* libv8_nosnapshot.a */,
|
||||
1A4E8E821F00E84C00F30872 /* libChakraCoreStatic.a */,
|
||||
1A4E8E801F00CB0200F30872 /* JavaScriptCore.framework */,
|
||||
1AC0650B1F00A926009EC214 /* JavaScriptCore.framework */,
|
||||
1AC065091F00A62A009EC214 /* libmozglue.a */,
|
||||
1AB064771EF9647F0061E1AF /* libbmalloc.a */,
|
||||
1AB064781EF9647F0061E1AF /* libJavaScriptCore.a */,
|
||||
1AB064791EF9647F0061E1AF /* libWTF.a */,
|
||||
1AFD37031EF116CB0097DBB1 /* libmozglue.a */,
|
||||
1A210DE21F46C2DF006CCBAE /* libjs_static.a */,
|
||||
1A210DE31F46C2DF006CCBAE /* libmozglue.a */,
|
||||
1A210DDE1F46C2D3006CCBAE /* libjs_static.a */,
|
||||
1A210DDF1F46C2D3006CCBAE /* libmozglue.a */,
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
@@ -705,6 +665,7 @@
|
||||
4DFA4C121CBCC49000E3B736 /* jsb_creator_auto.hpp in Headers */,
|
||||
1AFD365C1EF115100097DBB1 /* SeApi.h in Headers */,
|
||||
1AFD36961EF115100097DBB1 /* ScriptEngine.hpp in Headers */,
|
||||
1A210D961F456821006CCBAE /* MappingUtils.hpp in Headers */,
|
||||
1AFD36C81EF116190097DBB1 /* jsb_classtype.hpp in Headers */,
|
||||
1AFD36881EF115100097DBB1 /* Class.hpp in Headers */,
|
||||
1AFD36441EF115100097DBB1 /* SeApi.h in Headers */,
|
||||
@@ -796,6 +757,7 @@
|
||||
1AFD36D51EF116190097DBB1 /* jsb_conversions.hpp in Headers */,
|
||||
1AFD36C91EF116190097DBB1 /* jsb_classtype.hpp in Headers */,
|
||||
1AFD36351EF115100097DBB1 /* Base.h in Headers */,
|
||||
1A210D971F456821006CCBAE /* MappingUtils.hpp in Headers */,
|
||||
1AFD36931EF115100097DBB1 /* ObjectWrap.h in Headers */,
|
||||
1AFD36D11EF116190097DBB1 /* jsb_cocos2dx_manual.hpp in Headers */,
|
||||
1AFD36711EF115100097DBB1 /* HelperMacros.h in Headers */,
|
||||
@@ -977,6 +939,7 @@
|
||||
BA4F59841E28DCD3003F5096 /* jsb_cocos2dx_network_auto.cpp in Sources */,
|
||||
1A7759DB1F34105B0012A210 /* node_debug_options.cc in Sources */,
|
||||
1AFD36461EF115100097DBB1 /* Utils.cpp in Sources */,
|
||||
1A210D941F456821006CCBAE /* MappingUtils.cpp in Sources */,
|
||||
1A5F22961F0E306C0008BF09 /* jsb_box2d_manual.cpp in Sources */,
|
||||
1A7759F01F341D6E0012A210 /* env.cc in Sources */,
|
||||
1A7759D51F340FB10012A210 /* inspector_socket.cc in Sources */,
|
||||
@@ -1012,6 +975,7 @@
|
||||
1AB5E62C18D05BC80088DAA4 /* jsb_cocos2dx_ui_auto.cpp in Sources */,
|
||||
1AFD36651EF115100097DBB1 /* Ref.cpp in Sources */,
|
||||
BA4F59851E28DCD3003F5096 /* jsb_cocos2dx_network_auto.cpp in Sources */,
|
||||
1A210D951F456821006CCBAE /* MappingUtils.cpp in Sources */,
|
||||
1A119E9C18BDF19200352BAA /* jsb_cocos2dx_spine_auto.cpp in Sources */,
|
||||
1A5F22971F0E306C0008BF09 /* jsb_box2d_manual.cpp in Sources */,
|
||||
1AFD36C71EF116190097DBB1 /* jsb_classtype.cpp in Sources */,
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
<ClCompile Include="..\auto\jsb_cocos2dx_ui_auto.cpp" />
|
||||
<ClCompile Include="..\auto\jsb_creator_auto.cpp" />
|
||||
<ClCompile Include="..\jswrapper\HandleObject.cpp" />
|
||||
<ClCompile Include="..\jswrapper\MappingUtils.cpp" />
|
||||
<ClCompile Include="..\jswrapper\Ref.cpp" />
|
||||
<ClCompile Include="..\jswrapper\State.cpp" />
|
||||
<ClCompile Include="..\jswrapper\v8\Class.cpp" />
|
||||
@@ -56,6 +57,7 @@
|
||||
<ClCompile Include="..\jswrapper\v8\util.cc" />
|
||||
<ClCompile Include="..\jswrapper\v8\Utils.cpp" />
|
||||
<ClCompile Include="..\jswrapper\Value.cpp" />
|
||||
<ClCompile Include="..\manual\BaseJSAction.cpp" />
|
||||
<ClCompile Include="..\manual\jsb_box2d_manual.cpp" />
|
||||
<ClCompile Include="..\manual\jsb_classtype.cpp" />
|
||||
<ClCompile Include="..\manual\jsb_cocos2dx_extension_manual.cpp" />
|
||||
@@ -87,6 +89,7 @@
|
||||
<ClInclude Include="..\auto\jsb_creator_auto.hpp" />
|
||||
<ClInclude Include="..\jswrapper\config.hpp" />
|
||||
<ClInclude Include="..\jswrapper\HandleObject.hpp" />
|
||||
<ClInclude Include="..\jswrapper\MappingUtils.hpp" />
|
||||
<ClInclude Include="..\jswrapper\Object.hpp" />
|
||||
<ClInclude Include="..\jswrapper\Ref.hpp" />
|
||||
<ClInclude Include="..\jswrapper\SeApi.h" />
|
||||
@@ -114,6 +117,7 @@
|
||||
<ClInclude Include="..\jswrapper\v8\Utils.hpp" />
|
||||
<ClInclude Include="..\jswrapper\v8\v8_inspector_protocol_json.h" />
|
||||
<ClInclude Include="..\jswrapper\Value.hpp" />
|
||||
<ClInclude Include="..\manual\BaseJSAction.h" />
|
||||
<ClInclude Include="..\manual\jsb_box2d_manual.hpp" />
|
||||
<ClInclude Include="..\manual\jsb_classtype.hpp" />
|
||||
<ClInclude Include="..\manual\jsb_cocos2dx_extension_manual.hpp" />
|
||||
|
||||
@@ -155,6 +155,12 @@
|
||||
<ClCompile Include="..\jswrapper\v8\SHA1.cpp">
|
||||
<Filter>jswrapper\v8</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\jswrapper\MappingUtils.cpp">
|
||||
<Filter>jswrapper</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\manual\BaseJSAction.cpp">
|
||||
<Filter>manual</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\auto\jsb_cocos2dx_auto.hpp">
|
||||
@@ -325,5 +331,11 @@
|
||||
<ClInclude Include="..\jswrapper\v8\SHA1.h">
|
||||
<Filter>jswrapper\v8</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\jswrapper\MappingUtils.hpp">
|
||||
<Filter>jswrapper</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\manual\BaseJSAction.h">
|
||||
<Filter>manual</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
using namespace anysdk::framework;
|
||||
|
||||
SDKManager* SDKManager::_pInstance = NULL;
|
||||
SDKManager* SDKManager::_pInstance = nullptr;
|
||||
|
||||
SDKManager::SDKManager()
|
||||
{
|
||||
@@ -10,12 +10,13 @@ SDKManager::SDKManager()
|
||||
|
||||
SDKManager::~SDKManager()
|
||||
{
|
||||
_pAgent->unloadAllPlugins();
|
||||
AgentManager::getInstance()->unloadAllPlugins();
|
||||
AgentManager::end();
|
||||
}
|
||||
|
||||
SDKManager* SDKManager::getInstance()
|
||||
{
|
||||
if (_pInstance == NULL) {
|
||||
if (_pInstance == nullptr) {
|
||||
_pInstance = new SDKManager();
|
||||
}
|
||||
return _pInstance;
|
||||
@@ -23,10 +24,10 @@ SDKManager* SDKManager::getInstance()
|
||||
|
||||
void SDKManager::purge()
|
||||
{
|
||||
if (_pInstance)
|
||||
if (_pInstance != nullptr)
|
||||
{
|
||||
delete _pInstance;
|
||||
_pInstance = NULL;
|
||||
_pInstance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
#define __SDK_MANAGER_H__
|
||||
|
||||
#include "AgentManager.h"
|
||||
using namespace anysdk::framework;
|
||||
using namespace std;
|
||||
|
||||
class SDKManager
|
||||
{
|
||||
public:
|
||||
@@ -17,8 +16,6 @@ private:
|
||||
virtual ~SDKManager();
|
||||
|
||||
static SDKManager* _pInstance;
|
||||
|
||||
AgentManager* _pAgent;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef __JS_BASIC_CONVERSIONS_H__
|
||||
#define __JS_BASIC_CONVERSIONS_H__
|
||||
#pragma once
|
||||
|
||||
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
|
||||
|
||||
@@ -11,12 +10,6 @@
|
||||
#include "ProtocolUser.h"
|
||||
#include "ProtocolREC.h"
|
||||
|
||||
#ifndef CCLOGINFO
|
||||
#define CCLOGINFO(...)
|
||||
#endif
|
||||
|
||||
// to native
|
||||
bool seval_to_TVideoInfo(const se::Value& v, anysdk::framework::TVideoInfo* ret);
|
||||
|
||||
|
||||
#endif /* __JS_ANYSDK_CONVERSIONS_H__ */
|
||||
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "v3-deps-38",
|
||||
"version": "v3-deps-41",
|
||||
"zip_file_size": "114318593",
|
||||
"repo_name": "cocos2d-x-lite-external",
|
||||
"repo_parent": "https://github.com/cocos-creator/"
|
||||
|
||||
@@ -74,13 +74,7 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||
ScriptEngineManager::getInstance()->setScriptEngine(sc);
|
||||
|
||||
se::ScriptEngine* se = se::ScriptEngine::getInstance();
|
||||
if (!se->isValid())
|
||||
{
|
||||
CCLOGERROR("Unable to Initialize se::ScriptEngine.");
|
||||
return false;
|
||||
}
|
||||
|
||||
se::AutoHandleScope hs;
|
||||
jsb_register_all_modules();
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && PACKAGE_AS
|
||||
|
||||
+10
-1
@@ -39,10 +39,14 @@ using namespace cocos2d;
|
||||
#pragma mark Application lifecycle
|
||||
|
||||
// cocos2d application instance
|
||||
static AppDelegate s_sharedApplication;
|
||||
static AppDelegate* s_sharedApplication = nullptr;
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
|
||||
if (s_sharedApplication == nullptr)
|
||||
{
|
||||
s_sharedApplication = new (std::nothrow) AppDelegate();
|
||||
}
|
||||
cocos2d::Application *app = cocos2d::Application::getInstance();
|
||||
|
||||
// Initialize the GLView attributes
|
||||
@@ -127,6 +131,11 @@ static AppDelegate s_sharedApplication;
|
||||
Called when the application is about to terminate.
|
||||
See also applicationDidEnterBackground:.
|
||||
*/
|
||||
if (s_sharedApplication != nullptr)
|
||||
{
|
||||
delete s_sharedApplication;
|
||||
s_sharedApplication = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -74,13 +74,7 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||
ScriptEngineManager::getInstance()->setScriptEngine(sc);
|
||||
|
||||
se::ScriptEngine* se = se::ScriptEngine::getInstance();
|
||||
if (!se->isValid())
|
||||
{
|
||||
CCLOGERROR("Unable to Initialize se::ScriptEngine.");
|
||||
return false;
|
||||
}
|
||||
|
||||
se::AutoHandleScope hs;
|
||||
jsb_register_all_modules();
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && PACKAGE_AS
|
||||
|
||||
+11
-1
@@ -39,10 +39,14 @@ using namespace cocos2d;
|
||||
#pragma mark Application lifecycle
|
||||
|
||||
// cocos2d application instance
|
||||
static AppDelegate s_sharedApplication;
|
||||
static AppDelegate* s_sharedApplication = nullptr;
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
|
||||
if (s_sharedApplication == nullptr)
|
||||
{
|
||||
s_sharedApplication = new (std::nothrow) AppDelegate();
|
||||
}
|
||||
cocos2d::Application *app = cocos2d::Application::getInstance();
|
||||
|
||||
// Initialize the GLView attributes
|
||||
@@ -127,6 +131,12 @@ static AppDelegate s_sharedApplication;
|
||||
Called when the application is about to terminate.
|
||||
See also applicationDidEnterBackground:.
|
||||
*/
|
||||
|
||||
if (s_sharedApplication != nullptr)
|
||||
{
|
||||
delete s_sharedApplication;
|
||||
s_sharedApplication = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -74,13 +74,7 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||
ScriptEngineManager::getInstance()->setScriptEngine(sc);
|
||||
|
||||
se::ScriptEngine* se = se::ScriptEngine::getInstance();
|
||||
if (!se->isValid())
|
||||
{
|
||||
CCLOGERROR("Unable to Initialize se::ScriptEngine.");
|
||||
return false;
|
||||
}
|
||||
|
||||
se::AutoHandleScope hs;
|
||||
jsb_register_all_modules();
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && PACKAGE_AS
|
||||
|
||||
+10
-1
@@ -39,10 +39,14 @@ using namespace cocos2d;
|
||||
#pragma mark Application lifecycle
|
||||
|
||||
// cocos2d application instance
|
||||
static AppDelegate s_sharedApplication;
|
||||
static AppDelegate* s_sharedApplication = nullptr;
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
|
||||
if (s_sharedApplication == nullptr)
|
||||
{
|
||||
s_sharedApplication = new (std::nothrow) AppDelegate();
|
||||
}
|
||||
cocos2d::Application *app = cocos2d::Application::getInstance();
|
||||
|
||||
// Initialize the GLView attributes
|
||||
@@ -127,6 +131,11 @@ static AppDelegate s_sharedApplication;
|
||||
Called when the application is about to terminate.
|
||||
See also applicationDidEnterBackground:.
|
||||
*/
|
||||
if (s_sharedApplication != nullptr)
|
||||
{
|
||||
delete s_sharedApplication;
|
||||
s_sharedApplication = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Submodule native/tools/bindings-generator updated: 74c5788646...b79c709ab5
Reference in New Issue
Block a user