jdk.nashorn.internal.codegen.CompilerConstants Java Examples

The following examples show how to use jdk.nashorn.internal.codegen.CompilerConstants. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NashornException.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.PROGRAM.symbolName())) {
                methodName = "<program>";
            } else {
                methodName = stripMethodName(methodName);
            }

            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
Example #2
Source File: NashornException.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.PROGRAM.symbolName())) {
                methodName = "<program>";
            } else {
                methodName = stripMethodName(methodName);
            }

            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
Example #3
Source File: NashornException.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.PROGRAM.symbolName())) {
                methodName = "<program>";
            }

            if (methodName.contains(CompilerConstants.ANON_FUNCTION_PREFIX.symbolName())) {
                methodName = "<anonymous>";
            }

            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
Example #4
Source File: NashornException.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.RUN_SCRIPT.symbolName())) {
                methodName = "<program>";
            }
            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
Example #5
Source File: NashornException.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.RUN_SCRIPT.symbolName())) {
                methodName = "<program>";
            }
            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
Example #6
Source File: NashornException.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.PROGRAM.symbolName())) {
                methodName = "<program>";
            } else {
                methodName = stripMethodName(methodName);
            }

            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
Example #7
Source File: NashornException.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.PROGRAM.symbolName())) {
                methodName = "<program>";
            }

            if (methodName.contains(CompilerConstants.ANON_FUNCTION_PREFIX.symbolName())) {
                methodName = "<anonymous>";
            }

            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
Example #8
Source File: NashornException.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.PROGRAM.symbolName())) {
                methodName = "<program>";
            } else {
                methodName = stripMethodName(methodName);
            }

            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[0]);
}
 
Example #9
Source File: NashornException.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.PROGRAM.symbolName())) {
                methodName = "<program>";
            } else {
                methodName = stripMethodName(methodName);
            }

            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
Example #10
Source File: NashornException.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.RUN_SCRIPT.symbolName())) {
                methodName = "<program>";
            }
            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
Example #11
Source File: ECMAErrors.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check if a stack trace element is in JavaScript
 *
 * @param frame frame
 *
 * @return true if frame is in the script
 */
public static boolean isScriptFrame(final StackTraceElement frame) {
    final String className = frame.getClassName();

    // Look for script package in class name (into which compiler puts generated code)
    if (className.startsWith(scriptPackage) && !CompilerConstants.isInternalMethodName(frame.getMethodName())) {
        final String source = frame.getFileName();
        // Make sure that it is not some Java code that Nashorn has in that package!
        return source != null && !source.endsWith(".java");
    }
    return false;
}
 
Example #12
Source File: GetSplitState.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void toString(final StringBuilder sb, final boolean printType) {
    if (printType) {
        sb.append("{I}");
    }
    sb.append(CompilerConstants.SCOPE.symbolName()).append('.').append(Scope.GET_SPLIT_STATE.name()).append("()");
}
 
Example #13
Source File: JSONWriter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns AST as JSON compatible string.
 *
 * @param env  script environment to use
 * @param code code to be parsed
 * @param name name of the code source (used for location)
 * @param includeLoc tells whether to include location information for nodes or not
 * @return JSON string representation of AST of the supplied code
 */
public static String parse(final ScriptEnvironment env, final String code, final String name, final boolean includeLoc) {
    final Parser       parser     = new Parser(env, new Source(name, code), new Context.ThrowErrorManager(), env._strict);
    final JSONWriter   jsonWriter = new JSONWriter(includeLoc);
    try {
        final FunctionNode functionNode = parser.parse(CompilerConstants.RUN_SCRIPT.symbolName());
        functionNode.accept(jsonWriter);
        return jsonWriter.getString();
    } catch (final ParserException e) {
        e.throwAsEcmaException();
        return null;
    }
}
 
Example #14
Source File: AllocationStrategy.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Allocate an object with the given property map
 * @param map the property map
 * @return the allocated object
 */
ScriptObject allocate(final PropertyMap map) {
    try {
        if (allocator == null) {
            allocator = MH.findStatic(LOOKUP, Context.forStructureClass(getAllocatorClassName()),
                    CompilerConstants.ALLOCATE.symbolName(), MH.type(ScriptObject.class, PropertyMap.class));
        }
        return (ScriptObject)allocator.invokeExact(map);
    } catch (final RuntimeException | Error e) {
        throw e;
    } catch (final Throwable t) {
        throw new RuntimeException(t);
    }
}
 
Example #15
Source File: ScriptRuntime.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 11.4.3 The typeof Operator - generic implementation
 *
 * @param object   the object from which to retrieve property to type check
 * @param property property in object to check
 *
 * @return type name
 */
public static Object TYPEOF(final Object object, final Object property) {
    Object obj = object;

    if (property != null) {
        if (obj instanceof ScriptObject) {
            obj = ((ScriptObject)obj).get(property);
            if(Global.isLocationPropertyPlaceholder(obj)) {
                if(CompilerConstants.__LINE__.name().equals(property)) {
                    obj = Integer.valueOf(0);
                } else {
                    obj = "";
                }
            }
        } else if (object instanceof Undefined) {
            obj = ((Undefined)obj).get(property);
        } else if (object == null) {
            throw typeError("cant.get.property", safeToString(property), "null");
        } else if (JSType.isPrimitive(obj)) {
            obj = ((ScriptObject)JSType.toScriptObject(obj)).get(property);
        } else if (obj instanceof JSObject) {
            obj = ((JSObject)obj).getMember(property.toString());
        } else {
            obj = UNDEFINED;
        }
    }

    return JSType.of(obj).typeName();
}
 
Example #16
Source File: AllocationStrategy.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Allocate an object with the given property map
 * @param map the property map
 * @return the allocated object
 */
ScriptObject allocate(final PropertyMap map) {
    try {
        if (allocator == null) {
            allocator = MH.findStatic(LOOKUP, Context.forStructureClass(getAllocatorClassName()),
                    CompilerConstants.ALLOCATE.symbolName(), MH.type(ScriptObject.class, PropertyMap.class));
        }
        return (ScriptObject)allocator.invokeExact(map);
    } catch (final RuntimeException | Error e) {
        throw e;
    } catch (final Throwable t) {
        throw new RuntimeException(t);
    }
}
 
Example #17
Source File: AllocationStrategy.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Allocate an object with the given property map
 * @param map the property map
 * @return the allocated object
 */
ScriptObject allocate(final PropertyMap map) {
    try {
        if (allocator == null) {
            allocator = MH.findStatic(LOOKUP, Context.forStructureClass(getAllocatorClassName()),
                    CompilerConstants.ALLOCATE.symbolName(), MH.type(ScriptObject.class, PropertyMap.class));
        }
        return (ScriptObject)allocator.invokeExact(map);
    } catch (final RuntimeException | Error e) {
        throw e;
    } catch (final Throwable t) {
        throw new RuntimeException(t);
    }
}
 
Example #18
Source File: ECMAErrors.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check if a stack trace element is in JavaScript
 *
 * @param frame frame
 *
 * @return true if frame is in the script
 */
public static boolean isScriptFrame(final StackTraceElement frame) {
    final String className = frame.getClassName();

    // Look for script package in class name (into which compiler puts generated code)
    if (className.startsWith(scriptPackage) && !CompilerConstants.isInternalMethodName(frame.getMethodName())) {
        final String source = frame.getFileName();
        // Make sure that it is not some Java code that Nashorn has in that package!
        return source != null && !source.endsWith(".java");
    }
    return false;
}
 
Example #19
Source File: JSONWriter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns AST as JSON compatible string.
 *
 * @param env  script environment to use
 * @param code code to be parsed
 * @param name name of the code source (used for location)
 * @param includeLoc tells whether to include location information for nodes or not
 * @return JSON string representation of AST of the supplied code
 */
public static String parse(final ScriptEnvironment env, final String code, final String name, final boolean includeLoc) {
    final Parser       parser     = new Parser(env, new Source(name, code), new Context.ThrowErrorManager(), env._strict);
    final JSONWriter   jsonWriter = new JSONWriter(includeLoc);
    try {
        final FunctionNode functionNode = parser.parse(CompilerConstants.RUN_SCRIPT.symbolName());
        functionNode.accept(jsonWriter);
        return jsonWriter.getString();
    } catch (final ParserException e) {
        e.throwAsEcmaException();
        return null;
    }
}
 
Example #20
Source File: GetSplitState.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void toString(final StringBuilder sb, final boolean printType) {
    if (printType) {
        sb.append("{I}");
    }
    sb.append(CompilerConstants.SCOPE.symbolName()).append('.').append(Scope.GET_SPLIT_STATE.name()).append("()");
}
 
Example #21
Source File: JSONWriter.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns AST as JSON compatible string.
 *
 * @param env  script environment to use
 * @param code code to be parsed
 * @param name name of the code source (used for location)
 * @param includeLoc tells whether to include location information for nodes or not
 * @return JSON string representation of AST of the supplied code
 */
public static String parse(final ScriptEnvironment env, final String code, final String name, final boolean includeLoc) {
    final Parser       parser     = new Parser(env, new Source(name, code), new Context.ThrowErrorManager(), env._strict);
    final JSONWriter   jsonWriter = new JSONWriter(includeLoc);
    try {
        final FunctionNode functionNode = parser.parse(CompilerConstants.RUN_SCRIPT.symbolName());
        functionNode.accept(jsonWriter);
        return jsonWriter.getString();
    } catch (final ParserException e) {
        e.throwAsEcmaException();
        return null;
    }
}
 
Example #22
Source File: NashornException.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static String stripMethodName(final String methodName) {
    String name = methodName;

    final int nestedSeparator = name.lastIndexOf(CompilerConstants.NESTED_FUNCTION_SEPARATOR.symbolName());
    if (nestedSeparator >= 0) {
        name = name.substring(nestedSeparator + 1);
    }

    final int idSeparator = name.indexOf(CompilerConstants.ID_FUNCTION_SEPARATOR.symbolName());
    if (idSeparator >= 0) {
        name = name.substring(0, idSeparator);
    }

    return name.contains(CompilerConstants.ANON_FUNCTION_PREFIX.symbolName()) ? "<anonymous>" : name;
}
 
Example #23
Source File: ScriptRuntime.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 11.4.3 The typeof Operator - generic implementation
 *
 * @param object   the object from which to retrieve property to type check
 * @param property property in object to check
 *
 * @return type name
 */
public static Object TYPEOF(final Object object, final Object property) {
    Object obj = object;

    if (property != null) {
        if (obj instanceof ScriptObject) {
            obj = ((ScriptObject)obj).get(property);
            if(Global.isLocationPropertyPlaceholder(obj)) {
                if(CompilerConstants.__LINE__.name().equals(property)) {
                    obj = Integer.valueOf(0);
                } else {
                    obj = "";
                }
            }
        } else if (object instanceof Undefined) {
            obj = ((Undefined)obj).get(property);
        } else if (object == null) {
            throw typeError("cant.get.property", safeToString(property), "null");
        } else if (JSType.isPrimitive(obj)) {
            obj = ((ScriptObject)JSType.toScriptObject(obj)).get(property);
        } else if (obj instanceof JSObject) {
            obj = ((JSObject)obj).getMember(property.toString());
        } else {
            obj = UNDEFINED;
        }
    }

    return JSType.of(obj).typeName();
}
 
Example #24
Source File: GetSplitState.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void toString(final StringBuilder sb, final boolean printType) {
    if (printType) {
        sb.append("{I}");
    }
    sb.append(CompilerConstants.SCOPE.symbolName()).append('.').append(Scope.GET_SPLIT_STATE.name()).append("()");
}
 
Example #25
Source File: ECMAErrors.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check if a stack trace element is in JavaScript
 *
 * @param frame frame
 *
 * @return true if frame is in the script
 */
public static boolean isScriptFrame(final StackTraceElement frame) {
    final String className = frame.getClassName();

    // Look for script package in class name (into which compiler puts generated code)
    if (className.startsWith(scriptPackage) && !CompilerConstants.isInternalMethodName(frame.getMethodName())) {
        final String source = frame.getFileName();
        // Make sure that it is not some Java code that Nashorn has in that package!
        return source != null && !source.endsWith(".java");
    }
    return false;
}
 
Example #26
Source File: AllocationStrategy.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Allocate an object with the given property map
 * @param map the property map
 * @return the allocated object
 */
ScriptObject allocate(final PropertyMap map) {
    try {
        if (allocator == null) {
            allocator = MH.findStatic(LOOKUP, Context.forStructureClass(getAllocatorClassName()),
                    CompilerConstants.ALLOCATE.symbolName(), MH.type(ScriptObject.class, PropertyMap.class));
        }
        return (ScriptObject)allocator.invokeExact(map);
    } catch (final RuntimeException | Error e) {
        throw e;
    } catch (final Throwable t) {
        throw new RuntimeException(t);
    }
}
 
Example #27
Source File: NashornException.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static String stripMethodName(final String methodName) {
    String name = methodName;

    final int nestedSeparator = name.lastIndexOf(CompilerConstants.NESTED_FUNCTION_SEPARATOR.symbolName());
    if (nestedSeparator >= 0) {
        name = name.substring(nestedSeparator + 1);
    }

    final int idSeparator = name.indexOf(CompilerConstants.ID_FUNCTION_SEPARATOR.symbolName());
    if (idSeparator >= 0) {
        name = name.substring(0, idSeparator);
    }

    return name.contains(CompilerConstants.ANON_FUNCTION_PREFIX.symbolName()) ? "<anonymous>" : name;
}
 
Example #28
Source File: GetSplitState.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void toString(final StringBuilder sb, final boolean printType) {
    if (printType) {
        sb.append("{I}");
    }
    sb.append(CompilerConstants.SCOPE.symbolName()).append('.').append(Scope.GET_SPLIT_STATE.name()).append("()");
}
 
Example #29
Source File: ECMAErrors.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check if a stack trace element is in JavaScript
 *
 * @param frame frame
 *
 * @return true if frame is in the script
 */
public static boolean isScriptFrame(final StackTraceElement frame) {
    final String className = frame.getClassName();

    // Look for script package in class name (into which compiler puts generated code)
    if (className.startsWith(scriptPackage) && !CompilerConstants.isInternalMethodName(frame.getMethodName())) {
        final String source = frame.getFileName();
        // Make sure that it is not some Java code that Nashorn has in that package!
        return source != null && !source.endsWith(".java");
    }
    return false;
}
 
Example #30
Source File: NashornException.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static String stripMethodName(final String methodName) {
    String name = methodName;

    final int nestedSeparator = name.lastIndexOf(CompilerConstants.NESTED_FUNCTION_SEPARATOR.symbolName());
    if (nestedSeparator >= 0) {
        name = name.substring(nestedSeparator + 1);
    }

    final int idSeparator = name.indexOf(CompilerConstants.ID_FUNCTION_SEPARATOR.symbolName());
    if (idSeparator >= 0) {
        name = name.substring(0, idSeparator);
    }

    return name.contains(CompilerConstants.ANON_FUNCTION_PREFIX.symbolName()) ? "<anonymous>" : name;
}