Refine search
@Override public Object eval(Reader reader, ScriptContext context) throws ScriptException { try { // Get engine bindings and send them to Clojure Bindings engineBindings = context.getBindings(ScriptContext.ENGINE_SCOPE); engineBindings.entrySet().forEach((entry) -> Var.intern(Namespace.findOrCreate(NAMESPACE_SYMBOL), Symbol.create(entry.getKey().intern()), entry.getValue(), true)); Var.pushThreadBindings( RT.map(RT.CURRENT_NS, RT.CURRENT_NS.deref(), RT.IN, new LineNumberingPushbackReader(context.getReader()), RT.OUT, context.getWriter(), RT.ERR, context.getErrorWriter())); Object result = Compiler.load(reader); return result; } catch (Exception e) { throw new ScriptException(e); } finally { Namespace.remove(NAMESPACE_SYMBOL); } }
@Override protected void innerProcess(CrawlURI curi) { // depending on previous configuration, engine may // be local to this thread or shared ScriptEngine engine = getEngine(); synchronized(engine) { // synchronization is harmless for local thread engine, // necessary for shared engine engine.put("curi",curi); engine.put("appCtx", appCtx); try { engine.eval("process(curi)"); } catch (ScriptException e) { logger.log(Level.WARNING,e.getMessage(),e); } finally { engine.put("curi", null); engine.put("appCtx", null); } } }
ScriptEngine engine = enginePool.getEngine(); try { ScriptContext context = engine.getContext(); context.setAttribute("page", page, ScriptContext.ENGINE_SCOPE); context.setAttribute("config", site, ScriptContext.ENGINE_SCOPE); try { switch (language) { case JavaScript: engine.eval(defines + "\n" + script, context); RubyHash oRuby = (RubyHash) engine.eval(defines + "\n" + script, context); Iterator itruby = oRuby.entrySet().iterator(); while (itruby.hasNext()) { e.printStackTrace();
public ScriptRuntimeException(ScriptException e) { super(e); this.fileName = e.getFileName(); this.lineNumber = e.getLineNumber(); this.columnNumber = e.getColumnNumber(); }
@Override public Object eval(Reader reader, ScriptContext context) throws ScriptException { Scriptable scope = setupScope(cx, context); String filename = (filename = (String) get(ScriptEngine.FILENAME)) == null ? "<unknown>" : filename; try { return cx.evaluateReader(scope, reader, filename, 1, null); } catch (RhinoException e) { String msg; int line = (line = e.lineNumber()) == 0 ? -1 : line; if (e instanceof JavaScriptException) { msg = String.valueOf(((JavaScriptException) e).getValue()); } else { msg = e.getMessage(); } ScriptException scriptException = new ScriptException(msg, e.sourceName(), line); scriptException.initCause(e); throw scriptException; } catch (IOException e) { throw new ScriptException(e); } finally { Context.exit(); } }
ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName("jav8"); try { engine.eval("print('Hello, world!')"); } catch (ScriptException ex) { ex.printStackTrace(); }
private boolean runJS() { ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn"); String scriptBefore = "var Do = Java.type('com.sikulix.api.Do');\n" + "var SX = Java.type('com.sikulix.core.SX');\n" + "log = SX.getSXLog(\"SX.JAVASCRIPTRUNNER\");\n"; if (withTrace) { scriptBefore += "log.on(SX.TRACE);\n"; } String scriptText = scriptBefore; scriptText += script; log.trace("%s: running script %s", ScriptType.JAVASCRIPT, scriptName); if (withTrace) { log.p(script); log.p("---------- end of script"); } Object returned = null; try { returned = engine.eval(scriptText); } catch (ScriptException e) { log.trace("%s: error: %s", ScriptType.JAVASCRIPT, e.getMessage()); returnObject = new ReturnObject(false); return false; } log.trace("%s: ending run", ScriptType.JAVASCRIPT); returnObject = new ReturnObject(ScriptType.JAVASCRIPT, returned); return true; }
public boolean test(final Object a) { try { final Bindings bindings = new SimpleBindings(); bindings.put(A, a); return (boolean) this.engine.eval(this.script, bindings); } catch (final ScriptException e) { throw new IllegalArgumentException(e.getMessage()); } }
public static void main(String[] args) { ScriptEngineManager sem = new ScriptEngineManager(); ScriptEngine ruby = sem.getEngineByExtension("rb"); try { ruby.eval("puts 'Hello World!'"); } catch (ScriptException ex) { ex.printStackTrace(); } } }
public Object eval( final String script, final String scriptLanguage ) throws ScriptException { final ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName( scriptLanguage ); if ( scriptEngine == null ) { throw new ScriptException( String.format( "DataFactoryScriptingSupport: Failed to locate scripting engine for language '%s'.", scriptLanguage ) ); } scriptEngine.setContext( context ); return scriptEngine.eval( script ); }
} else { scriptEngine.eval(scriptBody); final Object obj = scriptEngine.get("lookupService"); if (obj != null) { final ComponentLog logger = getLogger(); throw new ScriptException("No LookupService was defined by the script."); throw new ScriptException("Script engine is not Invocable, cannot be used for ScriptedLookupService");
protected void runTest(String script, String testName) { try { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("jruby"); engine.eval("require '" + script + "'"); engine.eval(testName + "()"); } catch (ScriptException e) { throw new AssertionError(e.getCause()); } } }
@Override public void write(final NullWritable key, final VertexWritable vertex) throws IOException { if (null != vertex) { try { final Bindings bindings = this.engine.createBindings(); bindings.put(VERTEX, vertex.get()); final String line = (String) engine.eval(WRITE_CALL, bindings); if (line != null) { this.out.write(line.getBytes(UTF8)); this.out.write(NEWLINE); } } catch (final ScriptException e) { throw new IOException(e.getMessage(), e); } } }
engine = new ScriptEngineManager(). getEngineByExtension("js"); Object result = engine.eval(io.getText()); if (result == null) { io.setText("Output was 'null'"); io.setText(se.getMessage());
@Override public final void run() { Loggers.SCENARIO.log(Level.INFO, scenario); try { scriptEngine.eval(scenario); } catch (final ScriptException e) { LogUtil.trace( Loggers.ERR, Level.ERROR, e, "\nScenario failed, line #{}, column #{}:\n{}", e.getLineNumber(), e.getColumnNumber(), e.getMessage()); } } }
SingleGremlinScriptEngineManager.get(this.language); Bindings bindings = engine.createBindings(); bindings.putAll(this.bindings); bindings.put("g", this.factory.createTraversalSource(this.graph) .withStrategies(strategies)); bindings.put("graph", this.graph); Object result = engine.eval(this.script, bindings); throw new IllegalStateException(e.getMessage(), e);
try { engine = jsCodeCompiler.createEngine(script, testLogger, null, configManager, (e, bindings) -> { bindings.put("$$params", params); try { e.eval("var $$module = function(queryParams, body, headers) " + "{ return module(queryParams, body, $$params, headers)}"); } catch (ScriptException ex) { LOGGER.warn("Error while processing webhook script: " + e.getMessage()); String message = e.getCause() != null ? e.getCause().getMessage() : e.getMessage(); returnError(request, "Error while executing webhook script: " + message, BAD_REQUEST); } catch (Exception e) {
protected Object evaluate(String script, String language, Bindings bindings) { ScriptEngine scriptEngine = getEngineByName(language); try { return scriptEngine.eval(script, bindings); } catch (ScriptException e) { throw new ActivitiException("problem evaluating script: " + e.getMessage(), e); } }
data.cx.eval( strEndScript, data.scope ); if ( log.isDetailed() ) { logDetailed( ( "End Script found!" ) ); if ( e.getCause() instanceof ScriptException ) { ScriptException ee = (ScriptException) e.getCause(); location = "--> " + ee.getLineNumber() + ":" + ee.getColumnNumber();