mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-04-03 16:10:29 +00:00
Add js.NullableString
When a WebAPI takes `[]const u8`, we coerce values to strings. But when it takes a `?[]const u8` how should we handle `null`? Some APIs might want to know that it was null, others might just want `"null``. Currently when `null` is passed to `?[]const u8`, we'll get null. This adds a discriminator type, js.NullableString. When `null` is passed to it it'll be converted to `"null"`.
This commit is contained in:
@@ -453,6 +453,13 @@ pub fn jsValueToZig(self: *const Local, comptime T: type, js_val: js.Value) !T {
|
||||
return js_val;
|
||||
}
|
||||
|
||||
if (comptime o.child == js.NullableString) {
|
||||
if (js_val.isUndefined()) {
|
||||
return null;
|
||||
}
|
||||
return .{ .value = try js_val.toStringSlice() };
|
||||
}
|
||||
|
||||
if (comptime o.child == js.Object) {
|
||||
return js.Object{
|
||||
.local = self,
|
||||
|
||||
Reference in New Issue
Block a user