()
| 33 | |
| 34 | private TernSupport ternSupport; |
| 35 | |
| 36 | NashornScriptEngineFactory factory = new NashornScriptEngineFactory(); |
| 37 | ScriptEngine engine; |
| 38 | private SimpleBindings global; |
| 39 | |
| 40 | public Nashorn() { |
| 41 | |
| 42 | _sstdlib = _stdlib; |
| 43 | |
| 44 | engine = factory.getScriptEngine("-scripting", "--global-per-engine", "--optimistic-types=true", "--language=es6"); |
| 45 | |
| 46 | global = new SimpleBindings(); |
| 47 | try { |
| 48 | global.put("__fieldglobal", engine.eval("({})")); |
| 49 | global.put("global", global); |
| 50 | Log.log("bindings", () -> "__fieldglobal set up to be :" + global.get("__fieldglobal")); |
| 51 | } catch (ScriptException e) { |
| 52 | e.printStackTrace(); |
| 53 | } |
| 54 | |
| 55 | engine.setBindings(global, ScriptContext.GLOBAL_SCOPE); |
| 56 | |
| 57 | try { |
| 58 | engine.eval("__fieldglobal.fielded = Packages.fielded"); |
| 59 | engine.eval("__fieldglobal.fieldbox = Packages.fieldbox"); |
| 60 | engine.eval("__fieldglobal.field = Packages.field"); |
| 61 | engine.eval("__fieldglobal.fieldnashorn = Packages.fieldnashorn"); |
| 62 | engine.eval("__fieldglobal.fieldcef = Packages.fieldcef"); |
| 63 | } catch (ScriptException e) { |
| 64 | e.printStackTrace(); |
| 65 | } |
| 66 | |
| 67 | ternSupport = new TernSupport(); |
| 68 | ternSupport.inject(engine); |
| 69 | |
| 70 | Animatable.registerHandler((was, o) -> { |
| 71 | |
| 72 | if (o instanceof ScriptObjectMirror) { |
| 73 | ScriptObjectMirror som = ((ScriptObjectMirror) o); |
| 74 | if (som.isFunction()) { |
| 75 | return Animatable.interpret((Supplier) () -> som.call(som), was); |
| 76 | } |
| 77 | |
| 78 | Animatable.AnimationElement start = null; |
| 79 | Animatable.AnimationElement middle = null; |
| 80 | Animatable.AnimationElement end = null; |
| 81 | |
| 82 | if (som.hasSlot(0)) start = Animatable.interpret(som.getSlot(0), was); |
| 83 | if (som.hasSlot(1)) middle = Animatable.interpret(som.getSlot(1), was); |
| 84 | if (som.hasSlot(2)) end = Animatable.interpret(som.getSlot(2), was); |
| 85 | |
| 86 | if (som.hasMember("start")) start = Animatable.interpret(som.getMember("start"), was); |
| 87 | if (som.hasMember("middle")) |
| 88 | middle = Animatable.interpret(som.getMember("middle"), was); |
| 89 | if (som.hasMember("end")) end = Animatable.interpret(som.getMember("end"), was); |
| 90 | |
| 91 | if (start == null) start = noop(); |
| 92 | if (middle == null) middle = noop(); |
nothing calls this directly
no test coverage detected