JS: better debug logging

Change-Id: I5ff4feefd09812b9ff6e16aa041831d3b7497033
Fix Nullpointer exception

Change-Id: I8d5b2828c056e90f3a69c3f10c0ffaa322a39db8