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

Add iterator prototype tests #928

Merged
merged 1 commit into from
Jul 11, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion Jint.Tests.Test262/BuiltIns/ArrayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ public class ArrayTests : Test262Test
[Theory(DisplayName = "built-ins\\Array")]
[MemberData(nameof(SourceFiles), "built-ins\\Array", false)]
[MemberData(nameof(SourceFiles), "built-ins\\Array", true, Skip = "Skipped")]
protected void RunTest(SourceFile sourceFile)
protected void Array(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}

[Theory(DisplayName = "built-ins\\ArrayIteratorPrototype")]
[MemberData(nameof(SourceFiles), "built-ins\\ArrayIteratorPrototype", false)]
[MemberData(nameof(SourceFiles), "built-ins\\ArrayIteratorPrototype", true, Skip = "Skipped")]
protected void ArrayIteratorPrototype(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}
Expand Down
10 changes: 9 additions & 1 deletion Jint.Tests.Test262/BuiltIns/MapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ public class MapTests : Test262Test
[Theory(DisplayName = "built-ins\\Map")]
[MemberData(nameof(SourceFiles), "built-ins\\Map", false)]
[MemberData(nameof(SourceFiles), "built-ins\\Map", true, Skip = "Skipped")]
protected void RunTest(SourceFile sourceFile)
protected void Map(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}

[Theory(DisplayName = "built-ins\\MapIteratorPrototype")]
[MemberData(nameof(SourceFiles), "built-ins\\MapIteratorPrototype", false)]
[MemberData(nameof(SourceFiles), "built-ins\\MapIteratorPrototype", true, Skip = "Skipped")]
protected void MapIteratorPrototype(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}
Expand Down
2 changes: 1 addition & 1 deletion Jint.Tests.Test262/BuiltIns/RegExpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ protected void RegExp(SourceFile sourceFile)
RunTestInternal(sourceFile);
}

[Theory(DisplayName = "built-ins\\StringIteratorPrototype")]
[Theory(DisplayName = "built-ins\\RegExpStringIteratorPrototype")]
[MemberData(nameof(SourceFiles), "built-ins\\RegExpStringIteratorPrototype", false)]
[MemberData(nameof(SourceFiles), "built-ins\\RegExpStringIteratorPrototype", true, Skip = "Skipped")]
protected void RegExpStringIteratorPrototype(SourceFile sourceFile)
Expand Down
10 changes: 9 additions & 1 deletion Jint.Tests.Test262/BuiltIns/SetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ public class SetTests : Test262Test
[Theory(DisplayName = "built-ins\\Set")]
[MemberData(nameof(SourceFiles), "built-ins\\Set", false)]
[MemberData(nameof(SourceFiles), "built-ins\\Set", true, Skip = "Skipped")]
protected void RunTest(SourceFile sourceFile)
protected void Set(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}

[Theory(DisplayName = "built-ins\\SetIteratorPrototype")]
[MemberData(nameof(SourceFiles), "built-ins\\SetIteratorPrototype", false)]
[MemberData(nameof(SourceFiles), "built-ins\\SetIteratorPrototype", true, Skip = "Skipped")]
protected void SetIteratorPrototype(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}
Expand Down
4 changes: 4 additions & 0 deletions Jint.Tests.Test262/test/skipped.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@
"source": "built-ins/Map/prototype/forEach/iterates-values-deleted-then-readded.js",
"reason": "delete/add detection not implemented for map iterator during iteration"
},
{
"source": "built-ins/MapIteratorPrototype/next/iteration-mutable.js",
"reason": "delete/add detection not implemented for map iterator during iteration"
},
{
"source": "built-ins/Set/prototype/forEach/iterates-values-revisits-after-delete-re-add.js",
"reason": "delete/add detection not implemented for set iterator during iteration"
Expand Down
30 changes: 25 additions & 5 deletions Jint/Native/Iterator/IteratorConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ internal ObjectInstance Construct(ObjectInstance array, Func<Intrinsics, Prototy
return instance;
}

internal ObjectInstance Construct(MapInstance map)
internal ObjectInstance ConstructEntryIterator(MapInstance map)
{
var instance = new IteratorInstance.MapIterator(Engine, map)
{
Expand All @@ -84,11 +84,21 @@ internal ObjectInstance Construct(MapInstance map)
return instance;
}

internal ObjectInstance Construct(SetInstance set)
internal ObjectInstance ConstructKeyIterator(MapInstance map)
{
var instance = new IteratorInstance.SetIterator(Engine, set)
var instance = new IteratorInstance(Engine, map._map.Keys)
{
_prototype = SetIteratorPrototypeObject
_prototype = MapIteratorPrototypeObject
};

return instance;
}

internal ObjectInstance ConstructValueIterator(MapInstance map)
{
var instance = new IteratorInstance(Engine, map._map.Values)
{
_prototype = MapIteratorPrototypeObject
};

return instance;
Expand All @@ -98,7 +108,17 @@ internal ObjectInstance ConstructEntryIterator(SetInstance set)
{
var instance = new IteratorInstance.SetEntryIterator(Engine, set)
{
_prototype = GenericIteratorPrototypeObject
_prototype = SetIteratorPrototypeObject
};

return instance;
}

internal ObjectInstance ConstructValueIterator(SetInstance set)
{
var instance = new IteratorInstance.ListIterator(Engine, set._set._list)
{
_prototype = SetIteratorPrototypeObject
};

return instance;
Expand Down
26 changes: 0 additions & 26 deletions Jint/Native/Iterator/IteratorInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,32 +161,6 @@ public override bool TryIteratorStep(out ObjectInstance nextItem)
}
}

public class SetIterator : IteratorInstance
{
private readonly SetInstance _set;
private int _position;

public SetIterator(Engine engine, SetInstance set) : base(engine)
{
_set = set;
_position = 0;
}

public override bool TryIteratorStep(out ObjectInstance nextItem)
{
if (_position < _set._set._list.Count)
{
var value = _set._set[_position];
_position++;
nextItem = new ValueIteratorPosition(_engine, value);
return true;
}

nextItem = KeyValueIteratorPosition.Done;
return false;
}
}

public class SetEntryIterator : IteratorInstance
{
private readonly SetInstance _set;
Expand Down
6 changes: 3 additions & 3 deletions Jint/Native/Map/MapInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ internal JsValue MapGet(JsValue key)

internal ObjectInstance Iterator()
{
return _realm.Intrinsics.Iterator.Construct(this);
return _realm.Intrinsics.Iterator.ConstructEntryIterator(this);
}

internal ObjectInstance Keys()
{
return _realm.Intrinsics.Iterator.Construct(_map.Keys);
return _realm.Intrinsics.Iterator.ConstructKeyIterator(this);
}

internal ObjectInstance Values()
{
return _realm.Intrinsics.Iterator.Construct(_map.Values);
return _realm.Intrinsics.Iterator.ConstructValueIterator(this);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Set/SetInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ internal ObjectInstance Entries()

internal ObjectInstance Values()
{
return _engine.Realm.Intrinsics.Iterator.Construct(_set._list);
return _engine.Realm.Intrinsics.Iterator.ConstructValueIterator(this);
}
}
}