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

Function backtrace_oom_current_exception

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

Source from the content-addressed store, hash-verified

777}
778
779static void backtrace_oom_current_exception(void)
780{
781 static const char setup_code[] =
782 "globalThis.f = function() { missing; };\n"
783 "Object.defineProperty(f, 'name', { value: 'x'.repeat(2 * 1024 * 1024) });";
784 JSMemoryUsage stats;
785 JSValue ret, exception;
786 JSRuntime *rt;
787 JSContext *ctx;
788
789 rt = new_runtime();
790 ctx = JS_NewContext(rt);
791
792 ret = eval(ctx, setup_code);
793 assert(!JS_IsException(ret));
794 JS_FreeValue(ctx, ret);
795
796 JS_ComputeMemoryUsage(rt, &stats);
797 JS_SetMemoryLimit(rt, (size_t)stats.malloc_size + 128 * 1024);
798
799 ret = eval(ctx, "f()");
800 assert(JS_IsException(ret));
801 assert(JS_HasException(ctx));
802 exception = JS_GetException(ctx);
803 JS_FreeValue(ctx, exception);
804 JS_SetMemoryLimit(rt, 0);
805
806 JS_FreeContext(ctx);
807 JS_FreeRuntime(rt);
808}
809
810static int gop_get_own_property(JSContext *ctx, JSPropertyDescriptor *desc,
811 JSValueConst obj, JSAtom prop)

Callers 1

mainFunction · 0.85

Calls 4

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

Tested by

no test coverage detected