@@ -1201,3 +1201,57 @@ TEST_F(EnvironmentTest, LoadEnvironmentWithCallbackWithESModule) {
12011201 printf (" Frame: %s\n " , *frame_str);
12021202 EXPECT_EQ (frame_str.ToString (), " at embedded:esm.mjs:3:15" );
12031203}
1204+
1205+ namespace {
1206+ void CustomAbortHandlerForContractTest (const char * location,
1207+ const char * message) {}
1208+
1209+ bool abort_handler_dispatch_flag = false ;
1210+ const char * abort_handler_received_location = nullptr ;
1211+ const char * abort_handler_received_message = nullptr ;
1212+ void AbortHandlerThatSetsDispatchFlag (const char * location,
1213+ const char * message) {
1214+ abort_handler_dispatch_flag = true ;
1215+ abort_handler_received_location = location;
1216+ abort_handler_received_message = message;
1217+ }
1218+ } // namespace
1219+
1220+ TEST (AbortHandlerTest, DefaultIsNonNullAndSetAbortHandlerRoundTrips) {
1221+ node::AbortHandler old = node::GetAbortHandler ();
1222+
1223+ // There should always be a non-null default handler installed.
1224+ EXPECT_NE (node::GetAbortHandler (), nullptr );
1225+
1226+ node::SetAbortHandler (CustomAbortHandlerForContractTest);
1227+ EXPECT_EQ (node::GetAbortHandler (), CustomAbortHandlerForContractTest);
1228+
1229+ node::SetAbortHandler (nullptr );
1230+ EXPECT_NE (node::GetAbortHandler (), nullptr );
1231+ EXPECT_NE (node::GetAbortHandler (), CustomAbortHandlerForContractTest);
1232+
1233+ node::SetAbortHandler (old);
1234+ }
1235+
1236+ TEST (AbortHandlerTest, InstalledHandlerIsInvokedWhenCalled) {
1237+ node::AbortHandler old = node::GetAbortHandler ();
1238+ abort_handler_dispatch_flag = false ;
1239+ abort_handler_received_location = nullptr ;
1240+ abort_handler_received_message = nullptr ;
1241+
1242+ node::SetAbortHandler (AbortHandlerThatSetsDispatchFlag);
1243+ node::AbortHandler h = node::GetAbortHandler ();
1244+ // Fail cleanly (instead of crashing on a null call) if the handler wasn't
1245+ // actually installed.
1246+ ASSERT_NE (h, nullptr );
1247+
1248+ // Dispatch through the public GetAbortHandler() accessor directly (not via
1249+ // the ABORT() macro, so nothing terminates), and verify the message is
1250+ // passed through unchanged.
1251+ node::GetAbortHandler ()(" some-test-location" , " some-test-message" );
1252+ EXPECT_TRUE (abort_handler_dispatch_flag);
1253+ EXPECT_STREQ (abort_handler_received_location, " some-test-location" );
1254+ EXPECT_STREQ (abort_handler_received_message, " some-test-message" );
1255+
1256+ node::SetAbortHandler (old);
1257+ }
0 commit comments