diff --git a/lib/calendar.ts b/lib/calendar.ts index e3f5c132..c216cf35 100644 --- a/lib/calendar.ts +++ b/lib/calendar.ts @@ -61,8 +61,22 @@ export class Calendar implements Temporal.Calendar { fields(fields) { if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver'); const fieldsArray = []; + const allowed = new Set([ + 'year', + 'month', + 'monthCode', + 'day', + 'hour', + 'minute', + 'second', + 'millisecond', + 'microsecond', + 'nanosecond' + ]); for (const name of fields) { if (ES.Type(name) !== 'String') throw new TypeError('invalid fields'); + if (!allowed.has(name)) throw new RangeError(`invalid field name ${name}`); + allowed.delete(name); ArrayPrototypePush.call(fieldsArray, name); } return impl[GetSlot(this, CALENDAR_ID)].fields(fieldsArray);