Skip to content

Commit eaa14a7

Browse files
committed
Built-in properties (like Array.length) should not be enumerated even when they are defined in Object.prototype
1 parent cb889d1 commit eaa14a7

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

lib/Runtime/Library/ForInObjectEnumerator.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,18 @@ namespace Js
210210
return nullptr;
211211
}
212212

213+
// Ignore special properties (ex: Array.length)
214+
uint specialPropertyCount = this->shadowData->currentObject->GetSpecialPropertyCount();
215+
if (specialPropertyCount > 0)
216+
{
217+
PropertyId const* specialPropertyIds = this->shadowData->currentObject->GetSpecialPropertyIds();
218+
Assert(specialPropertyIds != nullptr);
219+
for (uint i = 0; i < specialPropertyCount; i++)
220+
{
221+
TestAndSetEnumerated(specialPropertyIds[i]);
222+
}
223+
}
224+
213225
RecyclableObject * object;
214226
if (!this->enumeratingPrototype)
215227
{

test/Bugs/bug_OS17614914.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
Object.prototype.length = undefined;
7+
var ary = Array();
8+
ary.prop1 = 1;
9+
Object.defineProperty(ary, "prop2", {
10+
value: 1,
11+
enumerable: false
12+
});
13+
for (var prop in ary) {
14+
if (prop !== "prop1") {
15+
console.log(`Fail: ${prop} property should not show in for-in`);
16+
}
17+
}
18+
console.log("pass");

test/Bugs/rlexe.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,4 +501,9 @@
501501
<files>withSplitScope.js</files>
502502
</default>
503503
</test>
504+
<test>
505+
<default>
506+
<files>bug_OS17614914.js</files>
507+
</default>
508+
</test>
504509
</regress-exe>

0 commit comments

Comments
 (0)