Skip to content

Commit

Permalink
* Added GuardException as a mechanism to differentiate coding excepti…
Browse files Browse the repository at this point in the history
…ons from GuardedExceptions.

* Better runtime exception handling and report.
* Added methods guardPreCondition and guardPostCondition to Session lifecycle.
  • Loading branch information
ibon tolosana committed Feb 5, 2013
1 parent c4b1bc0 commit 88f9105
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
39 changes: 37 additions & 2 deletions automata.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ var module = module || {};

FSM.GuardException= function(msg) {
this.msg= msg;

this.toString= function() {
return this.msg;
}

return this;
};

Expand Down Expand Up @@ -916,7 +921,12 @@ var module = module || {};
try {
firingTransition.checkGuardPreCondition( msg, this );
} catch( e ) {
return; // fails on pre-guard. simply return.
if ( e instanceof FSM.GuardException ) {
this.fireGuardPreCondition(firingTransition, msg, e);
return; // fails on pre-guard. simply return.
} else {
console.error("An error ocurred: "+ e.message, e.stack);
}
}

this.transitioning= true;
Expand Down Expand Up @@ -948,6 +958,7 @@ var module = module || {};
}
} catch( guardException ) {
if ( guardException instanceof FSM.GuardException ) {
this.fireGuardPostCondition(firingTransition, msg, guardException);
firingTransition.firePreTransitionGuardedByPostCondition( msg, this );
this.fireStateChanged( target, firingTransition.initialState, msg );
firingTransition.firePostTransitionGuardedByPostCondition( msg, this );
Expand Down Expand Up @@ -1051,6 +1062,28 @@ var module = module || {};
}
},

fireGuardPreCondition : function( firingTransition, msg, guardException ) {
for( var i=0; i<this.sessionListener.length; i++ ) {
this.sessionListener[i].guardPreCondition( {
session : this,
transition : firingTransition,
message : msg,
exception : guardException
});
}
},

fireGuardPostCondition : function( firingTransition, msg, guardException ) {
for( var i=0; i<this.sessionListener.length; i++ ) {
this.sessionListener[i].guardPostCondition( {
session : this,
transition : firingTransition,
message : msg,
exception : guardException
});
}
},

fireCustomEvent : function( msg ) {
for( var i=0; i<this.sessionListener.length; i++ ) {
this.sessionListener[i].customEvent( {
Expand All @@ -1076,7 +1109,9 @@ var module = module || {};
contextDestroyed : function( obj ) {},
finalStateReached : function( obj ) {},
stateChanged : function( obj ) {},
customEvent : function( obj ) {}
customEvent : function( obj ) {},
guardPreCondition : function( obj ) {},
guardPostCondition : function( obj ) {}
};

/**
Expand Down
7 changes: 7 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
04-02-2013 *1.0.7*
------------------

* 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.

05-15-2010 *1.0.6*
------------------

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "automata",
"version": "1.0.6",
"version": "1.0.7",
"main": "automata",
"keywords": [
"DFA",
Expand Down

0 comments on commit 88f9105

Please sign in to comment.