This commit is contained in:
minjaesong
2020-09-30 13:55:55 +09:00
parent dd3bb54e55
commit 516eced8e5
2 changed files with 5 additions and 4 deletions

View File

@@ -85,11 +85,11 @@ object VMRunnerFactory {
} }
override suspend fun executeCommand(command: String) { override suspend fun executeCommand(command: String) {
engine.eval("\"use strict\";" + sanitiseJS(toSingleLine(command)), context) engine.eval("\"use strict\";" + encapsulateJS(sanitiseJS(command)), context)
} }
override suspend fun evalGlobal(command: String) { override suspend fun evalGlobal(command: String) {
engine.eval("\"use strict\";" + toSingleLine(command), context) engine.eval("\"use strict\";" + sanitiseJS(command), context)
} }
} }
} }
@@ -99,6 +99,7 @@ object VMRunnerFactory {
private fun toSingleLine(code: String) = code.replace(Regex("//[^\\n]*"), "").replace('\n', ' ') private fun toSingleLine(code: String) = code.replace(Regex("//[^\\n]*"), "").replace('\n', ' ')
private fun sanitiseJS(code: String) = "eval('${toSingleLine(code).replace("\\", "\\\\")}')" private fun sanitiseJS(code: String) = toSingleLine(code).replace("\\", "\\\\")
private fun encapsulateJS(code: String) = "eval('$code')"
} }

View File

@@ -15,7 +15,7 @@ import net.torvald.tsvm.peripheral.GraphicsAdapter
class V2kRunTest(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter() { class V2kRunTest(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter() {
val vm = VM(64.kB()) val vm = VM(64.kB(), TheRealWorld())
lateinit var gpu: GraphicsAdapter lateinit var gpu: GraphicsAdapter
lateinit var batch: SpriteBatch lateinit var batch: SpriteBatch