Created
April 6, 2020 22:50
-
-
Save jisungbin/6d76ade2d9481150b18736f3ad97ea44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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