Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | // |reftest| skip -- obsolete test, need to remove minor failures to reenable. |
michael@0 | 2 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | //----------------------------------------------------------------------------- |
michael@0 | 8 | var BUGNUMBER = 380237; |
michael@0 | 9 | var summary = 'Generator expressions parenthesization test'; |
michael@0 | 10 | var actual = ''; |
michael@0 | 11 | var expect = ''; |
michael@0 | 12 | |
michael@0 | 13 | |
michael@0 | 14 | /* |
michael@0 | 15 | |
michael@0 | 16 | Given that parentheization seems so fragile *and* the rules for where |
michael@0 | 17 | genexps are allowed keep changing, I thought it would be good to have |
michael@0 | 18 | a way to test that: |
michael@0 | 19 | |
michael@0 | 20 | 1) unparenthesized genexps are allowed in some places and the |
michael@0 | 21 | decompilation is sane and not over-parenthesized |
michael@0 | 22 | |
michael@0 | 23 | 2) unparenthesized genexps are disallowed in many places and when |
michael@0 | 24 | there are parens, the decompilation is sane and not over-parenthesized |
michael@0 | 25 | |
michael@0 | 26 | */ |
michael@0 | 27 | |
michael@0 | 28 | // |genexp| must have the exact same whitespace the decompiler uses |
michael@0 | 29 | genexp = "x * x for (x in [])"; |
michael@0 | 30 | genexpParened = "(" + genexp + ")"; |
michael@0 | 31 | genexpParenedTwice = "(" + genexpParened + ")"; |
michael@0 | 32 | |
michael@0 | 33 | // Warning: be careful not to put [] around stuff, because that would |
michael@0 | 34 | // cause it to be treated as an array comprehension instead of a |
michael@0 | 35 | // generator expression! |
michael@0 | 36 | |
michael@0 | 37 | // Statements |
michael@0 | 38 | doesNotNeedParens(1, "if (xx) { }"); |
michael@0 | 39 | needParens(2, "if (1, xx) { }"); |
michael@0 | 40 | needParens(3, "if (xx, 1) { }"); |
michael@0 | 41 | doesNotNeedParens(4, "do { } while (xx);"); |
michael@0 | 42 | doesNotNeedParens(5, "while (xx) { }"); |
michael@0 | 43 | doesNotNeedParens(6, "switch (xx) { }"); |
michael@0 | 44 | doesNotNeedParens(7, "with (xx) { }"); |
michael@0 | 45 | needParens(8, "switch (x) { case xx: }"); |
michael@0 | 46 | needParens(9, "return xx;"); |
michael@0 | 47 | needParens(10, "yield xx;"); |
michael@0 | 48 | needParens(11, "for (xx;;) { }"); |
michael@0 | 49 | needParens(12, "for (;xx;) { }", "function anonymous() {\n for (;;) {\n }\n}"); |
michael@0 | 50 | needParens(13, "for (;;xx) { }"); |
michael@0 | 51 | needParens(14, "for (i in xx) { }"); |
michael@0 | 52 | needParens(15, "throw xx"); |
michael@0 | 53 | needParens(16, "try { } catch (e if xx) { }"); |
michael@0 | 54 | needParens(17, "let (x=3) xx"); |
michael@0 | 55 | needParens(18, "let (x=xx) 3"); |
michael@0 | 56 | |
michael@0 | 57 | // Function calls |
michael@0 | 58 | doesNotNeedParens(19, "f(xx);"); |
michael@0 | 59 | needParens(20, "f(xx, 1);"); |
michael@0 | 60 | needParens(21, "f(1, xx);"); |
michael@0 | 61 | doesNotNeedParens(22, "/x/(xx);"); |
michael@0 | 62 | needParens(23, "/x/(xx, 1);"); |
michael@0 | 63 | needParens(24, "/x/(1, xx);"); |
michael@0 | 64 | |
michael@0 | 65 | // eval is special and often confuses the decompiler. |
michael@0 | 66 | doesNotNeedParens(25, "eval(xx);"); |
michael@0 | 67 | needParens(26, "eval(xx, 1);"); |
michael@0 | 68 | needParens(27, "eval(1, xx);"); |
michael@0 | 69 | |
michael@0 | 70 | // Expressions |
michael@0 | 71 | needParens(28, "xx;"); // ??? |
michael@0 | 72 | needParens(29, "var g = xx;"); // ??? |
michael@0 | 73 | needParens(30, "g += xx;"); |
michael@0 | 74 | needParens(31, "xx();"); |
michael@0 | 75 | needParens(32, "xx() = 3;"); |
michael@0 | 76 | needParens(33, "a ? xx : c"); |
michael@0 | 77 | needParens(34, "xx ? b : c"); |
michael@0 | 78 | needParens(35, "a ? b : xx"); |
michael@0 | 79 | needParens(36, "1 ? xx : c"); |
michael@0 | 80 | needParens(37, "0 ? b : xx"); |
michael@0 | 81 | needParens(38, "1 + xx"); |
michael@0 | 82 | needParens(39, "xx + 1"); |
michael@0 | 83 | needParens(40, "1, xx"); |
michael@0 | 84 | doesNotNeedParens(41, "+(xx)"); |
michael@0 | 85 | doesNotNeedParens(42, "!(xx)"); |
michael@0 | 86 | needParens(43, "xx, 1"); |
michael@0 | 87 | needParens(44, "[1, xx]"); |
michael@0 | 88 | needParens(45, "[xx, 1]"); |
michael@0 | 89 | needParens(46, "[xx,3]"); |
michael@0 | 90 | needParens(47, "[xx,null]"); |
michael@0 | 91 | needParens(48, "xx.p"); |
michael@0 | 92 | needParens(49, "xx.@p"); |
michael@0 | 93 | needParens(50, "typeof xx;"); |
michael@0 | 94 | needParens(51, "void xx;"); |
michael@0 | 95 | needParens(52, "({ a: xx })"); |
michael@0 | 96 | needParens(53, "({ a: 1, b: xx })"); |
michael@0 | 97 | needParens(54, "({ a: xx, b: 1 })"); |
michael@0 | 98 | needParens(55, "({ a getter: xx })"); |
michael@0 | 99 | needParens(56, "<x a={xx}/>"); |
michael@0 | 100 | doesNotNeedParens(57, "new (xx);"); |
michael@0 | 101 | doesNotNeedParens(58, "new a(xx);"); |
michael@0 | 102 | |
michael@0 | 103 | |
michael@0 | 104 | // Generator expressions cannot be used as LHS, even though they're syntactic |
michael@0 | 105 | // sugar for something that looks a lot like an "lvalue return": (f() = 3). |
michael@0 | 106 | |
michael@0 | 107 | rejectLHS(59, "++ (xx);"); |
michael@0 | 108 | rejectLHS(60, "delete xx;"); |
michael@0 | 109 | rejectLHS(61, "delete (xx);"); |
michael@0 | 110 | rejectLHS(62, "for (xx in []) { }"); |
michael@0 | 111 | rejectLHS(63, "for ((xx) in []) { }"); |
michael@0 | 112 | rejectLHS(64, "try { } catch(xx) { }"); |
michael@0 | 113 | rejectLHS(65, "try { } catch([(xx)]) { }"); |
michael@0 | 114 | rejectLHS(66, "xx += 3;"); |
michael@0 | 115 | rejectLHS(67, "(xx) += 3;"); |
michael@0 | 116 | rejectLHS(68, "xx = 3;"); |
michael@0 | 117 | |
michael@0 | 118 | // Assignment |
michael@0 | 119 | rejectLHS(69, " (xx) = 3;"); |
michael@0 | 120 | rejectLHS(70, "var (xx) = 3;"); |
michael@0 | 121 | rejectLHS(71, "const (xx) = 3;"); |
michael@0 | 122 | rejectLHS(72, "let (xx) = 3;"); |
michael@0 | 123 | |
michael@0 | 124 | // Destructuring assignment |
michael@0 | 125 | rejectLHS(73, " [(xx)] = 3;"); |
michael@0 | 126 | rejectLHS(74, "var [(xx)] = 3;"); |
michael@0 | 127 | rejectLHS(75, "const [(xx)] = 3;"); |
michael@0 | 128 | rejectLHS(76, "let [(xx)] = 3;"); |
michael@0 | 129 | |
michael@0 | 130 | // Group assignment (Spidermonkey optimization for certain |
michael@0 | 131 | // destructuring assignments) |
michael@0 | 132 | rejectLHS(77, " [(xx)] = [3];"); |
michael@0 | 133 | rejectLHS(78, "var [(xx)] = [3];"); |
michael@0 | 134 | rejectLHS(79, "const [(xx)] = [3];"); |
michael@0 | 135 | rejectLHS(80, "let [(xx)] = [3];"); |
michael@0 | 136 | |
michael@0 | 137 | // Destructuring & group assignment for array comprehensions, just for kicks. |
michael@0 | 138 | rejectLHS(81, " [xx] = [3];"); |
michael@0 | 139 | rejectLHS(82, "var [xx] = [3];"); |
michael@0 | 140 | rejectLHS(83, "const [xx] = [3];"); |
michael@0 | 141 | rejectLHS(84, "let [xx] = 3;"); |
michael@0 | 142 | rejectLHS(85, " [xx] = 3;"); |
michael@0 | 143 | rejectLHS(86, "var [xx] = 3;"); |
michael@0 | 144 | rejectLHS(87, "const [xx] = 3;"); |
michael@0 | 145 | rejectLHS(88, "let [xx] = 3;"); |
michael@0 | 146 | |
michael@0 | 147 | // This is crazy, ambiguous, and/or buggy. |
michael@0 | 148 | // See https://bugzilla.mozilla.org/show_bug.cgi?id=380237#c23 et seq. |
michael@0 | 149 | //doesNotNeedParens("(yield xx);"); |
michael@0 | 150 | |
michael@0 | 151 | print("Done!"); |
michael@0 | 152 | |
michael@0 | 153 | function doesNotNeedParens(section, pat) |
michael@0 | 154 | { |
michael@0 | 155 | print("Testing section " + section + " pattern " + pat); |
michael@0 | 156 | |
michael@0 | 157 | var f, ft; |
michael@0 | 158 | sanityCheck(section, pat); |
michael@0 | 159 | |
michael@0 | 160 | expect = 'No Error'; |
michael@0 | 161 | actual = ''; |
michael@0 | 162 | ft = pat.replace(/xx/, genexp); |
michael@0 | 163 | try { |
michael@0 | 164 | f = new Function(ft); |
michael@0 | 165 | actual = 'No Error'; |
michael@0 | 166 | } catch(e) { |
michael@0 | 167 | print("Unparenthesized genexp SHOULD have been accepted here!"); |
michael@0 | 168 | actual = e + ''; |
michael@0 | 169 | } |
michael@0 | 170 | reportCompare(expect, actual, summary + ': doesNotNeedParens section ' + section + ' pattern ' + pat); |
michael@0 | 171 | |
michael@0 | 172 | roundTripTest(section, f); |
michael@0 | 173 | |
michael@0 | 174 | // Make sure the decompilation is not over-parenthesized. |
michael@0 | 175 | var uf = "" + f; |
michael@0 | 176 | if (pat.indexOf("(xx)") != -1) |
michael@0 | 177 | overParenTest(section, f); |
michael@0 | 178 | // else |
michael@0 | 179 | // print("Skipping the over-parenthesization test, because I don't know how to test for over-parenthesization when the pattern doesn't have parens snugly around it.") |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | function needParens(section, pat, exp) |
michael@0 | 183 | { |
michael@0 | 184 | print("Testing section " + section + " pattern " + pat); |
michael@0 | 185 | |
michael@0 | 186 | var f, ft; |
michael@0 | 187 | sanityCheck(section, pat); |
michael@0 | 188 | |
michael@0 | 189 | expect = 'SyntaxError'; |
michael@0 | 190 | actual = ''; |
michael@0 | 191 | ft = pat.replace(/xx/, genexp); |
michael@0 | 192 | try { |
michael@0 | 193 | f = new Function(ft); |
michael@0 | 194 | print("Unparenthesized genexp should NOT have been accepted here!"); |
michael@0 | 195 | } catch(e) { |
michael@0 | 196 | /* expected to throw */ |
michael@0 | 197 | actual = e.name; |
michael@0 | 198 | } |
michael@0 | 199 | reportCompare(expect, actual, summary + ': needParens section ' + section + ' pattern ' + pat); |
michael@0 | 200 | |
michael@0 | 201 | expect = 'No Error'; |
michael@0 | 202 | actual = ''; |
michael@0 | 203 | ft = pat.replace(/xx/, genexpParened); |
michael@0 | 204 | try { |
michael@0 | 205 | f = new Function(ft); |
michael@0 | 206 | actual = 'No Error'; |
michael@0 | 207 | } catch(e) { |
michael@0 | 208 | print("Yikes!"); |
michael@0 | 209 | actual = e + ''; |
michael@0 | 210 | } |
michael@0 | 211 | reportCompare(expect, actual, summary + ': needParens section ' + section + ' ft ' + ft); |
michael@0 | 212 | |
michael@0 | 213 | roundTripTest(section, f, exp); |
michael@0 | 214 | overParenTest(section, f, exp); |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | function rejectLHS(section, pat) |
michael@0 | 218 | { |
michael@0 | 219 | print("Testing section " + section + " pattern " + pat); |
michael@0 | 220 | |
michael@0 | 221 | // sanityCheck(pat); // because 'z' should be accepted as an LHS or binding |
michael@0 | 222 | |
michael@0 | 223 | var ft; |
michael@0 | 224 | |
michael@0 | 225 | expect = 'SyntaxError'; |
michael@0 | 226 | actual = ''; |
michael@0 | 227 | ft = pat.replace(/xx/, genexp) |
michael@0 | 228 | try { |
michael@0 | 229 | new Function(ft); |
michael@0 | 230 | print("That should have been a syntax error!"); |
michael@0 | 231 | actual = 'No Error'; |
michael@0 | 232 | } catch(e) { |
michael@0 | 233 | actual = e.name; |
michael@0 | 234 | } |
michael@0 | 235 | reportCompare(expect, actual, summary + ': rejectLHS section ' + section); |
michael@0 | 236 | } |
michael@0 | 237 | |
michael@0 | 238 | |
michael@0 | 239 | function overParenTest(section, f, exp) |
michael@0 | 240 | { |
michael@0 | 241 | var uf = "" + f; |
michael@0 | 242 | if (uf == exp) |
michael@0 | 243 | return; |
michael@0 | 244 | |
michael@0 | 245 | reportCompare(false, uf.indexOf(genexpParened) == -1, summary + |
michael@0 | 246 | ': overParenTest genexp snugly in parentheses: section ' + section + ' uf ' + uf); |
michael@0 | 247 | |
michael@0 | 248 | if (uf.indexOf(genexpParened) != -1) { |
michael@0 | 249 | reportCompare(true, uf.indexOf(genexpParenedTwice) == -1, summary + |
michael@0 | 250 | ': overParensTest decompilation should not be over-parenthesized: section ' + ' uf ' + uf); |
michael@0 | 251 | } |
michael@0 | 252 | } |
michael@0 | 253 | |
michael@0 | 254 | function sanityCheck(section, pat) |
michael@0 | 255 | { |
michael@0 | 256 | expect = ''; |
michael@0 | 257 | actual = ''; |
michael@0 | 258 | |
michael@0 | 259 | if (pat.indexOf("xx") == -1) |
michael@0 | 260 | { |
michael@0 | 261 | actual += "No 'xx' in this pattern? "; |
michael@0 | 262 | } |
michael@0 | 263 | |
michael@0 | 264 | var f, ft; |
michael@0 | 265 | ft = pat.replace(/xx/, "z"); |
michael@0 | 266 | try { |
michael@0 | 267 | f = new Function(ft); |
michael@0 | 268 | } catch(e) { |
michael@0 | 269 | actual += "Yowzers! Probably a bogus test!"; |
michael@0 | 270 | } |
michael@0 | 271 | reportCompare(expect, actual, summary + ': sanityCheck section ' + section + ' pattern ' + pat); |
michael@0 | 272 | } |
michael@0 | 273 | |
michael@0 | 274 | function roundTripTest(section, f, exp) |
michael@0 | 275 | { |
michael@0 | 276 | // Decompile |
michael@0 | 277 | var uf = "" + f; |
michael@0 | 278 | |
michael@0 | 279 | // Recompile |
michael@0 | 280 | expect = 'No Error'; |
michael@0 | 281 | actual = ''; |
michael@0 | 282 | var euf; |
michael@0 | 283 | try { |
michael@0 | 284 | euf = eval("(" + uf + ")"); |
michael@0 | 285 | actual = 'No Error'; |
michael@0 | 286 | reportCompare(expect, actual, summary + ': roundTripTest: section ' + section + ' uf ' + uf); |
michael@0 | 287 | } catch(e) { |
michael@0 | 288 | actual = e + ''; |
michael@0 | 289 | reportCompare(expect, actual, summary + ': roundTripTest: section ' + section + ' uf ' + uf); |
michael@0 | 290 | return; |
michael@0 | 291 | } |
michael@0 | 292 | |
michael@0 | 293 | // Decompile again and make sure the decompilations match exactly. |
michael@0 | 294 | expect = exp || uf; |
michael@0 | 295 | actual = "" + euf; |
michael@0 | 296 | reportCompare(expect, actual, summary + ': roundTripTest no round-trip change: section ' + section); |
michael@0 | 297 | } |