File tree Expand file tree Collapse file tree 3 files changed +39
-33
lines changed
javascript/src/androidMain/kotlin/dev/icerock/moko/javascript Expand file tree Collapse file tree 3 files changed +39
-33
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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- }
You can’t perform that action at this time.
0 commit comments