mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
re-impl of js eval function because wtf js
This commit is contained in:
@@ -268,10 +268,15 @@ if ('function' !== typeof Array.prototype.reduceRight) {
|
||||
};
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// NOTE TO PROGRAMMERS: this JS_INIT script does not, and must not be invoked with strict mode //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
load = undefined
|
||||
loadWithNewGlobal = undefined
|
||||
load = undefined;
|
||||
loadWithNewGlobal = undefined;
|
||||
var eval = function(s) { // installing new eval function
|
||||
return Function('"use strict";return(function(){'+s+'}())')();
|
||||
}
|
||||
//
|
||||
function javaArrayToJs(jarr) {
|
||||
if (!jarr.toString.startsWith("[")) return jarr;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package net.torvald.tsvm
|
||||
|
||||
import jdk.nashorn.api.scripting.NashornScriptEngineFactory
|
||||
import jdk.nashorn.api.scripting.ScriptUtils
|
||||
import jdk.nashorn.internal.runtime.regexp.joni.Syntax.Java
|
||||
import net.torvald.tsvm.peripheral.GraphicsAdapter
|
||||
import net.torvald.tsvm.vdc.Videotron2K
|
||||
import java.io.FileReader
|
||||
@@ -68,7 +66,7 @@ object VMRunnerFactory {
|
||||
|
||||
init {
|
||||
val engineFactory = NashornScriptEngineFactory()
|
||||
engine = engineFactory.getScriptEngine("-strict", "--no-java", "--no-syntax-extensions", "--language=es6")
|
||||
engine = engineFactory.getScriptEngine("--no-java", "--no-syntax-extensions", "--language=es6")
|
||||
assertNotNull(engine, "Script engine for extension $extension not found")
|
||||
}
|
||||
|
||||
@@ -83,17 +81,15 @@ object VMRunnerFactory {
|
||||
bind.put("base64", Base64Delegate())
|
||||
bind.put("com", SerialHelperDelegate(vm))
|
||||
|
||||
if (extension == "js") {
|
||||
val fr = FileReader("./assets/JS_INIT.js")
|
||||
val prg = fr.readText()
|
||||
fr.close()
|
||||
engine.eval(sanitiseJS(prg), context)
|
||||
}
|
||||
val fr = FileReader("./assets/JS_INIT.js")
|
||||
val prg = fr.readText()
|
||||
fr.close()
|
||||
engine.eval(sanitiseJS(prg), context)
|
||||
}
|
||||
|
||||
override suspend fun executeCommand(command: String) {
|
||||
try {
|
||||
engine.eval("\"use strict\";" + encapsulateJS(sanitiseJS(command)), context)
|
||||
engine.eval(encapsulateJS(sanitiseJS(command)), context)
|
||||
}
|
||||
catch (e: javax.script.ScriptException) {
|
||||
System.err.println("ScriptException from the script:")
|
||||
@@ -113,6 +109,6 @@ object VMRunnerFactory {
|
||||
|
||||
|
||||
private fun sanitiseJS(code: String) = code//.replace("\\", "\\\\")
|
||||
private fun encapsulateJS(code: String) = "(function(){$code})()"
|
||||
private fun encapsulateJS(code: String) = "\"use strict\";(function(){$code})()"
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user