Skip to content

Commit 3181c96

Browse files
committed
[MERGE #5319 @MikeHolman] don't cache writes to default setter
Merge pull request #5319 from MikeHolman:defaultsettercache We can't cache writes to the default setter in sloppy mode, because we may then get a cache hit in strict mode and call it, when we should throw an exception instead OS: 17124936
2 parents 8ece006 + 9428cd6 commit 3181c96

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

lib/Runtime/Language/JavascriptOperators.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,7 +2303,7 @@ using namespace Js;
23032303
}
23042304
if (setterValueOrProxy)
23052305
{
2306-
if (!WithScopeObject::Is(receiver) && info->GetPropertyRecordUsageCache())
2306+
if (!WithScopeObject::Is(receiver) && info->GetPropertyRecordUsageCache() && !JavascriptOperators::IsUndefinedAccessor(setterValueOrProxy, requestContext))
23072307
{
23082308
CacheOperators::CachePropertyWrite(RecyclableObject::FromVar(receiver), false, object->GetType(), info->GetPropertyRecordUsageCache()->GetPropertyRecord()->GetPropertyId(), info, requestContext);
23092309
}
@@ -2525,7 +2525,7 @@ using namespace Js;
25252525
{
25262526
receiver = (RecyclableObject::FromVar(receiver))->GetThisObjectOrUnWrap();
25272527
}
2528-
else
2528+
else if (!JavascriptOperators::IsUndefinedAccessor(setterValueOrProxy, requestContext))
25292529
{
25302530
CacheOperators::CachePropertyWrite(RecyclableObject::FromVar(receiver), isRoot, object->GetType(), propertyId, info, requestContext);
25312531
}

test/InlineCaches/defaultsetterbug.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
let threw = false
7+
try
8+
{
9+
var obj1 = {};
10+
var func0 = function () {
11+
for (var _strvar2 in Object) {
12+
Object.prototype[_strvar2] = {};
13+
}
14+
};
15+
let cnt = 0;
16+
17+
Object.defineProperty(obj1, 'prop0', {
18+
get: function () {
19+
print("BAD!");
20+
},
21+
configurable: true
22+
});
23+
24+
Object.prototype.prop0 = func0();
25+
Object.prototype.prop2 = func0();
26+
27+
Object.prop2 = Object.defineProperty(Object.prototype, 'prop2', {
28+
get: function () {
29+
}});
30+
(function () {
31+
'use strict';
32+
for (var _strvar0 in Object) {
33+
Object.prototype[_strvar0] = func0();
34+
}
35+
}());
36+
}
37+
catch(e)
38+
{
39+
threw = true;
40+
}
41+
42+
print(threw ? "Pass" : "Fail")

test/InlineCaches/rlexe.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@
8181
<files>writable3.js</files>
8282
</default>
8383
</test>
84+
<test>
85+
<default>
86+
<files>defaultsetterbug.js</files>
87+
</default>
88+
</test>
8489
<test>
8590
<default>
8691
<files>BigDictionaryTypeHandler.js</files>

0 commit comments

Comments
 (0)