From 9502e8508946ca78d966addfc153cfb79ace688d Mon Sep 17 00:00:00 2001 From: Guy Zana <guy@cloudius-systems.com> Date: Wed, 14 Aug 2013 16:20:25 +0300 Subject: [PATCH] cli: fix broken 'test' command Broken by 92b6753b0aa9ed4063dedffbedfecdb3990f2b7d. The test command of the CLI didn't work because Javascript cannot work with a Java String[] array as if it is a JS array, I was surprised to see 92b6753b0aa9ed4063dedffbedfecdb3990f2b7d and I assumed it works but apparently the test command got broken. This patch properly returning a Scriptable object that Javascript code understands, it acquires a thread specific Rhino Context that is used to cast the test names to a JS array, and from there the JS code picks it up. --- java/cli/com/cloudius/cli/tests/TestRunner.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/java/cli/com/cloudius/cli/tests/TestRunner.java b/java/cli/com/cloudius/cli/tests/TestRunner.java index 68c680486..8ec0d4b49 100644 --- a/java/cli/com/cloudius/cli/tests/TestRunner.java +++ b/java/cli/com/cloudius/cli/tests/TestRunner.java @@ -3,6 +3,7 @@ package com.cloudius.cli.tests; import java.io.File; import java.util.HashMap; +import sun.org.mozilla.javascript.Context; import sun.org.mozilla.javascript.Scriptable; import com.cloudius.cli.main.RhinoCLI; @@ -58,7 +59,12 @@ public class TestRunner { this.registerELFTests(); } - public String[] getTestNames() { - return _tests.keySet().toArray(new String[_tests.size()]); + public Scriptable getTestNames() { + Context cx = Context.enter(); + Object[] names = _tests.keySet().toArray(); + Scriptable tests = cx.newArray(cx.initStandardObjects(), names); + Context.exit(); + + return (tests); } } -- GitLab