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 | load(libdir + 'array-compare.js'); |
michael@0 | 2 | |
michael@0 | 3 | function compareIAndSet(v) { |
michael@0 | 4 | var res = 0; |
michael@0 | 5 | var c; |
michael@0 | 6 | var i = 0; |
michael@0 | 7 | c = (v > 1); |
michael@0 | 8 | res |= (c << i); |
michael@0 | 9 | i++; |
michael@0 | 10 | c = (v >= 2); |
michael@0 | 11 | res |= (c << i); |
michael@0 | 12 | i++; |
michael@0 | 13 | c = (v < 3); |
michael@0 | 14 | res |= (c << i); |
michael@0 | 15 | i++; |
michael@0 | 16 | c = (v <= 4); |
michael@0 | 17 | res |= (c << i); |
michael@0 | 18 | i++; |
michael@0 | 19 | c = (v == 5); |
michael@0 | 20 | res |= (c << i); |
michael@0 | 21 | i++; |
michael@0 | 22 | c = (v != 6); |
michael@0 | 23 | res |= (c << i); |
michael@0 | 24 | i++; |
michael@0 | 25 | c = (v === 7); |
michael@0 | 26 | res |= (c << i); |
michael@0 | 27 | i++; |
michael@0 | 28 | c = (v !== 8); |
michael@0 | 29 | res |= (c << i); |
michael@0 | 30 | i++; |
michael@0 | 31 | return res; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function compareIAndBranch(v) { |
michael@0 | 35 | var res = 0; |
michael@0 | 36 | var c = 1; |
michael@0 | 37 | var i = 0; |
michael@0 | 38 | if (v > 1) |
michael@0 | 39 | res |= (c << i); |
michael@0 | 40 | i++; |
michael@0 | 41 | if (v >= 2) |
michael@0 | 42 | res |= (c << i); |
michael@0 | 43 | i++; |
michael@0 | 44 | if (v < 3) |
michael@0 | 45 | res |= (c << i); |
michael@0 | 46 | i++; |
michael@0 | 47 | if (v <= 4) |
michael@0 | 48 | res |= (c << i); |
michael@0 | 49 | i++; |
michael@0 | 50 | if (v == 5) |
michael@0 | 51 | res |= (c << i); |
michael@0 | 52 | i++; |
michael@0 | 53 | if (v != 6) |
michael@0 | 54 | res |= (c << i); |
michael@0 | 55 | i++; |
michael@0 | 56 | if (v === 7) |
michael@0 | 57 | res |= (c << i); |
michael@0 | 58 | i++; |
michael@0 | 59 | if (v !== 8) |
michael@0 | 60 | res |= (c << i); |
michael@0 | 61 | i++; |
michael@0 | 62 | if (v) |
michael@0 | 63 | res |= (c << i); |
michael@0 | 64 | i++; |
michael@0 | 65 | return res; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | function compareDAndSet(v) { |
michael@0 | 69 | var res = 0; |
michael@0 | 70 | var c; |
michael@0 | 71 | var i = 0; |
michael@0 | 72 | c = (v > 1.5); |
michael@0 | 73 | res |= (c << i); |
michael@0 | 74 | i++; |
michael@0 | 75 | c = (v >= 2.5); |
michael@0 | 76 | res |= (c << i); |
michael@0 | 77 | i++; |
michael@0 | 78 | c = (v < 3.5); |
michael@0 | 79 | res |= (c << i); |
michael@0 | 80 | i++; |
michael@0 | 81 | c = (v <= 4.5); |
michael@0 | 82 | res |= (c << i); |
michael@0 | 83 | i++; |
michael@0 | 84 | c = (v == 5.5); |
michael@0 | 85 | res |= (c << i); |
michael@0 | 86 | i++; |
michael@0 | 87 | c = (v != 6.5); |
michael@0 | 88 | res |= (c << i); |
michael@0 | 89 | i++; |
michael@0 | 90 | c = (v === 7.5); |
michael@0 | 91 | res |= (c << i); |
michael@0 | 92 | i++; |
michael@0 | 93 | c = (v !== 8.5); |
michael@0 | 94 | res |= (c << i); |
michael@0 | 95 | i++; |
michael@0 | 96 | c = (v !== 0.0); |
michael@0 | 97 | res |= (c << i); |
michael@0 | 98 | i++; |
michael@0 | 99 | return res; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | function compareDAndBranch(v) { |
michael@0 | 103 | var res = 0; |
michael@0 | 104 | var c = 1; |
michael@0 | 105 | var i = 0; |
michael@0 | 106 | if (v > 1.5) |
michael@0 | 107 | res |= (c << i); |
michael@0 | 108 | i++; |
michael@0 | 109 | if (v >= 2.5) |
michael@0 | 110 | res |= (c << i); |
michael@0 | 111 | i++; |
michael@0 | 112 | if (v < 3.5) |
michael@0 | 113 | res |= (c << i); |
michael@0 | 114 | i++; |
michael@0 | 115 | if (v <= 4.5) |
michael@0 | 116 | res |= (c << i); |
michael@0 | 117 | i++; |
michael@0 | 118 | if (v == 5.5) |
michael@0 | 119 | res |= (c << i); |
michael@0 | 120 | i++; |
michael@0 | 121 | if (v != 6.5) |
michael@0 | 122 | res |= (c << i); |
michael@0 | 123 | i++; |
michael@0 | 124 | if (v === 7.5) |
michael@0 | 125 | res |= (c << i); |
michael@0 | 126 | i++; |
michael@0 | 127 | if (v !== 8.5) |
michael@0 | 128 | res |= (c << i); |
michael@0 | 129 | i++; |
michael@0 | 130 | if (v) |
michael@0 | 131 | res |= (c << i); |
michael@0 | 132 | i++; |
michael@0 | 133 | return res; |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | function compareSAndSet(v) { |
michael@0 | 137 | var res = 0; |
michael@0 | 138 | var c; |
michael@0 | 139 | var i = 0; |
michael@0 | 140 | c = (v > "a"); |
michael@0 | 141 | res |= (c << i); |
michael@0 | 142 | i++; |
michael@0 | 143 | c = (v >= "b"); |
michael@0 | 144 | res |= (c << i); |
michael@0 | 145 | i++; |
michael@0 | 146 | c = (v < "c"); |
michael@0 | 147 | res |= (c << i); |
michael@0 | 148 | i++; |
michael@0 | 149 | c = (v <= "d"); |
michael@0 | 150 | res |= (c << i); |
michael@0 | 151 | i++; |
michael@0 | 152 | c = (v == "e"); |
michael@0 | 153 | res |= (c << i); |
michael@0 | 154 | i++; |
michael@0 | 155 | c = (v != "f"); |
michael@0 | 156 | res |= (c << i); |
michael@0 | 157 | i++; |
michael@0 | 158 | c = (v === "g"); |
michael@0 | 159 | res |= (c << i); |
michael@0 | 160 | i++; |
michael@0 | 161 | c = (v !== "h"); |
michael@0 | 162 | res |= (c << i); |
michael@0 | 163 | i++; |
michael@0 | 164 | return res; |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | function compareSAndBranch(v) { |
michael@0 | 168 | var res = 0; |
michael@0 | 169 | var c = 1; |
michael@0 | 170 | var i = 0; |
michael@0 | 171 | if (v > "a") |
michael@0 | 172 | res |= (c << i); |
michael@0 | 173 | i++; |
michael@0 | 174 | if (v >= "b") |
michael@0 | 175 | res |= (c << i); |
michael@0 | 176 | i++; |
michael@0 | 177 | if (v < "c") |
michael@0 | 178 | res |= (c << i); |
michael@0 | 179 | i++; |
michael@0 | 180 | if (v <= "d") |
michael@0 | 181 | res |= (c << i); |
michael@0 | 182 | i++; |
michael@0 | 183 | if (v == "e") |
michael@0 | 184 | res |= (c << i); |
michael@0 | 185 | i++; |
michael@0 | 186 | if (v != "f") |
michael@0 | 187 | res |= (c << i); |
michael@0 | 188 | i++; |
michael@0 | 189 | if (v === "g") |
michael@0 | 190 | res |= (c << i); |
michael@0 | 191 | i++; |
michael@0 | 192 | if (v !== "h") |
michael@0 | 193 | res |= (c << i); |
michael@0 | 194 | i++; |
michael@0 | 195 | if (v) |
michael@0 | 196 | res |= (c << i); |
michael@0 | 197 | i++; |
michael@0 | 198 | return res; |
michael@0 | 199 | } |
michael@0 | 200 | |
michael@0 | 201 | var expected = [ |
michael@0 | 202 | // compareIAndSet |
michael@0 | 203 | 172, 175, 171, 171, 179, 131, 227, 35, |
michael@0 | 204 | // compareIAndBranch |
michael@0 | 205 | 428, 431, 427, 427, 435, 387, 483, 291, |
michael@0 | 206 | // compareDAndSet |
michael@0 | 207 | 428, 428, 431, 427, 427, 435, 387, 483, 291, 416, |
michael@0 | 208 | // compareDAndBranch |
michael@0 | 209 | 428, 428, 431, 427, 427, 435, 387, 483, 291, 160, 172, |
michael@0 | 210 | // compareSAndSet |
michael@0 | 211 | 172, 175, 171, 171, 179, 131, 227, 35, 172, |
michael@0 | 212 | // compareSAndBranch |
michael@0 | 213 | 428, 431, 427, 427, 435, 387, 483, 291, 172 |
michael@0 | 214 | ]; |
michael@0 | 215 | |
michael@0 | 216 | var result = [ |
michael@0 | 217 | compareIAndSet(1), |
michael@0 | 218 | compareIAndSet(2), |
michael@0 | 219 | compareIAndSet(3), |
michael@0 | 220 | compareIAndSet(4), |
michael@0 | 221 | compareIAndSet(5), |
michael@0 | 222 | compareIAndSet(6), |
michael@0 | 223 | compareIAndSet(7), |
michael@0 | 224 | compareIAndSet(8), |
michael@0 | 225 | |
michael@0 | 226 | compareIAndBranch(1), |
michael@0 | 227 | compareIAndBranch(2), |
michael@0 | 228 | compareIAndBranch(3), |
michael@0 | 229 | compareIAndBranch(4), |
michael@0 | 230 | compareIAndBranch(5), |
michael@0 | 231 | compareIAndBranch(6), |
michael@0 | 232 | compareIAndBranch(7), |
michael@0 | 233 | compareIAndBranch(8), |
michael@0 | 234 | |
michael@0 | 235 | compareDAndSet(0.5), |
michael@0 | 236 | compareDAndSet(1.5), |
michael@0 | 237 | compareDAndSet(2.5), |
michael@0 | 238 | compareDAndSet(3.5), |
michael@0 | 239 | compareDAndSet(4.5), |
michael@0 | 240 | compareDAndSet(5.5), |
michael@0 | 241 | compareDAndSet(6.5), |
michael@0 | 242 | compareDAndSet(7.5), |
michael@0 | 243 | compareDAndSet(8.5), |
michael@0 | 244 | compareDAndSet(NaN), |
michael@0 | 245 | |
michael@0 | 246 | compareDAndBranch(0.5), |
michael@0 | 247 | compareDAndBranch(1.5), |
michael@0 | 248 | compareDAndBranch(2.5), |
michael@0 | 249 | compareDAndBranch(3.5), |
michael@0 | 250 | compareDAndBranch(4.5), |
michael@0 | 251 | compareDAndBranch(5.5), |
michael@0 | 252 | compareDAndBranch(6.5), |
michael@0 | 253 | compareDAndBranch(7.5), |
michael@0 | 254 | compareDAndBranch(8.5), |
michael@0 | 255 | compareDAndBranch(NaN), |
michael@0 | 256 | compareDAndBranch(0.0), |
michael@0 | 257 | |
michael@0 | 258 | compareSAndSet("a"), |
michael@0 | 259 | compareSAndSet("b"), |
michael@0 | 260 | compareSAndSet("c"), |
michael@0 | 261 | compareSAndSet("d"), |
michael@0 | 262 | compareSAndSet("e"), |
michael@0 | 263 | compareSAndSet("f"), |
michael@0 | 264 | compareSAndSet("g"), |
michael@0 | 265 | compareSAndSet("h"), |
michael@0 | 266 | compareSAndSet(""), |
michael@0 | 267 | |
michael@0 | 268 | compareSAndBranch("a"), |
michael@0 | 269 | compareSAndBranch("b"), |
michael@0 | 270 | compareSAndBranch("c"), |
michael@0 | 271 | compareSAndBranch("d"), |
michael@0 | 272 | compareSAndBranch("e"), |
michael@0 | 273 | compareSAndBranch("f"), |
michael@0 | 274 | compareSAndBranch("g"), |
michael@0 | 275 | compareSAndBranch("h"), |
michael@0 | 276 | compareSAndBranch("") |
michael@0 | 277 | ]; |
michael@0 | 278 | |
michael@0 | 279 | assertEq(arraysEqual(result, expected), true); |