Explorar el Código

Fix Date's NaN JSON.stringify (#764)

Marko Lahma hace 5 años
padre
commit
02b4f692d4
Se han modificado 2 ficheros con 7 adiciones y 1 borrados
  1. 6 0
      Jint.Tests/Runtime/DateTests.cs
  2. 1 1
      Jint/Native/Date/DatePrototype.cs

+ 6 - 0
Jint.Tests/Runtime/DateTests.cs

@@ -57,5 +57,11 @@ namespace Jint.Tests.Runtime
             Assert.Equal("Invalid Date", value);
         }
 
+        [Fact]
+        public void ToJsonFromNaNObject()
+        {
+            var result = _engine.Execute("JSON.stringify({ date: new Date(NaN) });").GetCompletionValue();
+            Assert.Equal("{\"date\":null}", result.ToString());
+        }
     }
 }

+ 1 - 1
Jint/Native/Date/DatePrototype.cs

@@ -688,7 +688,7 @@ namespace Jint.Native.Date
         {
             var o = TypeConverter.ToObject(Engine, thisObj);
             var tv = TypeConverter.ToPrimitive(o, Types.Number);
-            if (tv.IsNumber() && double.IsInfinity(((JsNumber) tv)._value))
+            if (tv.IsNumber() && !IsFinite(((JsNumber) tv)._value))
             {
                 return Null;
             }