Skip to content

Commit 3480528

Browse files
ptomatoMs2ger
authored andcommitted
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.
1 parent fefa14c commit 3480528

File tree

58 files changed

+1363
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1363
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.from
6+
description: >
7+
A Temporal.Calendar instance passed to from() does not have its
8+
'calendar' property observably checked
9+
features: [Temporal]
10+
---*/
11+
12+
const arg = new Temporal.Calendar("iso8601");
13+
Object.defineProperty(arg, "calendar", {
14+
get() {
15+
throw new Test262Error("calendar.calendar should not be accessed");
16+
},
17+
});
18+
19+
Temporal.Calendar.from(arg);
20+
Temporal.Calendar.from({ calendar: arg });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.prototype.dateadd
6+
description: >
7+
A Temporal.Calendar instance passed to dateAdd() in a property bag does
8+
not have its 'calendar' property observably checked
9+
features: [Temporal]
10+
---*/
11+
12+
const instance = new Temporal.Calendar("iso8601");
13+
14+
const calendar = new Temporal.Calendar("iso8601");
15+
Object.defineProperty(calendar, "calendar", {
16+
get() {
17+
throw new Test262Error("calendar.calendar should not be accessed");
18+
},
19+
});
20+
21+
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
22+
instance.dateAdd(arg, new Temporal.Duration());
23+
24+
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
25+
instance.dateAdd(arg, new Temporal.Duration());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.prototype.dateuntil
6+
description: >
7+
A Temporal.Calendar instance passed to dateUntil() in a property bag does
8+
not have its 'calendar' property observably checked
9+
features: [Temporal]
10+
---*/
11+
12+
const instance = new Temporal.Calendar("iso8601");
13+
14+
const calendar = new Temporal.Calendar("iso8601");
15+
Object.defineProperty(calendar, "calendar", {
16+
get() {
17+
throw new Test262Error("calendar.calendar should not be accessed");
18+
},
19+
});
20+
21+
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
22+
instance.dateUntil(arg, arg);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.prototype.day
6+
description: >
7+
A Temporal.Calendar instance passed to day() in a property bag does
8+
not have its 'calendar' property observably checked
9+
features: [Temporal]
10+
---*/
11+
12+
const instance = new Temporal.Calendar("iso8601");
13+
14+
const calendar = new Temporal.Calendar("iso8601");
15+
Object.defineProperty(calendar, "calendar", {
16+
get() {
17+
throw new Test262Error("calendar.calendar should not be accessed");
18+
},
19+
});
20+
21+
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
22+
instance.day(arg);
23+
24+
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
25+
instance.day(arg);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.prototype.dayofweek
6+
description: >
7+
A Temporal.Calendar instance passed to dayOfWeek() in a property bag does
8+
not have its 'calendar' property observably checked
9+
features: [Temporal]
10+
---*/
11+
12+
const instance = new Temporal.Calendar("iso8601");
13+
14+
const calendar = new Temporal.Calendar("iso8601");
15+
Object.defineProperty(calendar, "calendar", {
16+
get() {
17+
throw new Test262Error("calendar.calendar should not be accessed");
18+
},
19+
});
20+
21+
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
22+
instance.dayOfWeek(arg);
23+
24+
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
25+
instance.dayOfWeek(arg);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.prototype.dayofyear
6+
description: >
7+
A Temporal.Calendar instance passed to dayOfYear() in a property bag does
8+
not have its 'calendar' property observably checked
9+
features: [Temporal]
10+
---*/
11+
12+
const instance = new Temporal.Calendar("iso8601");
13+
14+
const calendar = new Temporal.Calendar("iso8601");
15+
Object.defineProperty(calendar, "calendar", {
16+
get() {
17+
throw new Test262Error("calendar.calendar should not be accessed");
18+
},
19+
});
20+
21+
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
22+
instance.dayOfYear(arg);
23+
24+
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
25+
instance.dayOfYear(arg);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.prototype.daysinmonth
6+
description: >
7+
A Temporal.Calendar instance passed to daysInMonth() in a property bag does
8+
not have its 'calendar' property observably checked
9+
features: [Temporal]
10+
---*/
11+
12+
const instance = new Temporal.Calendar("iso8601");
13+
14+
const calendar = new Temporal.Calendar("iso8601");
15+
Object.defineProperty(calendar, "calendar", {
16+
get() {
17+
throw new Test262Error("calendar.calendar should not be accessed");
18+
},
19+
});
20+
21+
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
22+
instance.daysInMonth(arg);
23+
24+
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
25+
instance.daysInMonth(arg);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.prototype.daysinweek
6+
description: >
7+
A Temporal.Calendar instance passed to daysInWeek() in a property bag does
8+
not have its 'calendar' property observably checked
9+
features: [Temporal]
10+
---*/
11+
12+
const instance = new Temporal.Calendar("iso8601");
13+
14+
const calendar = new Temporal.Calendar("iso8601");
15+
Object.defineProperty(calendar, "calendar", {
16+
get() {
17+
throw new Test262Error("calendar.calendar should not be accessed");
18+
},
19+
});
20+
21+
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
22+
instance.daysInWeek(arg);
23+
24+
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
25+
instance.daysInWeek(arg);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.prototype.daysinyear
6+
description: >
7+
A Temporal.Calendar instance passed to daysInYear() in a property bag does
8+
not have its 'calendar' property observably checked
9+
features: [Temporal]
10+
---*/
11+
12+
const instance = new Temporal.Calendar("iso8601");
13+
14+
const calendar = new Temporal.Calendar("iso8601");
15+
Object.defineProperty(calendar, "calendar", {
16+
get() {
17+
throw new Test262Error("calendar.calendar should not be accessed");
18+
},
19+
});
20+
21+
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
22+
instance.daysInYear(arg);
23+
24+
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
25+
instance.daysInYear(arg);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.prototype.inleapyear
6+
description: >
7+
A Temporal.Calendar instance passed to inLeapYear() in a property bag does
8+
not have its 'calendar' property observably checked
9+
features: [Temporal]
10+
---*/
11+
12+
const instance = new Temporal.Calendar("iso8601");
13+
14+
const calendar = new Temporal.Calendar("iso8601");
15+
Object.defineProperty(calendar, "calendar", {
16+
get() {
17+
throw new Test262Error("calendar.calendar should not be accessed");
18+
},
19+
});
20+
21+
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
22+
instance.inLeapYear(arg);
23+
24+
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
25+
instance.inLeapYear(arg);

0 commit comments

Comments
 (0)