[JS] Replace J2V8 based ScriptEngine with a process-based version
The main advantage of this is that we can use a newer and official build of V8. Also, with new infra, we can use other JS engines. Other changes: * ScriptEngine API is simplified and documented. * Introduce ScriptEngineWithTypedResult with typed `eval`, mostly for JsReplEvaluator and JsScriptEvaluator. * J2V8 version is completely removed. * Use new ScriptEngineV8 everywhere by default. * System property `kotlin.js.useNashorn` switches to Nashorn in all tests.
This commit is contained in:
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -21,7 +21,7 @@ class JsReplEvaluator : ReplEvaluator {
|
||||
): ReplEvalResult {
|
||||
return try {
|
||||
val evaluationState = state.asState(JsEvaluationState::class.java)
|
||||
val evalResult = evaluationState.engine.eval<Any?>(compileResult.data as String)
|
||||
val evalResult = evaluationState.engine.evalWithTypedResult<Any?>(compileResult.data as String)
|
||||
ReplEvalResult.ValueResult("result", evalResult, "Any?")
|
||||
} catch (e: Exception) {
|
||||
ReplEvalResult.Error.Runtime("Error while evaluating", e)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.cli.common.repl.*
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ScriptDescriptor
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.NameTables
|
||||
import org.jetbrains.kotlin.js.engine.ScriptEngine
|
||||
import org.jetbrains.kotlin.js.engine.ScriptEngineWithTypedResult
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.script.experimental.api.CompiledScript
|
||||
@@ -31,9 +31,9 @@ abstract class JsCompilationState(
|
||||
val nameTables: NameTables,
|
||||
val dependencies: List<ModuleDescriptor>) : JsState(lock)
|
||||
|
||||
class JsEvaluationState(lock: ReentrantReadWriteLock, val engine: ScriptEngine) : JsState(lock) {
|
||||
class JsEvaluationState(lock: ReentrantReadWriteLock, val engine: ScriptEngineWithTypedResult) : JsState(lock) {
|
||||
override fun dispose() {
|
||||
engine.release()
|
||||
engine.reset()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -17,7 +17,7 @@ class JsScriptEvaluator : ScriptEvaluator {
|
||||
scriptEvaluationConfiguration: ScriptEvaluationConfiguration
|
||||
): ResultWithDiagnostics<EvaluationResult> {
|
||||
return try {
|
||||
val evalResult = engine.eval<Any?>((compiledScript as JsCompiledScript).jsCode)
|
||||
val evalResult = engine.evalWithTypedResult<Any?>((compiledScript as JsCompiledScript).jsCode)
|
||||
ResultWithDiagnostics.Success(
|
||||
EvaluationResult(
|
||||
ResultValue.Value(
|
||||
|
||||
Reference in New Issue
Block a user