Skip to content

Commit 9e08447

Browse files
authored
Update README.md
1 parent e188ab7 commit 9e08447

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0) [![Download](https://img.shields.io/maven-central/v/dev.icerock.moko/javascript) ](https://repo1.maven.org/maven2/dev/icerock/moko/javascript) ![kotlin-version](https://img.shields.io/badge/kotlin-1.4.32-orange)
1+
[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0) [![Download](https://img.shields.io/maven-central/v/dev.icerock.moko/javascript) ](https://repo1.maven.org/maven2/dev/icerock/moko/javascript/) ![kotlin-version](https://img.shields.io/badge/kotlin-1.4.32-orange)
22

33
# Mobile Kotlin javascript
44
This is a Kotlin MultiPlatform library that allows you to run JavaScript code from common Kotlin code
@@ -46,10 +46,15 @@ dependencies {
4646
## Usage
4747
```kotlin
4848
val javaScriptEngine = JavaScriptEngine()
49-
val result: JsType = javaScriptEngine.evaluate(
50-
context = emptyMap(),
51-
script = """ "Hello" + "World" """.trimIndent()
52-
)
49+
val result: JsType = try {
50+
javaScriptEngine.evaluate(
51+
context = emptyMap(),
52+
script = """ "Hello" + "World" """.trimIndent()
53+
)
54+
} catch (ex: JavaScriptEvaluationException) {
55+
// Handle script evaluation error
56+
JsType.Null
57+
}
5358
if (result is JsType.Str) {
5459
println(result.value)
5560
}
@@ -83,4 +88,4 @@ More detailed guide for contributers see in [contributing guide](CONTRIBUTING.md
8388
distributed under the License is distributed on an "AS IS" BASIS,
8489
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8590
See the License for the specific language governing permissions and
86-
limitations under the License.
91+
limitations under the License.

0 commit comments

Comments
 (0)