-
-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
namespace Jint.Native; | ||
|
||
internal sealed class JsSet : ObjectInstance | ||
public sealed class JsSet : ObjectInstance | ||
{ | ||
internal readonly OrderedSet<JsValue> _set; | ||
|
||
|
@@ -47,17 +47,17 @@ protected override bool TryGetProperty(JsValue property, [NotNullWhen(true)] out | |
return base.TryGetProperty(property, out descriptor); | ||
} | ||
|
||
internal void Add(JsValue value) => _set.Add(value); | ||
public void Add(JsValue value) => _set.Add(value); | ||
|
||
internal void Remove(JsValue value) => _set.Remove(value); | ||
public void Remove(JsValue value) => _set.Remove(value); | ||
|
||
internal void Clear() => _set.Clear(); | ||
public void Clear() => _set.Clear(); | ||
|
||
internal bool Has(JsValue key) => _set.Contains(key); | ||
public bool Has(JsValue key) => _set.Contains(key); | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done. This also eliminates a warning I was getting because |
||
{ | ||
var args = _engine._jsValueArrayPool.RentArray(3); | ||
args[2] = this; | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Are There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Changed back to internal. |
||
|
||
internal ObjectInstance Values() => _engine.Realm.Intrinsics.SetIteratorPrototype.ConstructValueIterator(this); | ||
public ObjectInstance Values() => _engine.Realm.Intrinsics.SetIteratorPrototype.ConstructValueIterator(this); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. I think this can remain as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
{ | ||
internal List<T> _list; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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. |
||
internal HashSet<T> _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.
I think this should be just plain
Delete
, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SetThere 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 wantingmySet.delete("abc")
to take a value out of the set.