Merge pull request #794 from dumganhar/jsb2.0

More renames: gc -> garbageCollect, isInGC -> isGarbageCollecting, _setInGC -> _setGarbageCollecting
This commit is contained in:
pandamicro
2017-08-31 17:19:08 +08:00
committed by GitHub
19 changed files with 65 additions and 65 deletions
@@ -41,14 +41,14 @@
if (nativeThisObject != nullptr) \
{ \
auto se = se::ScriptEngine::getInstance(); \
se->_setInGC(true); \
se->_setGarbageCollecting(true); \
bool ret = false; \
se::State state(nativeThisObject); \
se::Object* _thisObject = state.thisObject(); \
if (_thisObject) _thisObject->_cleanup(nativeThisObject); \
ret = funcName(state); \
SAFE_DEC_REF(_thisObject); \
se->_setInGC(false); \
se->_setGarbageCollecting(false); \
} \
}
@@ -166,7 +166,7 @@ namespace se {
{
// Don't unprotect if it's in cleanup, otherwise, it will trigger crash.
auto se = ScriptEngine::getInstance();
if (!se->isInCleanup() && !se->isInGC())
if (!se->isInCleanup() && !se->isGarbageCollecting())
{
unsigned int count = 0;
_CHECK(JsRelease(_obj, &count));
@@ -576,7 +576,7 @@ namespace se {
{
// Don't unprotect if it's in cleanup, otherwise, it will trigger crash.
auto se = ScriptEngine::getInstance();
if (!se->isInCleanup() && !se->isInGC())
if (!se->isInCleanup() && !se->isGarbageCollecting())
{
unsigned int count = 0;
_CHECK(JsRelease(_obj, &count));
@@ -16,7 +16,7 @@ namespace se {
JsValueRef __forceGC(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState)
{
ScriptEngine::getInstance()->gc();
ScriptEngine::getInstance()->garbageCollect();
return JS_INVALID_REFERENCE;
}
@@ -72,7 +72,7 @@ namespace se {
, _globalObj(nullptr)
, _isValid(false)
, _isInCleanup(false)
, _isInGC(false)
, _isGarbageCollecting(false)
, _currentSourceContext(0)
{
}
@@ -144,7 +144,7 @@ namespace se {
SAFE_DEC_REF(_globalObj);
Object::cleanup();
Class::cleanup();
gc();
garbageCollect();
_CHECK(JsSetCurrentContext(JS_INVALID_REFERENCE));
_CHECK(JsDisposeRuntime(_rt));
@@ -272,17 +272,17 @@ namespace se {
return ok;
}
bool ScriptEngine::isInGC()
bool ScriptEngine::isGarbageCollecting()
{
return _isInGC;
return _isGarbageCollecting;
}
void ScriptEngine::_setInGC(bool isInGC)
void ScriptEngine::_setGarbageCollecting(bool isGarbageCollecting)
{
_isInGC = isInGC;
_isGarbageCollecting = isGarbageCollecting;
}
void ScriptEngine::gc()
void ScriptEngine::garbageCollect()
{
LOGD("GC begin ..., (Native -> JS map) count: %d\n", (int)NativePtrToObjectMap::size());
_CHECK(JsCollectGarbage(_rt));
@@ -106,9 +106,9 @@ namespace se {
*/
bool runScript(const std::string& path, Value* ret = nullptr);
bool isInGC();
void _setInGC(bool isInGC);
void gc();
bool isGarbageCollecting();
void _setGarbageCollecting(bool isGarbageCollecting);
void garbageCollect();
bool isValid() { return _isValid; }
bool isInCleanup() { return _isInCleanup; }
@@ -142,7 +142,7 @@ namespace se {
bool _isValid;
bool _isInCleanup;
bool _isInGC;
bool _isGarbageCollecting;
unsigned _currentSourceContext;
NodeEventListener _nodeEventListener;
@@ -41,7 +41,7 @@
void funcName##Registry(JSObjectRef _obj) \
{ \
auto se = se::ScriptEngine::getInstance(); \
se->_setInGC(true); \
se->_setGarbageCollecting(true); \
void* nativeThisObject = JSObjectGetPrivate(_obj); \
if (nativeThisObject != nullptr) \
{ \
@@ -53,7 +53,7 @@
JSObjectSetPrivate(_obj, nullptr); \
SAFE_DEC_REF(_thisObject); \
} \
se->_setInGC(false); \
se->_setGarbageCollecting(false); \
}
#define SE_DECLARE_FINALIZE_FUNC(funcName) \
@@ -177,7 +177,7 @@ namespace se {
// printf("Object::_cleanup, (%p) rootCount: %u\n", this, _rootCount);
// Don't unprotect if it's in cleanup, otherwise, it will trigger crash.
auto se = ScriptEngine::getInstance();
if (!se->isInCleanup() && !se->isInGC())
if (!se->isInCleanup() && !se->isGarbageCollecting())
JSValueUnprotect(__cx, _obj);
_rootCount = 0;
@@ -561,7 +561,7 @@ namespace se {
{
// Don't unprotect if it's in cleanup, otherwise, it will trigger crash.
auto se = ScriptEngine::getInstance();
if (!se->isInCleanup() && !se->isInGC())
if (!se->isInCleanup() && !se->isGarbageCollecting())
JSValueUnprotect(__cx, _obj);
}
}
@@ -83,7 +83,7 @@ namespace se {
ScriptEngine::ScriptEngine()
: _cx(nullptr)
, _globalObj(nullptr)
, _isInGC(false)
, _isGarbageCollecting(false)
, _isValid(false)
, _isInCleanup(false)
{
@@ -169,7 +169,7 @@ namespace se {
SAFE_DEC_REF(_globalObj);
Object::cleanup();
Class::cleanup();
gc();
garbageCollect();
JSGlobalContextRelease(_cx);
@@ -243,14 +243,14 @@ namespace se {
}
}
bool ScriptEngine::isInGC()
bool ScriptEngine::isGarbageCollecting()
{
return _isInGC;
return _isGarbageCollecting;
}
void ScriptEngine::_setInGC(bool isInGC)
void ScriptEngine::_setGarbageCollecting(bool isGarbageCollecting)
{
_isInGC = isInGC;
_isGarbageCollecting = isGarbageCollecting;
}
Object* ScriptEngine::getGlobalObject()
@@ -305,7 +305,7 @@ namespace se {
return ok;
}
void ScriptEngine::gc()
void ScriptEngine::garbageCollect()
{
LOGD("GC begin ..., (Native -> JS map) count: %d\n", (int)NativePtrToObjectMap::size());
// JSGarbageCollect(_cx);
@@ -388,7 +388,7 @@ namespace se {
return evalString(scriptBuffer.c_str(), scriptBuffer.length(), ret, path.c_str());
}
LOGE("ScriptEngine::runScript script buffer is empty!\n");
LOGE("ScriptEngine::runScript script %s, buffer is empty!\n", path.c_str());
return false;
}
@@ -170,12 +170,12 @@ namespace se {
* @brief Tests whether script engine is doing garbage collection.
* @return true if it's in garbage collection, otherwise false.
*/
bool isInGC();
bool isGarbageCollecting();
/**
* @brief Performs a JavaScript garbage collection.
*/
void gc();
void garbageCollect();
/**
* @brief Tests whether script engine is being cleaned up.
@@ -220,7 +220,7 @@ namespace se {
JSContextRef _getContext() const { return _cx; }
void _setInGC(bool isInGC);
void _setGarbageCollecting(bool isGarbageCollecting);
//
private:
@@ -231,7 +231,7 @@ namespace se {
Object* _globalObj;
bool _isInGC;
bool _isGarbageCollecting;
bool _isValid;
bool _isInCleanup;
NodeEventListener _nodeEventListener;
@@ -101,13 +101,13 @@ namespace se {
* garbage collected. */
if (status == JSGC_BEGIN)
{
ScriptEngine::getInstance()->_setInGC(true);
ScriptEngine::getInstance()->_setGarbageCollecting(true);
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());
ScriptEngine::getInstance()->_setInGC(false);
ScriptEngine::getInstance()->_setGarbageCollecting(false);
}
}
@@ -226,7 +226,7 @@ namespace se {
: _cx(nullptr)
, _globalObj(nullptr)
, _oldCompartment(nullptr)
, _isInGC(false)
, _isGarbageCollecting(false)
, _isValid(false)
, _isInCleanup(false)
, _nodeEventListener(nullptr)
@@ -462,14 +462,14 @@ namespace se {
_afterInitHookArray.push_back(hook);
}
bool ScriptEngine::isInGC()
bool ScriptEngine::isGarbageCollecting()
{
return _isInGC;
return _isGarbageCollecting;
}
void ScriptEngine::_setInGC(bool isInGC)
void ScriptEngine::_setGarbageCollecting(bool isGarbageCollecting)
{
_isInGC = isInGC;
_isGarbageCollecting = isGarbageCollecting;
}
Object* ScriptEngine::getGlobalObject()
@@ -92,9 +92,9 @@ namespace se {
JSContext* _getContext() { return _cx; }
bool isInGC();
void _setInGC(bool isInGC);
void gc() { JS_GC( _cx ); }
bool isGarbageCollecting();
void _setGarbageCollecting(bool isGarbageCollecting);
void garbageCollect() { JS_GC( _cx ); }
bool isValid() { return _isValid; }
bool isInCleanup() { return _isInCleanup; }
@@ -131,7 +131,7 @@ namespace se {
Object* _globalObj;
bool _isInGC;
bool _isGarbageCollecting;
bool _isValid;
bool _isInCleanup;
NodeEventListener _nodeEventListener;
@@ -40,10 +40,10 @@
if (nativeThisObject == nullptr) \
return; \
auto se = se::ScriptEngine::getInstance(); \
se->_setInGC(true); \
se->_setGarbageCollecting(true); \
se::State state(nativeThisObject); \
SE_UNUSED bool ok = funcName(state); \
se->_setInGC(false); \
se->_setGarbageCollecting(false); \
}
#define SE_DECLARE_FINALIZE_FUNC(funcName) \
@@ -41,7 +41,7 @@ namespace se {
void __forceGC(const v8::FunctionCallbackInfo<v8::Value>& info)
{
ScriptEngine::getInstance()->gc();
ScriptEngine::getInstance()->garbageCollect();
}
void myFatalErrorCallback(const char* location, const char* message)
@@ -114,7 +114,7 @@ namespace se {
, _allocator(nullptr)
, _globalObj(nullptr)
, _isValid(false)
, _isInGC(false)
, _isGarbageCollecting(false)
, _isInCleanup(false)
, _nodeEventListener(nullptr)
#if SE_ENABLE_INSPECTOR
@@ -228,7 +228,7 @@ namespace se {
SAFE_DEC_REF(_globalObj);
Object::cleanup();
Class::cleanup();
gc();
garbageCollect();
#if SE_ENABLE_INSPECTOR
_env->inspector_agent()->Stop();
@@ -320,7 +320,7 @@ namespace se {
return ok;
}
void ScriptEngine::gc()
void ScriptEngine::garbageCollect()
{
LOGD("GC begin ..., (js->native map) size: %d, all objects: %d\n", (int)NativePtrToObjectMap::size(), (int)__objectMap.size());
const double kLongIdlePauseInSeconds = 1.0;
@@ -333,14 +333,14 @@ namespace se {
LOGD("GC end ..., (js->native map) size: %d, all objects: %d\n", (int)NativePtrToObjectMap::size(), (int)__objectMap.size());
}
bool ScriptEngine::isInGC()
bool ScriptEngine::isGarbageCollecting()
{
return _isInGC;
return _isGarbageCollecting;
}
void ScriptEngine::_setInGC(bool isInGC)
void ScriptEngine::_setGarbageCollecting(bool isGarbageCollecting)
{
_isInGC = isInGC;
_isGarbageCollecting = isGarbageCollecting;
}
bool ScriptEngine::isValid() const
@@ -411,7 +411,7 @@ namespace se {
return evalString(scriptBuffer.c_str(), scriptBuffer.length(), ret, path.c_str());
}
LOGE("ScriptEngine::runScript script buffer is empty!\n");
LOGE("ScriptEngine::runScript script %s, buffer is empty!\n", path.c_str());
return false;
}
@@ -126,9 +126,9 @@ namespace se {
*/
bool runScript(const std::string& path, Value* ret = nullptr);
bool isInGC();
void _setInGC(bool isInGC);
void gc();
bool isGarbageCollecting();
void _setGarbageCollecting(bool isGarbageCollecting);
void garbageCollect();
bool isValid() const;
bool isInCleanup() { return _isInCleanup; }
@@ -169,7 +169,7 @@ namespace se {
Object* _globalObj;
bool _isValid;
bool _isInGC;
bool _isGarbageCollecting;
bool _isInCleanup;
NodeEventListener _nodeEventListener;
@@ -62,7 +62,7 @@ void ScriptingCore::rootScriptObject(Ref* target)
void ScriptingCore::releaseScriptObject(Ref* owner, Ref* target)
{
assert(!se::ScriptEngine::getInstance()->isInGC());
assert(!se::ScriptEngine::getInstance()->isGarbageCollecting());
se::ScriptEngine::getInstance()->_releaseScriptObject(owner, target);
}
@@ -1106,7 +1106,7 @@ bool register_all_box2d_manual(se::Object* obj)
}
};
if (!se::ScriptEngine::getInstance()->isInGC())
if (!se::ScriptEngine::getInstance()->isGarbageCollecting())
{
cleanup();
}
@@ -439,7 +439,7 @@ bool register_all_dragonbones_manual(se::Object* obj)
}
};
if (!se::ScriptEngine::getInstance()->isInGC())
if (!se::ScriptEngine::getInstance()->isGarbageCollecting())
{
cleanup();
}
@@ -466,7 +466,7 @@ namespace {
static bool jsc_garbageCollect(se::State& s)
{
se::ScriptEngine::getInstance()->gc();
se::ScriptEngine::getInstance()->garbageCollect();
return true;
}
SE_BIND_FUNC(jsc_garbageCollect)
@@ -67,9 +67,9 @@ bool jsb_register_all_modules()
});
se->addBeforeCleanupHook([se](){
se->gc();
se->garbageCollect();
PoolManager::getInstance()->getCurrentPool()->clear();
se->gc();
se->garbageCollect();
PoolManager::getInstance()->getCurrentPool()->clear();
});
@@ -298,7 +298,7 @@ static bool js_register_spine_TrackEntry(se::Object* obj)
}
};
if (!se::ScriptEngine::getInstance()->isInGC())
if (!se::ScriptEngine::getInstance()->isGarbageCollecting())
{
cleanup();
}