Example usage for jdk.nashorn.internal.runtime ECMAErrors isScriptFrame

List of usage examples for jdk.nashorn.internal.runtime ECMAErrors isScriptFrame

Introduction

In this page you can find the example usage for jdk.nashorn.internal.runtime ECMAErrors isScriptFrame.

Prototype

public static boolean isScriptFrame(final StackTraceElement frame) 

Source Link

Document

Check if a stack trace element is in JavaScript

Usage

From source file:com.mckoi.mwpui.nodejs.nashorn.NashornJSSystem.java

License:Open Source License

@Override
public String getAlternativeStackTraceOf(GJavaScriptException ex) {
    NashornException nex = (NashornException) ex.internalGetException();
    if (nex != null) {
        StringBuilder buf = new StringBuilder();
        StackTraceElement[] stack_trace = nex.getStackTrace();
        boolean first = true;
        for (StackTraceElement ste : stack_trace) {
            if (ECMAErrors.isScriptFrame(ste)) {
                if (!first) {
                    buf.append("\n");
                }/*from   www .  ja  v  a  2s .c om*/

                // Extract the method name,
                // NOTE: This could change and will need updating if it does,

                String ANON_PREFIX = CompilerConstants.ANON_FUNCTION_PREFIX.symbolName();
                String encoded_method_name = ste.getMethodName();
                String js_name_to_report = "";
                int delim = encoded_method_name.lastIndexOf("$");
                if (delim >= 0) {
                    String js_method = encoded_method_name.substring(delim + 1);
                    if (!js_method.startsWith(ANON_PREFIX) && js_method.length() > 0) {
                        js_name_to_report = js_method + " ";
                    }
                }

                buf.append("\tat ");
                buf.append(js_name_to_report);
                buf.append("(");
                buf.append(ste.getFileName());
                buf.append(':');
                buf.append(ste.getLineNumber());
                buf.append(")");
                first = false;
            }
        }

        return buf.toString();
    }
    return null;
}