Kotlin eval() 危险吗?

Is Kotlin eval() dangerous?

我读了in the documentation of Javascript:

eval() is a dangerous function, which executes the code it's passed with the privileges of the caller. If you run eval() with a string that could be affected by a malicious party, you may end up running malicious code on the user's machine with the permissions of your webpage / extension.

我的问题是:这在 Kotlin 中是一样的吗?如果是这样,考虑到 Kotlin 是一种更先进、更现代的语言,为什么要实施它?

在 JavaScript 项目中使用 Kotlin 时,Kotlin 代码将被转换为 JavaScript 代码。为了提供完全兼容性,还可以使用 eval()。并回答主要问题:

是的,在 Kotlin 代码中使用 eval() 与在 JavaScript 代码中使用它一样危险 并且应该避免使用,原因与您已经提到的相同在你的问题中。

将 Kotlin 用于基于 JVM 的项目或本机项目时,您无权访问 eval 函数,因为它仅与 JavaScript.

兼容