From 04592cc177289cfbc4f596f3f51da83d33688227 Mon Sep 17 00:00:00 2001
From: David Vazgenovich Shakaryan <dvshakaryan@gmail.com>
Date: Wed, 27 Apr 2022 05:07:10 -0700
Subject: web: let's use our new function

---
 web/static/dartboat.js | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

(limited to 'web/static')

diff --git a/web/static/dartboat.js b/web/static/dartboat.js
index e43488b..4c2be26 100644
--- a/web/static/dartboat.js
+++ b/web/static/dartboat.js
@@ -19,12 +19,15 @@ function scheduleCCall(f, ms, ...args) {
 	setTimeout(() => Module[`_${func}`](...args), ms);
 }
 
-function promptGet() {
-	let tc = document.getElementById('prompt-input').textContent;
-	let len = lengthBytesUTF8(tc) + 1;
-	let str = _malloc(len);
-	stringToUTF8(tc, str, len);
-	return str;
+function toCString(str) { // caller must free
+	const len = lengthBytesUTF8(str) + 1;
+	const cstr = _malloc(len);
+	stringToUTF8(str, cstr, len);
+	return cstr;
+}
+
+function promptGet() { // caller must free
+	return toCString(document.getElementById('prompt-input').textContent);
 }
 
 function setPromptActive() {
@@ -47,16 +50,9 @@ function promptMsgR(p) {
 	document.getElementById('prompt-msg-r').textContent = UTF8ToString(p);
 }
 
-function stringToCString(str) { // caller must free
-	const len = lengthBytesUTF8(str) + 1;
-	const cstr = _malloc(len);
-	stringToUTF8(str, cstr, len);
-	return cstr;
-}
-
 function promptHandle(command, data) {
-	const str_c = stringToCString(command);
-	const str_d = data && stringToCString(data);
+	const str_c = toCString(command);
+	const str_d = data && toCString(data);
 	_prompt_handle(str_c, str_d);
 
 	_free(str_c);
-- 
cgit v1.2.3-70-g09d2