@@ -300,6 +300,11 @@ var module = module || {};
300300
301301 FSM . GuardException = function ( msg ) {
302302 this . msg = msg ;
303+
304+ this . toString = function ( ) {
305+ return this . msg ;
306+ }
307+
303308 return this ;
304309 } ;
305310
@@ -916,7 +921,12 @@ var module = module || {};
916921 try {
917922 firingTransition . checkGuardPreCondition ( msg , this ) ;
918923 } catch ( e ) {
919- return ; // fails on pre-guard. simply return.
924+ if ( e instanceof FSM . GuardException ) {
925+ this . fireGuardPreCondition ( firingTransition , msg , e ) ;
926+ return ; // fails on pre-guard. simply return.
927+ } else {
928+ console . error ( "An error ocurred: " + e . message , e . stack ) ;
929+ }
920930 }
921931
922932 this . transitioning = true ;
@@ -948,6 +958,7 @@ var module = module || {};
948958 }
949959 } catch ( guardException ) {
950960 if ( guardException instanceof FSM . GuardException ) {
961+ this . fireGuardPostCondition ( firingTransition , msg , guardException ) ;
951962 firingTransition . firePreTransitionGuardedByPostCondition ( msg , this ) ;
952963 this . fireStateChanged ( target , firingTransition . initialState , msg ) ;
953964 firingTransition . firePostTransitionGuardedByPostCondition ( msg , this ) ;
@@ -1051,6 +1062,28 @@ var module = module || {};
10511062 }
10521063 } ,
10531064
1065+ fireGuardPreCondition : function ( firingTransition , msg , guardException ) {
1066+ for ( var i = 0 ; i < this . sessionListener . length ; i ++ ) {
1067+ this . sessionListener [ i ] . guardPreCondition ( {
1068+ session : this ,
1069+ transition : firingTransition ,
1070+ message : msg ,
1071+ exception : guardException
1072+ } ) ;
1073+ }
1074+ } ,
1075+
1076+ fireGuardPostCondition : function ( firingTransition , msg , guardException ) {
1077+ for ( var i = 0 ; i < this . sessionListener . length ; i ++ ) {
1078+ this . sessionListener [ i ] . guardPostCondition ( {
1079+ session : this ,
1080+ transition : firingTransition ,
1081+ message : msg ,
1082+ exception : guardException
1083+ } ) ;
1084+ }
1085+ } ,
1086+
10541087 fireCustomEvent : function ( msg ) {
10551088 for ( var i = 0 ; i < this . sessionListener . length ; i ++ ) {
10561089 this . sessionListener [ i ] . customEvent ( {
@@ -1076,7 +1109,9 @@ var module = module || {};
10761109 contextDestroyed : function ( obj ) { } ,
10771110 finalStateReached : function ( obj ) { } ,
10781111 stateChanged : function ( obj ) { } ,
1079- customEvent : function ( obj ) { }
1112+ customEvent : function ( obj ) { } ,
1113+ guardPreCondition : function ( obj ) { } ,
1114+ guardPostCondition : function ( obj ) { }
10801115 } ;
10811116
10821117 /**
0 commit comments