Skip to content

Commit c0aac51

Browse files
committed
[MERGE #961] #535 - Proxy traps not triggered for __lookupGetter and __lookupSetter_
Merge pull request #961 from leirocks:lookupgetter just need to call GetPrototype instead of GetPrototypeNoTrap in JavascriptOperators::GetAccessors
2 parents 22d2fb0 + 614057f commit c0aac51

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

lib/Runtime/Language/JavascriptOperators.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,7 @@ namespace Js
25012501
{
25022502
break;
25032503
}
2504-
object = JavascriptOperators::GetPrototypeNoTrap(object);
2504+
object = JavascriptOperators::GetPrototype(object);
25052505
}
25062506
return FALSE;
25072507
}

test/es7/lookupgettersetter.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
7+
8+
var tests = [
9+
{
10+
name: "Object.prototype.__lookupGetter__ -> [[GetOwnProperty]], [[GetPrototypeOf]]",
11+
body: function () {
12+
// Object.prototype.__lookupGetter__ -> [[GetOwnProperty]]
13+
// Object.prototype.__lookupGetter__ -> [[GetPrototypeOf]]
14+
var gopd = [];
15+
var gpo = false;
16+
var p = new Proxy({},
17+
{
18+
getPrototypeOf: function(o) { gpo = true; return Object.getPrototypeOf(o); },
19+
getOwnPropertyDescriptor: function(o, v) { gopd.push(v); return Object.getOwnPropertyDescriptor(o, v); }
20+
});
21+
Object.prototype.__lookupGetter__.call(p, "foo");
22+
assert.areEqual(1, gopd.length, "getOwnPropertyDescriptor should only be called once");
23+
assert.areEqual("foo", gopd[0], "getOwnPropertyDescriptor should be called with foo");
24+
assert.isTrue(gpo, "getPrototypeOf should be called");
25+
}
26+
},
27+
{
28+
name: "Object.prototype.__lookupSetter__ -> [[GetOwnProperty]], [[GetPrototypeOf]]",
29+
body: function () {
30+
// Object.prototype.__lookupSetter__ -> [[GetOwnProperty]]
31+
// Object.prototype.__lookupSetter__ -> [[GetPrototypeOf]]
32+
var gopd = [];
33+
var gpo = false;
34+
var p = new Proxy({},
35+
{
36+
getPrototypeOf: function(o) { gpo = true; return Object.getPrototypeOf(o); },
37+
getOwnPropertyDescriptor: function(o, v) { gopd.push(v); return Object.getOwnPropertyDescriptor(o, v); }
38+
});
39+
Object.prototype.__lookupSetter__.call(p, "foo");
40+
assert.areEqual(1, gopd.length, "getOwnPropertyDescriptor should only be called once");
41+
assert.areEqual("foo", gopd[0], "getOwnPropertyDescriptor should be called with foo");
42+
assert.isTrue(gpo, "getPrototypeOf should be called");
43+
}
44+
}
45+
];
46+
47+
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

test/es7/rlexe.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,11 @@
6565
<compile-flags>-args summary -endargs</compile-flags>
6666
</default>
6767
</test>
68+
<test>
69+
<default>
70+
<files>lookupgettersetter.js</files>
71+
<compile-flags>-args summary -endargs</compile-flags>
72+
<tags>BugFix</tags>
73+
</default>
74+
</test>
6875
</regress-exe>

0 commit comments

Comments
 (0)