1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/xpconnect/tests/chrome/test_bug732665.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> 1.6 +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> 1.7 +<!-- 1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=732665 1.9 +--> 1.10 +<window title="Mozilla Bug 732665" 1.11 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.12 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.13 + 1.14 + <!-- test results are displayed in the html:body --> 1.15 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.16 + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=732665" 1.17 + target="_blank">Mozilla Bug 732665</a> 1.18 + </body> 1.19 + 1.20 + <!-- test code goes here --> 1.21 + <script type="application/javascript"> 1.22 + <![CDATA[ 1.23 + 1.24 + // 1.25 + // Important! If this test starts failing after a tricky platform-y change, 1.26 + // the stack quota numbers in XPCJSRuntime probably need twiddling. We want 1.27 + // to maintain the invariants in this test (at least to some approximation) 1.28 + // for security reasons. 1.29 + // 1.30 + 1.31 + // Executes f() d steps from the probed native stack limit, and returns 1.32 + // the number of steps to the recursion limit from the caller. 1.33 + function nearNativeStackLimit(d, f) { 1.34 + f = f || function() {}; 1.35 + function inner() { 1.36 + try { 1.37 + with ({}) { // keep things predictable -- stay in the interpreter 1.38 + var stepsFromLimit = eval("inner()"); // Use eval to force a number of native stackframes to be created. 1.39 + } 1.40 + if (stepsFromLimit == d) { 1.41 + try { f(); } catch(e) { ok(false, 'nearNativeStackLimit callback threw: ' + e); } 1.42 + } 1.43 + return stepsFromLimit + 1; 1.44 + } catch(e) { 1.45 + // It would be nice to check here that the exception is actually an 1.46 + // over-recursion here. But doing so would require toString()ing the 1.47 + // exception, which we may not have the stack space to do. 1.48 + return 0; 1.49 + } 1.50 + } 1.51 + return inner(); 1.52 + } 1.53 + 1.54 + const Cu = Components.utils; 1.55 + var contentSb = new Cu.Sandbox('http://www.example.com'); 1.56 + var chromeSb = new Cu.Sandbox(window); 1.57 + chromeSb.ok = contentSb.ok = ok; 1.58 + Cu.evalInSandbox(nearNativeStackLimit.toSource(), chromeSb); 1.59 + Cu.evalInSandbox(nearNativeStackLimit.toSource(), contentSb); 1.60 + var chromeLimit = Cu.evalInSandbox("nearNativeStackLimit(0);", chromeSb); 1.61 + var contentLimit = Cu.evalInSandbox("nearNativeStackLimit(0)", contentSb); 1.62 + ok(chromeLimit >= contentLimit + 10, 1.63 + "Chrome should be able to have at least 10 heavy frames more stack than content: " + chromeLimit + ", " + contentLimit); 1.64 + 1.65 + // Exhaust the stack space in content, and then make sure we can still get 10 1.66 + // heavy frames in chrome. 1.67 + // 1.68 + // Note that sometimes, if we pass |0| to nearNativeStackLimit, we can end up 1.69 + // so close to the border in content that we can't even get ourselves together 1.70 + // enough to make the cross-compartment call. So rather than exhausting the 1.71 + // stack entirely and then checking for 10 chrome frames, we leave ourselves 1.72 + // one frame's worth, and check for 11. 1.73 + contentSb.nnslChrome = chromeSb.nearNativeStackLimit; 1.74 + var nestedLimit = Cu.evalInSandbox("nearNativeStackLimit(1, function() { nestedLimit = nnslChrome(0);}); nestedLimit;", contentSb); 1.75 + ok(nestedLimit >= 11, "Chrome should be invokable from content script with an exhausted stack: " + nestedLimit); 1.76 + 1.77 + ]]> 1.78 + </script> 1.79 +</window>