JDK-8029967 : Final steps to have Error compliant with V8 Error API
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Priority: P4
  • Status: Resolved
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2013-12-11
  • Updated: 2014-01-23
  • Resolved: 2014-01-23
Related Reports
Relates :  
Relates :  
Relates :  
Description
The list of missing features to have node modules that rely on v8 error API(specified by : http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi) to work properly.

Points1) 2) 4) and 5) are must have and can't be implemented in avatar-is without Nashorn support.

1) Error constructor should capture the stack.
2) Error constructor should call prepareStackTrace.
3) captureStackTrace should call prepareStackTrace.
4) captureStackTrace should support option argument (a function to limit stackTrace). e.g.: Error.captureStackTrace(obj, arguments.callee);
5) Support for Callsite properties. The most properties we can get, we will not have all.
6) Stack filename shouldn't be an URL, file/xxx ==> /xxx, some modules load file from the filesystem using this information...
7) Support for Error.stackTraceLimit, optional, didn't find a module using it. But we could.
8) stack property of an Error shouldn't be replaced when throwing this error
9) Error properties are not enumerable, Object.keys called on an Error instance returns an empty array.

Typical rethrow case:
var backtrace = new Error;
Error.captureStackTrace(backtrace);
doit();
function doit() {
    throw backtrace;//doit function not in the stack!
}

Typical stack customisation:
function getStackofCallSites() {
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function(_, stack){ return stack; };
var err = {};
Error.captureStackTrace(err, arguments.callee);
Error.prepareStackTrace = orig;
return err.stack;
}
Comments
This is an umbrella Error rfes/bugs. A subset of issues addressed by separate bugs linked from this rfe. Remaining issues can not be addressed in nashorn implementation. So, I am resolving this rfe as "will not fix" (although a subset of issues have been fixed).
23-01-2014

All specific issues addressed by other fixes and by explaining why nashorn will not implement.
23-01-2014

> 1) Error constructor should capture the stack. Addressed by JDK-8031983 > 2) Error constructor should call prepareStackTrace. > 3) captureStackTrace should call prepareStackTrace. Will not be implemented. Error.prepareStackTrace can be defined. But nashorn will ignore it. > 4) captureStackTrace should support option argument (a function to limit stackTrace). e.g.: Error.captureStackTrace(obj, arguments.callee); Our stack trace is built on top of Java's stack trace (Throwable and StackTraceElement[] array). We don't have access to ScriptFunction object to filter. We'll not implement this. > 5) Support for Callsite properties. The most properties we can get, we will not have all. Java's StackTraceElement object does not have all the info needed to implement Callsite. Only line number, file name and method/class names are available. So, we can not implement this. > 6) Stack filename shouldn't be an URL, file/xxx ==> /xxx, some modules load file from the filesystem using this information... Nashorn uses whatever user supplied name as name for in .class file. Avatar uses file:/// URLs and so nashorn will put the same in .class and the same will be seen in stack traces. But, nashorn has support // #sourceURL (and // @sourceURL) directive comments (aka "eval naming"). Avatar can make use of this to associate any name for a script loaded by 'eval' or 'load'. The same name will be put in .class and will show up in stack traces too. See also JDK-8032068. > 7) Support for Error.stackTraceLimit, optional, didn't find a module using it. But we could. This will not be implemented. But user can specify Error.stackTraceLimit - but nashorn will ignore that. > 8) stack property of an Error shouldn't be replaced when throwing this error Done as part of JDK-8031983 > 9) Error properties are not enumerable, Object.keys called on an Error instance returns an empty array. Fixed by JDK-8032004
23-01-2014

This is v8 specific extension "compatibility" and so it is an RFE really.
11-12-2013