v8/test/mjsunit/temporal/calendar-fields.js
Frank Tang f811e89269 [Temporal] Part2 Add constructor and simple getters.
Bug: v8:11544

Change-Id: I3206ca3e0c505b14e4497ccb2af25a31940a1c1e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2967755
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78518}
2022-01-07 19:18:33 +00:00

59 lines
1.5 KiB
JavaScript

// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.fields
let cal = new Temporal.Calendar("iso8601")
assertEquals("iso8601", cal.id)
let i = 1;
const repeated = {
*[Symbol.iterator]() {
yield "year";
i++;
yield "year";
i++;
}
}
assertThrows(() => cal.fields(repeated), RangeError);
assertEquals(2, i);
let repeatedArray = Array.from(repeated);
assertThrows(() => cal.fields(repeatedArray), RangeError);
const week = {
*[Symbol.iterator]() {
yield "week";
}
}
assertThrows(() => cal.fields(week), RangeError);
assertThrows(() => cal.fields(['week']), RangeError);
assertThrows(() => cal.fields(new Set(['week'])), RangeError);
const allValid = {
*[Symbol.iterator]() {
yield "nanosecond";
yield "microsecond";
yield "millisecond";
yield "second";
yield "minute";
yield "hour";
yield "day";
yield "monthCode";
yield "month";
yield "year";
}
}
let allValidArray = Array.from(allValid);
let allValidSet = new Set(allValid);
assertArrayEquals(allValidArray, cal.fields(allValid));
assertArrayEquals(allValidArray, cal.fields(allValidArray));
assertArrayEquals(allValidArray, cal.fields(allValidSet));
// cannot just return the same array
assertTrue(allValidArray != cal.fields(allValidArray));