|
@@ -494,7 +494,7 @@ namespace Jint.Runtime
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static IEnumerable<Tuple<MethodBase, JsValue[]>> FindBestMatch<T>(T[] methods, Func<T, bool, JsValue[]> argumentProvider) where T : MethodBase
|
|
|
+ public static IEnumerable<Tuple<MethodBase, JsValue[]>> FindBestMatch<T>(Engine engine, T[] methods, Func<T, bool, JsValue[]> argumentProvider) where T : MethodBase
|
|
|
{
|
|
|
System.Collections.Generic.List<Tuple<T, JsValue[]>> matchingByParameterCount = null;
|
|
|
foreach (var m in methods)
|
|
@@ -522,6 +522,31 @@ namespace Jint.Runtime
|
|
|
matchingByParameterCount = matchingByParameterCount ?? new System.Collections.Generic.List<Tuple<T, JsValue[]>>();
|
|
|
matchingByParameterCount.Add(new Tuple<T, JsValue[]>(m, arguments));
|
|
|
}
|
|
|
+ else if (parameterInfos.Length > arguments.Length)
|
|
|
+ {
|
|
|
+ // check if we got enough default values to provide all parameters (or more in case some default values are provided/overwritten)
|
|
|
+ var defaultValuesCount = 0;
|
|
|
+ foreach (var param in parameterInfos)
|
|
|
+ {
|
|
|
+ if (param.HasDefaultValue) defaultValuesCount++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (parameterInfos.Length <= arguments.Length + defaultValuesCount)
|
|
|
+ {
|
|
|
+ // create missing arguments from default values
|
|
|
+
|
|
|
+ var argsWithDefaults = new System.Collections.Generic.List<JsValue>(arguments);
|
|
|
+ for (var i = arguments.Length; i < parameterInfos.Length; i++)
|
|
|
+ {
|
|
|
+ var param = parameterInfos[i];
|
|
|
+ var value = JsValue.FromObject(engine, param.DefaultValue);
|
|
|
+ argsWithDefaults.Add(value);
|
|
|
+ }
|
|
|
+
|
|
|
+ matchingByParameterCount = matchingByParameterCount ?? new System.Collections.Generic.List<Tuple<T, JsValue[]>>();
|
|
|
+ matchingByParameterCount.Add(new Tuple<T, JsValue[]>(m, argsWithDefaults.ToArray()));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (matchingByParameterCount == null)
|