Yet another javascript fsm