Browse Source

fix 15.12.3-11-2, 15.12.3-11-14, 15.12.3-6-b-3.js, S15.12.2_A1

fix 15.12.3-11-2, 15.12.3-11-14, 15.12.3-6-b-3.js, S15.12.2_A1
Frederic Torres 11 years ago
parent
commit
9bc86dfede
2 changed files with 17 additions and 4 deletions
  1. 2 2
      Jint/Native/Json/JsonInstance.cs
  2. 15 2
      Jint/Native/Json/JsonSerializer.cs

+ 2 - 2
Jint/Native/Json/JsonInstance.cs

@@ -39,7 +39,7 @@ namespace Jint.Native.Json
         {
             var parser = new JsonParser(_engine);
 
-            return parser.Parse(arguments[0].ToString());
+            return parser.Parse(arguments[0].AsString());
         }
 
         public JsValue Stringify(JsValue thisObject, JsValue[] arguments)
@@ -65,7 +65,7 @@ namespace Jint.Native.Json
             }
 
             var serializer = new JsonSerializer(_engine);
-            if (value == Undefined.Instance) {
+            if (value == Undefined.Instance && replacer == Undefined.Instance) {
                 return Undefined.Instance;
             }
             else {

+ 15 - 2
Jint/Native/Json/JsonSerializer.cs

@@ -27,6 +27,13 @@ namespace Jint.Native.Json
         {
             _stack = new Stack<object>();
 
+            // for JSON.stringify(), any function passed as the first argument will return undefined
+            // if the replacer if not defined. The function is not called either.
+            if (value.Is<ICallable>() && replacer == Undefined.Instance) 
+            {
+                return Undefined.Instance;
+            }
+
             if (replacer.IsObject())
             {
                 if (replacer.Is<ICallable>())
@@ -87,7 +94,13 @@ namespace Jint.Native.Json
             // defining the gap
             if (space.IsNumber())
             {
-                _gap = new System.String(' ', (int) System.Math.Min(10, space.AsNumber()));
+                if (space.AsNumber() > 0) {
+                    _gap = new System.String(' ', (int)System.Math.Min(10, space.AsNumber()));
+                }
+                else 
+                {
+                    _gap = string.Empty;
+                }
             }
             else if (space.IsString())
             {
@@ -96,7 +109,7 @@ namespace Jint.Native.Json
             }
             else
             {
-                _gap = "";
+                _gap = string.Empty;
             }
 
             var wrapper = _engine.Object.Construct(Arguments.Empty);