Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: add file name in stack traces for compiled classes #1773

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andreabergia
Copy link
Contributor

In interpreter mode, we always put the file name, but in compiled mode we do it only in case of compilerEnv.isGenerateDebugInfo(). I think that the interpreter's behavior is much more useful, so I changed the compiler to always include the file name.

For an example of the difference, create two files:

one.js

const two = require('./two');
two();

and two.js:

module.exports = function() {
	throw new Error('hey')
}

Then launch the shell passing -version 200 -opt -1 -require one.js to get the following, useful stack trace:

js: "file:/Users/andrea.bergia/src/rhino/two.js", line 2: exception from uncaught JavaScript throw: Error: hey
	at file:/Users/andrea.bergia/src/rhino/two.js:2
	at file:/Users/andrea.bergia/src/rhino/one.js:2

But with -opt 0 we get:

js: "file:/Users/andrea.bergia/src/rhino/two.js", line 2: exception from uncaught JavaScript throw: Error: hey
	at (unknown):2 (anonymous)
	at (unknown):2

which isn't as useful.

In interpreter mode, we always put the file name, but in compiled mode
we do it only in case of `compilerEnv.isGenerateDebugInfo()`. I think
that the interpreter's behavior is much more useful, so I changed the
compiler to always include the file name.

For an example of the difference, create two files:

<b>`one.js`</b>

```js
const two = require('./two');
two();
```

and <b>`two.js`</b>:

```js
module.exports = function() {
	throw new Error('hey')
}
```

Then launch the shell passing `-version 200 -opt -1 -require one.js` to
get the following, useful stack trace:

```
js: "file:/Users/andrea.bergia/src/rhino/two.js", line 2: exception from uncaught JavaScript throw: Error: hey
	at file:/Users/andrea.bergia/src/rhino/two.js:2
	at file:/Users/andrea.bergia/src/rhino/one.js:2
```

But with `-opt 0` we get:

```
js: "file:/Users/andrea.bergia/src/rhino/two.js", line 2: exception from uncaught JavaScript throw: Error: hey
	at (unknown):2 (anonymous)
	at (unknown):2
```

which isn't as useful.
Copy link
Collaborator

@gbrail gbrail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think of why anyone wouldn't want this, but let's see if anyone pops up and has questions.

@gbrail gbrail added this to the Release 1.8.0 milestone Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants