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