diff --git a/console/src/main/kotlin/com/caoccao/javet/shell/BaseJavetShell.kt b/console/src/main/kotlin/com/caoccao/javet/shell/BaseJavetShell.kt index 4e233d9..8fc741c 100644 --- a/console/src/main/kotlin/com/caoccao/javet/shell/BaseJavetShell.kt +++ b/console/src/main/kotlin/com/caoccao/javet/shell/BaseJavetShell.kt @@ -34,13 +34,17 @@ import java.util.* abstract class BaseJavetShell( protected val options: Options, ) { + companion object { + const val PROMPT_STRING = "Please input the script or press Ctrl+C to exit." + } + protected abstract val prompt: String protected abstract fun createEventLoop(v8Runtime: V8Runtime, options: Options): BaseEventLoop fun execute(): ExitCode { println("${Constants.Application.NAME} v${Constants.Application.VERSION} (${options.jsRuntimeType.name} ${options.jsRuntimeType.version})") - println("Please input the script or press Ctrl+C to exit.") + println(PROMPT_STRING) println() V8Host.getInstance(options.jsRuntimeType).createV8Runtime().use { v8Runtime -> v8Runtime.logger = JavetShellLogger() diff --git a/console/src/main/kotlin/com/caoccao/javet/shell/JavetShellNode.kt b/console/src/main/kotlin/com/caoccao/javet/shell/JavetShellNode.kt index 8cc6f9b..6f915ba 100644 --- a/console/src/main/kotlin/com/caoccao/javet/shell/JavetShellNode.kt +++ b/console/src/main/kotlin/com/caoccao/javet/shell/JavetShellNode.kt @@ -23,6 +23,15 @@ import com.caoccao.javet.shell.entities.Options class JavetShellNode( options: Options, ) : BaseJavetShell(options) { + companion object { + const val PROMISE_REJECT_CALLBACK_CODE_STRING = """const process = require('process'); + process.on('unhandledRejection', (reason, promise) => { + console.error(); + console.error(reason.toString()); + console.error(); + });""" + } + init { assert(options.jsRuntimeType.isNode) { "JS runtime type must be Node." } } @@ -36,13 +45,6 @@ class JavetShellNode( override fun registerPromiseRejectCallback(v8Runtime: V8Runtime) { v8Runtime.v8ModuleResolver = JavetBuiltInModuleResolver() - v8Runtime.getExecutor( - """const process = require('process'); - process.on('unhandledRejection', (reason, promise) => { - console.error(); - console.error(reason.toString()); - console.error(); - });""" - )?.executeVoid() + v8Runtime.getExecutor(PROMISE_REJECT_CALLBACK_CODE_STRING).executeVoid() } } \ No newline at end of file