This commit is contained in:
Horis committed 2024-07-31 17:42:19 +08:00
1 parent 1376feaecf
commit bc7b9383f5
18 files changed
+117 -40

No files matched your search

@@ -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()
}
}
}