@@ -911,29 +911,200 @@ func CreateExternalArrayBuffer(env Env, data unsafe.Pointer, length int, finaliz
911911 return result , status
912912}
913913
914- func GetTypedArrayInfo (env Env , value Value ) (TypedArrayType , int , * byte , Status ) {
915- var type_ TypedArrayType
916- var length C.size_t
917- var data * byte
918- status := Status (C .napi_get_typedarray_info (
914+ func GetElement (env Env , object Value , index int ) (Value , Status ) {
915+ var result Value
916+ status := Status (C .napi_get_element (
917+ C .napi_env (env ),
918+ C .napi_value (object ),
919+ C .uint32_t (index ),
920+ (* C .napi_value )(unsafe .Pointer (& result )),
921+ ))
922+ return result , status
923+ }
924+
925+ func GetProperty (env Env , object , key Value ) (Value , Status ) {
926+ var result Value
927+ status := Status (C .napi_get_property (
928+ C .napi_env (env ),
929+ C .napi_value (object ),
930+ C .napi_value (key ),
931+ (* C .napi_value )(unsafe .Pointer (& result )),
932+ ))
933+ return result , status
934+ }
935+
936+ func DeleteProperty (env Env , object , key Value ) Status {
937+ return Status (C .napi_delete_property (
938+ C .napi_env (env ),
939+ C .napi_value (object ),
940+ C .napi_value (key ),
941+ ))
942+ }
943+
944+ func SetNamedProperty (env Env , object Value , name string , value Value ) Status {
945+ cname := C .CString (name )
946+ defer C .free (unsafe .Pointer (cname ))
947+ return Status (C .napi_set_named_property (
919948 C .napi_env (env ),
949+ C .napi_value (object ),
950+ cname ,
920951 C .napi_value (value ),
921- (* C .napi_typedarray_type )(unsafe .Pointer (& type_ )),
922- & length ,
923- (* * C .void )(unsafe .Pointer (& data )),
924952 ))
925- return type_ , int (length ), data , status
926953}
927954
928- func CreateTypedArray (env Env , type_ TypedArrayType , length int , arrayBuffer Value , byteOffset int ) (Value , Status ) {
955+ func GetNamedProperty (env Env , object Value , name string ) (Value , Status ) {
956+ cname := C .CString (name )
957+ defer C .free (unsafe .Pointer (cname ))
929958 var result Value
930- status := Status (C .napi_create_typedarray (
959+ status := Status (C .napi_get_named_property (
931960 C .napi_env (env ),
932- C .napi_typedarray_type (type_ ),
933- C .size_t (length ),
934- C .napi_value (arrayBuffer ),
935- C .size_t (byteOffset ),
961+ C .napi_value (object ),
962+ cname ,
936963 (* C .napi_value )(unsafe .Pointer (& result )),
937964 ))
938965 return result , status
939966}
967+
968+ func HasNamedProperty (env Env , object Value , name string ) (bool , Status ) {
969+ cname := C .CString (name )
970+ defer C .free (unsafe .Pointer (cname ))
971+ var result bool
972+ status := Status (C .napi_has_named_property (
973+ C .napi_env (env ),
974+ C .napi_value (object ),
975+ cname ,
976+ (* C .bool )(unsafe .Pointer (& result )),
977+ ))
978+ return result , status
979+ }
980+
981+ func HasElement (env Env , object Value , index int ) (bool , Status ) {
982+ var result bool
983+ status := Status (C .napi_has_element (
984+ C .napi_env (env ),
985+ C .napi_value (object ),
986+ C .uint32_t (index ),
987+ (* C .bool )(unsafe .Pointer (& result )),
988+ ))
989+ return result , status
990+ }
991+
992+ func DeleteElement (env Env , object Value , index int ) Status {
993+ return Status (C .napi_delete_element (
994+ C .napi_env (env ),
995+ C .napi_value (object ),
996+ C .uint32_t (index ),
997+ ))
998+ }
999+
1000+ func ObjectFreeze (env Env , object Value ) Status {
1001+ return Status (C .napi_object_freeze (
1002+ C .napi_env (env ),
1003+ C .napi_value (object ),
1004+ ))
1005+ }
1006+
1007+ func ObjectSeal (env Env , object Value ) Status {
1008+ return Status (C .napi_object_seal (
1009+ C .napi_env (env ),
1010+ C .napi_value (object ),
1011+ ))
1012+ }
1013+
1014+ func ThrowTypeError (env Env , code , msg string ) Status {
1015+ codeCStr , msgCCstr := C .CString (code ), C .CString (msg )
1016+ defer C .free (unsafe .Pointer (codeCStr ))
1017+ defer C .free (unsafe .Pointer (msgCCstr ))
1018+
1019+ return Status (C .napi_throw_type_error (
1020+ C .napi_env (env ),
1021+ codeCStr ,
1022+ msgCCstr ,
1023+ ))
1024+ }
1025+
1026+ func ThrowRangeError (env Env , code , msg string ) Status {
1027+ codeCStr , msgCCstr := C .CString (code ), C .CString (msg )
1028+ defer C .free (unsafe .Pointer (codeCStr ))
1029+ defer C .free (unsafe .Pointer (msgCCstr ))
1030+
1031+ return Status (C .napi_throw_range_error (
1032+ C .napi_env (env ),
1033+ codeCStr ,
1034+ msgCCstr ,
1035+ ))
1036+ }
1037+
1038+ func CreateTypeError (env Env , code , msg Value ) (Value , Status ) {
1039+ var result Value
1040+ status := Status (C .napi_create_type_error (
1041+ C .napi_env (env ),
1042+ C .napi_value (code ),
1043+ C .napi_value (msg ),
1044+ (* C .napi_value )(unsafe .Pointer (& result )),
1045+ ))
1046+ return result , status
1047+ }
1048+
1049+ func CreateRangeError (env Env , code , msg Value ) (Value , Status ) {
1050+ var result Value
1051+ status := Status (C .napi_create_range_error (
1052+ C .napi_env (env ),
1053+ C .napi_value (code ),
1054+ C .napi_value (msg ),
1055+ (* C .napi_value )(unsafe .Pointer (& result )),
1056+ ))
1057+ return result , status
1058+ }
1059+
1060+ func IsExceptionPending (env Env ) (bool , Status ) {
1061+ var result bool
1062+ status := Status (C .napi_is_exception_pending (
1063+ C .napi_env (env ),
1064+ (* C .bool )(unsafe .Pointer (& result )),
1065+ ))
1066+ return result , status
1067+ }
1068+
1069+ func GetAndClearLastException (env Env ) (Value , Status ) {
1070+ var result Value
1071+ status := Status (C .napi_get_and_clear_last_exception (
1072+ C .napi_env (env ),
1073+ (* C .napi_value )(unsafe .Pointer (& result )),
1074+ ))
1075+ return result , status
1076+ }
1077+
1078+ type CallbackScope struct {
1079+ scope C.napi_callback_scope
1080+ }
1081+
1082+ // OpenCallbackScope Function to open a callback scope
1083+ func OpenCallbackScope (env Env , resourceObject , context Value ) (CallbackScope , Status ) {
1084+ var scope CallbackScope
1085+ status := Status (C .napi_open_callback_scope (
1086+ C .napi_env (env ),
1087+ C .napi_value (resourceObject ),
1088+ C .napi_value (context ),
1089+ (* C .napi_callback_scope )(unsafe .Pointer (& scope .scope )),
1090+ ))
1091+ return scope , status
1092+ }
1093+
1094+ // CloseCallbackScope Function to close a callback scope
1095+ func CloseCallbackScope (env Env , scope CallbackScope ) Status {
1096+ return Status (C .napi_close_callback_scope (
1097+ C .napi_env (env ),
1098+ scope .scope ,
1099+ ))
1100+ }
1101+
1102+ // GetExtendedErrorInfo Function to retrieve extended error information
1103+ func GetExtendedErrorInfo (env Env ) (* C.napi_extended_error_info , Status ) {
1104+ var errorInfo * C.napi_extended_error_info
1105+ status := Status (C .napi_get_last_error_info (
1106+ C .napi_env (env ),
1107+ & errorInfo ,
1108+ ))
1109+ return errorInfo , status
1110+ }
0 commit comments