graaljs
graaljs copied to clipboard
Offer option to disable some or all parts of V8 stack trace API
I noticed that even if js.v8-compat is false, the V8-style stack trace API is still present despite it being a non-standard extension to ECMA-262 in V8. The nasty things about this API are that it:
- Leaks internal values defined in closures.
- Makes global behavior controlled by static properties on global objects, something which doesn't otherwise exist in ECMA-262.
error.stackis a lazy getter, which has no parallel in ECMA-262 except for proxy objects.
Activation of the stack trace API could be controlled by js.v8-compat, but a partial clone of the API is also implemented by SpiderMonkey. The solution I propose is to add a flag, separate from js.v8-compat that controls whether the V8 stack trace API is implemented. When the flag is set to true, GraalVM JavaScript would behave as it currently does. When the flag is set to false:
Error.captureStackTraceis not implemented/present.- The stack trace formatter does not lookup
Error.prepareStackTrace. Error.stackTraceLimitis not present and its value, if it is defined by JavaScript code during execution, has no effect on the stack trace formatting.error.stackremains a thing, but it behaves as a data property.- All stack frames are included in the stack trace/
error.stack, as ifError.stackTraceLimitwere set toInfinityin the current version of GraalVM JavaScript.
Any movement on this, @iamstolis?
Fixed by https://github.com/oracle/graaljs/commit/7fccb3be23e15f1b9226d44bb0431838b7338782. This change ensures that Error.prepareStackTrace and Error.stackTraceLimit are used (and the latter defined) in js.v8-compat mode only. I.e. the maximum number of stack frames in error.stack is specified by js.stack-trace-limit option by default.
Note that we still provide Error.captureStackTrace by default. This built-in is useful when extending Error classes and is used outside js.v8-compat mode (in Nashorn, for example). Moreover, it is really simple to get rid of it if you don't want to make it available (just delete/remove it).