Skip to content

Commit

Permalink
代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
aiselp committed Sep 15, 2023
1 parent 48ae953 commit f888975
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ open class RhinoJavaScriptEngine(private val mAndroidContext: android.content.Co
}
}

internal fun initRequireBuilder(context: Context, scope: Scriptable) {
private fun initRequireBuilder(context: Context, scope: Scriptable) {
val provider = AssetAndUrlModuleSourceProvider(
mAndroidContext,
listOf(
Expand All @@ -126,7 +126,7 @@ open class RhinoJavaScriptEngine(private val mAndroidContext: android.content.Co
require.install(scope)
}

protected fun createScope(context: Context): TopLevelScope {
private fun createScope(context: Context): TopLevelScope {
val topLevelScope = TopLevelScope()
topLevelScope.initStandardObjects(context, false)
return topLevelScope
Expand All @@ -139,7 +139,7 @@ open class RhinoJavaScriptEngine(private val mAndroidContext: android.content.Co
return context
}

private fun setupContext(context: Context) {
fun setupContext(context: Context) {
context.wrapFactory = WrapFactory()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ class ScriptBridges {

private fun <T> useJsContext(f: (context: Context) -> T): T {
val context = Context.getCurrentContext()
val cx: Context = context ?: with(Context.enter()) {
engine?.setupContext(this)
this
}
try {
return f(context ?: engine?.enterContext() ?: Context.enter())
return f(cx)
} finally {
context ?: Context.exit()
}
Expand Down

0 comments on commit f888975

Please sign in to comment.