Browse Source

Fixing ErrorPrototype inheritance

Sebastien Ros 11 years ago
parent
commit
1eb6a6f727

+ 1 - 0
Jint.Tests.Ecma/Ecma/11.8.6.cs

@@ -2,6 +2,7 @@ using Xunit;
 
 
 namespace Jint.Tests.Ecma
 namespace Jint.Tests.Ecma
 {
 {
+    [Trait("Category","Pass")]
     public class Test_11_8_6 : EcmaTest
     public class Test_11_8_6 : EcmaTest
     {
     {
         [Fact]
         [Fact]

+ 4 - 4
Jint/Native/Error/ErrorConstructor.cs

@@ -15,13 +15,13 @@ namespace Jint.Native.Error
             var obj = new ErrorConstructor(engine);
             var obj = new ErrorConstructor(engine);
             obj.Extensible = true;
             obj.Extensible = true;
 
 
-            // The value of the [[Prototype]] internal property of the Error constructor is the Function prototype object 
+            // The value of the [[Prototype]] internal property of the Error constructor is the Function prototype object (15.11.3)
             obj.Prototype = engine.Function.PrototypeObject;
             obj.Prototype = engine.Function.PrototypeObject;
             obj.PrototypeObject = ErrorPrototype.CreatePrototypeObject(engine, obj, name);
             obj.PrototypeObject = ErrorPrototype.CreatePrototypeObject(engine, obj, name);
 
 
             obj.FastAddProperty("length", 1, false, false, false);
             obj.FastAddProperty("length", 1, false, false, false);
 
 
-            // The initial value of Date.prototype is the Boolean prototype object
+            // The initial value of Error.prototype is the Error prototype object
             obj.FastAddProperty("prototype", obj.PrototypeObject, false, false, false);
             obj.FastAddProperty("prototype", obj.PrototypeObject, false, false, false);
 
 
             return obj;
             return obj;
@@ -43,9 +43,9 @@ namespace Jint.Native.Error
             instance.Prototype = PrototypeObject;
             instance.Prototype = PrototypeObject;
             instance.Extensible = true;
             instance.Extensible = true;
 
 
-            if (arguments.Length > 0 && arguments[0] != Undefined.Instance)
+            if (arguments.At(0) != Undefined.Instance)
             {
             {
-                instance.Put("message", TypeConverter.ToString(arguments[0]), false);
+                instance.Put("message", TypeConverter.ToString(arguments.At(0)), false);
             }
             }
 
 
             return instance;
             return instance;

+ 1 - 2
Jint/Native/Error/ErrorInstance.cs

@@ -1,9 +1,8 @@
 using Jint.Native.Object;
 using Jint.Native.Object;
-using Jint.Runtime;
 
 
 namespace Jint.Native.Error
 namespace Jint.Native.Error
 {
 {
-    public sealed class ErrorInstance : ObjectInstance
+    public class ErrorInstance : ObjectInstance
     {
     {
         public ErrorInstance(Engine engine, string name)
         public ErrorInstance(Engine engine, string name)
             : base(engine)
             : base(engine)

+ 10 - 22
Jint/Native/Error/ErrorPrototype.cs

@@ -7,32 +7,28 @@ namespace Jint.Native.Error
     /// <summary>
     /// <summary>
     /// http://www.ecma-international.org/ecma-262/5.1/#sec-15.11.4
     /// http://www.ecma-international.org/ecma-262/5.1/#sec-15.11.4
     /// </summary>
     /// </summary>
-    public sealed class ErrorPrototype : ObjectInstance
+    public sealed class ErrorPrototype : ErrorInstance
     {
     {
-        private readonly string _name;
-
-        private ErrorPrototype(Engine engine, string name)
-            : base(engine)
+        private ErrorPrototype(Engine engine)
+            : base(engine, "Error")
         {
         {
-            _name = name;
         }
         }
 
 
         public static ErrorPrototype CreatePrototypeObject(Engine engine, ErrorConstructor errorConstructor, string name)
         public static ErrorPrototype CreatePrototypeObject(Engine engine, ErrorConstructor errorConstructor, string name)
         {
         {
-            var obj = new ErrorPrototype(engine, name) { Extensible = true };
-            obj.Prototype = engine.Object.PrototypeObject;
-
+            var obj = new ErrorPrototype(engine) { Extensible = true };
             obj.FastAddProperty("constructor", errorConstructor, false, false, false);
             obj.FastAddProperty("constructor", errorConstructor, false, false, false);
 
 
+            if (name != "Error")
+            {
+                obj.Prototype = engine.Error.PrototypeObject;
+            }
+
             return obj;
             return obj;
         }
         }
 
 
         public void Configure()
         public void Configure()
         {
         {
-            // Error prototype properties
-            FastAddProperty("message", "", true, false, true);
-            FastAddProperty("name", _name, true, false, true);
-
             // Error prototype functions
             // Error prototype functions
             FastAddProperty("toString", new ClrFunctionInstance<object, object>(Engine, ToString), true, false, true);
             FastAddProperty("toString", new ClrFunctionInstance<object, object>(Engine, ToString), true, false, true);
         }
         }
@@ -45,15 +41,7 @@ namespace Jint.Native.Error
                 throw new JavaScriptException(Engine.TypeError);
                 throw new JavaScriptException(Engine.TypeError);
             }
             }
 
 
-            var name = o.Get("name");
-            if (name == Undefined.Instance)
-            {
-                name = _name;
-            }
-            else
-            {
-                name = TypeConverter.ToString(name);
-            }
+            var name = TypeConverter.ToString(o.Get("name"));
 
 
             var msg = o.Get("message");
             var msg = o.Get("message");
             if (msg == Undefined.Instance)
             if (msg == Undefined.Instance)