js/src/tests/test262/intl402/ch13/13.2/13.2.1_4_1.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

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 Number.prototype.toLocaleString throws the same exceptions as Intl.NumberFormat.
michael@0 6 * @author Norbert Lindenberg
michael@0 7 */
michael@0 8
michael@0 9 var locales = [null, [NaN], ["i"], ["de_DE"]];
michael@0 10 var options = [
michael@0 11 {localeMatcher: null},
michael@0 12 {style: "invalid"},
michael@0 13 {style: "currency"},
michael@0 14 {style: "currency", currency: "ßP"},
michael@0 15 {maximumSignificantDigits: -Infinity}
michael@0 16 ];
michael@0 17
michael@0 18 locales.forEach(function (locales) {
michael@0 19 var referenceError, error;
michael@0 20 try {
michael@0 21 var format = new Intl.NumberFormat(locales);
michael@0 22 } catch (e) {
michael@0 23 referenceError = e;
michael@0 24 }
michael@0 25 if (referenceError === undefined) {
michael@0 26 $ERROR("Internal error: Expected exception was not thrown by Intl.NumberFormat for locales " + locales + ".");
michael@0 27 }
michael@0 28
michael@0 29 try {
michael@0 30 var result = (0).toLocaleString(locales);
michael@0 31 } catch (e) {
michael@0 32 error = e;
michael@0 33 }
michael@0 34 if (error === undefined) {
michael@0 35 $ERROR("Number.prototype.toLocaleString didn't throw exception for locales " + locales + ".");
michael@0 36 } else if (error.name !== referenceError.name) {
michael@0 37 $ERROR("Number.prototype.toLocaleString threw exception " + error.name +
michael@0 38 " for locales " + locales + "; expected " + referenceError.name + ".");
michael@0 39 }
michael@0 40 });
michael@0 41
michael@0 42 options.forEach(function (options) {
michael@0 43 var referenceError, error;
michael@0 44 try {
michael@0 45 var format = new Intl.NumberFormat([], options);
michael@0 46 } catch (e) {
michael@0 47 referenceError = e;
michael@0 48 }
michael@0 49 if (referenceError === undefined) {
michael@0 50 $ERROR("Internal error: Expected exception was not thrown by Intl.NumberFormat for options " +
michael@0 51 JSON.stringify(options) + ".");
michael@0 52 }
michael@0 53
michael@0 54 try {
michael@0 55 var result = (0).toLocaleString([], options);
michael@0 56 } catch (e) {
michael@0 57 error = e;
michael@0 58 }
michael@0 59 if (error === undefined) {
michael@0 60 $ERROR("Number.prototype.toLocaleString didn't throw exception for options " +
michael@0 61 JSON.stringify(options) + ".");
michael@0 62 } else if (error.name !== referenceError.name) {
michael@0 63 $ERROR("Number.prototype.toLocaleString threw exception " + error.name +
michael@0 64 " for options " + JSON.stringify(options) + "; expected " + referenceError.name + ".");
michael@0 65 }
michael@0 66 });
michael@0 67

mercurial