@@ -19,29 +19,10 @@ core.trap_add() {
1919 fi
2020 local function=" $1 "
2121
22- # Validation
23- if [ -z " $function " ]; then
24- core.panic ' First argument must not be empty'
25- fi
26-
27- if (( $# <= 1 )) ; then
28- core.panic ' Must specify at least one signal'
29- fi
22+ core.private.util.validate_args " $function " $#
3023 for signal_spec in " ${@: 2} " ; do
31- if [ -z " $signal_spec " ]; then
32- core.panic ' Signal must not be an empty string'
33- fi
34-
35- local regex=' ^[0-9]+$'
36- if [[ " $signal_spec " =~ $regex ]]; then
37- core.panic ' Passing numbers for the signal specs is prohibited'
38- fi ; unset regex
39- signal_spec=${signal_spec# SIG}
40- if ! declare -f " $function " & > /dev/null; then
41- core.panic " Function '$function ' is not defined"
42- fi
24+ core.private.util.validate_signal " $function " " $signal_spec "
4325
44- # Start
4526 ___global_trap_table___[" $signal_spec " ]=" ${___global_trap_table___[$signal_spec]} " $' \x1C ' " $function "
4627
4728 # rho (WET)
@@ -80,29 +61,10 @@ core.trap_remove() {
8061 fi
8162 local function=" $1 "
8263
83- # Validation
84- if [ -z " $function " ]; then
85- core.panic ' First argument must not be empty'
86- fi
87-
88- if (( $# <= 1 )) ; then
89- core.panic ' Must specify at least one signal'
90- fi
64+ core.private.util.validate_args " $function " $#
9165 for signal_spec in " ${@: 2} " ; do
92- if [ -z " $signal_spec " ]; then
93- core.panic ' Signal must not be an empty string'
94- fi
95-
96- local regex=' ^[0-9]+$'
97- if [[ " $signal_spec " =~ $regex ]]; then
98- core.panic ' Passing numbers for the signal specs is prohibited'
99- fi ; unset regex
100- signal_spec=" ${signal_spec# SIG} "
101- if ! declare -f " $function " & > /dev/null; then
102- core.panic " Function '$function ' is not defined"
103- fi
66+ core.private.util.validate_signal " $function " " $signal_spec "
10467
105- # Start
10668 local -a trap_handlers=()
10769 local new_trap_handlers=
10870 IFS=$' \x1C ' read -ra trap_handlers <<< " ${___global_trap_table___[$signal_spec]}"
0 commit comments