aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/Strong.cpp
blob: 8ec63e3185cdd71f0ee61e5ec85a1a83215650ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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();
}