Преглед изворни кода

Fixed some JSON.parse error and set exception msg

Fixed some JSON.parse errors and set exception message correctly
Frederic Torres пре 11 година
родитељ
комит
3026b3308e

+ 1 - 1
Jint/Native/Json/JsonParser.cs

@@ -76,7 +76,7 @@ namespace Jint.Native.Json
                 }
                 else
                 {
-                    return char.MinValue;
+                    throw new JavaScriptException(_engine.SyntaxError, string.Format("Expected hexadecimal digit:{0}", _source));
                 }
             }
             return (char)code;

+ 1 - 1
Jint/Native/Json/JsonSerializer.cs

@@ -28,7 +28,7 @@ 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 the replacer is not defined. The function is not called either.
             if (value.Is<ICallable>() && replacer == Undefined.Instance) 
             {
                 return Undefined.Instance;

+ 14 - 1
Jint/Runtime/JavaScriptException.cs

@@ -20,9 +20,22 @@ namespace Jint.Runtime
         }
 
         public JavaScriptException(JsValue error)
-            : base("")
+            : base(GetErrorMessage(error))
         {
             _errorObject = error;
+            
+        }
+
+        private static string GetErrorMessage(JsValue error) 
+        {
+            if (error.IsObject())
+            {
+                var oi = error.AsObject();
+                var message = oi.Get("message").AsString();
+                return message;
+            }
+            else
+                return string.Empty;            
         }
 
         public JsValue Error { get { return _errorObject; } }