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 | // Copyright 2012 Google Inc. All rights reserved. |
michael@0 | 2 | // This code is governed by the BSD license found in the LICENSE file. |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * @description Tests that Intl.NumberFormat.prototype.format |
michael@0 | 6 | * handles NaN, Infinity, and -Infinity properly. |
michael@0 | 7 | * @author: Roozbeh Pournader |
michael@0 | 8 | */ |
michael@0 | 9 | |
michael@0 | 10 | // FIXME: We are only listing Numeric_Type=Decimal. May need to add more |
michael@0 | 11 | // when the spec clarifies. Current as of Unicode 6.1. |
michael@0 | 12 | var hasUnicodeDigits = new RegExp('.*([' + |
michael@0 | 13 | '0-9\u0660-\u0669\u06F0-\u06F9\u07C0-\u07C9\u0966-\u096F' + |
michael@0 | 14 | '\u09E6-\u09EF\u0A66-\u0A6F\u0AE6-\u0AEF\u0B66-\u0B6F\u0BE6-\u0BEF' + |
michael@0 | 15 | '\u0C66-\u0C6F\u0CE6-\u0CEF\u0D66-\u0D6F\u0E50-\u0E59\u0ED0-\u0ED9' + |
michael@0 | 16 | '\u0F20-\u0F29\u1040-\u1049\u1090-\u1099\u17E0-\u17E9\u1810-\u1819' + |
michael@0 | 17 | '\u1946-\u194F\u19D0-\u19D9\u1A80-\u1A89\u1A90-\u1A99\u1B50-\u1B59' + |
michael@0 | 18 | '\u1BB0-\u1BB9\u1C40-\u1C49\u1C50-\u1C59\uA620-\uA629\uA8D0-\uA8D9' + |
michael@0 | 19 | '\uA900-\uA909\uA9D0-\uA9D9\uAA50-\uAA59\uABF0-\uABF9\uFF10-\uFF19' + |
michael@0 | 20 | ']|' + |
michael@0 | 21 | '\uD801[\uDCA0-\uDCA9]|' + |
michael@0 | 22 | '\uD804[\uDC66-\uDC6F\uDCF0-\uDCF9\uDD36-\uDD3F\uDDD0-\uDDD9]|' + |
michael@0 | 23 | '\uD805[\uDEC0-\uDEC9]|' + |
michael@0 | 24 | '\uD835[\uDFCE-\uDFFF])'); |
michael@0 | 25 | |
michael@0 | 26 | var formatter = new Intl.NumberFormat(); |
michael@0 | 27 | var formattedNaN = formatter.format(NaN); |
michael@0 | 28 | var formattedInfinity = formatter.format(Infinity); |
michael@0 | 29 | var formattedNegativeInfinity = formatter.format(-Infinity); |
michael@0 | 30 | |
michael@0 | 31 | if (formattedNaN === formattedInfinity) { |
michael@0 | 32 | $ERROR('Intl.NumberFormat formats NaN and Infinity the ' + |
michael@0 | 33 | 'same way.'); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | if (formattedNaN === formattedNegativeInfinity) { |
michael@0 | 37 | $ERROR('Intl.NumberFormat formats NaN and negative ' + |
michael@0 | 38 | 'Infinity the same way.'); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | if (formattedInfinity === formattedNegativeInfinity) { |
michael@0 | 42 | $ERROR('Intl.NumberFormat formats Infinity and ' + |
michael@0 | 43 | 'negative Infinity the same way.'); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | if (hasUnicodeDigits.test(formattedNaN)) { |
michael@0 | 47 | $ERROR('Intl.NumberFormat formats NaN using a digit.'); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | if (hasUnicodeDigits.test(formattedInfinity)) { |
michael@0 | 51 | $ERROR('Intl.NumberFormat formats Infinity using a ' + |
michael@0 | 52 | 'digit.'); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | if (hasUnicodeDigits.test(formattedNegativeInfinity)) { |
michael@0 | 56 | $ERROR('Intl.NumberFormat formats negative Infinity ' + |
michael@0 | 57 | 'using a digit.'); |
michael@0 | 58 | } |
michael@0 | 59 |