Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()")

Expand Down
Loading