Skip to content

Commit

Permalink
Fix ArrayPatternProtocol indexing for function parameters (#1348)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Nov 6, 2022
1 parent f9423a5 commit 943ac85
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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

0 comments on commit 943ac85

Please sign in to comment.