Skip to content

Commit 601d5d4

Browse files
committed
extract context provider classes to file
1 parent 168bc1c commit 601d5d4

File tree

3 files changed

+39
-33
lines changed

3 files changed

+39
-33
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package dev.icerock.moko.javascript
2+
3+
internal interface ContextProvider {
4+
fun getBool(name: String): Boolean
5+
fun getDouble(name: String): Double
6+
7+
fun getString(name: String): String
8+
9+
fun getScript(): String
10+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package dev.icerock.moko.javascript
6+
7+
internal class ContextProviderDynamic : ContextProvider {
8+
var context: Map<String, JsType> = emptyMap()
9+
var activeScript: String = ""
10+
11+
override fun getBool(name: String): Boolean {
12+
return context[name]!!.boolValue()
13+
}
14+
15+
override fun getDouble(name: String): Double {
16+
return context[name]!!.doubleValue()
17+
}
18+
19+
override fun getString(name: String): String {
20+
val jsType: JsType = context[name]!!
21+
return when (jsType) {
22+
is JsType.Bool, is JsType.DoubleNum, JsType.Null -> throw IllegalArgumentException()
23+
is JsType.Json -> jsType.value.toString()
24+
is JsType.Str -> jsType.value
25+
}
26+
}
27+
28+
override fun getScript(): String = activeScript
29+
}

javascript/src/androidMain/kotlin/dev/icerock/moko/javascript/JavaScriptEngine.kt

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -108,36 +108,3 @@ actual class JavaScriptEngine actual constructor() {
108108
}
109109
}
110110
}
111-
112-
private interface ContextProvider {
113-
fun getBool(name: String): Boolean
114-
fun getDouble(name: String): Double
115-
116-
fun getString(name: String): String
117-
118-
fun getScript(): String
119-
}
120-
121-
private class ContextProviderDynamic : ContextProvider {
122-
var context: Map<String, JsType> = emptyMap()
123-
var activeScript: String = ""
124-
125-
override fun getBool(name: String): Boolean {
126-
return context[name]!!.boolValue()
127-
}
128-
129-
override fun getDouble(name: String): Double {
130-
return context[name]!!.doubleValue()
131-
}
132-
133-
override fun getString(name: String): String {
134-
val jsType: JsType = context[name]!!
135-
return when (jsType) {
136-
is JsType.Bool, is JsType.DoubleNum, JsType.Null -> throw IllegalArgumentException()
137-
is JsType.Json -> jsType.value.toString()
138-
is JsType.Str -> jsType.value
139-
}
140-
}
141-
142-
override fun getScript(): String = activeScript
143-
}

0 commit comments

Comments
 (0)