sebastienros / jint

Javascript Interpreter for .NET
BSD 2-Clause "Simplified" License
4.05k stars 557 forks source link

Incorrect line number in stacktrace for undefined function in module mode #1967

Open trannamtrung1st opened 10 hours ago

trannamtrung1st commented 10 hours ago

Description:

When running in module mode, if a function is called that is undefined, the stacktrace reports an incorrect line number. It shows the line number of the next line instead of the line where the function is called.

Steps to reproduce:

  1. Create a JavaScript file with the following content:
function main() {
  const a = test(1, 
    2, 3, {});
}
main();
  1. Run this file in module mode using Jint.

  2. Observe the stacktrace when it fails due to test being undefined.

Expected behavior:

The stacktrace should show line 2 (where const a = test(1, is located) as the source of the error.

Actual behavior:

The stacktrace incorrectly shows line 3 (where 2, 3, {}); is located) as the source of the error.

Additional information:

Environment:

lahma commented 10 hours ago

Can you submit a PR to propose a fix?

trannamtrung1st commented 10 hours ago

I will try when I have time next week. I suspect that this issue is related to the parsing or statement tracking, so let's wait if there's anybody else who is more familiar with this process to give an idea.