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