log reentrancy guard
This commit is contained in:
@@ -131,12 +131,16 @@ JSC_CCALL(actor_removetimer,
|
||||
)
|
||||
|
||||
/* Log callback bridge: called from JS_Log, calls ƿit log(channel, [msg, stack])
|
||||
Captures the register VM stack trace so the log system can show the real error site. */
|
||||
Captures the register VM stack trace so the log system can show the real error site.
|
||||
Uses a re-entrancy guard to prevent infinite recursion when JS_Call triggers
|
||||
js_poll_interrupts -> JS_RaiseDisrupt -> JS_Log -> js_log_callback -> ... */
|
||||
static int js_log_reentrancy = 0;
|
||||
static void js_log_callback(JSContext *ctx, const char *channel, const char *msg) {
|
||||
if (JS_IsNull(ctx->log_callback_js)) {
|
||||
if (JS_IsNull(ctx->log_callback_js) || js_log_reentrancy) {
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
return;
|
||||
}
|
||||
js_log_reentrancy = 1;
|
||||
JS_FRAME(ctx);
|
||||
JS_ROOT(stack, JS_GetStack(ctx));
|
||||
JS_ROOT(args_array, JS_NewArray(ctx));
|
||||
@@ -147,6 +151,7 @@ static void js_log_callback(JSContext *ctx, const char *channel, const char *msg
|
||||
argv[1] = args_array.val;
|
||||
JS_Call(ctx, ctx->log_callback_js, JS_NULL, 2, argv);
|
||||
JS_RestoreFrame(ctx, _js_gc_frame, _js_local_frame);
|
||||
js_log_reentrancy = 0;
|
||||
}
|
||||
|
||||
JSC_CCALL(actor_set_log,
|
||||
|
||||
Reference in New Issue
Block a user