Browse Source

Fixing [[DefaultValue]] function

Sebastien Ros 11 years ago
parent
commit
3c02c5bd17

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

@@ -316,6 +316,22 @@ namespace Jint.Tests.Runtime
             ");
         }
 
+        [Fact]
+        public void ShouldConvertDateToNumber()
+        {
+            RunTest(@"
+                assert(Number(new Date(0)) === 0);
+            ");
+        }
+
+        [Fact]
+        public void DatePrimitiveValueShouldBeNaN()
+        {
+            RunTest(@"
+                assert(isNaN(Date.prototype.valueOf()));
+            ");
+        }
+
         [Fact]
         public void MathObjectIsDefined()
         {

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

@@ -20,7 +20,8 @@ namespace Jint.Native.Date
             var obj = new DatePrototype(engine)
             {
                 Prototype = engine.Object.PrototypeObject, 
-                Extensible = true
+                Extensible = true,
+                PrimitiveValue = double.NaN
             };
 
             obj.FastAddProperty("constructor", dateConstructor, true, false, true);

+ 2 - 2
Jint/Native/Object/ObjectInstance.cs

@@ -295,7 +295,7 @@ namespace Jint.Native.Object
         /// <returns></returns>
         public JsValue DefaultValue(Types hint)
         {
-            if ((hint == Types.String) || (hint == Types.None && this is StringInstance) || this is DateInstance)
+            if (hint == Types.String || (hint == Types.None && Class == "Date"))
             {
                 var toString = Get("toString").TryCast<ICallable>();
                 if (toString != null)
@@ -320,7 +320,7 @@ namespace Jint.Native.Object
                 throw new JavaScriptException(Engine.TypeError);
             }
 
-            if ((hint == Types.Number) || (hint == Types.None))
+            if (hint == Types.Number || hint == Types.None)
             {
                 var valueOf = Get("valueOf").TryCast<ICallable>();
                 if (valueOf != null)