aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/modules/BufferModule.h
blob: 9032f0d2e827ddeade642b20f8a1da310b7f5a08 (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
#include "../bindings/ZigGlobalObject.h"
#include "../bindings/JSBuffer.h"
#include "JavaScriptCore/JSGlobalObject.h"

namespace Zig {

inline void generateBufferSourceCode(JSC::JSGlobalObject* lexicalGlobalObject, JSC::Identifier moduleKey, Vector<JSC::Identifier, 4>& exportNames, JSC::MarkedArgumentBuffer& exportValues) {
    JSC::VM& vm = lexicalGlobalObject->vm();
    GlobalObject* globalObject = reinterpret_cast<GlobalObject*>(lexicalGlobalObject);

    exportNames.append(JSC::Identifier::fromString(vm, "Buffer"_s));
    exportValues.append(WebCore::JSBuffer::getConstructor(vm, globalObject));

    auto* slowBuffer = JSC::JSFunction::create(vm, globalObject, 0, "SlowBuffer"_s, WebCore::constructSlowBuffer, ImplementationVisibility::Public, NoIntrinsic, WebCore::constructSlowBuffer);
    slowBuffer->putDirect(vm, vm.propertyNames->prototype, WebCore::JSBuffer::prototype(vm, *jsCast<JSDOMGlobalObject*>(lexicalGlobalObject)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete);
    exportNames.append(JSC::Identifier::fromString(vm, "SlowBuffer"_s));
    exportValues.append(slowBuffer);

    // substitute after JSBlob is implemented.
    exportNames.append(JSC::Identifier::fromString(vm, "Blob"_s));
    exportValues.append(JSC::jsUndefined());

    exportNames.append(JSC::Identifier::fromString(vm, "INSPECT_MAX_BYTES"_s));
    exportValues.append(JSC::jsNumber(50));

    exportNames.append(JSC::Identifier::fromString(vm, "kMaxLength"_s));
    exportValues.append(JSC::jsNumber(4294967296LL));

    exportNames.append(JSC::Identifier::fromString(vm, "kMaxLength"_s));
    exportValues.append(JSC::jsNumber(536870888));
}

}