-
-
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
Make JsSet public #1987
Make JsSet public #1987
Conversation
Jint/Native/JsSet.cs
Outdated
|
||
internal bool SetDelete(JsValue key) => _set.Remove(key); | ||
public bool SetDelete(JsValue key) => _set.Remove(key); |
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.
Remove
(which should be Delete
) already handles this so can be removed altogether.
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.
I kept this name for now given that "Delete" is inherited. Alternatively I could use new
to hide the inherited version although I think that's generally discouraged.
Jint/Native/JsSet.cs
Outdated
@@ -73,7 +73,7 @@ internal void ForEach(ICallable callable, JsValue thisArg) | |||
_engine._jsValueArrayPool.ReturnArray(args); | |||
} | |||
|
|||
internal ObjectInstance Entries() => _engine.Realm.Intrinsics.SetIteratorPrototype.ConstructEntryIterator(this); | |||
public ObjectInstance Entries() => _engine.Realm.Intrinsics.SetIteratorPrototype.ConstructEntryIterator(this); |
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.
Are Entries
and Values
really needed, they don't expose meaningful API outside of Jint's logic at the moment?
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.
No, right enough. They're not really needed elsewhere.
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.
Changed back to internal.
Jint/Runtime/OrderedSet.cs
Outdated
@@ -1,6 +1,6 @@ | |||
namespace Jint.Runtime; | |||
|
|||
internal sealed class OrderedSet<T> | |||
public sealed class OrderedSet<T> |
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.
I think this can remain as internal
, unfortunate need for JS usage where they come up with oddities
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.
So SetConstructor
would handle all constructor requirements and JsSet
constructor should be internal, like I indicated in earlier discussion, SetConstructor.Construct()
would have the needed overloads
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.
Unfortunately, I wasn't able to compile without this change. I think the alternative would be to downgrade the JsSet
constructor that uses it to also be internal
. This could potentially be a breaking change as I don't know where all it is used.
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.
I was able to revert this by changing the affected JsSet constructor to internal. Hopefully that doesn't break something elsewhere. I only see it used by SetPrototype.
Jint/Native/JsSet.cs
Outdated
|
||
internal void Remove(JsValue value) => _set.Remove(value); | ||
public void Remove(JsValue value) => _set.Remove(value); |
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.
I think this should be just plain Delete
, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
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.
You mean rename the method itself to Delete(JsValue value)
? Given that it was previously internal, am I safe to assume that all existing consumers that could break as a result are in the same repo? Hopefully refactoring it globally is adequate.
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, so I see it's only used in SetPrototype, however I wonder if the name "SetDelete" was used to avoid conflicting with ObjectInstance.Delete() which would attempt to delete a property by that name from the object (presumably like javascript's delete foo.bar
) whereas we're wanting mySet.delete("abc")
to take a value out of the set.
Jint/Native/JsSet.cs
Outdated
|
||
internal void ForEach(ICallable callable, JsValue thisArg) | ||
public void ForEach(ICallable callable, JsValue thisArg) |
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.
Maybe better keep this internal, very JS spec specific and not a natural c# API
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. This also eliminates a warning I was getting because ICallable
is internal
.
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.
I did small adjustments and a public API test to show usage (and ensure API will be kept), did a 180 and went with the Remove
method name as SetDelete
felt too clunky...
Thanks for iterating a publishing the API! |
In #1988 I did another 180 and came to conclusion that in this case the |
namespace Jint.Runtime; | ||
|
||
internal sealed class OrderedSet<T> | ||
internal sealed class OrderedSet<T> : IEnumerable<T> | ||
{ | ||
internal List<T> _list; |
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.
OrderedDictionary<T, T> has been added recently, or is it soon? https://learn.microsoft.com/en-us/dotnet/api/system.collections.specialized.ordereddictionary?view=net-8.0
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.
The generic version ( https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.ordereddictionary-2 ) has been added NET 9, maybe not yet worth to add another TFM just for that..
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.
That's what was confusing me then. I knew the generic one was added to 9, but on the docs it said 2,3....9. I was pointing to the wrong one. It all makes sense and I agree not worth it if just for 9.
Thanks for finishing this. I've upgraded to Jint 4.1.0 and these changes are really helpful. |
Allow use of the
Jint.Native.JsSet
class outside of expressions, allowing consumers to cast to this type and call its members.For example, you might want to convert it to a
HashSet<T>
to use it elsewhere without being tied to using Jint types.The
OrderedSet
class also had to be madepublic
due to its use in theJsSet
constructor.