Add UndefinedOr(T) union

Some apis want a value or undefined. For these, we can't use an Optional
return type, null maps to JS null. Adds an Env.UndefinedOr(T) generic
union for such return types.
This commit is contained in:
Karl Seguin
2025-06-27 17:55:13 +08:00
parent 7a311a181b
commit c9936c2b7e
3 changed files with 13 additions and 13 deletions

View File

@@ -1858,6 +1858,13 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
}
};
pub fn UndefinedOr(comptime T: type) type {
return union(enum) {
value: T,
undefined: void,
};
}
fn compileModule(isolate: v8.Isolate, src: []const u8, name: []const u8) !v8.Module {
// compile
const script_name = v8.String.initUtf8(isolate, name);