Skip to content

Commit 88f9105

Browse files
author
ibon tolosana
committed
* Added GuardException as a mechanism to differentiate coding exceptions from GuardedExceptions.
* Better runtime exception handling and report. * Added methods guardPreCondition and guardPostCondition to Session lifecycle.
1 parent c4b1bc0 commit 88f9105

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

automata.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
/**

changelog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
04-02-2013 *1.0.7*
2+
------------------
3+
4+
* Added GuardException as a mechanism to differentiate coding exceptions from GuardedExceptions.
5+
* Better runtime exception handling and report.
6+
* Added methods guardPreCondition and guardPostCondition to Session lifecycle.
7+
18
05-15-2010 *1.0.6*
29
------------------
310

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "automata",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"main": "automata",
55
"keywords": [
66
"DFA",

0 commit comments

Comments
 (0)