Add a guard before deref history.

There were certain cases causing togetherjs to break
here when history would be undefined. This was caused
by, for instance, when text in a text box were changed
by script.