expose URLSearchParams toString and URL.toString

This commit is contained in:
Karl Seguin
2025-06-04 21:38:09 +08:00
parent b35107a966
commit b29e07faba
2 changed files with 6 additions and 10 deletions

View File

@@ -111,10 +111,12 @@ pub const URL = struct {
}
// get_href returns the URL by writing all its components.
// The query is replaced by a dump of search params.
//
pub fn get_href(self: *URL, page: *Page) ![]const u8 {
return try self.toString(page.arena);
return self.toString(page.arena);
}
pub fn _toString(self: *URL, page: *Page) ![]const u8 {
return self.toString(page.arena);
}
// format the url with all its components.
@@ -307,7 +309,7 @@ pub const URLSearchParams = struct {
return self._entries();
}
fn _toString(self: *const URLSearchParams, page: *Page) ![]const u8 {
pub fn _toString(self: *const URLSearchParams, page: *Page) ![]const u8 {
var arr: std.ArrayListUnmanaged(u8) = .empty;
try self.write(arr.writer(page.call_arena));
return arr.items;

View File

@@ -1806,14 +1806,8 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
}
fn generateProperty(comptime Struct: type, comptime name: []const u8, isolate: v8.Isolate, template_proto: v8.ObjectTemplate) void {
const getter = @field(Struct, "get_" ++ name);
const param_count = @typeInfo(@TypeOf(getter)).@"fn".params.len;
var js_name: v8.Name = undefined;
if (comptime std.mem.eql(u8, name, "symbol_toStringTag")) {
if (param_count != 0) {
@compileError(@typeName(Struct) ++ ".get_symbol_toStringTag() cannot take any parameters");
}
js_name = v8.Symbol.getToStringTag(isolate).toName();
} else {
js_name = v8.String.initUtf8(isolate, name).toName();