Rollback XHR/HTTP.client change

This PR will be only for having the destructor hook. XHR/http.client changes to
leverage this will be done in a subsequent PR.
This commit is contained in:
Karl Seguin
2025-05-21 11:38:26 +08:00
parent f42bd02cfc
commit ce832a8063
4 changed files with 21 additions and 29 deletions

View File

@@ -103,7 +103,7 @@ pub const MutationObserver = struct {
}
}
pub fn jsCallScopeEnd(self: *MutationObserver, _: anytype) void {
pub fn jsCallScopeEnd(self: *MutationObserver) void {
const record = self.observed.items;
if (record.len == 0) {
return;

View File

@@ -257,10 +257,6 @@ pub const XMLHttpRequest = struct {
};
}
pub fn destructor(self: *XMLHttpRequest, _: anytype) void {
self._abort();
}
pub fn reset(self: *XMLHttpRequest) void {
self.url = null;
@@ -539,10 +535,6 @@ pub const XMLHttpRequest = struct {
}
pub fn _abort(self: *XMLHttpRequest) void {
const request = &(self.request orelse return);
// safe to call even if the request is complete
request.abort();
self.onErr(DOMError.Abort);
}

View File

@@ -261,13 +261,6 @@ pub const Request = struct {
self._client.state_pool.release(self._state);
}
pub fn abort(self: *Request) void {
const connection = self._connection orelse return;
self.destroyConnection(connection);
self._connection = null;
self.deinit();
}
const DecomposedURL = struct {
secure: bool,
connect_port: u16,

View File

@@ -539,8 +539,15 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
// no init, started with executor.startScope()
fn deinit(self: *Scope) void {
for (self.destructor_callbacks.items) |cb| {
cb.destructor(self);
{
// reverse order, as this has more chance of respecting any
// dependencies objects might have with each other.
const items = self.destructor_callbacks.items;
var i = items.len;
while (i > 0) {
i -= 1;
items[i].destructor();
}
}
{
@@ -1687,16 +1694,16 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
// called when the call scope ends
const DestructorCallback = struct {
ptr: *anyopaque,
destructorFn: *const fn (ptr: *anyopaque, scope: *Scope) void,
destructorFn: *const fn (ptr: *anyopaque) void,
fn init(ptr: anytype) DestructorCallback {
const T = @TypeOf(ptr);
const ptr_info = @typeInfo(T);
const gen = struct {
pub fn destructor(pointer: *anyopaque, scope: *Scope) void {
pub fn destructor(pointer: *anyopaque) void {
const self: T = @ptrCast(@alignCast(pointer));
return ptr_info.pointer.child.destructor(self, scope);
return ptr_info.pointer.child.destructor(self);
}
};
@@ -1706,8 +1713,8 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
};
}
pub fn destructor(self: DestructorCallback, scope: *Scope) void {
self.destructorFn(self.ptr, scope);
pub fn destructor(self: DestructorCallback) void {
self.destructorFn(self.ptr);
}
};
@@ -1715,16 +1722,16 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
// called when the call scope ends
const CallScopeEndCallback = struct {
ptr: *anyopaque,
callScopeEndFn: *const fn (ptr: *anyopaque, scope: *Scope) void,
callScopeEndFn: *const fn (ptr: *anyopaque) void,
fn init(ptr: anytype) CallScopeEndCallback {
const T = @TypeOf(ptr);
const ptr_info = @typeInfo(T);
const gen = struct {
pub fn callScopeEnd(pointer: *anyopaque, scope: *Scope) void {
pub fn callScopeEnd(pointer: *anyopaque) void {
const self: T = @ptrCast(@alignCast(pointer));
return ptr_info.pointer.child.jsCallScopeEnd(self, scope);
return ptr_info.pointer.child.jsCallScopeEnd(self);
}
};
@@ -1734,8 +1741,8 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
};
}
pub fn callScopeEnd(self: CallScopeEndCallback, scope: *Scope) void {
self.callScopeEndFn(self.ptr, scope);
pub fn callScopeEnd(self: CallScopeEndCallback) void {
self.callScopeEndFn(self.ptr);
}
};
};
@@ -1815,7 +1822,7 @@ fn Caller(comptime E: type, comptime State: type) type {
// when a top-level (call_depth == 0) function ends.
if (call_depth == 0) {
for (scope.call_scope_end_callbacks.items) |cb| {
cb.callScopeEnd(scope);
cb.callScopeEnd();
}
const arena: *ArenaAllocator = @alignCast(@ptrCast(scope.call_arena.ptr));