Hmm, looks like it is _javascript_-mode specific...
Here is a simple workaround:
(defun cleanup-trailing-whitespaces ()
(interactive)
(let ((m-m major-mode))
(fundamental-mode)
(delete-trailing-whitespace)
(funcall m-m)))
But it seems to me that I also had a wrong behaviour of the delete-trailing-whitespace for other major-modes. Can not prove it though).