@@ -928,6 +928,43 @@ static void new_errors(void)
928928 JS_FreeRuntime (rt );
929929}
930930
931+ static void backtrace_oom_callsite_array (void )
932+ {
933+ static const char setup_code [] =
934+ "Error.prepareStackTrace = (e, frames) => frames;\n"
935+ "globalThis.f = () => new Error();\n" ;
936+ JSValue global_object , func , ret ;
937+ JSMemoryUsage stats ;
938+ uint32_t headroom ;
939+ JSRuntime * rt ;
940+ JSContext * ctx ;
941+
942+ rt = new_runtime ();
943+ ctx = JS_NewContext (rt );
944+ global_object = JS_GetGlobalObject (ctx );
945+
946+ ret = eval (ctx , setup_code );
947+ assert (!JS_IsException (ret ));
948+ JS_FreeValue (ctx , ret );
949+
950+ func = JS_GetPropertyStr (ctx , global_object , "f" );
951+ assert (JS_IsFunction (ctx , func ));
952+
953+ for (headroom = 0 ; headroom < 2048 ; headroom ++ ) {
954+ JS_ComputeMemoryUsage (rt , & stats );
955+ JS_SetMemoryLimit (rt , (size_t )stats .malloc_size + headroom );
956+ ret = JS_Call (ctx , func , JS_UNDEFINED , 0 , NULL );
957+ JS_SetMemoryLimit (rt , 0 );
958+ JS_FreeValue (ctx , ret );
959+ JS_FreeValue (ctx , JS_GetException (ctx ));
960+ }
961+
962+ JS_FreeValue (ctx , func );
963+ JS_FreeValue (ctx , global_object );
964+ JS_FreeContext (ctx );
965+ JS_FreeRuntime (rt );
966+ }
967+
931968static void backtrace_oom_current_exception (void )
932969{
933970 static const char setup_code [] =
@@ -1372,6 +1409,7 @@ int main(void)
13721409 dump_memory_usage ();
13731410 new_errors ();
13741411 backtrace_oom_current_exception ();
1412+ backtrace_oom_callsite_array ();
13751413 global_object_prototype ();
13761414 slice_string_tocstring ();
13771415 immutable_array_buffer ();
0 commit comments