mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 22:53:28 +00:00
stop using destructor callback for fetch
This commit is contained in:
@@ -78,14 +78,6 @@ pub const FetchContext = struct {
|
||||
.url = self.url,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn destructor(self: *FetchContext) void {
|
||||
if (self.transfer) |_| {
|
||||
self.promise_resolver.reject("TypeError") catch unreachable;
|
||||
self.promise_resolver.deinit();
|
||||
self.transfer = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch
|
||||
@@ -122,9 +114,6 @@ pub fn fetch(input: RequestInput, options: ?RequestInit, page: *Page) !Env.Promi
|
||||
.url = req.url,
|
||||
};
|
||||
|
||||
// Add destructor callback for FetchContext.
|
||||
try page.main_context.destructor_callbacks.append(arena, Env.DestructorCallback.init(fetch_ctx));
|
||||
|
||||
try page.http_client.request(.{
|
||||
.ctx = @ptrCast(fetch_ctx),
|
||||
.url = req.url,
|
||||
@@ -200,15 +189,18 @@ pub fn fetch(input: RequestInput, options: ?RequestInit, page: *Page) !Env.Promi
|
||||
.error_callback = struct {
|
||||
fn errorCallback(ctx: *anyopaque, err: anyerror) void {
|
||||
const self: *FetchContext = @ptrCast(@alignCast(ctx));
|
||||
if (self.transfer != null) {
|
||||
self.transfer = null;
|
||||
defer self.promise_resolver.deinit();
|
||||
self.transfer = null;
|
||||
|
||||
log.err(.http, "error", .{
|
||||
.url = self.url,
|
||||
.err = err,
|
||||
.source = "fetch error",
|
||||
});
|
||||
log.err(.http, "error", .{
|
||||
.url = self.url,
|
||||
.err = err,
|
||||
.source = "fetch error",
|
||||
});
|
||||
|
||||
// We throw an Abort error when the page is getting closed so,
|
||||
// in this case, we don't need to reject the promise.
|
||||
if (err != error.Abort) {
|
||||
self.promise_resolver.reject(@errorName(err)) catch unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2945,11 +2945,11 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
|
||||
|
||||
// An interface for types that want to have their jsDeinit function to be
|
||||
// called when the call context ends
|
||||
pub const DestructorCallback = struct {
|
||||
const DestructorCallback = struct {
|
||||
ptr: *anyopaque,
|
||||
destructorFn: *const fn (ptr: *anyopaque) void,
|
||||
|
||||
pub fn init(ptr: anytype) DestructorCallback {
|
||||
fn init(ptr: anytype) DestructorCallback {
|
||||
const T = @TypeOf(ptr);
|
||||
const ptr_info = @typeInfo(T);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user