use of net.sourceforge.htmlunit.corejs.javascript.Interpreter in project htmlunit by HtmlUnit.
the class Node method asJavaScriptException.
/**
* Encapsulates the given {@link DOMException} into a Rhino-compatible exception.
*
* @param exception the exception to encapsulate
* @return the created exception
*/
protected RhinoException asJavaScriptException(final DOMException exception) {
final Window w = getWindow();
exception.setPrototype(w.getPrototype(exception.getClass()));
exception.setParentScope(w);
// get current line and file name
// this method can only be used in interpreted mode. If one day we choose to use compiled mode,
// then we'll have to find an other way here.
final String fileName;
final int lineNumber;
if (Context.getCurrentContext().getOptimizationLevel() == -1) {
final int[] linep = new int[1];
final String sourceName = new Interpreter().getSourcePositionFromStack(Context.getCurrentContext(), linep);
fileName = sourceName.replaceFirst("script in (.*) from .*", "$1");
lineNumber = linep[0];
} else {
throw new Error("HtmlUnit not ready to run in compiled mode");
}
exception.setLocation(fileName, lineNumber);
return new JavaScriptException(exception, fileName, lineNumber);
}
Aggregations