-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporal: Add tests for fast path in ToTemporalCalendar
Normally, a plain object passed into an API that takes a Temporal.Calendar has its 'calendar' property checked (observably) with a Has operation followed by a Get operation if the property is present. In the normative change tc39/proposal-temporal#2392 which reached consensus at the September 2022 TC39 meeting, this was changed so that this check is skipped for objects which have the Temporal.Calendar internal slots. This adds tests to all entry points that pass a user-supplied object to ToTemporalCalendar, with a "poisoned" calendar object which has the correct internal slots but a 'calendar' accessor property whose getter throws. A correct implementation should not cause this getter to throw.
- Loading branch information
Showing
58 changed files
with
1,363 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
test/built-ins/Temporal/Calendar/from/calendar-instance-does-not-get-calendar-property.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,20 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.from | ||
description: > | ||
A Temporal.Calendar instance passed to from() does not have its | ||
'calendar' property observably checked | ||
features: [Temporal] | ||
---*/ | ||
|
||
const arg = new Temporal.Calendar("iso8601"); | ||
Object.defineProperty(arg, "calendar", { | ||
get() { | ||
throw new Test262Error("calendar.calendar should not be accessed"); | ||
}, | ||
}); | ||
|
||
Temporal.Calendar.from(arg); | ||
Temporal.Calendar.from({ calendar: arg }); |
25 changes: 25 additions & 0 deletions
25
...rototype/dateAdd/argument-propertybag-calendar-instance-does-not-get-calendar-property.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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.dateadd | ||
description: > | ||
A Temporal.Calendar instance passed to dateAdd() in a property bag does | ||
not have its 'calendar' property observably checked | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const calendar = new Temporal.Calendar("iso8601"); | ||
Object.defineProperty(calendar, "calendar", { | ||
get() { | ||
throw new Test262Error("calendar.calendar should not be accessed"); | ||
}, | ||
}); | ||
|
||
let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; | ||
instance.dateAdd(arg, new Temporal.Duration()); | ||
|
||
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; | ||
instance.dateAdd(arg, new Temporal.Duration()); |
22 changes: 22 additions & 0 deletions
22
...totype/dateUntil/argument-propertybag-calendar-instance-does-not-get-calendar-property.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,22 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.dateuntil | ||
description: > | ||
A Temporal.Calendar instance passed to dateUntil() in a property bag does | ||
not have its 'calendar' property observably checked | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const calendar = new Temporal.Calendar("iso8601"); | ||
Object.defineProperty(calendar, "calendar", { | ||
get() { | ||
throw new Test262Error("calendar.calendar should not be accessed"); | ||
}, | ||
}); | ||
|
||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; | ||
instance.dateUntil(arg, arg); |
25 changes: 25 additions & 0 deletions
25
...ar/prototype/day/argument-propertybag-calendar-instance-does-not-get-calendar-property.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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.day | ||
description: > | ||
A Temporal.Calendar instance passed to day() in a property bag does | ||
not have its 'calendar' property observably checked | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const calendar = new Temporal.Calendar("iso8601"); | ||
Object.defineProperty(calendar, "calendar", { | ||
get() { | ||
throw new Test262Error("calendar.calendar should not be accessed"); | ||
}, | ||
}); | ||
|
||
let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; | ||
instance.day(arg); | ||
|
||
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; | ||
instance.day(arg); |
25 changes: 25 additions & 0 deletions
25
...totype/dayOfWeek/argument-propertybag-calendar-instance-does-not-get-calendar-property.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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.dayofweek | ||
description: > | ||
A Temporal.Calendar instance passed to dayOfWeek() in a property bag does | ||
not have its 'calendar' property observably checked | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const calendar = new Temporal.Calendar("iso8601"); | ||
Object.defineProperty(calendar, "calendar", { | ||
get() { | ||
throw new Test262Error("calendar.calendar should not be accessed"); | ||
}, | ||
}); | ||
|
||
let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; | ||
instance.dayOfWeek(arg); | ||
|
||
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; | ||
instance.dayOfWeek(arg); |
25 changes: 25 additions & 0 deletions
25
...totype/dayOfYear/argument-propertybag-calendar-instance-does-not-get-calendar-property.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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.dayofyear | ||
description: > | ||
A Temporal.Calendar instance passed to dayOfYear() in a property bag does | ||
not have its 'calendar' property observably checked | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const calendar = new Temporal.Calendar("iso8601"); | ||
Object.defineProperty(calendar, "calendar", { | ||
get() { | ||
throw new Test262Error("calendar.calendar should not be accessed"); | ||
}, | ||
}); | ||
|
||
let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; | ||
instance.dayOfYear(arg); | ||
|
||
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; | ||
instance.dayOfYear(arg); |
25 changes: 25 additions & 0 deletions
25
...type/daysInMonth/argument-propertybag-calendar-instance-does-not-get-calendar-property.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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.daysinmonth | ||
description: > | ||
A Temporal.Calendar instance passed to daysInMonth() in a property bag does | ||
not have its 'calendar' property observably checked | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const calendar = new Temporal.Calendar("iso8601"); | ||
Object.defineProperty(calendar, "calendar", { | ||
get() { | ||
throw new Test262Error("calendar.calendar should not be accessed"); | ||
}, | ||
}); | ||
|
||
let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; | ||
instance.daysInMonth(arg); | ||
|
||
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; | ||
instance.daysInMonth(arg); |
25 changes: 25 additions & 0 deletions
25
...otype/daysInWeek/argument-propertybag-calendar-instance-does-not-get-calendar-property.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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.daysinweek | ||
description: > | ||
A Temporal.Calendar instance passed to daysInWeek() in a property bag does | ||
not have its 'calendar' property observably checked | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const calendar = new Temporal.Calendar("iso8601"); | ||
Object.defineProperty(calendar, "calendar", { | ||
get() { | ||
throw new Test262Error("calendar.calendar should not be accessed"); | ||
}, | ||
}); | ||
|
||
let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; | ||
instance.daysInWeek(arg); | ||
|
||
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; | ||
instance.daysInWeek(arg); |
25 changes: 25 additions & 0 deletions
25
...otype/daysInYear/argument-propertybag-calendar-instance-does-not-get-calendar-property.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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.daysinyear | ||
description: > | ||
A Temporal.Calendar instance passed to daysInYear() in a property bag does | ||
not have its 'calendar' property observably checked | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const calendar = new Temporal.Calendar("iso8601"); | ||
Object.defineProperty(calendar, "calendar", { | ||
get() { | ||
throw new Test262Error("calendar.calendar should not be accessed"); | ||
}, | ||
}); | ||
|
||
let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; | ||
instance.daysInYear(arg); | ||
|
||
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; | ||
instance.daysInYear(arg); |
25 changes: 25 additions & 0 deletions
25
...otype/inLeapYear/argument-propertybag-calendar-instance-does-not-get-calendar-property.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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.inleapyear | ||
description: > | ||
A Temporal.Calendar instance passed to inLeapYear() in a property bag does | ||
not have its 'calendar' property observably checked | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const calendar = new Temporal.Calendar("iso8601"); | ||
Object.defineProperty(calendar, "calendar", { | ||
get() { | ||
throw new Test262Error("calendar.calendar should not be accessed"); | ||
}, | ||
}); | ||
|
||
let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; | ||
instance.inLeapYear(arg); | ||
|
||
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; | ||
instance.inLeapYear(arg); |
25 changes: 25 additions & 0 deletions
25
.../prototype/month/argument-propertybag-calendar-instance-does-not-get-calendar-property.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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.month | ||
description: > | ||
A Temporal.Calendar instance passed to month() in a property bag does | ||
not have its 'calendar' property observably checked | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const calendar = new Temporal.Calendar("iso8601"); | ||
Object.defineProperty(calendar, "calendar", { | ||
get() { | ||
throw new Test262Error("calendar.calendar should not be accessed"); | ||
}, | ||
}); | ||
|
||
let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; | ||
instance.month(arg); | ||
|
||
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; | ||
instance.month(arg); |
25 changes: 25 additions & 0 deletions
25
...totype/monthCode/argument-propertybag-calendar-instance-does-not-get-calendar-property.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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.monthcode | ||
description: > | ||
A Temporal.Calendar instance passed to monthCode() in a property bag does | ||
not have its 'calendar' property observably checked | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const calendar = new Temporal.Calendar("iso8601"); | ||
Object.defineProperty(calendar, "calendar", { | ||
get() { | ||
throw new Test262Error("calendar.calendar should not be accessed"); | ||
}, | ||
}); | ||
|
||
let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; | ||
instance.monthCode(arg); | ||
|
||
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; | ||
instance.monthCode(arg); |
25 changes: 25 additions & 0 deletions
25
...ype/monthsInYear/argument-propertybag-calendar-instance-does-not-get-calendar-property.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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.monthsinyear | ||
description: > | ||
A Temporal.Calendar instance passed to monthsInYear() in a property bag does | ||
not have its 'calendar' property observably checked | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const calendar = new Temporal.Calendar("iso8601"); | ||
Object.defineProperty(calendar, "calendar", { | ||
get() { | ||
throw new Test262Error("calendar.calendar should not be accessed"); | ||
}, | ||
}); | ||
|
||
let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; | ||
instance.monthsInYear(arg); | ||
|
||
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; | ||
instance.monthsInYear(arg); |
25 changes: 25 additions & 0 deletions
25
...otype/weekOfYear/argument-propertybag-calendar-instance-does-not-get-calendar-property.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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.weekofyear | ||
description: > | ||
A Temporal.Calendar instance passed to weekOfYear() in a property bag does | ||
not have its 'calendar' property observably checked | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const calendar = new Temporal.Calendar("iso8601"); | ||
Object.defineProperty(calendar, "calendar", { | ||
get() { | ||
throw new Test262Error("calendar.calendar should not be accessed"); | ||
}, | ||
}); | ||
|
||
let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; | ||
instance.weekOfYear(arg); | ||
|
||
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; | ||
instance.weekOfYear(arg); |
25 changes: 25 additions & 0 deletions
25
...r/prototype/year/argument-propertybag-calendar-instance-does-not-get-calendar-property.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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.year | ||
description: > | ||
A Temporal.Calendar instance passed to year() in a property bag does | ||
not have its 'calendar' property observably checked | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const calendar = new Temporal.Calendar("iso8601"); | ||
Object.defineProperty(calendar, "calendar", { | ||
get() { | ||
throw new Test262Error("calendar.calendar should not be accessed"); | ||
}, | ||
}); | ||
|
||
let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; | ||
instance.year(arg); | ||
|
||
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; | ||
instance.year(arg); |
Oops, something went wrong.