fix arena, add fetch test

This commit is contained in:
Karl Seguin
2025-09-16 08:39:46 +08:00
committed by Muki Kiboigo
parent 31335fc4fb
commit af916dea1d
3 changed files with 33 additions and 1 deletions

View File

@@ -111,7 +111,7 @@ pub fn fetch(input: RequestInput, options: ?RequestInit, page: *Page) !Env.Promi
while (header_iter.next()) |entry| { while (header_iter.next()) |entry| {
// This is fine because curl/headers copies it internally. // This is fine because curl/headers copies it internally.
const combined = try std.fmt.allocPrintSentinel( const combined = try std.fmt.allocPrintSentinel(
page.call_arena, page.arena,
"{s}: {s}", "{s}: {s}",
.{ entry.key_ptr.*, entry.value_ptr.* }, .{ entry.key_ptr.*, entry.value_ptr.* },
0, 0,
@@ -229,3 +229,8 @@ pub fn fetch(input: RequestInput, options: ?RequestInit, page: *Page) !Env.Promi
return resolver.promise(); return resolver.promise();
} }
const testing = @import("../../testing.zig");
test "fetch: fetch" {
try testing.htmlRunner("fetch/fetch.html");
}

View File

@@ -0,0 +1,16 @@
<script src="../testing.js"></script>
<script id=fetch type=module>
const promise1 = new Promise((resolve) => {
fetch('http://127.0.0.1:9582/xhr/json')
.then((res) => {
return res.json()
})
.then((json) => {
resolve(json);
});
});
testing.async(promise1, (json) => {
testing.expectEqual({over: '9000!!!'}, json);
});
</script>

View File

@@ -36,3 +36,14 @@
let emptyResponse = new Response(""); let emptyResponse = new Response("");
testing.expectEqual(200, emptyResponse.status); testing.expectEqual(200, emptyResponse.status);
</script> </script>
<script id=json type=module>
const promise1 = new Promise((resolve) => {
let response = new Response('[]');
response.json().then(resolve)
});
testing.async(promise1, (json) => {
testing.expectEqual([], json);
});
</script>ref