Skip to content

Commit fed9437

Browse files
committed
[MERGE #5312 @akroshg] Proxy : getPrototype trap should not be called.
Merge pull request #5312 from akroshg:initproto when setting proxy as a prototype of another object - it should not inoke the trap. (If I read correctly, step 8.c.i: https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-setprototypeof-v ).
2 parents a93c18b + 49b384c commit fed9437

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/Runtime/Library/JavascriptObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ using namespace Js;
194194
// ii. Let nextp be the result of calling the [[GetInheritance]] internal method of p with no arguments.
195195
// iii. ReturnIfAbrupt(nextp).
196196
// iv. Let p be nextp.
197-
if (IsPrototypeOf(object, newPrototype, scriptContext)) // Reject cycle
197+
if (IsPrototypeOfStopAtProxy(object, newPrototype, scriptContext)) // Reject cycle
198198
{
199199
if (shouldThrow)
200200
{

test/Bugs/misc_bugs.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,23 @@ var tests = [
137137
new bar(...(new Array(2**16+1)))
138138
} catch(e) { }
139139
}
140+
},
141+
{
142+
name: "getPrototypeOf Should not be called when set as prototype",
143+
body: function () {
144+
var p = new Proxy({}, { getPrototypeOf: function() {
145+
assert.fail("this should not be called")
146+
return {};
147+
}});
148+
149+
var obj = {};
150+
obj.__proto__ = p; // This should not call the getPrototypeOf
151+
152+
var obj1 = {};
153+
Object.setPrototypeOf(obj1, p); // This should not call the getPrototypeOf
154+
155+
var obj2 = {__proto__ : p}; // This should not call the getPrototypeOf
156+
}
140157
}
141158

142159
];

0 commit comments

Comments
 (0)