Browse Source

LFixed issue where the line number for exceptions in nested function wasn't correct (#345)

Andrey Korolev 8 years ago
parent
commit
c4c80a398b
2 changed files with 19 additions and 1 deletions
  1. 18 0
      Jint.Tests/Runtime/EngineTests.cs
  2. 1 1
      Jint/Runtime/StatementInterpreter.cs

+ 18 - 0
Jint.Tests/Runtime/EngineTests.cs

@@ -1829,5 +1829,23 @@ namespace Jint.Tests.Runtime
             ");
         }
 
+        [Fact]
+        public void ExceptionShouldHaveLocationOfInnerFunction()
+        {
+            try
+            {
+                new Engine()
+                    .Execute(@"
+                    function test(s) {
+                        o.boom();
+                    }
+                    test('arg');
+                ");
+            }
+            catch (JavaScriptException ex)
+            {
+                Assert.Equal(3, ex.LineNumber);
+            }
+        }
     }
 }

+ 1 - 1
Jint/Runtime/StatementInterpreter.cs

@@ -432,7 +432,7 @@ namespace Jint.Runtime
             catch(JavaScriptException v)
             {
                 c = new Completion(Completion.Throw, v.Error, null);
-                c.Location = s.Location;
+                c.Location = v.Location ?? s.Location;
                 return c;
             }