diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/tests/test262/intl402/Date | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/intl402/Date')
22 files changed, 453 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/Date/browser.js b/js/src/tests/test262/intl402/Date/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Date/browser.js diff --git a/js/src/tests/test262/intl402/Date/prototype/browser.js b/js/src/tests/test262/intl402/Date/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/browser.js diff --git a/js/src/tests/test262/intl402/Date/prototype/returns-same-results-as-DateTimeFormat.js b/js/src/tests/test262/intl402/Date/prototype/returns-same-results-as-DateTimeFormat.js new file mode 100644 index 0000000000..0148c1c527 --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/returns-same-results-as-DateTimeFormat.js @@ -0,0 +1,57 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 13.3.0_7 +description: > + Tests that Date.prototype.toLocaleString & Co. produces the same + results as Intl.DateTimeFormat. +author: Norbert Lindenberg +includes: [compareArray.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); }); + assert.compareArray(formatted, referenceFormatted, + "(Testing with locales " + locales + "; options " + + (options ? JSON.stringify(options) : options) + ".)"); + }); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Date/prototype/shell.js b/js/src/tests/test262/intl402/Date/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/shell.js diff --git a/js/src/tests/test262/intl402/Date/prototype/taint-Intl-DateTimeFormat.js b/js/src/tests/test262/intl402/Date/prototype/taint-Intl-DateTimeFormat.js new file mode 100644 index 0000000000..78775974bf --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/taint-Intl-DateTimeFormat.js @@ -0,0 +1,18 @@ +// Copyright 2013 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +es5id: 13.3.0_6_2 +description: > + Tests that Date.prototype.toLocaleString & Co. use the standard + built-in Intl.DateTimeFormat constructor. +author: Norbert Lindenberg +includes: [testIntl.js] +---*/ + +taintDataProperty(Intl, "DateTimeFormat"); +new Date().toLocaleString(); +new Date().toLocaleDateString(); +new Date().toLocaleTimeString(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Date/prototype/this-value-invalid-date.js b/js/src/tests/test262/intl402/Date/prototype/this-value-invalid-date.js new file mode 100644 index 0000000000..4b5c4b4ed9 --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/this-value-invalid-date.js @@ -0,0 +1,27 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 13.3.0_2 +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)); + assert.sameValue(result, "Invalid Date", "Date.prototype." + p + " did not return \"Invalid Date\" for " + value); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Date/prototype/this-value-non-date.js b/js/src/tests/test262/intl402/Date/prototype/this-value-non-date.js new file mode 100644 index 0000000000..51f1197f0a --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/this-value-non-date.js @@ -0,0 +1,28 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 13.3.0_1 +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) { + assert.throws(TypeError, function() { + var result = f.call(value); + }, "Date.prototype." + p + " did not reject this = " + value + "."); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Date/prototype/throws-same-exceptions-as-DateTimeFormat.js b/js/src/tests/test262/intl402/Date/prototype/throws-same-exceptions-as-DateTimeFormat.js new file mode 100644 index 0000000000..17371d2a85 --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/throws-same-exceptions-as-DateTimeFormat.js @@ -0,0 +1,56 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 13.3.0_6_1 +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; + } + assert.notSameValue(referenceError, undefined, "Internal error: Expected exception was not thrown by Intl.DateTimeFormat for locales " + locales + "."); + + assert.throws(referenceError.constructor, function() { + var result = f.call(new Date(), locales); + }, "Date.prototype." + p + " didn't throw exception for locales " + locales + "."); + }); + + options.forEach(function (options) { + var referenceError, error; + try { + var format = new Intl.DateTimeFormat([], options); + } catch (e) { + referenceError = e; + } + assert.notSameValue(referenceError, undefined, "Internal error: Expected exception was not thrown by Intl.DateTimeFormat for options " + JSON.stringify(options) + "."); + + assert.throws(referenceError.constructor, function() { + var result = f.call(new Date(), [], options); + }, "Date.prototype." + p + " didn't throw exception for options " + JSON.stringify(options) + "."); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Date/prototype/toLocaleDateString/browser.js b/js/src/tests/test262/intl402/Date/prototype/toLocaleDateString/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/toLocaleDateString/browser.js diff --git a/js/src/tests/test262/intl402/Date/prototype/toLocaleDateString/builtin.js b/js/src/tests/test262/intl402/Date/prototype/toLocaleDateString/builtin.js new file mode 100644 index 0000000000..850f64fab5 --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/toLocaleDateString/builtin.js @@ -0,0 +1,30 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +es5id: 13.3.2_L15 +description: > + Tests that Date.prototype.toLocaleDateString meets the + requirements for built-in objects defined by the introduction of + chapter 17 of the ECMAScript Language Specification. +author: Norbert Lindenberg +includes: [isConstructor.js] +features: [Reflect.construct] +---*/ + +assert.sameValue(Object.prototype.toString.call(Date.prototype.toLocaleDateString), "[object Function]", + "The [[Class]] internal property of a built-in function must be " + + "\"Function\"."); + +assert(Object.isExtensible(Date.prototype.toLocaleDateString), + "Built-in objects must be extensible."); + +assert.sameValue(Object.getPrototypeOf(Date.prototype.toLocaleDateString), Function.prototype); + +assert.sameValue(Date.prototype.toLocaleDateString.hasOwnProperty("prototype"), false, + "Built-in functions that aren't constructors must not have a prototype property."); + +assert.sameValue(isConstructor(Date.prototype.toLocaleDateString), false, + "Built-in functions don't implement [[Construct]] unless explicitly specified."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Date/prototype/toLocaleDateString/length.js b/js/src/tests/test262/intl402/Date/prototype/toLocaleDateString/length.js new file mode 100644 index 0000000000..80614fb881 --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/toLocaleDateString/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sup-date.prototype.tolocaledatestring +description: > + Date.prototype.toLocaleDateString.length is 0. +info: | + Date.prototype.toLocaleDateString ( [ locales [ , options ] ] ) + + 17 ECMAScript Standard Built-in Objects: + + Every built-in function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. + +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Date.prototype.toLocaleDateString.length, 0); + +verifyNotEnumerable(Date.prototype.toLocaleDateString, "length"); +verifyNotWritable(Date.prototype.toLocaleDateString, "length"); +verifyConfigurable(Date.prototype.toLocaleDateString, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Date/prototype/toLocaleDateString/shell.js b/js/src/tests/test262/intl402/Date/prototype/toLocaleDateString/shell.js new file mode 100644 index 0000000000..54371b7789 --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/toLocaleDateString/shell.js @@ -0,0 +1,19 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +---*/ + +function isConstructor(f) { + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/intl402/Date/prototype/toLocaleString/browser.js b/js/src/tests/test262/intl402/Date/prototype/toLocaleString/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/toLocaleString/browser.js diff --git a/js/src/tests/test262/intl402/Date/prototype/toLocaleString/builtin.js b/js/src/tests/test262/intl402/Date/prototype/toLocaleString/builtin.js new file mode 100644 index 0000000000..7db6c9b8df --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/toLocaleString/builtin.js @@ -0,0 +1,30 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +es5id: 13.3.1_L15 +description: > + Tests that Date.prototype.toLocaleString meets the requirements + for built-in objects defined by the introduction of chapter 17 of + the ECMAScript Language Specification. +author: Norbert Lindenberg +includes: [isConstructor.js] +features: [Reflect.construct] +---*/ + +assert.sameValue(Object.prototype.toString.call(Date.prototype.toLocaleString), "[object Function]", + "The [[Class]] internal property of a built-in function must be " + + "\"Function\"."); + +assert(Object.isExtensible(Date.prototype.toLocaleString), + "Built-in objects must be extensible."); + +assert.sameValue(Object.getPrototypeOf(Date.prototype.toLocaleString), Function.prototype); + +assert.sameValue(Date.prototype.toLocaleString.hasOwnProperty("prototype"), false, + "Built-in functions that aren't constructors must not have a prototype property."); + +assert.sameValue(isConstructor(Date.prototype.toLocaleString), false, + "Built-in functions don't implement [[Construct]] unless explicitly specified."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Date/prototype/toLocaleString/default-options-object-prototype.js b/js/src/tests/test262/intl402/Date/prototype/toLocaleString/default-options-object-prototype.js new file mode 100644 index 0000000000..28654c8173 --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/toLocaleString/default-options-object-prototype.js @@ -0,0 +1,21 @@ +// Copyright (C) 2017 Daniel Ehrenberg. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-todatetimeoptions +description: > + Monkey-patching Object.prototype does not change the default + options for DateTimeFormat as a null prototype is used. +info: | + ToDateTimeOptions ( options, required, defaults ) + + 1. If options is undefined, let options be null; otherwise let options be ? ToObject(options). + 1. Let options be ObjectCreate(options). +---*/ + +if (new Intl.DateTimeFormat("en").resolvedOptions().locale === "en") { + Object.prototype.year = "2-digit"; + assert.notSameValue(new Date().toLocaleString("en").length, 2); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Date/prototype/toLocaleString/length.js b/js/src/tests/test262/intl402/Date/prototype/toLocaleString/length.js new file mode 100644 index 0000000000..405aaf824c --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/toLocaleString/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sup-date.prototype.tolocalestring +description: > + Date.prototype.toLocaleString.length is 0. +info: | + Date.prototype.toLocaleString ( [ locales [ , options ] ] ) + + 17 ECMAScript Standard Built-in Objects: + + Every built-in function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. + +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Date.prototype.toLocaleString.length, 0); + +verifyNotEnumerable(Date.prototype.toLocaleString, "length"); +verifyNotWritable(Date.prototype.toLocaleString, "length"); +verifyConfigurable(Date.prototype.toLocaleString, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Date/prototype/toLocaleString/shell.js b/js/src/tests/test262/intl402/Date/prototype/toLocaleString/shell.js new file mode 100644 index 0000000000..54371b7789 --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/toLocaleString/shell.js @@ -0,0 +1,19 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +---*/ + +function isConstructor(f) { + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/intl402/Date/prototype/toLocaleTimeString/browser.js b/js/src/tests/test262/intl402/Date/prototype/toLocaleTimeString/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/toLocaleTimeString/browser.js diff --git a/js/src/tests/test262/intl402/Date/prototype/toLocaleTimeString/builtin.js b/js/src/tests/test262/intl402/Date/prototype/toLocaleTimeString/builtin.js new file mode 100644 index 0000000000..e82ac0017e --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/toLocaleTimeString/builtin.js @@ -0,0 +1,30 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +es5id: 13.3.3_L15 +description: > + Tests that Date.prototype.toLocaleTimeString meets the + requirements for built-in objects defined by the introduction of + chapter 17 of the ECMAScript Language Specification. +author: Norbert Lindenberg +includes: [isConstructor.js] +features: [Reflect.construct] +---*/ + +assert.sameValue(Object.prototype.toString.call(Date.prototype.toLocaleTimeString), "[object Function]", + "The [[Class]] internal property of a built-in function must be " + + "\"Function\"."); + +assert(Object.isExtensible(Date.prototype.toLocaleTimeString), + "Built-in objects must be extensible."); + +assert.sameValue(Object.getPrototypeOf(Date.prototype.toLocaleTimeString), Function.prototype); + +assert.sameValue(Date.prototype.toLocaleTimeString.hasOwnProperty("prototype"), false, + "Built-in functions that aren't constructors must not have a prototype property."); + +assert.sameValue(isConstructor(Date.prototype.toLocaleTimeString), false, + "Built-in functions don't implement [[Construct]] unless explicitly specified."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Date/prototype/toLocaleTimeString/length.js b/js/src/tests/test262/intl402/Date/prototype/toLocaleTimeString/length.js new file mode 100644 index 0000000000..16f92ccf49 --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/toLocaleTimeString/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sup-date.prototype.tolocaletimestring +description: > + Date.prototype.toLocaleTimeString.length is 0. +info: | + Date.prototype.toLocaleTimeString ( [ locales [ , options ] ] ) + + 17 ECMAScript Standard Built-in Objects: + + Every built-in function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. + +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Date.prototype.toLocaleTimeString.length, 0); + +verifyNotEnumerable(Date.prototype.toLocaleTimeString, "length"); +verifyNotWritable(Date.prototype.toLocaleTimeString, "length"); +verifyConfigurable(Date.prototype.toLocaleTimeString, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Date/prototype/toLocaleTimeString/shell.js b/js/src/tests/test262/intl402/Date/prototype/toLocaleTimeString/shell.js new file mode 100644 index 0000000000..54371b7789 --- /dev/null +++ b/js/src/tests/test262/intl402/Date/prototype/toLocaleTimeString/shell.js @@ -0,0 +1,19 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +---*/ + +function isConstructor(f) { + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/intl402/Date/shell.js b/js/src/tests/test262/intl402/Date/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Date/shell.js |