diff --git a/test/intl402/DurationFormat/prototype/format/taint-temporal-duration-prototype.js b/test/intl402/DurationFormat/prototype/format/taint-temporal-duration-prototype.js new file mode 100644 index 0000000000..b6169cf1c8 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/taint-temporal-duration-prototype.js @@ -0,0 +1,49 @@ +// Copyright 2025 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.format +description: > + Ensure Temporal.Duration.prototype getters aren't called. +features: [Temporal, Intl.DurationFormat] +---*/ + +var duration = new Temporal.Duration( + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 +); + +var formatter = new Intl.DurationFormat(); + +var expected = formatter.format(duration); + +// Taint all Temporal.Duration.prototype getters. +for (var prop of [ + "years", + "months", + "weeks", + "days", + "hours", + "minutes", + "seconds", + "milliseconds", + "microseconds", + "nanoseconds", +]) { + // Ensure the property is present. + var desc = Object.getOwnPropertyDescriptor(Temporal.Duration.prototype, prop); + assert.notSameValue( + desc, + undefined, + "Descriptor not found: " + prop + ); + + Object.defineProperty(Temporal.Duration.prototype, prop, { + get() { + throw new Test262Error(); + } + }); +} + +var actual = formatter.format(duration); + +assert.sameValue(actual, expected); diff --git a/test/intl402/DurationFormat/prototype/format/temporal-duration-object-arg.js b/test/intl402/DurationFormat/prototype/format/temporal-duration-object-arg.js new file mode 100644 index 0000000000..f2119c156e --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/temporal-duration-object-arg.js @@ -0,0 +1,41 @@ +// Copyright 2025 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.format +description: > + Temporal.Duration objects can be passed to format. +features: [Temporal, Intl.DurationFormat] +---*/ + +var durations = [ + { + object: new Temporal.Duration(), + durationLike: { + years: 0, + }, + }, + { + object: new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), + durationLike: { + years: 1, + months: 2, + weeks: 3, + days: 4, + hours: 5, + minutes: 6, + seconds: 7, + milliseconds: 8, + microseconds: 9, + nanoseconds: 10, + }, + }, +]; + +var formatter = new Intl.DurationFormat(); + +for (var {object, durationLike} of durations) { + var expected = formatter.format(durationLike); + var actual = formatter.format(object); + assert.sameValue(actual, expected, `"${object}"`); +} diff --git a/test/intl402/DurationFormat/prototype/format/temporal-duration-string-arg.js b/test/intl402/DurationFormat/prototype/format/temporal-duration-string-arg.js new file mode 100644 index 0000000000..49134d1dfd --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/temporal-duration-string-arg.js @@ -0,0 +1,41 @@ +// Copyright 2025 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.format +description: > + Temporal duration strings can be passed to format. +features: [Temporal, Intl.DurationFormat] +---*/ + +var durations = [ + { + string: "PT0S", + durationLike: { + years: 0, + }, + }, + { + string: "P1Y2M3W4DT5H6M7.00800901S", + durationLike: { + years: 1, + months: 2, + weeks: 3, + days: 4, + hours: 5, + minutes: 6, + seconds: 7, + milliseconds: 8, + microseconds: 9, + nanoseconds: 10, + }, + }, +]; + +var formatter = new Intl.DurationFormat(); + +for (var {string, durationLike} of durations) { + var expected = formatter.format(durationLike); + var actual = formatter.format(string); + assert.sameValue(actual, expected, `"${string}"`); +} diff --git a/test/intl402/DurationFormat/prototype/formatToParts/taint-temporal-duration-prototype.js b/test/intl402/DurationFormat/prototype/formatToParts/taint-temporal-duration-prototype.js new file mode 100644 index 0000000000..89f745a3f5 --- /dev/null +++ b/test/intl402/DurationFormat/prototype/formatToParts/taint-temporal-duration-prototype.js @@ -0,0 +1,59 @@ +// Copyright 2025 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.formatToParts +description: > + Ensure Temporal.Duration.prototype getters aren't called. +features: [Temporal, Intl.DurationFormat] +---*/ + +function assertSameParts(actual, expected) { + assert.sameValue(actual.length, expected.length); + + for (var i = 0; i < actual.length; ++i) { + assert.sameValue(actual[i].type, expected[i].type); + assert.sameValue(actual[i].value, expected[i].value); + assert.sameValue(actual[i].unit, expected[i].unit); + } +} + +var duration = new Temporal.Duration( + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 +); + +var formatter = new Intl.DurationFormat(); + +var expected = formatter.formatToParts(duration); + +// Taint all Temporal.Duration.prototype getters. +for (var prop of [ + "years", + "months", + "weeks", + "days", + "hours", + "minutes", + "seconds", + "milliseconds", + "microseconds", + "nanoseconds", +]) { + // Ensure the property is present. + var desc = Object.getOwnPropertyDescriptor(Temporal.Duration.prototype, prop); + assert.notSameValue( + desc, + undefined, + "Descriptor not found: " + prop + ); + + Object.defineProperty(Temporal.Duration.prototype, prop, { + get() { + throw new Test262Error(); + } + }); +} + +var actual = formatter.formatToParts(duration); + +assertSameParts(actual, expected); diff --git a/test/intl402/DurationFormat/prototype/formatToParts/temporal-duration-object-arg.js b/test/intl402/DurationFormat/prototype/formatToParts/temporal-duration-object-arg.js new file mode 100644 index 0000000000..86522119de --- /dev/null +++ b/test/intl402/DurationFormat/prototype/formatToParts/temporal-duration-object-arg.js @@ -0,0 +1,51 @@ +// Copyright 2025 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.formatToParts +description: > + Temporal.Duration objects can be passed to formatToParts. +features: [Temporal, Intl.DurationFormat] +---*/ + +function assertSameParts(actual, expected) { + assert.sameValue(actual.length, expected.length); + + for (var i = 0; i < actual.length; ++i) { + assert.sameValue(actual[i].type, expected[i].type); + assert.sameValue(actual[i].value, expected[i].value); + assert.sameValue(actual[i].unit, expected[i].unit); + } +} + +var durations = [ + { + object: new Temporal.Duration(), + durationLike: { + years: 0, + }, + }, + { + object: new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), + durationLike: { + years: 1, + months: 2, + weeks: 3, + days: 4, + hours: 5, + minutes: 6, + seconds: 7, + milliseconds: 8, + microseconds: 9, + nanoseconds: 10, + }, + }, +]; + +var formatter = new Intl.DurationFormat(); + +for (var {object, durationLike} of durations) { + var expected = formatter.format(durationLike); + var actual = formatter.format(object); + assertSameParts(actual, expected); +} diff --git a/test/intl402/DurationFormat/prototype/formatToParts/temporal-duration-string-arg.js b/test/intl402/DurationFormat/prototype/formatToParts/temporal-duration-string-arg.js new file mode 100644 index 0000000000..5434ff419a --- /dev/null +++ b/test/intl402/DurationFormat/prototype/formatToParts/temporal-duration-string-arg.js @@ -0,0 +1,51 @@ +// Copyright 2025 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DurationFormat.prototype.formatToParts +description: > + Temporal duration strings can be passed to formatToParts. +features: [Temporal, Intl.DurationFormat] +---*/ + +function assertSameParts(actual, expected) { + assert.sameValue(actual.length, expected.length); + + for (var i = 0; i < actual.length; ++i) { + assert.sameValue(actual[i].type, expected[i].type); + assert.sameValue(actual[i].value, expected[i].value); + assert.sameValue(actual[i].unit, expected[i].unit); + } +} + +var durations = [ + { + string: "PT0S", + durationLike: { + years: 0, + }, + }, + { + string: "P1Y2M3W4DT5H6M7.00800901S", + durationLike: { + years: 1, + months: 2, + weeks: 3, + days: 4, + hours: 5, + minutes: 6, + seconds: 7, + milliseconds: 8, + microseconds: 9, + nanoseconds: 10, + }, + }, +]; + +var formatter = new Intl.DurationFormat(); + +for (var {string, durationLike} of durations) { + var expected = formatter.format(durationLike); + var actual = formatter.format(string); + assertSameParts(actual, expected); +} diff --git a/test/intl402/Temporal/Duration/prototype/toLocaleString/returns-same-results-as-DurationFormat.js b/test/intl402/Temporal/Duration/prototype/toLocaleString/returns-same-results-as-DurationFormat.js new file mode 100644 index 0000000000..388bb5c5df --- /dev/null +++ b/test/intl402/Temporal/Duration/prototype/toLocaleString/returns-same-results-as-DurationFormat.js @@ -0,0 +1,50 @@ +// Copyright 2025 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.tolocalestring +description: > + Tests that Temporal.Duration.prototype.toLocaleString produces the same + results as Intl.DurationFormat. +features: [Temporal, Intl.DurationFormat] +---*/ + +var durationLike = { + years: 1, + months: 2, + weeks: 3, + days: 4, + hours: 5, + minutes: 6, + seconds: 7, + milliseconds: 8, + microseconds: 9, + nanoseconds: 10, +}; + +var duration = Temporal.Duration.from(durationLike); + +var locales = [ + undefined, + "en", + "de", + "th-u-nu-thai", + ["ar-u-nu-arab"], +]; + +var options = [ + undefined, + {style: "long"}, +]; + +for (var locale of locales) { + for (var opts of options) { + var formatter = new Intl.DurationFormat(locale, opts); + + assert.sameValue( + duration.toLocaleString(locale, opts), + formatter.format(durationLike), + `locale="${locale}", options="${JSON.stringify(opts)}", duration="${JSON.stringify(duration)}"` + ); + } +} diff --git a/test/intl402/Temporal/Duration/prototype/toLocaleString/taint-duration-prototype.js b/test/intl402/Temporal/Duration/prototype/toLocaleString/taint-duration-prototype.js new file mode 100644 index 0000000000..cc65f5bf2c --- /dev/null +++ b/test/intl402/Temporal/Duration/prototype/toLocaleString/taint-duration-prototype.js @@ -0,0 +1,47 @@ +// Copyright 2025 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.tolocalestring +description: > + Ensure Temporal.Duration.prototype getters aren't called. +features: [Temporal, Intl.DurationFormat] +---*/ + +var duration = new Temporal.Duration( + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 +); + +var expected = duration.toLocaleString(); + +// Taint all Temporal.Duration.prototype getters. +for (var prop of [ + "years", + "months", + "weeks", + "days", + "hours", + "minutes", + "seconds", + "milliseconds", + "microseconds", + "nanoseconds", +]) { + // Ensure the property is present. + var desc = Object.getOwnPropertyDescriptor(Temporal.Duration.prototype, prop); + assert.notSameValue( + desc, + undefined, + "Descriptor not found: " + prop + ); + + Object.defineProperty(Temporal.Duration.prototype, prop, { + get() { + throw new Test262Error(); + } + }); +} + +var actual = duration.toLocaleString(); + +assert.sameValue(actual, expected);