From 669404f74cf61d8bc5b32c2ed86b87c71adfac34 Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 5 Apr 2016 16:19:55 +1000 Subject: [PATCH] Change new paramAray test methods in BindingTest.html to execute immediately (same as all the majority) Revert changes to NuGet.config Remove unused using statement from ScriptedMethodsBoundObject Rename JavascriptMethod.Parameters to just JavascriptMethod.Parameters (it's in the context of the method so naming was redundant) Pre compute HasParamArray for minor (very minor) performance improvement - relevant when executing method many times in a tight loop --- CefSharp.Example/BoundObject.cs | 6 ++-- CefSharp.Example/Resources/BindingTest.html | 29 ++++--------------- .../ScriptedMethodsBoundObject.cs | 1 - CefSharp/Internals/JavascriptMethod.cs | 7 ++++- .../Internals/JavascriptObjectRepository.cs | 23 ++++++++------- NuGet.config | 4 --- 6 files changed, 26 insertions(+), 44 deletions(-) diff --git a/CefSharp.Example/BoundObject.cs b/CefSharp.Example/BoundObject.cs index c5d0656be..e34f29026 100644 --- a/CefSharp.Example/BoundObject.cs +++ b/CefSharp.Example/BoundObject.cs @@ -279,15 +279,15 @@ namespace CefSharp.Example /// Params Argument public string MethodWithParams(string name, params object[] args) { - return String.Join(", ", args.ToArray()); + return "Name:" + name + ";Args:" + string.Join(", ", args.ToArray()); } public string MethodWithoutParams(string name, string arg2) { - return String.Format("{0}, {1}", name, arg2); + return string.Format("{0}, {1}", name, arg2); } - public string methodWithoutAnything() + public string MethodWithoutAnything() { return "Method without anything called and returned successfully."; } diff --git a/CefSharp.Example/Resources/BindingTest.html b/CefSharp.Example/Resources/BindingTest.html index c08a017da..4a5866c3a 100644 --- a/CefSharp.Example/Resources/BindingTest.html +++ b/CefSharp.Example/Resources/BindingTest.html @@ -240,31 +240,12 @@

Javascript function sending variable number of parameters to Bound Object. (ParamArray Test) -

- ParamArray Results -
-

diff --git a/CefSharp.Example/ScriptedMethodsBoundObject.cs b/CefSharp.Example/ScriptedMethodsBoundObject.cs index 453cc6e93..406e0131d 100644 --- a/CefSharp.Example/ScriptedMethodsBoundObject.cs +++ b/CefSharp.Example/ScriptedMethodsBoundObject.cs @@ -2,7 +2,6 @@ // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. using System; -using System.Linq; namespace CefSharp.Example { diff --git a/CefSharp/Internals/JavascriptMethod.cs b/CefSharp/Internals/JavascriptMethod.cs index 5028dcb22..deb45a580 100644 --- a/CefSharp/Internals/JavascriptMethod.cs +++ b/CefSharp/Internals/JavascriptMethod.cs @@ -34,7 +34,12 @@ namespace CefSharp.Internals [DataMember] public string JavascriptName { get; set; } - public List MethodParameters { get; set; } + /// + /// Params this method expects + /// + public List Parameters { get; set; } + + public bool HasParamArray { get;set; } /// /// Number of Params this function exepects diff --git a/CefSharp/Internals/JavascriptObjectRepository.cs b/CefSharp/Internals/JavascriptObjectRepository.cs index 6aa310c77..6e89659e1 100644 --- a/CefSharp/Internals/JavascriptObjectRepository.cs +++ b/CefSharp/Internals/JavascriptObjectRepository.cs @@ -104,32 +104,32 @@ namespace CefSharp.Internals try { - //Added param array support. Current implementation support param Object only. 04/04/2016 + //Added param array support #1644 var missingParams = method.ParameterCount - parameters.Length; //CONDITION #1 : Check for parameter count missmatch between the parameters on the javascript function and the - // number of parameters on the bound object method. + // number of parameters on the bound object method. (This is relevant for methods that have default values) //CONDITION #2 : Check if the bound object method contains a ParamArray as the last parameter on the method signature. - if (missingParams > 0 || method.MethodParameters.LastOrDefault(t => t.IsParamArray) != null) + if (missingParams > 0 || method.HasParamArray) { - var paramList = new List(method.MethodParameters.Count); + var paramList = new List(method.Parameters.Count); //Loop through all of the method parameters on the bound object. - for (var i = 0; i < method.MethodParameters.Count; i++) + for (var i = 0; i < method.Parameters.Count; i++) { //Attempt to get the javascript function param at the current bound object parameter index. //If the javascript function param is missing IE: NULL, then add Type.Missing. //This will allow for default bound object parameters. IE: (string someParameter = "someValue") - object jsParam = parameters.ElementAtOrDefault(i); - if (jsParam == null && !method.MethodParameters[i].IsParamArray) + var jsParam = parameters.ElementAtOrDefault(i); + if (jsParam == null && !method.Parameters[i].IsParamArray) { paramList.Add(Type.Missing); } //If the method parameter is a paramArray IE: (params Object[] someParameter) //grab the parameters from the javascript function starting at the current bound object parameter index //and add create an array that will be passed in as the last bound object method parameter. - else if (method.MethodParameters[i].IsParamArray) + else if (method.Parameters[i].IsParamArray) { - List convertedParams = new List(); + var convertedParams = new List(); for (var s = i; s < parameters.Length; s++) { convertedParams.Add(parameters[s]); @@ -314,12 +314,13 @@ namespace CefSharp.Internals jsMethod.JavascriptName = GetJavascriptName(methodInfo.Name, camelCaseJavascriptNames); jsMethod.Function = methodInfo.Invoke; jsMethod.ParameterCount = methodInfo.GetParameters().Length; - jsMethod.MethodParameters = methodInfo.GetParameters() + jsMethod.Parameters = methodInfo.GetParameters() .Select(t => new MethodParameter() { IsParamArray = t.GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0 }).ToList(); - + //Pre compute HasParamArray for a very minor performance gain + jsMethod.HasParamArray = jsMethod.Parameters.LastOrDefault(t => t.IsParamArray) != null; return jsMethod; } diff --git a/NuGet.config b/NuGet.config index 8d4d26dc0..631795137 100644 --- a/NuGet.config +++ b/NuGet.config @@ -5,9 +5,5 @@ - - - - \ No newline at end of file