graaljs icon indicating copy to clipboard operation
graaljs copied to clipboard

Offer option to disable some or all parts of V8 stack trace API

Open Melab opened this issue 3 years ago • 1 comments

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:

  1. Leaks internal values defined in closures.
  2. Makes global behavior controlled by static properties on global objects, something which doesn't otherwise exist in ECMA-262.
  3. error.stack is 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:

  1. Error.captureStackTrace is not implemented/present.
  2. The stack trace formatter does not lookup Error.prepareStackTrace.
  3. Error.stackTraceLimit is not present and its value, if it is defined by JavaScript code during execution, has no effect on the stack trace formatting.
  4. error.stack remains a thing, but it behaves as a data property.
  5. All stack frames are included in the stack trace/error.stack, as if Error.stackTraceLimit were set to Infinity in the current version of GraalVM JavaScript.

Melab avatar Oct 24 '22 17:10 Melab

Any movement on this, @iamstolis?

Melab avatar May 30 '24 17:05 Melab

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).

iamstolis avatar Jul 08 '24 08:07 iamstolis