diff --git a/contract/src/main/kotlin/com/xfl/msgbot/plugin/api/engine/ScriptEngine.kt b/contract/src/main/kotlin/com/xfl/msgbot/plugin/api/engine/ScriptEngine.kt index c659b19..5843e9e 100644 --- a/contract/src/main/kotlin/com/xfl/msgbot/plugin/api/engine/ScriptEngine.kt +++ b/contract/src/main/kotlin/com/xfl/msgbot/plugin/api/engine/ScriptEngine.kt @@ -23,7 +23,12 @@ interface ScriptEngine : AutoCloseable { /** Calls `__dispatch(name, payload)`. Returns after synchronous handlers finish; async work is not awaited. */ fun dispatch(event: ScriptEvent) - /** Evaluates [source] in the global scope. For tests and a REPL. */ + /** + * Evaluates [source] in the global scope. For tests and a REPL. + * + * A result that cannot cross as a [Value], such as a function or an object holding functions, is + * not an error: it comes back as a string that shows it, in the language's own notation. + */ fun eval(source: String): Value /** diff --git a/tck/src/main/kotlin/com/xfl/msgbot/plugin/tck/JavaScriptEngineConformance.kt b/tck/src/main/kotlin/com/xfl/msgbot/plugin/tck/JavaScriptEngineConformance.kt index 3bcfc61..78eb386 100644 --- a/tck/src/main/kotlin/com/xfl/msgbot/plugin/tck/JavaScriptEngineConformance.kt +++ b/tck/src/main/kotlin/com/xfl/msgbot/plugin/tck/JavaScriptEngineConformance.kt @@ -188,6 +188,15 @@ abstract class JavaScriptEngineConformance { assertTrue(harness.calls.isEmpty(), "the host never saw them: ${harness.calls}") } + @Test + fun anEvalResultThatIsNotPlainDataIsShownAsText() { + load("var holder = { get: function get() {}, n: 1 };") + val object_ = eval("holder") + assertTrue(object_ is Value.VString && "[Function: get]" in object_.value, "shown as text: $object_") + assertTrue(eval("(function get() {})") is Value.VString, "a function is shown as text too") + assertEquals(Value.VInt(42), eval("6 * 7")) + } + @Test fun classInstancesAreRefused() = assertRefused("function Point() { this.x = 1; }", "new Point()")