msg = String.valueOf(((JavaScriptException) e).getValue()); } else { msg = e.getMessage();
@Override public Object eval(String script, ScriptContext context) throws ScriptException { Scriptable scope = setupScope(cx, context); String filename = (filename = (String) get(ScriptEngine.FILENAME)) == null ? "<unknown>" : filename; try { return cx.evaluateString(scope, script, 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; } finally { Context.exit(); } }
@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(); } }
JCoffeeScriptCompileException (JavaScriptException e) { super(e.getValue().toString(), e); }
CoffeeException(JavaScriptException e) { super(e.getValue().toString(), e); }
private LessCompilationException newLessException(JavaScriptException e) { if (e.getValue() instanceof Scriptable) { Scriptable value = (Scriptable) e.getValue(); String type = String.valueOf(ScriptableObject.getProperty(value, "type")); String message = String.valueOf(ScriptableObject.getProperty(value, "message")); if ("Syntax".equals(type)) { return new LessSyntaxException(message, e); } else if ("Unresolvable Import".equals(type)) { return new UnresolvableImportException(message, e); } } return new LessCompilationException(describeJsObject(e.getValue()), e); }
private static CompilerException parseException(final JavaScriptException exception) { final Scriptable value = (Scriptable) exception.getValue(); if (value != null && ScriptableObject.hasProperty(value, "message")) { final String message = ScriptableObject.getProperty(value, "message").toString(); final Matcher matcher = IMPORT_ERROR_PATTERN.matcher(message); if (matcher.find()) { return new ResolveImportException(message, matcher.group(IMPORT_ERROR_FILE_NAME_GROUP_INDEX), exception); } return new SyntaxException(message, exception); } return new SyntaxException(exception); } }
public Object wrap(Context cx, Scriptable scope, Object obj, Class staticType) { if (obj instanceof List) { return new MyScriptableList(scope, (List) obj); } else if (obj instanceof JavaScriptException) { JavaScriptException jse = (JavaScriptException) obj; Object nativeError = jse.getValue(); if (nativeError != null) { return nativeError; } } return super.wrap(cx, scope, obj, staticType); } }
/** * Creates a more detailed message based on {@link RhinoException} thrown by rhino execution. The message will contain * a detailed description of the problem by inspecting the JSON value provided by exception. * * @param e * {@link RhinoException} thrown by rhino execution. * @return detailed string message. */ public static String createExceptionMessage(final RhinoException e) { StringBuffer message = new StringBuffer("Could not execute the script because: \n"); if (e instanceof JavaScriptException) { message.append(toJson(((JavaScriptException) e).getValue())); } else if (e instanceof EcmaError) { final EcmaError ecmaError = (EcmaError) e; message.append(String.format("Error message: %s at line: %s. \nSource: %s", ecmaError.getErrorMessage(), ecmaError.lineNumber(), ecmaError.lineSource())); } else { message.append(e.getMessage()); } return message.toString(); }
/** * Creates a more detailed message based on {@link RhinoException} thrown by rhino execution. The message will contain * a detailed description of the problem by inspecting the JSON value provided by exception. * * @param e * {@link RhinoException} thrown by rhino execution. * @return detailed string message. */ public static String createExceptionMessage(final RhinoException e) { StringBuffer message = new StringBuffer("Could not execute the script because: \n"); if (e instanceof JavaScriptException) { message.append(toJson(((JavaScriptException) e).getValue())); } else if (e instanceof EcmaError) { final EcmaError ecmaError = (EcmaError) e; message.append(String.format("Error message: %s at line: %s. \nSource: %s", ecmaError.getErrorMessage(), ecmaError.lineNumber(), ecmaError.lineSource())); } else { message.append(e.getMessage()); } return message.toString(); }
public void execute(I18n i18n, Object[] args) throws Throwable { try { bodyFunc.call(cx, scope, scope, args); } catch (JavaScriptException e) { Object value = e.getValue(); if (value instanceof NativeJavaObject) { NativeJavaObject njo = (NativeJavaObject) value; Object unwrapped = njo.unwrap(); if (unwrapped instanceof Throwable) { throw (Throwable) unwrapped; } } throw e.getCause() == null ? e : e.getCause(); } }
} catch (final Exception e) { if (e instanceof JavaScriptException) { final Scriptable value = (Scriptable) ((JavaScriptException) e).getValue(); if (value != null && ScriptableObject.hasProperty(value, "message")) { final String message = ScriptableObject.getProperty(value, "message").toString();
public Object eval(ScriptContext context) throws ScriptException { Object result = null; Context cx = RhinoScriptEngine.enterContext(); try { Scriptable scope = engine.getRuntimeScope(context); Object ret = script.exec(cx, scope); result = engine.unwrapReturnValue(ret); } catch (JavaScriptException jse) { if (DEBUG) jse.printStackTrace(); int line = (line = jse.lineNumber()) == 0 ? -1 : line; Object value = jse.getValue(); String str = (value != null && value.getClass().getName().equals("org.mozilla.javascript.NativeError") ? value.toString() : jse.toString()); throw new ExtendedScriptException(jse, str, jse.sourceName(), line); } catch (RhinoException re) { if (DEBUG) re.printStackTrace(); int line = (line = re.lineNumber()) == 0 ? -1 : line; throw new ExtendedScriptException(re, re.toString(), re.sourceName(), line); } finally { Context.exit(); } return result; }
public Object eval(ScriptContext context) throws ScriptException { Object result = null; Context cx = RhinoScriptEngine.enterContext(); try { Scriptable scope = engine.getRuntimeScope(context); Object ret = script.exec(cx, scope); result = engine.unwrapReturnValue(ret); } catch (JavaScriptException jse) { if (DEBUG) jse.printStackTrace(); int line = (line = jse.lineNumber()) == 0 ? -1 : line; Object value = jse.getValue(); String str = (value != null && value.getClass().getName().equals("org.mozilla.javascript.NativeError") ? value.toString() : jse.toString()); throw new ExtendedScriptException(jse, str, jse.sourceName(), line); } catch (RhinoException re) { if (DEBUG) re.printStackTrace(); int line = (line = re.lineNumber()) == 0 ? -1 : line; throw new ExtendedScriptException(re, re.toString(), re.sourceName(), line); } finally { Context.exit(); } return result; }
@Override public Object eval(ScriptContext context) throws ScriptException { Object result = null; Context cx = RhinoScriptEngine.enterContext(); try { Scriptable scope = engine.getRuntimeScope(context); Object ret = script.exec(cx, scope); result = engine.unwrapReturnValue(ret); } catch (JavaScriptException jse) { if (DEBUG) jse.printStackTrace(); int line = (line = jse.lineNumber()) == 0 ? -1 : line; Object value = jse.getValue(); String str = (value != null && value.getClass().getName().equals("org.mozilla.javascript.NativeError") ? value.toString() : jse.toString()); throw new ExtendedScriptException(jse, str, jse.sourceName(), line); } catch (RhinoException re) { if (DEBUG) re.printStackTrace(); int line = (line = re.lineNumber()) == 0 ? -1 : line; throw new ExtendedScriptException(re, re.toString(), re.sourceName(), line); } finally { Context.exit(); } return result; }
private LessException parseLessException(Exception root) throws LessException { logger.debug("Parsing LESS Exception", root); if (root instanceof JavaScriptException) { Scriptable value = (Scriptable) ((JavaScriptException) root).getValue(); String type = (String) ScriptableObject.getProperty(value, "type") + " Error"; String message = (String) ScriptableObject.getProperty(value, "message");
public Object eval(ScriptContext context) throws ScriptException { Object result = null; Context cx = RhinoScriptEngine.enterContext(); try { Scriptable scope = engine.getRuntimeScope(context); Object ret = script.exec(cx, scope); result = engine.unwrapReturnValue(ret); } catch (RhinoException re) { int line = (line = re.lineNumber()) == 0 ? -1 : line; String msg; if (re instanceof JavaScriptException) { msg = String.valueOf(((JavaScriptException)re).getValue()); } else { msg = re.toString(); } ScriptException se = new ScriptException(msg, re.sourceName(), line); se.initCause(re); throw se; } finally { Context.exit(); } return result; }
public static String compile(String coffeeScript) throws ScriptException { Context ctx = Context.enter(); try { Scriptable scope = ctx.initStandardObjects(); Script script = (Script) new CoffeeScript(); script.exec(ctx, scope); NativeObject obj = (NativeObject) scope.get("CoffeeScript", scope); Function fun = (Function) obj.get("compile", scope); Object opts = ctx.evaluateString(scope, "({bare: true})", null, 1, null); String javaScript = (String) fun.call(ctx, scope, obj, new Object[] {coffeeScript, opts}); return javaScript; } catch (JavaScriptException e) { // Extract line and column of the error location in the CoffeeScript. // The below code is guessed from: // - Experimenting http://coffeescript.org/ with Chrome JavaScript Console // - https://code.google.com/p/wiquery/source/browse/trunk/src/main/java/org/mozilla/javascript/NativeError.java?spec=svn1010&r=1010 Scriptable syntaxError = (Scriptable) e.getValue(); Scriptable location = (Scriptable) ScriptableObject.getProperty(syntaxError, "location"); Double firstLine = (Double) ScriptableObject.getProperty(location, "first_line"); Double firstColumn = (Double) ScriptableObject.getProperty(location, "first_column"); throw new ScriptException("CoffeeScript syntax error", "", firstLine.intValue(), firstColumn.intValue()); } finally { Context.exit(); } } }
public Object eval(Reader reader, ScriptContext ctxt) throws ScriptException { Object ret; Context cx = enterContext(); try { Scriptable scope = getRuntimeScope(ctxt); String filename = (String) get(ScriptEngine.FILENAME); filename = filename == null ? "<Unknown source>" : filename; ret = cx.evaluateReader(scope, reader, filename , 1, null); } catch (RhinoException re) { if (DEBUG) re.printStackTrace(); int line = (line = re.lineNumber()) == 0 ? -1 : line; String msg; if (re instanceof JavaScriptException) { msg = String.valueOf(((JavaScriptException)re).getValue()); } else { msg = re.toString(); } ScriptException se = new ScriptException(msg, re.sourceName(), line); se.initCause(re); throw se; } catch (IOException ee) { throw new ScriptException(ee); } finally { cx.exit(); } return unwrapReturnValue(ret); }
obj = ((JavaScriptException)t).getValue(); } else { cacheObj = true;