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).