Skip to content

Commit

Permalink
Fix rest/spread bug with empty object (#1642)
Browse files Browse the repository at this point in the history
  • Loading branch information
CreepGin authored Oct 1, 2023
1 parent da88d1e commit 1697fc3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Jint.Tests/Runtime/DestructuringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,10 @@ public void WithNestedRest()
{
_engine.Execute("return function([x, ...[y, ...z]]) { equal(1, x); equal(2, y); equal('3,4', z + ''); }([1, 2, 3, 4]);");
}

[Fact]
public void EmptyRest()
{
_engine.Execute("function test({ ...props }){}; test({});");
}
}
2 changes: 1 addition & 1 deletion Jint/Runtime/Environments/FunctionEnvironmentRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private void HandleObjectPattern(EvaluationContext context, bool initiallyEmpty,
{
if (((RestElement) property).Argument is Identifier restIdentifier)
{
var rest = _engine.Realm.Intrinsics.Object.Construct(argumentObject.Properties!.Count - processedProperties!.Count);
var rest = _engine.Realm.Intrinsics.Object.Construct((argumentObject.Properties?.Count ?? 0) - processedProperties!.Count);
argumentObject.CopyDataProperties(rest, processedProperties);
SetItemSafely(restIdentifier.Name, rest, initiallyEmpty);
}
Expand Down

0 comments on commit 1697fc3

Please sign in to comment.