title: How to pass Javascript native types to Nashorn objects from Java?
body: <p>For security reasons I'd like to pass to JS functions in Nashorn native Java types.</p>
  
  <p>If I create an engine and I run the following:</p>
  
  <pre><code>        NashornScriptEngineFactory nashornScriptEngineFactory = new      NashornScriptEngineFactory();
          ScriptEngine engine = nashornScriptEngineFactory.getScriptEngine();
          engine.eval(script);
          Invocable invocable = (Invocable) engine;
          JSObject objectWork = (JSObject) engine.get("objectWork");
          objectWork.call(null,"eee");
  </code></pre>
  
  <p>with script being</p>
  
  <pre><code>function objectWork(arg){
     print ("arg is "+ typeof arg);
     print ("arg.getClass()"+ arg.getClass());
  
     for (var k in arg){
          print(k);
     }
  }
  </code></pre>
  
  <p>The output is </p>
  
  <pre><code>arg is string
  arg.getClass()class java.lang.String
  </code></pre>
  
  <p>I'm not so happy about the 2nd and I don't know if getClass is exposing any method of the java.lang.Class object. Is there a way to pass something that wraps the Java String in a native one extending Nashorn own JSObject?</p>