From 218f8fba7b61ac0940c51a4cdd1a6136bdb4bea3 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Fri, 29 May 2026 14:23:21 -0600 Subject: [PATCH 1/3] Always use convince wrappers, make class itself private --- .../com/lagradost/cloudstream3/utils/JsInterpreter.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/JsInterpreter.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/JsInterpreter.kt index 3d85f87a22a..8b2b96584b4 100644 --- a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/JsInterpreter.kt +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/JsInterpreter.kt @@ -29,13 +29,16 @@ import kotlin.math.* * - typeof * * Usage: - * val result = JsInterpreter().eval("var x = 1+2; x") + * val result = evalJs("var x = 1+2; x") * // result == 3.0 (numbers are always Double internally) * * // Drop-in replacement for the old Rhino-based evaluateString pattern: * val ctx = JsContext() * ctx.eval("var url = 'https:' + computeSuffix()") * val url = ctx["url"] // retrieves the variable as a String + * + * // Or simpler: + * val url = evalJs("var url = 'https:' + computeSuffix()", "url") */ /** @@ -695,8 +698,7 @@ private class Scope(val parent: Scope? = null) { if (vars.containsKey(name)) this else parent?.findOwner(name) } -@Prerelease -class JsInterpreter { +private class JsInterpreter { private val globalScope = Scope() init { installGlobals() } From 4a2bb68edfce8556ddf987746205645facbeb9e2 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Fri, 29 May 2026 14:25:12 -0600 Subject: [PATCH 2/3] - --- .../com/lagradost/cloudstream3/utils/JsInterpreterTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/commonTest/kotlin/com/lagradost/cloudstream3/utils/JsInterpreterTest.kt b/library/src/commonTest/kotlin/com/lagradost/cloudstream3/utils/JsInterpreterTest.kt index 20b46acb93d..df186066d1f 100644 --- a/library/src/commonTest/kotlin/com/lagradost/cloudstream3/utils/JsInterpreterTest.kt +++ b/library/src/commonTest/kotlin/com/lagradost/cloudstream3/utils/JsInterpreterTest.kt @@ -9,7 +9,7 @@ import kotlin.test.assertFalse class JsInterpreterTest { - private fun num(code: String, variable: String? = null) = (evalJs(code, variable) as? Double) ?: Double.NaN + private fun num(code: String, variable: String? = null) = evalJs(code, variable) as? Double ?: Double.NaN private fun str(code: String, variable: String? = null) = jsValueToString(evalJs(code, variable)) private fun bool(code: String, variable: String? = null) = evalJs(code, variable) as? Boolean ?: false From d8cbc682b5a93b077c48aa98ca52ee29ad7ddb8f Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Fri, 29 May 2026 14:25:54 -0600 Subject: [PATCH 3/3] order --- .../com/lagradost/cloudstream3/utils/JsInterpreterTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/commonTest/kotlin/com/lagradost/cloudstream3/utils/JsInterpreterTest.kt b/library/src/commonTest/kotlin/com/lagradost/cloudstream3/utils/JsInterpreterTest.kt index df186066d1f..3e90feccd39 100644 --- a/library/src/commonTest/kotlin/com/lagradost/cloudstream3/utils/JsInterpreterTest.kt +++ b/library/src/commonTest/kotlin/com/lagradost/cloudstream3/utils/JsInterpreterTest.kt @@ -9,9 +9,9 @@ import kotlin.test.assertFalse class JsInterpreterTest { + private fun bool(code: String, variable: String? = null) = evalJs(code, variable) as? Boolean ?: false private fun num(code: String, variable: String? = null) = evalJs(code, variable) as? Double ?: Double.NaN private fun str(code: String, variable: String? = null) = jsValueToString(evalJs(code, variable)) - private fun bool(code: String, variable: String? = null) = evalJs(code, variable) as? Boolean ?: false private fun assertApprox(expected: Double, actual: Double, tol: Double = 1e-9) { assertTrue(abs(actual - expected) <= tol, "Expected $expected ± $tol but was $actual")