This commit is contained in:
kunfei
2023-04-20 22:49:12 +08:00
parent f817954b7c
commit 4db8213312
3 changed files with 71 additions and 17 deletions
@@ -0,0 +1,27 @@
@file:Suppress("unused")
package io.legado.app.rhino
import org.mozilla.javascript.Context
import org.mozilla.javascript.Scriptable
import org.mozilla.javascript.ScriptableObject
import java.io.Reader
fun Context.evaluateString(scope: Scriptable, source: String, sourceName: String) {
evaluateString(scope, source, sourceName, 1, null)
}
fun Context.evaluateReader(scope: Scriptable, reader: Reader, sourceName: String) {
evaluateReader(scope, reader, sourceName, 1, null)
}
fun Scriptable.putBinding(key: String, value: Any?) {
val wrappedOut = Context.javaToJS(value, this)
ScriptableObject.putProperty(this, key, wrappedOut)
}
fun Scriptable.putBindings(bindings: Map<String, Any?>) {
bindings.forEach { (t, u) ->
putBinding(t, u)
}
}