1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/xpconnect/tests/chrome/test_bug771429.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,51 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> 1.6 +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> 1.7 +<!-- 1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=771429 1.9 +--> 1.10 +<window title="Mozilla Bug 771429" 1.11 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.12 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.13 + 1.14 + <!-- test results are displayed in the html:body --> 1.15 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.16 + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=771429" 1.17 + target="_blank">Mozilla Bug 771429</a> 1.18 + </body> 1.19 + 1.20 + <!-- test code goes here --> 1.21 + <script type="application/javascript"> 1.22 + <![CDATA[ 1.23 + /** Test for Bug 771429 **/ 1.24 + function f() {} 1.25 + function g() { return this; } 1.26 + function h() { "use strict"; return this; } 1.27 + function ctor() { this.x = 1; } 1.28 + f.x = 2; 1.29 + f.g = g; 1.30 + var Cu = Components.utils; 1.31 + var s = new Cu.Sandbox(window, { sandboxPrototype: window } ); 1.32 + try { 1.33 + is(Cu.evalInSandbox('g()', s), window, 1.34 + "Should get window as this object of non-strict global function"); 1.35 + is(Cu.evalInSandbox('h()', s), undefined, 1.36 + "Should get undefined as this object of strict global function"); 1.37 + is(Cu.evalInSandbox('f.x', s), 2, 1.38 + "Should have gotten the right thing back"); 1.39 + is(Cu.evalInSandbox('f.g()', s), f, 1.40 + "Should have the right function object"); 1.41 + is(Cu.evalInSandbox('var x = { z: 7 }; g.call(x).z', s), 7, 1.42 + "Should not rebind calls that are already bound"); 1.43 + // And test what happens when we use the normal Function.prototype.call 1.44 + // on g instead of whatever our proxies happen to return. 1.45 + is(Cu.evalInSandbox('var x = { z: 7 }; Function.prototype.call.call(g, x).z', s), 7, 1.46 + "Should not rebind calls that are already bound"); 1.47 + is(Cu.evalInSandbox('new ctor();', s).x, 1, 1.48 + "Should get a properly constructed object out of the sandbox"); 1.49 + } catch (e) { 1.50 + ok(false, "Should not get an exception: " + e); 1.51 + } 1.52 + ]]> 1.53 + </script> 1.54 +</window>