How can I pass JavaScript Strings to a Nashorn engine instead of Java Strings?
<p>Using a ScriptEngine and Bindings, it seems that it treats the variables going in as Java Strings instead of JavaScript strings.  The languages have member functions with identical signatures but different behaviors, and this creates quite a bit of confusion when writing scriptlets.  I would like the Java functions to not be available, passing the bindings as if they were JavaScript string literals, forcing use of only JavaScript functions.</p>

<p>I have tried using the --no-java arg, which it is accepting, but doesn't seem to be doing what I thought it would.  I have also tried using a ClassFilter to accomplish the same thing, to no avail.</p>

<p>In the below example, I would like to get an exception for an undefined method (replaceAll is only in Java, not in JavaScript).  Instead it prints Qonald Quck.</p>

<pre><code>package test;

import javax.script.Bindings;
import javax.script.ScriptEngine;
import javax.script.ScriptException;

import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
import jdk.nashorn.api.scripting.ClassFilter;

public class TestScripting {

    public static void main(String[] args) throws ScriptException {

        System.getProperties().setProperty("nashorn.args", "--no-java");
        NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
        ScriptEngine jsEngine = factory.getScriptEngine(new ClassFilter() {

            @Override
            public boolean exposeToScripts(String arg0) {
                return false;
            }
        });

        Bindings bindings = jsEngine.createBindings();
        bindings.put("MyString", "Donald Duck");

        String res = (String) jsEngine.eval("MyString.replaceAll('D','Q')",
                bindings);
        System.out.println(res);
    }
}
</code></pre>