Guest User

Untitled

a guest
Oct 22nd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. `// Where script returns a 'function () {}' object.
  2. final String script = someScript;
  3. // ScriptUtils comes from jdk.nashorn.api.scripting.ScriptUtils
  4. final ScriptObjectMirror som = ScriptUtils.unwrap(engine.eval(source ));
  5. /* This object will be created once and kept around to avoid re-creating
  6. it through ScriptObjectMirror#call varargs. */
  7. Object[] args = something;
  8. // Then calling the js function object with itself as 'this'.
  9. som.call( som, args );`
  10.  
  11. `// 'context' is a Java object.
  12. function (context) {
  13. let id = context.ownerId;
  14. let data = context.dataFor(id);
  15. // do things with data and context.
  16. }`
Add Comment
Please, Sign In to add comment