Skip to content
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
4425fdc
add fetch abort signal
cirospaciari Feb 9, 2023
15edd3f
merge main
cirospaciari Feb 9, 2023
ddd709f
get aborted (still segfaults)
cirospaciari Feb 9, 2023
f218d11
Merge branch 'main' of https://github.com/oven-sh/bun
cirospaciari Feb 10, 2023
41614da
Merge branch 'main' into ciro/fetch-abort
cirospaciari Feb 10, 2023
a044bc3
bidings.zig u0 error
cirospaciari Feb 10, 2023
a1070d6
still GC/memory error
cirospaciari Feb 14, 2023
7b8c60b
fix start crash
cirospaciari Feb 14, 2023
67ea732
fix AbortSignal fromJS
cirospaciari Feb 14, 2023
504c0ac
change fromJS to obj.as
cirospaciari Feb 14, 2023
32b49ed
addAbortSignalEventListenner
cirospaciari Feb 14, 2023
122b9a5
handle abort types, and add tests
cirospaciari Feb 15, 2023
e84b0b9
fix tests
cirospaciari Feb 15, 2023
136d2de
Merge branch 'main' of https://github.com/oven-sh/bun
cirospaciari Feb 15, 2023
ecb5a4e
merge main
cirospaciari Feb 15, 2023
bfdf26a
add custom reason test
cirospaciari Feb 15, 2023
65db746
merge 2 substring methods, use MAKE_STATIC_STRING_IMPL
cirospaciari Feb 15, 2023
aec0efb
fix create AbortError and TimeoutError, move globalThis and exception…
cirospaciari Feb 15, 2023
a01a15b
Merge branch 'main' of https://github.com/oven-sh/bun
cirospaciari Feb 15, 2023
09e59c2
Merge branch 'main' into ciro/fetch-abort
cirospaciari Feb 15, 2023
a4dd7ba
fix tests and rebuild headers
cirospaciari Feb 15, 2023
e424f6f
no need to check with substring reason is already an exception
cirospaciari Feb 15, 2023
d6c1217
no need to check with substring reason is already an exception
cirospaciari Feb 15, 2023
6716d5e
fix dumb error inverting conditions for check reason
cirospaciari Feb 15, 2023
a76eb9e
fix custom reason behavior
cirospaciari Feb 15, 2023
ec6f8df
Request signal
cirospaciari Feb 18, 2023
aaa0aba
update branch
cirospaciari Feb 18, 2023
59659ee
remove package-lock.json
cirospaciari Feb 18, 2023
df75246
Remove JSC.Strong from Request signal
cirospaciari Feb 18, 2023
587a898
fix globals for fetch abort signal
cirospaciari Feb 18, 2023
9826ea6
more tests, clone signal crashs
cirospaciari Feb 18, 2023
c968b72
fix AbortSignal.toJS
cirospaciari Feb 18, 2023
5b2e809
fix toJS bidings for AbortSignal
cirospaciari Feb 20, 2023
c28cd45
add streaming tests
cirospaciari Feb 20, 2023
8c9017c
fix abortion before connecting
cirospaciari Feb 20, 2023
e874f14
fix tests and segfault
cirospaciari Feb 20, 2023
799864f
add fetch testing abort after finish
cirospaciari Feb 20, 2023
9c01cb6
fix signal handler cleanup
cirospaciari Feb 20, 2023
cbbec6c
support signal event Bun.serve
cirospaciari Feb 21, 2023
a89cfa0
pull tests (failing)
cirospaciari Feb 21, 2023
6198e5d
remove unsupported test
cirospaciari Feb 22, 2023
2b274e2
Merge branch 'main' into ciro/fetch-abort
cirospaciari Feb 22, 2023
2817ba7
formating
cirospaciari Feb 22, 2023
f5fe5bd
Merge branch 'ciro/fetch-abort' of https://github.com/oven-sh/bun int…
cirospaciari Feb 22, 2023
483a9f8
fix server Request.signal, fix cleanNativeBindings
cirospaciari Feb 22, 2023
32f6db9
add direct tests
cirospaciari Feb 22, 2023
a79356e
more pull tests
cirospaciari Feb 22, 2023
ff2d14c
fix stream tests
cirospaciari Feb 23, 2023
a3cc758
fix fetch, pending onAborted fix in HTTPServerWritable
cirospaciari Feb 23, 2023
116ef78
Merge branch 'main' into ciro/fetch-abort
Jarred-Sumner Feb 23, 2023
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: 0 additions & 2 deletions packages/bun-types/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,6 @@ declare class Request implements BlobInterface {
readonly referrerPolicy: ReferrerPolicy;
/**
* Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler.
*
* Note: this is **not implemented yet**. The cake is a lie.
*/
readonly signal: AbortSignal;

Expand Down
18 changes: 17 additions & 1 deletion src/bun.js/api/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@ pub const ServerConfig = struct {
args.base_url = URL.parse(args.base_uri);
}
} else {

const hostname: string =
if (has_hostname and std.mem.span(args.hostname).len > 0) std.mem.span(args.hostname) else "0.0.0.0";
const protocol: string = if (args.ssl_config != null) "https" else "http";
Expand Down Expand Up @@ -1011,6 +1010,15 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
// User called .blob(), .json(), text(), or .arrayBuffer() on the Request object
// but we received nothing or the connection was aborted
if (request_js.as(Request)) |req| {
if (req.signal) |signal| {
// if signal is not aborted, abort the signal
if (!signal.aborted()) {
const reason = JSC.AbortSignal.createAbortError(JSC.ZigString.static("The user aborted a request"), &JSC.ZigString.Empty, this.server.globalThis);
reason.ensureStillAlive();
_ = signal.signal(reason);
}
}

// the promise is pending
if (req.body == .Locked and (req.body.Locked.action != .none or req.body.Locked.promise != null)) {
this.pending_promises_for_abort += 1;
Expand Down Expand Up @@ -1079,6 +1087,14 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
// User called .blob(), .json(), text(), or .arrayBuffer() on the Request object
// but we received nothing or the connection was aborted
if (request_js.as(Request)) |req| {
if (req.signal) |signal| {
// if signal is not aborted, abort the signal
if (!signal.aborted()) {
const reason = JSC.AbortSignal.createAbortError(JSC.ZigString.static("The user aborted a request"), &JSC.ZigString.Empty, this.server.globalThis);
reason.ensureStillAlive();
_ = signal.signal(reason);
}
}
// the promise is pending
if (req.body == .Locked and req.body.Locked.action != .none and req.body.Locked.promise != null) {
req.body.toErrorInstance(JSC.toTypeError(.ABORT_ERR, "Request aborted", .{}, this.server.globalThis), this.server.globalThis);
Expand Down
37 changes: 37 additions & 0 deletions src/bun.js/bindings/ZigGeneratedClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6201,6 +6201,9 @@ JSC_DECLARE_CUSTOM_GETTER(RequestPrototype__referrerGetterWrap);
extern "C" JSC::EncodedJSValue RequestPrototype__getReferrerPolicy(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
JSC_DECLARE_CUSTOM_GETTER(RequestPrototype__referrerPolicyGetterWrap);

extern "C" JSC::EncodedJSValue RequestPrototype__getSignal(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
JSC_DECLARE_CUSTOM_GETTER(RequestPrototype__signalGetterWrap);

extern "C" EncodedJSValue RequestPrototype__getText(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
JSC_DECLARE_HOST_FUNCTION(RequestPrototype__textCallback);

Expand All @@ -6227,6 +6230,7 @@ static const HashTableValue JSRequestPrototypeTableValues[] = {
{ "redirect"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, RequestPrototype__redirectGetterWrap, 0 } },
{ "referrer"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, RequestPrototype__referrerGetterWrap, 0 } },
{ "referrerPolicy"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, RequestPrototype__referrerPolicyGetterWrap, 0 } },
{ "signal"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, RequestPrototype__signalGetterWrap, 0 } },
{ "text"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::NativeFunctionType, RequestPrototype__textCallback, 0 } },
{ "url"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute | PropertyAttribute::DontDelete), NoIntrinsic, { HashTableValue::GetterSetterType, RequestPrototype__urlGetterWrap, 0 } }
};
Expand Down Expand Up @@ -6507,6 +6511,37 @@ JSC_DEFINE_CUSTOM_GETTER(RequestPrototype__referrerPolicyGetterWrap, (JSGlobalOb
RELEASE_AND_RETURN(throwScope, result);
}

JSC_DEFINE_CUSTOM_GETTER(RequestPrototype__signalGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
{
auto& vm = lexicalGlobalObject->vm();
Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
JSRequest* thisObject = jsCast<JSRequest*>(JSValue::decode(thisValue));
JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);

if (JSValue cachedValue = thisObject->m_signal.get())
return JSValue::encode(cachedValue);

JSC::JSValue result = JSC::JSValue::decode(
RequestPrototype__getSignal(thisObject->wrapped(), globalObject));
RETURN_IF_EXCEPTION(throwScope, {});
thisObject->m_signal.set(vm, thisObject, result);
RELEASE_AND_RETURN(throwScope, JSValue::encode(result));
}

extern "C" void RequestPrototype__signalSetCachedValue(JSC::EncodedJSValue thisValue, JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value)
{
auto& vm = globalObject->vm();
auto* thisObject = jsCast<JSRequest*>(JSValue::decode(thisValue));
thisObject->m_signal.set(vm, thisObject, JSValue::decode(value));
}

extern "C" EncodedJSValue RequestPrototype__signalGetCachedValue(JSC::EncodedJSValue thisValue)
{
auto* thisObject = jsCast<JSRequest*>(JSValue::decode(thisValue));
return JSValue::encode(thisObject->m_signal.get());
}

JSC_DEFINE_HOST_FUNCTION(RequestPrototype__textCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
{
auto& vm = lexicalGlobalObject->vm();
Expand Down Expand Up @@ -6720,6 +6755,7 @@ void JSRequest::visitChildrenImpl(JSCell* cell, Visitor& visitor)
}
visitor.append(thisObject->m_body);
visitor.append(thisObject->m_headers);
visitor.append(thisObject->m_signal);
visitor.append(thisObject->m_url);
}

Expand All @@ -6733,6 +6769,7 @@ void JSRequest::visitAdditionalChildren(Visitor& visitor)

visitor.append(thisObject->m_body);
visitor.append(thisObject->m_headers);
visitor.append(thisObject->m_signal);
visitor.append(thisObject->m_url);
;
}
Expand Down
1 change: 1 addition & 0 deletions src/bun.js/bindings/ZigGeneratedClasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ class JSRequest final : public JSC::JSDestructibleObject {

mutable JSC::WriteBarrier<JSC::Unknown> m_body;
mutable JSC::WriteBarrier<JSC::Unknown> m_headers;
mutable JSC::WriteBarrier<JSC::Unknown> m_signal;
mutable JSC::WriteBarrier<JSC::Unknown> m_url;
};

Expand Down
23 changes: 21 additions & 2 deletions src/bun.js/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3819,8 +3819,22 @@ extern "C" void JSC__JSGlobalObject__queueMicrotaskJob(JSC__JSGlobalObject* arg0
JSC::JSValue::decode(JSValue4));
}

extern "C" JSC__AbortSignal* JSC__AbortSignal__signal(JSC__AbortSignal* arg0, JSC__JSValue JSValue1)
{
extern "C" JSC__JSValue JSC__AbortSignal__create(JSC__JSGlobalObject* globalObject) {
Zig::GlobalObject* thisObject = JSC::jsCast<Zig::GlobalObject*>(globalObject);
auto* context = thisObject->scriptExecutionContext();
auto abortSignal = WebCore::AbortSignal::create(context);

return JSValue::encode(toJSNewlyCreated<IDLInterface<JSC__AbortSignal>>(*globalObject, *jsCast<JSDOMGlobalObject*>(globalObject), WTFMove(abortSignal)));
}
extern "C" JSC__JSValue JSC__AbortSignal__toJS(JSC__AbortSignal* arg0, JSC__JSGlobalObject* globalObject) {
WebCore::AbortSignal* abortSignal = reinterpret_cast<WebCore::AbortSignal*>(arg0);

return JSValue::encode(toJS<IDLInterface<JSC__AbortSignal>>(*globalObject, *jsCast<JSDOMGlobalObject*>(globalObject), *abortSignal));
}


extern "C" JSC__AbortSignal* JSC__AbortSignal__signal(JSC__AbortSignal* arg0, JSC__JSValue JSValue1) {

WebCore::AbortSignal* abortSignal = reinterpret_cast<WebCore::AbortSignal*>(arg0);
abortSignal->signalAbort(JSC::JSValue::decode(JSValue1));
return arg0;
Expand Down Expand Up @@ -3851,6 +3865,10 @@ extern "C" JSC__AbortSignal* JSC__AbortSignal__unref(JSC__AbortSignal* arg0)
abortSignal->deref();
return arg0;
}
extern "C" void JSC__AbortSignal__cleanNativeBindings(JSC__AbortSignal* arg0, void* arg1) {
WebCore::AbortSignal* abortSignal = reinterpret_cast<WebCore::AbortSignal*>(arg0);
abortSignal->cleanNativeBindings(arg1);
}

extern "C" JSC__AbortSignal* JSC__AbortSignal__addListener(JSC__AbortSignal* arg0, void* ctx, void (*callback)(void* ctx, JSC__JSValue reason))
{
Expand Down Expand Up @@ -3919,6 +3937,7 @@ extern "C" JSC__JSValue JSC__AbortSignal__createTimeoutError(const ZigString* me

return JSC::JSValue::encode(error);
}

#pragma mark - WebCore::DOMFormData

CPP_DECL void WebCore__DOMFormData__append(WebCore__DOMFormData* arg0, ZigString* arg1, ZigString* arg2)
Expand Down
18 changes: 17 additions & 1 deletion src/bun.js/bindings/bindings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,11 @@ pub const AbortSignal = extern opaque {
) *AbortSignal {
return cppFn("addListener", .{ this, ctx, callback });
}

pub fn cleanNativeBindings(this: *AbortSignal, ctx: ?*anyopaque) void {
return cppFn("cleanNativeBindings", .{ this, ctx });
}

pub fn signal(
this: *AbortSignal,
reason: JSValue,
Expand Down Expand Up @@ -1728,6 +1733,14 @@ pub const AbortSignal = extern opaque {
return cppFn("fromJS", .{value});
}

pub fn toJS(this: *AbortSignal, global: *JSGlobalObject) JSValue {
return cppFn("toJS", .{this, global});
}

pub fn create(global: *JSGlobalObject) JSValue {
return cppFn("create", .{ global });
}

pub fn createAbortError(message: *const ZigString, code: *const ZigString, global: *JSGlobalObject) JSValue {
return cppFn("createAbortError", .{ message, code, global });
}
Expand All @@ -1739,13 +1752,16 @@ pub const AbortSignal = extern opaque {
pub const Extern = [_][]const u8{
"createAbortError",
"createTimeoutError",
"create",
"ref",
"unref",
"signal",
"abortReason",
"aborted",
"addListener",
"fromJS",
"toJS",
"cleanNativeBindings"
};
};

Expand Down Expand Up @@ -3557,7 +3573,7 @@ pub const JSValue = enum(JSValueReprInt) {
status,
url,
body,
data,
data
};

// intended to be more lightweight than ZigString
Expand Down
26 changes: 26 additions & 0 deletions src/bun.js/bindings/generated_classes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1680,6 +1680,28 @@ pub const JSRequest = struct {
return result;
}

extern fn RequestPrototype__signalSetCachedValue(JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) void;

extern fn RequestPrototype__signalGetCachedValue(JSC.JSValue) JSC.JSValue;

/// `Request.signal` setter
/// This value will be visited by the garbage collector.
pub fn signalSetCached(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void {
JSC.markBinding(@src());
RequestPrototype__signalSetCachedValue(thisValue, globalObject, value);
}

/// `Request.signal` getter
/// This value will be visited by the garbage collector.
pub fn signalGetCached(thisValue: JSC.JSValue) ?JSC.JSValue {
JSC.markBinding(@src());
const result = RequestPrototype__signalGetCachedValue(thisValue);
if (result == .zero)
return null;

return result;
}

extern fn RequestPrototype__urlSetCachedValue(JSC.JSValue, *JSC.JSGlobalObject, JSC.JSValue) void;

extern fn RequestPrototype__urlGetCachedValue(JSC.JSValue) JSC.JSValue;
Expand Down Expand Up @@ -1799,6 +1821,9 @@ pub const JSRequest = struct {
if (@TypeOf(Request.getReferrerPolicy) != GetterType)
@compileLog("Expected Request.getReferrerPolicy to be a getter");

if (@TypeOf(Request.getSignal) != GetterType)
@compileLog("Expected Request.getSignal to be a getter");

if (@TypeOf(Request.getText) != CallbackType)
@compileLog("Expected Request.getText to be a callback but received " ++ @typeName(@TypeOf(Request.getText)));
if (@TypeOf(Request.getUrl) != GetterType)
Expand All @@ -1825,6 +1850,7 @@ pub const JSRequest = struct {
@export(Request.getRedirect, .{ .name = "RequestPrototype__getRedirect" });
@export(Request.getReferrer, .{ .name = "RequestPrototype__getReferrer" });
@export(Request.getReferrerPolicy, .{ .name = "RequestPrototype__getReferrerPolicy" });
@export(Request.getSignal, .{ .name = "RequestPrototype__getSignal" });
@export(Request.getText, .{ .name = "RequestPrototype__getText" });
@export(Request.getUrl, .{ .name = "RequestPrototype__getUrl" });
}
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/bindings/headers-cpp.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//-- AUTOGENERATED FILE -- 1676656020
//-- AUTOGENERATED FILE -- 1676922916
// clang-format off
#pragma once

Expand Down
5 changes: 4 additions & 1 deletion src/bun.js/bindings/headers.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// clang-format off
//-- AUTOGENERATED FILE -- 1676945760
//-- AUTOGENERATED FILE -- 1676922916
#pragma once

#include <stddef.h>
Expand Down Expand Up @@ -210,11 +210,14 @@ CPP_DECL JSC__JSInternalPromise* JSC__JSModuleLoader__loadAndEvaluateModule(JSC_
CPP_DECL bool JSC__AbortSignal__aborted(JSC__AbortSignal* arg0);
CPP_DECL JSC__JSValue JSC__AbortSignal__abortReason(JSC__AbortSignal* arg0);
CPP_DECL JSC__AbortSignal* JSC__AbortSignal__addListener(JSC__AbortSignal* arg0, void* arg1, void(* ArgFn2)(void* arg0, JSC__JSValue JSValue1)) __attribute__((nonnull (2)));
CPP_DECL void JSC__AbortSignal__cleanNativeBindings(JSC__AbortSignal* arg0, void* arg1);
CPP_DECL JSC__JSValue JSC__AbortSignal__create(JSC__JSGlobalObject* arg0);
CPP_DECL JSC__JSValue JSC__AbortSignal__createAbortError(const ZigString* arg0, const ZigString* arg1, JSC__JSGlobalObject* arg2);
CPP_DECL JSC__JSValue JSC__AbortSignal__createTimeoutError(const ZigString* arg0, const ZigString* arg1, JSC__JSGlobalObject* arg2);
CPP_DECL JSC__AbortSignal* JSC__AbortSignal__fromJS(JSC__JSValue JSValue0);
CPP_DECL JSC__AbortSignal* JSC__AbortSignal__ref(JSC__AbortSignal* arg0);
CPP_DECL JSC__AbortSignal* JSC__AbortSignal__signal(JSC__AbortSignal* arg0, JSC__JSValue JSValue1);
CPP_DECL JSC__JSValue JSC__AbortSignal__toJS(JSC__AbortSignal* arg0, JSC__JSGlobalObject* arg1);
CPP_DECL JSC__AbortSignal* JSC__AbortSignal__unref(JSC__AbortSignal* arg0);

#pragma mark - JSC::JSPromise
Expand Down
3 changes: 3 additions & 0 deletions src/bun.js/bindings/headers.zig
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,14 @@ pub extern fn JSC__JSModuleLoader__loadAndEvaluateModule(arg0: *bindings.JSGloba
pub extern fn JSC__AbortSignal__aborted(arg0: ?*bindings.AbortSignal) bool;
pub extern fn JSC__AbortSignal__abortReason(arg0: ?*bindings.AbortSignal) JSC__JSValue;
pub extern fn JSC__AbortSignal__addListener(arg0: ?*bindings.AbortSignal, arg1: ?*anyopaque, ArgFn2: ?*const fn (?*anyopaque, JSC__JSValue) callconv(.C) void) ?*bindings.AbortSignal;
pub extern fn JSC__AbortSignal__cleanNativeBindings(arg0: ?*bindings.AbortSignal, arg1: ?*anyopaque) void;
pub extern fn JSC__AbortSignal__create(arg0: *bindings.JSGlobalObject) JSC__JSValue;
pub extern fn JSC__AbortSignal__createAbortError(arg0: [*c]const ZigString, arg1: [*c]const ZigString, arg2: *bindings.JSGlobalObject) JSC__JSValue;
pub extern fn JSC__AbortSignal__createTimeoutError(arg0: [*c]const ZigString, arg1: [*c]const ZigString, arg2: *bindings.JSGlobalObject) JSC__JSValue;
pub extern fn JSC__AbortSignal__fromJS(JSValue0: JSC__JSValue) ?*bindings.AbortSignal;
pub extern fn JSC__AbortSignal__ref(arg0: ?*bindings.AbortSignal) ?*bindings.AbortSignal;
pub extern fn JSC__AbortSignal__signal(arg0: ?*bindings.AbortSignal, JSValue1: JSC__JSValue) ?*bindings.AbortSignal;
pub extern fn JSC__AbortSignal__toJS(arg0: ?*bindings.AbortSignal, arg1: *bindings.JSGlobalObject) JSC__JSValue;
pub extern fn JSC__AbortSignal__unref(arg0: ?*bindings.AbortSignal) ?*bindings.AbortSignal;
pub extern fn JSC__JSPromise__asValue(arg0: ?*bindings.JSPromise, arg1: *bindings.JSGlobalObject) JSC__JSValue;
pub extern fn JSC__JSPromise__create(arg0: *bindings.JSGlobalObject) ?*bindings.JSPromise;
Expand Down
9 changes: 9 additions & 0 deletions src/bun.js/bindings/webcore/AbortSignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ void AbortSignal::signalAbort(JSC::JSValue reason)
dispatchEvent(Event::create(eventNames().abortEvent, Event::CanBubble::No, Event::IsCancelable::No));
}

void AbortSignal::cleanNativeBindings(void* ref) {
auto callbacks = std::exchange(m_native_callbacks, {});

callbacks.removeAllMatching([=](auto callback){
const auto [ ctx, func ] = callback;
return ctx == ref;
});
}

// https://dom.spec.whatwg.org/#abortsignal-follow
void AbortSignal::signalFollow(AbortSignal& signal)
{
Expand Down
1 change: 1 addition & 0 deletions src/bun.js/bindings/webcore/AbortSignal.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class AbortSignal final : public RefCounted<AbortSignal>, public EventTargetWith

using Algorithm = Function<void(JSValue)>;
void addAlgorithm(Algorithm&& algorithm) { m_algorithms.append(WTFMove(algorithm)); }
void cleanNativeBindings(void* ref);
void addNativeCallback(std::tuple<void*, void (*)(void*, JSC::EncodedJSValue)> callback) { m_native_callbacks.append(callback); }

bool isFollowingSignal() const { return !!m_followingSignal; }
Expand Down
Loading