Przeglądaj źródła

Merge pull request #105 from sebastienros/bug/101

Bug/101
Sébastien Ros 10 lat temu
rodzic
commit
341883a06f

+ 15 - 0
Jint.Tests/Runtime/InteropTests.cs

@@ -1083,6 +1083,21 @@ namespace Jint.Tests.Runtime
                 assert(x === null);
             ");
         }
+        
+        [Fact]
+        public void ShouldSetPropertyToNull()
+        {
+            var p = new Person { Name = "Mickey" };
+            _engine.SetValue("p", p);
+            
+            RunTest(@"
+                assert(p.Name != null);
+                p.Name = null;
+                assert(p.Name == null);
+            ");
+            
+            Assert.True(p.Name == null);
+        }
 
     }
 }

+ 1 - 1
Jint/Runtime/Descriptors/Specialized/PropertyInfoDescriptor.cs

@@ -38,7 +38,7 @@ namespace Jint.Runtime.Descriptors.Specialized
                 {
                     // attempt to convert the JsValue to the target type
                     obj = currentValue.ToObject();
-                    if (obj.GetType() != _propertyInfo.PropertyType)
+                    if (obj != null && obj.GetType() != _propertyInfo.PropertyType)
                     {
                         obj = _engine.ClrTypeConverter.Convert(obj, _propertyInfo.PropertyType, CultureInfo.InvariantCulture);
                     }