commit 9341f5ee7d69f4199a5f5d1e36a361bb4e369188
parent 631c0445009e2ff752ffb602d3a7f94291062338
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Tue, 30 Apr 2024 01:00:15 +0200
fix(scripting): optimization level
Diffstat:
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/scripting/JSModule.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/scripting/JSModule.kt
@@ -183,7 +183,9 @@ class JSModule(
else -> moduleBindings[bindingName]?.getObject()
}
}
+ }
+ contextScope(shouldOptimize = true) {
evaluateString(moduleObject, content, moduleInfo.name, 1, null)
}
}
diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/scripting/ktx/RhinoKtx.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/scripting/ktx/RhinoKtx.kt
@@ -10,9 +10,10 @@ import java.io.File
private val rhinoAndroidHelper = RhinoAndroidHelper(null as File?)
-fun contextScope(f: Context.() -> Any?): Any? {
+fun contextScope(shouldOptimize: Boolean = false, f: Context.() -> Any?): Any? {
val context = rhinoAndroidHelper.enterContext().apply {
languageVersion = Context.VERSION_ES6
+ optimizationLevel = if (!shouldOptimize) -1 else 0
}
try {
return context.f().let {