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

Fix ArrayPatternProtocol indexing for function parameters #1348

Merged
merged 1 commit into from
Nov 6, 2022
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
16 changes: 16 additions & 0 deletions Jint.Tests/Runtime/DestructuringTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Jint.Tests.Runtime;

public class DestructuringTests
{
[Fact]
public void WithStrings()
{
const string Script = @"
return function([a, b, c]) {
return a === ""a"" && b === ""b"" && c === void undefined;
}(""ab"");";

var engine = new Engine();
Assert.True(engine.Evaluate(Script).AsBoolean());
}
}
4 changes: 2 additions & 2 deletions Jint/Runtime/Environments/FunctionEnvironmentRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ private sealed class ArrayPatternProtocol : IteratorProtocol
{
private readonly ArrayInstance _instance;
private readonly int _max;
private long _index = 0;
private long _index;

public ArrayPatternProtocol(
Engine engine,
Expand All @@ -434,8 +434,8 @@ private sealed class ArrayPatternProtocol : IteratorProtocol

protected override void ProcessItem(JsValue[] args, JsValue currentValue)
{
_index++;
_instance.SetIndexValue((uint) _index, currentValue, updateLength: false);
_index++;
}

protected override bool ShouldContinue => _index < _max;
Expand Down