|
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=732665 |
|
6 --> |
|
7 <window title="Mozilla Bug 732665" |
|
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 |
|
11 <!-- test results are displayed in the html:body --> |
|
12 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
13 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=732665" |
|
14 target="_blank">Mozilla Bug 732665</a> |
|
15 </body> |
|
16 |
|
17 <!-- test code goes here --> |
|
18 <script type="application/javascript"> |
|
19 <![CDATA[ |
|
20 |
|
21 // |
|
22 // Important! If this test starts failing after a tricky platform-y change, |
|
23 // the stack quota numbers in XPCJSRuntime probably need twiddling. We want |
|
24 // to maintain the invariants in this test (at least to some approximation) |
|
25 // for security reasons. |
|
26 // |
|
27 |
|
28 // Executes f() d steps from the probed native stack limit, and returns |
|
29 // the number of steps to the recursion limit from the caller. |
|
30 function nearNativeStackLimit(d, f) { |
|
31 f = f || function() {}; |
|
32 function inner() { |
|
33 try { |
|
34 with ({}) { // keep things predictable -- stay in the interpreter |
|
35 var stepsFromLimit = eval("inner()"); // Use eval to force a number of native stackframes to be created. |
|
36 } |
|
37 if (stepsFromLimit == d) { |
|
38 try { f(); } catch(e) { ok(false, 'nearNativeStackLimit callback threw: ' + e); } |
|
39 } |
|
40 return stepsFromLimit + 1; |
|
41 } catch(e) { |
|
42 // It would be nice to check here that the exception is actually an |
|
43 // over-recursion here. But doing so would require toString()ing the |
|
44 // exception, which we may not have the stack space to do. |
|
45 return 0; |
|
46 } |
|
47 } |
|
48 return inner(); |
|
49 } |
|
50 |
|
51 const Cu = Components.utils; |
|
52 var contentSb = new Cu.Sandbox('http://www.example.com'); |
|
53 var chromeSb = new Cu.Sandbox(window); |
|
54 chromeSb.ok = contentSb.ok = ok; |
|
55 Cu.evalInSandbox(nearNativeStackLimit.toSource(), chromeSb); |
|
56 Cu.evalInSandbox(nearNativeStackLimit.toSource(), contentSb); |
|
57 var chromeLimit = Cu.evalInSandbox("nearNativeStackLimit(0);", chromeSb); |
|
58 var contentLimit = Cu.evalInSandbox("nearNativeStackLimit(0)", contentSb); |
|
59 ok(chromeLimit >= contentLimit + 10, |
|
60 "Chrome should be able to have at least 10 heavy frames more stack than content: " + chromeLimit + ", " + contentLimit); |
|
61 |
|
62 // Exhaust the stack space in content, and then make sure we can still get 10 |
|
63 // heavy frames in chrome. |
|
64 // |
|
65 // Note that sometimes, if we pass |0| to nearNativeStackLimit, we can end up |
|
66 // so close to the border in content that we can't even get ourselves together |
|
67 // enough to make the cross-compartment call. So rather than exhausting the |
|
68 // stack entirely and then checking for 10 chrome frames, we leave ourselves |
|
69 // one frame's worth, and check for 11. |
|
70 contentSb.nnslChrome = chromeSb.nearNativeStackLimit; |
|
71 var nestedLimit = Cu.evalInSandbox("nearNativeStackLimit(1, function() { nestedLimit = nnslChrome(0);}); nestedLimit;", contentSb); |
|
72 ok(nestedLimit >= 11, "Chrome should be invokable from content script with an exhausted stack: " + nestedLimit); |
|
73 |
|
74 ]]> |
|
75 </script> |
|
76 </window> |