本文整理汇总了Java中org.mozilla.javascript.RhinoException.details方法的典型用法代码示例。如果您正苦于以下问题:Java RhinoException.details方法的具体用法?Java RhinoException.details怎么用?Java RhinoException.details使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mozilla.javascript.RhinoException
的用法示例。
在下文中一共展示了RhinoException.details方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertException
import org.mozilla.javascript.RhinoException; //导入方法依赖的package包/类
/**
* Converts general exception to more readable format.
*
* @param ex
* @return
*/
protected CrosstabException convertException( Exception ex )
{
if ( ex instanceof RhinoException )
{
RhinoException e = (RhinoException) ex;
String lineSource = e.lineSource( );
String details = e.details( );
String lineNumber = String.valueOf( e.lineNumber( ) );
if ( lineSource == null )
lineSource = "";//$NON-NLS-1$
return new CrosstabException( Messages.getString( "CrosstabScriptHandler.error.javascript", //$NON-NLS-1$
new Object[]{
details, lineNumber, lineSource
} ) );
}
else
{
return new CrosstabException( ex );
}
}
示例2: convertException
import org.mozilla.javascript.RhinoException; //导入方法依赖的package包/类
/**
* Converts general exception to more readable format.
*
* @param ex
* @return
*/
protected ChartException convertException( Exception ex )
{
if ( ex instanceof RhinoException )
{
RhinoException e = (RhinoException) ex;
String lineSource = e.lineSource( );
String details = e.details( );
String lineNumber = String.valueOf( e.lineNumber( ) );
if ( lineSource == null )
lineSource = "";//$NON-NLS-1$
return new ChartException( ChartEnginePlugin.ID,
ChartException.SCRIPT,
"exception.javascript.error", //$NON-NLS-1$
new Object[]{
details, lineNumber, lineSource
},
Messages.getResourceBundle( csc.getULocale( ) ),
e );
}
/*
* TODO convert those exceptions too else if ( ex instanceof
* IllegalAccessException ) {} else if ( ex instanceof
* InstantiationException ) {} else if ( ex instanceof
* InvocationTargetException ) { }
*/
else
return new ChartException( ChartEnginePlugin.ID,
ChartException.SCRIPT,
ex );
}
示例3: executeRhinoScript
import org.mozilla.javascript.RhinoException; //导入方法依赖的package包/类
private Object executeRhinoScript() {
Context cx = CTX_FACTORY.enterContext();
try {
cx.setOptimizationLevel(optLevel);
Scriptable scope = cx.initStandardObjects();
for (String harnessFile : harnessFiles) {
if (!HARNESS_SCRIPT_CACHE.get(optLevel).containsKey(harnessFile)) {
HARNESS_SCRIPT_CACHE.get(optLevel).put(
harnessFile,
cx.compileReader(new FileReader("test262/harness/" + harnessFile), "test262/harness/" + harnessFile, 1, null)
);
}
HARNESS_SCRIPT_CACHE.get(optLevel).get(harnessFile).exec(cx, scope);
}
String str = jsFileStr;
if (useStrict) { // taken from test262.py
str = "\"use strict\";\nvar strict_mode = true;\n" + jsFileStr;
}
Object result = cx.evaluateString(scope, str, jsFilePath.replaceAll("\\\\", "/"), 1, null);
if (errorType != EcmaErrorType.NONE) {
fail(String.format("failed negative test. expected error: %s", errorType));
return null;
}
return result;
} catch (RhinoException ex) {
if (errorType == EcmaErrorType.NONE) {
fail(String.format("%s%n%s", ex.getMessage(), ex.getScriptStackTrace()));
} else {
if (errorType == EcmaErrorType.ANY) {
// passed
} else {
String exceptionName;
if (ex instanceof EvaluatorException) {
exceptionName = "SyntaxError";
} else {
exceptionName = ex.details();
if (exceptionName.contains(":")) {
exceptionName = exceptionName.substring(0, exceptionName.indexOf(":"));
}
}
assertEquals(ex.details(), errorType.name(), exceptionName);
}
}
return null;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
Context.exit();
}
}
示例4: parse
import org.mozilla.javascript.RhinoException; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public ParseResult parse(RSyntaxDocument doc, String style) {
astRoot = null;
result.clearNotices();
// Always spell check all lines, for now.
Element root = doc.getDefaultRootElement();
int lineCount = root.getElementCount();
result.setParsedLines(0, lineCount - 1);
DocumentReader r = new DocumentReader(doc);
ErrorCollector errorHandler = new ErrorCollector();
CompilerEnvirons env = createCompilerEnvironment(errorHandler, langSupport);
long start = System.currentTimeMillis();
try {
Parser parser = new Parser(env);
astRoot = parser.parse(r, null, 0);
long time = System.currentTimeMillis() - start;
result.setParseTime(time);
} catch (IOException ioe) { // Never happens
result.setError(ioe);
ioe.printStackTrace();
} catch (RhinoException re) {
// Shouldn't happen since we're passing an ErrorCollector in
int line = re.lineNumber();
// if (line>0) {
Element elem = root.getElement(line);
int offs = elem.getStartOffset();
int len = elem.getEndOffset() - offs - 1;
String msg = re.details();
result.addNotice(new DefaultParserNotice(this, msg, line, offs, len));
// }
} catch (Exception e) {
result.setError(e); // catch all
}
r.close();
// Get any parser errors.
switch (langSupport.getErrorParser()) {
default:
case RHINO:
gatherParserErrorsRhino(errorHandler, root);
break;
case JSHINT:
gatherParserErrorsJsHint(doc);
break;
}
// addNotices(doc);
support.firePropertyChange(PROPERTY_AST, null, astRoot);
return result;
}
示例5: execute
import org.mozilla.javascript.RhinoException; //导入方法依赖的package包/类
public Object execute(Object[] args) {
Context cx = RhinoUtil.enter();
Object ret = null;
try {
Scriptable scope = RhinoUtil.getScope();
Object jsRet;
if (_elStyle && args != null) {
Object host = getELStyleHost(cx, scope);
jsRet = functionExecute(cx, scope, host, args);
} else {
jsRet = normalExecute(cx, scope);
}
ret = RhinoUtil.convertResult(cx, getExpectedClass(), jsRet);
} catch (RhinoException e) {
if (e instanceof WrappedException) {
WrappedException we = (WrappedException) e;
Throwable wrapped = we.getWrappedException();
if (wrapped instanceof RenderingBrake) {
RhinoUtil.removeWrappedException(we);
}
}
// エラーとなったソース情報が微妙なので微調整。
// 行番号はスクリプト次第でずれてしまう。
int offsetLine;
String message;
String sourceName;
if (e instanceof JavaScriptException
&& ((JavaScriptException)e).getValue() instanceof IdScriptableObject) {
offsetLine = -1;
IdScriptableObject scriptable =
(IdScriptableObject) ((JavaScriptException) e).getValue();
Object messageProperty = scriptable.get("message", scriptable);
if (messageProperty != Scriptable.NOT_FOUND) {
message = messageProperty.toString();
} else {
message = scriptable.toString();
}
} else {
offsetLine = e.lineNumber() - _lineNumber + 1; // one "\n" is added
message = e.details() + " in script=\n" + getText();
}
if (e.lineSource() == null && message != null) {
String[] lines = message.split("\n");
offsetLine = (lines.length > offsetLine) ? offsetLine : _offsetLine;
if (offsetLine >= 0 && lines.length > offsetLine) {
e.initLineSource(lines[offsetLine]);
sourceName = _sourceName;
} else {
sourceName = e.sourceName();
}
} else {
sourceName = e.sourceName();
}
throw new OffsetLineRhinoException(
message,
sourceName, e.lineNumber(), e.lineSource(),
e.columnNumber(), offsetLine, e.getCause());
} finally {
Context.exit();
}
return ret;
}