/** * Nashorn extension: Error.prototype.getStackTrace() "stack" property is an array typed value * containing {@link StackTraceElement} objects of JavaScript stack frames. * * @param self self reference * @return stack trace as a script array. */ @Function(attributes = Attribute.NOT_ENUMERABLE) public static Object getStackTrace(final Object self) { final ScriptObject sobj = Global.checkObject(self); final Object exception = ECMAException.getException(sobj); Object[] res; if (exception instanceof Throwable) { res = NashornException.getScriptFrames((Throwable) exception); } else { res = ScriptRuntime.EMPTY_ARRAY; } return new NativeArray(res); }
private static String getScriptStackString(final ScriptObject sobj, final Throwable exp) { return JSType.toString(sobj) + "\n" + NashornException.getScriptStackString(exp); }