Skip to content
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

Implement Set Methods for JavaScript #1741

Merged
merged 7 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Jint.Tests.Test262/Test262Harness.settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"SuiteGitSha": "2060494f280ba89d71a0f51d4ff171bafe476a05",
"SuiteGitSha": "a1ba783ca340e4bf3d80b5f5e11fa54f2ee5f1ef",
//"SuiteDirectory": "//mnt/c/work/test262",
"TargetPath": "./Generated",
"Namespace": "Jint.Tests.Test262",
Expand Down Expand Up @@ -84,6 +84,11 @@
"language/expressions/class/elements/*-generator-method-*.js",
"built-ins/Set/prototype/union/allows-set-like-class.js",
"built-ins/Set/prototype/union/allows-set-like-object.js",
"built-ins/Set/prototype/symmetricDifference/allows-set-like-class.js",
"built-ins/Set/prototype/symmetricDifference/allows-set-like-object.js",
"built-ins/Set/prototype/isSupersetOf/allows-set-like-class.js",
"built-ins/Set/prototype/isSupersetOf/allows-set-like-object.js",
"built-ins/Set/prototype/isSupersetOf/set-like-class-mutation.js",

// generators not implemented
"built-ins/Object/prototype/toString/proxy-function.js",
Expand Down
40 changes: 16 additions & 24 deletions Jint/Native/Set/JsSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ internal sealed class JsSet : ObjectInstance
public JsSet(Engine engine, OrderedSet<JsValue> set) : base(engine)
{
_set = set;
_prototype = _engine.Realm.Intrinsics.Set.PrototypeObject;
}

public int Size => _set.Count;

public JsValue? this[int index]
{
get { return index < _set._list.Count ? _set._list[index] : null; }
}

public override PropertyDescriptor GetOwnProperty(JsValue property)
Expand All @@ -39,25 +47,15 @@ protected override bool TryGetProperty(JsValue property, [NotNullWhen(true)] out
return base.TryGetProperty(property, out descriptor);
}

internal void Add(JsValue value)
{
_set.Add(value);
}
internal void Add(JsValue value) => _set.Add(value);

internal void Clear()
{
_set.Clear();
}
internal void Remove(JsValue value) => _set.Remove(value);

internal bool Has(JsValue key)
{
return _set.Contains(key);
}
internal void Clear() => _set.Clear();

internal bool SetDelete(JsValue key)
{
return _set.Remove(key);
}
internal bool Has(JsValue key) => _set.Contains(key);

internal bool SetDelete(JsValue key) => _set.Remove(key);

internal void ForEach(ICallable callable, JsValue thisArg)
{
Expand All @@ -75,13 +73,7 @@ internal void ForEach(ICallable callable, JsValue thisArg)
_engine._jsValueArrayPool.ReturnArray(args);
}

internal ObjectInstance Entries()
{
return _engine.Realm.Intrinsics.SetIteratorPrototype.ConstructEntryIterator(this);
}
internal ObjectInstance Entries() => _engine.Realm.Intrinsics.SetIteratorPrototype.ConstructEntryIterator(this);

internal ObjectInstance Values()
{
return _engine.Realm.Intrinsics.SetIteratorPrototype.ConstructValueIterator(this);
}
internal ObjectInstance Values() => _engine.Realm.Intrinsics.SetIteratorPrototype.ConstructValueIterator(this);
}
Loading