|
|
@@ -86,32 +86,6 @@ object RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|
|
return eval(js, bindings)
|
|
|
}
|
|
|
|
|
|
- @Throws(ScriptException::class)
|
|
|
- override fun eval(reader: Reader, scope: Scriptable): Any? {
|
|
|
- val cx = Context.enter()
|
|
|
- val ret: Any?
|
|
|
- try {
|
|
|
- var filename = this["javax.script.filename"] as? String
|
|
|
- filename = filename ?: "<Unknown source>"
|
|
|
- ret = cx.evaluateReader(scope, reader, filename, 1, null)
|
|
|
- } catch (re: RhinoException) {
|
|
|
- val line = if (re.lineNumber() == 0) -1 else re.lineNumber()
|
|
|
- val msg: String = if (re is JavaScriptException) {
|
|
|
- re.value.toString()
|
|
|
- } else {
|
|
|
- re.toString()
|
|
|
- }
|
|
|
- val se = ScriptException(msg, re.sourceName(), line)
|
|
|
- se.initCause(re)
|
|
|
- throw se
|
|
|
- } catch (var14: IOException) {
|
|
|
- throw ScriptException(var14)
|
|
|
- } finally {
|
|
|
- Context.exit()
|
|
|
- }
|
|
|
- return unwrapReturnValue(ret)
|
|
|
- }
|
|
|
-
|
|
|
override fun eval(
|
|
|
reader: Reader,
|
|
|
scope: Scriptable,
|
|
|
@@ -120,6 +94,7 @@ object RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|
|
val cx = Context.enter() as RhinoContext
|
|
|
val previousCoroutineContext = cx.coroutineContext
|
|
|
cx.coroutineContext = coroutineContext
|
|
|
+ cx.allowScriptRun = true
|
|
|
val ret: Any?
|
|
|
try {
|
|
|
var filename = this["javax.script.filename"] as? String
|
|
|
@@ -139,6 +114,7 @@ object RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|
|
throw ScriptException(var14)
|
|
|
} finally {
|
|
|
cx.coroutineContext = previousCoroutineContext
|
|
|
+ cx.allowScriptRun = false
|
|
|
Context.exit()
|
|
|
}
|
|
|
return unwrapReturnValue(ret)
|
|
|
@@ -146,9 +122,10 @@ object RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|
|
|
|
|
@Throws(ContinuationPending::class)
|
|
|
override suspend fun evalSuspend(reader: Reader, scope: Scriptable): Any? {
|
|
|
- val cx = Context.enter()
|
|
|
+ val cx = Context.enter() as RhinoContext
|
|
|
var ret: Any?
|
|
|
withContext(VMBridgeReflect.contextLocal.asContextElement()) {
|
|
|
+ cx.allowScriptRun = true
|
|
|
try {
|
|
|
var filename = this@RhinoScriptEngine["javax.script.filename"] as? String
|
|
|
filename = filename ?: "<Unknown source>"
|
|
|
@@ -186,6 +163,7 @@ object RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|
|
} catch (var14: IOException) {
|
|
|
throw ScriptException(var14)
|
|
|
} finally {
|
|
|
+ cx.allowScriptRun = false
|
|
|
Context.exit()
|
|
|
}
|
|
|
}
|
|
|
@@ -395,7 +373,12 @@ object RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|
|
args: Array<Any>
|
|
|
): Any? {
|
|
|
try {
|
|
|
- (cx as RhinoContext).ensureActive()
|
|
|
+ if (cx is RhinoContext) {
|
|
|
+ if (!cx.allowScriptRun) {
|
|
|
+ error("Not allow run script in unauthorized way.")
|
|
|
+ }
|
|
|
+ cx.ensureActive()
|
|
|
+ }
|
|
|
return super.doTopCall(callable, cx, scope, thisObj, args)
|
|
|
} catch (e: RhinoInterruptError) {
|
|
|
throw e.cause
|