Browse Source

Fixed JSON unit tests
This end up fixing 12 unit tests

Fixed unit tests 5.12.3-11-1, 15.12.3-0-2, 15.12.3-11-10, 15.12.3-11-12.
This end up fixing 12 unit tests

Frederic Torres 11 years ago
parent
commit
accc2fc6b3
2 changed files with 21 additions and 7 deletions
  1. 9 4
      Jint/Native/Json/JsonInstance.cs
  2. 12 3
      Jint/Native/Json/JsonSerializer.cs

+ 9 - 4
Jint/Native/Json/JsonInstance.cs

@@ -31,9 +31,9 @@ namespace Jint.Native.Json
 
 
         public void Configure()
         public void Configure()
         {
         {
-
-            FastAddProperty("parse", new ClrFunctionInstance(Engine, Parse), true, false, true);
-            FastAddProperty("stringify", new ClrFunctionInstance(Engine, Stringify), true, false, true);
+            FastAddProperty("parse", new ClrFunctionInstance(Engine, Parse, 2), true, false, true);
+            // 15.12.3-0-2
+            FastAddProperty("stringify", new ClrFunctionInstance(Engine, Stringify, 3), true, false, true);
         }
         }
 
 
         public JsValue Parse(JsValue thisObject, JsValue[] arguments)
         public JsValue Parse(JsValue thisObject, JsValue[] arguments)
@@ -66,7 +66,12 @@ namespace Jint.Native.Json
             }
             }
 
 
             var serializer = new JsonSerializer(_engine);
             var serializer = new JsonSerializer(_engine);
-            return serializer.Serialize(value, replacer, space);
+            if (value == Undefined.Instance) {
+                return Undefined.Instance; // Unit test 5.12.3-11-1
+            }
+            else {
+                return serializer.Serialize(value, replacer, space);
+            }
         }
         }
     }
     }
 }
 }

+ 12 - 3
Jint/Native/Json/JsonSerializer.cs

@@ -105,8 +105,9 @@ namespace Jint.Native.Json
             return Str("", wrapper);
             return Str("", wrapper);
         }
         }
 
 
-        private string Str(string key, ObjectInstance holder)
+        private JsValue Str(string key, ObjectInstance holder)
         {
         {
+            
             var value = holder.Get(key);
             var value = holder.Get(key);
             if (value.IsObject())
             if (value.IsObject())
             {
             {
@@ -124,7 +125,7 @@ namespace Jint.Native.Json
             if (_replacerFunction != Undefined.Instance)
             if (_replacerFunction != Undefined.Instance)
             {
             {
                 var replacerFunctionCallable = (ICallable)_replacerFunction.AsObject();
                 var replacerFunctionCallable = (ICallable)_replacerFunction.AsObject();
-                value = replacerFunctionCallable.Call(holder, Arguments.From(key));
+                value = replacerFunctionCallable.Call(holder, Arguments.From(key, value)); // 15.12.3-11-12 added missing value parameter
             }
             }
 
 
             
             
@@ -142,8 +143,16 @@ namespace Jint.Native.Json
                     case "Boolean":
                     case "Boolean":
                         value = TypeConverter.ToPrimitive(value);
                         value = TypeConverter.ToPrimitive(value);
                         break;
                         break;
+                    case "Array":  // 15.12.3-11-12 added missing serialization of array           
+                        value = SerializeArray(value.As<ArrayInstance>());
+                        return value;
+                        break;
                 }
                 }
             }
             }
+            
+            if (value == Undefined.Instance) {
+                return Undefined.Instance; // 15.12.3-11-10 
+            }
 
 
             if (value == Null.Instance)
             if (value == Null.Instance)
             {
             {
@@ -248,7 +257,7 @@ namespace Jint.Native.Json
             for (int i = 0; i < len; i++)
             for (int i = 0; i < len; i++)
             {
             {
                 var strP = Str(TypeConverter.ToString(i), value);
                 var strP = Str(TypeConverter.ToString(i), value);
-                partial.Add(strP);
+                partial.Add(strP.AsString()); // 15.12.3-11-12
             }
             }
             if (partial.Count == 0)
             if (partial.Count == 0)
             {
             {