| 1 |
// |reftest| skip-if(!xulRuntime.shell) |
| 2 |
// Any copyright is dedicated to the Public Domain. |
| 3 |
// http://creativecommons.org/licenses/publicdomain/ |
| 4 |
// Contributor: Blake Kaplan |
| 5 |
|
| 6 |
function expect(actual, arg) { |
| 7 |
reportCompare(expect.expected, actual, arg); |
| 8 |
} |
| 9 |
|
| 10 |
var window = { set x(y) { expect(this, y) }, y: 4 }; |
| 11 |
expect.expected = window; |
| 12 |
window.x = "setting through a setter directly"; |
| 13 |
window.y = 5; |
| 14 |
reportCompare(5, window.y, "setting properties works"); |
| 15 |
var easy = { easy: 'yes', __proto__: window } |
| 16 |
expect.expected = easy; |
| 17 |
easy.x = "setting through a setter all-native on prototype"; |
| 18 |
easy.y = 6; |
| 19 |
reportCompare(5, window.y, "window.y remains as it was"); |
| 20 |
reportCompare(6, easy.y, "shadowing works properly"); |
| 21 |
|
| 22 |
var sandbox = evalcx(''); |
| 23 |
sandbox.window = window; |
| 24 |
sandbox.print = print; |
| 25 |
sandbox.expect = expect; |
| 26 |
var hard = evalcx('Object.create(window)', sandbox); |
| 27 |
expect.expected = hard; |
| 28 |
hard.x = "a setter through proxy -> native"; |
| 29 |
hard.y = 6; |
| 30 |
reportCompare(5, window.y, "window.y remains as it was through a proxy"); |
| 31 |
reportCompare(6, hard.y, "shadowing works on proxies"); |
| 32 |
|
| 33 |
hard.__proto__ = { 'passed': true } |
| 34 |
reportCompare(true, hard.passed, "can set proxy.__proto__ through a native"); |
| 35 |
|
| 36 |
var inverse = evalcx('({ set x(y) { expect(this, y); }, y: 4 })', sandbox); |
| 37 |
expect.expected = inverse; |
| 38 |
inverse.x = "setting through a proxy directly"; |
| 39 |
inverse.y = 5; |
| 40 |
reportCompare(5, inverse.y, "setting properties works on proxies"); |
| 41 |
|
| 42 |
var inversehard = Object.create(inverse); |
| 43 |
expect.expected = inversehard; |
| 44 |
inversehard.x = "setting through a setter with a proxy on the proto chain"; |
| 45 |
inversehard.y = 6; |
| 46 |
reportCompare(5, inverse.y, "inverse.y remains as it was"); |
| 47 |
reportCompare(6, inversehard.y, "shadowing works native -> proxy"); |
| 48 |
|
| 49 |
inversehard.__proto__ = { 'passed': true } |
| 50 |
reportCompare(true, inversehard.passed, "can set native.__proto__ through a proxy"); |