test_bug771429.xul 2.2 KB

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