2005-09-06 Florian Gross <flgr@ccan.de>
authorFlorian Gross <florian@mono-cvs.ximian.com>
Tue, 6 Sep 2005 15:57:38 +0000 (15:57 -0000)
committerFlorian Gross <florian@mono-cvs.ximian.com>
Tue, 6 Sep 2005 15:57:38 +0000 (15:57 -0000)
* ObjectPrototype.cs: Implemented better working hasOwnProperty
* In.cs: Implemented JScriptIn
* LateBinding.cs: Added LateBinding.Delete, HasObjectProperty,
DirectHasObjectProperty

svn path=/trunk/mcs/; revision=49548

mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
mcs/class/Microsoft.JScript/Microsoft.JScript/In.cs
mcs/class/Microsoft.JScript/Microsoft.JScript/LateBinding.cs
mcs/class/Microsoft.JScript/Microsoft.JScript/ObjectPrototype.cs
mcs/class/Microsoft.JScript/Microsoft.JScript/SemanticAnalizer.cs

index 8cac06cfe372b7832241c5341dbd5c1a7bc7d9bb..26dc8f3e6cd047b88b027a739dbc6e08177ebbca 100644 (file)
@@ -1,3 +1,10 @@
+2005-09-06  Florian Gross  <flgr@ccan.de>
+
+       * ObjectPrototype.cs: Implemented better working hasOwnProperty
+       * In.cs: Implemented JScriptIn
+       * LateBinding.cs: Added LateBinding.Delete, HasObjectProperty,
+       DirectHasObjectProperty
+
 2005-09-06  Cesar Lopez Nataren  <cnataren@novell.com>
 
        * CodeGenerator.cs (GetBoxType): Take into account the case where
index cb386de56a9cd8ddf93a095a40d11bc38473263a..486ceca326d50532f5a42d0f8a43204b89175073 100644 (file)
@@ -41,7 +41,11 @@ namespace Microsoft.JScript {
 
                public static bool JScriptIn (object v1, object v2)
                {
-                       return false;
+                       ScriptObject obj = v2 as ScriptObject;
+                       if (obj == null)
+                               return false;
+                       string key = Convert.ToString (v1);
+                       return LateBinding.HasObjectProperty (obj, key);
                }
 
                internal override bool Resolve (IdentificationTable context)
index bc0649f553d5a2522a88109f2d4ce805a9c43f0f..4ce0910c57678cfbbe88e262c302efe23982cc76 100644 (file)
@@ -283,7 +283,9 @@ namespace Microsoft.JScript {
 
                public bool Delete ()
                {
-                       throw new NotImplementedException ();
+                       // We are currently only calling LateBinding.Delete where we know that the
+                       // properties can't be deleted.
+                       return false;
                }
 
 
@@ -454,6 +456,42 @@ namespace Microsoft.JScript {
                        return null;
                }
 
+               internal static bool HasObjectProperty (ScriptObject obj, string key)
+               {
+                       return HasObjectProperty (obj, key, 0);
+               }
+
+               private static bool HasObjectProperty (ScriptObject obj, string key, int nesting)
+               {
+                       ScriptObject prop_obj;
+                       if (nesting > 0 && GetCacheEntry (out prop_obj, obj, key))
+                               return prop_obj != null;
+
+                       if (DirectHasObjectProperty (obj, key)) {
+                               if (nesting > 0)
+                                       SetCacheEntry (obj, key, obj);
+                               return true;
+                       }
+
+                       ScriptObject cur_obj = obj.proto as ScriptObject;
+                       if (cur_obj != null) {
+                               bool success = HasObjectProperty (cur_obj, key, nesting + 1);
+                               if (nesting > 0)
+                                       SetCacheEntry (obj, key, cur_obj);
+                               return success;
+                       }
+
+                       if (nesting > 0)
+                               SetCacheEntry (obj, key, null);
+                       return false;
+               }
+
+               internal static bool DirectHasObjectProperty (ScriptObject obj, string key)
+               {
+                       object result;
+                       return TryDirectGetObjectProperty (out result, obj, key);
+               }
+
                private static bool TryDirectGetObjectProperty (out object result, ScriptObject obj, string rhs)
                {
                        ArrayObject ary = obj as ArrayObject;
index 492da9dd4e376be995b386ef6990cfd006694958..99012fb2e3599a898f499fb300eb2f3499068a89 100644 (file)
@@ -48,11 +48,11 @@ namespace Microsoft.JScript {
                [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Object_hasOwnProperty)]
                public static bool hasOwnProperty (object thisObj, object name)
                {
-                       if (thisObj == null || name == null)
+                       ScriptObject obj = thisObj as ScriptObject;
+                       if (obj == null)
                                return false;
-                       Type type = thisObj.GetType ();
-                       FieldInfo res = type.GetField (Convert.ToString (name));
-                       return res == null;
+                       string key = Convert.ToString (name);
+                       return LateBinding.DirectHasObjectProperty (obj, key);
                }
 
                [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Object_isPrototypeOf)]
index ccd3dea93bf0d1c5f1454df53e2142b6cd51f6bb..21f03b658f35484c1817fac7049f66d943ff1b15 100644 (file)
@@ -359,8 +359,8 @@ namespace Microsoft.JScript {
                                if (right.name.Value == "prototype")
                                        return false;
                        }
-                       Console.WriteLine ("left = {0}...left.Type = {1} ... right = {2}...right.Type = {3}",
-                                  left, left.GetType (), right, right.GetType ());
+                       Console.WriteLine ("ctr = {0}, left = {1} ({2}); right = {3} ({4})",
+                                  ctr, left, left.GetType (), right, right.GetType ());
                        throw new NotImplementedException ();
                }
        }