-
-
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
Add support for wrapped lists to push and pop items #1822
Conversation
Jint doesn't automatically attach array prototype when wrapping objects (same as with STJ). Here's a good example which it would a bad decision by default. JS expects that you can index outside of collection size to create a new entry. Probably a custom |
Hmm... I guess that is kind of confusing that it implements things like |
IndexOf is a List method, it doesn't need JS array prototype |
Hmm... yeah, I guess a lot of the JS Array methods line up with the list methods. I tried what you said and it didn't work either. [Fact]
public void ArrayPrototypePushWithInteropList()
{
var engine = new Jint.Engine(options =>
{
// make List behave like JS array
options.Interop.WrapObjectHandler = static (e, target, type) =>
{
if (target is IList)
{
var wrapped = ObjectWrapper.Create(e, target);
wrapped.Prototype = e.Intrinsics.Array.PrototypeObject;
return wrapped;
}
return ObjectWrapper.Create(e, target);
};
});
engine.SetValue("list", new List<string> { "A", "B", "C" });
engine.Evaluate("list.push('D')");
Assert.Equal(3, engine.Evaluate("list.lastIndexOf('D')"));
} |
You probably need to implement something custom deriving from ObjectWrapper which would intercept problematic calls. |
|
This seems like something that should work out of the box. Do you agree with that or is against the direction you want to go with the project? I am going to investigate more and try and figure out the correct spot to implement this. The code is quite complex so trying to figure out the correct way to implement it will probably take some time. I'd be willing to send some sponsor money your way to either give me a tour of the code and point me in the right direction or if you just want to implement yourself. |
Kept digging and found a way that I think might be acceptable to get |
3979170
to
c877dfc
Compare
Updated. Thanks for the feedback! |
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.
Thank you!
No, thank you! |
Test that is showing that trying to push to an interop list does not work. Should this work? Is there some rule that I'm not aware of that is trying to keep interop to read only operations?