From 9e08447578765d5ee95a3ae394f734759bce4858 Mon Sep 17 00:00:00 2001 From: Vladislav Areshkin Date: Thu, 17 Jun 2021 19:32:39 +0700 Subject: [PATCH] Update README.md --- README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2ff2c87..51c46aa 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![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) +[![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) # Mobile Kotlin javascript This is a Kotlin MultiPlatform library that allows you to run JavaScript code from common Kotlin code @@ -46,10 +46,15 @@ dependencies { ## Usage ```kotlin val javaScriptEngine = JavaScriptEngine() -val result: JsType = javaScriptEngine.evaluate( - context = emptyMap(), - script = """ "Hello" + "World" """.trimIndent() -) +val result: JsType = try { + javaScriptEngine.evaluate( + context = emptyMap(), + script = """ "Hello" + "World" """.trimIndent() + ) +} catch (ex: JavaScriptEvaluationException) { + // Handle script evaluation error + JsType.Null +} if (result is JsType.Str) { println(result.value) } @@ -83,4 +88,4 @@ More detailed guide for contributers see in [contributing guide](CONTRIBUTING.md distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file + limitations under the License.