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]
         [Fact]
         public void MathObjectIsDefined()
         public void MathObjectIsDefined()
         {
         {

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

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

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

@@ -295,7 +295,7 @@ namespace Jint.Native.Object
         /// <returns></returns>
         /// <returns></returns>
         public JsValue DefaultValue(Types hint)
         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>();
                 var toString = Get("toString").TryCast<ICallable>();
                 if (toString != null)
                 if (toString != null)
@@ -320,7 +320,7 @@ namespace Jint.Native.Object
                 throw new JavaScriptException(Engine.TypeError);
                 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>();
                 var valueOf = Get("valueOf").TryCast<ICallable>();
                 if (valueOf != null)
                 if (valueOf != null)