Skip to content

Commit

Permalink
Temporal: Add tests for fast path in ToTemporalTimeZone
Browse files Browse the repository at this point in the history
Normally, a plain object passed into an API that takes a Temporal.TimeZone
has its 'timeZone' 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.TimeZone
internal slots.

This adds tests to all entry points that pass a user-supplied object to
ToTemporalTimeZone, with a "poisoned" timeZone object which has the
correct internal slots but a 'timeZone' 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 3480528 commit 1f59bf5
Show file tree
Hide file tree
Showing 26 changed files with 551 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.duration.compare
description: >
A Temporal.TimeZone instance passed to compare() does not have its
'timeZone' property observably checked
features: [Temporal]
---*/

const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "timeZone", {
get() {
throw new Test262Error("timeZone.timeZone should not be accessed");
},
});

Temporal.Duration.compare(new Temporal.Duration(), new Temporal.Duration(), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } });
Temporal.Duration.compare(new Temporal.Duration(), new Temporal.Duration(), { relativeTo: { year: 2000, month: 5, day: 2, timeZone: { timeZone } } });
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.duration.prototype.add
description: >
A Temporal.TimeZone instance passed to add() does not have its
'timeZone' property observably checked
features: [Temporal]
---*/

const instance = new Temporal.Duration(1);

const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "timeZone", {
get() {
throw new Test262Error("timeZone.timeZone should not be accessed");
},
});

instance.add(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } });
instance.add(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone: { timeZone } } });
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.duration.prototype.round
description: >
A Temporal.TimeZone instance passed to round() does not have its
'timeZone' property observably checked
features: [Temporal]
---*/

const instance = new Temporal.Duration(1);

const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "timeZone", {
get() {
throw new Test262Error("timeZone.timeZone should not be accessed");
},
});

instance.round({ largestUnit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone } });
instance.round({ largestUnit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone: { timeZone } } });
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.duration.prototype.subtract
description: >
A Temporal.TimeZone instance passed to subtract() does not have its
'timeZone' property observably checked
features: [Temporal]
---*/

const instance = new Temporal.Duration(1);

const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "timeZone", {
get() {
throw new Test262Error("timeZone.timeZone should not be accessed");
},
});

instance.subtract(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } });
instance.subtract(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone: { timeZone } } });
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.duration.prototype.total
description: >
A Temporal.TimeZone instance passed to total() does not have its
'timeZone' property observably checked
features: [Temporal]
---*/

const instance = new Temporal.Duration(1);

const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "timeZone", {
get() {
throw new Test262Error("timeZone.timeZone should not be accessed");
},
});

instance.total({ unit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone } });
instance.total({ unit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone: { timeZone } } });
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.instant.prototype.tostring
description: >
A Temporal.TimeZone instance passed to toString() does not have its
'timeZone' property observably checked
features: [Temporal]
---*/

const instance = new Temporal.Instant(0n);

const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "timeZone", {
get() {
throw new Test262Error("timeZone.timeZone should not be accessed");
},
});

instance.toString({ timeZone });
instance.toString({ timeZone: { timeZone } });
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.instant.prototype.tozoneddatetime
description: >
A Temporal.TimeZone instance passed to toZonedDateTime() does not have its
'timeZone' property observably checked
features: [Temporal]
---*/

const instance = new Temporal.Instant(0n);

const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "timeZone", {
get() {
throw new Test262Error("timeZone.timeZone should not be accessed");
},
});

instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
instance.toZonedDateTime({ timeZone: { timeZone }, calendar: "iso8601" });
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.instant.prototype.tozoneddatetimeiso
description: >
A Temporal.TimeZone instance passed to toZonedDateTimeISO() does not have its
'timeZone' property observably checked
features: [Temporal]
---*/

const instance = new Temporal.Instant(0n);

const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "timeZone", {
get() {
throw new Test262Error("timeZone.timeZone should not be accessed");
},
});

instance.toZonedDateTimeISO(timeZone);
instance.toZonedDateTimeISO({ timeZone });
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.now.plaindate
description: >
A Temporal.TimeZone instance passed to plainDate() does not have its
'timeZone' property observably checked
features: [Temporal]
---*/

const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "timeZone", {
get() {
throw new Test262Error("timeZone.timeZone should not be accessed");
},
});

Temporal.Now.plainDate("iso8601", timeZone);
Temporal.Now.plainDate("iso8601", { timeZone });
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.now.plaindateiso
description: >
A Temporal.TimeZone instance passed to plainDateISO() does not have its
'timeZone' property observably checked
features: [Temporal]
---*/

const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "timeZone", {
get() {
throw new Test262Error("timeZone.timeZone should not be accessed");
},
});

Temporal.Now.plainDateISO(timeZone);
Temporal.Now.plainDateISO({ timeZone });
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.now.plaindatetime
description: >
A Temporal.TimeZone instance passed to plainDateTime() does not have its
'timeZone' property observably checked
features: [Temporal]
---*/

const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "timeZone", {
get() {
throw new Test262Error("timeZone.timeZone should not be accessed");
},
});

Temporal.Now.plainDateTime("iso8601", timeZone);
Temporal.Now.plainDateTime("iso8601", { timeZone });
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.now.plaindatetimeiso
description: >
A Temporal.TimeZone instance passed to plainDateTimeISO() does not have its
'timeZone' property observably checked
features: [Temporal]
---*/

const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "timeZone", {
get() {
throw new Test262Error("timeZone.timeZone should not be accessed");
},
});

Temporal.Now.plainDateTimeISO(timeZone);
Temporal.Now.plainDateTimeISO({ timeZone });
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.now.plaintimeiso
description: >
A Temporal.TimeZone instance passed to plainTimeISO() does not have its
'timeZone' property observably checked
features: [Temporal]
---*/

const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "timeZone", {
get() {
throw new Test262Error("timeZone.timeZone should not be accessed");
},
});

Temporal.Now.plainTimeISO(timeZone);
Temporal.Now.plainTimeISO({ timeZone });
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.now.zoneddatetime
description: >
A Temporal.TimeZone instance passed to zonedDateTime() does not have its
'timeZone' property observably checked
features: [Temporal]
---*/

const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "timeZone", {
get() {
throw new Test262Error("timeZone.timeZone should not be accessed");
},
});

Temporal.Now.zonedDateTime("iso8601", timeZone);
Temporal.Now.zonedDateTime("iso8601", { timeZone });
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.now.zoneddatetimeiso
description: >
A Temporal.TimeZone instance passed to zonedDateTimeISO() does not have its
'timeZone' property observably checked
features: [Temporal]
---*/

const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "timeZone", {
get() {
throw new Test262Error("timeZone.timeZone should not be accessed");
},
});

Temporal.Now.zonedDateTimeISO(timeZone);
Temporal.Now.zonedDateTimeISO({ timeZone });
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.plaindate.prototype.tozoneddatetime
description: >
A Temporal.TimeZone instance passed to toZonedDateTime() does not have its
'timeZone' property observably checked
features: [Temporal]
---*/

const instance = new Temporal.PlainDate(2000, 5, 2);

const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "timeZone", {
get() {
throw new Test262Error("timeZone.timeZone should not be accessed");
},
});

instance.toZonedDateTime(timeZone);
instance.toZonedDateTime({ timeZone });
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.plaindatetime.prototype.tozoneddatetime
description: >
A Temporal.TimeZone instance passed to toZonedDateTime() does not have its
'timeZone' property observably checked
features: [Temporal]
---*/

const instance = new Temporal.PlainDateTime(2000, 5, 2);

const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "timeZone", {
get() {
throw new Test262Error("timeZone.timeZone should not be accessed");
},
});

instance.toZonedDateTime(timeZone);
instance.toZonedDateTime({ timeZone });
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.plaintime.prototype.tozoneddatetime
description: >
A Temporal.TimeZone instance passed to toZonedDateTime() does not have its
'timeZone' property observably checked
features: [Temporal]
---*/

const instance = new Temporal.PlainTime();

const timeZone = new Temporal.TimeZone("UTC");
Object.defineProperty(timeZone, "timeZone", {
get() {
throw new Test262Error("timeZone.timeZone should not be accessed");
},
});

instance.toZonedDateTime({ plainDate: new Temporal.PlainDate(2000, 5, 2), timeZone });
instance.toZonedDateTime({ plainDate: new Temporal.PlainDate(2000, 5, 2), timeZone: { timeZone } });
Loading

0 comments on commit 1f59bf5

Please sign in to comment.