diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/tests/test262/intl402/ch13 | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/test262/intl402/ch13')
29 files changed, 642 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/ch13/13.1/13.1.1_1.js b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_1.js new file mode 100644 index 000000000..37be9711b --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_1.js @@ -0,0 +1,24 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that localeCompare rejects values that can't be coerced to an object. + * @author Norbert Lindenberg + */ + +var invalidValues = [undefined, null]; + +invalidValues.forEach(function (value) { + var error; + try { + var result = String.prototype.localeCompare.call(value, ""); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("String.prototype.localeCompare did not reject this = " + value + "."); + } else if (error.name !== "TypeError") { + $ERROR("String.prototype.localeCompare rejected this = " + value + " with wrong error " + error.name + "."); + } +}); + diff --git a/js/src/tests/test262/intl402/ch13/13.1/13.1.1_2.js b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_2.js new file mode 100644 index 000000000..bad7c0fdd --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_2.js @@ -0,0 +1,26 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that localeCompare coerces this to a string. + * @author Norbert Lindenberg + */ + +var thisValues = [true, 5, "hello", {toString: function () { return "good bye"; }}]; +var thatValues = ["true", "5", "hello", "good bye"]; + +var i; +for (i = 0; i < thisValues.length; i++) { + var j; + for (j = 0; j < thatValues.length; j++) { + var result = String.prototype.localeCompare.call(thisValues[i], thatValues[j]); + if ((result === 0) !== (i === j)) { + if (result === 0) { + $ERROR("localeCompare treats " + thisValues[i] + " and " + thatValues[j] + " as equal."); + } else { + $ERROR("localeCompare treats " + thisValues[i] + " and " + thatValues[j] + " as different."); + } + } + } +} + diff --git a/js/src/tests/test262/intl402/ch13/13.1/13.1.1_3_1.js b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_3_1.js new file mode 100644 index 000000000..113a2d9aa --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_3_1.js @@ -0,0 +1,26 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that localeCompare coerces that to a string. + * @author Norbert Lindenberg + */ + +var thisValues = ["true", "5", "hello", "good bye"]; +var thatValues = [true, 5, "hello", {toString: function () { return "good bye"; }}]; + +var i; +for (i = 0; i < thisValues.length; i++) { + var j; + for (j = 0; j < thatValues.length; j++) { + var result = String.prototype.localeCompare.call(thisValues[i], thatValues[j]); + if ((result === 0) !== (i === j)) { + if (result === 0) { + $ERROR("localeCompare treats " + thisValues[i] + " and " + thatValues[j] + " as equal."); + } else { + $ERROR("localeCompare treats " + thisValues[i] + " and " + thatValues[j] + " as different."); + } + } + } +} + diff --git a/js/src/tests/test262/intl402/ch13/13.1/13.1.1_3_2.js b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_3_2.js new file mode 100644 index 000000000..441166c9f --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_3_2.js @@ -0,0 +1,22 @@ +// Copyright 2013 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that String.prototype.localeCompare treats a missing + * "that" argument, undefined, and "undefined" as equivalent. + * @author Norbert Lindenberg + */ + +var thisValues = ["a", "t", "u", "undefined", "UNDEFINED", "nicht definiert", "xyz", "未定义"]; + +var i; +for (i = 0; i < thisValues.length; i++) { + var thisValue = thisValues[i]; + if (thisValue.localeCompare() !== thisValue.localeCompare(undefined)) { + $ERROR("String.prototype.localeCompare does not treat missing 'that' argument as undefined."); + } + if (thisValue.localeCompare(undefined) !== thisValue.localeCompare("undefined")) { + $ERROR("String.prototype.localeCompare does not treat undefined 'that' argument as \"undefined\"."); + } +} + diff --git a/js/src/tests/test262/intl402/ch13/13.1/13.1.1_6_1.js b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_6_1.js new file mode 100644 index 000000000..30607d317 --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_6_1.js @@ -0,0 +1,65 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that String.prototype.localeCompare throws the same exceptions as Intl.Collator. + * @author Norbert Lindenberg + */ + +var locales = [null, [NaN], ["i"], ["de_DE"]]; +var options = [ + {localeMatcher: null}, + {usage: "invalid"}, + {sensitivity: "invalid"} +]; + +locales.forEach(function (locales) { + var referenceError, error; + try { + var collator = new Intl.Collator(locales); + } catch (e) { + referenceError = e; + } + if (referenceError === undefined) { + $ERROR("Internal error: Expected exception was not thrown by Intl.Collator for locales " + locales + "."); + } + + try { + var result = "".localeCompare("", locales); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("String.prototype.localeCompare didn't throw exception for locales " + locales + "."); + } else if (error.name !== referenceError.name) { + $ERROR("String.prototype.localeCompare threw exception " + error.name + + " for locales " + locales + "; expected " + referenceError.name + "."); + } +}); + +options.forEach(function (options) { + var referenceError, error; + try { + var collator = new Intl.Collator([], options); + } catch (e) { + referenceError = e; + } + if (referenceError === undefined) { + $ERROR("Internal error: Expected exception was not thrown by Intl.Collator for options " + + JSON.stringify(options) + "."); + } + + try { + var result = "".localeCompare("", [], options); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("String.prototype.localeCompare didn't throw exception for options " + + JSON.stringify(options) + "."); + } else if (error.name !== referenceError.name) { + $ERROR("String.prototype.localeCompare threw exception " + error.name + + " for options " + JSON.stringify(options) + "; expected " + referenceError.name + "."); + } +}); + diff --git a/js/src/tests/test262/intl402/ch13/13.1/13.1.1_6_2.js b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_6_2.js new file mode 100644 index 000000000..481a7803b --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_6_2.js @@ -0,0 +1,13 @@ +// Copyright 2013 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that String.prototype.localeCompare uses the standard + * built-in Intl.Collator constructor. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +taintDataProperty(Intl, "Collator"); +"a".localeCompare("b"); diff --git a/js/src/tests/test262/intl402/ch13/13.1/13.1.1_7.js b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_7.js new file mode 100644 index 000000000..f0c588f64 --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_7.js @@ -0,0 +1,33 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that localeCompare produces the same results as Intl.Collator. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +var strings = ["d", "O", "od", "oe", "of", "ö", "o\u0308", "X", "y", "Z", "Z.", "𠮷野家", "吉野家", "!A", "A", "b", "C"]; +var locales = [undefined, ["de"], ["de-u-co-phonebk"], ["en"], ["ja"], ["sv"]]; +var options = [ + undefined, + {usage: "search"}, + {sensitivity: "base", ignorePunctuation: true} +]; + +locales.forEach(function (locales) { + options.forEach(function (options) { + var referenceCollator = new Intl.Collator(locales, options); + var referenceSorted = strings.slice().sort(referenceCollator.compare); + + strings.sort(function (a, b) { return a.localeCompare(b, locales, options); }); + try { + testArraysAreSame(referenceSorted, strings); + } catch (e) { + e.message += " (Testing with locales " + locales + "; options " + JSON.stringify(options) + ".)"; + throw e; + } + }); +}); + diff --git a/js/src/tests/test262/intl402/ch13/13.1/13.1.1_L15.js b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_L15.js new file mode 100644 index 000000000..d921de000 --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that String.prototype.localeCompare + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(String.prototype.localeCompare, true, false, [], 1); + diff --git a/js/src/tests/test262/intl402/ch13/13.1/browser.js b/js/src/tests/test262/intl402/ch13/13.1/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.1/browser.js diff --git a/js/src/tests/test262/intl402/ch13/13.1/shell.js b/js/src/tests/test262/intl402/ch13/13.1/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.1/shell.js diff --git a/js/src/tests/test262/intl402/ch13/13.2/13.2.1_1.js b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_1.js new file mode 100644 index 000000000..da1ee8fe5 --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_1.js @@ -0,0 +1,37 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that toLocaleString handles "this Number value" correctly. + * @author Norbert Lindenberg + */ + +var invalidValues = [undefined, null, "5", false, {valueOf: function () { return 5; }}]; +var validValues = [5, NaN, -1234567.89, -Infinity]; + +invalidValues.forEach(function (value) { + var error; + try { + var result = Number.prototype.toLocaleString.call(value); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("Number.prototype.toLocaleString did not reject this = " + value + "."); + } else if (error.name !== "TypeError") { + $ERROR("Number.prototype.toLocaleString rejected this = " + value + " with wrong error " + error.name + "."); + } +}); + +// for valid values, just check that a Number value and the corresponding +// Number object get the same result. +validValues.forEach(function (value) { + var Constructor = Number; // to keep jshint happy + var valueResult = Number.prototype.toLocaleString.call(value); + var objectResult = Number.prototype.toLocaleString.call(new Constructor(value)); + if (valueResult !== objectResult) { + $ERROR("Number.prototype.toLocaleString produces different results for Number value " + + value + " and corresponding Number object: " + valueResult + " vs. " + objectResult + "."); + } +}); + diff --git a/js/src/tests/test262/intl402/ch13/13.2/13.2.1_4_1.js b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_4_1.js new file mode 100644 index 000000000..e6e0b1163 --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_4_1.js @@ -0,0 +1,67 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @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; + } + if (referenceError === undefined) { + $ERROR("Internal error: Expected exception was not thrown by Intl.NumberFormat for locales " + locales + "."); + } + + try { + var result = (0).toLocaleString(locales); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("Number.prototype.toLocaleString didn't throw exception for locales " + locales + "."); + } else if (error.name !== referenceError.name) { + $ERROR("Number.prototype.toLocaleString threw exception " + error.name + + " for locales " + locales + "; expected " + referenceError.name + "."); + } +}); + +options.forEach(function (options) { + var referenceError, error; + try { + var format = new Intl.NumberFormat([], options); + } catch (e) { + referenceError = e; + } + if (referenceError === undefined) { + $ERROR("Internal error: Expected exception was not thrown by Intl.NumberFormat for options " + + JSON.stringify(options) + "."); + } + + try { + var result = (0).toLocaleString([], options); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("Number.prototype.toLocaleString didn't throw exception for options " + + JSON.stringify(options) + "."); + } else if (error.name !== referenceError.name) { + $ERROR("Number.prototype.toLocaleString threw exception " + error.name + + " for options " + JSON.stringify(options) + "; expected " + referenceError.name + "."); + } +}); + diff --git a/js/src/tests/test262/intl402/ch13/13.2/13.2.1_4_2.js b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_4_2.js new file mode 100644 index 000000000..a79cfffde --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_4_2.js @@ -0,0 +1,13 @@ +// Copyright 2013 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Number.prototype.toLocaleString uses the standard + * built-in Intl.NumberFormat constructor. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +taintDataProperty(Intl, "NumberFormat"); +(0.0).toLocaleString(); diff --git a/js/src/tests/test262/intl402/ch13/13.2/13.2.1_5.js b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_5.js new file mode 100644 index 000000000..eb953b64d --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_5.js @@ -0,0 +1,41 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Number.prototype.toLocaleString produces the same results as Intl.NumberFormat. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +var numbers = [0, -0, 1, -1, 5.5, 123, -123, -123.45, 123.44501, 0.001234, + -0.00000000123, 0.00000000000000000000000000000123, 1.2, 0.0000000012344501, + 123445.01, 12344501000000000000000000000000000, -12344501000000000000000000000000000, + Infinity, -Infinity, NaN]; +var locales = [undefined, ["de"], ["th-u-nu-thai"], ["en"], ["ja-u-nu-jpanfin"], ["ar-u-nu-arab"]]; +var options = [ + undefined, + {style: "percent"}, + {style: "currency", currency: "EUR", currencyDisplay: "symbol"}, + {style: "currency", currency: "IQD", currencyDisplay: "symbol"}, + {style: "currency", currency: "KMF", currencyDisplay: "symbol"}, + {style: "currency", currency: "CLF", currencyDisplay: "symbol"}, + {useGrouping: false, minimumIntegerDigits: 3, minimumFractionDigits: 1, maximumFractionDigits: 3} +]; + +locales.forEach(function (locales) { + options.forEach(function (options) { + var referenceNumberFormat = new Intl.NumberFormat(locales, options); + var referenceFormatted = numbers.map(referenceNumberFormat.format); + + var formatted = numbers.map(function (a) { return a.toLocaleString(locales, options); }); + try { + testArraysAreSame(referenceFormatted, formatted); + } catch (e) { + e.message += " (Testing with locales " + locales + "; options " + + (options ? JSON.stringify(options) : options) + ".)"; + throw e; + } + }); +}); + diff --git a/js/src/tests/test262/intl402/ch13/13.2/13.2.1_L15.js b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_L15.js new file mode 100644 index 000000000..8b53f7496 --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Number.prototype.toLocaleString + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(Number.prototype.toLocaleString, true, false, [], 0); + diff --git a/js/src/tests/test262/intl402/ch13/13.2/browser.js b/js/src/tests/test262/intl402/ch13/13.2/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.2/browser.js diff --git a/js/src/tests/test262/intl402/ch13/13.2/shell.js b/js/src/tests/test262/intl402/ch13/13.2/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.2/shell.js diff --git a/js/src/tests/test262/intl402/ch13/13.3/13.3.0_1.js b/js/src/tests/test262/intl402/ch13/13.3/13.3.0_1.js new file mode 100644 index 000000000..0f2902162 --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.3/13.3.0_1.js @@ -0,0 +1,32 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Date.prototype.toLocaleString & Co. handle "this time value" correctly. + * @author Norbert Lindenberg + */ + +var functions = { + toLocaleString: Date.prototype.toLocaleString, + toLocaleDateString: Date.prototype.toLocaleDateString, + toLocaleTimeString: Date.prototype.toLocaleTimeString +}; +var invalidValues = [undefined, null, 5, "5", false, {valueOf: function () { return 5; }}]; + +Object.getOwnPropertyNames(functions).forEach(function (p) { + var f = functions[p]; + invalidValues.forEach(function (value) { + var error; + try { + var result = f.call(value); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("Date.prototype." + p + " did not reject this = " + value + "."); + } else if (error.name !== "TypeError") { + $ERROR("Date.prototype." + p + " rejected this = " + value + " with wrong error " + error.name + "."); + } + }); +}); + diff --git a/js/src/tests/test262/intl402/ch13/13.3/13.3.0_2.js b/js/src/tests/test262/intl402/ch13/13.3/13.3.0_2.js new file mode 100644 index 000000000..7d5f32fa6 --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.3/13.3.0_2.js @@ -0,0 +1,26 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Date.prototype.toLocaleString & Co. handle non-finite values correctly. + * @author Norbert Lindenberg + */ + +var functions = { + toLocaleString: Date.prototype.toLocaleString, + toLocaleDateString: Date.prototype.toLocaleDateString, + toLocaleTimeString: Date.prototype.toLocaleTimeString +}; +var invalidValues = [NaN, Infinity, -Infinity]; + +Object.getOwnPropertyNames(functions).forEach(function (p) { + var f = functions[p]; + invalidValues.forEach(function (value) { + var result = f.call(new Date(value)); + if (result !== "Invalid Date") { + $ERROR("Date.prototype." + p + " did not return \"Invalid Date\" for " + + value + " – got " + result + " instead."); + } + }); +}); + diff --git a/js/src/tests/test262/intl402/ch13/13.3/13.3.0_6_1.js b/js/src/tests/test262/intl402/ch13/13.3/13.3.0_6_1.js new file mode 100644 index 000000000..c97b240b4 --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.3/13.3.0_6_1.js @@ -0,0 +1,74 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Date.prototype.toLocaleString & Co. throws the same exceptions as Intl.DateTimeFormat. + * @author Norbert Lindenberg + */ + +var functions = { + toLocaleString: Date.prototype.toLocaleString, + toLocaleDateString: Date.prototype.toLocaleDateString, + toLocaleTimeString: Date.prototype.toLocaleTimeString +}; +var locales = [null, [NaN], ["i"], ["de_DE"]]; +var options = [ + {localeMatcher: null}, + {timeZone: "invalid"}, + {hour: "long"}, + {formatMatcher: "invalid"} +]; + +Object.getOwnPropertyNames(functions).forEach(function (p) { + var f = functions[p]; + locales.forEach(function (locales) { + var referenceError, error; + try { + var format = new Intl.DateTimeFormat(locales); + } catch (e) { + referenceError = e; + } + if (referenceError === undefined) { + $ERROR("Internal error: Expected exception was not thrown by Intl.DateTimeFormat for locales " + locales + "."); + } + + try { + var result = f.call(new Date(), locales); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("Date.prototype." + p + " didn't throw exception for locales " + locales + "."); + } else if (error.name !== referenceError.name) { + $ERROR("Date.prototype." + p + " threw exception " + error.name + + " for locales " + locales + "; expected " + referenceError.name + "."); + } + }); + + options.forEach(function (options) { + var referenceError, error; + try { + var format = new Intl.DateTimeFormat([], options); + } catch (e) { + referenceError = e; + } + if (referenceError === undefined) { + $ERROR("Internal error: Expected exception was not thrown by Intl.DateTimeFormat for options " + + JSON.stringify(options) + "."); + } + + try { + var result = f.call(new Date(), [], options); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("Date.prototype." + p + " didn't throw exception for options " + + JSON.stringify(options) + "."); + } else if (error.name !== referenceError.name) { + $ERROR("Date.prototype." + p + " threw exception " + error.name + + " for options " + JSON.stringify(options) + "; expected " + referenceError.name + "."); + } + }); +}); + diff --git a/js/src/tests/test262/intl402/ch13/13.3/13.3.0_6_2.js b/js/src/tests/test262/intl402/ch13/13.3/13.3.0_6_2.js new file mode 100644 index 000000000..dcce05906 --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.3/13.3.0_6_2.js @@ -0,0 +1,15 @@ +// Copyright 2013 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Date.prototype.toLocaleString & Co. use the standard + * built-in Intl.DateTimeFormat constructor. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +taintDataProperty(Intl, "DateTimeFormat"); +new Date().toLocaleString(); +new Date().toLocaleDateString(); +new Date().toLocaleTimeString(); diff --git a/js/src/tests/test262/intl402/ch13/13.3/13.3.0_7.js b/js/src/tests/test262/intl402/ch13/13.3/13.3.0_7.js new file mode 100644 index 000000000..fe7c9271d --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.3/13.3.0_7.js @@ -0,0 +1,58 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Date.prototype.toLocaleString & Co. produces the same results as Intl.DateTimeFormat. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +var functions = { + toLocaleString: [Date.prototype.toLocaleString, + {year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric"}], + toLocaleDateString: [Date.prototype.toLocaleDateString, + {year: "numeric", month: "numeric", day: "numeric"}], + toLocaleTimeString: [Date.prototype.toLocaleTimeString, + {hour: "numeric", minute: "numeric", second: "numeric"}] +}; +var dates = [new Date(), new Date(0), new Date(Date.parse("1989-11-09T17:57:00Z"))]; +var locales = [undefined, ["de"], ["th-u-ca-gregory-nu-thai"], ["en"], ["ja-u-ca-japanese"], ["ar-u-ca-islamicc-nu-arab"]]; +var options = [ + undefined, + {hour12: false}, + {month: "long", day: "numeric", hour: "2-digit", minute: "2-digit"} +]; + +Object.getOwnPropertyNames(functions).forEach(function (p) { + var f = functions[p][0]; + var defaults = functions[p][1]; + locales.forEach(function (locales) { + options.forEach(function (options) { + var constructorOptions = options; + if (options === undefined) { + constructorOptions = defaults; + } else if (options.day === undefined) { + // for simplicity, our options above have either both date and time or neither + constructorOptions = Object.create(defaults); + for (var prop in options) { + if (options.hasOwnProperty(prop)) { + constructorOptions[prop] = options[prop]; + } + } + } + var referenceDateTimeFormat = new Intl.DateTimeFormat(locales, constructorOptions); + var referenceFormatted = dates.map(referenceDateTimeFormat.format); + + var formatted = dates.map(function (a) { return f.call(a, locales, options); }); + try { + testArraysAreSame(referenceFormatted, formatted); + } catch (e) { + e.message += " (Testing with locales " + locales + "; options " + + (options ? JSON.stringify(options) : options) + ".)"; + throw e; + } + }); + }); +}); + diff --git a/js/src/tests/test262/intl402/ch13/13.3/13.3.1_L15.js b/js/src/tests/test262/intl402/ch13/13.3/13.3.1_L15.js new file mode 100644 index 000000000..a8c697c07 --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.3/13.3.1_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Date.prototype.toLocaleString + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(Date.prototype.toLocaleString, true, false, [], 0); + diff --git a/js/src/tests/test262/intl402/ch13/13.3/13.3.2_L15.js b/js/src/tests/test262/intl402/ch13/13.3/13.3.2_L15.js new file mode 100644 index 000000000..5eeed944e --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.3/13.3.2_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Date.prototype.toLocaleDateString + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(Date.prototype.toLocaleDateString, true, false, [], 0); + diff --git a/js/src/tests/test262/intl402/ch13/13.3/13.3.3_L15.js b/js/src/tests/test262/intl402/ch13/13.3/13.3.3_L15.js new file mode 100644 index 000000000..dac7c3513 --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.3/13.3.3_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Date.prototype.toLocaleTimeString + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(Date.prototype.toLocaleTimeString, true, false, [], 0); + diff --git a/js/src/tests/test262/intl402/ch13/13.3/browser.js b/js/src/tests/test262/intl402/ch13/13.3/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.3/browser.js diff --git a/js/src/tests/test262/intl402/ch13/13.3/shell.js b/js/src/tests/test262/intl402/ch13/13.3/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/13.3/shell.js diff --git a/js/src/tests/test262/intl402/ch13/browser.js b/js/src/tests/test262/intl402/ch13/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/browser.js diff --git a/js/src/tests/test262/intl402/ch13/shell.js b/js/src/tests/test262/intl402/ch13/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch13/shell.js |