test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java

Print this page




 590 
 591         for (final String name : propNames) {
 592             checkProperty(e, name);
 593         }
 594     }
 595 
 596     // @bug 8046013: TypeError: Cannot apply "with" to non script object
 597     @Test
 598     public void withOnMirrorTest() throws ScriptException {
 599         final ScriptEngineManager m = new ScriptEngineManager();
 600         final ScriptEngine e = m.getEngineByName("nashorn");
 601 
 602         final Object obj = e.eval("({ foo: 'hello'})");
 603         final Object[] arr = new Object[1];
 604         arr[0] = obj;
 605         e.put("arr", arr);
 606         final Object res = e.eval("var res; with(arr[0]) { res = foo; }; res");
 607         assertEquals(res, "hello");
 608     }
 609 








 610     // @bug 8050432:javax.script.filename variable should not be enumerable
 611     // with nashorn engine's ENGINE_SCOPE bindings
 612     @Test
 613     public void enumerableGlobalsTest() throws ScriptException {
 614         final ScriptEngineManager m = new ScriptEngineManager();
 615         final ScriptEngine e = m.getEngineByName("nashorn");
 616 
 617         e.put(ScriptEngine.FILENAME, "test");
 618         Object enumerable = e.eval(
 619             "Object.getOwnPropertyDescriptor(this, " +
 620             " 'javax.script.filename').enumerable");
 621         assertEquals(enumerable, Boolean.FALSE);
 622     }
 623 
 624     private static void checkProperty(final ScriptEngine e, final String name)
 625         throws ScriptException {
 626         final String value = System.getProperty(name);
 627         e.put("name", name);
 628         assertEquals(value, e.eval("java.lang.System.getProperty(name)"));
 629     }


 590 
 591         for (final String name : propNames) {
 592             checkProperty(e, name);
 593         }
 594     }
 595 
 596     // @bug 8046013: TypeError: Cannot apply "with" to non script object
 597     @Test
 598     public void withOnMirrorTest() throws ScriptException {
 599         final ScriptEngineManager m = new ScriptEngineManager();
 600         final ScriptEngine e = m.getEngineByName("nashorn");
 601 
 602         final Object obj = e.eval("({ foo: 'hello'})");
 603         final Object[] arr = new Object[1];
 604         arr[0] = obj;
 605         e.put("arr", arr);
 606         final Object res = e.eval("var res; with(arr[0]) { res = foo; }; res");
 607         assertEquals(res, "hello");
 608     }
 609 
 610     // @bug 8054223: Nashorn: AssertionError when use __DIR__ and ScriptEngine.eval()
 611     @Test
 612     public void check__DIR__Test() throws ScriptException {
 613         final ScriptEngineManager m = new ScriptEngineManager();
 614         final ScriptEngine e = m.getEngineByName("nashorn");
 615         e.eval("__DIR__");
 616     }
 617 
 618     // @bug 8050432:javax.script.filename variable should not be enumerable
 619     // with nashorn engine's ENGINE_SCOPE bindings
 620     @Test
 621     public void enumerableGlobalsTest() throws ScriptException {
 622         final ScriptEngineManager m = new ScriptEngineManager();
 623         final ScriptEngine e = m.getEngineByName("nashorn");
 624 
 625         e.put(ScriptEngine.FILENAME, "test");
 626         Object enumerable = e.eval(
 627             "Object.getOwnPropertyDescriptor(this, " +
 628             " 'javax.script.filename').enumerable");
 629         assertEquals(enumerable, Boolean.FALSE);
 630     }
 631 
 632     private static void checkProperty(final ScriptEngine e, final String name)
 633         throws ScriptException {
 634         final String value = System.getProperty(name);
 635         e.put("name", name);
 636         assertEquals(value, e.eval("java.lang.System.getProperty(name)"));
 637     }