test_discardSystemSource.xul 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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=990353
  6. -->
  7. <window title="Mozilla Bug 990353"
  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=990353"
  13. target="_blank">Mozilla Bug 990353</a>
  14. </body>
  15. <!-- test code goes here -->
  16. <script type="application/javascript">
  17. <![CDATA[
  18. /** Test for Bug 990353 **/
  19. SimpleTest.waitForExplicitFinish();
  20. const Cu = Components.utils;
  21. function canary() {
  22. var someBitOfSource = 42;
  23. }
  24. var gLoadCount = 0;
  25. function frameLoaded() {
  26. switch (++gLoadCount) {
  27. case 1:
  28. ok(/sourceless/.test(window[0].canary.toSource()), "System function should be sourceless: " + window[0].canary.toSource());
  29. ok(/sourceless/.test(window[0].onload.toSource()), "System event handler should be sourceless: " + window[0].onload.toSource());
  30. var sb = new Cu.Sandbox('http://www.example.com', { discardSource: true });
  31. Cu.evalInSandbox('function canary() { var someBitOfSource = 42; }', sb);
  32. ok(/sourceless/.test(sb.canary.toSource()), "Function from sandbox with explicit discarding should be sourceless");
  33. try {
  34. window[0].throwSomething();
  35. ok(false, "should have thrown");
  36. } catch (e) {
  37. ok(/some error/.test(e), "Threw exception as expected: " + e);
  38. ok(/throwSomething/.test(e.stack), "Exception stack trace works: " + e.stack);
  39. }
  40. window[0].location = "http://example.org/tests/js/xpconnect/tests/chrome/file_discardSystemSource.html";
  41. break;
  42. case 2:
  43. ok(/someBitOfSource/.test(Cu.waiveXrays(window[0]).canary.toSource()), "Content function should have source");
  44. ok(/someBitOfSource/.test(Cu.waiveXrays(window[0]).onload.toSource()), "Content event handler should have source");
  45. testWorker();
  46. break;
  47. }
  48. }
  49. function testWorker() {
  50. var worker = new window[0].wrappedJSObject.Worker('worker_discardSystemSource.js');
  51. worker.onmessage = function(evt) {
  52. ok(/someBitOfSource/.test(evt.data), "Non-chrome worker should have source: " + evt.data);
  53. var chromeWorker = new Worker('worker_discardSystemSource.js');
  54. chromeWorker.onmessage = function(evt) {
  55. ok(/sourceless/.test(evt.data), "Chrome worker should not have source: " + evt.data);
  56. SimpleTest.finish();
  57. }
  58. }
  59. }
  60. function go() {
  61. // We should have our own source, because the pref wasn't enabled when we
  62. // were loaded.
  63. ok(/someBitOfSource/.test(canary.toSource()), "Should have own source");
  64. window[0].frameElement.onload = frameLoaded;
  65. window[0].location = "file_discardSystemSource.html";
  66. }
  67. addLoadEvent(function() {
  68. SpecialPowers.pushPrefEnv({set: [['javascript.options.discardSystemSource', true]]}, go);
  69. });
  70. ]]>
  71. </script>
  72. <iframe></iframe>
  73. </window>