@@ -79,48 +79,21 @@ pub const Object = struct {
7979 }
8080
8181 pub fn Set (self : Object , comptime key : []const u8 , value : anytype ) ! void {
82- const value_type = @TypeOf (value );
83- const infos = @typeInfo (value_type );
84-
85- switch (infos ) {
86- .@"fn" = > {
87- const args_type = comptime helper .collectFunctionArgs (value_type );
88- const return_type = infos .@"fn" .return_type .? ;
89- const fn_impl = try Function (args_type , return_type ).New (Env .from_raw (self .env ), key , value );
90- const napi_desc = [_ ]napi.napi_property_descriptor {
91- .{
92- .utf8name = @ptrCast (key .ptr ),
93- .method = fn_impl .inner_fn ,
94- .getter = null ,
95- .setter = null ,
96- .value = null ,
97- .attributes = napi .napi_default ,
98- .data = null ,
99- },
100- };
101- const status = napi .napi_define_properties (self .env , self .raw , 1 , & napi_desc );
102- if (status != napi .napi_ok ) {
103- return NapiError .Error .fromStatus (NapiError .Status .New (status ));
104- }
105- },
106- else = > {
107- const n_value = try Napi .to_napi_value (self .env , value , null );
108- const napi_desc = [_ ]napi.napi_property_descriptor {
109- .{
110- .utf8name = @ptrCast (key .ptr ),
111- .method = null ,
112- .getter = null ,
113- .setter = null ,
114- .value = n_value ,
115- .attributes = napi .napi_default ,
116- .data = null ,
117- },
118- };
119- const status = napi .napi_define_properties (self .env , self .raw , 1 , & napi_desc );
120- if (status != napi .napi_ok ) {
121- return NapiError .Error .fromStatus (NapiError .Status .New (status ));
122- }
82+ const n_value = try Napi .to_napi_value (self .env , value , key );
83+ const napi_desc = [_ ]napi.napi_property_descriptor {
84+ .{
85+ .utf8name = @ptrCast (key .ptr ),
86+ .method = null ,
87+ .getter = null ,
88+ .setter = null ,
89+ .value = n_value ,
90+ .attributes = napi .napi_default ,
91+ .data = null ,
12392 },
93+ };
94+ const status = napi .napi_define_properties (self .env , self .raw , 1 , & napi_desc );
95+ if (status != napi .napi_ok ) {
96+ return NapiError .Error .fromStatus (NapiError .Status .New (status ));
12497 }
12598 }
12699
0 commit comments