Skip to content

Commit

Permalink
Temporal: Add tests for fast path in ToTemporalCalendar
Browse files Browse the repository at this point in the history
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
ptomato authored and Ms2ger committed Oct 18, 2022
1 parent fefa14c commit 3480528
Show file tree
Hide file tree
Showing 58 changed files with 1,363 additions and 0 deletions.
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 });
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());
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
Loading

0 comments on commit 3480528

Please sign in to comment.