MCPcopy Create free account
hub / github.com/buke/quickjs-go / async_call_stack_overflow

Function async_call_stack_overflow

deps/quickjs/api-test.c:249–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247}
248
249static 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
286static void raw_context_global_var(void)

Callers 1

mainFunction · 0.85

Calls 5

new_runtimeFunction · 0.85
JS_NewCFunctionFunction · 0.85
evalFunction · 0.85
JS_IsExceptionFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected