@@ -140,7 +140,8 @@ class PolymodInterpEx extends Interp
140140 // Force call super function.
141141 return super .fcall (o , ' __super_ ${f }' , args );
142142 }
143- else if (Std .isOfType (o , PolymodStaticClassReference )) {
143+ else if (Std .isOfType (o , PolymodStaticClassReference ))
144+ {
144145 var ref : PolymodStaticClassReference = cast (o , PolymodStaticClassReference );
145146
146147 return ref .callFunction (f , args );
@@ -153,50 +154,60 @@ class PolymodInterpEx extends Interp
153154 }
154155
155156 var func = get (o , f );
157+ if (func != null )
158+ {
159+ return call (o , func , args );
160+ }
156161
157162 @:privateAccess
163+ if (_proxy != null && _proxy ._cachedUsingFunctions .exists (f ))
164+ {
165+ return _proxy ._cachedUsingFunctions [f ]([o ].concat (args ));
166+ }
167+ else if (_classDeclOverride != null )
158168 {
159- if (func == null && _proxy != null && _proxy ._cachedUsingFunctions .exists (f ))
169+ // TODO: Optimize with a cache
170+ var usingFuncs : Map <String , Array <Dynamic >-> Dynamic > = [];
171+ PolymodScriptClass .buildExtensionFunctionCache (_classDeclOverride , usingFuncs );
172+
173+ if (usingFuncs .exists (f ))
160174 {
161- return _proxy . _cachedUsingFunctions [f ]([o ].concat (args ));
175+ return usingFuncs [f ]([o ].concat (args ));
162176 }
163177 }
164178
165179 #if html5
166180 // Workaround for an HTML5-specific issue.
167181 // https://github.com/HaxeFoundation/haxe/issues/11298
168- if (func == null && f == " contains" ) {
182+ if (f == " contains" )
183+ {
169184 func = get (o , " includes" );
170185 }
171-
172186 // For web: remove is inlined so we have to use something else.
173- if (func == null && f == " remove" )
187+ else if (f == " remove" )
174188 {
175189 @:privateAccess
176190 return HxOverrides .remove (cast o , args [0 ]);
177191 }
178192 #end
179193
180- if (func == null )
194+ if (Std . isOfType ( o , HScriptedClass ) )
181195 {
182- if (Std .isOfType (o , HScriptedClass ))
196+ // This is a scripted class!
197+ // We should try to call the function on the scripted class.
198+ // If it doesn't exist, `asc.callFunction()` will handle generating an error message.
199+ if (o .scriptCall != null )
183200 {
184- // This is a scripted class!
185- // We should try to call the function on the scripted class.
186- // If it doesn't exist, `asc.callFunction()` will handle generating an error message.
187- if (o .scriptCall != null ) {
188- return o .scriptCall (f , args );
189- }
190-
191- errorEx (EInvalidScriptedFnAccess (f ));
192- }
193- else
194- {
195- // Throw an error for a missing function.
196- errorEx (EInvalidAccess (f ));
201+ return o .scriptCall (f , args );
197202 }
203+
204+ return errorEx (EInvalidScriptedFnAccess (f ));
205+ }
206+ else
207+ {
208+ // Throw an error for a missing function.
209+ return errorEx (EInvalidAccess (f ));
198210 }
199- return call (o , func , args );
200211 }
201212
202213 private static var _scriptClassDescriptors : Map <String , PolymodClassDeclEx > = new Map <String , PolymodClassDeclEx >();
0 commit comments