Browse Source

#27: Fixing CLR member assignment

Implementing Put() on DelegateWrapper
Sebastien Ros 11 years ago
parent
commit
6e70af7b21

+ 1 - 1
Jint.Tests/Runtime/InteropTests.cs

@@ -574,7 +574,7 @@ namespace Jint.Tests.Runtime
             _engine.SetValue("p", p);
             _engine.SetValue("p", p);
 
 
             RunTest(@"
             RunTest(@"
-                assert(p.Age++ === 2);
+                assert(++p.Age === 2);
             ");
             ");
 
 
             Assert.Equal(2, p.Age);
             Assert.Equal(2, p.Age);

+ 1 - 1
Jint/Engine.cs

@@ -193,7 +193,7 @@ namespace Jint
 
 
         public Engine SetValue(string name, JsValue value)
         public Engine SetValue(string name, JsValue value)
         {
         {
-            Global.Set(name, value);
+            Global.Put(name, value, false);
             return this;
             return this;
         }
         }
 
 

+ 2 - 15
Jint/Native/Object/ObjectInstance.cs

@@ -69,20 +69,7 @@ namespace Jint.Native.Object
             var callable = getter.TryCast<ICallable>();
             var callable = getter.TryCast<ICallable>();
             return callable.Call(this, Arguments.Empty);
             return callable.Call(this, Arguments.Empty);
         }
         }
-
-        public void Set(string name, JsValue value)
-        {
-
-            if (!HasProperty(name))
-            {
-                DefineOwnProperty(name, new PropertyDescriptor(value, true, true, true), false);
-            }
-            else
-            {
-                Put(name, value, false);
-            }
-        }
-
+        
         /// <summary>
         /// <summary>
         /// Returns the Property Descriptor of the named 
         /// Returns the Property Descriptor of the named 
         /// own property of this object, or undefined if 
         /// own property of this object, or undefined if 
@@ -147,7 +134,7 @@ namespace Jint.Native.Object
         /// <param name="propertyName"></param>
         /// <param name="propertyName"></param>
         /// <param name="value"></param>
         /// <param name="value"></param>
         /// <param name="throwOnError"></param>
         /// <param name="throwOnError"></param>
-        public void Put(string propertyName, JsValue value, bool throwOnError)
+        public virtual void Put(string propertyName, JsValue value, bool throwOnError)
         {
         {
             if (!CanPut(propertyName))
             if (!CanPut(propertyName))
             {
             {

+ 30 - 0
Jint/Runtime/Interop/ObjectWrapper .cs

@@ -1,6 +1,7 @@
 using System;
 using System;
 using System.Linq;
 using System.Linq;
 using System.Reflection;
 using System.Reflection;
+using Jint.Native;
 using Jint.Native.Object;
 using Jint.Native.Object;
 using Jint.Runtime.Descriptors;
 using Jint.Runtime.Descriptors;
 using Jint.Runtime.Descriptors.Specialized;
 using Jint.Runtime.Descriptors.Specialized;
@@ -19,6 +20,35 @@ namespace Jint.Runtime.Interop
             Target = obj;
             Target = obj;
         }
         }
 
 
+        public override void Put(string propertyName, JsValue value, bool throwOnError)
+        {
+            if (!CanPut(propertyName))
+            {
+                if (throwOnError)
+                {
+                    throw new JavaScriptException(Engine.TypeError);
+                }
+
+                return;
+            }
+
+            var ownDesc = GetOwnProperty(propertyName);
+
+            if (ownDesc == null)
+            {
+                if (throwOnError)
+                {
+                    throw new JavaScriptException(Engine.TypeError, "Unknown member: " + propertyName);
+                }
+                else
+                {
+                    return;
+                }
+            }
+
+            ownDesc.Value = value;
+        }
+
         public override PropertyDescriptor GetOwnProperty(string propertyName)
         public override PropertyDescriptor GetOwnProperty(string propertyName)
         {
         {
             PropertyDescriptor x;
             PropertyDescriptor x;