List of usage examples for java.lang VirtualMachineError toString
public String toString()
From source file:com.alvermont.javascript.tools.shell.ShellMain.java
public static Object evaluateScript(Script script, Context cx, Scriptable scope) { try {//w ww. j a va 2 s . co m return script.exec(cx, scope); } catch (RhinoException rex) { ToolErrorReporter.reportException(cx.getErrorReporter(), rex); exitCode = EXITCODE_RUNTIME_ERROR; } catch (VirtualMachineError ex) { // Treat StackOverflow and OutOfMemory as runtime errors ex.printStackTrace(); final String msg = ToolErrorReporter.getMessage("msg.uncaughtJSException", ex.toString()); exitCode = EXITCODE_RUNTIME_ERROR; Context.reportError(msg); } return Context.getUndefinedValue(); }
From source file:com.alvermont.javascript.tools.shell.ShellMain.java
public static Script loadScriptFromSource(Context cx, String scriptSource, String path, int lineno, Object securityDomain) {/* ww w .j a v a 2 s . co m*/ try { return cx.compileString(scriptSource, path, lineno, securityDomain); } catch (EvaluatorException ee) { // Already printed message. exitCode = EXITCODE_RUNTIME_ERROR; } catch (RhinoException rex) { ToolErrorReporter.reportException(cx.getErrorReporter(), rex); exitCode = EXITCODE_RUNTIME_ERROR; } catch (VirtualMachineError ex) { // Treat StackOverflow and OutOfMemory as runtime errors ex.printStackTrace(); final String msg = ToolErrorReporter.getMessage("msg.uncaughtJSException", ex.toString()); exitCode = EXITCODE_RUNTIME_ERROR; Context.reportError(msg); } return null; }
From source file:jetbrains.exodus.sshd.RhinoCommand.java
private void processInput(final Context cx) { while (true) { final API api = new API(); if (scope == null) { scope = createScope(cx, api); }/*from w ww. j a v a 2 s . c o m*/ out.flush(); int lineno = 0; final StringBuilder source = new StringBuilder(); // Collect lines of source to compile. while (true) { lineno++; api.printChar(lineno == 1 ? '>' : ' '); String newline = readLine(api); if (newline == null) return; source.append(newline).append("\n"); if (cx.stringIsCompilableUnit(source.toString())) break; } // execute script in transaction try { final Script script = cx.compileString(source.toString(), "<stdin>", lineno, null); if (script != null) { long start = System.currentTimeMillis(); PersistentEntityStore entityStore = getPersistentStore(scope); if (entityStore == null) { processScript(api, script, cx, scope); } else { entityStore.executeInTransaction(new StoreTransactionalExecutable() { @Override public void execute(@NotNull StoreTransaction txn) { ScriptableObject.putProperty(scope, "txn", Context.javaToJS(txn, scope)); processScript(api, script, cx, scope); } }); } api.println("Complete in " + ((System.currentTimeMillis() - start)) + " ms"); } } catch (RhinoException rex) { ToolErrorReporter.reportException(cx.getErrorReporter(), rex); } catch (VirtualMachineError ex) { // Treat StackOverflow and OutOfMemory as runtime errors ex.printStackTrace(); Context.reportError(ex.toString()); } if (api.reset) { synchronized (lock) { evalResourceScript(cx, scope, "destroy.js"); scope = null; } } } }
From source file:volumesculptor.shell.Main.java
static TriangleMesh processFile(Context cx, String[] args, Object[] scriptArgs, boolean show) { // define "arguments" array in the top-level object: // need to allocate new array since newArray requires instances // of exactly Object[], not ObjectSubclass[] Object[] array = new Object[args.length]; System.arraycopy(args, 0, array, 0, args.length); Scriptable argsObj = cx.newArray(global, array); global.defineProperty("arguments", argsObj, ScriptableObject.DONTENUM); for (String file : fileList) { try {/* w w w. j a v a 2s.c o m*/ return processSource(cx, file, scriptArgs, show); } catch (IOException ioex) { Context.reportError( ToolErrorReporter.getMessage("msg.couldnt.read.source", file, ioex.getMessage())); exitCode = EXITCODE_FILE_NOT_FOUND; } catch (RhinoException rex) { if (rex instanceof WrappedException) { System.out.println("Wrapped exception:"); int cnt = 0; int max = 5; Throwable we = ((WrappedException) rex).getWrappedException(); while (we instanceof WrappedException) { we = ((WrappedException) rex).getWrappedException(); cnt++; if (cnt > max) { System.out.println("Exceeded maximum wrappings, exiting."); break; } } if (we != null) we.printStackTrace(System.out); } 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; } } return null; }
From source file:volumesculptor.shell.Main.java
static TriangleMesh evalInlineScript(Context cx, String scriptText, Object[] args, boolean show) { try {/*from w ww . ja v a 2 s . co m*/ Script script = cx.compileString(scriptText, "<command>", 1, null); if (script != null) { script.exec(cx, getShellScope()); return executeMain(cx, getShellScope(), show, args); } } 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; } return null; }
From source file:volumesculptor.shell.Main.java
/** * Evaluate JavaScript source.//from w w w. j a v a 2s . com * * @param cx the current context * @param filename the name of the file to compile, or null * for interactive mode. * @throws IOException if the source could not be read * @throws RhinoException thrown during evaluation of source */ public static TriangleMesh processSource(Context cx, String filename, Object[] args, boolean show) throws IOException { if (filename == null || filename.equals("-")) { Scriptable scope = getShellScope(); PrintStream ps = global.getErr(); if (filename == null) { // print implementation version ps.println(cx.getImplementationVersion()); } String charEnc = shellContextFactory.getCharacterEncoding(); if (charEnc == null) { charEnc = System.getProperty("file.encoding"); } BufferedReader in; try { in = new BufferedReader(new InputStreamReader(global.getIn(), charEnc)); } catch (UnsupportedEncodingException e) { throw new UndeclaredThrowableException(e); } int lineno = 1; boolean hitEOF = false; while (!hitEOF) { String[] prompts = global.getPrompts(cx); if (filename == null) ps.print(prompts[0]); ps.flush(); String source = ""; // Collect lines of source to compile. while (true) { String newline; try { newline = in.readLine(); } catch (IOException ioe) { ps.println(ioe.toString()); break; } if (newline == null) { hitEOF = true; break; } source = source + newline + "\n"; lineno++; if (cx.stringIsCompilableUnit(source)) break; ps.print(prompts[1]); } try { Script script = cx.compileString(source, "<stdin>", lineno, null); if (script != null) { Object result = script.exec(cx, scope); // Avoid printing out undefined or function definitions. if (result != Context.getUndefinedValue() && !(result instanceof Function && source.trim().startsWith("function"))) { try { ps.println(Context.toString(result)); } catch (RhinoException rex) { ToolErrorReporter.reportException(cx.getErrorReporter(), rex); } } NativeArray h = global.history; h.put((int) h.getLength(), h, source); return executeMain(cx, scope, show, args); } } 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; } } ps.println(); } else if (useRequire && filename.equals(mainModule)) { require.requireMain(cx, filename); } else { return processFile(cx, getScope(filename), filename, args, show); } return null; }
From source file:volumesculptor.shell.Main.java
public static TriangleMesh processFileNoThrow(Context cx, Scriptable scope, String filename, String[] args, boolean show) { try {//from w w w. j a v a 2s . co m return processFile(cx, scope, filename, args, show); } 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; } return null; }