Skip to content

Commit f6d6d7b

Browse files
committed
In JavaScriptEngineSwitcher.ChakraCore fixed a error, that occurred during finding a suitable method overload, that receives interfaces as parameters, of the host object
1 parent 0f3c714 commit f6d6d7b

File tree

8 files changed

+81
-13
lines changed

8 files changed

+81
-13
lines changed

NuGet/JavaScriptEngineSwitcher.ChakraCore/JavaScriptEngineSwitcher.ChakraCore.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This package does not contain the native implementations of ChakraCore. Therefor
2020
* JavaScriptEngineSwitcher.ChakraCore.Native.linux-x64
2121
* JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64</description>
2222
<summary>JavaScriptEngineSwitcher.ChakraCore contains adapter `ChakraCoreJsEngine` (wrapper for the ChakraCore).</summary>
23-
<releaseNotes>Fixed a error, that occurred during finding a suitable method overload, that receives numeric parameters, of the host object.</releaseNotes>
23+
<releaseNotes>Fixed a error, that occurred during finding the suitable method overload, that receives numeric values and interfaces as parameters, of the host object.</releaseNotes>
2424
<copyright>Copyright (c) 2013-2017 Andrey Taritsyn - http://www.taritsyn.ru</copyright>
2525
<language>en-US</language>
2626
<tags>JavaScriptEngineSwitcher JavaScript ECMAScript ChakraCore</tags>

NuGet/JavaScriptEngineSwitcher.ChakraCore/readme.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
=============
3131
RELEASE NOTES
3232
=============
33-
Fixed a error, that occurred during finding a suitable method overload, that
34-
receives numeric parameters, of the host object.
33+
Fixed a error, that occurred during finding the suitable method overload, that
34+
receives numeric values and interfaces as parameters, of the host object.
3535

3636
=============
3737
DOCUMENTATION

src/JavaScriptEngineSwitcher.ChakraCore/Helpers/ReflectionHelpers.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,16 @@ private static bool CompareParameterTypes(object[] argValues, Type[] argTypes, T
169169
}
170170
else
171171
{
172-
if (NumericHelpers.IsNumericType(argType) && NumericHelpers.IsNumericType(parameterType))
173-
{
174-
object convertedArgValue;
175-
176-
if (!TypeConverter.TryConvertToType(argValue, parameterType, out convertedArgValue))
177-
{
178-
return false;
179-
}
172+
// TODO: It is necessary to calculate the compatibility score based on length
173+
// of inheritance and interface implementation chains.
174+
object convertedArgValue;
180175

181-
continue;
176+
if (!TypeConverter.TryConvertToType(argValue, parameterType, out convertedArgValue))
177+
{
178+
return false;
182179
}
183180

184-
return false;
181+
continue;
185182
}
186183
}
187184

@@ -203,6 +200,7 @@ public Type[] ParameterTypes
203200
set;
204201
}
205202

203+
/// TODO: In future will need to change type to <code>double</code>
206204
public ushort CompatibilityScore
207205
{
208206
get;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace JavaScriptEngineSwitcher.Tests.Interop.Animals
2+
{
3+
public sealed class AnimalTrainer
4+
{
5+
public string ExecuteVoiceCommand(IAnimal animal)
6+
{
7+
return animal.Cry();
8+
}
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace JavaScriptEngineSwitcher.Tests.Interop.Animals
2+
{
3+
public sealed class Cat : IAnimal
4+
{
5+
public string Cry()
6+
{
7+
return "Meow!";
8+
}
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace JavaScriptEngineSwitcher.Tests.Interop.Animals
2+
{
3+
public sealed class Dog : IAnimal
4+
{
5+
public string Cry()
6+
{
7+
return "Woof!";
8+
}
9+
}
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace JavaScriptEngineSwitcher.Tests.Interop.Animals
2+
{
3+
public interface IAnimal
4+
{
5+
string Cry();
6+
}
7+
}

test/JavaScriptEngineSwitcher.Tests/InteropTestsBase.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Xunit;
1010

1111
using JavaScriptEngineSwitcher.Tests.Interop;
12+
using JavaScriptEngineSwitcher.Tests.Interop.Animals;
1213
#if NETCOREAPP1_0
1314
using JavaScriptEngineSwitcher.Tests.Interop.Drawing;
1415
#endif
@@ -353,6 +354,38 @@ public virtual void EmbeddingOfInstanceOfCustomReferenceTypeWithMethodIsCorrect(
353354
Assert.Equal(targetOutput, output);
354355
}
355356

357+
[Fact]
358+
public virtual void CallingOfMethodOfCustomReferenceTypeWithInterfaceParameterIsCorrect()
359+
{
360+
// Arrange
361+
var animalTrainer = new AnimalTrainer();
362+
var cat = new Cat();
363+
var dog = new Dog();
364+
365+
const string input1 = "animalTrainer.ExecuteVoiceCommand(cat)";
366+
const string targetOutput1 = "Meow!";
367+
368+
const string input2 = "animalTrainer.ExecuteVoiceCommand(dog)";
369+
const string targetOutput2 = "Woof!";
370+
371+
// Act
372+
string output1;
373+
string output2;
374+
375+
using (var jsEngine = CreateJsEngine())
376+
{
377+
jsEngine.EmbedHostObject("animalTrainer", animalTrainer);
378+
jsEngine.EmbedHostObject("cat", cat);
379+
jsEngine.EmbedHostObject("dog", dog);
380+
output1 = jsEngine.Evaluate<string>(input1);
381+
output2 = jsEngine.Evaluate<string>(input2);
382+
}
383+
384+
// Assert
385+
Assert.Equal(targetOutput1, output1);
386+
Assert.Equal(targetOutput2, output2);
387+
}
388+
356389
#endregion
357390

358391
#region Delegates

0 commit comments

Comments
 (0)