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

Location.Start.Column and JavaScriptStackTrace properties of the JavaScriptException class sometimes have different column values #1245

Closed
Taritsyn opened this issue Jul 25, 2022 · 4 comments · Fixed by #1273
Labels

Comments

@Taritsyn
Copy link
Contributor

Hello!

In Jint version Beta 2039, the accuracy of determining the location of error has been improved. I have encountered only one case where the location of error was not determined accurately.

To reproduce this inaccuracy, I created a example:

using System;

using Jint;
using Jint.Runtime;

namespace TestJint
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                var engine = new Engine();
                engine.Execute(@"var $variable1 = 611;
var _variable2 = 711;
var variable3 = 678;

$variable1 + -variable2 - variable3;");
            }
            catch (JavaScriptException e)
            {
                Console.WriteLine("Location.Start.Line: {0}", e.Location.Start.Line);
                Console.WriteLine("Location.Start.Column: {0}", e.Location.Start.Column);
                Console.WriteLine("JavaScriptStackTrace: {0}", e.JavaScriptStackTrace);
            }
        }
    }
}

This example produces the following result:

Location.Start.Line: 5
Location.Start.Column: 0
JavaScriptStackTrace:    at <anonymous>:5:15

The value of the Location.Start.Column property is zero, but should be equal to 14. The most interesting thing is that the JavaScriptStackTrace property contains the accurate location.

@lahma
Copy link
Collaborator

lahma commented Jul 26, 2022

Thanks for the report and repro, this is the minimal test case which is failing:

        [Fact]
        public void ShouldReportCorrectColumn()
        {
            var e = Assert.Throws<JavaScriptException>(() =>
            {
                var engine = new Engine();
                engine.Execute(@"var $variable1 = 611;
var _variable2 = 711;
var variable3 = 678;

$variable1 + -variable2 - variable3;");
            });

            Assert.Equal(5, e.Location.Start.Line);
            Assert.Equal(15, e.Location.Start.Column);
            Assert.Equal("   at <anonymous>:5:15", e.JavaScriptStackTrace);
        }

I'll try to look into this at some point unless @christianrondeau gets nerd-sniped by this as he's been working with exceptions and stack traces recently 😉

@Taritsyn
Copy link
Contributor Author

            Assert.Equal(15, e.Location.Start.Column);

Only in this place it will not be 15, but 14, because the value of this property usually starts from zero.

@Taritsyn
Copy link
Contributor Author

Thanks!

@lahma
Copy link
Collaborator

lahma commented Aug 29, 2022

Thanks for reporting all the regressions you find, you have a great test suite! 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants