1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/xpconnect/tests/mochitest/test_bug960820.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,56 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=960820 1.8 +--> 1.9 +<head> 1.10 + <meta charset="utf-8"> 1.11 + <title>Test for Bug 960820</title> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 + <script type="application/javascript"> 1.15 + 1.16 + /** Test for exception stacks crossing **/ 1.17 + 1.18 + // Synchronous event dispatch creates a new script entry point. At the time 1.19 + // of this writing, an event listener defined in a Sandbox will cause the 1.20 + // SafeJSContext to be pushed to the cx stack, which differs from the JSContext 1.21 + // associated with this DOM window. So we test both kinds of boundaries. 1.22 + var sb = new SpecialPowers.Cu.Sandbox(SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal()); 1.23 + sb.win = window; 1.24 + SpecialPowers.Cu.evalInSandbox("win.document.addEventListener('click', " + 1.25 + "function clickHandler() { win.wrappedJSObject.clickCallback(); });", sb); 1.26 + function clickCallback() { 1.27 + var stack = (new Error()).stack; 1.28 + ok(true, "Invoked clickCallback. Stack: " + stack); 1.29 + ok(/clickCallback/.test(stack), "clickCallback should be in the stack"); 1.30 + ok(!/clickHandler/.test(stack), "clickHandler should not be in the stack"); 1.31 + ok(/dispatchClick/.test(stack), "dispatchClick should be in the stack"); 1.32 + 1.33 + // Check Components.stack, but first filter through the SpecialPowers junk. 1.34 + var stack = SpecialPowers.wrap(SpecialPowers.Components).stack; 1.35 + while (/specialpowers/.test(stack)) { 1.36 + stack = stack.caller; 1.37 + } 1.38 + ok(/clickCallback/.test(stack), "clickCallback should be reachable via Components.stack"); 1.39 + ok(/clickHandler/.test(stack.caller), "clickHandler should be reachable via Components.stack"); 1.40 + ok(/dispatchClick/.test(stack.caller.caller), "dispatchClick hould be reachable via Components.stack"); 1.41 + } 1.42 + function dispatchClick() { 1.43 + document.dispatchEvent(new MouseEvent('click')); 1.44 + } 1.45 + dispatchClick(); 1.46 + 1.47 + 1.48 + </script> 1.49 +</head> 1.50 +<body> 1.51 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=960820">Mozilla Bug 960820</a> 1.52 +<p id="display"></p> 1.53 +<div id="content" style="display: none"> 1.54 + 1.55 +</div> 1.56 +<pre id="test"> 1.57 +</pre> 1.58 +</body> 1.59 +</html>