Permalink
Browse files

core, refactor: uniform the two constructor of AsyncCallback.

  • Loading branch information...
xicilion committed Nov 28, 2017
1 parent ff75686 commit c73b24caaf9d00a82736970f6530eedc14d2d28a
Showing with 31 additions and 33 deletions.
  1. +1 −8 fibjs/include/AsyncCall.h
  2. +20 −20 fibjs/include/object_async.inl
  3. +7 −3 fibjs/src/base/acPool.cpp
  4. +2 −1 fibjs/src/global/Timer.cpp
  5. +1 −1 tools/gen_stub.js
@@ -354,14 +354,7 @@ class _at<T*> {
class NType;
class AsyncCallBack : public AsyncEvent {
public:
AsyncCallBack(v8::Local<v8::Function> cb)
{
m_isolate = Isolate::current();
m_isolate->Ref();
m_cb.Reset(m_isolate->m_isolate, cb);
}
AsyncCallBack(object_base* pThis, v8::Local<v8::Function> cb);
AsyncCallBack(v8::Local<v8::Function> cb, object_base* pThis = NULL);
~AsyncCallBack()
{
@@ -76,7 +76,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb) \
AsyncCallBack(cb, pThis) \
{} \
virtual void invoke() \
{ \
@@ -182,7 +182,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb) \
AsyncCallBack(cb, pThis) \
{} \
virtual void invoke() \
{ \
@@ -291,7 +291,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, T0& v0, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb), m_v0(v0) \
AsyncCallBack(cb, pThis), m_v0(v0) \
{} \
virtual void invoke() \
{ \
@@ -401,7 +401,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, T0& v0, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb), m_v0(v0) \
AsyncCallBack(cb, pThis), m_v0(v0) \
{} \
virtual void invoke() \
{ \
@@ -512,7 +512,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, T0& v0, T1& v1, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb), m_v0(v0), m_v1(v1) \
AsyncCallBack(cb, pThis), m_v0(v0), m_v1(v1) \
{} \
virtual void invoke() \
{ \
@@ -624,7 +624,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, T0& v0, T1& v1, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb), m_v0(v0), m_v1(v1) \
AsyncCallBack(cb, pThis), m_v0(v0), m_v1(v1) \
{} \
virtual void invoke() \
{ \
@@ -737,7 +737,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, T0& v0, T1& v1, T2& v2, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb), m_v0(v0), m_v1(v1), m_v2(v2) \
AsyncCallBack(cb, pThis), m_v0(v0), m_v1(v1), m_v2(v2) \
{} \
virtual void invoke() \
{ \
@@ -851,7 +851,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, T0& v0, T1& v1, T2& v2, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb), m_v0(v0), m_v1(v1), m_v2(v2) \
AsyncCallBack(cb, pThis), m_v0(v0), m_v1(v1), m_v2(v2) \
{} \
virtual void invoke() \
{ \
@@ -966,7 +966,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, T0& v0, T1& v1, T2& v2, T3& v3, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3) \
AsyncCallBack(cb, pThis), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3) \
{} \
virtual void invoke() \
{ \
@@ -1082,7 +1082,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, T0& v0, T1& v1, T2& v2, T3& v3, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3) \
AsyncCallBack(cb, pThis), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3) \
{} \
virtual void invoke() \
{ \
@@ -1199,7 +1199,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, T0& v0, T1& v1, T2& v2, T3& v3, T4& v4, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4) \
AsyncCallBack(cb, pThis), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4) \
{} \
virtual void invoke() \
{ \
@@ -1317,7 +1317,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, T0& v0, T1& v1, T2& v2, T3& v3, T4& v4, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4) \
AsyncCallBack(cb, pThis), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4) \
{} \
virtual void invoke() \
{ \
@@ -1436,7 +1436,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, T0& v0, T1& v1, T2& v2, T3& v3, T4& v4, T5& v5, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4), m_v5(v5) \
AsyncCallBack(cb, pThis), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4), m_v5(v5) \
{} \
virtual void invoke() \
{ \
@@ -1556,7 +1556,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, T0& v0, T1& v1, T2& v2, T3& v3, T4& v4, T5& v5, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4), m_v5(v5) \
AsyncCallBack(cb, pThis), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4), m_v5(v5) \
{} \
virtual void invoke() \
{ \
@@ -1677,7 +1677,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, T0& v0, T1& v1, T2& v2, T3& v3, T4& v4, T5& v5, T6& v6, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4), m_v5(v5), m_v6(v6) \
AsyncCallBack(cb, pThis), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4), m_v5(v5), m_v6(v6) \
{} \
virtual void invoke() \
{ \
@@ -1799,7 +1799,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, T0& v0, T1& v1, T2& v2, T3& v3, T4& v4, T5& v5, T6& v6, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4), m_v5(v5), m_v6(v6) \
AsyncCallBack(cb, pThis), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4), m_v5(v5), m_v6(v6) \
{} \
virtual void invoke() \
{ \
@@ -1922,7 +1922,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, T0& v0, T1& v1, T2& v2, T3& v3, T4& v4, T5& v5, T6& v6, T7& v7, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4), m_v5(v5), m_v6(v6), m_v7(v7) \
AsyncCallBack(cb, pThis), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4), m_v5(v5), m_v6(v6), m_v7(v7) \
{} \
virtual void invoke() \
{ \
@@ -2046,7 +2046,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, T0& v0, T1& v1, T2& v2, T3& v3, T4& v4, T5& v5, T6& v6, T7& v7, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4), m_v5(v5), m_v6(v6), m_v7(v7) \
AsyncCallBack(cb, pThis), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4), m_v5(v5), m_v6(v6), m_v7(v7) \
{} \
virtual void invoke() \
{ \
@@ -2171,7 +2171,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, T0& v0, T1& v1, T2& v2, T3& v3, T4& v4, T5& v5, T6& v6, T7& v7, T8& v8, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4), m_v5(v5), m_v6(v6), m_v7(v7), m_v8(v8) \
AsyncCallBack(cb, pThis), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4), m_v5(v5), m_v6(v6), m_v7(v7), m_v8(v8) \
{} \
virtual void invoke() \
{ \
@@ -2297,7 +2297,7 @@
class _t: public AsyncCallBack { \
public: \
_t(cls* pThis, T0& v0, T1& v1, T2& v2, T3& v3, T4& v4, T5& v5, T6& v6, T7& v7, T8& v8, v8::Local<v8::Function> cb) : \
AsyncCallBack(pThis, cb), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4), m_v5(v5), m_v6(v6), m_v7(v7), m_v8(v8) \
AsyncCallBack(cb, pThis), m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3), m_v4(v4), m_v5(v5), m_v6(v6), m_v7(v7), m_v8(v8) \
{} \
virtual void invoke() \
{ \
View
@@ -121,10 +121,14 @@ void AsyncEvent::async(int32_t type)
putGuiPool(this);
}
AsyncCallBack::AsyncCallBack(object_base* pThis, v8::Local<v8::Function> cb)
AsyncCallBack::AsyncCallBack(v8::Local<v8::Function> cb, object_base* pThis)
{
m_pThis = pThis;
m_isolate = pThis->holder();
if (pThis) {
m_pThis = pThis;
m_isolate = pThis->holder();
} else
m_isolate = Isolate::current();
m_isolate->Ref();
m_cb.Reset(m_isolate->m_isolate, cb);
}
@@ -80,8 +80,9 @@ class JSTimer : public Timer {
{
m_callback.Reset();
if (!m_clear_pendding) {
Isolate* isolate = holder();
m_clear_pendding = true;
holder()->Unref();
isolate->Unref();
}
}
View
@@ -134,7 +134,7 @@ function gen_stub(argn, bInst, bRet) {
s += 'v8::Local<v8::Function> cb) : \\';
txt.push(s);
s = ' AsyncCallBack(' + (bInst ? 'pThis, ' : '') + 'cb)';
s = ' AsyncCallBack(cb' + (bInst ? ', pThis' : '') + ')';
for (i = 0; i < argn1; i++)
s += ', m_v' + i + '(v' + i + ')';
s += ' \\';

0 comments on commit c73b24c

Please sign in to comment.