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
56
57
58
|
// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.datefromfields
description: Temporal.Calendar.prototype.dateFromFields should throw TypeError with wrong type.
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. If Type(fields) is not Object, throw a TypeError exception.
5. Set options to ? GetOptionsObject(options).
6. Let result be ? ISODateFromFields(fields, options).
7. Return ? CreateTemporalDate(result.[[Year]], result.[[Month]], result.[[Day]], calendar).
features: [BigInt, Symbol, Temporal, arrow-function]
---*/
// Check throw for first arg
let cal = new Temporal.Calendar('iso8601');
assert.throws(TypeError, () => cal.dateFromFields(), 'cal.dateFromFields() throws a TypeError exception');
[undefined, true, false, 123, 456n, Symbol(), 'string'].forEach(function(fields) {
assert.throws(
TypeError,
() => cal.dateFromFields(fields),
'cal.dateFromFields(fields) throws a TypeError exception'
);
assert.throws(
TypeError,
() => cal.dateFromFields(fields, undefined),
'cal.dateFromFields(fields, undefined) throws a TypeError exception'
);
assert.throws(TypeError, () => cal.dateFromFields(fields, {
overflow: 'constrain'
}), 'cal.dateFromFields(fields, {overflow: "constrain"}) throws a TypeError exception');
assert.throws(TypeError, () => cal.dateFromFields(fields, {
overflow: 'reject'
}), 'cal.dateFromFields(fields, {overflow: "reject"}) throws a TypeError exception');
});
assert.throws(TypeError, () => cal.dateFromFields({
month: 1,
day: 17
}), 'cal.dateFromFields({month: 1, day: 17}) throws a TypeError exception');
assert.throws(TypeError, () => cal.dateFromFields({
year: 2021,
day: 17
}), 'cal.dateFromFields({year: 2021, day: 17}) throws a TypeError exception');
assert.throws(TypeError, () => cal.dateFromFields({
year: 2021,
month: 12
}), 'cal.dateFromFields({year: 2021, month: 12}) throws a TypeError exception');
reportCompare(0, 0);
|