-
-
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
Difficulty using Set - members of Jint.Native.JsSet are not public #1979
Comments
Would you like to propose a PR accompanied by tests in public API test project to ensure API promise? |
@lahma Not really. I’m asking how it’s meant to work. Is it expected that the JsSet class is used here? |
Well basically I think there should probably be an API like we have ArrayBuffer: jint/Jint.Tests.PublicInterface/ArrayBufferTests.cs Lines 36 to 37 in 7857b9c
So both |
The way I'm using Jint, the JavaScript being evaluated is dynamically provided at runtime, so I wouldn't be using I've checked out the repo and experimented with it. Even if I change the members of JsSet to public, they are still not visible when I do this:
I'm also having trouble creating instances of classes within the |
Not sure what you are after here..
Listed as supported, where? They would be a huge undertaking, but PRs welcome of course. |
In my first snippet, the Sorry, I was mistaken about the |
I think that if you follow the example I linked how native constructs are being constructed in a PR backed with public tests, that would a great addition. |
I think we're talking at cross purposes here. I understand you see the value in copying the existing patterns for consistency and to add some more code coverage. My concern is that the changes you're suggesting don't seem to help me. They don't make the members visible in my use case. I expected that changing the accessor on Also, more broadly I think that the way I'm using Jint isn't the way you're expecting it to be, based on the tests I see. For example, I see that the NegativeZeroKeyConvertsToPositiveZero test in |
I think it would greatly clarify things if you could submit a PR with test cases you would like to see succeed. You can alter any APIs you need for it to compile of course. |
I'm starting to get frustrated with this repeated discussion about PRs. I will not add a pull request as I don't know what changes are necessary. I am asking for your help! Here is a unit test that roughly demonstrates how I use Jint and expect it to work:
The second
Other code changes I made trying to get this to work:
My priority is to learn:
I am not volunteering to dig through your codebase and try to fix it for you. I'm asking what's actually expected to work. |
Please do understand that when someone asks something to be green and ideal for consumption, it's really hard to understand the usage scenario. Thank you for bringing some code into the table to investigate. I'll try to find some time to dig into this. |
Your test case passes if you remove the |
@lahma Thanks for your help and sorry for the confusion along the way. I think we got there. It seems then all I need to do is avoid using Now that I see a way to get the members of Thanks again! |
Great that this is now sorted. I think that ideally if you have the need to add items on c# side, you would cast to |
That makes sense. The challenge I face is that our product is used by customers who link together separate steps in a flowchart type structure that are evaluated separately. They could put any JavaScript in these and also refer back to the output of previous steps. We don't know in advance what their scripts are going to be so we need a generic enough solution that works in as many cases as possible. For most cases, the outputs of the expression are most likely only going to be re-used in subsequent Jint expressions, although I will need to check to be sure. There might be cases where things are also passed through to C# code. I could still try the casting like you suggest, although I might need to somehow inspect the object at runtime to determine the type it should be cast to. I'm not sure if there would be a dynamic way to achieve that. |
I discovered it’s not possible to cast to JsSet as the class is internal. This does seem to be a slight inconsistency. I have worked around it, though. I’ve made my code charges and written some unit tests. I use .GetType().FullName to check if the result of my expression is a Jint.Native.JsSet. In that one case I no longer call .ToObject() in the result. This allows a set to be reused in a subsequent expression without affecting my application’s existing behaviour for other types. That is the lowest risk of regressions. Thanks again for your help. I’m glad we found a solution. |
Version used
4.0.3
Describe the bug
I'm trying to create a
new Set()
in JavaScript. This creates aJint.Native.JsSet
. I expect to be able to use methods likeadd()
but they all seem to be internal.To Reproduce
I had one expression which returns a
new Set()
and then a subsequent one that attempted to call.add()
on the object that had been returned from the first one. I had been using.ToObject()
on the result of the first expression to get a .NET type, so it was technically aSystem.Dynamic.ExpandoObject
.Expected behavior
I expect the methods Set to be available in a Jint expression.
Additional context
I do see there is a Jint.Native.Set type that seems to expose more of the members that I might have expected. However, I don't want to have to hard-code any special handling of
Set
. It is my understanding that Jint is meant to provide the equivalent APIs of the JavaScript types without any additional handling.The text was updated successfully, but these errors were encountered: