Java Code Examples for jdk.nashorn.api.scripting.ScriptObjectMirror#setSlot()
The following examples show how to use
jdk.nashorn.api.scripting.ScriptObjectMirror#setSlot() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScriptObjectMirrorTest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Test public void jsobjectTest() { final ScriptEngineManager m = new ScriptEngineManager(); final ScriptEngine e = m.getEngineByName("nashorn"); try { e.eval("var obj = { '1': 'world', func: function() { return this.bar; }, bar: 'hello' }"); final ScriptObjectMirror obj = (ScriptObjectMirror) e.get("obj"); // try basic get on existing properties if (!obj.getMember("bar").equals("hello")) { fail("obj.bar != 'hello'"); } if (!obj.getSlot(1).equals("world")) { fail("obj[1] != 'world'"); } if (!obj.callMember("func", new Object[0]).equals("hello")) { fail("obj.func() != 'hello'"); } // try setting properties obj.setMember("bar", "new-bar"); obj.setSlot(1, "new-element-1"); if (!obj.getMember("bar").equals("new-bar")) { fail("obj.bar != 'new-bar'"); } if (!obj.getSlot(1).equals("new-element-1")) { fail("obj[1] != 'new-element-1'"); } // try adding properties obj.setMember("prop", "prop-value"); obj.setSlot(12, "element-12"); if (!obj.getMember("prop").equals("prop-value")) { fail("obj.prop != 'prop-value'"); } if (!obj.getSlot(12).equals("element-12")) { fail("obj[12] != 'element-12'"); } // delete properties obj.removeMember("prop"); if ("prop-value".equals(obj.getMember("prop"))) { fail("obj.prop is not deleted!"); } // Simple eval tests assertEquals(obj.eval("typeof Object"), "function"); assertEquals(obj.eval("'nashorn'.substring(3)"), "horn"); } catch (final Exception exp) { exp.printStackTrace(); fail(exp.getMessage()); } }
Example 2
Source File: ScriptObjectMirrorTest.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Test public void jsobjectTest() { final ScriptEngineManager m = new ScriptEngineManager(); final ScriptEngine e = m.getEngineByName("nashorn"); try { e.eval("var obj = { '1': 'world', func: function() { return this.bar; }, bar: 'hello' }"); final ScriptObjectMirror obj = (ScriptObjectMirror) e.get("obj"); // try basic get on existing properties if (!obj.getMember("bar").equals("hello")) { fail("obj.bar != 'hello'"); } if (!obj.getSlot(1).equals("world")) { fail("obj[1] != 'world'"); } if (!obj.callMember("func", new Object[0]).equals("hello")) { fail("obj.func() != 'hello'"); } // try setting properties obj.setMember("bar", "new-bar"); obj.setSlot(1, "new-element-1"); if (!obj.getMember("bar").equals("new-bar")) { fail("obj.bar != 'new-bar'"); } if (!obj.getSlot(1).equals("new-element-1")) { fail("obj[1] != 'new-element-1'"); } // try adding properties obj.setMember("prop", "prop-value"); obj.setSlot(12, "element-12"); if (!obj.getMember("prop").equals("prop-value")) { fail("obj.prop != 'prop-value'"); } if (!obj.getSlot(12).equals("element-12")) { fail("obj[12] != 'element-12'"); } // delete properties obj.removeMember("prop"); if ("prop-value".equals(obj.getMember("prop"))) { fail("obj.prop is not deleted!"); } // Simple eval tests assertEquals(obj.eval("typeof Object"), "function"); assertEquals(obj.eval("'nashorn'.substring(3)"), "horn"); } catch (final Exception exp) { exp.printStackTrace(); fail(exp.getMessage()); } }
Example 3
Source File: ScriptObjectMirrorTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Test public void jsobjectTest() { final ScriptEngineManager m = new ScriptEngineManager(); final ScriptEngine e = m.getEngineByName("nashorn"); try { e.eval("var obj = { '1': 'world', func: function() { return this.bar; }, bar: 'hello' }"); final ScriptObjectMirror obj = (ScriptObjectMirror) e.get("obj"); // try basic get on existing properties if (!obj.getMember("bar").equals("hello")) { fail("obj.bar != 'hello'"); } if (!obj.getSlot(1).equals("world")) { fail("obj[1] != 'world'"); } if (!obj.callMember("func", new Object[0]).equals("hello")) { fail("obj.func() != 'hello'"); } // try setting properties obj.setMember("bar", "new-bar"); obj.setSlot(1, "new-element-1"); if (!obj.getMember("bar").equals("new-bar")) { fail("obj.bar != 'new-bar'"); } if (!obj.getSlot(1).equals("new-element-1")) { fail("obj[1] != 'new-element-1'"); } // try adding properties obj.setMember("prop", "prop-value"); obj.setSlot(12, "element-12"); if (!obj.getMember("prop").equals("prop-value")) { fail("obj.prop != 'prop-value'"); } if (!obj.getSlot(12).equals("element-12")) { fail("obj[12] != 'element-12'"); } // delete properties obj.removeMember("prop"); if ("prop-value".equals(obj.getMember("prop"))) { fail("obj.prop is not deleted!"); } // Simple eval tests assertEquals(obj.eval("typeof Object"), "function"); assertEquals(obj.eval("'nashorn'.substring(3)"), "horn"); } catch (final Exception exp) { exp.printStackTrace(); fail(exp.getMessage()); } }
Example 4
Source File: ScriptObjectMirrorTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Test public void jsobjectTest() { final ScriptEngineManager m = new ScriptEngineManager(); final ScriptEngine e = m.getEngineByName("nashorn"); try { e.eval("var obj = { '1': 'world', func: function() { return this.bar; }, bar: 'hello' }"); final ScriptObjectMirror obj = (ScriptObjectMirror) e.get("obj"); // try basic get on existing properties if (!obj.getMember("bar").equals("hello")) { fail("obj.bar != 'hello'"); } if (!obj.getSlot(1).equals("world")) { fail("obj[1] != 'world'"); } if (!obj.callMember("func", new Object[0]).equals("hello")) { fail("obj.func() != 'hello'"); } // try setting properties obj.setMember("bar", "new-bar"); obj.setSlot(1, "new-element-1"); if (!obj.getMember("bar").equals("new-bar")) { fail("obj.bar != 'new-bar'"); } if (!obj.getSlot(1).equals("new-element-1")) { fail("obj[1] != 'new-element-1'"); } // try adding properties obj.setMember("prop", "prop-value"); obj.setSlot(12, "element-12"); if (!obj.getMember("prop").equals("prop-value")) { fail("obj.prop != 'prop-value'"); } if (!obj.getSlot(12).equals("element-12")) { fail("obj[12] != 'element-12'"); } // delete properties obj.removeMember("prop"); if ("prop-value".equals(obj.getMember("prop"))) { fail("obj.prop is not deleted!"); } // Simple eval tests assertEquals(obj.eval("typeof Object"), "function"); assertEquals(obj.eval("'nashorn'.substring(3)"), "horn"); } catch (final Exception exp) { exp.printStackTrace(); fail(exp.getMessage()); } }
Example 5
Source File: ScriptObjectMirrorTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test public void jsobjectTest() { final ScriptEngineManager m = new ScriptEngineManager(); final ScriptEngine e = m.getEngineByName("nashorn"); try { e.eval("var obj = { '1': 'world', func: function() { return this.bar; }, bar: 'hello' }"); final ScriptObjectMirror obj = (ScriptObjectMirror) e.get("obj"); // try basic get on existing properties if (!obj.getMember("bar").equals("hello")) { fail("obj.bar != 'hello'"); } if (!obj.getSlot(1).equals("world")) { fail("obj[1] != 'world'"); } if (!obj.callMember("func", new Object[0]).equals("hello")) { fail("obj.func() != 'hello'"); } // try setting properties obj.setMember("bar", "new-bar"); obj.setSlot(1, "new-element-1"); if (!obj.getMember("bar").equals("new-bar")) { fail("obj.bar != 'new-bar'"); } if (!obj.getSlot(1).equals("new-element-1")) { fail("obj[1] != 'new-element-1'"); } // try adding properties obj.setMember("prop", "prop-value"); obj.setSlot(12, "element-12"); if (!obj.getMember("prop").equals("prop-value")) { fail("obj.prop != 'prop-value'"); } if (!obj.getSlot(12).equals("element-12")) { fail("obj[12] != 'element-12'"); } // delete properties obj.removeMember("prop"); if ("prop-value".equals(obj.getMember("prop"))) { fail("obj.prop is not deleted!"); } // Simple eval tests assertEquals(obj.eval("typeof Object"), "function"); assertEquals(obj.eval("'nashorn'.substring(3)"), "horn"); } catch (final Exception exp) { exp.printStackTrace(); fail(exp.getMessage()); } }
Example 6
Source File: ScriptObjectMirrorTest.java From hottub with GNU General Public License v2.0 | 4 votes |
@Test public void jsobjectTest() { final ScriptEngineManager m = new ScriptEngineManager(); final ScriptEngine e = m.getEngineByName("nashorn"); try { e.eval("var obj = { '1': 'world', func: function() { return this.bar; }, bar: 'hello' }"); final ScriptObjectMirror obj = (ScriptObjectMirror) e.get("obj"); // try basic get on existing properties if (!obj.getMember("bar").equals("hello")) { fail("obj.bar != 'hello'"); } if (!obj.getSlot(1).equals("world")) { fail("obj[1] != 'world'"); } if (!obj.callMember("func", new Object[0]).equals("hello")) { fail("obj.func() != 'hello'"); } // try setting properties obj.setMember("bar", "new-bar"); obj.setSlot(1, "new-element-1"); if (!obj.getMember("bar").equals("new-bar")) { fail("obj.bar != 'new-bar'"); } if (!obj.getSlot(1).equals("new-element-1")) { fail("obj[1] != 'new-element-1'"); } // try adding properties obj.setMember("prop", "prop-value"); obj.setSlot(12, "element-12"); if (!obj.getMember("prop").equals("prop-value")) { fail("obj.prop != 'prop-value'"); } if (!obj.getSlot(12).equals("element-12")) { fail("obj[12] != 'element-12'"); } // delete properties obj.removeMember("prop"); if ("prop-value".equals(obj.getMember("prop"))) { fail("obj.prop is not deleted!"); } // Simple eval tests assertEquals(obj.eval("typeof Object"), "function"); assertEquals(obj.eval("'nashorn'.substring(3)"), "horn"); } catch (final Exception exp) { exp.printStackTrace(); fail(exp.getMessage()); } }
Example 7
Source File: ScriptObjectMirrorTest.java From jdk8u_nashorn with GNU General Public License v2.0 | 4 votes |
@Test public void jsobjectTest() { final ScriptEngineManager m = new ScriptEngineManager(); final ScriptEngine e = m.getEngineByName("nashorn"); try { e.eval("var obj = { '1': 'world', func: function() { return this.bar; }, bar: 'hello' }"); final ScriptObjectMirror obj = (ScriptObjectMirror) e.get("obj"); // try basic get on existing properties if (!obj.getMember("bar").equals("hello")) { fail("obj.bar != 'hello'"); } if (!obj.getSlot(1).equals("world")) { fail("obj[1] != 'world'"); } if (!obj.callMember("func", new Object[0]).equals("hello")) { fail("obj.func() != 'hello'"); } // try setting properties obj.setMember("bar", "new-bar"); obj.setSlot(1, "new-element-1"); if (!obj.getMember("bar").equals("new-bar")) { fail("obj.bar != 'new-bar'"); } if (!obj.getSlot(1).equals("new-element-1")) { fail("obj[1] != 'new-element-1'"); } // try adding properties obj.setMember("prop", "prop-value"); obj.setSlot(12, "element-12"); if (!obj.getMember("prop").equals("prop-value")) { fail("obj.prop != 'prop-value'"); } if (!obj.getSlot(12).equals("element-12")) { fail("obj[12] != 'element-12'"); } // delete properties obj.removeMember("prop"); if ("prop-value".equals(obj.getMember("prop"))) { fail("obj.prop is not deleted!"); } // Simple eval tests assertEquals(obj.eval("typeof Object"), "function"); assertEquals(obj.eval("'nashorn'.substring(3)"), "horn"); } catch (final Exception exp) { exp.printStackTrace(); fail(exp.getMessage()); } }