diff --git a/CMakeLists.txt b/CMakeLists.txt index d445fca60..133de63f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,18 @@ if(MSVC) xcheck_add_c_compiler_flag(/wd5045) # Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified endif() +# Set a 8MB default stack size on Windows. +# It defaults to 1MB on MSVC, which is the same as our current JS stack size, +# so it will overflow and crash otherwise. +# On MinGW it defaults to 2MB. +if(WIN32) + if(MSVC) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:8388608") + else() + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,8388608") + endif() +endif() + # MacOS and GCC 11 or later need -Wno-maybe-uninitialized # https://github.com/quickjs-ng/quickjs/issues/453 if(APPLE AND CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 11) diff --git a/api-test.c b/api-test.c index 1c604c7b2..84b275815 100644 --- a/api-test.c +++ b/api-test.c @@ -8,7 +8,7 @@ #define MAX_TIME 10 -static int timeout_interrupt_handler(JSRuntime *rt, void *opaque) +static int timeout_interrupt_handler(JSRuntime *rt, void *opaque) { int *time = (int *)opaque; if (*time <= MAX_TIME) @@ -18,7 +18,7 @@ static int timeout_interrupt_handler(JSRuntime *rt, void *opaque) static void sync_call(void) { - const char *code = + const char *code = "(function() { \ try { \ while (true) {} \ @@ -43,7 +43,7 @@ static void sync_call(void) static void async_call(void) { - const char *code = + const char *code = "(async function() { \ const loop = async () => { \ await Promise.resolve(); \ @@ -97,8 +97,6 @@ static void async_call_stack_overflow(void) JSRuntime *rt = JS_NewRuntime(); JSContext *ctx = JS_NewContext(rt); - JS_SetMaxStackSize(rt, 128 * 1024); - JS_UpdateStackTop(rt); JSValue value = JS_UNDEFINED; JS_SetContextOpaque(ctx, &value); JSValue global = JS_GetGlobalObject(ctx);