Просмотр исходного кода

Empty error message when trying to call an object like a function (#581)

Marko Lahma 6 лет назад
Родитель
Сommit
33ffc9912b

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

@@ -123,6 +123,21 @@ namespace Jint.Tests.Runtime
             ");
             ");
         }
         }
 
 
+        [Fact]
+        public void ShouldHaveProperNotAFunctionErrorMessage()
+        {
+            RunTest(@"
+                try {
+                    var example = {};
+                    example();
+                    assert(false);
+                }
+                catch (ex) {
+                    assert(ex.message === 'example is not a function');
+                }
+            ");
+        }
+
         [Fact]
         [Fact]
         public void ShouldEvaluateHasOwnProperty()
         public void ShouldEvaluateHasOwnProperty()
         {
         {

+ 1 - 1
Jint/Native/Number/Dtoa/Bignum.cs

@@ -155,7 +155,7 @@ namespace Jint.Native.Number.Dtoa
         // Guaranteed to lie in one Bigit.
         // Guaranteed to lie in one Bigit.
         internal void AssignUInt16(uint value)
         internal void AssignUInt16(uint value)
         {
         {
-            Debug.Assert(kBigitSize >= 8 * sizeof(uint));
+            Debug.Assert(kBigitSize <= 8 * sizeof(uint));
             Zero();
             Zero();
             if (value == 0) return;
             if (value == 0) return;
 
 

+ 2 - 1
Jint/Runtime/Interpreter/Expressions/JintCallExpression.cs

@@ -135,7 +135,8 @@ namespace Jint.Runtime.Interpreter.Expressions
 
 
             if (!(func is ICallable callable))
             if (!(func is ICallable callable))
             {
             {
-                return ExceptionHelper.ThrowTypeError<object>(_engine);
+                var message = $"{r?.GetReferencedName() ?? ""} is not a function";
+                return ExceptionHelper.ThrowTypeError<object>(_engine, message);
             }
             }
 
 
             var thisObject = Undefined.Instance;
             var thisObject = Undefined.Instance;