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