|
| 1 | +// Copyright 2025 André Bargull. All rights reserved. |
| 2 | +// This code is governed by the BSD license found in the LICENSE file. |
| 3 | + |
| 4 | +/*--- |
| 5 | +esid: sec-Intl.DurationFormat.prototype.formatToParts |
| 6 | +description: > |
| 7 | + Ensure Temporal.Duration.prototype getters aren't called. |
| 8 | +features: [Temporal, Intl.DurationFormat] |
| 9 | +---*/ |
| 10 | + |
| 11 | +function assertSameParts(actual, expected) { |
| 12 | + assert.sameValue(actual.length, expected.length); |
| 13 | + |
| 14 | + for (var i = 0; i < actual.length; ++i) { |
| 15 | + assert.sameValue(actual[i].type, expected[i].type); |
| 16 | + assert.sameValue(actual[i].value, expected[i].value); |
| 17 | + assert.sameValue(actual[i].unit, expected[i].unit); |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +var duration = new Temporal.Duration( |
| 22 | + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 |
| 23 | +); |
| 24 | + |
| 25 | +var formatter = new Intl.DurationFormat(); |
| 26 | + |
| 27 | +var expected = formatter.formatToParts(duration); |
| 28 | + |
| 29 | +// Taint all Temporal.Duration.prototype getters. |
| 30 | +for (var prop of [ |
| 31 | + "years", |
| 32 | + "months", |
| 33 | + "weeks", |
| 34 | + "days", |
| 35 | + "hours", |
| 36 | + "minutes", |
| 37 | + "seconds", |
| 38 | + "milliseconds", |
| 39 | + "microseconds", |
| 40 | + "nanoseconds", |
| 41 | +]) { |
| 42 | + // Ensure the property is present. |
| 43 | + var desc = Object.getOwnPropertyDescriptor(Temporal.Duration.prototype, prop); |
| 44 | + assert.notSameValue( |
| 45 | + desc, |
| 46 | + undefined, |
| 47 | + "Descriptor not found: " + prop |
| 48 | + ); |
| 49 | + |
| 50 | + Object.defineProperty(Temporal.Duration.prototype, prop, { |
| 51 | + get() { |
| 52 | + throw new Test262Error(); |
| 53 | + } |
| 54 | + }); |
| 55 | +} |
| 56 | + |
| 57 | +var actual = formatter.formatToParts(duration); |
| 58 | + |
| 59 | +assertSameParts(actual, expected); |
0 commit comments