This commit is contained in:
Horis
2024-07-31 17:42:19 +08:00
parent beb561a052
commit 7e6a1e4749
18 changed files with 117 additions and 40 deletions
@@ -0,0 +1,42 @@
package com.script
import org.mozilla.javascript.Context
import org.mozilla.javascript.NativeObject
import org.mozilla.javascript.ScriptableObject
class ScriptBindings : NativeObject() {
companion object {
private val topLevelScope: ScriptableObject by lazy {
val cx = Context.enter()
try {
cx.initStandardObjects()
} finally {
Context.exit()
}
}
}
init {
prototype = topLevelScope
}
operator fun set(key: String, value: Any?) {
Context.enter()
try {
put(key, this, Context.javaToJS(value, this))
} finally {
Context.exit()
}
}
operator fun set(index: Int, value: Any?) {
Context.enter()
try {
put(index, this, Context.javaToJS(value, this))
} finally {
Context.exit()
}
}
}