Skip to content

Instantly share code, notes, and snippets.

@jisungbin
Created April 6, 2020 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jisungbin/6d76ade2d9481150b18736f3ad97ea44 to your computer and use it in GitHub Desktop.
Save jisungbin/6d76ade2d9481150b18736f3ad97ea44 to your computer and use it in GitHub Desktop.
package com.sungbin.autoreply.bot.three.service
import org.mozilla.javascript.Context
import org.mozilla.javascript.Scriptable
class RhinoService {
fun runJs(source: String): String{
val rhino: Context = Context.enter()
rhino.languageVersion = Context.VERSION_ES6
rhino.optimizationLevel = -1
return try {
val scope: Scriptable = rhino.initSafeStandardObjects()
val result: Any = rhino.evaluateString(scope, source, "sandbox", 1, null)
result.toString()
} catch (e: Exception) {
e.toString()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment