File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,21 @@ pub const URL = struct {
7171 alloc .free (self .rawuri );
7272 }
7373
74+ pub fn get_origin (self : * URL , alloc : std.mem.Allocator ) ! []const u8 {
75+ var buf = std .ArrayList (u8 ).init (alloc );
76+ defer buf .deinit ();
77+
78+ try self .uri .writeToStream (.{
79+ .scheme = true ,
80+ .authentication = false ,
81+ .authority = true ,
82+ .path = false ,
83+ .query = false ,
84+ .fragment = false ,
85+ }, buf .writer ());
86+ return try buf .toOwnedSlice ();
87+ }
88+
7489 // the caller must free the returned string.
7590 // TODO return a disposable string
7691 // https://github.com/lightpanda-io/jsruntime-lib/issues/195
@@ -223,6 +238,7 @@ pub fn testExecFn(
223238) anyerror ! void {
224239 var url = [_ ]Case {
225240 .{ .src = "var url = new URL('https://foo.bar/path?query#fragment')" , .ex = "undefined" },
241+ .{ .src = "url.origin" , .ex = "https://foo.bar" },
226242 .{ .src = "url.href" , .ex = "https://foo.bar/path?query#fragment" },
227243 .{ .src = "url.protocol" , .ex = "https:" },
228244 .{ .src = "url.username" , .ex = "" },
You can’t perform that action at this time.
0 commit comments