User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:220.127.116.11) Gecko/2010021501 Ubuntu/9.04 (jaunty) Firefox/3.0.18 Build Identifier: NativeError already has two interesting non ECMA properties: lineNumber and fileName. It would be useful to have property stack as well as done in different browsers. Additionally, the information returned by RhinoException.getScriptStackTrace vary depending on the optimization level used. In interpreted mode in contains the function name whereas it is not the case in compiled mode. Reproducible: Always
Created attachment 429708 [details] [diff] [review] Patch with unit test implementing NativeError's stack property and improving RhinoException.getScriptStacktrace in compiled mode
Thanks for report and patch. I guess mirroring the stack format from Firefox is important to you? I prefer the one we have in RhinoException.getScriptStackTrace() for readability, but I think anything that's easy to parse is ok. One thing I'd like to add to your patch is including support for the stack property for Errors generated via new Error() when the Context.FEATURE_LOCATION_INFORMATION_IN_ERROR feature is enabled (see bug #342807), so I consider doing a bit more refactoring on that.
Indeed it is important for me to mirror Firefox format. RhinoException.getScriptStackTrace is a bit more coherent with this patch but if you really want to improve the situation in this area, I think that RhinoException should rather provide access to a StackTraceElement. It would be far better than having to parse strings. You're right, it makes sense to handle Context.FEATURE_LOCATION_INFORMATION_IN_ERROR too.
Created attachment 436164 [details] [diff] [review] new patch Rewritten patch. This adds getScriptStack() methods to RhinoExceptions to get the exception's stack as array of the (newly introduced) ScriptStackElement class. The default stack format is the "traditional" Rhino format, but there's a static useMozillaStackStyle(boolean) method in RhinoException to switch to Mozilla/Firefox stack format. Is that a viable solution for you, Marc? The patch also sets the stack on Errors thrown by script code if the FEATURE_LOCATION_INFORMATION_IN_ERROR context feature is enabled.
Created attachment 436176 [details] [diff] [review] slightly revised version of the second patch