Bug 603201 - Tests: Enable primitive receivers in [[Get]]. r=jorendorff

This commit is contained in:
Tom Schuster 2015-12-21 23:43:06 +01:00
parent 1cd64b091d
commit 0adeb23681
3 changed files with 102 additions and 0 deletions

View File

@ -64,6 +64,7 @@ skip-if = debug == false
[test_worker_UnwrapArg.html]
[test_unforgeablesonexpando.html]
[test_crossOriginWindowSymbolAccess.html]
[test_primitive_this.html]
[test_callback_exceptions.html]
[test_bug1123516_maplikesetlike.html]
skip-if = debug == false

View File

@ -0,0 +1,45 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=603201
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 603201</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 603201 **/
SimpleTest.waitForExplicitFinish();
function runTest()
{
var nodes = document.body.childNodes;
Object.setPrototypeOf(Number.prototype, nodes);
Object.defineProperty(nodes, "getter", {get: function() {
"use strict";
is(this, 1);
return "getter";
}});
Object.defineProperty(Object.getPrototypeOf(nodes), "getter2", {get: function() {
"use strict";
is(this, 1);
return "getter2";
}});
var number = 1;
is(number.getter, "getter");
is(number.getter2, "getter2");
SimpleTest.finish();
}
</script>
</head>
<body onload="runTest();">
<pre>Test</pre>
</body>
</html>

View File

@ -0,0 +1,56 @@
let primitives = [
10,
false,
"test",
Symbol()
]
let getter = "getter";
let getter2 = "getter2";
let key = "key";
for (let value of primitives) {
let prototype = Object.getPrototypeOf(value);
// Strict getters receive a primitive this value.
Object.defineProperty(prototype, "getter", {get: function() {
"use strict";
assertEq(this, value);
return "getter";
}})
assertEq(value.getter, "getter");
assertEq(value[getter], "getter");
// The proxy's [[Get]] trap is also invoked with primitive receiver values.
let proxy = new Proxy({}, {
get(target, property, receiver) {
assertEq(property, "key");
assertEq(receiver, value);
return "get";
}
});
Object.setPrototypeOf(prototype, proxy);
assertEq(value.key, "get");
assertEq(value[key], "get");
assertEq(value.getter, "getter");
assertEq(value[getter], "getter");
// A getter still gets a primitive this value even after going through a proxy.
proxy = new Proxy({
get getter2() {
"use strict";
assertEq(this, value);
return "getter2";
}
}, {});
Object.setPrototypeOf(prototype, proxy);
assertEq(value.getter2, "getter2");
assertEq(value[getter2], "getter2");
assertEq(value.getter, "getter");
assertEq(value[getter], "getter");
}
reportCompare(true, true);