test_bug960820.html 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=960820
  5. -->
  6. <head>
  7. <meta charset="utf-8">
  8. <title>Test for Bug 960820</title>
  9. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  10. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  11. <script type="application/javascript">
  12. /** Test for exception stacks crossing **/
  13. // Synchronous event dispatch creates a new script entry point. At the time
  14. // of this writing, an event listener defined in a Sandbox will cause the
  15. // SafeJSContext to be pushed to the cx stack, which differs from the JSContext
  16. // associated with this DOM window. So we test both kinds of boundaries.
  17. var sb = new SpecialPowers.Cu.Sandbox(SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal());
  18. sb.win = window;
  19. SpecialPowers.Cu.evalInSandbox("win.document.addEventListener('click', " +
  20. "function clickHandler() { win.wrappedJSObject.clickCallback(); });", sb);
  21. function clickCallback() {
  22. var stack = (new Error()).stack;
  23. ok(true, "Invoked clickCallback. Stack: " + stack);
  24. ok(/clickCallback/.test(stack), "clickCallback should be in the stack");
  25. ok(!/clickHandler/.test(stack), "clickHandler should not be in the stack");
  26. ok(/dispatchClick/.test(stack), "dispatchClick should be in the stack");
  27. // Check Components.stack, but first filter through the SpecialPowers junk.
  28. var stack = SpecialPowers.wrap(SpecialPowers.Components).stack;
  29. while (/specialpowers/.test(stack)) {
  30. stack = stack.caller;
  31. }
  32. ok(/clickCallback/.test(stack), "clickCallback should be reachable via Components.stack");
  33. ok(/clickHandler/.test(stack.caller), "clickHandler should be reachable via Components.stack");
  34. ok(/dispatchClick/.test(stack.caller.caller), "dispatchClick hould be reachable via Components.stack");
  35. }
  36. function dispatchClick() {
  37. document.dispatchEvent(new MouseEvent('click'));
  38. }
  39. dispatchClick();
  40. </script>
  41. </head>
  42. <body>
  43. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=960820">Mozilla Bug 960820</a>
  44. <p id="display"></p>
  45. <div id="content" style="display: none">
  46. </div>
  47. <pre id="test">
  48. </pre>
  49. </body>
  50. </html>