mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
stop using destructor callback for fetch
This commit is contained in:
@@ -78,14 +78,6 @@ pub const FetchContext = struct {
|
|||||||
.url = self.url,
|
.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
|
// 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,
|
.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(.{
|
try page.http_client.request(.{
|
||||||
.ctx = @ptrCast(fetch_ctx),
|
.ctx = @ptrCast(fetch_ctx),
|
||||||
.url = req.url,
|
.url = req.url,
|
||||||
@@ -200,15 +189,18 @@ pub fn fetch(input: RequestInput, options: ?RequestInit, page: *Page) !Env.Promi
|
|||||||
.error_callback = struct {
|
.error_callback = struct {
|
||||||
fn errorCallback(ctx: *anyopaque, err: anyerror) void {
|
fn errorCallback(ctx: *anyopaque, err: anyerror) void {
|
||||||
const self: *FetchContext = @ptrCast(@alignCast(ctx));
|
const self: *FetchContext = @ptrCast(@alignCast(ctx));
|
||||||
if (self.transfer != null) {
|
defer self.promise_resolver.deinit();
|
||||||
self.transfer = null;
|
self.transfer = null;
|
||||||
|
|
||||||
log.err(.http, "error", .{
|
log.err(.http, "error", .{
|
||||||
.url = self.url,
|
.url = self.url,
|
||||||
.err = err,
|
.err = err,
|
||||||
.source = "fetch error",
|
.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;
|
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
|
// An interface for types that want to have their jsDeinit function to be
|
||||||
// called when the call context ends
|
// called when the call context ends
|
||||||
pub const DestructorCallback = struct {
|
const DestructorCallback = struct {
|
||||||
ptr: *anyopaque,
|
ptr: *anyopaque,
|
||||||
destructorFn: *const fn (ptr: *anyopaque) void,
|
destructorFn: *const fn (ptr: *anyopaque) void,
|
||||||
|
|
||||||
pub fn init(ptr: anytype) DestructorCallback {
|
fn init(ptr: anytype) DestructorCallback {
|
||||||
const T = @TypeOf(ptr);
|
const T = @TypeOf(ptr);
|
||||||
const ptr_info = @typeInfo(T);
|
const ptr_info = @typeInfo(T);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user