+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
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)
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;
}
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;
[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)]
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 ();
}
}