The problem with running crypto code in Javascript is that practically any function that the crypto depends on could be overridden silently by any piece of content used to build the hosting page.
Ecmascript 5, the latest version of the Javascript standard, provides the ability to lock down the malleable runtime. Functions can be frozen so that no later code can overwrite or change their behavior. For more information, see this talk[1] by Mario Heiderich in 2011 or his slides[2].
[1] https://www.youtube.com/watch?v=yuNfO6I6pEA
[2] https://www.owasp.org/images/a/a3/Mario_Heiderich_OWASP_Swed...