From ffeaa77370a9ef5b080d1bacf6bb1d66aaec8222 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Thu, 16 May 2024 20:35:57 -0700 Subject: [PATCH] Add a debug assertion --- src/bun.js/bindings/bindings.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index 7091f87364..31c3246406 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -2213,6 +2213,11 @@ extern "C" JSC__JSValue JSObjectCallAsFunctionReturnValue(JSContextRef ctx, JSC_ JSC::JSGlobalObject* globalObject = toJS(ctx); JSC::VM& vm = globalObject->vm(); +#if BUN_DEBUG + // This is a redundant check, but we add it to make the error message clearer. + ASSERT_WITH_MESSAGE(!vm.isCollectorBusyOnCurrentThread(), "Cannot call function inside a finalizer or while GC is running on same thread."); +#endif + if (UNLIKELY(!object)) return JSC::JSValue::encode(JSC::JSValue()); @@ -2263,6 +2268,11 @@ JSC__JSValue JSObjectCallAsFunctionReturnValueHoldingAPILock(JSContextRef ctx, J JSC::JSLockHolder lock(vm); +#if BUN_DEBUG + // This is a redundant check, but we add it to make the error message clearer. + ASSERT_WITH_MESSAGE(!vm.isCollectorBusyOnCurrentThread(), "Cannot call function inside a finalizer or while GC is running on same thread."); +#endif + if (!object) return JSC::JSValue::encode(JSC::JSValue());