Skip to content

Commit

Permalink
[MERGE #5695 @pleath] Writing to proto can leave the TypeHandler::pro…
Browse files Browse the repository at this point in the history
…toCachesWereInvalidated set, and writing to proto again with the same type on the RHS object can skip proto cache invalidation

Merge pull request #5695 from pleath:missingprotoinval

Clear the flag on objects in the new prototype chain on entry to the ChangePrototype method so that invalidation happens based on the current state of those objects.
  • Loading branch information
pleath committed Sep 14, 2018
2 parents 172fbd8 + 83071cb commit c666aa4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/Runtime/Library/JavascriptObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ BOOL JavascriptObject::ChangePrototype(RecyclableObject* object, RecyclableObjec
// ii. Let nextp be the result of calling the [[GetInheritance]] internal method of p with no arguments.
// iii. ReturnIfAbrupt(nextp).
// iv. Let p be nextp.
if (IsPrototypeOfStopAtProxy(object, newPrototype, scriptContext)) // Reject cycle
if (IsPrototypeOfStopAtProxy(object, newPrototype, scriptContext)) // Reject cycle
{
if (shouldThrow)
{
Expand Down Expand Up @@ -229,6 +229,11 @@ BOOL JavascriptObject::ChangePrototype(RecyclableObject* object, RecyclableObjec
{
bool allProtoCachesInvalidated = false;

JavascriptOperators::MapObjectAndPrototypes<true>(newPrototype, [&](RecyclableObject* obj)
{
obj->ClearProtoCachesWereInvalidated();
});

// Notify old prototypes that they are being removed from a prototype chain. This triggers invalidating protocache, etc.
JavascriptOperators::MapObjectAndPrototypesUntil<true>(object->GetPrototype(), [&](RecyclableObject* obj)->bool
{
Expand Down
54 changes: 54 additions & 0 deletions test/InlineCaches/MissingProtoInval.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

function f1() {
var o1 = {},o2 = {};
var proto1 = {a:'a',b:'b'},proto2 = {a:'a'};
o1.__proto__ = proto1;
o2.__proto__ = proto2;

function a(o) { return o.a; }
function b(o) { return o.b; }

a(o1);
a(o2);
b(o1);
b(o2);
proto2.__proto__ = {b:'b'};
if (b(o2) !== 'b') {
WScript.Echo('fail');
}
}

f1()
f1();

function f2() {
var o1 = {b:'b'},o2 = {b:'b'};
var proto1 = {a:'a',b:'b'},proto2 = {a:'a'};
o1.__proto__ = proto1;
o2.__proto__ = proto2;

function a(o) { return o.a; }
function b(o) { return o.b; }

a(o1);
a(o2);

delete o1.b;
delete o2.b;

b(o1);
b(o2);
proto2.__proto__ = {b:'b'};
if (b(o2) !== 'b') {
WScript.Echo('fail');
}
}

f2();
f2();

WScript.Echo('pass');
5 changes: 5 additions & 0 deletions test/InlineCaches/rlexe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@
<files>MissingPropertyCache4.js</files>
</default>
</test>
<test>
<default>
<files>MissingProtoInval.js</files>
</default>
</test>
<test>
<default>
<files>instanceOfCacheCrossRegistration.js</files>
Expand Down

0 comments on commit c666aa4

Please sign in to comment.