@@ -192,6 +192,41 @@ pub const NodeObject = struct {
192192 }
193193};
194194
195+ pub const NodeArray = struct {
196+ const Self = @This ();
197+
198+ napi_env : c.napi_env ,
199+ napi_value : c.napi_value ,
200+
201+ pub fn asValue (self : NodeArray.Self ) ! NodeValue {
202+ return NodeValue {
203+ .napi_env = self .napi_env ,
204+ .napi_value = self .napi_value ,
205+ };
206+ }
207+
208+ pub fn len (self : NodeArray.Self ) ! u32 {
209+ var v : u32 = undefined ;
210+ try s2e (c .napi_get_array_length (self .napi_env , self .napi_value , & v ));
211+ return v ;
212+ }
213+
214+ /// Gets a NodeValue indicating wether the object has a property with the specified name.
215+ pub fn get (self : NodeArray.Self , index : u32 ) ! NodeValue {
216+ var v : c.napi_value = undefined ;
217+ try s2e (c .napi_get_element (self .napi_env , self .napi_value , index , & v ));
218+ return NodeValue { .napi_env = self .napi_env , .napi_value = v };
219+ }
220+
221+ /// Set the specified NodeValue at the specified index of the NodeArray.
222+ pub fn set (self : NodeArray.Self , index : u32 , value : NodeValue ) ! NodeValue {
223+ try s2e (c .napi_set_element (self .napi_env , self .napi_value , index , value .napi_value ));
224+ return value ;
225+ }
226+
227+ // get/set [], push, splice, etc.
228+ };
229+
195230/// Represents a JS function.
196231pub fn NodeFunction (comptime F : anytype ) type {
197232 const f = switch (@typeInfo (F )) {
@@ -234,24 +269,3 @@ fn TupleTypeOf(params: []const std.builtin.Type.Fn.Param) type {
234269
235270 return std .meta .Tuple (& argTypes );
236271}
237- pub const NodeArray = struct {
238- const Self = @This ();
239-
240- napi_env : c.napi_env ,
241- napi_value : c.napi_value ,
242-
243- fn len (self : NodeValue.Self ) ! u32 {
244- var v : u32 = undefined ;
245- s2e (c .napi_get_array_length (self .napi_env , self .napi_value , & v ));
246- return v ;
247- }
248-
249- pub fn asValue (self : NodeArray.Self ) ! NodeValue {
250- return NodeValue {
251- .napi_env = self .napi_env ,
252- .napi_value = self .napi_value ,
253- };
254- }
255-
256- // get/set [], push, splice, etc.
257- };
0 commit comments