@@ -710,6 +710,62 @@ CheckTypeTag(napi_env env, napi_callback_info info) {
710710 return js_result ;
711711}
712712
713+ static napi_value TestCreateObjectWithProperties (napi_env env , napi_callback_info info ) {
714+ napi_value names [3 ];
715+ napi_value values [3 ];
716+ napi_value result ;
717+
718+ NODE_API_CALL (env , napi_create_string_utf8 (env , "name" , NAPI_AUTO_LENGTH , & names [0 ]));
719+ NODE_API_CALL (env , napi_create_string_utf8 (env , "Foo" , NAPI_AUTO_LENGTH , & values [0 ]));
720+
721+ NODE_API_CALL (env , napi_create_string_utf8 (env , "age" , NAPI_AUTO_LENGTH , & names [1 ]));
722+ NODE_API_CALL (env , napi_create_int32 (env , 42 , & values [1 ]));
723+
724+ NODE_API_CALL (env , napi_create_string_utf8 (env , "active" , NAPI_AUTO_LENGTH , & names [2 ]));
725+ NODE_API_CALL (env , napi_get_boolean (env , true, & values [2 ]));
726+
727+ napi_value null_prototype ;
728+ NODE_API_CALL (env , napi_get_null (env , & null_prototype ));
729+ NODE_API_CALL (env , napi_create_object_with_properties (
730+ env , null_prototype , names , values , 3 , & result ));
731+
732+ return result ;
733+ }
734+
735+ static napi_value TestCreateObjectWithPropertiesEmpty (napi_env env , napi_callback_info info ) {
736+ napi_value result ;
737+
738+ napi_value null_prototype ;
739+ NODE_API_CALL (env , napi_get_null (env , & null_prototype ));
740+ NODE_API_CALL (env , napi_create_object_with_properties (
741+ env , null_prototype , NULL , NULL , 0 , & result ));
742+
743+ return result ;
744+ }
745+
746+ static napi_value TestCreateObjectWithCustomPrototype (napi_env env , napi_callback_info info ) {
747+ napi_value prototype ;
748+ napi_value method_name ;
749+ napi_value method_func ;
750+ napi_value names [1 ];
751+ napi_value values [1 ];
752+ napi_value result ;
753+
754+ NODE_API_CALL (env , napi_create_object (env , & prototype ));
755+ NODE_API_CALL (env , napi_create_string_utf8 (env , "test" , NAPI_AUTO_LENGTH , & method_name ));
756+ NODE_API_CALL (env , napi_create_function (env , "test" , NAPI_AUTO_LENGTH ,
757+ TestCreateObjectWithProperties , NULL , & method_func ));
758+ NODE_API_CALL (env , napi_set_property (env , prototype , method_name , method_func ));
759+
760+ NODE_API_CALL (env , napi_create_string_utf8 (env , "value" , NAPI_AUTO_LENGTH , & names [0 ]));
761+ NODE_API_CALL (env , napi_create_int32 (env , 42 , & values [0 ]));
762+
763+ NODE_API_CALL (env , napi_create_object_with_properties (
764+ env , prototype , names , values , 1 , & result ));
765+
766+ return result ;
767+ }
768+
713769EXTERN_C_START
714770napi_value Init (napi_env env , napi_value exports ) {
715771 napi_property_descriptor descriptors [] = {
@@ -743,6 +799,9 @@ napi_value Init(napi_env env, napi_value exports) {
743799 DECLARE_NODE_API_PROPERTY ("TestGetProperty" , TestGetProperty ),
744800 DECLARE_NODE_API_PROPERTY ("TestFreeze" , TestFreeze ),
745801 DECLARE_NODE_API_PROPERTY ("TestSeal" , TestSeal ),
802+ DECLARE_NODE_API_PROPERTY ("TestCreateObjectWithProperties" , TestCreateObjectWithProperties ),
803+ DECLARE_NODE_API_PROPERTY ("TestCreateObjectWithPropertiesEmpty" , TestCreateObjectWithPropertiesEmpty ),
804+ DECLARE_NODE_API_PROPERTY ("TestCreateObjectWithCustomPrototype" , TestCreateObjectWithCustomPrototype ),
746805 };
747806
748807 init_test_null (env , exports );
0 commit comments