5 // Cesar Lopez Nataren (cesar@ciencias.unam.mx)
7 // (C) 2003, Cesar Lopez Nataren
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Reflection;
34 namespace Microsoft.JScript {
36 public class ObjectPrototype : JSObject {
38 internal ObjectPrototype ()
42 internal static ObjectPrototype Proto = new ObjectPrototype ();
44 public static ObjectConstructor constructor {
45 get { return ObjectConstructor.Ctr; }
48 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Object_hasOwnProperty)]
49 public static bool hasOwnProperty (object thisObj, object name)
51 ScriptObject obj = thisObj as ScriptObject;
54 string key = Convert.ToString (name);
55 return LateBinding.DirectHasObjectProperty (obj, key);
58 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Object_isPrototypeOf)]
59 public static bool isPrototypeOf (object thisObj, object obj)
61 throw new NotImplementedException ();
64 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Object_propertyIsEnumerable)]
65 public static bool propertyIsEnumerable (object thisObj, object name)
67 if (thisObj == null || name == null)
69 // TODO: Implement me.
70 // Type type = thisObj.GetType ();
71 // FieldInfo res = type.GetField (Convert.ToString (name));
75 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Object_toLocaleString)]
76 public static string toLocaleString (object thisObj)
78 return toString (thisObj);
81 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Object_toString)]
82 public static string toString (object thisObj)
84 if (thisObj is ScriptObject) {
85 ScriptObject obj = (ScriptObject) thisObj;
86 return "[object " + obj.ClassName + "]";
88 throw new NotImplementedException ();
91 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Object_valueOf)]
92 public static object valueOf (object thisObj)
97 internal static object smartToString (JSObject thisObj)
99 JSObject obj = (JSObject) thisObj;
100 object val = obj.GetDefaultValue (typeof (string), true);
102 return toString (thisObj);
104 return Convert.ToString (val);