Skip to content

Commit 8b5d0df

Browse files
committed
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
1 parent a078eae commit 8b5d0df

File tree

6 files changed

+26
-44
lines changed

6 files changed

+26
-44
lines changed

CefSharp.Example/BoundObject.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,15 @@ public SubBoundObject GetSubObject()
279279
/// <param name="args">Params Argument</param>
280280
public string MethodWithParams(string name, params object[] args)
281281
{
282-
return String.Join(", ", args.ToArray());
282+
return "Name:" + name + ";Args:" + string.Join(", ", args.ToArray());
283283
}
284284

285285
public string MethodWithoutParams(string name, string arg2)
286286
{
287-
return String.Format("{0}, {1}", name, arg2);
287+
return string.Format("{0}, {1}", name, arg2);
288288
}
289289

290-
public string methodWithoutAnything()
290+
public string MethodWithoutAnything()
291291
{
292292
return "Method without anything called and returned successfully.";
293293
}

CefSharp.Example/Resources/BindingTest.html

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -240,31 +240,12 @@
240240
<p>
241241
Javascript function sending variable number of parameters to Bound Object. (ParamArray Test)
242242
<script type="text/javascript">
243-
function invokeParamArrayMethod(func) {
244-
var result = func();
245-
document.getElementById('paramArrayResults').innerHTML = result;
246-
}
243+
document.write(bound.methodWithParams('With 1 Params', 'hello-world') + "<br/>");
244+
document.write(bound.methodWithParams('With 2 Params', 'hello-world', 'chris was here') + "<br/>");
245+
document.write(bound.methodWithParams('With no Params') + "<br/>");
246+
document.write(bound.methodWithoutParams('Normal Method', 'hello') + "<br/>");
247+
document.write(bound.methodWithoutAnything() + "<br/>");
247248
</script>
248-
<ul>
249-
<li style="list-style:none;display:inline-block;">
250-
<button onclick="invokeParamArrayMethod(function(){return bound.methodWithParams('test', 'hello-world')})">With 1 Params</button>
251-
</li>
252-
<li style="list-style:none;display:inline-block;">
253-
<button onclick="invokeParamArrayMethod(function(){return bound.methodWithParams('test', 'hello-world', 'chris was here')})">With 2 Params</button>
254-
</li>
255-
<li style="list-style:none;display:inline-block;">
256-
<button onclick="invokeParamArrayMethod(function(){return bound.methodWithParams('test')})">With no Params</button>
257-
</li>
258-
<li style="list-style:none;display:inline-block;">
259-
<button onclick="invokeParamArrayMethod(function(){return bound.methodWithoutParams('test', 'hello')})">Normal Method</button>
260-
</li>
261-
<li style="list-style:none;display:inline-block;">
262-
<button onclick="invokeParamArrayMethod(function(){return bound.methodWithoutAnything()})">Normal Method No Params</button>
263-
</li>
264-
</ul>
265-
<span>ParamArray Results</span>
266-
<br />
267-
<span id="paramArrayResults"></span>
268249
</p>
269250
</body>
270251
</html>

CefSharp.Example/ScriptedMethodsBoundObject.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//
33
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
44
using System;
5-
using System.Linq;
65

76
namespace CefSharp.Example
87
{

CefSharp/Internals/JavascriptMethod.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ public class JavascriptMethod
3434
[DataMember]
3535
public string JavascriptName { get; set; }
3636

37-
public List<MethodParameter> MethodParameters { get; set; }
37+
/// <summary>
38+
/// Params this method expects
39+
/// </summary>
40+
public List<MethodParameter> Parameters { get; set; }
41+
42+
public bool HasParamArray { get;set; }
3843

3944
/// <summary>
4045
/// Number of Params this function exepects

CefSharp/Internals/JavascriptObjectRepository.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,32 +104,32 @@ public bool TryCallMethod(long objectId, string name, object[] parameters, out o
104104

105105
try
106106
{
107-
//Added param array support. Current implementation support param Object only. 04/04/2016
107+
//Added param array support #1644
108108
var missingParams = method.ParameterCount - parameters.Length;
109109
//CONDITION #1 : Check for parameter count missmatch between the parameters on the javascript function and the
110-
// number of parameters on the bound object method.
110+
// number of parameters on the bound object method. (This is relevant for methods that have default values)
111111
//CONDITION #2 : Check if the bound object method contains a ParamArray as the last parameter on the method signature.
112-
if (missingParams > 0 || method.MethodParameters.LastOrDefault(t => t.IsParamArray) != null)
112+
if (missingParams > 0 || method.HasParamArray)
113113
{
114-
var paramList = new List<object>(method.MethodParameters.Count);
114+
var paramList = new List<object>(method.Parameters.Count);
115115

116116
//Loop through all of the method parameters on the bound object.
117-
for (var i = 0; i < method.MethodParameters.Count; i++)
117+
for (var i = 0; i < method.Parameters.Count; i++)
118118
{
119119
//Attempt to get the javascript function param at the current bound object parameter index.
120120
//If the javascript function param is missing IE: NULL, then add Type.Missing.
121121
//This will allow for default bound object parameters. IE: (string someParameter = "someValue")
122-
object jsParam = parameters.ElementAtOrDefault(i);
123-
if (jsParam == null && !method.MethodParameters[i].IsParamArray)
122+
var jsParam = parameters.ElementAtOrDefault(i);
123+
if (jsParam == null && !method.Parameters[i].IsParamArray)
124124
{
125125
paramList.Add(Type.Missing);
126126
}
127127
//If the method parameter is a paramArray IE: (params Object[] someParameter)
128128
//grab the parameters from the javascript function starting at the current bound object parameter index
129129
//and add create an array that will be passed in as the last bound object method parameter.
130-
else if (method.MethodParameters[i].IsParamArray)
130+
else if (method.Parameters[i].IsParamArray)
131131
{
132-
List<object> convertedParams = new List<object>();
132+
var convertedParams = new List<object>();
133133
for (var s = i; s < parameters.Length; s++)
134134
{
135135
convertedParams.Add(parameters[s]);
@@ -314,12 +314,13 @@ private static JavascriptMethod CreateJavaScriptMethod(MethodInfo methodInfo, bo
314314
jsMethod.JavascriptName = GetJavascriptName(methodInfo.Name, camelCaseJavascriptNames);
315315
jsMethod.Function = methodInfo.Invoke;
316316
jsMethod.ParameterCount = methodInfo.GetParameters().Length;
317-
jsMethod.MethodParameters = methodInfo.GetParameters()
317+
jsMethod.Parameters = methodInfo.GetParameters()
318318
.Select(t => new MethodParameter()
319319
{
320320
IsParamArray = t.GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0
321321
}).ToList();
322-
322+
//Pre compute HasParamArray for a very minor performance gain
323+
jsMethod.HasParamArray = jsMethod.Parameters.LastOrDefault(t => t.IsParamArray) != null;
323324

324325
return jsMethod;
325326
}

NuGet.config

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,5 @@
55
</activePackageSource>
66
<packageSources>
77
<add key="cefsharp-myget" value="https://www.myget.org/F/cefsharp/" />
8-
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
98
</packageSources>
10-
<disabledPackageSources>
11-
<add key="nuget.org" value="true" />
12-
</disabledPackageSources>
139
</configuration>

0 commit comments

Comments
 (0)