1+ JSIL . MakeStaticClass ( "Microsoft.CSharp.RuntimeBinder.Binder" , true , [ ] , function ( $ ) {
2+ $ . RawMethod ( true , "BinaryOperation" ,
3+ function ( flags , operation , context , argumentInfo ) {
4+ var binder = new $jsilcore . System . Runtime . CompilerServices . CallSiteBinder ( ) ;
5+ if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . Add || operation === $jsilcore . System . Linq . Expressions . ExpressionType . AddChecked ) {
6+ binder . Method = function ( callSite , left , right ) {
7+ return left + right ;
8+ } ;
9+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . And ) {
10+ binder . Method = function ( callSite , left , right ) {
11+ return left & right ;
12+ } ;
13+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . AndAlso ) {
14+ binder . Method = function ( callSite , left , right ) {
15+ return left && right ;
16+ } ;
17+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . Divide ) {
18+ binder . Method = function ( callSite , left , right ) {
19+ return left / right ;
20+ } ;
21+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . Equal ) {
22+ binder . Method = function ( callSite , left , right ) {
23+ return left == right ;
24+ } ;
25+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . ExclusiveOr ) {
26+ binder . Method = function ( callSite , left , right ) {
27+ return left ^ right ;
28+ } ;
29+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . GreaterThan ) {
30+ binder . Method = function ( callSite , left , right ) {
31+ return left > right ;
32+ } ;
33+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . GreaterThanOrEqual ) {
34+ binder . Method = function ( callSite , left , right ) {
35+ return left >= right ;
36+ } ;
37+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . LeftShift ) {
38+ binder . Method = function ( callSite , left , right ) {
39+ return left << right ;
40+ } ;
41+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . LessThan ) {
42+ binder . Method = function ( callSite , left , right ) {
43+ return left < right ;
44+ } ;
45+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . LessThanOrEqual ) {
46+ binder . Method = function ( callSite , left , right ) {
47+ return left <= right ;
48+ } ;
49+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . Modulo ) {
50+ binder . Method = function ( callSite , left , right ) {
51+ return left % right ;
52+ } ;
53+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . Multiply || operation === $jsilcore . System . Linq . Expressions . ExpressionType . MultiplyChecked ) {
54+ binder . Method = function ( callSite , left , right ) {
55+ return left * right ;
56+ } ;
57+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . NotEqual ) {
58+ binder . Method = function ( callSite , left , right ) {
59+ return left != right ;
60+ } ;
61+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . Or ) {
62+ binder . Method = function ( callSite , left , right ) {
63+ return left | right ;
64+ } ;
65+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . OrElse ) {
66+ binder . Method = function ( callSite , left , right ) {
67+ return left || right ;
68+ } ;
69+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . RightShift ) {
70+ binder . Method = function ( callSite , left , right ) {
71+ return left >> right ;
72+ } ;
73+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . Subtract || operation === $jsilcore . System . Linq . Expressions . ExpressionType . SubtractChecked ) {
74+ binder . Method = function ( callSite , left , right ) {
75+ return left - right ;
76+ } ;
77+ } else {
78+ throw new Error ( "Binary operator is not supported." ) ;
79+ }
80+ return binder ;
81+ } ) ;
82+
83+ $ . RawMethod ( true , "Convert" ,
84+ function ( flags , type , context ) {
85+ var binder = new $jsilcore . System . Runtime . CompilerServices . CallSiteBinder ( ) ;
86+ binder . Method = function ( callSite , target ) {
87+ return type . __PublicInterface__ . $Cast ( target ) ;
88+ } ;
89+ return binder ;
90+ } ) ;
91+
92+ $ . RawMethod ( true , "GetIndex" ,
93+ function ( flags , context , argumentInfo ) {
94+ var binder = new $jsilcore . System . Runtime . CompilerServices . CallSiteBinder ( ) ;
95+ var isStaticCall = ( argumentInfo [ 0 ] . Flags & $jsilcore . Microsoft . CSharp . RuntimeBinder . CSharpArgumentInfoFlags . IsStaticType ) > 0 ;
96+ binder . Method = function ( callSite , target ) {
97+ var realTarget = ( isStaticCall ? target . __PublicInterface__ : target ) ;
98+ if ( "get_Item" in realTarget ) {
99+ return realTarget [ "get_Item" ] . apply ( realTarget , Array . prototype . slice . call ( arguments , 2 ) ) ;
100+ } else {
101+ // TODO: Jagged arrays support
102+ if ( arguments . length === 3 ) {
103+ return realTarget [ arguments [ 2 ] ] ;
104+ } else {
105+ throw new Error ( "Cannot use multi-dimensional indexer for object without indexed property." ) ;
106+ }
107+ }
108+ } ;
109+ return binder ;
110+ } ) ;
111+
112+ $ . RawMethod ( true , "GetMember" ,
113+ function ( flags , name , context , argumentInfo ) {
114+ var binder = new $jsilcore . System . Runtime . CompilerServices . CallSiteBinder ( ) ;
115+ var isStaticCall = ( argumentInfo [ 0 ] . Flags & $jsilcore . Microsoft . CSharp . RuntimeBinder . CSharpArgumentInfoFlags . IsStaticType ) > 0 ;
116+ binder . Method = function ( callSite , target ) {
117+ var realTarget = ( isStaticCall ? target . __PublicInterface__ : target ) ;
118+ if ( ( "get_" + name ) in realTarget ) {
119+ return realTarget [ "get_" + name ] ( ) ;
120+ } else {
121+ return realTarget [ name ] ;
122+ }
123+ } ;
124+ return binder ;
125+ } ) ;
126+
127+ $ . RawMethod ( true , "Invoke" ,
128+ function ( flags , context , argumentInfo ) {
129+ var binder = new $jsilcore . System . Runtime . CompilerServices . CallSiteBinder ( ) ;
130+ binder . Method = function ( callSite , target ) {
131+ return target . apply ( null , Array . prototype . slice . call ( arguments , 2 ) ) ;
132+ } ;
133+ return binder ;
134+ } ) ;
135+
136+ $ . RawMethod ( true , "InvokeConstructor" ,
137+ function ( flags , context , argumentInfo ) {
138+ throw new Error ( "Not implemented" ) ;
139+ } ) ;
140+
141+ $ . RawMethod ( true , "InvokeMember" ,
142+ function ( flags , name , typeArguments , context , argumentInfo ) {
143+ var binder = new $jsilcore . System . Runtime . CompilerServices . CallSiteBinder ( ) ;
144+ var isStaticCall = ( argumentInfo [ 0 ] . Flags & $jsilcore . Microsoft . CSharp . RuntimeBinder . CSharpArgumentInfoFlags . IsStaticType ) > 0 ;
145+ if ( typeArguments !== null ) {
146+ var useMemberName = name + "$b" + typeArguments . length ;
147+ binder . Method = function ( callSite , target ) {
148+ var realTarget = ( isStaticCall ? target . __PublicInterface__ : target ) ;
149+ return realTarget [ useMemberName ] . apply ( realTarget , typeArguments ) . apply ( realTarget , Array . prototype . slice . call ( arguments , 2 ) ) ;
150+ } ;
151+ } else {
152+ binder . Method = function ( callSite , target ) {
153+ var realTarget = ( isStaticCall ? target . __PublicInterface__ : target ) ;
154+ return realTarget [ name ] . apply ( realTarget , Array . prototype . slice . call ( arguments , 2 ) ) ;
155+ } ;
156+ }
157+ return binder ;
158+ } ) ;
159+
160+ $ . RawMethod ( true , "IsEvent" ,
161+ function ( flags , name , context ) {
162+ var binder = new $jsilcore . System . Runtime . CompilerServices . CallSiteBinder ( ) ;
163+ binder . Method = function ( ) {
164+ return false ;
165+ } ;
166+ return binder ;
167+ } ) ;
168+
169+ $ . RawMethod ( true , "SetIndex" ,
170+ function ( flags , context , argumentInfo ) {
171+ var binder = new $jsilcore . System . Runtime . CompilerServices . CallSiteBinder ( ) ;
172+ var isStaticCall = ( argumentInfo [ 0 ] . Flags & $jsilcore . Microsoft . CSharp . RuntimeBinder . CSharpArgumentInfoFlags . IsStaticType ) > 0 ;
173+ binder . Method = function ( callSite , target ) {
174+ var realTarget = ( isStaticCall ? target . __PublicInterface__ : target ) ;
175+ if ( "set_Item" in realTarget ) {
176+ return realTarget [ "set_Item" ] . apply ( realTarget , Array . prototype . slice . call ( arguments , 2 ) ) ;
177+ } else {
178+ // TODO: Jagged arrays support
179+ if ( arguments . length === 4 ) {
180+ realTarget [ arguments [ 2 ] ] = arguments [ 3 ] ;
181+ } else {
182+ throw new Error ( "Cannot use multi-dimensional indexer for object without indexed property." ) ;
183+ }
184+ }
185+ } ;
186+ return binder ;
187+ } ) ;
188+
189+ $ . RawMethod ( true , "SetMember" ,
190+ function ( flags , name , context , argumentInfo ) {
191+ var binder = new $jsilcore . System . Runtime . CompilerServices . CallSiteBinder ( ) ;
192+ var isStaticCall = ( argumentInfo [ 0 ] . Flags & $jsilcore . Microsoft . CSharp . RuntimeBinder . CSharpArgumentInfoFlags . IsStaticType ) > 0 ;
193+ binder . Method = function ( callSite , target , value ) {
194+ var realTarget = ( isStaticCall ? target . __PublicInterface__ : target ) ;
195+ if ( ( "set_" + name ) in realTarget ) {
196+ return realTarget [ "set_" + name ] ( value ) ;
197+ } else {
198+ realTarget [ name ] = value ;
199+ }
200+ } ;
201+ return binder ;
202+ } ) ;
203+
204+ $ . RawMethod ( true , "UnaryOperation" ,
205+ function ( flags , operation , context , argumentInfo ) {
206+ var binder = new $jsilcore . System . Runtime . CompilerServices . CallSiteBinder ( ) ;
207+ if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . UnaryPlus ) {
208+ binder . Method = function ( callSite , target ) {
209+ return target ;
210+ } ;
211+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . Negate || operation === $jsilcore . System . Linq . Expressions . ExpressionType . NegateChecked ) {
212+ binder . Method = function ( callSite , target ) {
213+ return - target ;
214+ } ;
215+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . Not ) {
216+ binder . Method = function ( callSite , target ) {
217+ if ( typeof ( target ) === "boolean" ) {
218+ return ~ target ;
219+ }
220+ return ~ target ;
221+ } ;
222+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . IsTrue ) {
223+ binder . Method = function ( callSite , target ) {
224+ return target === true ;
225+ } ;
226+ } else if ( operation === $jsilcore . System . Linq . Expressions . ExpressionType . IsFalse ) {
227+ binder . Method = function ( callSite , target ) {
228+ return target === false ;
229+ } ;
230+ } else {
231+ throw new Error ( "Unary operator is not supported." ) ;
232+ }
233+ return binder ;
234+ } ) ;
235+ } ) ;
0 commit comments