mirror of
https://github.com/Ylianst/MeshAgent
synced 2026-01-13 14:03:33 +00:00
Updated Event Proxy, so proxyFunc is deleted when event is deleted
This commit is contained in:
@@ -83,6 +83,8 @@ typedef struct ILibDuktape_ContextData
|
||||
typedef void(*Duktape_EventLoopDispatch)(void *chain, void *user);
|
||||
void Duktape_RunOnEventLoop(void *chain, uintptr_t nonce, duk_context *ctx, Duktape_EventLoopDispatch handler, Duktape_EventLoopDispatch abortHandler, void *user);
|
||||
#define Duktape_RunOnEventLoopEx(chain, nonce, ctx, handler, user, freeOnShutdown) Duktape_RunOnEventLoop(chain, nonce, ctx, handler, (freeOnShutdown==0?NULL:(Duktape_EventLoopDispatch)(uintptr_t)0x01), user)
|
||||
extern void *_duk_get_tval(void *thr, duk_idx_t idx);
|
||||
extern duk_int_t* _get_refcount_ptr(void *thr, duk_idx_t idx);
|
||||
|
||||
void ILibDuktape_ExecutorTimeout_Start(duk_context *ctx);
|
||||
void ILibDuktape_ExecutorTimeout_Stop(duk_context *ctx);
|
||||
|
||||
@@ -850,6 +850,7 @@ duk_ret_t ILibDuktape_readableStream_unpipe(duk_context *ctx)
|
||||
duk_get_prop_string(ctx, -1, ILibDuktape_readableStream_RSPTRS); // [readable][ptrs]
|
||||
data = (ILibDuktape_readableStream*)Duktape_GetBuffer(ctx, -1, NULL);
|
||||
duk_pop(ctx); // [readable]
|
||||
duk_pop(ctx); // ...
|
||||
|
||||
if (data->emitter->ctx == NULL) { return(0); }
|
||||
|
||||
@@ -868,7 +869,7 @@ duk_ret_t ILibDuktape_readableStream_unpipe(duk_context *ctx)
|
||||
if (onlyItem) { break; }
|
||||
}
|
||||
if (onlyItem && wcount > 1) { onlyItem = 0; }
|
||||
duk_pop_2(ctx); // [readable]
|
||||
duk_pop_3(ctx); // ...
|
||||
}
|
||||
ILibSpinLock_UnLock(&(data->pipeLock));
|
||||
|
||||
@@ -881,16 +882,18 @@ duk_ret_t ILibDuktape_readableStream_unpipe(duk_context *ctx)
|
||||
duk_get_prop_string(ctx, -1, "pause"); // [readable][pause]
|
||||
duk_dup(ctx, -2); // [readable][pause][this]
|
||||
duk_call_method(ctx, 0); duk_pop(ctx); // [readable]
|
||||
duk_pop(ctx); // ...
|
||||
}
|
||||
|
||||
//ILibDuktape_readableStream_unpipe_later(ctx, (void*[]) { data->object, nargs == 0 ? NULL : duk_get_heapptr(ctx, 0) }, nargs == 0 ? 1 : 2);
|
||||
// We must yield, and do this on the next event loop, because we can't unpipe if we're called from a pipe'ed call
|
||||
duk_push_this(ctx); // [readable]
|
||||
void *imm = ILibDuktape_Immediate(ctx, (void*[]) { duk_get_heapptr(ctx, -1), nargs == 1 ? duk_get_heapptr(ctx, 0) : NULL }, nargs + 1, ILibDuktape_readableStream_unpipe_later);
|
||||
duk_push_heapptr(ctx, imm); // [immediate]
|
||||
duk_push_this(ctx); // [immediate][this]
|
||||
duk_put_prop_string(ctx, -2, "\xFF_Self"); // [immediate]
|
||||
if (nargs == 1) { duk_dup(ctx, 0); duk_put_prop_string(ctx, -2, "\xFF_w"); }
|
||||
duk_pop(ctx); // ...
|
||||
duk_pop_2(ctx); // ...
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1617,6 +1617,8 @@ duk_ret_t ILibDuktape_EventEmitter_ForwardEx_target_removeListenerSink(duk_conte
|
||||
duk_dup(ctx, 0); // [source][removeListener][this][name]
|
||||
duk_get_prop_string(ctx, 1, "proxyFunc"); // [source][removeListener][this][name][func]
|
||||
duk_call_method(ctx, 2); // [source][ret]
|
||||
|
||||
duk_del_prop_string(ctx, 1, "proxyFunc");
|
||||
return(0);
|
||||
}
|
||||
int ILibDuktape_EventEmitter_ForwardEventEx(duk_context *ctx, duk_idx_t sourceIdx, duk_idx_t targetIdx, char *eventName)
|
||||
|
||||
@@ -99903,3 +99903,15 @@ DUK_INTERNAL duk_double_t duk_util_tinyrandom_get_double(duk_hthread *thr) {
|
||||
#undef DUK__RANDOM_XOROSHIRO128PLUS
|
||||
#undef DUK__RND_BIT
|
||||
#undef DUK__UPDATE_RND
|
||||
|
||||
void *_duk_get_tval(void *thr, duk_idx_t idx)
|
||||
{
|
||||
return(duk_get_tval(thr, idx));
|
||||
}
|
||||
|
||||
duk_int_t* _get_refcount_ptr(void *thr, duk_idx_t idx)
|
||||
{
|
||||
duk_tval *tv = duk_get_tval_or_unused(thr, idx);
|
||||
duk_heaphdr *h = (DUK_TVAL_IS_HEAP_ALLOCATED(tv) ? DUK_TVAL_GET_HEAPHDR(tv) : NULL);
|
||||
return(&(DUK_HEAPHDR_GET_REFCOUNT(h)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user