Skip to content

Commit

Permalink
Implement Set Methods for JavaScript (sebastienros#1741)
Browse files Browse the repository at this point in the history
* Implement Set.difference
* implement Set.symmetricDifference
* implement Set.isSubsetOf
* Implement Set.isSupersetOf
* Implement Set.intersection
* Implement Set.isDisjointFrom
* update README
  • Loading branch information
lahma authored and scgm0 committed Jan 25, 2024
1 parent a337f48 commit 2fcd163
Show file tree
Hide file tree
Showing 5 changed files with 374 additions and 52 deletions.
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

0 comments on commit 2fcd163

Please sign in to comment.