Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | // Copyright 2012 Mozilla Corporation. 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 Date.prototype.toLocaleString & Co. throws the same exceptions as Intl.DateTimeFormat. |
michael@0 | 6 | * @author Norbert Lindenberg |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | var functions = { |
michael@0 | 10 | toLocaleString: Date.prototype.toLocaleString, |
michael@0 | 11 | toLocaleDateString: Date.prototype.toLocaleDateString, |
michael@0 | 12 | toLocaleTimeString: Date.prototype.toLocaleTimeString |
michael@0 | 13 | }; |
michael@0 | 14 | var locales = [null, [NaN], ["i"], ["de_DE"]]; |
michael@0 | 15 | var options = [ |
michael@0 | 16 | {localeMatcher: null}, |
michael@0 | 17 | {timeZone: "invalid"}, |
michael@0 | 18 | {hour: "long"}, |
michael@0 | 19 | {formatMatcher: "invalid"} |
michael@0 | 20 | ]; |
michael@0 | 21 | |
michael@0 | 22 | Object.getOwnPropertyNames(functions).forEach(function (p) { |
michael@0 | 23 | var f = functions[p]; |
michael@0 | 24 | locales.forEach(function (locales) { |
michael@0 | 25 | var referenceError, error; |
michael@0 | 26 | try { |
michael@0 | 27 | var format = new Intl.DateTimeFormat(locales); |
michael@0 | 28 | } catch (e) { |
michael@0 | 29 | referenceError = e; |
michael@0 | 30 | } |
michael@0 | 31 | if (referenceError === undefined) { |
michael@0 | 32 | $ERROR("Internal error: Expected exception was not thrown by Intl.DateTimeFormat for locales " + locales + "."); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | try { |
michael@0 | 36 | var result = f.call(new Date(), locales); |
michael@0 | 37 | } catch (e) { |
michael@0 | 38 | error = e; |
michael@0 | 39 | } |
michael@0 | 40 | if (error === undefined) { |
michael@0 | 41 | $ERROR("Date.prototype." + p + " didn't throw exception for locales " + locales + "."); |
michael@0 | 42 | } else if (error.name !== referenceError.name) { |
michael@0 | 43 | $ERROR("Date.prototype." + p + " threw exception " + error.name + |
michael@0 | 44 | " for locales " + locales + "; expected " + referenceError.name + "."); |
michael@0 | 45 | } |
michael@0 | 46 | }); |
michael@0 | 47 | |
michael@0 | 48 | options.forEach(function (options) { |
michael@0 | 49 | var referenceError, error; |
michael@0 | 50 | try { |
michael@0 | 51 | var format = new Intl.DateTimeFormat([], options); |
michael@0 | 52 | } catch (e) { |
michael@0 | 53 | referenceError = e; |
michael@0 | 54 | } |
michael@0 | 55 | if (referenceError === undefined) { |
michael@0 | 56 | $ERROR("Internal error: Expected exception was not thrown by Intl.DateTimeFormat for options " + |
michael@0 | 57 | JSON.stringify(options) + "."); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | try { |
michael@0 | 61 | var result = f.call(new Date(), [], options); |
michael@0 | 62 | } catch (e) { |
michael@0 | 63 | error = e; |
michael@0 | 64 | } |
michael@0 | 65 | if (error === undefined) { |
michael@0 | 66 | $ERROR("Date.prototype." + p + " didn't throw exception for options " + |
michael@0 | 67 | JSON.stringify(options) + "."); |
michael@0 | 68 | } else if (error.name !== referenceError.name) { |
michael@0 | 69 | $ERROR("Date.prototype." + p + " threw exception " + error.name + |
michael@0 | 70 | " for options " + JSON.stringify(options) + "; expected " + referenceError.name + "."); |
michael@0 | 71 | } |
michael@0 | 72 | }); |
michael@0 | 73 | }); |
michael@0 | 74 |