Example usage for jdk.nashorn.internal.codegen CompilerConstants ANON_FUNCTION_PREFIX

List of usage examples for jdk.nashorn.internal.codegen CompilerConstants ANON_FUNCTION_PREFIX

Introduction

In this page you can find the example usage for jdk.nashorn.internal.codegen CompilerConstants ANON_FUNCTION_PREFIX.

Prototype

CompilerConstants ANON_FUNCTION_PREFIX

To view the source code for jdk.nashorn.internal.codegen CompilerConstants ANON_FUNCTION_PREFIX.

Click Source Link

Document

function prefix for anonymous functions

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");
                }//  w  w  w.  j  a  v  a 2  s  . 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;
}