@@ -9,12 +9,13 @@ const ThreadSafeFunction = @import("../wrapper/thread_safe_function.zig").Thread
99const class = @import ("../wrapper/class.zig" );
1010const Buffer = @import ("../wrapper/buffer.zig" ).Buffer ;
1111const ArrayBuffer = @import ("../wrapper/arraybuffer.zig" ).ArrayBuffer ;
12+ const DataView = @import ("../wrapper/dataview.zig" ).DataView ;
1213
1314pub const Napi = struct {
1415 pub fn from_napi_value (env : napi.napi_env , raw : napi.napi_value , comptime T : type ) T {
1516 const infos = @typeInfo (T );
1617 switch (T ) {
17- NapiValue .BigInt , NapiValue .Number , NapiValue .String , NapiValue .Object , NapiValue .Promise , NapiValue .Array , NapiValue .Undefined , NapiValue .Null , Buffer , ArrayBuffer = > {
18+ NapiValue .BigInt , NapiValue .Number , NapiValue .String , NapiValue .Object , NapiValue .Promise , NapiValue .Array , NapiValue .Undefined , NapiValue .Null , Buffer , ArrayBuffer , DataView = > {
1819 return T .from_raw (env , raw );
1920 },
2021 else = > {
@@ -91,6 +92,12 @@ pub const Napi = struct {
9192 }
9293 return Function (args_type , return_type ).from_raw (env , raw );
9394 }
95+ if (comptime helper .isTypedArray (T )) {
96+ return T .from_raw (env , raw );
97+ }
98+ if (comptime helper .isDataView (T )) {
99+ return T .from_raw (env , raw );
100+ }
94101
95102 if (comptime helper .isTuple (T )) {
96103 return NapiValue .Array .from_napi_value (env , raw , T );
@@ -136,7 +143,7 @@ pub const Napi = struct {
136143 const infos = @typeInfo (value_type );
137144
138145 switch (value_type ) {
139- NapiValue .BigInt , NapiValue .Bool , NapiValue .Number , NapiValue .String , NapiValue .Object , NapiValue .Promise , NapiValue .Array , NapiValue .Undefined , NapiValue .Null , Buffer , ArrayBuffer = > {
146+ NapiValue .BigInt , NapiValue .Bool , NapiValue .Number , NapiValue .String , NapiValue .Object , NapiValue .Promise , NapiValue .Array , NapiValue .Undefined , NapiValue .Null , Buffer , ArrayBuffer , DataView = > {
140147 return value .raw ;
141148 },
142149 // If value is already a napi_value, return it directly
@@ -194,9 +201,15 @@ pub const Napi = struct {
194201 if (comptime helper .isNapiFunction (value_type )) {
195202 return value .raw ;
196203 }
204+ if (comptime helper .isTypedArray (value_type )) {
205+ return value .raw ;
206+ }
197207 if (comptime helper .isThreadSafeFunction (value_type )) {
198208 @compileError ("ThreadSafeFunction is not supported for to_napi_value" );
199209 }
210+ if (comptime helper .isDataView (value_type )) {
211+ return value .raw ;
212+ }
200213 if (comptime helper .isTuple (value_type )) {
201214 const array = try NapiValue .Array .New (Env .from_raw (env ), value );
202215 return array .raw ;
0 commit comments