title: Why does Rhino Javascript engine complain a function does not exist?
body: <p>Please forgive me, as I am a Java man dabbling in Javascript business :)</p>
  
  <p>I wanted to be able to define a set of integration test cases to be easy to script against a Java application. I thought Javascript would be a perfect language to script against. To that end, I am using the Rhino engine that comes with JDK 7, via Java's Scripting API. The scripts would have access to Java classes already defined in the application, and could be reused to define use case scenarios for integration testing.</p>
  
  <p>In the Java application, I have binded the javascript engine itself to the script as jsengine, so that I can load javascript files (<a href="https://stackoverflow.com/questions/12357334/including-a-javascript-file-during-rhino-eval">Including a JavaScript file during Rhino eval</a>).</p>
  
  <p>I have two Javascript files, as defined below:</p>
  
  <p>Function.js:</p>
  
  <pre><code>function send(msg) {
      send.sendMessage(msg);
  }
  </code></pre>
  
  <p>TestCase.js</p>
  
  <pre><code>jsengine.eval(new java.io.FileReader("Function.js");
  
  sendMsg("Test Message");
  </code></pre>
  
  <p>I also have the following object defined and binded to the script as "javaobj":</p>
  
  <pre><code>public class TestConnection {
  
      ...
  
      public void send(String message) {
          // Code to send the string message via JMS
      }
  
  }
  </code></pre>
  
  <p>However, the Rhino engine complains with the following Exception. It seems to not like calling the javaobj's send method, for some reason.</p>
  
  <pre><code>javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: TypeError: Cannot find function send in object 
  function sendMsg(msg) {...}. (TestCase.js#3) in TestCase.js at line number 3
      at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:224)
      at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:212)
      at com.foo.test.scenario.JavaScriptEngine.execute(JavaScriptEngine.java:56)
      at com.foo.test.TestSuite.start(TestSuite.java:88)
      at com.foo.test.TestSuite.main(TestSuite.java:41)
  Caused by: sun.org.mozilla.javascript.internal.EcmaError: TypeError: Cannot find function send in object 
  function sendMsg(msg) {...}. (TestCase.js#3) in TestCase.js at line number 3
      at sun.org.mozilla.javascript.internal.ScriptRuntime.constructError(ScriptRuntime.java:3773)
      at sun.org.mozilla.javascript.internal.ScriptRuntime.constructError(ScriptRuntime.java:3751)
      at sun.org.mozilla.javascript.internal.ScriptRuntime.typeError(ScriptRuntime.java:3779)
      at sun.org.mozilla.javascript.internal.ScriptRuntime.typeError2(ScriptRuntime.java:3798)
      at sun.org.mozilla.javascript.internal.ScriptRuntime.notFunctionError(ScriptRuntime.java:3869)
      at sun.org.mozilla.javascript.internal.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2345)
      at sun.org.mozilla.javascript.internal.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2312)
      at sun.org.mozilla.javascript.internal.Interpreter.interpretLoop(Interpreter.java:1524)
      at sun.org.mozilla.javascript.internal.Interpreter.interpret(Interpreter.java:854)
      at sun.org.mozilla.javascript.internal.InterpretedFunction.call(InterpretedFunction.java:164)
      at sun.org.mozilla.javascript.internal.ContextFactory.doTopCall(ContextFactory.java:429)
      at com.sun.script.javascript.RhinoScriptEngine$1.superDoTopCall(RhinoScriptEngine.java:116)
      at com.sun.script.javascript.RhinoScriptEngine$1.doTopCall(RhinoScriptEngine.java:109)
      at sun.org.mozilla.javascript.internal.ScriptRuntime.doTopCall(ScriptRuntime.java:3163)
      at sun.org.mozilla.javascript.internal.InterpretedFunction.exec(InterpretedFunction.java:175)
      at sun.org.mozilla.javascript.internal.Context.evaluateReader(Context.java:1159)
      at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:214)
      ... 4 more
  </code></pre>
  
  <p>Has anyone ever encountered this type of issue with Rhino? </p>
  
  <p>P.S. This question seems related, but no answer given as well (<a href="https://stackoverflow.com/questions/18634585/typeerror-in-rhino-migration-from-java-6-to-java-7">TypeError in Rhino: migration from Java 6 to Java 7</a>)</p>