From d8fa9b8c4f03332d302d05631d514590c737cea7 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Sun, 20 Apr 2025 12:47:28 +0800 Subject: [PATCH] Return TypeError if trying to turn an unknown v8.Object into a toa --- src/runtime/js.zig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/runtime/js.zig b/src/runtime/js.zig index 4a267e75..ab540696 100644 --- a/src/runtime/js.zig +++ b/src/runtime/js.zig @@ -1340,6 +1340,13 @@ pub fn Env(comptime S: type, comptime types: anytype) type { 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); if (@hasField(TypeLookup, type_name) == false) { @compileError(std.fmt.comptimePrint(