|
| 1 | +// Copyright (C) 2023 Richard Gibson. All rights reserved. |
| 2 | +// This code is governed by the BSD license found in the LICENSE file. |
| 3 | + |
| 4 | +/*--- |
| 5 | +esid: sec-get-temporal.plaindatetime.prototype.erayear |
| 6 | +description: Validate result returned from calendar eraYear() method |
| 7 | +features: [Temporal] |
| 8 | +---*/ |
| 9 | + |
| 10 | +const badResults = [ |
| 11 | + [null, TypeError], |
| 12 | + [false, TypeError], |
| 13 | + [Infinity, RangeError], |
| 14 | + [-Infinity, RangeError], |
| 15 | + [NaN, RangeError], |
| 16 | + [-0.1, RangeError], |
| 17 | + ["string", TypeError], |
| 18 | + [Symbol("foo"), TypeError], |
| 19 | + [7n, TypeError], |
| 20 | + [{}, TypeError], |
| 21 | + [true, TypeError], |
| 22 | + [7.1, RangeError], |
| 23 | + ["7", TypeError], |
| 24 | + ["7.5", TypeError], |
| 25 | + [{valueOf() { return 7; }}, TypeError], |
| 26 | +]; |
| 27 | + |
| 28 | +badResults.forEach(([result, error]) => { |
| 29 | + const calendar = new class extends Temporal.Calendar { |
| 30 | + eraYear() { |
| 31 | + return result; |
| 32 | + } |
| 33 | + }("iso8601"); |
| 34 | + const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar); |
| 35 | + assert.throws(error, () => instance.eraYear, `${typeof result} ${String(result)} not converted to integer`); |
| 36 | +}); |
| 37 | + |
| 38 | +const preservedResults = [ |
| 39 | + undefined, |
| 40 | + -7, |
| 41 | +]; |
| 42 | + |
| 43 | +preservedResults.forEach(result => { |
| 44 | + const calendar = new class extends Temporal.Calendar { |
| 45 | + eraYear() { |
| 46 | + return result; |
| 47 | + } |
| 48 | + }("iso8601"); |
| 49 | + const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar); |
| 50 | + assert.sameValue(instance.eraYear, result, `${typeof result} ${String(result)} preserved`); |
| 51 | +}); |
0 commit comments