From 6f3a092564e25a62d04fc45555be6987c8d715e2 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Sat, 2 Jul 2022 02:35:43 -0700 Subject: [bun:jsc] Add `protectedObjectTypeCounts`, disallow gc --- src/bun.js/bindings/BunJSCModule.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/bun.js/bindings/BunJSCModule.cpp') diff --git a/src/bun.js/bindings/BunJSCModule.cpp b/src/bun.js/bindings/BunJSCModule.cpp index b81f2db93..dd5c4b062 100644 --- a/src/bun.js/bindings/BunJSCModule.cpp +++ b/src/bun.js/bindings/BunJSCModule.cpp @@ -197,8 +197,21 @@ const ClassInfo JSCMemoryFootprint::s_info = { "MemoryFootprint"_s, &Base::s_inf JSC_DECLARE_HOST_FUNCTION(functionMemoryUsageStatistics); JSC_DEFINE_HOST_FUNCTION(functionMemoryUsageStatistics, (JSGlobalObject * globalObject, CallFrame*)) { - auto contextRef = toRef(globalObject); - return JSValue::encode(toJS(JSGetMemoryUsageStatistics(contextRef))); + + auto& vm = globalObject->vm(); + JSC::DisallowGC disallowGC; + + // this is a C API function + auto* stats = toJS(JSGetMemoryUsageStatistics(toRef(globalObject))); + + // This is missing from the C API + JSC::JSObject* protectedCounts = constructEmptyObject(globalObject); + auto typeCounts = *vm.heap.protectedObjectTypeCounts(); + for (auto& it : typeCounts) + protectedCounts->putDirect(vm, Identifier::fromLatin1(vm, it.key), jsNumber(it.value)); + + stats->putDirect(vm, Identifier::fromLatin1(vm, "protectedObjectTypeCounts"_s), protectedCounts); + return JSValue::encode(stats); } JSC_DECLARE_HOST_FUNCTION(functionCreateMemoryFootprint); -- cgit v1.2.3