forked from tc39/test262
-
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.
Store strings or objects in Temporal objects' [[Calendar]] slot
In several tests involving custom calendars, we need to change the implementation of dateFromFields/monthDayFromFields/yearMonthFromFields so that the returned object gets the receiver as its calendar after chaining up to the builtin implementation. Normative PR: tc39/proposal-temporal#2482
- Loading branch information
Showing
141 changed files
with
3,116 additions
and
166 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
25 changes: 25 additions & 0 deletions
25
test/built-ins/Temporal/Duration/compare/relativeto-propertybag-calendar-string.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) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.compare | ||
description: > | ||
Builtin dateFromFields method is not observably called when the property bag | ||
has a string-valued calendar property | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const dateFromFieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "dateFromFields"); | ||
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", { | ||
configurable: true, | ||
enumerable: false, | ||
get() { | ||
TemporalHelpers.assertUnreachable("dateFromFields should not be looked up"); | ||
}, | ||
}); | ||
|
||
const relativeTo = { year: 2000, month: 5, day: 2, calendar: "iso8601" }; | ||
Temporal.Duration.compare(new Temporal.Duration(), new Temporal.Duration(), { relativeTo }); | ||
|
||
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", dateFromFieldsOriginal); |
26 changes: 26 additions & 0 deletions
26
test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-string.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,26 @@ | ||
// Copyright (C) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.add | ||
description: > | ||
Builtin dateFromFields method is not observably called when the property bag | ||
has a string-valued calendar property | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const dateFromFieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "dateFromFields"); | ||
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", { | ||
configurable: true, | ||
enumerable: false, | ||
get() { | ||
TemporalHelpers.assertUnreachable("dateFromFields should not be looked up"); | ||
}, | ||
}); | ||
|
||
const instance = new Temporal.Duration(1, 0, 0, 1); | ||
const relativeTo = { year: 2000, month: 5, day: 2, calendar: "iso8601" }; | ||
instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); | ||
|
||
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", dateFromFieldsOriginal); |
26 changes: 26 additions & 0 deletions
26
test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-string.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,26 @@ | ||
// Copyright (C) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.round | ||
description: > | ||
Builtin dateFromFields method is not observably called when the property bag | ||
has a string-valued calendar property | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const dateFromFieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "dateFromFields"); | ||
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", { | ||
configurable: true, | ||
enumerable: false, | ||
get() { | ||
TemporalHelpers.assertUnreachable("dateFromFields should not be looked up"); | ||
}, | ||
}); | ||
|
||
const instance = new Temporal.Duration(1, 0, 0, 0, 24); | ||
const relativeTo = { year: 2000, month: 5, day: 2, calendar: "iso8601" }; | ||
instance.round({ largestUnit: "years", relativeTo }); | ||
|
||
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", dateFromFieldsOriginal); |
26 changes: 26 additions & 0 deletions
26
.../built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-string.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,26 @@ | ||
// Copyright (C) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.subtract | ||
description: > | ||
Builtin dateFromFields method is not observably called when the property bag | ||
has a string-valued calendar property | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const dateFromFieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "dateFromFields"); | ||
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", { | ||
configurable: true, | ||
enumerable: false, | ||
get() { | ||
TemporalHelpers.assertUnreachable("dateFromFields should not be looked up"); | ||
}, | ||
}); | ||
|
||
const instance = new Temporal.Duration(1, 0, 0, 1); | ||
const relativeTo = { year: 2000, month: 5, day: 2, calendar: "iso8601" }; | ||
instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); | ||
|
||
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", dateFromFieldsOriginal); |
26 changes: 26 additions & 0 deletions
26
test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-string.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,26 @@ | ||
// Copyright (C) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.total | ||
description: > | ||
Builtin dateFromFields method is not observably called when the property bag | ||
has a string-valued calendar property | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const dateFromFieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "dateFromFields"); | ||
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", { | ||
configurable: true, | ||
enumerable: false, | ||
get() { | ||
TemporalHelpers.assertUnreachable("dateFromFields should not be looked up"); | ||
}, | ||
}); | ||
|
||
const instance = new Temporal.Duration(1, 0, 0, 0, 24); | ||
const relativeTo = { year: 2000, month: 5, day: 2, calendar: "iso8601" }; | ||
instance.total({ unit: "days", relativeTo }); | ||
|
||
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", dateFromFieldsOriginal); |
13 changes: 13 additions & 0 deletions
13
test/built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/calendar-is-builtin.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,13 @@ | ||
// Copyright (C) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.instant.prototype.tozoneddatetimeiso | ||
description: > | ||
toZonedDateTimeISO() results in a ZonedDateTime with builtin ISO calendar | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Instant(0n); | ||
const result = instance.toZonedDateTimeISO("UTC"); | ||
assert.sameValue(result.getISOFields().calendar, "iso8601", "calendar slot stores a string"); |
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
test/built-ins/Temporal/PlainDate/prototype/add/builtin-calendar-no-observable-calls.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) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.plaindate.prototype.add | ||
description: > | ||
Calling the method on an instance constructed with a builtin calendar causes | ||
no observable lookups or calls to calendar methods. | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const dateAddOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "dateAdd"); | ||
Object.defineProperty(Temporal.Calendar.prototype, "dateAdd", { | ||
configurable: true, | ||
enumerable: false, | ||
get() { | ||
TemporalHelpers.assertUnreachable("dateAdd should not be looked up"); | ||
}, | ||
}); | ||
|
||
const instance = new Temporal.PlainDate(2000, 5, 2, "iso8601"); | ||
instance.add(new Temporal.Duration(1)); | ||
|
||
Object.defineProperty(Temporal.Calendar.prototype, "dateAdd", dateAddOriginal); |
25 changes: 25 additions & 0 deletions
25
...built-ins/Temporal/PlainDate/prototype/calendarId/builtin-calendar-no-observable-calls.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) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.plaindate.prototype.calendarid | ||
description: > | ||
Calling the method on an instance constructed with a builtin calendar causes | ||
no observable lookups or calls to calendar methods. | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const idOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "id"); | ||
Object.defineProperty(Temporal.Calendar.prototype, "id", { | ||
configurable: true, | ||
enumerable: false, | ||
get() { | ||
TemporalHelpers.assertUnreachable("id should not be looked up"); | ||
}, | ||
}); | ||
|
||
const instance = new Temporal.PlainDate(2000, 5, 2, "iso8601"); | ||
instance.calendarId; | ||
|
||
Object.defineProperty(Temporal.Calendar.prototype, "id", idOriginal); |
25 changes: 25 additions & 0 deletions
25
test/built-ins/Temporal/PlainDate/prototype/day/builtin-calendar-no-observable-calls.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) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.plaindate.prototype.day | ||
description: > | ||
Calling the method on an instance constructed with a builtin calendar causes | ||
no observable lookups or calls to calendar methods. | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const dayOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "day"); | ||
Object.defineProperty(Temporal.Calendar.prototype, "day", { | ||
configurable: true, | ||
enumerable: false, | ||
get() { | ||
TemporalHelpers.assertUnreachable("day should not be looked up"); | ||
}, | ||
}); | ||
|
||
const instance = new Temporal.PlainDate(2000, 5, 2, "iso8601"); | ||
instance.day; | ||
|
||
Object.defineProperty(Temporal.Calendar.prototype, "day", dayOriginal); |
25 changes: 25 additions & 0 deletions
25
.../built-ins/Temporal/PlainDate/prototype/dayOfWeek/builtin-calendar-no-observable-calls.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) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.plaindate.prototype.dayofweek | ||
description: > | ||
Calling the method on an instance constructed with a builtin calendar causes | ||
no observable lookups or calls to calendar methods. | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const dayOfWeekOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "dayOfWeek"); | ||
Object.defineProperty(Temporal.Calendar.prototype, "dayOfWeek", { | ||
configurable: true, | ||
enumerable: false, | ||
get() { | ||
TemporalHelpers.assertUnreachable("dayOfWeek should not be looked up"); | ||
}, | ||
}); | ||
|
||
const instance = new Temporal.PlainDate(2000, 5, 2, "iso8601"); | ||
instance.dayOfWeek; | ||
|
||
Object.defineProperty(Temporal.Calendar.prototype, "dayOfWeek", dayOfWeekOriginal); |
25 changes: 25 additions & 0 deletions
25
.../built-ins/Temporal/PlainDate/prototype/dayOfYear/builtin-calendar-no-observable-calls.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) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.plaindate.prototype.dayofyear | ||
description: > | ||
Calling the method on an instance constructed with a builtin calendar causes | ||
no observable lookups or calls to calendar methods. | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const dayOfYearOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "dayOfYear"); | ||
Object.defineProperty(Temporal.Calendar.prototype, "dayOfYear", { | ||
configurable: true, | ||
enumerable: false, | ||
get() { | ||
TemporalHelpers.assertUnreachable("dayOfYear should not be looked up"); | ||
}, | ||
}); | ||
|
||
const instance = new Temporal.PlainDate(2000, 5, 2, "iso8601"); | ||
instance.dayOfYear; | ||
|
||
Object.defineProperty(Temporal.Calendar.prototype, "dayOfYear", dayOfYearOriginal); |
25 changes: 25 additions & 0 deletions
25
...uilt-ins/Temporal/PlainDate/prototype/daysInMonth/builtin-calendar-no-observable-calls.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) 2023 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.plaindate.prototype.daysinmonth | ||
description: > | ||
Calling the method on an instance constructed with a builtin calendar causes | ||
no observable lookups or calls to calendar methods. | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const daysInMonthOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "daysInMonth"); | ||
Object.defineProperty(Temporal.Calendar.prototype, "daysInMonth", { | ||
configurable: true, | ||
enumerable: false, | ||
get() { | ||
TemporalHelpers.assertUnreachable("daysInMonth should not be looked up"); | ||
}, | ||
}); | ||
|
||
const instance = new Temporal.PlainDate(2000, 5, 2, "iso8601"); | ||
instance.daysInMonth; | ||
|
||
Object.defineProperty(Temporal.Calendar.prototype, "daysInMonth", daysInMonthOriginal); |
Oops, something went wrong.