Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/codegen/generate-jssink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const classes = [
"H3ResponseSink",
"NetworkSink",
"FetchRequestBodySink",
"HTMLRewriterInputSink",
];

function names(name) {
Expand Down Expand Up @@ -1054,6 +1055,7 @@ function rustSink() {
H3ResponseSink: "crate::webcore::streams::H3ResponseSink",
NetworkSink: "crate::webcore::streams::NetworkSink",
FetchRequestBodySink: "crate::webcore::fetch::fetch_request_body_sink::FetchRequestBodySink",
HTMLRewriterInputSink: "crate::api::html_rewriter::HTMLRewriterInputSink",
};

const symbols: string[] = [];
Expand Down
1 change: 0 additions & 1 deletion src/jsc/bindings/NativePromiseContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class NativePromiseContext final : public JSC::JSCell {
HTTPSServerRequestContext,
DebugHTTPServerRequestContext,
DebugHTTPSServerRequestContext,
BodyValueBufferer,
HTTPSServerH3RequestContext,
DebugHTTPSServerH3RequestContext,
};
Expand Down
3 changes: 2 additions & 1 deletion src/jsc/bindings/Sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ enum SinkID : uint8_t {
NetworkSink = 6,
H3ResponseSink = 7,
FetchRequestBodySink = 8,
HTMLRewriterInputSink = 9,

};
static constexpr unsigned numberOfSinkIDs
= 9;
= 10;

}
18 changes: 14 additions & 4 deletions src/jsc/bindings/ZigGlobalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2687,6 +2687,16 @@ void GlobalObject::finishCreation(VM& vm)
init.setConstructor(constructor);
});

m_JSHTMLRewriterInputSinkClassStructure.initLater(
[](LazyClassStructure::Initializer& init) {
auto* prototype = createJSSinkPrototype(init.vm, init.global, WebCore::SinkID::HTMLRewriterInputSink);
auto* structure = JSHTMLRewriterInputSink::createStructure(init.vm, init.global, prototype);
auto* constructor = JSHTMLRewriterInputSinkConstructor::create(init.vm, init.global, JSHTMLRewriterInputSinkConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), prototype);
init.setPrototype(prototype);
init.setStructure(structure);
init.setConstructor(constructor);
});

m_JSBufferClassStructure.initLater(
[](LazyClassStructure::Initializer& init) {
auto* prototype = WebCore::createBufferPrototype(init.vm, init.global);
Expand Down Expand Up @@ -4053,10 +4063,10 @@ GlobalObject::PromiseFunctions GlobalObject::promiseHandlerID(Zig::FFIFunction h
return GlobalObject::PromiseFunctions::Bun__TestScope__Describe2__bunTestThen;
} else if (handler == Bun__TestScope__Describe2__bunTestCatch) {
return GlobalObject::PromiseFunctions::Bun__TestScope__Describe2__bunTestCatch;
} else if (handler == Bun__BodyValueBufferer__onResolveStream) {
return GlobalObject::PromiseFunctions::Bun__BodyValueBufferer__onResolveStream;
} else if (handler == Bun__BodyValueBufferer__onRejectStream) {
return GlobalObject::PromiseFunctions::Bun__BodyValueBufferer__onRejectStream;
} else if (handler == Bun__HTMLRewriterInput__onResolveStream) {
return GlobalObject::PromiseFunctions::Bun__HTMLRewriterInput__onResolveStream;
} else if (handler == Bun__HTMLRewriterInput__onRejectStream) {
return GlobalObject::PromiseFunctions::Bun__HTMLRewriterInput__onRejectStream;
} else if (handler == Bun__onResolveEntryPointResult) {
return GlobalObject::PromiseFunctions::Bun__onResolveEntryPointResult;
} else if (handler == Bun__onRejectEntryPointResult) {
Expand Down
9 changes: 7 additions & 2 deletions src/jsc/bindings/ZigGlobalObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ class GlobalObject : public Bun::GlobalScope {
JSC::Structure* FetchRequestBodySinkStructure() const { return m_JSFetchRequestBodySinkClassStructure.getInitializedOnMainThread(this); }
JSC::JSObject* FetchRequestBodySink() { return m_JSFetchRequestBodySinkClassStructure.constructorInitializedOnMainThread(this); }
JSC::JSValue FetchRequestBodySinkPrototype() const { return m_JSFetchRequestBodySinkClassStructure.prototypeInitializedOnMainThread(this); }

JSC::Structure* HTMLRewriterInputSinkStructure() const { return m_JSHTMLRewriterInputSinkClassStructure.getInitializedOnMainThread(this); }
JSC::JSObject* HTMLRewriterInputSink() { return m_JSHTMLRewriterInputSinkClassStructure.constructorInitializedOnMainThread(this); }
JSC::JSValue HTMLRewriterInputSinkPrototype() const { return m_JSHTMLRewriterInputSinkClassStructure.prototypeInitializedOnMainThread(this); }
JSC::JSValue JSReadableNetworkSinkControllerPrototype() const { return m_JSFetchTaskletChunkedRequestControllerPrototype.getInitializedOnMainThread(this); }

JSC::Structure* JSBufferListStructure() const { return m_JSBufferListClassStructure.getInitializedOnMainThread(this); }
Expand Down Expand Up @@ -398,8 +402,8 @@ class GlobalObject : public Bun::GlobalScope {
jsFunctionOnLoadObjectResultReject,
Bun__TestScope__Describe2__bunTestThen,
Bun__TestScope__Describe2__bunTestCatch,
Bun__BodyValueBufferer__onRejectStream,
Bun__BodyValueBufferer__onResolveStream,
Bun__HTMLRewriterInput__onResolveStream,
Bun__HTMLRewriterInput__onRejectStream,
Bun__onResolveEntryPointResult,
Bun__onRejectEntryPointResult,
Bun__NodeHTTPRequest__onResolve,
Expand Down Expand Up @@ -568,6 +572,7 @@ class GlobalObject : public Bun::GlobalScope {
V(private, LazyClassStructure, m_JSNetworkSinkClassStructure) \
V(private, LazyClassStructure, m_JSH3ResponseSinkClassStructure) \
V(private, LazyClassStructure, m_JSFetchRequestBodySinkClassStructure) \
V(private, LazyClassStructure, m_JSHTMLRewriterInputSinkClassStructure) \
\
V(private, LazyClassStructure, m_JSStringDecoderClassStructure) \
V(private, LazyPropertyOfGlobalObject<JSObject>, m_JSFFICStringConstructor) \
Expand Down
30 changes: 20 additions & 10 deletions src/jsc/bindings/headers.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/jsc/bindings/webcore/streams/BunStreamSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ static void startJSSinkController(JSC::VM& vm, JSGlobalObject* globalObject, JSO
BUN_START_JSSINK_CONTROLLER(JSReadableH3ResponseSinkController)
BUN_START_JSSINK_CONTROLLER(JSReadableNetworkSinkController)
BUN_START_JSSINK_CONTROLLER(JSReadableFetchRequestBodySinkController)
BUN_START_JSSINK_CONTROLLER(JSReadableHTMLRewriterInputSinkController)
#undef BUN_START_JSSINK_CONTROLLER
throwTypeError(globalObject, scope, "Unknown direct controller. This is a bug in Bun."_s);
}
Expand Down
25 changes: 3 additions & 22 deletions src/runtime/api/NativePromiseContext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ use bun_event_loop::{Task, TaskTag, Taskable, task_tag};
use bun_jsc::virtual_machine::VirtualMachine;
use bun_jsc::{JSGlobalObject, JSValue};

use crate::api::html_rewriter;
use crate::api::server;
use crate::webcore::body;

// Request contexts are a single generic
// `NewRequestContext<ThisServer, SSL, DEBUG, HTTP3>`; alias the six
Expand All @@ -55,13 +53,12 @@ pub enum Tag {
HTTPSServerRequestContext,
DebugHTTPServerRequestContext,
DebugHTTPSServerRequestContext,
BodyValueBufferer,
HTTPSServerH3RequestContext,
DebugHTTPSServerH3RequestContext,
}

impl Tag {
pub const COUNT: usize = 7;
pub const COUNT: usize = 6;

#[inline]
const fn from_raw(n: u8) -> Tag {
Expand All @@ -70,9 +67,8 @@ impl Tag {
1 => Tag::HTTPSServerRequestContext,
2 => Tag::DebugHTTPServerRequestContext,
3 => Tag::DebugHTTPSServerRequestContext,
4 => Tag::BodyValueBufferer,
5 => Tag::HTTPSServerH3RequestContext,
6 => Tag::DebugHTTPSServerH3RequestContext,
4 => Tag::HTTPSServerH3RequestContext,
5 => Tag::DebugHTTPSServerH3RequestContext,
_ => unreachable!(),
}
}
Expand Down Expand Up @@ -105,9 +101,6 @@ impl<ThisServer, const SSL: bool, const DBG: bool, const H3: bool> NativePromise
{
const TAG: Tag = npc_tag_for(SSL, DBG, H3);
}
impl NativePromiseContextType for body::ValueBufferer<'_> {
const TAG: Tag = Tag::BodyValueBufferer;
}

// `&JSGlobalObject` is ABI-identical to a non-null pointer. `ctx` is stored
// opaquely (never dereferenced by the C++ side), so the FFI itself has no
Expand Down Expand Up @@ -218,16 +211,6 @@ impl DeferredDerefTask {
Tag::DebugHTTPSServerRequestContext => {
(*ctx.cast::<DebugHTTPSServerRequestContext>()).deref()
}
Tag::BodyValueBufferer => {
// ValueBufferer is embedded by value inside HTMLRewriter's
// BufferOutputSink, with the owner pointer stored in .ctx.
// The pending-promise ref was taken on the owner, so we
// release it there.
let bufferer = &*ctx.cast::<body::ValueBufferer<'_>>();
html_rewriter::BufferOutputSink::deref(
bufferer.ctx.cast::<html_rewriter::BufferOutputSink>(),
);
}
Tag::HTTPSServerH3RequestContext => {
(*ctx.cast::<HTTPSServerH3RequestContext>()).deref()
}
Expand All @@ -250,5 +233,3 @@ const _: () =
assert!(core::mem::align_of::<DebugHTTPServerRequestContext>() > DeferredDerefTask::TAG_MASK);
const _: () =
assert!(core::mem::align_of::<DebugHTTPSServerRequestContext>() > DeferredDerefTask::TAG_MASK);
const _: () =
assert!(core::mem::align_of::<body::ValueBufferer<'_>>() > DeferredDerefTask::TAG_MASK);
Loading
Loading