aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/BunStream.h
blob: 64837c21917a40398447bc88efbcc842a8762a3b (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once

#include "BunBuiltinNames.h"
#include "BunClientData.h"
#include "root.h"

namespace WebCore {

using namespace JSC;

class Readable : public JSC::JSNonFinalObject {
    using Base = JSC::JSNonFinalObject;

public:
    Bun__Readable* state;
    Readable(JSC::VM& vm, Bun__Readable* readable, JSC::Structure* structure)
        : Base(vm, structure)
    {
        state = readable;
    }

    ~Readable();

    DECLARE_INFO;

    static constexpr unsigned StructureFlags = Base::StructureFlags;

    template<typename CellType, SubspaceAccess> static GCClient::IsoSubspace* subspaceFor(VM& vm)
    {
        return &vm.plainObjectSpace();
    }

    static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject,
        JSC::JSValue prototype)
    {
        return JSC::Structure::create(vm, globalObject, prototype,
            JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
    }

    static Readable* create(JSC::VM& vm, Bun__Readable* state, JSC::Structure* structure)
    {
        Readable* accessor = new (NotNull, JSC::allocateCell<WebCore::Readable>(vm)) Readable(vm, state, structure);
        accessor->finishCreation(vm);
        return accessor;
    }

    void finishCreation(JSC::VM& vm);
};

class Writable : public JSC::JSNonFinalObject {
    using Base = JSC::JSNonFinalObject;

public:
    Bun__Writable* state;
    Writable(JSC::VM& vm, Bun__Writable* writable, JSC::Structure* structure)
        : Base(vm, structure)
    {
        state = writable;
    }

    DECLARE_INFO;

    static constexpr unsigned StructureFlags = Base::StructureFlags;

    template<typename CellType, SubspaceAccess> static GCClient::IsoSubspace* subspaceFor(VM& vm)
    {
        return &vm.plainObjectSpace();
    }

    static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject,
        JSC::JSValue prototype)
    {
        return JSC::Structure::create(vm, globalObject, prototype,
            JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
    }

    static Writable* create(JSC::VM& vm, Bun__Writable* state, JSC::Structure* structure)
    {

        Writable* accessor = new (NotNull, JSC::allocateCell<Writable>(vm)) Writable(vm, state, structure);
        accessor->finishCreation(vm);
        return accessor;
    }
    ~Writable();

    void finishCreation(JSC::VM& vm);
};

} // namespace WebCore