Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | // http://creativecommons.org/licenses/publicdomain/ |
michael@0 | 3 | |
michael@0 | 4 | //----------------------------------------------------------------------------- |
michael@0 | 5 | var BUGNUMBER = 514568; |
michael@0 | 6 | var summary = "eval in all its myriad flavors"; |
michael@0 | 7 | |
michael@0 | 8 | print(BUGNUMBER + ": " + summary); |
michael@0 | 9 | |
michael@0 | 10 | /************** |
michael@0 | 11 | * BEGIN TEST * |
michael@0 | 12 | **************/ |
michael@0 | 13 | |
michael@0 | 14 | var x = 17; |
michael@0 | 15 | |
michael@0 | 16 | var ev = eval; |
michael@0 | 17 | |
michael@0 | 18 | var xcode = |
michael@0 | 19 | "var x = 4;" + |
michael@0 | 20 | "function actX(action)" + |
michael@0 | 21 | "{" + |
michael@0 | 22 | " switch (action)" + |
michael@0 | 23 | " {" + |
michael@0 | 24 | " case 'get':" + |
michael@0 | 25 | " return x;" + |
michael@0 | 26 | " case 'set1':" + |
michael@0 | 27 | " x = 9;" + |
michael@0 | 28 | " return;" + |
michael@0 | 29 | " case 'set2':" + |
michael@0 | 30 | " x = 23;" + |
michael@0 | 31 | " return;" + |
michael@0 | 32 | " case 'delete':" + |
michael@0 | 33 | " try { return eval('delete x'); }" + |
michael@0 | 34 | " catch (e) { return e.name; }" + |
michael@0 | 35 | " }" + |
michael@0 | 36 | "}" + |
michael@0 | 37 | "actX;"; |
michael@0 | 38 | |
michael@0 | 39 | var local0 = x; |
michael@0 | 40 | |
michael@0 | 41 | var f = eval(xcode); |
michael@0 | 42 | |
michael@0 | 43 | var inner1 = f("get"); |
michael@0 | 44 | var local1 = x; |
michael@0 | 45 | |
michael@0 | 46 | x = 7; |
michael@0 | 47 | var inner2 = f("get"); |
michael@0 | 48 | var local2 = x; |
michael@0 | 49 | |
michael@0 | 50 | f("set1"); |
michael@0 | 51 | var inner3 = f("get"); |
michael@0 | 52 | var local3 = x; |
michael@0 | 53 | |
michael@0 | 54 | var del = f("delete"); |
michael@0 | 55 | var inner4 = f("get"); |
michael@0 | 56 | var local4 = x; |
michael@0 | 57 | |
michael@0 | 58 | f("set2"); |
michael@0 | 59 | var inner5 = f("get"); |
michael@0 | 60 | var local5 = x; |
michael@0 | 61 | |
michael@0 | 62 | var resultsX = |
michael@0 | 63 | { |
michael@0 | 64 | local0: local0, |
michael@0 | 65 | inner1: inner1, local1: local1, |
michael@0 | 66 | inner2: inner2, local2: local2, |
michael@0 | 67 | inner3: inner3, local3: local3, |
michael@0 | 68 | del: del, |
michael@0 | 69 | inner4: inner4, local4: local4, |
michael@0 | 70 | inner5: inner5, local5: local5, |
michael@0 | 71 | }; |
michael@0 | 72 | |
michael@0 | 73 | assertEq(resultsX.local0, 17); |
michael@0 | 74 | |
michael@0 | 75 | assertEq(resultsX.inner1, 4); |
michael@0 | 76 | assertEq(resultsX.local1, 4); |
michael@0 | 77 | |
michael@0 | 78 | assertEq(resultsX.inner2, 7); |
michael@0 | 79 | assertEq(resultsX.local2, 7); |
michael@0 | 80 | |
michael@0 | 81 | assertEq(resultsX.inner3, 9); |
michael@0 | 82 | assertEq(resultsX.local3, 9); |
michael@0 | 83 | |
michael@0 | 84 | assertEq(resultsX.del, false); |
michael@0 | 85 | |
michael@0 | 86 | assertEq(resultsX.inner4, 9); |
michael@0 | 87 | assertEq(resultsX.local4, 9); |
michael@0 | 88 | |
michael@0 | 89 | assertEq(resultsX.inner5, 23); |
michael@0 | 90 | assertEq(resultsX.local5, 23); |
michael@0 | 91 | |
michael@0 | 92 | |
michael@0 | 93 | var ycode = |
michael@0 | 94 | "var y = 5;" + |
michael@0 | 95 | "function actY(action)" + |
michael@0 | 96 | "{" + |
michael@0 | 97 | " switch (action)" + |
michael@0 | 98 | " {" + |
michael@0 | 99 | " case 'get':" + |
michael@0 | 100 | " return y;" + |
michael@0 | 101 | " case 'set1':" + |
michael@0 | 102 | " y = 2;" + |
michael@0 | 103 | " return;" + |
michael@0 | 104 | " case 'set2':" + |
michael@0 | 105 | " y = 71;" + |
michael@0 | 106 | " return;" + |
michael@0 | 107 | " case 'delete':" + |
michael@0 | 108 | " try { return eval('delete y'); }" + |
michael@0 | 109 | " catch (e) { return e.name; }" + |
michael@0 | 110 | " }" + |
michael@0 | 111 | "}" + |
michael@0 | 112 | "actY;"; |
michael@0 | 113 | |
michael@0 | 114 | try { var local0 = y; } catch (e) { local0 = e.name; } |
michael@0 | 115 | |
michael@0 | 116 | var f = eval(ycode); |
michael@0 | 117 | |
michael@0 | 118 | var inner1 = f("get"); |
michael@0 | 119 | var local1 = y; |
michael@0 | 120 | |
michael@0 | 121 | y = 8; |
michael@0 | 122 | var inner2 = f("get"); |
michael@0 | 123 | var local2 = y; |
michael@0 | 124 | |
michael@0 | 125 | f("set1"); |
michael@0 | 126 | var inner3 = f("get"); |
michael@0 | 127 | var local3 = y; |
michael@0 | 128 | |
michael@0 | 129 | var del = f("delete"); |
michael@0 | 130 | try { var inner4 = f("get"); } catch (e) { inner4 = e.name; } |
michael@0 | 131 | try { var local4 = y; } catch (e) { local4 = e.name; } |
michael@0 | 132 | |
michael@0 | 133 | f("set2"); |
michael@0 | 134 | try { var inner5 = f("get"); } catch (e) { inner5 = e.name; } |
michael@0 | 135 | try { var local5 = y; } catch (e) { local5 = e.name; } |
michael@0 | 136 | |
michael@0 | 137 | var resultsY = |
michael@0 | 138 | { |
michael@0 | 139 | local0: local0, |
michael@0 | 140 | inner1: inner1, local1: local1, |
michael@0 | 141 | inner2: inner2, local2: local2, |
michael@0 | 142 | inner3: inner3, local3: local3, |
michael@0 | 143 | del: del, |
michael@0 | 144 | inner4: inner4, local4: local4, |
michael@0 | 145 | inner5: inner5, local5: local5, |
michael@0 | 146 | }; |
michael@0 | 147 | |
michael@0 | 148 | assertEq(resultsY.local0, "ReferenceError"); |
michael@0 | 149 | |
michael@0 | 150 | assertEq(resultsY.inner1, 5); |
michael@0 | 151 | assertEq(resultsY.local1, 5); |
michael@0 | 152 | |
michael@0 | 153 | assertEq(resultsY.inner2, 8); |
michael@0 | 154 | assertEq(resultsY.local2, 8); |
michael@0 | 155 | |
michael@0 | 156 | assertEq(resultsY.inner3, 2); |
michael@0 | 157 | assertEq(resultsY.local3, 2); |
michael@0 | 158 | |
michael@0 | 159 | assertEq(resultsY.del, true); |
michael@0 | 160 | |
michael@0 | 161 | assertEq(resultsY.inner4, "ReferenceError"); |
michael@0 | 162 | assertEq(resultsY.local4, "ReferenceError"); |
michael@0 | 163 | |
michael@0 | 164 | assertEq(resultsY.inner5, 71); |
michael@0 | 165 | assertEq(resultsY.local5, 71); |
michael@0 | 166 | |
michael@0 | 167 | /******************************************************************************/ |
michael@0 | 168 | |
michael@0 | 169 | if (typeof reportCompare === "function") |
michael@0 | 170 | reportCompare(true, true); |
michael@0 | 171 | |
michael@0 | 172 | print("Tests complete!"); |