Don't error when failing to convert type to function.

Because jsValueToStruct is now used in union probing, it shouldn't fail on a
mismatch, but rather return null. It's up to the caller to decide whether that's
an error or not.
This commit is contained in:
Karl Seguin
2025-05-22 13:02:08 +08:00
parent 3c3de9d325
commit 38c6fa9c76

View File

@@ -910,7 +910,6 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
// compatible with. A compatible field has higher precedence // compatible with. A compatible field has higher precedence
// than a coercible, but still isn't a perfect match. // than a coercible, but still isn't a perfect match.
var compatible_index: ?usize = null; var compatible_index: ?usize = null;
inline for (u.fields, 0..) |field, i| { inline for (u.fields, 0..) |field, i| {
switch (try self.probeJsValueToZig(named_function, field.type, js_value)) { switch (try self.probeJsValueToZig(named_function, field.type, js_value)) {
.value => |v| return @unionInit(T, field.name, v), .value => |v| return @unionInit(T, field.name, v),
@@ -949,7 +948,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
fn jsValueToStruct(self: *Scope, comptime named_function: NamedFunction, comptime T: type, js_value: v8.Value) !?T { fn jsValueToStruct(self: *Scope, comptime named_function: NamedFunction, comptime T: type, js_value: v8.Value) !?T {
if (@hasDecl(T, "_FUNCTION_ID_KLUDGE")) { if (@hasDecl(T, "_FUNCTION_ID_KLUDGE")) {
if (!js_value.isFunction()) { if (!js_value.isFunction()) {
return error.InvalidArgument; return null;
} }
const func = v8.Persistent(v8.Function).init(self.isolate, js_value.castTo(v8.Function)); const func = v8.Persistent(v8.Function).init(self.isolate, js_value.castTo(v8.Function));