public static ScriptNode parseVariables( Context cx, Scriptable scope, String source, String sourceName, int lineno, Object securityDomain ) { // Interpreter compiler = new Interpreter(); CompilerEnvirons evn = new CompilerEnvirons(); // evn.setLanguageVersion(Context.VERSION_1_5); evn.setOptimizationLevel( -1 ); evn.setGeneratingSource( true ); evn.setGenerateDebugInfo( true ); ErrorReporter errorReporter = new ToolErrorReporter( false ); Parser p = new Parser( evn, errorReporter ); ScriptNode tree = p.parse( source, "", 0 ); // IOException new NodeTransformer().transform( tree ); // Script result = (Script)compiler.compile(scope, evn, tree, p.getEncodedSource(),false, null); return tree; } }
static RuntimeException reportRuntimeError(String msgId, String msgArg) { String message = ToolErrorReporter.getMessage(msgId, msgArg); return Context.reportRuntimeError(message); } }
public void error(String message, String sourceName, int line, String lineSource, int lineOffset) { hasReportedErrorFlag = true; reportErrorMessage(message, sourceName, line, lineSource, lineOffset, false); }
/** * Initialize the context. */ private ScriptableObject createContext(final ScriptableObject initialScope) { final Context context = getContext(); context.setOptimizationLevel(-1); // TODO redirect errors from System.err to LOG.error() context.setErrorReporter(new ToolErrorReporter(false)); context.setLanguageVersion(Context.VERSION_1_8); InputStream script = null; final ScriptableObject scriptCommon = (ScriptableObject) context.initStandardObjects(initialScope); try { script = getClass().getResourceAsStream("commons.js"); context.evaluateReader(scriptCommon, new InputStreamReader(script), "commons.js", 1, null); } catch (final IOException e) { throw new RuntimeException("Problem while evaluationg commons script.", e); } finally { IOUtils.closeQuietly(script); } return scriptCommon; }
i++; PrintStream savedOut = this.getOut(); PrintStream savedErr = this.getErr(); ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream(); this.setOut(new PrintStream(out)); this.setErr(new PrintStream(err)); String resultString = ""; ErrorReporter savedErrorReporter = cx.getErrorReporter(); cx.setErrorReporter(new ToolErrorReporter(false, this.getErr())); try { testCount++; Object result = cx.evaluateString(scope, inputString, "doctest input", 1, null); if (result != Context.getUndefinedValue() && ToolErrorReporter.reportException(cx.getErrorReporter(), e); } finally { this.setOut(savedOut);
protected Context enterContext() { Context context = Context.enter(); context.setOptimizationLevel(-1); // TODO redirect errors from System.err to LOG.error() context.setErrorReporter(new ToolErrorReporter(false)); context.setLanguageVersion(Context.VERSION_1_8); return context; }
cs = Charset.defaultCharset(); ShellConsole console = global.getConsole(cs); if (filename == null) { console.println(cx.getImplementationVersion()); if (cx.stringIsCompilableUnit(source)) break; prompt = prompts[1]; Script script = cx.compileString(source, "<stdin>", lineno, null); if (script != null) { Object result = script.exec(cx, scope); console.println(Context.toString(result)); } catch (RhinoException rex) { ToolErrorReporter.reportException( cx.getErrorReporter(), rex); ToolErrorReporter.reportException( cx.getErrorReporter(), rex); exitCode = EXITCODE_RUNTIME_ERROR; String msg = ToolErrorReporter.getMessage( "msg.uncaughtJSException", ex.toString()); Context.reportError(msg);
public static void processFileNoThrow(Context cx, Scriptable scope, String filename) { try { processFile(cx, scope, filename); } catch (IOException ioex) { Context.reportError(ToolErrorReporter.getMessage( "msg.couldnt.read.source", filename, ioex.getMessage())); exitCode = EXITCODE_FILE_NOT_FOUND; } catch (RhinoException rex) { ToolErrorReporter.reportException( cx.getErrorReporter(), rex); exitCode = EXITCODE_RUNTIME_ERROR; } catch (VirtualMachineError ex) { // Treat StackOverflow and OutOfMemory as runtime errors ex.printStackTrace(); String msg = ToolErrorReporter.getMessage( "msg.uncaughtJSException", ex.toString()); Context.reportError(msg); exitCode = EXITCODE_RUNTIME_ERROR; } }
/** * Load and execute a set of JavaScript source files. * * This method is defined as a JavaScript function. * */ public static void load(Context cx, Scriptable thisObj, Object[] args, Function funObj) { for (Object arg : args) { String file = Context.toString(arg); try { Main.processFile(cx, thisObj, file); } catch (IOException ioex) { String msg = ToolErrorReporter.getMessage( "msg.couldnt.read.source", file, ioex.getMessage()); throw Context.reportRuntimeError(msg); } catch (VirtualMachineError ex) { // Treat StackOverflow and OutOfMemory as runtime errors ex.printStackTrace(); String msg = ToolErrorReporter.getMessage( "msg.uncaughtJSException", ex.toString()); throw Context.reportRuntimeError(msg); } } }
Scriptable argsObj = cx.newArray(global, array); global.defineProperty("arguments", argsObj, ScriptableObject.DONTENUM); processSource(cx, file); } catch (IOException ioex) { Context.reportError(ToolErrorReporter.getMessage( "msg.couldnt.read.source", file, ioex.getMessage())); exitCode = EXITCODE_FILE_NOT_FOUND; } catch (RhinoException rex) { ToolErrorReporter.reportException( cx.getErrorReporter(), rex); exitCode = EXITCODE_RUNTIME_ERROR; } catch (VirtualMachineError ex) { String msg = ToolErrorReporter.getMessage( "msg.uncaughtJSException", ex.toString()); Context.reportError(msg);
break goodUsage; shellContextFactory.setStrictMode(true); shellContextFactory.setAllowReservedKeywords(false); errorReporter.setIsReportingWarnings(true); continue; global.init(shellContextFactory); errorReporter.setIsReportingWarnings(true); continue; global.setSealedStdLib(true); continue; arg.equals("-help")) { global.getOut().println( ToolErrorReporter.getMessage("msg.shell.usage", Main.class.getName())); System.exit(1); global.getOut().println( ToolErrorReporter.getMessage("msg.shell.invalid", usageError)); global.getOut().println( ToolErrorReporter.getMessage("msg.shell.usage", Main.class.getName())); System.exit(1); return null;
public static void main(String[] args) { errorReporter = new ToolErrorReporter(false, global.getErr()); shellContextFactory.setErrorReporter(errorReporter); IProxy iproxy = new IProxy(IProxy.PROCESS_FILES, processOptions(args)); global.init(shellContextFactory); shellContextFactory.call(iproxy); }
public Object execute(CompilableSource source) { try { logger.debug("Compiling source {}", source.getSource()); Script script = compile(source); if (script != null) { logger.debug("Executing compiled script"); Object result = script.exec(Context.getCurrentContext(), shellScope.get()); logger.debug("Returned object [{}]", result); if(result instanceof Undefined) { return null; } return result; } } catch(RhinoException rex) { logger.error(rex.getMessage(), rex); Context.reportError(rex.details(), null, rex.lineNumber(), rex.lineSource(), rex.columnNumber()); } catch(VirtualMachineError ex) { logger.error(ex.getMessage(), ex); String msg = ToolErrorReporter.getMessage("msg.uncaughtJSException", ex.toString()); Context.reportError(msg); } catch(Throwable t) { logger.error(t.getMessage(), t); String msg = ToolErrorReporter.getMessage("msg.uncaughtJSException", t.toString()); Context.reportError(msg); } return null; }
i++; PrintStream savedOut = this.getOut(); PrintStream savedErr = this.getErr(); ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream(); this.setOut(new PrintStream(out)); this.setErr(new PrintStream(err)); String resultString = ""; ErrorReporter savedErrorReporter = cx.getErrorReporter(); cx.setErrorReporter(new ToolErrorReporter(false, this.getErr())); try { testCount++; ToolErrorReporter.reportException(cx.getErrorReporter(), e); } finally { this.setOut(savedOut);
errorReporter.setIsReportingWarnings(true); continue; global.init(shellContextFactory); errorReporter.setIsReportingWarnings(true); continue; global.setSealedStdLib(true); continue; arg.equals("-help")) { global.getOut().println( ToolErrorReporter.getMessage("msg.shell.usage", Main.class.getName())); System.exit(1); global.getOut().println( ToolErrorReporter.getMessage("msg.shell.invalid", usageError)); global.getOut().println( ToolErrorReporter.getMessage("msg.shell.usage", Main.class.getName())); System.exit(1); return null;
public static String getMessage(String messageId, Object arg1, Object arg2) { Object[] args = { arg1, arg2 }; return getMessage(messageId, args); }
/** * Print a help message. * * This method is defined as a JavaScript function. */ public static void help(Context cx, Scriptable thisObj, Object[] args, Function funObj) { PrintStream out = getInstance(funObj).getOut(); out.println(ToolErrorReporter.getMessage("msg.help")); }
private int exec(String[] args) { R = new ToolErrorReporter(true, System.err); int arg_count = process_options(args); if (arg_count == 0) { option_error(ToolErrorReporter.getMessage( "msg.idswitch.no_file_argument")); return -1; } if (arg_count > 1) { option_error(ToolErrorReporter.getMessage( "msg.idswitch.too_many_arguments")); return -1; } P = new CodePrinter(); P.setIndentStep(4); P.setIndentTabSize(0); try { process_file(args[0]); } catch (IOException ex) { print_error(ToolErrorReporter.getMessage( "msg.idswitch.io_error", ex.toString())); return -1; } catch (EvaluatorException ex) { return -1; } return 0; }
private EvaluatorException on_same_pair_fail(IdValuePair a, IdValuePair b) { int line1 = a.getLineNumber(), line2 = b.getLineNumber(); if (line2 > line1) { int tmp = line1; line1 = line2; line2 = tmp; } String error_text = ToolErrorReporter.getMessage( "msg.idswitch.same_string", a.id, new Integer(line2)); return R.runtimeError(error_text, source_file, line1, null, 0); }
PrintStream ps = global.getErr(); if (filename == null) { try in = new BufferedReader(new InputStreamReader(global.getIn(), charEnc)); boolean hitEOF = false; while (!hitEOF) { String[] prompts = global.getPrompts(cx); if (filename == null) ps.print(prompts[0]); ps.println(Context.toString(result)); } catch (RhinoException rex) { ToolErrorReporter.reportException( cx.getErrorReporter(), rex);