@@ -22,6 +22,22 @@ static napi_value returnException(napi_env env, napi_callback_info info) {
22
22
return NULL ;
23
23
}
24
24
25
+ static napi_value constructReturnException (napi_env env , napi_callback_info info ) {
26
+ size_t argc = 1 ;
27
+ napi_value args [1 ];
28
+ NODE_API_CALL (env , napi_get_cb_info (env , info , & argc , args , NULL , NULL ));
29
+
30
+ napi_value result ;
31
+ napi_status status = napi_new_instance (env , args [0 ], 0 , 0 , & result );
32
+ if (status == napi_pending_exception ) {
33
+ napi_value ex ;
34
+ NODE_API_CALL (env , napi_get_and_clear_last_exception (env , & ex ));
35
+ return ex ;
36
+ }
37
+
38
+ return NULL ;
39
+ }
40
+
25
41
static napi_value allowException (napi_env env , napi_callback_info info ) {
26
42
size_t argc = 1 ;
27
43
napi_value args [1 ];
@@ -38,6 +54,19 @@ static napi_value allowException(napi_env env, napi_callback_info info) {
38
54
return NULL ;
39
55
}
40
56
57
+ static napi_value constructAllowException (napi_env env , napi_callback_info info ) {
58
+ size_t argc = 1 ;
59
+ napi_value args [1 ];
60
+ NODE_API_CALL (env , napi_get_cb_info (env , info , & argc , args , NULL , NULL ));
61
+
62
+ napi_value result ;
63
+ napi_new_instance (env , args [0 ], 0 , 0 , & result );
64
+ // Ignore status and check napi_is_exception_pending() instead.
65
+
66
+ NODE_API_CALL (env , napi_is_exception_pending (env , & exceptionWasPending ));
67
+ return NULL ;
68
+ }
69
+
41
70
static napi_value wasPending (napi_env env , napi_callback_info info ) {
42
71
napi_value result ;
43
72
NODE_API_CALL (env , napi_get_boolean (env , exceptionWasPending , & result ));
@@ -64,6 +93,8 @@ napi_value Init(napi_env env, napi_value exports) {
64
93
napi_property_descriptor descriptors [] = {
65
94
DECLARE_NODE_API_PROPERTY ("returnException" , returnException ),
66
95
DECLARE_NODE_API_PROPERTY ("allowException" , allowException ),
96
+ DECLARE_NODE_API_PROPERTY ("constructReturnException" , constructReturnException ),
97
+ DECLARE_NODE_API_PROPERTY ("constructAllowException" , constructAllowException ),
67
98
DECLARE_NODE_API_PROPERTY ("wasPending" , wasPending ),
68
99
DECLARE_NODE_API_PROPERTY ("createExternal" , createExternal ),
69
100
};
0 commit comments