Skip to content

Commit e149067

Browse files
committed
[MERGE #5978 @pleath] Do not convert simple type to path type when deleting built-in function property
Merge pull request #5978 from pleath:5952 Catch addition of Deleted attribute in PathTypeHandler SetAttributes API's.
2 parents bdbe408 + 23bf17d commit e149067

File tree

5 files changed

+42
-7
lines changed

5 files changed

+42
-7
lines changed

lib/Runtime/Types/PathTypeHandler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,11 @@ namespace Js
18611861

18621862
BOOL PathTypeHandlerBase::SetAttributesAtIndex(DynamicObject* instance, PropertyId propertyId, PropertyIndex index, PropertyAttributes attributes)
18631863
{
1864+
if (attributes & PropertyDeleted)
1865+
{
1866+
DeleteProperty(instance, propertyId, PropertyOperation_None);
1867+
return true;
1868+
}
18641869
return SetAttributesHelper(instance, propertyId, index, GetAttributeArray(), PropertyAttributesToObjectSlotAttributes(attributes));
18651870
}
18661871

lib/Runtime/Types/SimpleTypeHandler.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,15 @@ namespace Js
677677
CompileAssert(_countof(descriptors) == size);
678678
if (size > 1)
679679
{
680-
SetAttribute(instance, index, PropertyDeleted);
680+
if (GetIsLocked())
681+
{
682+
// Prevent conversion to path type and then dictionary. Remove this when path types support deleted properties.
683+
this->ConvertToNonSharedSimpleType(instance)->SetAttribute(instance, index, PropertyDeleted);
684+
}
685+
else
686+
{
687+
SetAttribute(instance, index, PropertyDeleted);
688+
}
681689
}
682690
else
683691
{
@@ -1000,6 +1008,10 @@ namespace Js
10001008
}
10011009
Assert(!oldType->GetIsLocked() || instance->GetDynamicType() != oldType);
10021010
}
1011+
if (descriptors[index].Attributes & PropertyDeleted)
1012+
{
1013+
instance->GetScriptContext()->InvalidateProtoCaches(propertyId);
1014+
}
10031015
typeHandler->descriptors[index].Attributes = attributes;
10041016
if (attributes & PropertyEnumerable)
10051017
{

test/DebuggerCommon/ES6_intl_simple_attach.js.dbg.baseline

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@
171171
"caller": "Error <large string>",
172172
"arguments": "Error <large string>"
173173
},
174-
"length": "number 2",
175-
"name": "string "
174+
"length": "number 2"
176175
}
177176
}
178177
}
@@ -321,8 +320,7 @@
321320
"caller": "Error <large string>",
322321
"arguments": "Error <large string>"
323322
},
324-
"length": "number 1",
325-
"name": "string "
323+
"length": "number 1"
326324
}
327325
}
328326
}
@@ -460,8 +458,7 @@
460458
"caller": "Error <large string>",
461459
"arguments": "Error <large string>"
462460
},
463-
"length": "number 1",
464-
"name": "string "
461+
"length": "number 1"
465462
},
466463
"resolvedOptions": {
467464
"#__proto__": {

test/Function/deleteProperty.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
var l = (function () {
7+
function func_0() {
8+
}
9+
delete func_0.length;
10+
Object.defineProperty(Function.prototype, 'length', { writable: true });
11+
func_0.length = 'candy';
12+
return func_0.length;
13+
}());
14+
15+
if (l === 'candy')
16+
WScript.Echo('pass')

test/Function/rlexe.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@
226226
<tags>exclude_test</tags>
227227
</default>
228228
</test>
229+
<test>
230+
<default>
231+
<files>deleteProperty.js</files>
232+
</default>
233+
</test>
229234
<test>
230235
<default>
231236
<files>newFunction.js</files>

0 commit comments

Comments
 (0)