/** * 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); }
/** * Nashorn extension: Error.prototype.stack "stack" property is a string typed value containing * JavaScript stack frames. Each frame information is separated bv "\n" character. * * @param self self reference * @return value of "stack" property */ public static Object getStack(final Object self) { final ScriptObject sobj = Global.checkObject(self); if (sobj.has(STACK)) { return sobj.get(STACK); } final Object exception = ECMAException.getException(sobj); if (exception instanceof Throwable) { final Object value = getScriptStackString(sobj, (Throwable) exception); if (sobj.hasOwnProperty(STACK)) { sobj.put(STACK, value, false); } else { sobj.addOwnProperty(STACK, Attribute.NOT_ENUMERABLE, value); } return value; } return UNDEFINED; }
/** * Nashorn extension: Error.prototype.fileName * * @param self self reference * @return file name from which error was thrown */ public static Object getFileName(final Object self) { final ScriptObject sobj = Global.checkObject(self); return sobj.has(FILENAME) ? sobj.get(FILENAME) : ECMAException.getFileName((ScriptObject) self); }
/** * Nashorn extension: Error.prototype.columnNumber * * @param self self reference * @return column number from which error was thrown */ public static Object getColumnNumber(final Object self) { final ScriptObject sobj = Global.checkObject(self); return sobj.has(COLUMNNUMBER) ? sobj.get(COLUMNNUMBER) : ECMAException.getColumnNumber((ScriptObject) self); }
/** * Nashorn extension: Error.prototype.lineNumber * * @param self self reference * @return line number from which error was thrown */ public static Object getLineNumber(final Object self) { final ScriptObject sobj = Global.checkObject(self); return sobj.has(LINENUMBER) ? sobj.get(LINENUMBER) : ECMAException.getLineNumber(sobj); }
/** * Nashorn extension: Error.prototype.printStackTrace prints stack trace associated with the * exception (if available). to the standard error stream. * * @param self self reference * @return result of {@link ECMAException#printStackTrace(ScriptObject)}, which is typically * undefined */ @Function(attributes = Attribute.NOT_ENUMERABLE) public static Object printStackTrace(final Object self) { return ECMAException.printStackTrace(Global.checkObject(self)); }