Set initial line number to -1 and fix StackTraceTests

This fixes https://github.com/mozilla/rhino/issues/477
This commit is contained in:
Cam Walter 2024-09-03 16:57:07 -05:00 коммит произвёл Greg Brail
Родитель 1fb4321481
Коммит 3577b83557
2 изменённых файлов: 4 добавлений и 4 удалений

Просмотреть файл

@ -38,7 +38,7 @@ class CodeGenerator extends Icode {
private ScriptNode scriptOrFn;
private int iCodeTop;
private int stackDepth;
private int lineNumber;
private int lineNumber = -1;
private int doubleTableTop;
private final HashMap<String, Integer> strings = new HashMap<>();

Просмотреть файл

@ -32,7 +32,7 @@ public class StackTraceTest {
final String source2 = "function f2() { 'H'.toLowerCase(); throw 'hello'; }; f2();";
final String source3 =
"function f2() { new java.lang.String('H').toLowerCase(); throw 'hello'; }; f2();";
final String result = "\tat test.js (f2)" + LS + "\tat test.js" + LS;
final String result = "\tat test.js:0 (f2)" + LS + "\tat test.js:0" + LS;
runWithExpectedStackTrace(source1, result);
runWithExpectedStackTrace(source2, result);
@ -56,7 +56,7 @@ public class StackTraceTest {
final String source2 = "function f2() { 'H'.toLowerCase(); throw 'hello'; }; f2();";
final String source3 =
"function f2() { new java.lang.String('H').toLowerCase(); throw 'hello'; }; f2();";
final String result = "f2()@test.js" + LS + "@test.js" + LS;
final String result = "f2()@test.js:0" + LS + "@test.js:0" + LS;
runWithExpectedStackTrace(source1, result);
runWithExpectedStackTrace(source2, result);
@ -80,7 +80,7 @@ public class StackTraceTest {
final String source2 = "function f2() { 'H'.toLowerCase(); throw 'hello'; }; f2();";
final String source3 =
"function f2() { new java.lang.String('H').toLowerCase(); throw 'hello'; }; f2();";
final String result = "f2()@test.js\n@test.js\n";
final String result = "f2()@test.js:0\n@test.js:0\n";
runWithExpectedStackTrace(source1, result);
runWithExpectedStackTrace(source2, result);