-
-
Notifications
You must be signed in to change notification settings - Fork 560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix interface methods #1638
fix interface methods #1638
Conversation
I'm not familiar with this area so I can't comment on whether the fix itself is appropriate or not. Please use simple loops instead of LINQ as LINQ use much more memory and CPU cycles compared to simple for loops. |
@Genteure , That object is too complicated. So I don't know how to instantiate it.... using System.Linq.Expressions;
namespace Jint.Tests.Runtime.TestClasses
{
public class InterfaceTestModel
{
public string Name { get; set; }
public int Age { get; set; }
public static ISelect<InterfaceTestModel> BuildSelect()
{
var select = new SelectProvider<InterfaceTestModel>();
return select;
}
}
public class SelectProvider<T1> : Select0Provider<ISelect<T1>, T1>, ISelect<T1>
{
public bool Any(Expression<Func<T1, bool>> exp)
{
return true;
}
}
public class Select0Provider<TSelect, T1>
{
public bool Any()
{
return true;
}
}
public class InterfaceTest<TSelect, T1> : ISelect0<TSelect, T1>
{
public bool Any()
{
return true;
}
}
public interface ISelect0 { }
public partial interface ISelect0<TSelect, T1> : ISelect0
{
bool Any();
}
public interface ISelect<T1> : ISelect0<ISelect<T1>, T1>
{
bool Any(Expression<Func<T1, bool>> exp);
}
}
|
@2881099 ,Can you help me see how this thing can be instantiated? I have been unable to reproduce the problem using the following code simulation, I should be instantiating the wrong way [Fact]
public void InterfaceMethodTest()
{
Assert.Equal(true, InterfaceTestModel.BuildSelect().Any());
var engine = new Engine();
engine.SetValue("mySelect", InterfaceTestModel.BuildSelect());
var result = engine.Evaluate("mySelect.any()").IsBoolean();
Assert.Equal(true, result);
} |
Hi @lahma ,Could you please review this PR? Thank you. I don't know why PR Check tasks don't pass to windows tasks, But on my computer, I passed most of the unit tests and failed only a few that involved language and culture. |
@hyzx86 , I provide you the tests. But there is still something unresolved, maybe you should mark diff --git a/Jint.Tests/Runtime/InteropExplicitTypeTests.cs b/Jint.Tests/Runtime/InteropExplicitTypeTests.cs
index eef485018..a5be5e201 100644
--- a/Jint.Tests/Runtime/InteropExplicitTypeTests.cs
+++ b/Jint.Tests/Runtime/InteropExplicitTypeTests.cs
@@ -1,13 +1,23 @@
namespace Jint.Tests.Runtime;
using Jint.Native;
+using Jint.Runtime;
using Jint.Runtime.Interop;
public class InteropExplicitTypeTests
{
- public interface I1
+ public interface I0
+ {
+ string NameI0 { get => "I0.Name"; }
+ string OverloadSuperMethod() => "I0.OverloadSuperMethod()";
+ string SubPropertySuperMethod() => "I0.SubPropertySuperMethod()";
+ }
+
+ public interface I1 : I0
{
string Name { get; }
+ string OverloadSuperMethod(int x) => $"I1.OverloadSuperMethod(int {x})";
+ new string SubPropertySuperMethod => "I1.SubPropertySuperMethod";
}
public class Super
@@ -120,6 +130,42 @@ public class InteropExplicitTypeTests
Assert.Equal(holder.IndexerI1[0].Name, _engine.Evaluate("holder.IndexerI1[0].Name"));
}
+ [Fact]
+ public void CallSuperPropertyFromInterface()
+ {
+ Assert.Equal(holder.I1.NameI0, _engine.Evaluate("holder.I1.NameI0"));
+ }
+
+ [Fact]
+ public void CallOverloadSuperMethod()
+ {
+ Assert.Equal(
+ holder.I1.OverloadSuperMethod(1),
+ _engine.Evaluate("holder.I1.OverloadSuperMethod(1)"));
+ Assert.Equal(
+ holder.I1.OverloadSuperMethod(),
+ _engine.Evaluate("holder.I1.OverloadSuperMethod()"));
+ }
+
+ [Fact]
+ public void CallSubPropertySuperMethod_SubProperty()
+ {
+ Assert.Equal(
+ holder.I1.SubPropertySuperMethod,
+ _engine.Evaluate("holder.I1.SubPropertySuperMethod"));
+ }
+
+ [Fact]
+ public void CallSubPropertySuperMethod_SuperMethod()
+ {
+ var ex = Assert.Throws<JavaScriptException>(() =>
+ {
+ Assert.Equal(
+ holder.I1.SubPropertySuperMethod(),
+ _engine.Evaluate("holder.I1.SubPropertySuperMethod()"));
+ });
+ Assert.Equal("Property 'SubPropertySuperMethod' of object is not a function", ex.Message);
+ }
[Fact]
public void SuperClassFromField()
|
Hi @viruscamp , Thanks for your support , I have done the And all of the |
I wrote the test in Linux, so I wrote interface default methods which won't run in net462. Just copy the 5 methods with body in |
restore InteropExplicitTypeTests changes
@viruscamp I have created a new file as Jint.Tests/Runtime/InterfaceTests.cs I ran the 4 tests you mentioned on my computer and they all passed ,Whether it's net462 or net6.0 |
Jint.Tests/Runtime/InterfaceTests.cs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you like to rename the class to a clearer name like InteropInterfaceExtendTests
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Jint/Native/WeakMap/JsWeakMap.cs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you please remove this change from the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
Hi @lahma ,Could you please review this PR? Thank you. |
Thank you. |
fix #1637