| 247 | } |
| 248 | |
| 249 | static void async_call_stack_overflow(void) |
| 250 | { |
| 251 | static const char code[] = |
| 252 | "(async function() { \ |
| 253 | const f = () => f(); \ |
| 254 | try { \ |
| 255 | await Promise.resolve(); \ |
| 256 | f(); \ |
| 257 | } catch (e) { \ |
| 258 | save_value(e); \ |
| 259 | } \ |
| 260 | })();"; |
| 261 | |
| 262 | JSRuntime *rt = new_runtime(); |
| 263 | JSContext *ctx = JS_NewContext(rt); |
| 264 | JSValue value = JS_UNDEFINED; |
| 265 | JS_SetContextOpaque(ctx, &value); |
| 266 | JSValue global = JS_GetGlobalObject(ctx); |
| 267 | JS_SetPropertyStr(ctx, global, "save_value", JS_NewCFunction(ctx, save_value, "save_value", 1)); |
| 268 | JS_FreeValue(ctx, global); |
| 269 | JSValue ret = eval(ctx, code); |
| 270 | assert(!JS_IsException(ret)); |
| 271 | JS_FreeValue(ctx, ret); |
| 272 | assert(JS_IsJobPending(rt)); |
| 273 | int r = 0; |
| 274 | while (JS_IsJobPending(rt)) { |
| 275 | r = JS_ExecutePendingJob(rt, &ctx); |
| 276 | } |
| 277 | assert(r == 1); |
| 278 | assert(!JS_HasException(ctx)); |
| 279 | assert(JS_IsError(value)); // stack overflow should be caught |
| 280 | JS_FreeValue(ctx, value); |
| 281 | JS_FreeContext(ctx); |
| 282 | JS_FreeRuntime(rt); |
| 283 | } |
| 284 | |
| 285 | // https://github.com/quickjs-ng/quickjs/issues/914 |
| 286 | static void raw_context_global_var(void) |
no test coverage detected