@@ -22,6 +22,22 @@ static napi_value returnException(napi_env env, napi_callback_info info) {
2222 return NULL ;
2323}
2424
25+ static napi_value constructReturnException (napi_env env , napi_callback_info info ) {
26+ size_t argc = 1 ;
27+ napi_value args [1 ];
28+ NAPI_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+ NAPI_CALL (env , napi_get_and_clear_last_exception (env , & ex ));
35+ return ex ;
36+ }
37+
38+ return NULL ;
39+ }
40+
2541static napi_value allowException (napi_env env , napi_callback_info info ) {
2642 size_t argc = 1 ;
2743 napi_value args [1 ];
@@ -38,6 +54,19 @@ static napi_value allowException(napi_env env, napi_callback_info info) {
3854 return NULL ;
3955}
4056
57+ static napi_value constructAllowException (napi_env env , napi_callback_info info ) {
58+ size_t argc = 1 ;
59+ napi_value args [1 ];
60+ NAPI_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+ NAPI_CALL (env , napi_is_exception_pending (env , & exceptionWasPending ));
67+ return NULL ;
68+ }
69+
4170static napi_value wasPending (napi_env env , napi_callback_info info ) {
4271 napi_value result ;
4372 NAPI_CALL (env , napi_get_boolean (env , exceptionWasPending , & result ));
@@ -64,6 +93,8 @@ napi_value Init(napi_env env, napi_value exports) {
6493 napi_property_descriptor descriptors [] = {
6594 DECLARE_NAPI_PROPERTY ("returnException" , returnException ),
6695 DECLARE_NAPI_PROPERTY ("allowException" , allowException ),
96+ DECLARE_NAPI_PROPERTY ("constructReturnException" , constructReturnException ),
97+ DECLARE_NAPI_PROPERTY ("constructAllowException" , constructAllowException ),
6798 DECLARE_NAPI_PROPERTY ("wasPending" , wasPending ),
6899 DECLARE_NAPI_PROPERTY ("createExternal" , createExternal ),
69100 };
0 commit comments