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 | /* |
michael@0 | 2 | * Copyright (c) 2013 Mathias Bynens. All rights reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
michael@0 | 5 | * copy of this software and associated documentation files (the "Software"), |
michael@0 | 6 | * to deal in the Software without restriction, including without limitation |
michael@0 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
michael@0 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
michael@0 | 9 | * Software is furnished to do so, subject to the following conditions: |
michael@0 | 10 | * |
michael@0 | 11 | * The above copyright notice and this permission notice shall be included in |
michael@0 | 12 | * all copies or substantial portions of the Software. |
michael@0 | 13 | * |
michael@0 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
michael@0 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
michael@0 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
michael@0 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
michael@0 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
michael@0 | 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
michael@0 | 20 | * DEALINGS IN THE SOFTWARE. |
michael@0 | 21 | */ |
michael@0 | 22 | |
michael@0 | 23 | function assertThrows(fun, errorType) { |
michael@0 | 24 | try { |
michael@0 | 25 | fun(); |
michael@0 | 26 | assertEq(true, false, "Expected error, but none was thrown"); |
michael@0 | 27 | } catch (e) { |
michael@0 | 28 | assertEq(e instanceof errorType, true, "Wrong error type thrown"); |
michael@0 | 29 | } |
michael@0 | 30 | } |
michael@0 | 31 | assertEq(String.prototype.endsWith.length, 1); |
michael@0 | 32 | assertEq(String.prototype.propertyIsEnumerable('endsWith'), false); |
michael@0 | 33 | |
michael@0 | 34 | assertEq('undefined'.endsWith(), true); |
michael@0 | 35 | assertEq('undefined'.endsWith(undefined), true); |
michael@0 | 36 | assertEq('undefined'.endsWith(null), false); |
michael@0 | 37 | assertEq('null'.endsWith(), false); |
michael@0 | 38 | assertEq('null'.endsWith(undefined), false); |
michael@0 | 39 | assertEq('null'.endsWith(null), true); |
michael@0 | 40 | |
michael@0 | 41 | assertEq('abc'.endsWith(), false); |
michael@0 | 42 | assertEq('abc'.endsWith(''), true); |
michael@0 | 43 | assertEq('abc'.endsWith('\0'), false); |
michael@0 | 44 | assertEq('abc'.endsWith('c'), true); |
michael@0 | 45 | assertEq('abc'.endsWith('b'), false); |
michael@0 | 46 | assertEq('abc'.endsWith('a'), false); |
michael@0 | 47 | assertEq('abc'.endsWith('ab'), false); |
michael@0 | 48 | assertEq('abc'.endsWith('bc'), true); |
michael@0 | 49 | assertEq('abc'.endsWith('abc'), true); |
michael@0 | 50 | assertEq('abc'.endsWith('bcd'), false); |
michael@0 | 51 | assertEq('abc'.endsWith('abcd'), false); |
michael@0 | 52 | assertEq('abc'.endsWith('bcde'), false); |
michael@0 | 53 | |
michael@0 | 54 | assertEq('abc'.endsWith('', NaN), true); |
michael@0 | 55 | assertEq('abc'.endsWith('\0', NaN), false); |
michael@0 | 56 | assertEq('abc'.endsWith('c', NaN), false); |
michael@0 | 57 | assertEq('abc'.endsWith('b', NaN), false); |
michael@0 | 58 | assertEq('abc'.endsWith('a', NaN), false); |
michael@0 | 59 | assertEq('abc'.endsWith('ab', NaN), false); |
michael@0 | 60 | assertEq('abc'.endsWith('bc', NaN), false); |
michael@0 | 61 | assertEq('abc'.endsWith('abc', NaN), false); |
michael@0 | 62 | assertEq('abc'.endsWith('bcd', NaN), false); |
michael@0 | 63 | assertEq('abc'.endsWith('abcd', NaN), false); |
michael@0 | 64 | assertEq('abc'.endsWith('bcde', NaN), false); |
michael@0 | 65 | |
michael@0 | 66 | assertEq('abc'.endsWith('', false), true); |
michael@0 | 67 | assertEq('abc'.endsWith('\0', false), false); |
michael@0 | 68 | assertEq('abc'.endsWith('c', false), false); |
michael@0 | 69 | assertEq('abc'.endsWith('b', false), false); |
michael@0 | 70 | assertEq('abc'.endsWith('a', false), false); |
michael@0 | 71 | assertEq('abc'.endsWith('ab', false), false); |
michael@0 | 72 | assertEq('abc'.endsWith('bc', false), false); |
michael@0 | 73 | assertEq('abc'.endsWith('abc', false), false); |
michael@0 | 74 | assertEq('abc'.endsWith('bcd', false), false); |
michael@0 | 75 | assertEq('abc'.endsWith('abcd', false), false); |
michael@0 | 76 | assertEq('abc'.endsWith('bcde', false), false); |
michael@0 | 77 | |
michael@0 | 78 | assertEq('abc'.endsWith('', undefined), true); |
michael@0 | 79 | assertEq('abc'.endsWith('\0', undefined), false); |
michael@0 | 80 | assertEq('abc'.endsWith('c', undefined), true); |
michael@0 | 81 | assertEq('abc'.endsWith('b', undefined), false); |
michael@0 | 82 | assertEq('abc'.endsWith('a', undefined), false); |
michael@0 | 83 | assertEq('abc'.endsWith('ab', undefined), false); |
michael@0 | 84 | assertEq('abc'.endsWith('bc', undefined), true); |
michael@0 | 85 | assertEq('abc'.endsWith('abc', undefined), true); |
michael@0 | 86 | assertEq('abc'.endsWith('bcd', undefined), false); |
michael@0 | 87 | assertEq('abc'.endsWith('abcd', undefined), false); |
michael@0 | 88 | assertEq('abc'.endsWith('bcde', undefined), false); |
michael@0 | 89 | |
michael@0 | 90 | assertEq('abc'.endsWith('', null), true); |
michael@0 | 91 | assertEq('abc'.endsWith('\0', null), false); |
michael@0 | 92 | assertEq('abc'.endsWith('c', null), false); |
michael@0 | 93 | assertEq('abc'.endsWith('b', null), false); |
michael@0 | 94 | assertEq('abc'.endsWith('a', null), false); |
michael@0 | 95 | assertEq('abc'.endsWith('ab', null), false); |
michael@0 | 96 | assertEq('abc'.endsWith('bc', null), false); |
michael@0 | 97 | assertEq('abc'.endsWith('abc', null), false); |
michael@0 | 98 | assertEq('abc'.endsWith('bcd', null), false); |
michael@0 | 99 | assertEq('abc'.endsWith('abcd', null), false); |
michael@0 | 100 | assertEq('abc'.endsWith('bcde', null), false); |
michael@0 | 101 | |
michael@0 | 102 | assertEq('abc'.endsWith('', -Infinity), true); |
michael@0 | 103 | assertEq('abc'.endsWith('\0', -Infinity), false); |
michael@0 | 104 | assertEq('abc'.endsWith('c', -Infinity), false); |
michael@0 | 105 | assertEq('abc'.endsWith('b', -Infinity), false); |
michael@0 | 106 | assertEq('abc'.endsWith('a', -Infinity), false); |
michael@0 | 107 | assertEq('abc'.endsWith('ab', -Infinity), false); |
michael@0 | 108 | assertEq('abc'.endsWith('bc', -Infinity), false); |
michael@0 | 109 | assertEq('abc'.endsWith('abc', -Infinity), false); |
michael@0 | 110 | assertEq('abc'.endsWith('bcd', -Infinity), false); |
michael@0 | 111 | assertEq('abc'.endsWith('abcd', -Infinity), false); |
michael@0 | 112 | assertEq('abc'.endsWith('bcde', -Infinity), false); |
michael@0 | 113 | |
michael@0 | 114 | assertEq('abc'.endsWith('', -1), true); |
michael@0 | 115 | assertEq('abc'.endsWith('\0', -1), false); |
michael@0 | 116 | assertEq('abc'.endsWith('c', -1), false); |
michael@0 | 117 | assertEq('abc'.endsWith('b', -1), false); |
michael@0 | 118 | assertEq('abc'.endsWith('a', -1), false); |
michael@0 | 119 | assertEq('abc'.endsWith('ab', -1), false); |
michael@0 | 120 | assertEq('abc'.endsWith('bc', -1), false); |
michael@0 | 121 | assertEq('abc'.endsWith('abc', -1), false); |
michael@0 | 122 | assertEq('abc'.endsWith('bcd', -1), false); |
michael@0 | 123 | assertEq('abc'.endsWith('abcd', -1), false); |
michael@0 | 124 | assertEq('abc'.endsWith('bcde', -1), false); |
michael@0 | 125 | |
michael@0 | 126 | assertEq('abc'.endsWith('', -0), true); |
michael@0 | 127 | assertEq('abc'.endsWith('\0', -0), false); |
michael@0 | 128 | assertEq('abc'.endsWith('c', -0), false); |
michael@0 | 129 | assertEq('abc'.endsWith('b', -0), false); |
michael@0 | 130 | assertEq('abc'.endsWith('a', -0), false); |
michael@0 | 131 | assertEq('abc'.endsWith('ab', -0), false); |
michael@0 | 132 | assertEq('abc'.endsWith('bc', -0), false); |
michael@0 | 133 | assertEq('abc'.endsWith('abc', -0), false); |
michael@0 | 134 | assertEq('abc'.endsWith('bcd', -0), false); |
michael@0 | 135 | assertEq('abc'.endsWith('abcd', -0), false); |
michael@0 | 136 | assertEq('abc'.endsWith('bcde', -0), false); |
michael@0 | 137 | |
michael@0 | 138 | assertEq('abc'.endsWith('', +0), true); |
michael@0 | 139 | assertEq('abc'.endsWith('\0', +0), false); |
michael@0 | 140 | assertEq('abc'.endsWith('c', +0), false); |
michael@0 | 141 | assertEq('abc'.endsWith('b', +0), false); |
michael@0 | 142 | assertEq('abc'.endsWith('a', +0), false); |
michael@0 | 143 | assertEq('abc'.endsWith('ab', +0), false); |
michael@0 | 144 | assertEq('abc'.endsWith('bc', +0), false); |
michael@0 | 145 | assertEq('abc'.endsWith('abc', +0), false); |
michael@0 | 146 | assertEq('abc'.endsWith('bcd', +0), false); |
michael@0 | 147 | assertEq('abc'.endsWith('abcd', +0), false); |
michael@0 | 148 | assertEq('abc'.endsWith('bcde', +0), false); |
michael@0 | 149 | |
michael@0 | 150 | assertEq('abc'.endsWith('', 1), true); |
michael@0 | 151 | assertEq('abc'.endsWith('\0', 1), false); |
michael@0 | 152 | assertEq('abc'.endsWith('c', 1), false); |
michael@0 | 153 | assertEq('abc'.endsWith('b', 1), false); |
michael@0 | 154 | assertEq('abc'.endsWith('ab', 1), false); |
michael@0 | 155 | assertEq('abc'.endsWith('bc', 1), false); |
michael@0 | 156 | assertEq('abc'.endsWith('abc', 1), false); |
michael@0 | 157 | assertEq('abc'.endsWith('bcd', 1), false); |
michael@0 | 158 | assertEq('abc'.endsWith('abcd', 1), false); |
michael@0 | 159 | assertEq('abc'.endsWith('bcde', 1), false); |
michael@0 | 160 | |
michael@0 | 161 | assertEq('abc'.endsWith('', 2), true); |
michael@0 | 162 | assertEq('abc'.endsWith('\0', 2), false); |
michael@0 | 163 | assertEq('abc'.endsWith('c', 2), false); |
michael@0 | 164 | assertEq('abc'.endsWith('b', 2), true); |
michael@0 | 165 | assertEq('abc'.endsWith('ab', 2), true); |
michael@0 | 166 | assertEq('abc'.endsWith('bc', 2), false); |
michael@0 | 167 | assertEq('abc'.endsWith('abc', 2), false); |
michael@0 | 168 | assertEq('abc'.endsWith('bcd', 2), false); |
michael@0 | 169 | assertEq('abc'.endsWith('abcd', 2), false); |
michael@0 | 170 | assertEq('abc'.endsWith('bcde', 2), false); |
michael@0 | 171 | |
michael@0 | 172 | assertEq('abc'.endsWith('', +Infinity), true); |
michael@0 | 173 | assertEq('abc'.endsWith('\0', +Infinity), false); |
michael@0 | 174 | assertEq('abc'.endsWith('c', +Infinity), true); |
michael@0 | 175 | assertEq('abc'.endsWith('b', +Infinity), false); |
michael@0 | 176 | assertEq('abc'.endsWith('a', +Infinity), false); |
michael@0 | 177 | assertEq('abc'.endsWith('ab', +Infinity), false); |
michael@0 | 178 | assertEq('abc'.endsWith('bc', +Infinity), true); |
michael@0 | 179 | assertEq('abc'.endsWith('abc', +Infinity), true); |
michael@0 | 180 | assertEq('abc'.endsWith('bcd', +Infinity), false); |
michael@0 | 181 | assertEq('abc'.endsWith('abcd', +Infinity), false); |
michael@0 | 182 | assertEq('abc'.endsWith('bcde', +Infinity), false); |
michael@0 | 183 | |
michael@0 | 184 | assertEq('abc'.endsWith('', true), true); |
michael@0 | 185 | assertEq('abc'.endsWith('\0', true), false); |
michael@0 | 186 | assertEq('abc'.endsWith('c', true), false); |
michael@0 | 187 | assertEq('abc'.endsWith('b', true), false); |
michael@0 | 188 | assertEq('abc'.endsWith('ab', true), false); |
michael@0 | 189 | assertEq('abc'.endsWith('bc', true), false); |
michael@0 | 190 | assertEq('abc'.endsWith('abc', true), false); |
michael@0 | 191 | assertEq('abc'.endsWith('bcd', true), false); |
michael@0 | 192 | assertEq('abc'.endsWith('abcd', true), false); |
michael@0 | 193 | assertEq('abc'.endsWith('bcde', true), false); |
michael@0 | 194 | |
michael@0 | 195 | assertEq('abc'.endsWith('', 'x'), true); |
michael@0 | 196 | assertEq('abc'.endsWith('\0', 'x'), false); |
michael@0 | 197 | assertEq('abc'.endsWith('c', 'x'), false); |
michael@0 | 198 | assertEq('abc'.endsWith('b', 'x'), false); |
michael@0 | 199 | assertEq('abc'.endsWith('a', 'x'), false); |
michael@0 | 200 | assertEq('abc'.endsWith('ab', 'x'), false); |
michael@0 | 201 | assertEq('abc'.endsWith('bc', 'x'), false); |
michael@0 | 202 | assertEq('abc'.endsWith('abc', 'x'), false); |
michael@0 | 203 | assertEq('abc'.endsWith('bcd', 'x'), false); |
michael@0 | 204 | assertEq('abc'.endsWith('abcd', 'x'), false); |
michael@0 | 205 | assertEq('abc'.endsWith('bcde', 'x'), false); |
michael@0 | 206 | |
michael@0 | 207 | assertEq('[a-z]+(bar)?'.endsWith('(bar)?'), true); |
michael@0 | 208 | assertThrows(function() { '[a-z]+(bar)?'.endsWith(/(bar)?/); }, TypeError); |
michael@0 | 209 | assertEq('[a-z]+(bar)?'.endsWith('[a-z]+', 6), true); |
michael@0 | 210 | assertThrows(function() { '[a-z]+(bar)?'.endsWith(/(bar)?/); }, TypeError); |
michael@0 | 211 | assertThrows(function() { '[a-z]+/(bar)?/'.endsWith(/(bar)?/); }, TypeError); |
michael@0 | 212 | var global = newGlobal(); |
michael@0 | 213 | global.eval('this.re = /(bar)?/'); |
michael@0 | 214 | assertThrows(function() { '[a-z]+/(bar)?/'.endsWith(global.re); }, TypeError); |
michael@0 | 215 | |
michael@0 | 216 | // http://mathiasbynens.be/notes/javascript-unicode#poo-test |
michael@0 | 217 | var string = 'I\xF1t\xEBrn\xE2ti\xF4n\xE0liz\xE6ti\xF8n\u2603\uD83D\uDCA9'; |
michael@0 | 218 | assertEq(string.endsWith(''), true); |
michael@0 | 219 | assertEq(string.endsWith('\xF1t\xEBr'), false); |
michael@0 | 220 | assertEq(string.endsWith('\xF1t\xEBr', 5), true); |
michael@0 | 221 | assertEq(string.endsWith('\xE0liz\xE6'), false); |
michael@0 | 222 | assertEq(string.endsWith('\xE0liz\xE6', 16), true); |
michael@0 | 223 | assertEq(string.endsWith('\xF8n\u2603\uD83D\uDCA9'), true); |
michael@0 | 224 | assertEq(string.endsWith('\xF8n\u2603\uD83D\uDCA9', 23), true); |
michael@0 | 225 | assertEq(string.endsWith('\u2603'), false); |
michael@0 | 226 | assertEq(string.endsWith('\u2603', 21), true); |
michael@0 | 227 | assertEq(string.endsWith('\uD83D\uDCA9'), true); |
michael@0 | 228 | assertEq(string.endsWith('\uD83D\uDCA9', 23), true); |
michael@0 | 229 | |
michael@0 | 230 | assertThrows(function() { String.prototype.endsWith.call(undefined); }, TypeError); |
michael@0 | 231 | assertThrows(function() { String.prototype.endsWith.call(undefined, 'b'); }, TypeError); |
michael@0 | 232 | assertThrows(function() { String.prototype.endsWith.call(undefined, 'b', 4); }, TypeError); |
michael@0 | 233 | assertThrows(function() { String.prototype.endsWith.call(null); }, TypeError); |
michael@0 | 234 | assertThrows(function() { String.prototype.endsWith.call(null, 'b'); }, TypeError); |
michael@0 | 235 | assertThrows(function() { String.prototype.endsWith.call(null, 'b', 4); }, TypeError); |
michael@0 | 236 | assertEq(String.prototype.endsWith.call(42, '2'), true); |
michael@0 | 237 | assertEq(String.prototype.endsWith.call(42, '4'), false); |
michael@0 | 238 | assertEq(String.prototype.endsWith.call(42, 'b', 4), false); |
michael@0 | 239 | assertEq(String.prototype.endsWith.call(42, '2', 1), false); |
michael@0 | 240 | assertEq(String.prototype.endsWith.call(42, '2', 4), true); |
michael@0 | 241 | assertEq(String.prototype.endsWith.call({ 'toString': function() { return 'abc'; } }, 'b', 0), false); |
michael@0 | 242 | assertEq(String.prototype.endsWith.call({ 'toString': function() { return 'abc'; } }, 'b', 1), false); |
michael@0 | 243 | assertEq(String.prototype.endsWith.call({ 'toString': function() { return 'abc'; } }, 'b', 2), true); |
michael@0 | 244 | assertThrows(function() { String.prototype.endsWith.call({ 'toString': function() { throw RangeError(); } }, /./); }, RangeError); |
michael@0 | 245 | assertThrows(function() { String.prototype.endsWith.call({ 'toString': function() { return 'abc' } }, /./); }, TypeError); |
michael@0 | 246 | |
michael@0 | 247 | assertThrows(function() { String.prototype.endsWith.apply(undefined); }, TypeError); |
michael@0 | 248 | assertThrows(function() { String.prototype.endsWith.apply(undefined, ['b']); }, TypeError); |
michael@0 | 249 | assertThrows(function() { String.prototype.endsWith.apply(undefined, ['b', 4]); }, TypeError); |
michael@0 | 250 | assertThrows(function() { String.prototype.endsWith.apply(null); }, TypeError); |
michael@0 | 251 | assertThrows(function() { String.prototype.endsWith.apply(null, ['b']); }, TypeError); |
michael@0 | 252 | assertThrows(function() { String.prototype.endsWith.apply(null, ['b', 4]); }, TypeError); |
michael@0 | 253 | assertEq(String.prototype.endsWith.apply(42, ['2']), true); |
michael@0 | 254 | assertEq(String.prototype.endsWith.apply(42, ['4']), false); |
michael@0 | 255 | assertEq(String.prototype.endsWith.apply(42, ['b', 4]), false); |
michael@0 | 256 | assertEq(String.prototype.endsWith.apply(42, ['2', 1]), false); |
michael@0 | 257 | assertEq(String.prototype.endsWith.apply(42, ['2', 4]), true); |
michael@0 | 258 | assertEq(String.prototype.endsWith.apply({ 'toString': function() { return 'abc'; } }, ['b', 0]), false); |
michael@0 | 259 | assertEq(String.prototype.endsWith.apply({ 'toString': function() { return 'abc'; } }, ['b', 1]), false); |
michael@0 | 260 | assertEq(String.prototype.endsWith.apply({ 'toString': function() { return 'abc'; } }, ['b', 2]), true); |
michael@0 | 261 | assertThrows(function() { String.prototype.endsWith.apply({ 'toString': function() { throw RangeError(); } }, [/./]); }, RangeError); |
michael@0 | 262 | assertThrows(function() { String.prototype.endsWith.apply({ 'toString': function() { return 'abc' } }, [/./]); }, TypeError); |