ArrayBufferSink works and it's good.

This commit is contained in:
Jarred Sumner
2022-06-12 21:40:45 -07:00
parent 6d88a3d9c0
commit dbde52504d
26 changed files with 2054 additions and 170 deletions

View File

@@ -0,0 +1,10 @@
static const HashTableValue JSArrayBufferSinkPrototypeTableValues[]
= {
{ "close"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ArrayBufferSink__close), (intptr_t)(0) } },
{ "closeWithError"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ArrayBufferSink__closeWithError), (intptr_t)(1) } },
{ "drain"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ArrayBufferSink__drain), (intptr_t)(1) } },
{ "end"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ArrayBufferSink__end), (intptr_t)(0) } },
{ "start"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ArrayBufferSink__start), (intptr_t)(1) } },
{ "write"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ArrayBufferSink__write), (intptr_t)(1) } },
};

View File

@@ -0,0 +1,220 @@
// AUTO-GENERATED FILE. DO NOT EDIT.
// Generated by /Users/jarred/Code/bun/src/javascript/jsc/generate-jssink.js at 2022-06-13T03:43:14.001Z
// To regenerate this file, run:
//
// bun src/javascript/jsc/generate-jssink.js
//
#include "root.h"
#include "JSSink.h"
#include "ActiveDOMObject.h"
#include "ExtendedDOMClientIsoSubspaces.h"
#include "ExtendedDOMIsoSubspaces.h"
#include "IDLTypes.h"
// #include "JSBlob.h"
#include "JSDOMAttribute.h"
#include "JSDOMBinding.h"
#include "JSDOMConstructor.h"
#include "JSDOMConvertBase.h"
#include "JSDOMConvertInterface.h"
#include "JSDOMConvertStrings.h"
#include "JSDOMExceptionHandling.h"
#include "JSDOMGlobalObject.h"
#include "JSDOMGlobalObjectInlines.h"
#include "JSDOMOperation.h"
#include "JSDOMWrapperCache.h"
#include "ScriptExecutionContext.h"
#include "WebCoreJSClientData.h"
#include "JavaScriptCore/FunctionPrototype.h"
#include "JavaScriptCore/HeapAnalyzer.h"
#include "JavaScriptCore/JSDestructibleObjectHeapCellType.h"
#include "JavaScriptCore/SlotVisitorMacros.h"
#include "JavaScriptCore/SubspaceInlines.h"
#include "wtf/GetPtr.h"
#include "wtf/PointerPreparations.h"
#include "wtf/URL.h"
#include "JavaScriptCore/BuiltinNames.h"
#include "JSBufferEncodingType.h"
#include "JSBufferPrototypeBuiltins.h"
#include "JSBufferConstructorBuiltins.h"
#include "JavaScriptCore/JSBase.h"
#if ENABLE(MEDIA_SOURCE)
#include "BufferMediaSource.h"
#include "JSMediaSource.h"
#endif
// #include "JavaScriptCore/JSTypedArrayViewPrototype.h"
#include "JavaScriptCore/JSArrayBufferViewInlines.h"
namespace WebCore {
using namespace JSC;
JSC_DEFINE_CUSTOM_GETTER(functionArrayBufferSink__getter, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName))
{
auto& vm = lexicalGlobalObject->vm();
Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
return JSC::JSValue::encode(globalObject->ArrayBufferSink());
}
static const HashTableValue JSArrayBufferSinkPrototypeTableValues[]
= {
{ "close"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ArrayBufferSink__close), (intptr_t)(0) } },
{ "closeWithError"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ArrayBufferSink__closeWithError), (intptr_t)(1) } },
{ "drain"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ArrayBufferSink__drain), (intptr_t)(1) } },
{ "end"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ArrayBufferSink__end), (intptr_t)(0) } },
{ "start"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ArrayBufferSink__start), (intptr_t)(1) } },
{ "write"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ArrayBufferSink__write), (intptr_t)(1) } },
};
#pragma mark - ArrayBufferSink
class JSArrayBufferSinkPrototype final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static JSArrayBufferSinkPrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure)
{
JSArrayBufferSinkPrototype* ptr = new (NotNull, JSC::allocateCell<JSArrayBufferSinkPrototype>(vm)) JSArrayBufferSinkPrototype(vm, globalObject, structure);
ptr->finishCreation(vm, globalObject);
return ptr;
}
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::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());
}
private:
JSArrayBufferSinkPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
: Base(vm, structure)
{
}
void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
};
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSArrayBufferSinkPrototype, JSArrayBufferSinkPrototype::Base);
const ClassInfo JSArrayBufferSinkPrototype::s_info = { "ArrayBufferSink"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSArrayBufferSinkPrototype) };
const ClassInfo JSArrayBufferSink::s_info = { "ArrayBufferSink"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSArrayBufferSink) };
const ClassInfo JSArrayBufferSinkConstructor::s_info = { "ArrayBufferSink"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSArrayBufferSinkConstructor) };
JSArrayBufferSink::~JSArrayBufferSink()
{
if (m_sinkPtr) {
ArrayBufferSink__finalize(m_sinkPtr);
}
}
JSArrayBufferSinkConstructor* JSArrayBufferSinkConstructor::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSObject* prototype)
{
JSArrayBufferSinkConstructor* ptr = new (NotNull, JSC::allocateCell<JSArrayBufferSinkConstructor>(vm)) JSArrayBufferSinkConstructor(vm, structure, ArrayBufferSink__construct);
ptr->finishCreation(vm, globalObject, prototype);
return ptr;
}
JSArrayBufferSink* JSArrayBufferSink::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* sinkPtr)
{
JSArrayBufferSink* ptr = new (NotNull, JSC::allocateCell<JSArrayBufferSink>(vm)) JSArrayBufferSink(vm, structure, sinkPtr);
ptr->finishCreation(vm);
return ptr;
}
void JSArrayBufferSinkConstructor::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, JSObject* prototype)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
initializeProperties(vm, globalObject, prototype);
}
JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSArrayBufferSinkConstructor::construct(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame) {
return ArrayBufferSink__construct(globalObject, callFrame);
}
void JSArrayBufferSinkConstructor::initializeProperties(VM& vm, JSC::JSGlobalObject* globalObject, JSObject* prototype)
{
putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
JSString* nameString = jsNontrivialString(vm, "ArrayBufferSink"_s);
m_originalName.set(vm, this, nameString);
putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
}
void JSArrayBufferSinkPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, JSArrayBufferSink::info(), JSArrayBufferSinkPrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
void JSArrayBufferSink::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
}
void JSArrayBufferSink::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
{
auto* thisObject = jsCast<JSArrayBufferSink*>(cell);
if (void* wrapped = thisObject->wrapped()) {
analyzer.setWrappedObjectForCell(cell, wrapped);
// if (thisObject->scriptExecutionContext())
// analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
}
Base::analyzeHeap(cell, analyzer);
}
void JSArrayBufferSink::destroy(JSCell* cell)
{
static_cast<JSArrayBufferSink*>(cell)->JSArrayBufferSink::~JSArrayBufferSink();
}
JSObject* createJSSinkPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, SinkID sinkID)
{
switch (sinkID) {
case ArrayBufferSink:
return JSArrayBufferSinkPrototype::create(vm, globalObject, JSArrayBufferSinkPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
default:
RELEASE_ASSERT_NOT_REACHED();
}
}
} // namespace WebCore
extern "C" JSC__JSValue ArrayBufferSink__createObject(JSC__JSGlobalObject* arg0, void* sinkPtr)
{
auto& vm = arg0->vm();
Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(arg0);
JSC::JSValue prototype = globalObject->ArrayBufferSinkPrototype();
JSC::Structure* structure = WebCore::JSArrayBufferSink::createStructure(vm, globalObject, prototype);
return JSC::JSValue::encode(WebCore::JSArrayBufferSink::create(vm, globalObject, structure, sinkPtr));
}
extern "C" void* ArrayBufferSink__fromJS(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1)
{
JSC::VM& vm = WebCore::getVM(arg0);
if (auto* sink = JSC::jsDynamicCast<WebCore::JSArrayBufferSink*>(JSC::JSValue::decode(JSValue1)))
return sink->wrapped();
return nullptr;
}

View File

@@ -0,0 +1,106 @@
// AUTO-GENERATED FILE. DO NOT EDIT.
// Generated by /Users/jarred/Code/bun/src/javascript/jsc/generate-jssink.js at 2022-06-13T03:43:13.999Z
//
#pragma once
#include "root.h"
#include "JSDOMWrapper.h"
#include "wtf/NeverDestroyed.h"
#include "Sink.h"
extern "C" bool JSSink_isSink(JSC::JSGlobalObject*, JSC::EncodedJSValue);
namespace WebCore {
using namespace JSC;
class JSArrayBufferSinkConstructor final : public JSC::InternalFunction {
public:
using Base = JSC::InternalFunction;
static JSArrayBufferSinkConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSC::JSObject* prototype);
static constexpr SinkID Sink = SinkID::ArrayBufferSink;
static constexpr unsigned StructureFlags = Base::StructureFlags;
static constexpr bool needsDestruction = false;
DECLARE_EXPORT_INFO;
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return WebCore::subspaceForImpl<JSArrayBufferSinkConstructor, WebCore::UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForJSSinkConstructor.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSSinkConstructor = WTFMove(space); },
[](auto& spaces) { return spaces.m_subspaceForJSSinkConstructor.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForJSSinkConstructor = WTFMove(space); });
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info());
}
void initializeProperties(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSObject* prototype);
// Must be defined for each specialization class.
static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*);
private:
JSArrayBufferSinkConstructor(JSC::VM& vm, JSC::Structure* structure, JSC::NativeFunction nativeFunction)
: Base(vm, structure, nativeFunction, nativeFunction)
{
}
void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, JSC::JSObject* prototype);
};
class JSArrayBufferSink final : public JSC::JSDestructibleObject {
public:
using Base = JSC::JSDestructibleObject;
static JSArrayBufferSink* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* sinkPtr);
static constexpr SinkID Sink = SinkID::ArrayBufferSink;
DECLARE_EXPORT_INFO;
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return WebCore::subspaceForImpl<JSArrayBufferSink, WebCore::UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForJSSink.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSSink = WTFMove(space); },
[](auto& spaces) { return spaces.m_subspaceForJSSink.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForJSSink = WTFMove(space); });
}
static void destroy(JSC::JSCell*);
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());
}
~JSArrayBufferSink();
void* wrapped() const { return m_sinkPtr; }
static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
void* m_sinkPtr;
JSArrayBufferSink(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
m_sinkPtr = sinkPtr;
}
void finishCreation(JSC::VM&);
};
JSC_DECLARE_CUSTOM_GETTER(functionArrayBufferSink__getter);
JSObject* createJSSinkPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, WebCore::SinkID sinkID);
} // namespace WebCore

View File

@@ -0,0 +1,15 @@
#include "root.h"
namespace WebCore {
enum SinkID : uint8_t {
ArrayBufferSink = 0,
TextSink = 1,
FileSink = 2,
HTMLRewriterSink = 3,
};
static constexpr unsigned numberOfSinkIDs
= 4;
}

View File

@@ -136,6 +136,8 @@ using JSBuffer = WebCore::JSBuffer;
#include "StructuredClone.h"
#include "ReadableStream.h"
#include "JSSink.h"
// #include <iostream>
static bool has_loaded_jsc = false;
@@ -1635,6 +1637,26 @@ void GlobalObject::finishCreation(VM& vm)
Base::finishCreation(vm);
ASSERT(inherits(info()));
m_NapiClassStructure.initLater(
[](LazyClassStructure::Initializer& init) {
init.setStructure(Zig::NapiClass::createStructure(init.vm, init.global, init.global->functionPrototype()));
});
m_JSArrayBufferSinkClassStructure.initLater(
[](LazyClassStructure::Initializer& init) {
auto* prototype = createJSSinkPrototype(init.vm, init.global, WebCore::SinkID::ArrayBufferSink);
auto* structure = JSArrayBufferSink::createStructure(init.vm, init.global, prototype);
auto* constructor = JSArrayBufferSinkConstructor::create(init.vm, init.global, JSArrayBufferSinkConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<JSObject*>(prototype));
init.setPrototype(prototype);
init.setStructure(structure);
init.setConstructor(constructor);
});
m_JSFFIFunctionStructure.initLater(
[](LazyClassStructure::Initializer& init) {
init.setStructure(Zig::JSFFIFunction::createStructure(init.vm, init.global, init.global->functionPrototype()));
});
addBuiltinGlobals(vm);
RELEASE_ASSERT(classInfo());
@@ -1877,6 +1899,12 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count, JSC::VM& vm
JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DontDelete | 0);
}
{
JSC::Identifier identifier = JSC::Identifier::fromString(vm, "ArrayBufferSink"_s);
object->putDirectCustomAccessor(vm, identifier, JSC::CustomGetterSetter::create(vm, functionArrayBufferSink__getter, nullptr),
JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
}
{
object->putDirectBuiltinFunction(vm, this, builtinNames.readableStreamToArrayPublicName(), readableStreamReadableStreamToArrayCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
}
@@ -1926,16 +1954,6 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count, JSC::VM& vm
this->addStaticGlobals(extraStaticGlobals.data(), extraStaticGlobals.size());
m_NapiClassStructure.initLater(
[](LazyClassStructure::Initializer& init) {
init.setStructure(Zig::NapiClass::createStructure(init.vm, init.global, init.global->m_functionPrototype.get()));
});
m_JSFFIFunctionStructure.initLater(
[](LazyClassStructure::Initializer& init) {
init.setStructure(Zig::JSFFIFunction::createStructure(init.vm, init.global, init.global->m_functionPrototype.get()));
});
// putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "SQL"_s), JSC::CustomGetterSetter::create(vm, JSSQLStatement_getter, nullptr),
// JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
@@ -1970,10 +1988,13 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor)
thisObject->m_builtinInternalFunctions.visit(visitor);
thisObject->m_JSFFIFunctionStructure.visit(visitor);
thisObject->m_JSArrayBufferSinkClassStructure.visit(visitor);
visitor.append(thisObject->m_readableStreamToArrayBufferResolve);
visitor.append(thisObject->m_readableStreamToText);
visitor.append(thisObject->m_readableStreamToJSON);
visitor.append(thisObject->m_readableStreamToBlob);
ScriptExecutionContext* context = thisObject->scriptExecutionContext();
visitor.addOpaqueRoot(context);
}

View File

@@ -148,6 +148,9 @@ public:
WebCore::JSBuiltinInternalFunctions& builtinInternalFunctions() { return m_builtinInternalFunctions; }
JSC::Structure* FFIFunctionStructure() { return m_JSFFIFunctionStructure.getInitializedOnMainThread(this); }
JSC::Structure* NapiClassStructure() { return m_NapiClassStructure.getInitializedOnMainThread(this); }
JSC::Structure* ArrayBufferSinkStructure() { return m_JSArrayBufferSinkClassStructure.getInitializedOnMainThread(this); }
JSC::JSObject* ArrayBufferSink() { return m_JSArrayBufferSinkClassStructure.constructorInitializedOnMainThread(this); }
JSC::JSValue ArrayBufferSinkPrototype() { return m_JSArrayBufferSinkClassStructure.prototypeInitializedOnMainThread(this); }
void* bunVM() { return m_bunVM; }
bool isThreadLocalDefaultGlobalObject = false;
@@ -171,6 +174,7 @@ private:
Ref<WebCore::DOMWrapperWorld> m_world;
LazyClassStructure m_JSFFIFunctionStructure;
LazyClassStructure m_NapiClassStructure;
LazyClassStructure m_JSArrayBufferSinkClassStructure;
DOMGuardedObjectSet m_guardedObjects WTF_GUARDED_BY_LOCK(m_gcLock);
void* m_bunVM;

View File

@@ -3236,6 +3236,8 @@ pub const CallFrame = opaque {
const argumentsCount_offset = thisValue_offset - 1;
const alignment = std.meta.alignment([]const JSC.JSValue);
pub const name = "JSC::CallFrame";
pub fn argumentsPtr(self: *const CallFrame) [*]const JSC.JSValue {
return @ptrCast([*]const JSC.JSValue, @alignCast(alignment, self)) + arguments_offset;
}

View File

@@ -313,6 +313,8 @@ function consumeReadableStream(nativePtr, nativeType, inputStream) {
if (!this.#ptr) return @throwTypeError("ReadableStreamSink is already closed");
return this.processResult(this.#reader.readMany());
}
};
const minlength = nativeType + 1;
@@ -326,7 +328,7 @@ function consumeReadableStream(nativePtr, nativeType, inputStream) {
@throwTypeError("Cannot start reading from a locked stream");
}
return new Prototype(inputStream.getReader(), nativePtr);
return new Prototype(inputStream.getReader(), nativePtr);
}
@globalPrivate

View File

@@ -183,6 +183,9 @@ pub const NodePath = JSC.Node.Path;
pub const JSReadableStreamBlob = JSC.WebCore.ByteBlobLoader.Source.JSReadableStreamSource;
pub const JSReadableStreamFile = JSC.WebCore.FileBlobLoader.Source.JSReadableStreamSource;
// Sinks
pub const JSArrayBufferSink = JSC.WebCore.ArrayBufferSink.JSArrayBufferSink;
pub fn Errorable(comptime Type: type) type {
return extern struct {
result: Result,
@@ -1599,9 +1602,8 @@ pub const ZigConsoleClient = struct {
writer.print(comptime Output.prettyFmt("<r><yellow>{d}<r>", enable_ansi_colors), .{value.toInt64()});
},
.BigInt => {
var sliced = value.toSlice(this.globalThis, bun.default_allocator);
defer sliced.deinit();
writer.print(comptime Output.prettyFmt("<r><yellow>{s}<r>", enable_ansi_colors), .{sliced.slice()});
var wtf = value.toWTFString(this.globalThis);
writer.print(comptime Output.prettyFmt("<r><yellow>{s}n<r>", enable_ansi_colors), .{wtf.slice()});
},
.Double => {
writer.print(comptime Output.prettyFmt("<r><yellow>{d}<r>", enable_ansi_colors), .{value.asNumber()});
@@ -2507,12 +2509,14 @@ comptime {
_ = Process.setTitle;
_ = Zig__getAPIGlobals;
_ = Zig__getAPIConstructors;
std.testing.refAllDecls(NodeReadableStream);
std.testing.refAllDecls(Bun.Timer);
std.testing.refAllDecls(NodeWritableStream);
std.testing.refAllDecls(NodePath);
std.testing.refAllDecls(JSReadableStreamBlob);
std.testing.refAllDecls(JSReadableStreamFile);
NodeReadableStream.shim.ref();
Bun.Timer.shim.ref();
NodeWritableStream.shim.ref();
NodePath.shim.ref();
JSReadableStreamBlob.shim.ref();
JSArrayBufferSink.shim.ref();
JSReadableStreamFile.shim.ref();
_ = ZigString__free;
_ = ZigString__free_global;
}

View File

@@ -1,4 +1,4 @@
//-- AUTOGENERATED FILE -- 1654055796
//-- AUTOGENERATED FILE -- 1655075078
// clang-format off
#pragma once
@@ -256,8 +256,8 @@ extern "C" const size_t Zig__ConsoleClient_object_align_ = alignof(Zig::ConsoleC
extern "C" const size_t Bun__Timer_object_size_ = sizeof(Bun__Timer);
extern "C" const size_t Bun__Timer_object_align_ = alignof(Bun__Timer);
const size_t sizes[31] = {sizeof(JSC::JSObject), sizeof(WebCore::DOMURL), sizeof(WebCore::FetchHeaders), sizeof(SystemError), sizeof(JSC::JSCell), sizeof(JSC::JSString), sizeof(Inspector::ScriptArguments), sizeof(JSC::JSModuleLoader), sizeof(JSC::JSModuleRecord), sizeof(JSC::JSPromise), sizeof(JSC::JSInternalPromise), sizeof(JSC::SourceOrigin), sizeof(JSC::SourceCode), sizeof(JSC::JSFunction), sizeof(JSC::JSGlobalObject), sizeof(WTF::URL), sizeof(WTF::String), sizeof(JSC::JSValue), sizeof(JSC::PropertyName), sizeof(JSC::Exception), sizeof(JSC::VM), sizeof(JSC::ThrowScope), sizeof(JSC::CatchScope), sizeof(JSC::Identifier), sizeof(WTF::StringImpl), sizeof(WTF::ExternalStringImpl), sizeof(WTF::StringView), sizeof(Zig::GlobalObject), sizeof(Bun__Readable), sizeof(Bun__Writable), sizeof(Bun__Path)};
const size_t sizes[32] = {sizeof(JSC::JSObject), sizeof(WebCore::DOMURL), sizeof(WebCore::FetchHeaders), sizeof(SystemError), sizeof(JSC::JSCell), sizeof(JSC::JSString), sizeof(Inspector::ScriptArguments), sizeof(JSC::JSModuleLoader), sizeof(JSC::JSModuleRecord), sizeof(JSC::JSPromise), sizeof(JSC::JSInternalPromise), sizeof(JSC::SourceOrigin), sizeof(JSC::SourceCode), sizeof(JSC::JSFunction), sizeof(JSC::JSGlobalObject), sizeof(WTF::URL), sizeof(WTF::String), sizeof(JSC::JSValue), sizeof(JSC::PropertyName), sizeof(JSC::Exception), sizeof(JSC::VM), sizeof(JSC::ThrowScope), sizeof(JSC::CatchScope), sizeof(JSC::Identifier), sizeof(WTF::StringImpl), sizeof(WTF::ExternalStringImpl), sizeof(WTF::StringView), sizeof(Zig::GlobalObject), sizeof(Bun__Readable), sizeof(Bun__Writable), sizeof(Bun__Path), sizeof(ArrayBufferSink)};
const char* names[31] = {"JSC__JSObject", "WebCore__DOMURL", "WebCore__FetchHeaders", "SystemError", "JSC__JSCell", "JSC__JSString", "Inspector__ScriptArguments", "JSC__JSModuleLoader", "JSC__JSModuleRecord", "JSC__JSPromise", "JSC__JSInternalPromise", "JSC__SourceOrigin", "JSC__SourceCode", "JSC__JSFunction", "JSC__JSGlobalObject", "WTF__URL", "WTF__String", "JSC__JSValue", "JSC__PropertyName", "JSC__Exception", "JSC__VM", "JSC__ThrowScope", "JSC__CatchScope", "JSC__Identifier", "WTF__StringImpl", "WTF__ExternalStringImpl", "WTF__StringView", "Zig__GlobalObject", "Bun__Readable", "Bun__Writable", "Bun__Path"};
const char* names[32] = {"JSC__JSObject", "WebCore__DOMURL", "WebCore__FetchHeaders", "SystemError", "JSC__JSCell", "JSC__JSString", "Inspector__ScriptArguments", "JSC__JSModuleLoader", "JSC__JSModuleRecord", "JSC__JSPromise", "JSC__JSInternalPromise", "JSC__SourceOrigin", "JSC__SourceCode", "JSC__JSFunction", "JSC__JSGlobalObject", "WTF__URL", "WTF__String", "JSC__JSValue", "JSC__PropertyName", "JSC__Exception", "JSC__VM", "JSC__ThrowScope", "JSC__CatchScope", "JSC__Identifier", "WTF__StringImpl", "WTF__ExternalStringImpl", "WTF__StringView", "Zig__GlobalObject", "Bun__Readable", "Bun__Writable", "Bun__Path", "ArrayBufferSink"};
const size_t aligns[31] = {alignof(JSC::JSObject), alignof(WebCore::DOMURL), alignof(WebCore::FetchHeaders), alignof(SystemError), alignof(JSC::JSCell), alignof(JSC::JSString), alignof(Inspector::ScriptArguments), alignof(JSC::JSModuleLoader), alignof(JSC::JSModuleRecord), alignof(JSC::JSPromise), alignof(JSC::JSInternalPromise), alignof(JSC::SourceOrigin), alignof(JSC::SourceCode), alignof(JSC::JSFunction), alignof(JSC::JSGlobalObject), alignof(WTF::URL), alignof(WTF::String), alignof(JSC::JSValue), alignof(JSC::PropertyName), alignof(JSC::Exception), alignof(JSC::VM), alignof(JSC::ThrowScope), alignof(JSC::CatchScope), alignof(JSC::Identifier), alignof(WTF::StringImpl), alignof(WTF::ExternalStringImpl), alignof(WTF::StringView), alignof(Zig::GlobalObject), alignof(Bun__Readable), alignof(Bun__Writable), alignof(Bun__Path)};
const size_t aligns[32] = {alignof(JSC::JSObject), alignof(WebCore::DOMURL), alignof(WebCore::FetchHeaders), alignof(SystemError), alignof(JSC::JSCell), alignof(JSC::JSString), alignof(Inspector::ScriptArguments), alignof(JSC::JSModuleLoader), alignof(JSC::JSModuleRecord), alignof(JSC::JSPromise), alignof(JSC::JSInternalPromise), alignof(JSC::SourceOrigin), alignof(JSC::SourceCode), alignof(JSC::JSFunction), alignof(JSC::JSGlobalObject), alignof(WTF::URL), alignof(WTF::String), alignof(JSC::JSValue), alignof(JSC::PropertyName), alignof(JSC::Exception), alignof(JSC::VM), alignof(JSC::ThrowScope), alignof(JSC::CatchScope), alignof(JSC::Identifier), alignof(WTF::StringImpl), alignof(WTF::ExternalStringImpl), alignof(WTF::StringView), alignof(Zig::GlobalObject), alignof(Bun__Readable), alignof(Bun__Writable), alignof(Bun__Path), alignof(ArrayBufferSink)};

View File

@@ -44,6 +44,8 @@ typedef struct SystemError {
ZigString syscall;
} SystemError;
typedef void* ArrayBufferSink;
typedef uint8_t ZigStackFrameCode;
const ZigStackFrameCode ZigStackFrameCodeNone = 0;
const ZigStackFrameCode ZigStackFrameCodeEval = 1;

View File

@@ -1,6 +1,6 @@
// GENERATED FILE - do not modify!
const bindings = @import("../../../jsc.zig");
pub const struct_JSC__CallFrame = bindings.CallFrame;
pub const struct_JSC__StringPrototype = bindings.StringPrototype;
pub const struct_JSC__SetIteratorPrototype = bindings.SetIteratorPrototype;
pub const struct_JSC__RegExpPrototype = bindings.RegExpPrototype;
@@ -17,6 +17,7 @@ pub const struct_JSC__AsyncGeneratorPrototype = bindings.AsyncGeneratorPrototype
pub const struct_JSC__AsyncGeneratorFunctionPrototype = bindings.AsyncGeneratorFunctionPrototype;
pub const struct_JSC__AsyncFunctionPrototype = bindings.AsyncFunctionPrototype;
pub const struct_JSC__ArrayPrototype = bindings.ArrayPrototype;
pub const struct_JSC__ArrayIteratorPrototype = bindings.ArrayIteratorPrototype;
pub const bWTF__URL = bindings.URL;
pub const bWTF__StringView = bindings.StringView;
@@ -63,3 +64,4 @@ pub const struct_WebCore__DOMURL = bindings.DOMURL;
pub const struct_WebCore__FetchHeaders = bindings.FetchHeaders;
pub const StringPointer = @import("../../../api/schema.zig").Api.StringPointer;
pub const struct_VirtualMachine = bindings.VirtualMachine;
pub const ArrayBufferSink = @import("../webcore/streams.zig").ArrayBufferSink;

View File

@@ -1,5 +1,5 @@
// clang-format: off
//-- AUTOGENERATED FILE -- 1654055796
//-- AUTOGENERATED FILE -- 1655075078
#pragma once
#include <stddef.h>
@@ -105,6 +105,7 @@ typedef void* JSClassRef;
typedef struct JSC__RegExpPrototype JSC__RegExpPrototype; // JSC::RegExpPrototype
typedef struct JSC__MapIteratorPrototype JSC__MapIteratorPrototype; // JSC::MapIteratorPrototype
typedef struct WebCore__FetchHeaders WebCore__FetchHeaders; // WebCore::FetchHeaders
typedef struct JSC__CallFrame JSC__CallFrame; // JSC::CallFrame
typedef bWTF__StringView WTF__StringView; // WTF::StringView
typedef bJSC__ThrowScope JSC__ThrowScope; // JSC::ThrowScope
typedef bWTF__StringImpl WTF__StringImpl; // WTF::StringImpl
@@ -165,6 +166,7 @@ typedef void* JSClassRef;
class SourceCode;
class FunctionPrototype;
class IteratorPrototype;
class CallFrame;
class ObjectPrototype;
}
namespace WTF {
@@ -228,6 +230,7 @@ typedef void* JSClassRef;
using JSC__SourceCode = JSC::SourceCode;
using JSC__FunctionPrototype = JSC::FunctionPrototype;
using JSC__IteratorPrototype = JSC::IteratorPrototype;
using JSC__CallFrame = JSC::CallFrame;
using JSC__ObjectPrototype = JSC::ObjectPrototype;
using WTF__URL = WTF::URL;
using WTF__StringImpl = WTF::StringImpl;
@@ -726,6 +729,21 @@ ZIG_DECL JSC__JSValue ByteBlob__JSReadableStreamSource__load(JSC__JSGlobalObject
ZIG_DECL JSC__JSValue FileBlobLoader__JSReadableStreamSource__load(JSC__JSGlobalObject* arg0);
#endif
CPP_DECL JSC__JSValue ArrayBufferSink__createObject(JSC__JSGlobalObject* arg0, void* arg1);
CPP_DECL void* ArrayBufferSink__fromJS(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1);
#ifdef __cplusplus
ZIG_DECL JSC__JSValue ArrayBufferSink__close(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
ZIG_DECL JSC__JSValue ArrayBufferSink__closeWithError(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
ZIG_DECL JSC__JSValue ArrayBufferSink__construct(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
ZIG_DECL JSC__JSValue ArrayBufferSink__drain(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
ZIG_DECL JSC__JSValue ArrayBufferSink__end(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
ZIG_DECL void ArrayBufferSink__finalize(void* arg0);
ZIG_DECL JSC__JSValue ArrayBufferSink__start(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
ZIG_DECL JSC__JSValue ArrayBufferSink__write(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
#endif
#ifdef __cplusplus

View File

@@ -1,6 +1,6 @@
// GENERATED FILE - do not modify!
const bindings = @import("../../../jsc.zig");
pub const struct_JSC__CallFrame = bindings.CallFrame;
pub const struct_JSC__StringPrototype = bindings.StringPrototype;
pub const struct_JSC__SetIteratorPrototype = bindings.SetIteratorPrototype;
pub const struct_JSC__RegExpPrototype = bindings.RegExpPrototype;
@@ -17,6 +17,7 @@ pub const struct_JSC__AsyncGeneratorPrototype = bindings.AsyncGeneratorPrototype
pub const struct_JSC__AsyncGeneratorFunctionPrototype = bindings.AsyncGeneratorFunctionPrototype;
pub const struct_JSC__AsyncFunctionPrototype = bindings.AsyncFunctionPrototype;
pub const struct_JSC__ArrayPrototype = bindings.ArrayPrototype;
pub const struct_JSC__ArrayIteratorPrototype = bindings.ArrayIteratorPrototype;
pub const bWTF__URL = bindings.URL;
pub const bWTF__StringView = bindings.StringView;
@@ -63,6 +64,7 @@ pub const struct_WebCore__DOMURL = bindings.DOMURL;
pub const struct_WebCore__FetchHeaders = bindings.FetchHeaders;
pub const StringPointer = @import("../../../api/schema.zig").Api.StringPointer;
pub const struct_VirtualMachine = bindings.VirtualMachine;
pub const ArrayBufferSink = @import("../webcore/streams.zig").ArrayBufferSink;
// GENERATED CODE - DO NOT MODIFY BY HAND
pub const ptrdiff_t = c_long;
@@ -116,6 +118,8 @@ pub const JSC__RegExpPrototype = struct_JSC__RegExpPrototype;
pub const JSC__MapIteratorPrototype = struct_JSC__MapIteratorPrototype;
pub const WebCore__FetchHeaders = struct_WebCore__FetchHeaders;
pub const JSC__CallFrame = struct_JSC__CallFrame;
pub const WTF__StringView = bWTF__StringView;
pub const JSC__ThrowScope = bJSC__ThrowScope;
pub const WTF__StringImpl = bWTF__StringImpl;
@@ -460,4 +464,6 @@ pub extern fn Zig__GlobalObject__resetModuleRegistryMap(arg0: [*c]JSC__JSGlobalO
pub extern fn Bun__Readable__create(arg0: [*c]Bun__Readable, arg1: [*c]JSC__JSGlobalObject) JSC__JSValue;
pub extern fn Bun__Writable__create(arg0: [*c]Bun__Writable, arg1: [*c]JSC__JSGlobalObject) JSC__JSValue;
pub extern fn Bun__Path__create(arg0: [*c]JSC__JSGlobalObject, arg1: bool) JSC__JSValue;
pub extern fn ArrayBufferSink__createObject(arg0: [*c]JSC__JSGlobalObject, arg1: ?*anyopaque) JSC__JSValue;
pub extern fn ArrayBufferSink__fromJS(arg0: [*c]JSC__JSGlobalObject, JSValue1: JSC__JSValue) ?*anyopaque;
pub extern fn ZigException__fromException(arg0: [*c]JSC__Exception) ZigException;

View File

@@ -13,6 +13,20 @@ pub fn Shimmer(comptime _namespace: []const u8, comptime _name: []const u8, comp
pub const namespace = _namespace;
pub const name = _name;
pub fn ref() void {
if (comptime @hasDecl(Parent, "Export")) {
inline for (Parent.Export) |exp| {
_ = exp;
}
}
if (comptime @hasDecl(Parent, "Extern")) {
inline for (Parent.Extern) |exp| {
_ = @field(Parent, exp);
}
}
}
// fn toCppType(comptime FromType: type) type {
// var NewReturnType = FromType;

View File

@@ -22,6 +22,8 @@ public:
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForNapiPrototype;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForJSSQLStatement;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForJSSQLStatementConstructor;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForJSSinkConstructor;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForJSSink;
/* --- bun --- */
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForDOMException;

View File

@@ -22,6 +22,8 @@ public:
std::unique_ptr<IsoSubspace> m_subspaceForNapiPrototype;
std::unique_ptr<IsoSubspace> m_subspaceForJSSQLStatement;
std::unique_ptr<IsoSubspace> m_subspaceForJSSQLStatementConstructor;
std::unique_ptr<IsoSubspace> m_subspaceForJSSinkConstructor;
std::unique_ptr<IsoSubspace> m_subspaceForJSSink;
/*-- BUN --*/
// std::unique_ptr<IsoSubspace> m_subspaceForTouch;

View File

@@ -0,0 +1,380 @@
const classes = ["ArrayBufferSink"];
function header() {
function classTemplate(idName) {
const name = `JS${idName}`;
const constructor = `${name}Constructor`;
const constructorName = `JS${name}Constructor`;
return `class ${constructor} final : public JSC::InternalFunction {
public:
using Base = JSC::InternalFunction;
static ${constructor}* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSC::JSObject* prototype);
static constexpr SinkID Sink = SinkID::${idName};
static constexpr unsigned StructureFlags = Base::StructureFlags;
static constexpr bool needsDestruction = false;
DECLARE_EXPORT_INFO;
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return WebCore::subspaceForImpl<${constructor}, WebCore::UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForJSSinkConstructor.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSSinkConstructor = WTFMove(space); },
[](auto& spaces) { return spaces.m_subspaceForJSSinkConstructor.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForJSSinkConstructor = WTFMove(space); });
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info());
}
void initializeProperties(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSObject* prototype);
// Must be defined for each specialization class.
static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*);
private:
${constructor}(JSC::VM& vm, JSC::Structure* structure, JSC::NativeFunction nativeFunction)
: Base(vm, structure, nativeFunction, nativeFunction)
{
}
void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, JSC::JSObject* prototype);
};
class ${name} final : public JSC::JSDestructibleObject {
public:
using Base = JSC::JSDestructibleObject;
static ${name}* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* sinkPtr);
static constexpr SinkID Sink = SinkID::${idName};
DECLARE_EXPORT_INFO;
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return WebCore::subspaceForImpl<${name}, WebCore::UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForJSSink.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSSink = WTFMove(space); },
[](auto& spaces) { return spaces.m_subspaceForJSSink.get(); },
[](auto& spaces, auto&& space) { spaces.m_subspaceForJSSink = WTFMove(space); });
}
static void destroy(JSC::JSCell*);
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());
}
~${name}();
void* wrapped() const { return m_sinkPtr; }
static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
void* m_sinkPtr;
${name}(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
m_sinkPtr = sinkPtr;
}
void finishCreation(JSC::VM&);
};
JSC_DECLARE_CUSTOM_GETTER(function${idName}__getter);
`;
}
const outer = `
// AUTO-GENERATED FILE. DO NOT EDIT.
// Generated by ${import.meta.path} at ${new Date().toISOString()}
//
#pragma once
#include "root.h"
#include "JSDOMWrapper.h"
#include "wtf/NeverDestroyed.h"
#include "Sink.h"
extern "C" bool JSSink_isSink(JSC::JSGlobalObject*, JSC::EncodedJSValue);
namespace WebCore {
using namespace JSC;
`;
const bottom = `JSObject* createJSSinkPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, WebCore::SinkID sinkID);
} // namespace WebCore
`;
var templ = outer;
for (let name of classes) {
templ += classTemplate(name) + "\n";
}
templ += bottom;
return templ;
}
async function implementation() {
const head = `
// AUTO-GENERATED FILE. DO NOT EDIT.
// Generated by ${import.meta.path} at ${new Date().toISOString()}
// To regenerate this file, run:
//
// bun src/javascript/jsc/generate-jssink.js
//
#include "root.h"
#include "JSSink.h"
#include "ActiveDOMObject.h"
#include "ExtendedDOMClientIsoSubspaces.h"
#include "ExtendedDOMIsoSubspaces.h"
#include "IDLTypes.h"
// #include "JSBlob.h"
#include "JSDOMAttribute.h"
#include "JSDOMBinding.h"
#include "JSDOMConstructor.h"
#include "JSDOMConvertBase.h"
#include "JSDOMConvertInterface.h"
#include "JSDOMConvertStrings.h"
#include "JSDOMExceptionHandling.h"
#include "JSDOMGlobalObject.h"
#include "JSDOMGlobalObjectInlines.h"
#include "JSDOMOperation.h"
#include "JSDOMWrapperCache.h"
#include "ScriptExecutionContext.h"
#include "WebCoreJSClientData.h"
#include "JavaScriptCore/FunctionPrototype.h"
#include "JavaScriptCore/HeapAnalyzer.h"
#include "JavaScriptCore/JSDestructibleObjectHeapCellType.h"
#include "JavaScriptCore/SlotVisitorMacros.h"
#include "JavaScriptCore/SubspaceInlines.h"
#include "wtf/GetPtr.h"
#include "wtf/PointerPreparations.h"
#include "wtf/URL.h"
#include "JavaScriptCore/BuiltinNames.h"
#include "JSBufferEncodingType.h"
#include "JSBufferPrototypeBuiltins.h"
#include "JSBufferConstructorBuiltins.h"
#include "JavaScriptCore/JSBase.h"
#if ENABLE(MEDIA_SOURCE)
#include "BufferMediaSource.h"
#include "JSMediaSource.h"
#endif
// #include "JavaScriptCore/JSTypedArrayViewPrototype.h"
#include "JavaScriptCore/JSArrayBufferViewInlines.h"
namespace WebCore {
using namespace JSC;
`;
var templ = head;
for (let name of classes) {
templ += `
JSC_DEFINE_CUSTOM_GETTER(function${name}__getter, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName))
{
auto& vm = lexicalGlobalObject->vm();
Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
return JSC::JSValue::encode(globalObject->${name}());
}
`;
}
templ += `
${(await Bun.file(import.meta.dir + "/bindings/JSSink+custom.h").text()).trim()}
`;
const footer = `
} // namespace WebCore
`;
for (let name of classes) {
const constructorName = `JS${name}Constructor`;
const className = `JS${name}`;
const prototypeName = `JS${name}Prototype`;
templ += `
#pragma mark - ${name}
class ${prototypeName} final : public JSC::JSNonFinalObject {
public:
using Base = JSC::JSNonFinalObject;
static ${prototypeName}* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure)
{
${prototypeName}* ptr = new (NotNull, JSC::allocateCell<${prototypeName}>(vm)) ${prototypeName}(vm, globalObject, structure);
ptr->finishCreation(vm, globalObject);
return ptr;
}
DECLARE_INFO;
template<typename CellType, JSC::SubspaceAccess>
static JSC::GCClient::IsoSubspace* subspaceFor(JSC::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());
}
private:
${prototypeName}(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
: Base(vm, structure)
{
}
void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
};
STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(${prototypeName}, ${prototypeName}::Base);
const ClassInfo ${prototypeName}::s_info = { "${name}"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(${prototypeName}) };
const ClassInfo ${className}::s_info = { "${name}"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(${className}) };
const ClassInfo ${constructorName}::s_info = { "${name}"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(${constructorName}) };
${className}::~${className}()
{
if (m_sinkPtr) {
${name}__finalize(m_sinkPtr);
}
}
`;
templ += `
${constructorName}* ${constructorName}::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSObject* prototype)
{
${constructorName}* ptr = new (NotNull, JSC::allocateCell<${constructorName}>(vm)) ${constructorName}(vm, structure, ${name}__construct);
ptr->finishCreation(vm, globalObject, prototype);
return ptr;
}
${className}* ${className}::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* sinkPtr)
{
${className}* ptr = new (NotNull, JSC::allocateCell<${className}>(vm)) ${className}(vm, structure, sinkPtr);
ptr->finishCreation(vm);
return ptr;
}
void ${constructorName}::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, JSObject* prototype)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
initializeProperties(vm, globalObject, prototype);
}
JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES ${constructorName}::construct(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame) {
return ${name}__construct(globalObject, callFrame);
}
void ${constructorName}::initializeProperties(VM& vm, JSC::JSGlobalObject* globalObject, JSObject* prototype)
{
putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
JSString* nameString = jsNontrivialString(vm, "${name}"_s);
m_originalName.set(vm, this, nameString);
putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
}
void ${prototypeName}::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, ${className}::info(), ${className}PrototypeTableValues, *this);
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
}
void ${className}::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
}
void ${className}::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
{
auto* thisObject = jsCast<${className}*>(cell);
if (void* wrapped = thisObject->wrapped()) {
analyzer.setWrappedObjectForCell(cell, wrapped);
// if (thisObject->scriptExecutionContext())
// analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
}
Base::analyzeHeap(cell, analyzer);
}
void ${className}::destroy(JSCell* cell)
{
static_cast<${className}*>(cell)->${className}::~${className}();
}
`;
}
templ += `
JSObject* createJSSinkPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, SinkID sinkID)
{
switch (sinkID) {
`;
for (let name of classes) {
templ += `
case ${name}:
return JS${name}Prototype::create(vm, globalObject, JS${name}Prototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
`;
}
templ += `
default:
RELEASE_ASSERT_NOT_REACHED();
}
}`;
templ += footer;
for (let name of classes) {
templ += `
extern "C" JSC__JSValue ${name}__createObject(JSC__JSGlobalObject* arg0, void* sinkPtr)
{
auto& vm = arg0->vm();
Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(arg0);
JSC::JSValue prototype = globalObject->${name}Prototype();
JSC::Structure* structure = WebCore::JS${name}::createStructure(vm, globalObject, prototype);
return JSC::JSValue::encode(WebCore::JS${name}::create(vm, globalObject, structure, sinkPtr));
}
extern "C" void* ${name}__fromJS(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1)
{
JSC::VM& vm = WebCore::getVM(arg0);
if (auto* sink = JSC::jsDynamicCast<WebCore::JS${name}*>(JSC::JSValue::decode(JSValue1)))
return sink->wrapped();
return nullptr;
}
`;
return templ;
}
}
await Bun.write(import.meta.dir + "/bindings/JSSink.h", header());
await Bun.write(
import.meta.dir + "/bindings/JSSink.cpp",
await implementation()
);

View File

@@ -85,6 +85,55 @@ pub fn Maybe(comptime ResultType: type) type {
pub const todo: @This() = @This(){ .err = Syscall.Error.todo };
pub fn toJS(this: @This(), globalThis: *JSC.JSGlobalObject) JSC.JSValue {
switch (this) {
.err => |e| {
return e.toJSC(globalThis);
},
.result => |r| {
if (comptime ReturnType == void) {
return JSC.JSValue.jsUndefined();
}
if (comptime ReturnType == JSC.ArrayBuffer) {
return r.toJS(globalThis, null);
}
if (comptime std.meta.trait.isNumber(ResultType) or std.meta.trait.isFloat(ResultType)) {
return JSC.JSValue.jsNumber(r);
}
if (comptime std.meta.trait.isZigString(ResultType)) {
if (ResultType == []u8) {
return JSC.ArrayBuffer.fromBytes(r, .ArrayBuffer).toJS(globalThis, null);
}
return JSC.ZigString.init(std.mem.span(r)).withEncoding().toValueAuto(globalThis);
}
if (comptime @typeInfo(ReturnType) == .Bool) {
return JSC.JSValue.jsBoolean(r);
}
if (comptime std.meta.trait.isContainer(ReturnType)) {
return r.toJS(globalThis);
}
@compileError("toJS Not implemented for type " ++ @typeName(ReturnType));
},
}
}
pub fn toArrayBuffer(this: @This(), globalThis: *JSC.JSGlobalObject) JSC.JSValue {
switch (this) {
.err => |e| {
return e.toJSC(globalThis);
},
.result => |r| {
return JSC.ArrayBuffer.fromBytes(r, .ArrayBuffer).toJS(globalThis, null);
},
}
}
pub inline fn getErrno(this: @This()) os.E {
return switch (this) {
.result => os.E.SUCCESS,

View File

@@ -5,6 +5,14 @@ pub usingnamespace @import("./webcore/streams.zig");
const JSC = @import("../../jsc.zig");
const std = @import("std");
pub const Lifetime = enum {
clone,
transfer,
share,
/// When reading from a fifo like STDIN/STDERR
temporary,
};
pub const Crypto = struct {
const UUID = @import("./uuid.zig");

View File

@@ -3122,14 +3122,7 @@ pub const Blob = struct {
return this.store.?.sharedView()[this.offset..][0..this.size];
}
pub const Lifetime = enum {
clone,
transfer,
share,
/// When reading from a fifo like STDIN/STDERR
temporary,
};
pub const Lifetime = JSC.WebCore.Lifetime;
pub fn setIsASCIIFlag(this: *Blob, is_all_ascii: bool) void {
this.is_all_ascii = is_all_ascii;
// if this Blob represents the entire binary data
@@ -3811,7 +3804,8 @@ pub const Body = struct {
pub const PendingValue = struct {
promise: ?JSValue = null,
stream: ?JSC.WebCore.ReadableStream = null,
readable: ?JSC.WebCore.ReadableStream = null,
// writable: JSC.WebCore.Sink
global: *JSGlobalObject,
task: ?*anyopaque = null,
@@ -3826,28 +3820,28 @@ pub const Body = struct {
pub fn setPromise(value: *PendingValue, globalThis: *JSC.JSGlobalObject, action: Action) JSValue {
value.action = action;
if (value.stream) |*stream| {
// switch (stream.ptr) {
if (value.readable) |*readable| {
// switch (readable.ptr) {
// .JavaScript
// }
switch (action) {
.getText, .getJSON, .getBlob, .getArrayBuffer => {
switch (stream.ptr) {
switch (readable.ptr) {
.Blob => unreachable,
else => {},
}
value.promise = switch (action) {
.getJSON => globalThis.readableStreamToJSON(stream.value),
.getArrayBuffer => globalThis.readableStreamToArrayBuffer(stream.value),
.getText => globalThis.readableStreamToText(stream.value),
.getBlob => globalThis.readableStreamToBlob(stream.value),
.getJSON => globalThis.readableStreamToJSON(readable.value),
.getArrayBuffer => globalThis.readableStreamToArrayBuffer(readable.value),
.getText => globalThis.readableStreamToText(readable.value),
.getBlob => globalThis.readableStreamToBlob(readable.value),
else => unreachable,
};
value.promise.?.ensureStillAlive();
stream.value.unprotect();
readable.value.unprotect();
// js now owns the memory
value.stream = null;
value.readable = null;
return value.promise.?;
},
@@ -3894,15 +3888,15 @@ pub const Body = struct {
pub const empty = Value{ .Empty = .{} };
pub fn fromReadableStream(stream: JSC.WebCore.ReadableStream, globalThis: *JSGlobalObject) Value {
if (stream.isLocked(globalThis)) {
pub fn fromReadableStream(readable: JSC.WebCore.ReadableStream, globalThis: *JSGlobalObject) Value {
if (readable.isLocked(globalThis)) {
return .{ .Error = ZigString.init("Cannot use a locked ReadableStream").toErrorInstance(globalThis) };
}
stream.value.protect();
readable.value.protect();
return .{
.Locked = .{
.stream = stream,
.readable = readable,
.global = globalThis,
},
};
@@ -3911,9 +3905,9 @@ pub const Body = struct {
pub fn resolve(this: *Value, new: *Value, global: *JSGlobalObject) void {
if (this.* == .Locked) {
var locked = &this.Locked;
if (locked.stream) |stream| {
stream.done();
locked.stream = null;
if (locked.readable) |readable| {
readable.done();
locked.readable = null;
}
if (locked.callback) |callback| {
@@ -3988,9 +3982,9 @@ pub const Body = struct {
locked.promise = null;
}
if (locked.stream) |stream| {
stream.done();
locked.stream = null;
if (locked.readable) |readable| {
readable.done();
locked.readable = null;
}
this.* = .{ .Error = error_instance };
@@ -4024,8 +4018,8 @@ pub const Body = struct {
pub fn deinit(this: *Value) void {
const tag = @as(Tag, this.*);
if (tag == .Locked) {
if (this.Locked.stream) |*stream| {
stream.done();
if (this.Locked.readable) |*readable| {
readable.done();
}
this.Locked.deinit = true;
@@ -4593,6 +4587,21 @@ fn BlobInterface(comptime Type: type) type {
blob.allocator = getAllocator(ctx);
return JSC.JSPromise.resolvedPromiseValue(ctx.ptr(), JSValue.fromRef(Blob.Class.make(ctx, ptr))).asObjectRef();
}
// pub fn getBody(
// this: *Type,
// ctx: js.JSContextRef,
// _: js.JSObjectRef,
// _: js.JSObjectRef,
// _: []const js.JSValueRef,
// _: js.ExceptionRef,
// ) js.JSValueRef {
// var value: *Body.Value = this.getBodyValue();
// switch (value.*) {
// .Empty => {},
// }
// }
};
}

File diff suppressed because it is too large Load Diff