[JavaScript] added 'directive' state

it will be useful in NodeJS
fixed an issue that causes infinite loop
update themes