From 967a2030e6a0965f6ecf3197f033330157245be4 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Fri, 9 Jan 2026 10:31:01 +0800 Subject: [PATCH] Define the index handler on the instance, not the prototype. While it sorta works if done on the prototype, it's incorrect as these are no longer "own" properties (which some WPT tests care about). NamedIndexes were already correctly defined on the instance. --- src/browser/js/Snapshot.zig | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/browser/js/Snapshot.zig b/src/browser/js/Snapshot.zig index 2be129c3..d227bee3 100644 --- a/src/browser/js/Snapshot.zig +++ b/src/browser/js/Snapshot.zig @@ -387,6 +387,8 @@ fn generateConstructor(comptime JsApi: type, isolate: v8.Isolate) v8.FunctionTem // Attaches JsApi members to the prototype template (normal case) fn attachClass(comptime JsApi: type, isolate: v8.Isolate, template: v8.FunctionTemplate) void { const target = template.getPrototypeTemplate(); + const instance = template.getInstanceTemplate(); + const declarations = @typeInfo(JsApi).@"struct".decls; inline for (declarations) |d| { const name: [:0]const u8 = d.name; @@ -422,9 +424,9 @@ fn attachClass(comptime JsApi: type, isolate: v8.Isolate, template: v8.FunctionT const configuration = v8.IndexedPropertyHandlerConfiguration{ .getter = value.getter, }; - target.setIndexedProperty(configuration, null); + instance.setIndexedProperty(configuration, null); }, - bridge.NamedIndexed => template.getInstanceTemplate().setNamedProperty(.{ + bridge.NamedIndexed => instance.setNamedProperty(.{ .getter = value.getter, .setter = value.setter, .deleter = value.deleter, @@ -456,15 +458,13 @@ fn attachClass(comptime JsApi: type, isolate: v8.Isolate, template: v8.FunctionT } if (@hasDecl(JsApi.Meta, "htmldda")) { - const instance_template = template.getInstanceTemplate(); - instance_template.markAsUndetectable(); - instance_template.setCallAsFunctionHandler(JsApi.Meta.callable.func); + instance.markAsUndetectable(); + instance.setCallAsFunctionHandler(JsApi.Meta.callable.func); } if (@hasDecl(JsApi.Meta, "name")) { const js_name = v8.Symbol.getToStringTag(isolate).toName(); - const instance_template = template.getInstanceTemplate(); - instance_template.set(js_name, v8.String.initUtf8(isolate, JsApi.Meta.name), v8.PropertyAttribute.ReadOnly + v8.PropertyAttribute.DontDelete); + instance.set(js_name, v8.String.initUtf8(isolate, JsApi.Meta.name), v8.PropertyAttribute.ReadOnly + v8.PropertyAttribute.DontDelete); } }