diff options
Diffstat (limited to 'js/src/tests/test262/intl402/Number/prototype/toLocaleString/throws-same-exceptions-as-NumberFormat.js')
-rw-r--r-- | js/src/tests/test262/intl402/Number/prototype/toLocaleString/throws-same-exceptions-as-NumberFormat.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/Number/prototype/toLocaleString/throws-same-exceptions-as-NumberFormat.js b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/throws-same-exceptions-as-NumberFormat.js new file mode 100644 index 0000000000..8dbb5b72a3 --- /dev/null +++ b/js/src/tests/test262/intl402/Number/prototype/toLocaleString/throws-same-exceptions-as-NumberFormat.js @@ -0,0 +1,49 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 13.2.1_4_1 +description: > + Tests that Number.prototype.toLocaleString throws the same + exceptions as Intl.NumberFormat. +author: Norbert Lindenberg +---*/ + +var locales = [null, [NaN], ["i"], ["de_DE"]]; +var options = [ + {localeMatcher: null}, + {style: "invalid"}, + {style: "currency"}, + {style: "currency", currency: "ßP"}, + {maximumSignificantDigits: -Infinity} +]; + +locales.forEach(function (locales) { + var referenceError, error; + try { + var format = new Intl.NumberFormat(locales); + } catch (e) { + referenceError = e; + } + assert.notSameValue(referenceError, undefined, "Internal error: Expected exception was not thrown by Intl.NumberFormat for locales " + locales + "."); + + assert.throws(referenceError.constructor, function() { + var result = (0).toLocaleString(locales); + }, "Number.prototype.toLocaleString didn't throw exception for locales " + locales + "."); +}); + +options.forEach(function (options) { + var referenceError, error; + try { + var format = new Intl.NumberFormat([], options); + } catch (e) { + referenceError = e; + } + assert.notSameValue(referenceError, undefined, "Internal error: Expected exception was not thrown by Intl.NumberFormat for options " + JSON.stringify(options) + "."); + + assert.throws(referenceError.constructor, function() { + var result = (0).toLocaleString([], options); + }, "Number.prototype.toLocaleString didn't throw exception for options " + JSON.stringify(options) + "."); +}); + +reportCompare(0, 0); |