优化
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
*/
|
||||
package com.script
|
||||
|
||||
import org.mozilla.javascript.Scriptable
|
||||
|
||||
abstract class CompiledScript {
|
||||
|
||||
abstract fun getEngine(): ScriptEngine
|
||||
@@ -10,6 +12,9 @@ abstract class CompiledScript {
|
||||
@Throws(ScriptException::class)
|
||||
abstract fun eval(context: ScriptContext): Any?
|
||||
|
||||
@Throws(ScriptException::class)
|
||||
abstract fun eval(scope: Scriptable): Any?
|
||||
|
||||
@Throws(ScriptException::class)
|
||||
fun eval(bindings: Bindings?): Any? {
|
||||
var ctxt = getEngine().context
|
||||
|
||||
@@ -69,4 +69,26 @@ internal class RhinoCompiledScript(
|
||||
return result
|
||||
}
|
||||
|
||||
override fun eval(scope: Scriptable): Any? {
|
||||
val cx = Context.enter()
|
||||
val result: Any?
|
||||
try {
|
||||
val ret = script.exec(cx, scope)
|
||||
result = engine.unwrapReturnValue(ret)
|
||||
} 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
|
||||
} finally {
|
||||
Context.exit()
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user