11#include <js_native_api.h>
22#include "../common.h"
33
4+ #include <stdio.h>
5+
46static double value_ = 1 ;
57static double static_value_ = 10 ;
68
9+ static void
10+ add_named_status (napi_env env , const char * key , napi_value return_value ) {
11+ napi_value prop_value ;
12+ const napi_extended_error_info * p_last_error ;
13+ NAPI_CALL_RETURN_VOID (env , napi_get_last_error_info (env , & p_last_error ));
14+
15+ NAPI_CALL_RETURN_VOID (env ,
16+ napi_create_string_utf8 (env ,
17+ (p_last_error -> error_message == NULL ?
18+ "napi_ok" :
19+ p_last_error -> error_message ),
20+ NAPI_AUTO_LENGTH ,
21+ & prop_value ));
22+ NAPI_CALL_RETURN_VOID (env , napi_set_named_property (env ,
23+ return_value ,
24+ key ,
25+ prop_value ));
26+ }
27+
728static napi_value TestDefineClass (napi_env env ,
829 napi_callback_info info ) {
9- napi_status ret [ 7 ] ;
30+ napi_status status ;
1031 napi_value result , return_value , prop_value ;
32+ char p_napi_message [100 ] = "" ;
1133
1234 napi_property_descriptor property_descriptor = {
1335 "TestDefineClass" ,
@@ -19,34 +41,9 @@ static napi_value TestDefineClass(napi_env env,
1941 napi_enumerable | napi_static ,
2042 NULL };
2143
22- ret [0 ] = napi_define_class (NULL ,
23- "TrackedFunction" ,
24- NAPI_AUTO_LENGTH ,
25- TestDefineClass ,
26- NULL ,
27- 1 ,
28- & property_descriptor ,
29- & result );
30-
31- ret [1 ] = napi_define_class (env ,
32- NULL ,
33- NAPI_AUTO_LENGTH ,
34- TestDefineClass ,
35- NULL ,
36- 1 ,
37- & property_descriptor ,
38- & result );
39-
40- ret [2 ] = napi_define_class (env ,
41- "TrackedFunction" ,
42- NAPI_AUTO_LENGTH ,
43- NULL ,
44- NULL ,
45- 1 ,
46- & property_descriptor ,
47- & result );
44+ NAPI_CALL (env , napi_create_object (env , & return_value ));
4845
49- ret [ 3 ] = napi_define_class (env ,
46+ status = napi_define_class (NULL ,
5047 "TrackedFunction" ,
5148 NAPI_AUTO_LENGTH ,
5249 TestDefineClass ,
@@ -55,85 +52,76 @@ static napi_value TestDefineClass(napi_env env,
5552 & property_descriptor ,
5653 & result );
5754
58- ret [4 ] = napi_define_class (env ,
59- "TrackedFunction" ,
60- NAPI_AUTO_LENGTH ,
61- TestDefineClass ,
62- NULL ,
63- 1 ,
64- NULL ,
65- & result );
66-
67- ret [5 ] = napi_define_class (env ,
68- "TrackedFunction" ,
69- NAPI_AUTO_LENGTH ,
70- TestDefineClass ,
71- NULL ,
72- 1 ,
73- & property_descriptor ,
74- NULL );
75-
76- NAPI_CALL (env , napi_create_object (env , & return_value ));
55+ if (status == napi_invalid_arg ) {
56+ snprintf (p_napi_message , 99 , "Invalid argument" );
57+ } else {
58+ snprintf (p_napi_message , 99 , "Invalid status [%d]" , status );
59+ }
7760
7861 NAPI_CALL (env , napi_create_string_utf8 (env ,
79- (ret [0 ] == napi_invalid_arg ?
80- "pass" : "fail" ),
62+ p_napi_message ,
8163 NAPI_AUTO_LENGTH ,
8264 & prop_value ));
8365 NAPI_CALL (env , napi_set_named_property (env ,
8466 return_value ,
8567 "envIsNull" ,
86- prop_value ));
87-
88- NAPI_CALL (env , napi_create_string_utf8 (env ,
89- (ret [1 ] == napi_invalid_arg ?
90- "pass" : "fail" ),
91- NAPI_AUTO_LENGTH ,
92- & prop_value ));
93- NAPI_CALL (env , napi_set_named_property (env ,
94- return_value ,
95- "nameIsNull" ,
96- prop_value ));
97-
98- NAPI_CALL (env , napi_create_string_utf8 (env ,
99- (ret [2 ] == napi_invalid_arg ?
100- "pass" : "fail" ),
101- NAPI_AUTO_LENGTH ,
102- & prop_value ));
103- NAPI_CALL (env , napi_set_named_property (env ,
104- return_value ,
105- "cbIsNull" ,
106- prop_value ));
107-
108- NAPI_CALL (env , napi_create_string_utf8 (env ,
109- (ret [3 ] == napi_ok ?
110- "pass" : "fail" ),
111- NAPI_AUTO_LENGTH ,
112- & prop_value ));
113- NAPI_CALL (env , napi_set_named_property (env ,
114- return_value ,
115- "cbDataIsNull" ,
116- prop_value ));
117-
118- NAPI_CALL (env , napi_create_string_utf8 (env ,
119- (ret [4 ] == napi_invalid_arg ?
120- "pass" : "fail" ),
121- NAPI_AUTO_LENGTH ,
122- & prop_value ));
123- NAPI_CALL (env , napi_set_named_property (env ,
124- return_value ,
125- "propertiesIsNull" ,
126- prop_value ));
127-
128- NAPI_CALL (env , napi_create_string_utf8 (env ,
129- (ret [5 ] == napi_invalid_arg ?
130- "pass" : "fail" ),
131- NAPI_AUTO_LENGTH ,
132- & prop_value ));
133- NAPI_CALL (env , napi_set_named_property (env ,
134- return_value ,
135- "resultIsNull" ,
136- prop_value ));
68+ prop_value ));
69+
70+ napi_define_class (env ,
71+ NULL ,
72+ NAPI_AUTO_LENGTH ,
73+ TestDefineClass ,
74+ NULL ,
75+ 1 ,
76+ & property_descriptor ,
77+ & result );
78+
79+ add_named_status (env , "nameIsNull" , return_value );
80+
81+ napi_define_class (env ,
82+ "TrackedFunction" ,
83+ NAPI_AUTO_LENGTH ,
84+ NULL ,
85+ NULL ,
86+ 1 ,
87+ & property_descriptor ,
88+ & result );
89+
90+ add_named_status (env , "cbIsNull" , return_value );
91+
92+ napi_define_class (env ,
93+ "TrackedFunction" ,
94+ NAPI_AUTO_LENGTH ,
95+ TestDefineClass ,
96+ NULL ,
97+ 1 ,
98+ & property_descriptor ,
99+ & result );
100+
101+ add_named_status (env , "cbDataIsNull" , return_value );
102+
103+ napi_define_class (env ,
104+ "TrackedFunction" ,
105+ NAPI_AUTO_LENGTH ,
106+ TestDefineClass ,
107+ NULL ,
108+ 1 ,
109+ NULL ,
110+ & result );
111+
112+ add_named_status (env , "propertiesIsNull" , return_value );
113+
114+
115+ napi_define_class (env ,
116+ "TrackedFunction" ,
117+ NAPI_AUTO_LENGTH ,
118+ TestDefineClass ,
119+ NULL ,
120+ 1 ,
121+ & property_descriptor ,
122+ NULL );
123+
124+ add_named_status (env , "resultIsNull" , return_value );
137125
138126 return return_value ;
139127}
0 commit comments