forked from tc39/proposal-temporal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow calendar.fields() to accept an iterable
Temporal will only ever call the fields() method with an array, but other callers may want to supply a different iterable (such as a Set). See: tc39#1427
Showing
7 changed files
with
53 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
polyfill/test/Calendar/prototype/fields/argument-iterable-not-array.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (C) 2021 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.fields | ||
info: | | ||
sec-temporal.calendar.prototype.fields step 4: | ||
4. Let _fieldNames_ be ? IterableToList(_fields_). | ||
includes: [compareArray.js] | ||
---*/ | ||
|
||
const fieldNames = ["day", "month", "monthCode", "year"]; | ||
const iterable = { | ||
iteratorExhausted: false, | ||
*[Symbol.iterator]() { | ||
yield* fieldNames; | ||
this.iteratorExhausted = true; | ||
}, | ||
}; | ||
|
||
const calendar = new Temporal.Calendar("iso8601"); | ||
const result = calendar.fields(iterable); | ||
|
||
assert.compareArray(result, fieldNames); | ||
assert(iterable.iteratorExhausted); |
15 changes: 15 additions & 0 deletions
15
polyfill/test/Calendar/prototype/fields/non-string-element-throws.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (C) 2021 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.fields | ||
info: | | ||
sec-temporal.calendar.prototype.fields step 5: | ||
5. For each element _fieldName_ of _fieldNames_, do | ||
a. If Type(_fieldName_) is not String, throw a *TypeError* exception. | ||
---*/ | ||
|
||
const calendar = new Temporal.Calendar("iso8601"); | ||
[true, 3, 3n, {}, () => {}, Symbol(), undefined, null].forEach((element) => { | ||
assert.throws(TypeError, () => calendar.fields([element]), "bad input to calendar.fields()"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters