mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-16 16:23:25 +00:00
Updated Helper Methods
This commit is contained in:
@@ -1279,3 +1279,31 @@ void ILibDuktape_Log_Object(duk_context *ctx, duk_idx_t i, char *meta)
|
|||||||
duk_pop(ctx);
|
duk_pop(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ILibDuktape_DisplayProperties(duk_context *ctx, duk_idx_t idx)
|
||||||
|
{
|
||||||
|
duk_idx_t i = duk_get_top(ctx);
|
||||||
|
duk_dup(ctx, idx); // [obj]
|
||||||
|
duk_push_global_object(ctx); // [obj][g]
|
||||||
|
duk_get_prop_string(ctx, -1, "console"); // [obj][g][console]
|
||||||
|
duk_prepare_method_call(ctx, -1, "log"); // [obj][g][console][log][this]
|
||||||
|
duk_get_prop_string(ctx, -5, ILibDuktape_OBJID); // [obj][g][console][log][this][ID]
|
||||||
|
duk_pcall_method(ctx, 1); duk_pop_3(ctx); // [obj]
|
||||||
|
|
||||||
|
|
||||||
|
duk_eval_string(ctx, "require('events').allProperties"); // [obj][allProp]
|
||||||
|
duk_swap_top(ctx, -2); // [allProp][obj]
|
||||||
|
duk_pcall(ctx, 1); // [array]
|
||||||
|
duk_push_global_object(ctx); // [array][g]
|
||||||
|
duk_get_prop_string(ctx, -1, "console"); // [array][g][console]
|
||||||
|
duk_prepare_method_call(ctx, -1, "log"); // [array][g][console][log][this]
|
||||||
|
|
||||||
|
duk_get_prop_string(ctx, -4, "JSON"); // [array][g][console][log][this][JSON]
|
||||||
|
duk_prepare_method_call(ctx, -1, "stringify"); // [array][g][console][log][this][JSON][stringify][this]
|
||||||
|
duk_dup(ctx, -8); // [array][g][console][log][this][JSON][stringify][this][array]
|
||||||
|
duk_push_null(ctx); duk_push_int(ctx, 1); // [array][g][console][log][this][JSON][stringify][this][array][null][1]
|
||||||
|
duk_pcall_method(ctx, 3); // [array][g][console][log][this][JSON][string]
|
||||||
|
duk_remove(ctx, -2); // [array][g][console][log][this][string]
|
||||||
|
duk_pcall_method(ctx, 1);
|
||||||
|
duk_set_top(ctx, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,8 @@ typedef struct ILibDuktape_ContextData
|
|||||||
typedef void(*Duktape_EventLoopDispatch)(void *chain, void *user);
|
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);
|
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)
|
#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_Start(duk_context *ctx);
|
||||||
void ILibDuktape_ExecutorTimeout_Stop(duk_context *ctx);
|
void ILibDuktape_ExecutorTimeout_Stop(duk_context *ctx);
|
||||||
@@ -228,5 +230,6 @@ void* ILibDuktape_Timeout(duk_context *ctx, void **args, int argsLen, int delay,
|
|||||||
int ILibDuktape_GetReferenceCount(duk_context *ctx, duk_idx_t i);
|
int ILibDuktape_GetReferenceCount(duk_context *ctx, duk_idx_t i);
|
||||||
|
|
||||||
#define ILibDuktape_WriteID(ctx, id) duk_push_string(ctx, id);duk_put_prop_string(ctx, -2, ILibDuktape_OBJID)
|
#define ILibDuktape_WriteID(ctx, id) duk_push_string(ctx, id);duk_put_prop_string(ctx, -2, ILibDuktape_OBJID)
|
||||||
|
void ILibDuktape_DisplayProperties(duk_context *ctx, duk_idx_t idx);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ limitations under the License.
|
|||||||
|
|
||||||
#define ILibDuktape_AddCompressedModule(ctx, name, b64str) duk_push_global_object(ctx);duk_get_prop_string(ctx, -1, "addCompressedModule");duk_swap_top(ctx, -2);duk_push_string(ctx, name);duk_push_global_object(ctx);duk_get_prop_string(ctx, -1, "Buffer"); duk_remove(ctx, -2);duk_get_prop_string(ctx, -1, "from");duk_swap_top(ctx, -2);duk_push_string(ctx, b64str);duk_push_string(ctx, "base64");duk_pcall_method(ctx, 2);duk_pcall_method(ctx, 2);duk_pop(ctx);
|
#define ILibDuktape_AddCompressedModule(ctx, name, b64str) duk_push_global_object(ctx);duk_get_prop_string(ctx, -1, "addCompressedModule");duk_swap_top(ctx, -2);duk_push_string(ctx, name);duk_push_global_object(ctx);duk_get_prop_string(ctx, -1, "Buffer"); duk_remove(ctx, -2);duk_get_prop_string(ctx, -1, "from");duk_swap_top(ctx, -2);duk_push_string(ctx, b64str);duk_push_string(ctx, "base64");duk_pcall_method(ctx, 2);duk_pcall_method(ctx, 2);duk_pop(ctx);
|
||||||
|
|
||||||
|
extern void* _duk_get_first_object(void *ctx);
|
||||||
|
extern void* _duk_get_next_object(void *ctx, void *heapptr);
|
||||||
|
|
||||||
|
|
||||||
typedef enum ILibDuktape_Console_DestinationFlags
|
typedef enum ILibDuktape_Console_DestinationFlags
|
||||||
@@ -978,6 +980,14 @@ duk_ret_t ILibDuktape_Polyfills_timer_finalizer(duk_context *ctx)
|
|||||||
|
|
||||||
ILibLifeTime_Remove(ILibGetBaseTimer(Duktape_GetChain(ctx)), ptrs);
|
ILibLifeTime_Remove(ILibGetBaseTimer(Duktape_GetChain(ctx)), ptrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
duk_eval_string(ctx, "require('events')"); // [events]
|
||||||
|
duk_prepare_method_call(ctx, -1, "deleteProperty"); // [events][deleteProperty][this]
|
||||||
|
duk_push_this(ctx); // [events][deleteProperty][this][timer]
|
||||||
|
duk_prepare_method_call(ctx, -4, "hiddenProperties");//[events][deleteProperty][this][timer][hidden][this]
|
||||||
|
duk_push_this(ctx); // [events][deleteProperty][this][timer][hidden][this][timer]
|
||||||
|
duk_call_method(ctx, 1); // [events][deleteProperty][this][timer][array]
|
||||||
|
duk_call_method(ctx, 2); // [events][ret]
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void ILibDuktape_Polyfills_timer_elapsed(void *obj)
|
void ILibDuktape_Polyfills_timer_elapsed(void *obj)
|
||||||
@@ -1122,6 +1132,9 @@ duk_ret_t ILibDuktape_Polyfills_timer_clear(duk_context *ctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
duk_dup(ctx, 0);
|
||||||
|
duk_del_prop_string(ctx, -1, "\xFF_argArray");
|
||||||
|
|
||||||
duk_get_prop_string(ctx, 0, ILibDuktape_Timer_Ptrs);
|
duk_get_prop_string(ctx, 0, ILibDuktape_Timer_Ptrs);
|
||||||
ptrs = (ILibDuktape_Timer*)Duktape_GetBuffer(ctx, -1, NULL);
|
ptrs = (ILibDuktape_Timer*)Duktape_GetBuffer(ctx, -1, NULL);
|
||||||
|
|
||||||
@@ -1191,6 +1204,7 @@ duk_ret_t ILibDuktape_Polyfills_addCompressedModule_dataSink(duk_context *ctx)
|
|||||||
duk_ret_t ILibDuktape_Polyfills_addCompressedModule(duk_context *ctx)
|
duk_ret_t ILibDuktape_Polyfills_addCompressedModule(duk_context *ctx)
|
||||||
{
|
{
|
||||||
duk_eval_string(ctx, "require('compressed-stream').createDecompressor();");
|
duk_eval_string(ctx, "require('compressed-stream').createDecompressor();");
|
||||||
|
duk_dup(ctx, 0); duk_put_prop_string(ctx, -2, ILibDuktape_EventEmitter_FinalizerDebugMessage);
|
||||||
void *decoder = duk_get_heapptr(ctx, -1);
|
void *decoder = duk_get_heapptr(ctx, -1);
|
||||||
ILibDuktape_EventEmitter_AddOnEx(ctx, -1, "data", ILibDuktape_Polyfills_addCompressedModule_dataSink);
|
ILibDuktape_EventEmitter_AddOnEx(ctx, -1, "data", ILibDuktape_Polyfills_addCompressedModule_dataSink);
|
||||||
|
|
||||||
@@ -1213,6 +1227,10 @@ duk_ret_t ILibDuktape_Polyfills_addCompressedModule(duk_context *ctx)
|
|||||||
duk_pcall_method(ctx, 2);
|
duk_pcall_method(ctx, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
duk_push_heapptr(ctx, decoder); // [stream]
|
||||||
|
duk_prepare_method_call(ctx, -1, "removeAllListeners"); // [stream][remove][this]
|
||||||
|
duk_pcall_method(ctx, 0);
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
duk_ret_t ILibDuktape_Polyfills_addModuleObject(duk_context *ctx)
|
duk_ret_t ILibDuktape_Polyfills_addModuleObject(duk_context *ctx)
|
||||||
@@ -3147,7 +3165,105 @@ duk_ret_t ILibDuktape_Polyfills_NativeAllocSize(duk_context *ctx)
|
|||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
duk_ret_t ILibDuktape_Polyfills_WeakReference_isAlive(duk_context *ctx)
|
||||||
|
{
|
||||||
|
duk_push_this(ctx); // [weak]
|
||||||
|
void **p = Duktape_GetPointerProperty(ctx, -1, "\xFF_heapptr");
|
||||||
|
duk_push_boolean(ctx, ILibMemory_CanaryOK(p));
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
duk_ret_t ILibDuktape_Polyfills_WeakReference_object(duk_context *ctx)
|
||||||
|
{
|
||||||
|
duk_push_this(ctx); // [weak]
|
||||||
|
void **p = Duktape_GetPointerProperty(ctx, -1, "\xFF_heapptr");
|
||||||
|
if (ILibMemory_CanaryOK(p))
|
||||||
|
{
|
||||||
|
duk_push_heapptr(ctx, p[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
duk_push_null(ctx);
|
||||||
|
}
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
duk_ret_t ILibDuktape_Polyfills_WeakReference(duk_context *ctx)
|
||||||
|
{
|
||||||
|
duk_push_object(ctx); // [weak]
|
||||||
|
ILibDuktape_WriteID(ctx, "WeakReference");
|
||||||
|
duk_dup(ctx, 0); // [weak][obj]
|
||||||
|
void *j = duk_get_heapptr(ctx, -1);
|
||||||
|
void **p = (void**)Duktape_PushBuffer(ctx, sizeof(void*)); // [weak][obj][buffer]
|
||||||
|
p[0] = j;
|
||||||
|
duk_put_prop_string(ctx, -2, Duktape_GetStashKey(duk_get_heapptr(ctx, -1)));// [weak][obj]
|
||||||
|
|
||||||
|
duk_pop(ctx); // [weak]
|
||||||
|
|
||||||
|
duk_push_pointer(ctx, p); duk_put_prop_string(ctx, -2, "\xFF_heapptr"); // [weak]
|
||||||
|
ILibDuktape_CreateInstanceMethod(ctx, "isAlive", ILibDuktape_Polyfills_WeakReference_isAlive, 0);
|
||||||
|
ILibDuktape_CreateEventWithGetter_SetEnumerable(ctx, "object", ILibDuktape_Polyfills_WeakReference_object, 1);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
duk_ret_t ILibDuktape_Polyfills_rootObject(duk_context *ctx)
|
||||||
|
{
|
||||||
|
void *h = _duk_get_first_object(ctx);
|
||||||
|
duk_push_heapptr(ctx, h);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
duk_ret_t ILibDuktape_Polyfills_nextObject(duk_context *ctx)
|
||||||
|
{
|
||||||
|
void *h = duk_require_heapptr(ctx, 0);
|
||||||
|
void *next = _duk_get_next_object(ctx, h);
|
||||||
|
if (next != NULL)
|
||||||
|
{
|
||||||
|
duk_push_heapptr(ctx, next);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
duk_push_null(ctx);
|
||||||
|
}
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
duk_ret_t ILibDuktape_Polyfills_countObject(duk_context *ctx)
|
||||||
|
{
|
||||||
|
void *h = _duk_get_first_object(ctx);
|
||||||
|
duk_int_t i = 1;
|
||||||
|
|
||||||
|
while (h != NULL)
|
||||||
|
{
|
||||||
|
if ((h = _duk_get_next_object(ctx, h)) != NULL) { ++i; }
|
||||||
|
}
|
||||||
|
duk_push_int(ctx, i);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
duk_ret_t ILibDuktape_Polyfills_hide(duk_context *ctx)
|
||||||
|
{
|
||||||
|
duk_idx_t top = duk_get_top(ctx);
|
||||||
|
duk_push_heap_stash(ctx); // [stash]
|
||||||
|
|
||||||
|
if (top == 0)
|
||||||
|
{
|
||||||
|
duk_get_prop_string(ctx, -1, "__STASH__"); // [stash][value]
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (duk_is_boolean(ctx, 0))
|
||||||
|
{
|
||||||
|
duk_get_prop_string(ctx, -1, "__STASH__"); // [stash][value]
|
||||||
|
if (duk_require_boolean(ctx, 0))
|
||||||
|
{
|
||||||
|
duk_del_prop_string(ctx, -2, "__STASH__");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
duk_dup(ctx, 0); // [stash][value]
|
||||||
|
duk_dup(ctx, -1); // [stash][value][value]
|
||||||
|
duk_put_prop_string(ctx, -3, "__STASH__"); // [stash][value]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
void ILibDuktape_Polyfills_Init(duk_context *ctx)
|
void ILibDuktape_Polyfills_Init(duk_context *ctx)
|
||||||
{
|
{
|
||||||
ILibDuktape_ModSearch_AddHandler(ctx, "queue", ILibDuktape_Queue_Push);
|
ILibDuktape_ModSearch_AddHandler(ctx, "queue", ILibDuktape_Queue_Push);
|
||||||
@@ -3194,6 +3310,12 @@ void ILibDuktape_Polyfills_Init(duk_context *ctx)
|
|||||||
ILibDuktape_CreateInstanceMethod(ctx, "_ipv4From", ILibDuktape_Polyfills_ipv4From, 1);
|
ILibDuktape_CreateInstanceMethod(ctx, "_ipv4From", ILibDuktape_Polyfills_ipv4From, 1);
|
||||||
ILibDuktape_CreateInstanceMethod(ctx, "_isBuffer", ILibDuktape_Polyfills_isBuffer, 1);
|
ILibDuktape_CreateInstanceMethod(ctx, "_isBuffer", ILibDuktape_Polyfills_isBuffer, 1);
|
||||||
ILibDuktape_CreateInstanceMethod(ctx, "_MSH", ILibDuktape_Polyfills_MSH, 0);
|
ILibDuktape_CreateInstanceMethod(ctx, "_MSH", ILibDuktape_Polyfills_MSH, 0);
|
||||||
|
ILibDuktape_CreateInstanceMethod(ctx, "WeakReference", ILibDuktape_Polyfills_WeakReference, 1);
|
||||||
|
ILibDuktape_CreateInstanceMethod(ctx, "_rootObject", ILibDuktape_Polyfills_rootObject, 0);
|
||||||
|
ILibDuktape_CreateInstanceMethod(ctx, "_nextObject", ILibDuktape_Polyfills_nextObject, 1);
|
||||||
|
ILibDuktape_CreateInstanceMethod(ctx, "_countObjects", ILibDuktape_Polyfills_countObject, 0);
|
||||||
|
ILibDuktape_CreateInstanceMethod(ctx, "_hide", ILibDuktape_Polyfills_hide, DUK_VARARGS);
|
||||||
|
|
||||||
#if defined(ILIBMEMTRACK) && !defined(ILIBCHAIN_GLOBAL_LOCK)
|
#if defined(ILIBMEMTRACK) && !defined(ILIBCHAIN_GLOBAL_LOCK)
|
||||||
ILibDuktape_CreateInstanceMethod(ctx, "_NativeAllocSize", ILibDuktape_Polyfills_NativeAllocSize, 0);
|
ILibDuktape_CreateInstanceMethod(ctx, "_NativeAllocSize", ILibDuktape_Polyfills_NativeAllocSize, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ limitations under the License.
|
|||||||
#include "ILibDuktape_Polyfills.h"
|
#include "ILibDuktape_Polyfills.h"
|
||||||
|
|
||||||
#define ILibDuktape_EventEmitter_MaxEventNameLen 255
|
#define ILibDuktape_EventEmitter_MaxEventNameLen 255
|
||||||
|
#define ILibDuktape_EventEmitter_EmitterUtils "\xFF_emitterUtils"
|
||||||
#define ILibDuktape_EventEmitter_Data "\xFF_EventEmitter_Data"
|
#define ILibDuktape_EventEmitter_Data "\xFF_EventEmitter_Data"
|
||||||
#define ILibDuktape_EventEmitter_RetVal "\xFF_EventEmitter_RetVal"
|
#define ILibDuktape_EventEmitter_RetVal "\xFF_EventEmitter_RetVal"
|
||||||
#define ILibDuktape_EventEmitter_LastRetValueTable "\xFF_EventEmitter_LastRetValueTable"
|
#define ILibDuktape_EventEmitter_LastRetValueTable "\xFF_EventEmitter_LastRetValueTable"
|
||||||
@@ -37,6 +38,7 @@ limitations under the License.
|
|||||||
#define ILibDuktape_EventEmitter_EventTable "\xFF_EventEmitter_EventTable"
|
#define ILibDuktape_EventEmitter_EventTable "\xFF_EventEmitter_EventTable"
|
||||||
#define ILibDuktape_EventEmitter_CountTable "\xFF_EventEmitter_CountTable"
|
#define ILibDuktape_EventEmitter_CountTable "\xFF_EventEmitter_CountTable"
|
||||||
#define ILibDuktape_EventEmitter_References "\xFF_EventReferences"
|
#define ILibDuktape_EventEmitter_References "\xFF_EventReferences"
|
||||||
|
extern void ILibDuktape_GenericMarshal_Variable_PUSH(duk_context *ctx, void *ptr, int size);
|
||||||
|
|
||||||
#ifdef ILIBEVENTEMITTER_REFHOLD
|
#ifdef ILIBEVENTEMITTER_REFHOLD
|
||||||
int gEventEmitterReferenceHold = ILIBEVENTEMITTER_REFHOLD;
|
int gEventEmitterReferenceHold = ILIBEVENTEMITTER_REFHOLD;
|
||||||
@@ -785,7 +787,7 @@ duk_ret_t ILibDuktape_EventEmitter_listeners_tableinit(duk_context *ctx)
|
|||||||
emitter->listenerCountTableLength = len;
|
emitter->listenerCountTableLength = len;
|
||||||
duk_push_this(ctx); // [g][JSON][array][index][string][array][string][string][this]
|
duk_push_this(ctx); // [g][JSON][array][index][string][array][string][string][this]
|
||||||
duk_swap_top(ctx, -2); // [g][JSON][array][index][string][array][string][this][string]
|
duk_swap_top(ctx, -2); // [g][JSON][array][index][string][array][string][this][string]
|
||||||
duk_put_prop_string(ctx, -2, ILibDuktape_EventEmitter_CountTable);
|
ILibDuktape_CreateReadonlyProperty_SetEnumerable(ctx, ILibDuktape_EventEmitter_CountTable, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -803,18 +805,18 @@ ILibDuktape_EventEmitter* ILibDuktape_EventEmitter_Create(duk_context *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
retVal = (ILibDuktape_EventEmitter*)Duktape_PushBuffer(ctx, sizeof(ILibDuktape_EventEmitter)); // [event][data]
|
retVal = (ILibDuktape_EventEmitter*)Duktape_PushBuffer(ctx, sizeof(ILibDuktape_EventEmitter)); // [event][data]
|
||||||
duk_put_prop_string(ctx, -2, ILibDuktape_EventEmitter_Data); // [event]
|
ILibDuktape_CreateReadonlyProperty_SetEnumerable(ctx, ILibDuktape_EventEmitter_Data, 0); // [event]
|
||||||
|
|
||||||
retVal->ctx = ctx;
|
retVal->ctx = ctx;
|
||||||
retVal->object = duk_get_heapptr(ctx, -1);
|
retVal->object = duk_get_heapptr(ctx, -1);
|
||||||
|
|
||||||
duk_push_object(ctx);
|
duk_push_object(ctx);
|
||||||
retVal->table = duk_get_heapptr(ctx, -1);
|
retVal->table = duk_get_heapptr(ctx, -1);
|
||||||
duk_put_prop_string(ctx, -2, ILibDuktape_EventEmitter_EventTable);
|
ILibDuktape_CreateReadonlyProperty_SetEnumerable(ctx, ILibDuktape_EventEmitter_EventTable, 0);
|
||||||
|
|
||||||
duk_push_object(ctx);
|
duk_push_object(ctx);
|
||||||
retVal->retValTable = duk_get_heapptr(ctx, -1);
|
retVal->retValTable = duk_get_heapptr(ctx, -1);
|
||||||
duk_put_prop_string(ctx, -2, ILibDuktape_EventEmitter_LastRetValueTable);
|
ILibDuktape_CreateReadonlyProperty_SetEnumerable(ctx, ILibDuktape_EventEmitter_LastRetValueTable, 0);
|
||||||
ILibSpinLock_Init(&(retVal->listenerCountTableLock));
|
ILibSpinLock_Init(&(retVal->listenerCountTableLock));
|
||||||
retVal->listenerCountTable = (char*)"[]";
|
retVal->listenerCountTable = (char*)"[]";
|
||||||
retVal->listenerCountTableLength = 2;
|
retVal->listenerCountTableLength = 2;
|
||||||
@@ -1036,8 +1038,8 @@ duk_ret_t ILibDuktape_EventEmitter_Inherits(duk_context *ctx)
|
|||||||
duk_dup(ctx, 0); // [target]
|
duk_dup(ctx, 0); // [target]
|
||||||
emitter = ILibDuktape_EventEmitter_Create(ctx);
|
emitter = ILibDuktape_EventEmitter_Create(ctx);
|
||||||
duk_push_object(ctx); // [target][emitterUtils]
|
duk_push_object(ctx); // [target][emitterUtils]
|
||||||
duk_dup(ctx, -1); // [target][emitterUtils][dup]
|
ILibDuktape_CreateReadonlyProperty_SetEnumerable(ctx, ILibDuktape_EventEmitter_EmitterUtils, 0);
|
||||||
duk_put_prop_string(ctx, -3, "\xFF_emitterUtils"); // [target][emitterUtils]
|
duk_get_prop_string(ctx, -1, ILibDuktape_EventEmitter_EmitterUtils);
|
||||||
duk_push_pointer(ctx, emitter); // [target][emitterUtils][ptr]
|
duk_push_pointer(ctx, emitter); // [target][emitterUtils][ptr]
|
||||||
duk_put_prop_string(ctx, -2, "emitter"); // [target][emitterUtils]
|
duk_put_prop_string(ctx, -2, "emitter"); // [target][emitterUtils]
|
||||||
ILibDuktape_CreateInstanceMethod(ctx, "createEvent", ILibDuktape_EventEmitter_Inherits_createEvent, 1);
|
ILibDuktape_CreateInstanceMethod(ctx, "createEvent", ILibDuktape_EventEmitter_Inherits_createEvent, 1);
|
||||||
@@ -1053,8 +1055,8 @@ duk_ret_t ILibDuktape_EventEmitter_EventEmitter(duk_context *ctx)
|
|||||||
duk_push_this(ctx); // [target]
|
duk_push_this(ctx); // [target]
|
||||||
emitter = ILibDuktape_EventEmitter_Create(ctx);
|
emitter = ILibDuktape_EventEmitter_Create(ctx);
|
||||||
duk_push_object(ctx); // [target][emitterUtils]
|
duk_push_object(ctx); // [target][emitterUtils]
|
||||||
duk_dup(ctx, -1); // [target][emitterUtils][dup]
|
ILibDuktape_CreateReadonlyProperty_SetEnumerable(ctx, ILibDuktape_EventEmitter_EmitterUtils, 0);
|
||||||
duk_put_prop_string(ctx, -3, "\xFF_emitterUtils"); // [target][emitterUtils]
|
duk_get_prop_string(ctx, -1, ILibDuktape_EventEmitter_EmitterUtils);
|
||||||
duk_push_pointer(ctx, emitter); // [target][emitterUtils][ptr]
|
duk_push_pointer(ctx, emitter); // [target][emitterUtils][ptr]
|
||||||
duk_put_prop_string(ctx, -2, "emitter"); // [target][emitterUtils]
|
duk_put_prop_string(ctx, -2, "emitter"); // [target][emitterUtils]
|
||||||
|
|
||||||
@@ -1136,27 +1138,205 @@ duk_ret_t ILibDuktape_EventEmitter_moderated(duk_context *ctx)
|
|||||||
|
|
||||||
duk_ret_t ILibDuktape_EventEmitter_allProperties(duk_context *ctx)
|
duk_ret_t ILibDuktape_EventEmitter_allProperties(duk_context *ctx)
|
||||||
{
|
{
|
||||||
|
duk_push_current_function(ctx);
|
||||||
|
int all = Duktape_GetIntPropertyValue(ctx, -1, "all", 0);
|
||||||
|
|
||||||
const char *tmp;
|
const char *tmp;
|
||||||
duk_push_array(ctx); // [arr]
|
duk_push_array(ctx); // [arr]
|
||||||
duk_dup(ctx, 0); // [arr][obj]
|
duk_dup(ctx, 0); // [arr][obj]
|
||||||
duk_enum(ctx, -1, DUK_ENUM_INCLUDE_NONENUMERABLE | DUK_ENUM_INCLUDE_HIDDEN );
|
duk_enum(ctx, -1, (all == 0 ? 0 : DUK_ENUM_INCLUDE_NONENUMERABLE) | (all == 2 ? DUK_ENUM_OWN_PROPERTIES_ONLY : 0) | DUK_ENUM_INCLUDE_HIDDEN | DUK_ENUM_INCLUDE_SYMBOLS);;
|
||||||
while (duk_next(ctx, -1, 0)) // [arr][obj][enum][key]
|
while (duk_next(ctx, -1, 0)) // [arr][obj][enum][key]
|
||||||
{
|
{
|
||||||
tmp = duk_get_string(ctx, -1);
|
tmp = NULL;
|
||||||
duk_push_string(ctx, tmp); // [arr][obj][enum][key][string]
|
if (duk_is_symbol(ctx, -1))
|
||||||
duk_array_push(ctx, -5); // [arr][obj][enum][key]
|
{
|
||||||
|
duk_size_t len;
|
||||||
|
tmp = Duktape_GetBuffer(ctx, -1, &len);
|
||||||
|
char *buf = duk_push_fixed_buffer(ctx, len + 1); // [arr][obj][enum][key][buf]
|
||||||
|
duk_insert(ctx, -5); // [buf][arr][obj][enum][key]
|
||||||
|
memcpy_s(buf, len + 1, tmp, len);
|
||||||
|
buf[0] = '?';
|
||||||
|
buf[len] = 0;
|
||||||
|
tmp = buf;
|
||||||
|
if (all == 0)
|
||||||
|
{
|
||||||
|
if (strcmp(tmp, "?Finalizer") == 0) { tmp = NULL; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (all) { tmp = duk_get_string(ctx, -1); }
|
||||||
|
}
|
||||||
|
if (tmp != NULL)
|
||||||
|
{
|
||||||
|
duk_push_string(ctx, tmp); // [arr][obj][enum][key][string]
|
||||||
|
duk_array_push(ctx, -5); // [arr][obj][enum][key]
|
||||||
|
}
|
||||||
duk_pop(ctx); // [arr][obj][enum]
|
duk_pop(ctx); // [arr][obj][enum]
|
||||||
}
|
}
|
||||||
duk_pop_2(ctx); // [arr]
|
duk_pop_2(ctx); // [arr]
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
duk_ret_t ILibDuktape_EventEmitter_showReferences(duk_context *ctx)
|
||||||
|
{
|
||||||
|
const char *ID, *MSG;
|
||||||
|
duk_push_heap_stash(ctx); // [stash]
|
||||||
|
duk_get_prop_string(ctx, -1, ILibDuktape_EventEmitter_References); // [stash][refs]
|
||||||
|
if (!duk_is_null_or_undefined(ctx, -1))
|
||||||
|
{
|
||||||
|
duk_enum(ctx, -1, DUK_ENUM_OWN_PROPERTIES_ONLY); // [stash][refs][enum]
|
||||||
|
while (duk_next(ctx, -1, 1)) // [stash][refs][enum][key][value]
|
||||||
|
{
|
||||||
|
ID = Duktape_GetStringPropertyValue(ctx, -1, ILibDuktape_OBJID, "?");
|
||||||
|
MSG = Duktape_GetStringPropertyValue(ctx, -1, ILibDuktape_EventEmitter_FinalizerDebugMessage, "");
|
||||||
|
duk_push_global_object(ctx); // [stash][refs][enum][key][value][g]
|
||||||
|
duk_get_prop_string(ctx, -1, "console"); // [stash][refs][enum][key][value][g][console]
|
||||||
|
duk_remove(ctx, -2); // [stash][refs][enum][key][value][console]
|
||||||
|
duk_prepare_method_call(ctx, -1, "log"); // [stash][refs][enum][key][value][console][log][this]
|
||||||
|
duk_push_sprintf(ctx, "%s%s%s", ID, MSG != NULL ? " => " : "", MSG != NULL ? MSG : ""); //][value][console][log][this][string]
|
||||||
|
duk_call_method(ctx, 1); duk_pop_n(ctx, 2); // [stash][refs][enum][key][value]
|
||||||
|
duk_prepare_method_call(ctx, -1, "eventNames"); // [stash][refs][enum][key][value][eventNames][this]
|
||||||
|
if (duk_pcall_method(ctx, 0) == 0) // [stash][refs][enum][key][value][array]
|
||||||
|
{
|
||||||
|
if (duk_get_length(ctx, -1) > 0)
|
||||||
|
{
|
||||||
|
duk_push_global_object(ctx); // [stash][refs][enum][key][value][array][g]
|
||||||
|
duk_get_prop_string(ctx, -1, "JSON"); // [stash][refs][enum][key][value][array][g][JSON]
|
||||||
|
duk_prepare_method_call(ctx, -1, "stringify"); // [stash][refs][enum][key][value][array][g][JSON][stringify][this]
|
||||||
|
duk_dup(ctx, -5); // [stash][refs][enum][key][value][array][g][JSON][stringify][this][array]
|
||||||
|
duk_call_method(ctx, 1); // [stash][refs][enum][key][value][array][g][JSON][STRING]
|
||||||
|
duk_get_prop_string(ctx, -3, "console"); // [stash][refs][enum][key][value][array][g][JSON][STRING][console]
|
||||||
|
duk_prepare_method_call(ctx, -1, "log"); // [stash][refs][enum][key][value][array][g][JSON][STRING][console][log][this]
|
||||||
|
duk_push_sprintf(ctx, " -> events %s", duk_get_string(ctx, -4));// tash][refs][enum][key][value][array][g][JSON][STRING][console][log][this][VAL]
|
||||||
|
duk_call_method(ctx, 1); // [stash][refs][enum][key][value][array][g][JSON][STRING][console][ret]
|
||||||
|
duk_pop_n(ctx, 5); // [stash][refs][enum][key][value][array]
|
||||||
|
}
|
||||||
|
duk_eval_string(ctx, "require('events')"); // [stash][refs][enum][key][value][array][events]
|
||||||
|
duk_prepare_method_call(ctx, -1, "hiddenProperties"); // [stash][refs][enum][key][value][array][events][hidden][this]
|
||||||
|
duk_dup(ctx, -5); // [stash][refs][enum][key][value][array][events][hidden][this][value]
|
||||||
|
duk_call_method(ctx, 1); // [stash][refs][enum][key][value][array][events][props]
|
||||||
|
duk_push_global_object(ctx); // [stash][refs][enum][key][value][array][events][props][g]
|
||||||
|
duk_get_prop_string(ctx, -1, "JSON"); // [stash][refs][enum][key][value][array][events][props][g][JSON]
|
||||||
|
duk_prepare_method_call(ctx, -1, "stringify"); // [stash][refs][enum][key][value][array][events][props][g][JSON][stringify][this]
|
||||||
|
duk_dup(ctx, -5); // [stash][refs][enum][key][value][array][events][props][g][JSON][stringify][this][props]
|
||||||
|
duk_push_null(ctx); duk_push_int(ctx, 1); // [stash][refs][enum][key][value][array][events][props][g][JSON][stringify][this][props][null][1]
|
||||||
|
duk_call_method(ctx, 3); // [stash][refs][enum][key][value][array][events][props][g][JSON][PROPSTRING]
|
||||||
|
duk_get_prop_string(ctx, -3, "console"); // [stash][refs][enum][key][value][array][events][props][g][JSON][PROPSTRING][console]
|
||||||
|
duk_prepare_method_call(ctx, -1, "log"); // [stash][refs][enum][key][value][array][events][props][g][JSON][PROPSTRING][console][log][this]
|
||||||
|
duk_push_sprintf(ctx, " -> props %s", duk_get_string(ctx, -4)); // [refs][enum][key][value][array][events][props][g][JSON][PROPSTRING][console][log][this][string]
|
||||||
|
duk_call_method(ctx, 1); // [stash][refs][enum][key][value][array][events][props][g][JSON][PROPSTRING][console][ret]
|
||||||
|
duk_pop_n(ctx, 7); // [stash][refs][enum][key][value][array]
|
||||||
|
}
|
||||||
|
duk_pop_n(ctx, 3); // [stash][refs][enum]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
duk_ret_t ILibDuktape_EventEmitter_addHidden(duk_context *ctx)
|
||||||
|
{
|
||||||
|
duk_dup(ctx, 0); // [a]
|
||||||
|
duk_dup(ctx, 1); // [a][b]
|
||||||
|
duk_put_prop_string(ctx, -2, "\xFF_HIDDEN");
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
duk_ret_t ILibDuktape_EventEmitter_deleteProperty(duk_context *ctx)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
duk_dup(ctx, 0); // [obj]
|
||||||
|
if (duk_is_string(ctx, 1))
|
||||||
|
{
|
||||||
|
duk_dup(ctx, 1); // [obj][string]
|
||||||
|
duk_del_prop(ctx, -2);
|
||||||
|
}
|
||||||
|
else if (duk_is_array(ctx, 1))
|
||||||
|
{
|
||||||
|
duk_dup(ctx, 1); // [obj][array]
|
||||||
|
while (duk_get_length(ctx, -1) > 0)
|
||||||
|
{
|
||||||
|
duk_array_pop(ctx, -1); // [obj][array][string]
|
||||||
|
tmp = (char*)duk_push_sprintf(ctx, "%s", duk_get_string(ctx, -1)); // [obj][array][string][string]
|
||||||
|
tmp[0] = '\xFF';
|
||||||
|
duk_del_prop_string(ctx, -4, tmp);
|
||||||
|
duk_pop_2(ctx); // [obj][array]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(ILibDuktape_Error(ctx, "Invalid Args"));
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
duk_ret_t ILibDuktape_EventEmitter_setFinalizerMetadata(duk_context *ctx)
|
||||||
|
{
|
||||||
|
duk_push_this(ctx);
|
||||||
|
duk_dup(ctx, 0);
|
||||||
|
duk_put_prop_string(ctx, -2, ILibDuktape_EventEmitter_FinalizerDebugMessage);
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
duk_ret_t ILibDuktape_RefCountPointer_eval(duk_context *ctx)
|
||||||
|
{
|
||||||
|
duk_push_this(ctx);
|
||||||
|
duk_int_t *t = (duk_int_t*)Duktape_GetPointerProperty(ctx, -1, "_ptr");
|
||||||
|
if (t == NULL) { return(ILibDuktape_Error(ctx, "ERROR")); }
|
||||||
|
duk_push_int(ctx, *t);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
duk_ret_t ILibDuktape_RefCountPointer_set(duk_context *ctx)
|
||||||
|
{
|
||||||
|
duk_push_this(ctx);
|
||||||
|
duk_int_t *t = (duk_int_t*)Duktape_GetPointerProperty(ctx, -1, "_ptr");
|
||||||
|
if (t == NULL) { return(ILibDuktape_Error(ctx, "ERROR")); }
|
||||||
|
*t = duk_require_int(ctx, 0);
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
duk_ret_t ILibDuktape_RefCountPointer(duk_context *ctx)
|
||||||
|
{
|
||||||
|
int nargs = duk_get_top(ctx);
|
||||||
|
duk_push_this(ctx);
|
||||||
|
char *tmp = Duktape_GetStringPropertyValue(ctx, -1, ILibDuktape_OBJID, "");
|
||||||
|
if (nargs == 1) { duk_dup(ctx, 0); }
|
||||||
|
duk_int_t *t = _get_refcount_ptr(ctx, -1);
|
||||||
|
if (nargs == 1) { duk_pop(ctx); }
|
||||||
|
ILibDuktape_GenericMarshal_Variable_PUSH(ctx, t, sizeof(void*));
|
||||||
|
duk_push_sprintf(ctx, "_get_refcount_ptr(%s)", tmp); duk_put_prop_string(ctx, -2, ILibDuktape_EventEmitter_FinalizerDebugMessage);
|
||||||
|
ILibDuktape_CreateInstanceMethod(ctx, "eval", ILibDuktape_RefCountPointer_eval, 0);
|
||||||
|
ILibDuktape_CreateInstanceMethod(ctx, "set", ILibDuktape_RefCountPointer_set, 1);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
duk_ret_t ILibDuktape_EventEmitter_getProperty(duk_context *ctx)
|
||||||
|
{
|
||||||
|
duk_push_this(ctx); // [obj]
|
||||||
|
char *tmp = (char*)duk_push_sprintf(ctx, "%s", duk_get_string(ctx, 0));// [obj][string]
|
||||||
|
if (tmp[0] == '?') { tmp[0] = '\xFF'; }
|
||||||
|
duk_get_prop_string(ctx, -2, tmp);
|
||||||
|
tmp = (char*)duk_get_string(ctx, -1);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
duk_ret_t ILibDuktape_EventEmitter_setProperty(duk_context *ctx)
|
||||||
|
{
|
||||||
|
duk_push_this(ctx); // [obj]
|
||||||
|
char *tmp = (char*)duk_push_sprintf(ctx, "%s", duk_get_string(ctx, 0));// [obj][string]
|
||||||
|
duk_dup(ctx, 1); // [obj][string][val]
|
||||||
|
if (tmp[0] == '?') { tmp[0] = '\xFF'; }
|
||||||
|
duk_put_prop_string(ctx, -3, tmp);
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
void ILibDuktape_EventEmitter_PUSH(duk_context *ctx, void *chain)
|
void ILibDuktape_EventEmitter_PUSH(duk_context *ctx, void *chain)
|
||||||
{
|
{
|
||||||
duk_push_object(ctx); // [emitter]
|
duk_push_object(ctx); // [emitter]
|
||||||
ILibDuktape_CreateInstanceMethod(ctx, "inherits", ILibDuktape_EventEmitter_Inherits, 1);
|
ILibDuktape_CreateInstanceMethod(ctx, "inherits", ILibDuktape_EventEmitter_Inherits, 1);
|
||||||
ILibDuktape_CreateInstanceMethod(ctx, "EventEmitter", ILibDuktape_EventEmitter_EventEmitter, DUK_VARARGS);
|
ILibDuktape_CreateInstanceMethod(ctx, "EventEmitter", ILibDuktape_EventEmitter_EventEmitter, DUK_VARARGS);
|
||||||
ILibDuktape_CreateInstanceMethod(ctx, "moderated", ILibDuktape_EventEmitter_moderated, DUK_VARARGS);
|
ILibDuktape_CreateInstanceMethod(ctx, "moderated", ILibDuktape_EventEmitter_moderated, DUK_VARARGS);
|
||||||
ILibDuktape_CreateInstanceMethod(ctx, "allProperties", ILibDuktape_EventEmitter_allProperties, 1);
|
ILibDuktape_CreateInstanceMethodWithIntProperty(ctx, "all", 1, "allProperties", ILibDuktape_EventEmitter_allProperties, 1);
|
||||||
|
ILibDuktape_CreateInstanceMethodWithIntProperty(ctx, "all", 0, "hiddenProperties", ILibDuktape_EventEmitter_allProperties, 1);
|
||||||
|
ILibDuktape_CreateInstanceMethodWithIntProperty(ctx, "all", 2, "allOwnProperties", ILibDuktape_EventEmitter_allProperties, 1);
|
||||||
|
ILibDuktape_CreateInstanceMethod(ctx, "showReferences", ILibDuktape_EventEmitter_showReferences, DUK_VARARGS);
|
||||||
|
ILibDuktape_CreateInstanceMethod(ctx, "addHiddenReference", ILibDuktape_EventEmitter_addHidden, 2);
|
||||||
|
ILibDuktape_CreateInstanceMethod(ctx, "deleteProperty", ILibDuktape_EventEmitter_deleteProperty, 2);
|
||||||
|
ILibDuktape_CreateInstanceMethod(ctx, "setFinalizerMetadata", ILibDuktape_EventEmitter_setFinalizerMetadata, 1);
|
||||||
|
ILibDuktape_CreateInstanceMethod(ctx, "_refCountPointer", ILibDuktape_RefCountPointer, DUK_VARARGS);
|
||||||
|
ILibDuktape_CreateInstanceMethod(ctx, "getProperty", ILibDuktape_EventEmitter_getProperty, 1);
|
||||||
|
ILibDuktape_CreateInstanceMethod(ctx, "setProperty", ILibDuktape_EventEmitter_setProperty, 2);
|
||||||
}
|
}
|
||||||
void ILibDuktape_EventEmitter_Init(duk_context *ctx)
|
void ILibDuktape_EventEmitter_Init(duk_context *ctx)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -99903,3 +99903,26 @@ DUK_INTERNAL duk_double_t duk_util_tinyrandom_get_double(duk_hthread *thr) {
|
|||||||
#undef DUK__RANDOM_XOROSHIRO128PLUS
|
#undef DUK__RANDOM_XOROSHIRO128PLUS
|
||||||
#undef DUK__RND_BIT
|
#undef DUK__RND_BIT
|
||||||
#undef DUK__UPDATE_RND
|
#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)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void* _duk_get_first_object(void *ctx)
|
||||||
|
{
|
||||||
|
duk_hthread *thr = (duk_hthread*)ctx;
|
||||||
|
return(thr->heap->heap_allocated);
|
||||||
|
}
|
||||||
|
void* _duk_get_next_object(void *ctx, void *heapptr)
|
||||||
|
{
|
||||||
|
duk_hthread *thr = (duk_hthread*)ctx;
|
||||||
|
return(DUK_HEAPHDR_GET_NEXT(thr->heap, ((duk_heaphdr*)heapptr)));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user