浏览代码

Fixed some JSON.parse error and set exception msg

Fixed some JSON.parse errors and set exception message correctly
Frederic Torres 11 年之前
父节点
当前提交
3026b3308e
共有 3 个文件被更改,包括 16 次插入3 次删除
  1. 1 1
      Jint/Native/Json/JsonParser.cs
  2. 1 1
      Jint/Native/Json/JsonSerializer.cs
  3. 14 1
      Jint/Runtime/JavaScriptException.cs

+ 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; } }