Search in sources :

Example 1 with Interpreter

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);
}
Also used : Window(com.gargoylesoftware.htmlunit.javascript.host.Window) Interpreter(net.sourceforge.htmlunit.corejs.javascript.Interpreter) JavaScriptException(net.sourceforge.htmlunit.corejs.javascript.JavaScriptException)

Aggregations

Window (com.gargoylesoftware.htmlunit.javascript.host.Window)1 Interpreter (net.sourceforge.htmlunit.corejs.javascript.Interpreter)1 JavaScriptException (net.sourceforge.htmlunit.corejs.javascript.JavaScriptException)1