-
Notifications
You must be signed in to change notification settings - Fork 858
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: add file name in stack traces for compiled classes
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.
- Loading branch information
1 parent
d243106
commit f87e7f3
Showing
4 changed files
with
37 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
tests/src/test/resources/org/mozilla/javascript/tests/commonjs/module/throw-one.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const two = require('throw-two'); | ||
two(); |
3 changes: 3 additions & 0 deletions
3
tests/src/test/resources/org/mozilla/javascript/tests/commonjs/module/throw-two.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function() { | ||
throw new Error('hey') | ||
} |