Return TypeError if trying to turn an unknown v8.Object into a toa

This commit is contained in:
Karl Seguin
2025-04-20 12:47:28 +08:00
parent 66ec087416
commit d8fa9b8c4f

View File

@@ -1340,6 +1340,13 @@ pub fn Env(comptime S: type, comptime types: anytype) type {
return @constCast(@as(*const T, &.{})); return @constCast(@as(*const T, &.{}));
} }
// if it isn't an empty struct, then the v8.Object should have an
// InternalFieldCount > 0, since our toa pointer should be embedded
// at index 0 of the internal field count.
if (js_obj.internalFieldCount() == 0) {
return error.InvalidArgument;
}
const type_name = @typeName(T); const type_name = @typeName(T);
if (@hasField(TypeLookup, type_name) == false) { if (@hasField(TypeLookup, type_name) == false) {
@compileError(std.fmt.comptimePrint( @compileError(std.fmt.comptimePrint(