michael@0: // |reftest| skip-if(!xulRuntime.shell) michael@0: // Any copyright is dedicated to the Public Domain. michael@0: // http://creativecommons.org/licenses/publicdomain/ michael@0: // Contributor: Blake Kaplan michael@0: michael@0: function expect(actual, arg) { michael@0: reportCompare(expect.expected, actual, arg); michael@0: } michael@0: michael@0: var window = { set x(y) { expect(this, y) }, y: 4 }; michael@0: expect.expected = window; michael@0: window.x = "setting through a setter directly"; michael@0: window.y = 5; michael@0: reportCompare(5, window.y, "setting properties works"); michael@0: var easy = { easy: 'yes', __proto__: window } michael@0: expect.expected = easy; michael@0: easy.x = "setting through a setter all-native on prototype"; michael@0: easy.y = 6; michael@0: reportCompare(5, window.y, "window.y remains as it was"); michael@0: reportCompare(6, easy.y, "shadowing works properly"); michael@0: michael@0: var sandbox = evalcx(''); michael@0: sandbox.window = window; michael@0: sandbox.print = print; michael@0: sandbox.expect = expect; michael@0: var hard = evalcx('Object.create(window)', sandbox); michael@0: expect.expected = hard; michael@0: hard.x = "a setter through proxy -> native"; michael@0: hard.y = 6; michael@0: reportCompare(5, window.y, "window.y remains as it was through a proxy"); michael@0: reportCompare(6, hard.y, "shadowing works on proxies"); michael@0: michael@0: hard.__proto__ = { 'passed': true } michael@0: reportCompare(true, hard.passed, "can set proxy.__proto__ through a native"); michael@0: michael@0: var inverse = evalcx('({ set x(y) { expect(this, y); }, y: 4 })', sandbox); michael@0: expect.expected = inverse; michael@0: inverse.x = "setting through a proxy directly"; michael@0: inverse.y = 5; michael@0: reportCompare(5, inverse.y, "setting properties works on proxies"); michael@0: michael@0: var inversehard = Object.create(inverse); michael@0: expect.expected = inversehard; michael@0: inversehard.x = "setting through a setter with a proxy on the proto chain"; michael@0: inversehard.y = 6; michael@0: reportCompare(5, inverse.y, "inverse.y remains as it was"); michael@0: reportCompare(6, inversehard.y, "shadowing works native -> proxy"); michael@0: michael@0: inversehard.__proto__ = { 'passed': true } michael@0: reportCompare(true, inversehard.passed, "can set native.__proto__ through a proxy");