@@ -157,7 +157,7 @@ pub fn _getIndex(self: *Caller, comptime T: type, func: anytype, idx: u32, info:
157157 @field (args , "0" ) = try Context .typeTaggedAnyOpaque (* T , info .getThis ());
158158 @field (args , "1" ) = idx ;
159159 const ret = @call (.auto , func , args );
160- return self .handleIndexedReturn (T , F , ret , info , opts );
160+ return self .handleIndexedReturn (T , F , true , ret , info , opts );
161161}
162162
163163pub fn getNamedIndex (self : * Caller , comptime T : type , func : anytype , name : v8.Name , info : v8.PropertyCallbackInfo , comptime opts : CallOpts ) u8 {
@@ -173,10 +173,49 @@ pub fn _getNamedIndex(self: *Caller, comptime T: type, func: anytype, name: v8.N
173173 @field (args , "0" ) = try Context .typeTaggedAnyOpaque (* T , info .getThis ());
174174 @field (args , "1" ) = try self .nameToString (name );
175175 const ret = @call (.auto , func , args );
176- return self .handleIndexedReturn (T , F , ret , info , opts );
176+ return self .handleIndexedReturn (T , F , true , ret , info , opts );
177177}
178178
179- fn handleIndexedReturn (self : * Caller , comptime T : type , comptime F : type , ret : anytype , info : v8.PropertyCallbackInfo , comptime opts : CallOpts ) ! u8 {
179+ pub fn setNamedIndex (self : * Caller , comptime T : type , func : anytype , name : v8.Name , js_value : v8.Value , info : v8.PropertyCallbackInfo , comptime opts : CallOpts ) u8 {
180+ return self ._setNamedIndex (T , func , name , js_value , info , opts ) catch | err | {
181+ self .handleError (T , @TypeOf (func ), err , info , opts );
182+ return v8 .Intercepted .No ;
183+ };
184+ }
185+
186+ pub fn _setNamedIndex (self : * Caller , comptime T : type , func : anytype , name : v8.Name , js_value : v8.Value , info : v8.PropertyCallbackInfo , comptime opts : CallOpts ) ! u8 {
187+ const F = @TypeOf (func );
188+ var args : ParameterTypes (F ) = undefined ;
189+ @field (args , "0" ) = try Context .typeTaggedAnyOpaque (* T , info .getThis ());
190+ @field (args , "1" ) = try self .nameToString (name );
191+ @field (args , "2" ) = try self .context .jsValueToZig (@TypeOf (@field (args , "2" )), js_value );
192+ if (@typeInfo (F ).@"fn" .params .len == 4 ) {
193+ @field (args , "3" ) = self .context .page ;
194+ }
195+ const ret = @call (.auto , func , args );
196+ return self .handleIndexedReturn (T , F , false , ret , info , opts );
197+ }
198+
199+ pub fn deleteNamedIndex (self : * Caller , comptime T : type , func : anytype , name : v8.Name , info : v8.PropertyCallbackInfo , comptime opts : CallOpts ) u8 {
200+ return self ._deleteNamedIndex (T , func , name , info , opts ) catch | err | {
201+ self .handleError (T , @TypeOf (func ), err , info , opts );
202+ return v8 .Intercepted .No ;
203+ };
204+ }
205+
206+ pub fn _deleteNamedIndex (self : * Caller , comptime T : type , func : anytype , name : v8.Name , info : v8.PropertyCallbackInfo , comptime opts : CallOpts ) ! u8 {
207+ const F = @TypeOf (func );
208+ var args : ParameterTypes (F ) = undefined ;
209+ @field (args , "0" ) = try Context .typeTaggedAnyOpaque (* T , info .getThis ());
210+ @field (args , "1" ) = try self .nameToString (name );
211+ if (@typeInfo (F ).@"fn" .params .len == 3 ) {
212+ @field (args , "2" ) = self .context .page ;
213+ }
214+ const ret = @call (.auto , func , args );
215+ return self .handleIndexedReturn (T , F , false , ret , info , opts );
216+ }
217+
218+ fn handleIndexedReturn (self : * Caller , comptime T : type , comptime F : type , comptime getter : bool , ret : anytype , info : v8.PropertyCallbackInfo , comptime opts : CallOpts ) ! u8 {
180219 // need to unwrap this error immediately for when opts.null_as_undefined == true
181220 // and we need to compare it to null;
182221 const non_error_ret = switch (@typeInfo (@TypeOf (ret ))) {
@@ -197,7 +236,9 @@ fn handleIndexedReturn(self: *Caller, comptime T: type, comptime F: type, ret: a
197236 else = > ret ,
198237 };
199238
200- info .getReturnValue ().set (try self .context .zigValueToJs (non_error_ret , opts ));
239+ if (comptime getter ) {
240+ info .getReturnValue ().set (try self .context .zigValueToJs (non_error_ret , opts ));
241+ }
201242 return v8 .Intercepted .Yes ;
202243}
203244
0 commit comments