MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

async operation stack errors

+17
+2
include/ant.h
··· 33 33 typedef uint64_t jsval_t; 34 34 35 35 #define ANT_LIMIT_SIZE_CACHE 16384 36 + #define CORO_PER_TICK_LIMIT 10000 37 + 36 38 #define GC_FWD_ARGS jsval_t (*fwd_val)(void *ctx, jsval_t old), void *ctx 37 39 #define GC_UPDATE_ARGS ant_t *js, jsoff_t (*fwd_off)(void *ctx, jsoff_t old), GC_FWD_ARGS 38 40
+1
include/internal.h
··· 54 54 int eval_depth; // recursion depth of js_eval calls 55 55 int parse_depth; // recursion depth of parser (for stack overflow protection) 56 56 bool skip_func_hoist; // skip function declaration hoisting (pre-computed) 57 + bool fatal_error; // fatal error that should bypass promise rejection handling 57 58 58 59 // for-let loop context stack 59 60 struct for_let_ctx *for_let_stack;
+14
src/ant.c
··· 158 158 159 159 static this_stack_t global_this_stack = {NULL, 0, 0}; 160 160 static call_stack_t global_call_stack = {NULL, 0, 0}; 161 + 162 + static uint32_t coros_this_tick = 0; 161 163 static coroutine_queue_t pending_coroutines = {NULL, NULL}; 162 164 163 165 typedef struct { ··· 1074 1076 } 1075 1077 1076 1078 void js_poll_events(struct js *js) { 1079 + coros_this_tick = 0; 1080 + 1077 1081 fetch_poll_events(); 1078 1082 fs_poll_events(); 1079 1083 child_process_poll_events(); ··· 1154 1158 } 1155 1159 1156 1160 static jsval_t start_async_in_coroutine(struct js *js, const char *code, size_t code_len, jsval_t closure_scope, jsval_t *args, int nargs) { 1161 + if (++coros_this_tick > CORO_PER_TICK_LIMIT) { 1162 + js->fatal_error = true; 1163 + return js_mkerr_typed(js, JS_ERR_RANGE | JS_ERR_NO_STACK, "Maximum async operations per tick exceeded"); 1164 + } 1165 + 1157 1166 jsval_t promise = js_mkpromise(js); 1158 1167 async_exec_context_t *ctx = (async_exec_context_t *)CORO_MALLOC(sizeof(async_exec_context_t)); 1159 1168 if (!ctx) return js_mkerr(js, "out of memory for async context"); ··· 23566 23575 if (parent && parent->has_rejection_handler) { 23567 23576 HASH_DELETE(hh_unhandled, unhandled_rejections, pd); continue; 23568 23577 } 23578 + } 23579 + 23580 + if (js->fatal_error) { 23581 + fprintf(stderr, "%s\n", js->errmsg ? js->errmsg : js_str(js, pd->value)); 23582 + js_destroy(js); exit(1); 23569 23583 } 23570 23584 23571 23585 char buf[1024];