Skip to content

Commit f270e03

Browse files
committed
[MERGE #5562 @sigatrev] use correct property descriptor for array built ins CreateDataProperty
Merge pull request #5562 from sigatrev:property This affects the code path for several Array.prototype.xxx methods when called with non-array objects fixes issue #3532
2 parents 798f77b + 67bb96c commit f270e03

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

lib/Runtime/Library/JavascriptArray.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3129,13 +3129,22 @@ using namespace Js;
31293129
{
31303130
ScriptContext* scriptContext = pDestObj->GetScriptContext();
31313131

3132+
PropertyRecord const * propertyRecord;
31323133
if (idxDest.IsSmallIndex())
31333134
{
3134-
return pDestObj->SetItem(idxDest.GetSmallIndex(), aItem, Js::PropertyOperation_ThrowIfNotExtensible);
3135+
JavascriptOperators::GetPropertyIdForInt(idxDest.GetSmallIndex(), scriptContext, &propertyRecord);
31353136
}
3136-
PropertyRecord const * propertyRecord;
3137-
JavascriptOperators::GetPropertyIdForInt(idxDest.GetBigIndex(), scriptContext, &propertyRecord);
3138-
return pDestObj->SetProperty(propertyRecord->GetPropertyId(), aItem, PropertyOperation_ThrowIfNotExtensible, nullptr);
3137+
else
3138+
{
3139+
JavascriptOperators::GetPropertyIdForInt(idxDest.GetBigIndex(), scriptContext, &propertyRecord);
3140+
}
3141+
3142+
PropertyDescriptor propertyDescriptor;
3143+
propertyDescriptor.SetConfigurable(true);
3144+
propertyDescriptor.SetEnumerable(true);
3145+
propertyDescriptor.SetWritable(true);
3146+
propertyDescriptor.SetValue(aItem);
3147+
return JavascriptObject::DefineOwnPropertyHelper(pDestObj, propertyRecord->GetPropertyId(), propertyDescriptor, scriptContext, false);
31393148
}
31403149

31413150
template<typename T>

test/Array/FilterWithTypedArray.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
class dummy {
7+
constructor() {
8+
return new Int16Array(4);
9+
}
10+
}
11+
12+
var handler = {
13+
get: function(oTarget, sKey) {
14+
if (sKey.toString()=="constructor") {
15+
return { [Symbol.species] : dummy };
16+
} else {
17+
return 4;
18+
}
19+
},
20+
21+
has: function (oTarget, sKey) {
22+
return Reflect.has(oTarget, sKey);
23+
},
24+
};
25+
26+
var array = [1];
27+
var proxy = new Proxy(array, handler);
28+
29+
try
30+
{
31+
// By spec, Array.prototype.filter (and other built-ins) adds configurable properties to a new array, created from ArraySpeciesCreate.
32+
// If the constructed array is a TypedArray, setting of index properties should throw a type error because they cannot be configurable.
33+
var boundFilter = Array.prototype.filter.bind(proxy);
34+
boundFilter(function() { return true; });
35+
WScript.Echo("TypeError expected. TypedArray indicies should be non-configurable.");
36+
}
37+
catch (e)
38+
{
39+
if (e == "TypeError: Cannot redefine property '0'")
40+
{
41+
WScript.Echo("passed");
42+
}
43+
}

test/Array/rlexe.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,4 +775,9 @@
775775
<files>bug16717501.js</files>
776776
</default>
777777
</test>
778+
<test>
779+
<default>
780+
<files>FilterWithTypedArray.js</files>
781+
</default>
782+
</test>
778783
</regress-exe>

0 commit comments

Comments
 (0)