Skip to content

Commit ce832a8

Browse files
committed
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.
1 parent f42bd02 commit ce832a8

File tree

4 files changed

+21
-29
lines changed

4 files changed

+21
-29
lines changed

src/browser/dom/mutation_observer.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub const MutationObserver = struct {
103103
}
104104
}
105105

106-
pub fn jsCallScopeEnd(self: *MutationObserver, _: anytype) void {
106+
pub fn jsCallScopeEnd(self: *MutationObserver) void {
107107
const record = self.observed.items;
108108
if (record.len == 0) {
109109
return;

src/browser/xhr/xhr.zig

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,6 @@ pub const XMLHttpRequest = struct {
257257
};
258258
}
259259

260-
pub fn destructor(self: *XMLHttpRequest, _: anytype) void {
261-
self._abort();
262-
}
263-
264260
pub fn reset(self: *XMLHttpRequest) void {
265261
self.url = null;
266262

@@ -539,10 +535,6 @@ pub const XMLHttpRequest = struct {
539535
}
540536

541537
pub fn _abort(self: *XMLHttpRequest) void {
542-
const request = &(self.request orelse return);
543-
// safe to call even if the request is complete
544-
request.abort();
545-
546538
self.onErr(DOMError.Abort);
547539
}
548540

src/http/client.zig

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,6 @@ pub const Request = struct {
261261
self._client.state_pool.release(self._state);
262262
}
263263

264-
pub fn abort(self: *Request) void {
265-
const connection = self._connection orelse return;
266-
self.destroyConnection(connection);
267-
self._connection = null;
268-
self.deinit();
269-
}
270-
271264
const DecomposedURL = struct {
272265
secure: bool,
273266
connect_port: u16,

src/runtime/js.zig

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,15 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
539539
// no init, started with executor.startScope()
540540

541541
fn deinit(self: *Scope) void {
542-
for (self.destructor_callbacks.items) |cb| {
543-
cb.destructor(self);
542+
{
543+
// reverse order, as this has more chance of respecting any
544+
// dependencies objects might have with each other.
545+
const items = self.destructor_callbacks.items;
546+
var i = items.len;
547+
while (i > 0) {
548+
i -= 1;
549+
items[i].destructor();
550+
}
544551
}
545552

546553
{
@@ -1687,16 +1694,16 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
16871694
// called when the call scope ends
16881695
const DestructorCallback = struct {
16891696
ptr: *anyopaque,
1690-
destructorFn: *const fn (ptr: *anyopaque, scope: *Scope) void,
1697+
destructorFn: *const fn (ptr: *anyopaque) void,
16911698

16921699
fn init(ptr: anytype) DestructorCallback {
16931700
const T = @TypeOf(ptr);
16941701
const ptr_info = @typeInfo(T);
16951702

16961703
const gen = struct {
1697-
pub fn destructor(pointer: *anyopaque, scope: *Scope) void {
1704+
pub fn destructor(pointer: *anyopaque) void {
16981705
const self: T = @ptrCast(@alignCast(pointer));
1699-
return ptr_info.pointer.child.destructor(self, scope);
1706+
return ptr_info.pointer.child.destructor(self);
17001707
}
17011708
};
17021709

@@ -1706,25 +1713,25 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
17061713
};
17071714
}
17081715

1709-
pub fn destructor(self: DestructorCallback, scope: *Scope) void {
1710-
self.destructorFn(self.ptr, scope);
1716+
pub fn destructor(self: DestructorCallback) void {
1717+
self.destructorFn(self.ptr);
17111718
}
17121719
};
17131720

17141721
// An interface for types that want to have their jsScopeEnd function be
17151722
// called when the call scope ends
17161723
const CallScopeEndCallback = struct {
17171724
ptr: *anyopaque,
1718-
callScopeEndFn: *const fn (ptr: *anyopaque, scope: *Scope) void,
1725+
callScopeEndFn: *const fn (ptr: *anyopaque) void,
17191726

17201727
fn init(ptr: anytype) CallScopeEndCallback {
17211728
const T = @TypeOf(ptr);
17221729
const ptr_info = @typeInfo(T);
17231730

17241731
const gen = struct {
1725-
pub fn callScopeEnd(pointer: *anyopaque, scope: *Scope) void {
1732+
pub fn callScopeEnd(pointer: *anyopaque) void {
17261733
const self: T = @ptrCast(@alignCast(pointer));
1727-
return ptr_info.pointer.child.jsCallScopeEnd(self, scope);
1734+
return ptr_info.pointer.child.jsCallScopeEnd(self);
17281735
}
17291736
};
17301737

@@ -1734,8 +1741,8 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
17341741
};
17351742
}
17361743

1737-
pub fn callScopeEnd(self: CallScopeEndCallback, scope: *Scope) void {
1738-
self.callScopeEndFn(self.ptr, scope);
1744+
pub fn callScopeEnd(self: CallScopeEndCallback) void {
1745+
self.callScopeEndFn(self.ptr);
17391746
}
17401747
};
17411748
};
@@ -1815,7 +1822,7 @@ fn Caller(comptime E: type, comptime State: type) type {
18151822
// when a top-level (call_depth == 0) function ends.
18161823
if (call_depth == 0) {
18171824
for (scope.call_scope_end_callbacks.items) |cb| {
1818-
cb.callScopeEnd(scope);
1825+
cb.callScopeEnd();
18191826
}
18201827

18211828
const arena: *ArenaAllocator = @alignCast(@ptrCast(scope.call_arena.ptr));

0 commit comments

Comments
 (0)