Skip to content

Commit 8d61086

Browse files
authored
Merge pull request #6394 from rhuanjl/minorSpreadFix
Fix:5678 update array spread implementation
2 parents 0c6da93 + 2f43d08 commit 8d61086

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/Runtime/Library/JavascriptArray.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11645,10 +11645,13 @@ using namespace Js;
1164511645
JS_REENTRANT(jsReentLock, BOOL gotItem = JavascriptOperators::GetItem(srcArray, propertyObject, j, &element, scriptContext));
1164611646
if (!gotItem)
1164711647
{
11648-
// Copy across missing values as undefined as per 12.2.5.2 SpreadElement : ... AssignmentExpression 5f.
11649-
element = scriptContext->GetLibrary()->GetUndefined();
11648+
// skip elided elements
11649+
dstIndex++;
1165011650
}
11651-
dstArray->DirectSetItemAt(dstIndex++, element);
11651+
else
11652+
{
11653+
dstArray->DirectSetItemAt(dstIndex++, element);
11654+
}
1165211655
}
1165311656
};
1165411657

test/es6/spread.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ var tests = [
3131
}
3232
}
3333
},
34+
{
35+
name: "Bug Issue 5678, Spread should not set property descriptors on missing elements of target array",
36+
body: function () {
37+
var a = [1,,...[3]];
38+
assert.isFalse(Reflect.has(a, 1));
39+
assert.isUndefined(Object.getOwnPropertyDescriptor(a, 1));
40+
}
41+
},
3442
{
3543
name: "Testing call with spread args (all should be the same)",
3644
body: function() {

0 commit comments

Comments
 (0)