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 | // 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 = 886949; |
michael@0 | 6 | var summary = "ES6 (draft May 2013) 15.7.3.9 Number.parseInt(string, radix)"; |
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 str, radix; |
michael@0 | 15 | var upvar; |
michael@0 | 16 | |
michael@0 | 17 | /* 1. Let inputString be ToString(string). */ |
michael@0 | 18 | |
michael@0 | 19 | assertEq(Number.parseInt({ toString: function() { return "17" } }, 10), 17); |
michael@0 | 20 | |
michael@0 | 21 | upvar = 0; |
michael@0 | 22 | str = { get toString() { upvar++; return function() { upvar++; return "12345"; } } }; |
michael@0 | 23 | assertEq(Number.parseInt(str, 10), 12345); |
michael@0 | 24 | assertEq(upvar, 2); |
michael@0 | 25 | |
michael@0 | 26 | |
michael@0 | 27 | /* |
michael@0 | 28 | * 2. Let S be a newly created substring of inputString consisting of the first |
michael@0 | 29 | * character that is not a StrWhiteSpaceChar and all characters following |
michael@0 | 30 | * that character. (In other words, remove leading white space.) |
michael@0 | 31 | */ |
michael@0 | 32 | |
michael@0 | 33 | var ws = |
michael@0 | 34 | ["\t", "\v", "\f", " ", "\xA0", "\uFEFF", |
michael@0 | 35 | "\u2004", "\u3000", // a few Unicode whitespaces |
michael@0 | 36 | "\r", "\n", "\u2028", "\u2029"]; |
michael@0 | 37 | |
michael@0 | 38 | str = "8675309"; |
michael@0 | 39 | for (var i = 0, sz = ws.length; i < sz; i++) |
michael@0 | 40 | { |
michael@0 | 41 | assertEq(Number.parseInt(ws[i] + str, 10), 8675309); |
michael@0 | 42 | for (var j = 0, sz = ws.length; j < sz; j++) |
michael@0 | 43 | { |
michael@0 | 44 | assertEq(Number.parseInt(ws[i] + ws[j] + str, 10), 8675309, |
michael@0 | 45 | ws[i].charCodeAt(0).toString(16) + ", " + |
michael@0 | 46 | ws[j].charCodeAt(0).toString(16)); |
michael@0 | 47 | } |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | |
michael@0 | 51 | /* |
michael@0 | 52 | * 3. Let sign be 1. |
michael@0 | 53 | * 4. If S is not empty and the first character of S is a minus sign -, let |
michael@0 | 54 | * sign be −1. |
michael@0 | 55 | */ |
michael@0 | 56 | str = "5552368"; |
michael@0 | 57 | assertEq(Number.parseInt("-" + str, 10), -Number.parseInt(str, 10)); |
michael@0 | 58 | assertEq(Number.parseInt(" -" + str, 10), -Number.parseInt(str, 10)); |
michael@0 | 59 | assertEq(Number.parseInt("-", 10), NaN); |
michael@0 | 60 | assertEq(Number.parseInt("", 10), NaN); |
michael@0 | 61 | assertEq(Number.parseInt("-0", 10), -0); |
michael@0 | 62 | |
michael@0 | 63 | |
michael@0 | 64 | /* |
michael@0 | 65 | * 5. If S is not empty and the first character of S is a plus sign + or a |
michael@0 | 66 | * minus sign -, then remove the first character from S. |
michael@0 | 67 | */ |
michael@0 | 68 | assertEq(Number.parseInt("+12345", 10), 12345); |
michael@0 | 69 | assertEq(Number.parseInt(" +12345", 10), 12345); |
michael@0 | 70 | assertEq(Number.parseInt("-12345", 10), -12345); |
michael@0 | 71 | assertEq(Number.parseInt(" -12345", 10), -12345); |
michael@0 | 72 | |
michael@0 | 73 | |
michael@0 | 74 | /* |
michael@0 | 75 | * 6. Let R = ToInt32(radix). |
michael@0 | 76 | */ |
michael@0 | 77 | |
michael@0 | 78 | upvar = ""; |
michael@0 | 79 | str = |
michael@0 | 80 | { toString: function() { if (!upvar) upvar = "string"; return "42"; } }; |
michael@0 | 81 | radix = |
michael@0 | 82 | { toString: function() { if (!upvar) upvar = "radix"; return "10"; } }; |
michael@0 | 83 | |
michael@0 | 84 | assertEq(Number.parseInt(str, radix), 42); |
michael@0 | 85 | assertEq(upvar, "string"); |
michael@0 | 86 | |
michael@0 | 87 | assertEq(Number.parseInt("123", null), 123); |
michael@0 | 88 | assertEq(Number.parseInt("123", undefined), 123); |
michael@0 | 89 | assertEq(Number.parseInt("123", NaN), 123); |
michael@0 | 90 | assertEq(Number.parseInt("123", -0), 123); |
michael@0 | 91 | assertEq(Number.parseInt("10", 72057594037927950), 16); |
michael@0 | 92 | assertEq(Number.parseInt("10", -4294967292), 4); |
michael@0 | 93 | assertEq(Number.parseInt("0x10", 1e308), 16); |
michael@0 | 94 | assertEq(Number.parseInt("10", 1e308), 10); |
michael@0 | 95 | assertEq(Number.parseInt("10", { valueOf: function() { return 16; } }), 16); |
michael@0 | 96 | |
michael@0 | 97 | |
michael@0 | 98 | /* |
michael@0 | 99 | * 7. Let stripPrefix be true. |
michael@0 | 100 | * 8. If R ≠ 0, then |
michael@0 | 101 | * a. If R < 2 or R > 36, then return NaN. |
michael@0 | 102 | * b. If R ≠ 16, let stripPrefix be false. |
michael@0 | 103 | * 9. Else, R = 0 |
michael@0 | 104 | * a. Let R = 10. |
michael@0 | 105 | * 10. If stripPrefix is true, then |
michael@0 | 106 | * a. If the length of S is at least 2 and the first two characters of S |
michael@0 | 107 | * are either “0x” or “0X”, then remove the first two characters from S and |
michael@0 | 108 | * let R = 16. |
michael@0 | 109 | */ |
michael@0 | 110 | var vs = ["1", "51", "917", "2343", "99963"]; |
michael@0 | 111 | for (var i = 0, sz = vs.length; i < sz; i++) |
michael@0 | 112 | assertEq(Number.parseInt(vs[i], 0), Number.parseInt(vs[i], 10), "bad " + vs[i]); |
michael@0 | 113 | |
michael@0 | 114 | assertEq(Number.parseInt("0x10"), 16); |
michael@0 | 115 | assertEq(Number.parseInt("0x10", 0), 16); |
michael@0 | 116 | assertEq(Number.parseInt("0x10", 16), 16); |
michael@0 | 117 | assertEq(Number.parseInt("0x10", 8), 0); |
michael@0 | 118 | assertEq(Number.parseInt("-0x10", 16), -16); |
michael@0 | 119 | |
michael@0 | 120 | assertEq(Number.parseInt("5", 1), NaN); |
michael@0 | 121 | assertEq(Number.parseInt("5", 37), NaN); |
michael@0 | 122 | assertEq(Number.parseInt("5", { valueOf: function() { return -1; } }), NaN); |
michael@0 | 123 | |
michael@0 | 124 | |
michael@0 | 125 | /* |
michael@0 | 126 | * 11. If S contains any character that is not a radix-R digit, then let Z be |
michael@0 | 127 | * the substring of S consisting of all characters before the first such |
michael@0 | 128 | * character; otherwise, let Z be S. |
michael@0 | 129 | * 12. If Z is empty, return NaN. |
michael@0 | 130 | */ |
michael@0 | 131 | assertEq(Number.parseInt(""), NaN); |
michael@0 | 132 | assertEq(Number.parseInt("ohai"), NaN); |
michael@0 | 133 | assertEq(Number.parseInt("0xohai"), NaN); |
michael@0 | 134 | assertEq(Number.parseInt("-ohai"), NaN); |
michael@0 | 135 | assertEq(Number.parseInt("+ohai"), NaN); |
michael@0 | 136 | assertEq(Number.parseInt(" ohai"), NaN); |
michael@0 | 137 | |
michael@0 | 138 | assertEq(Number.parseInt("0xaohai"), 10); |
michael@0 | 139 | assertEq(Number.parseInt("hohai", 18), 17); |
michael@0 | 140 | |
michael@0 | 141 | |
michael@0 | 142 | /* |
michael@0 | 143 | * 13. Let mathInt be the mathematical integer value that is represented by Z |
michael@0 | 144 | * in radix-R notation, using the letters A-Z and a-z for digits with |
michael@0 | 145 | * values 10 through 35. (However, if R is 10 and Z contains more than 20 |
michael@0 | 146 | * significant digits, every significant digit after the 20th may be |
michael@0 | 147 | * replaced by a 0 digit, at the option of the implementation; and if R is |
michael@0 | 148 | * not 2, 4, 8, 10, 16, or 32, then mathInt may be an implementation- |
michael@0 | 149 | * dependent approximation to the mathematical integer value that is |
michael@0 | 150 | * represented by Z in radix-R notation.) |
michael@0 | 151 | * 14. Let number be the Number value for mathInt. |
michael@0 | 152 | * 15. Return sign × number. |
michael@0 | 153 | */ |
michael@0 | 154 | assertEq(Number.parseInt("ohai", 36), 1142154); |
michael@0 | 155 | assertEq(Number.parseInt("0ohai", 36), 1142154); |
michael@0 | 156 | assertEq(Number.parseInt("00ohai", 36), 1142154); |
michael@0 | 157 | assertEq(Number.parseInt("A", 16), 10); |
michael@0 | 158 | assertEq(Number.parseInt("0A", 16), 10); |
michael@0 | 159 | assertEq(Number.parseInt("00A", 16), 10); |
michael@0 | 160 | assertEq(Number.parseInt("A", 17), 10); |
michael@0 | 161 | assertEq(Number.parseInt("0A", 17), 10); |
michael@0 | 162 | assertEq(Number.parseInt("00A", 17), 10); |
michael@0 | 163 | |
michael@0 | 164 | |
michael@0 | 165 | /******************************************************************************/ |
michael@0 | 166 | |
michael@0 | 167 | if (typeof reportCompare === "function") |
michael@0 | 168 | reportCompare(true, true); |
michael@0 | 169 | |
michael@0 | 170 | print("All tests passed!"); |