Switch to compiler-tester
[mono.git] / mcs / class / Microsoft.JScript / Microsoft.JScript / LateBinding.cs
1 //
2 // LateBinding.cs:
3 //
4 // Author:
5 //      Cesar Lopez Nataren (cesar@ciencias.unam.mx)
6 //
7 // (C) 2003, Cesar Lopez Nataren
8 // (C) 2005, Novell Inc, (http://novell.com)
9 //
10
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 using System;
33 using System.Reflection;
34 using System.Diagnostics;
35 using Microsoft.JScript.Vsa;
36 using System.Collections;
37
38 namespace Microsoft.JScript {
39
40         public sealed class LateBinding {
41
42                 public object obj;
43                 private static BindingFlags bind_flags = BindingFlags.Public;
44                 private string right_hand_side;
45                         
46                 public LateBinding (string name)
47                 {
48                         this.right_hand_side = name;
49                 }
50
51
52                 public LateBinding (string name, object obj)
53                 {
54                         throw new NotImplementedException ();
55                 }
56
57
58                 [DebuggerStepThroughAttribute]
59                 [DebuggerHiddenAttribute]
60                 public object Call (object [] arguments, bool construct, bool brackets,
61                                     VsaEngine engine)
62                 {
63                         if (construct) {
64                                 if (brackets) {                                 
65                                 } else {
66                                 }
67                         } else {
68                                 if (brackets) {
69                                 } else {
70                                         Type type = null;
71
72                                         if (obj is JSObject)
73                                                 type = SemanticAnalyser.map_to_prototype ((JSObject) obj);
74
75                                         MethodInfo method = type.GetMethod (right_hand_side, BindingFlags.Public | BindingFlags.Static);
76                                         object [] args = build_args (arguments, engine);
77                                         return method.Invoke (type, args);
78                                 }
79                         }
80                         throw new NotImplementedException ();
81                 }
82
83                 private object [] build_args (object [] arguments, VsaEngine engine)
84                 {
85                         ArrayList args = new ArrayList ();
86                         if (obj != null)
87                                 args.Add (obj);
88                         if (engine != null)
89                                 args.Add (engine);
90                         foreach (object o in arguments)
91                                 args.Add (o);
92                         return args.ToArray ();
93                 }
94                 
95                 [DebuggerStepThroughAttribute]
96                 [DebuggerHiddenAttribute]
97                 public static object CallValue (object thisObj, object val, object [] arguments,
98                                                 bool construct, bool brackets, VsaEngine engine)
99                 {
100                         if (construct) {
101                                 if (brackets) {
102                                         return null;
103                                 } 
104                                 return null;
105                         } else if (brackets) {
106                                 if (!(val is JSObject))
107                                         throw new Exception ("val has to be a JSObject");
108
109                                 JSObject js_val = (JSObject) val;
110                                 object res = js_val.GetField (Convert.ToString (arguments [0]));
111                                 if (res is JSFieldInfo) 
112                                         return ((JSFieldInfo) res).GetValue (arguments [0]);
113                                 else 
114                                         throw new NotImplementedException ();
115                         } else {
116                                 return null;
117                         }
118                 }
119
120                 [DebuggerStepThroughAttribute]
121                 [DebuggerHiddenAttribute]
122                 public static object CallValue2 (object val, object thisObj, object [] arguments,
123                                                  bool construct, bool brackets, VsaEngine engine)
124                 {
125                         throw new NotImplementedException ();
126                 }
127
128
129                 public bool Delete ()
130                 {
131                         throw new NotImplementedException ();
132                 }
133
134
135                 public static bool DeleteMember (object obj, string name)
136                 {
137                         throw new NotImplementedException ();
138                 }
139
140                 [DebuggerStepThroughAttribute]
141                 [DebuggerHiddenAttribute]
142                 public object GetNonMissingValue ()
143                 {
144                         Type type = obj.GetType ();
145                         MemberInfo [] members = type.GetMember (right_hand_side);
146                         if (members.Length > 0) {
147                                 MemberInfo member = members [0];
148                                 MemberTypes member_type = member.MemberType;
149
150                                 switch (member_type) {
151                                 case MemberTypes.Property:
152                                         MethodInfo method = ((PropertyInfo) member).GetGetMethod ();
153                                         return method.Invoke (obj, new object [] {});
154                                 }
155                         }
156                         throw new NotImplementedException ();
157                 }
158
159                 [DebuggerStepThroughAttribute]
160                 [DebuggerHiddenAttribute]
161                 public object GetValue2 ()
162                 {
163                         throw new NotImplementedException ();
164                 }
165
166                 [DebuggerStepThroughAttribute]
167                 [DebuggerHiddenAttribute]
168                 public static void SetIndexedPropertyValueStatic (object obj, object [] arguments,
169                                                                   object value)
170                 {
171                         if (!(obj is JSObject))
172                                 throw new Exception ("obj should be a JSObject");
173
174                         JSObject js_obj = (JSObject) obj;
175                         foreach (object o in arguments)
176                                 js_obj.AddField (o, value);
177                 }
178
179                 [DebuggerStepThroughAttribute]
180                 [DebuggerHiddenAttribute]
181                 public void SetValue (object value)
182                 {
183                         throw new NotImplementedException ();
184                 }
185         }
186 }