Unless you want to write your own Javascript interpreter and execution engine, you would have to use a 3rd party library to do something like this, like
Jint[
^].
But, you're at the mercy of those people who write the library. Not every feature of every ECMAScript standard is going to be implemented and some things may not work to standard.