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

namespace Zig {
using namespace WebCore;

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);

  exportNames.append(JSC::Identifier::fromString(vm, "Blob"_s));
  exportValues.append(lexicalGlobalObject->get(
      globalObject, PropertyName(Identifier::fromString(vm, "Blob"_s))));

  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));
}

} // namespace Zig