#include #include #include "quickjs.h" #include "quickjs-libc.h" int main(void){ JSRuntime *rt = JS_NewRuntime(); JSContext *ctx = JS_NewContext(rt); js_std_init_handlers(rt); js_std_add_helpers(ctx, 0, NULL); const char *src = "let a=1; const b=2; const p=new Promise((res)=>{res(a+b)}); " "class C { static tag(){ return 'ES2023'; } } " "async function f(){ return (await p) + C.tag(); } " "f().then((v)=> { console.log('RESULT '+v); });"; JSValue r = JS_Eval(ctx, src, strlen(src), "smoke", 0); if (JS_IsException(r)) { JSValue e=JS_GetException(ctx); const char *es=JS_ToCString(ctx,e); printf("EXC: %s\n", es?es:"?"); JS_FreeCString(ctx, es); JS_FreeValue(ctx, e); } JS_FreeValue(ctx, r); for (;;) { JSContext *c2; int j = JS_ExecutePendingJob(rt, &c2); if (j != 1) break; } JS_FreeContext(ctx); js_std_free_handlers(rt); JS_FreeRuntime(rt); return 0; }