title: Automatically prefix undefined methods by `Math.` when using the built-in JavaScript engine?
body: <p>To evaluate a mathematical expression given in a String, I'm using the built-in JavaScript engine as explained in <a href="https://stackoverflow.com/a/3423360/1225328">this answer</a>:</p>
  
  <pre class="lang-java prettyprint-override"><code>ScriptEngineManager manager = new ScriptEngineManager();
  ScriptEngine engine = manager.getEngineByName("JavaScript");
  double result = (Double) engine.eval("Math.min(2, 4)");
  // result: 2.0
  </code></pre>
  
  <p>It would be great if every function that belongs to <code>Math</code> (<code>min</code>, <code>max</code>, <code>pow</code>...) could be written without the <code>Math.</code> prefix, to lighten the expressions:</p>
  
  <pre class="lang-java prettyprint-override"><code>double result = (Double) engine.eval("min(2, 4)");
  </code></pre>
  
  <p>For now, I get the following exception:</p>
  
  <pre class="lang-none prettyprint-override"><code>sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "min" is not defined (&lt;Unknown source&gt;#1) in &lt;Unknown source&gt; at line number 1
  </code></pre>
  
  <p>Is there anyway to get this improvement done? For example, every time the exception gets catched, try to prefix the undefined reference by <code>Math.</code> and re-evaluate the expression? I've not been able to find how to proceed.</p>
  
  <p>I tried to used the <code>engine.put("min", ...)</code> method, in vain.</p>