Skip to content

Commit 6e5d041

Browse files
committed
Issue in setting accessor in PathTypeHandlerWithAttr
When the property is deleted (say when we are in SimpleTypeHandler) and then later if we create an accessor on the same property we have converted the type handler to PathTypeHandlerWithAttr. Since a property got deleted and PathTypeHandler should not handle that deleted property we need to convert this to Dictionary type. In order to fix that When we add the accessor on any property we need to check if any property deleted upon that we need to convert to Dictionary type instead of type.
1 parent 6b98ef8 commit 6e5d041

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

lib/Runtime/Types/PathTypeHandler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,8 @@ namespace Js
11961196
}
11971197
}
11981198

1199+
Assert((attr & ObjectSlotAttr_Deleted) != ObjectSlotAttr_Deleted);
1200+
11991201
SetAttributesHelper(instance, propertyId, propertyIndex, attributes, (ObjectSlotAttributes)(attr | ObjectSlotAttr_Accessor));
12001202
// SetAttributesHelper can convert to dictionary in corner cases, e.g., if we haven't got a full path from the root. Remove this check when that's fixed.
12011203
if (!instance->GetTypeHandler()->IsPathTypeHandler())

lib/Runtime/Types/SimpleTypeHandler.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ namespace Js
9595
}
9696
}
9797

98+
if (HasDeletedProperties())
99+
{
100+
return false;
101+
}
102+
98103
return true;
99104
}
100105

@@ -172,6 +177,21 @@ namespace Js
172177
return newTypeHandler;
173178
}
174179

180+
template<size_t size>
181+
bool SimpleTypeHandler<size>::HasDeletedProperties()
182+
{
183+
for (PropertyIndex i = 0; i < propertyCount; i++)
184+
{
185+
if (descriptors[i].Attributes & PropertyDeleted)
186+
{
187+
return true;
188+
}
189+
}
190+
191+
return false;
192+
}
193+
194+
175195
template<size_t size>
176196
PathTypeHandlerBase* SimpleTypeHandler<size>::ConvertToPathType(DynamicObject* instance)
177197
{

lib/Runtime/Types/SimpleTypeHandler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ namespace Js
9292
ES5ArrayTypeHandler* ConvertToES5ArrayType(DynamicObject* instance);
9393
SimpleTypeHandler<size>* ConvertToNonSharedSimpleType(DynamicObject * instance);
9494

95+
bool HasDeletedProperties();
96+
9597
BOOL GetDescriptor(PropertyId propertyId, PropertyIndex * index);
9698
BOOL SetAttribute(DynamicObject* instance, PropertyIndex index, PropertyAttributes attribute);
9799
BOOL ClearAttribute(DynamicObject* instance, PropertyIndex index, PropertyAttributes attribute);

test/Bugs/bug_6271.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
function testReconfigureAsAccessorProperty(f) {
7+
var length = 2;
8+
Object.defineProperty(f, 'length', {
9+
get: function () {
10+
return length;
11+
},
12+
set: function (v) {
13+
length = v;
14+
}
15+
});
16+
}
17+
(function testSetOnInstance() {
18+
function f() {}
19+
delete f.length;
20+
testReconfigureAsAccessorProperty(f);
21+
Object.defineProperty(Function.prototype, 'length', {
22+
writable: true
23+
});
24+
f.length = 123;
25+
f.length == 123 ? print("Pass") : print('fail');
26+
})();
27+

test/Bugs/rlexe.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,11 @@
623623
<files>bug_6277.js</files>
624624
</default>
625625
</test>
626+
<test>
627+
<default>
628+
<files>bug_6271.js</files>
629+
</default>
630+
</test>
626631
<test>
627632
<default>
628633
<files>bug_OS23102586.js</files>

0 commit comments

Comments
 (0)