diff options
author | 2023-07-30 02:03:32 -0700 | |
---|---|---|
committer | 2023-07-30 02:03:32 -0700 | |
commit | 1db119ec1180fbbfb5fa55d46f3b38ea19738bc2 (patch) | |
tree | 64eb6f456d47c287856bfdf7bf2d50c1ea2237b7 /src/bun.js/bindings/Strong.cpp | |
parent | 413fd281208f24a532c47249dec1bfc3aef2bf37 (diff) | |
download | bun-1db119ec1180fbbfb5fa55d46f3b38ea19738bc2.tar.gz bun-1db119ec1180fbbfb5fa55d46f3b38ea19738bc2.tar.zst bun-1db119ec1180fbbfb5fa55d46f3b38ea19738bc2.zip |
Fix memory leak (#3887)
* Fix memory leak
* Remove an extra copy
* Further fixes
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/bindings/Strong.cpp')
-rw-r--r-- | src/bun.js/bindings/Strong.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/bun.js/bindings/Strong.cpp b/src/bun.js/bindings/Strong.cpp new file mode 100644 index 000000000..8ec63e318 --- /dev/null +++ b/src/bun.js/bindings/Strong.cpp @@ -0,0 +1,53 @@ +#include "root.h" +#include <JavaScriptCore/StrongInlines.h> +#include "BunClientData.h" + +namespace Bun { + +// We tried to pool these +// But it was very complicated +class StrongRef { + WTF_MAKE_ISO_ALLOCATED(StrongRef); + +public: + StrongRef(JSC::VM& vm, JSC::JSValue value) + : m_cell(vm, value) + { + } + + StrongRef() + : m_cell() + { + } + + JSC::Strong<JSC::Unknown> m_cell; +}; + +WTF_MAKE_ISO_ALLOCATED_IMPL(StrongRef); + +} + +extern "C" void Bun__StrongRef__delete(Bun::StrongRef* strongRef) +{ + delete strongRef; +} + +extern "C" Bun::StrongRef* Bun__StrongRef__new(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue encodedValue) +{ + return new Bun::StrongRef(globalObject->vm(), JSC::JSValue::decode(encodedValue)); +} + +extern "C" JSC::EncodedJSValue Bun__StrongRef__get(Bun::StrongRef* strongRef) +{ + return JSC::JSValue::encode(strongRef->m_cell.get()); +} + +extern "C" void Bun__StrongRef__set(Bun::StrongRef* strongRef, JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value) +{ + strongRef->m_cell.set(globalObject->vm(), JSC::JSValue::decode(value)); +} + +extern "C" void Bun__StrongRef__clear(Bun::StrongRef* strongRef) +{ + strongRef->m_cell.clear(); +} |