|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?> |
|
3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> |
|
4 <!-- |
|
5 https://bugzilla.mozilla.org/show_bug.cgi?id=771429 |
|
6 --> |
|
7 <window title="Mozilla Bug 771429" |
|
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
10 |
|
11 <!-- test results are displayed in the html:body --> |
|
12 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
13 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=771429" |
|
14 target="_blank">Mozilla Bug 771429</a> |
|
15 </body> |
|
16 |
|
17 <!-- test code goes here --> |
|
18 <script type="application/javascript"> |
|
19 <![CDATA[ |
|
20 /** Test for Bug 771429 **/ |
|
21 function f() {} |
|
22 function g() { return this; } |
|
23 function h() { "use strict"; return this; } |
|
24 function ctor() { this.x = 1; } |
|
25 f.x = 2; |
|
26 f.g = g; |
|
27 var Cu = Components.utils; |
|
28 var s = new Cu.Sandbox(window, { sandboxPrototype: window } ); |
|
29 try { |
|
30 is(Cu.evalInSandbox('g()', s), window, |
|
31 "Should get window as this object of non-strict global function"); |
|
32 is(Cu.evalInSandbox('h()', s), undefined, |
|
33 "Should get undefined as this object of strict global function"); |
|
34 is(Cu.evalInSandbox('f.x', s), 2, |
|
35 "Should have gotten the right thing back"); |
|
36 is(Cu.evalInSandbox('f.g()', s), f, |
|
37 "Should have the right function object"); |
|
38 is(Cu.evalInSandbox('var x = { z: 7 }; g.call(x).z', s), 7, |
|
39 "Should not rebind calls that are already bound"); |
|
40 // And test what happens when we use the normal Function.prototype.call |
|
41 // on g instead of whatever our proxies happen to return. |
|
42 is(Cu.evalInSandbox('var x = { z: 7 }; Function.prototype.call.call(g, x).z', s), 7, |
|
43 "Should not rebind calls that are already bound"); |
|
44 is(Cu.evalInSandbox('new ctor();', s).x, 1, |
|
45 "Should get a properly constructed object out of the sandbox"); |
|
46 } catch (e) { |
|
47 ok(false, "Should not get an exception: " + e); |
|
48 } |
|
49 ]]> |
|
50 </script> |
|
51 </window> |