Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for audit of Temporal user code calls, part 2 #3897

Merged
merged 8 commits into from
Sep 13, 2023
24 changes: 24 additions & 0 deletions harness/temporalHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,30 @@ var TemporalHelpers = {
});
},

/*
* A custom time zone that does not allow any of its methods to be called, for
* the purpose of asserting that a particular operation does not call into
* user code.
*/
timeZoneThrowEverything() {
class TimeZoneThrowEverything extends Temporal.TimeZone {
constructor() {
super("UTC");
}
getOffsetNanosecondsFor() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be called");
}
getPossibleInstantsFor() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be called");
}
toString() {
TemporalHelpers.assertUnreachable("toString should not be called");
}
}

return new TimeZoneThrowEverything();
},

/*
* Returns an object that will append logs of any Gets or Calls of its valueOf
* or toString properties to the array calls. Both valueOf and toString will
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.calendar.prototype.dateadd
description: >
Calling the method with a property bag argument with a builtin calendar causes
no observable array iteration when getting the calendar fields.
features: [Temporal]
---*/

const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function arrayIterator() {
throw new Test262Error("Array should not be iterated");
}

const instance = new Temporal.Calendar("iso8601");
const arg = { year: 2000, month: 5, day: 2, calendar: "iso8601" };
instance.dateAdd(arg, new Temporal.Duration());

Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.calendar.prototype.dateuntil
description: >
Calling the method with a property bag argument with a builtin calendar causes
no observable array iteration when getting the calendar fields.
features: [Temporal]
---*/

const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function arrayIterator() {
throw new Test262Error("Array should not be iterated");
}

const instance = new Temporal.Calendar("iso8601");
const arg = { year: 2000, month: 5, day: 2, calendar: "iso8601" };
instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19));
instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg);

Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.calendar.prototype.day
description: >
Calling the method with a property bag argument with a builtin calendar causes
no observable array iteration when getting the calendar fields.
features: [Temporal]
---*/

const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function arrayIterator() {
throw new Test262Error("Array should not be iterated");
}

const instance = new Temporal.Calendar("iso8601");
const arg = { year: 2000, month: 5, day: 2, calendar: "iso8601" };
instance.day(arg);

Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.calendar.prototype.dayofweek
description: >
Calling the method with a property bag argument with a builtin calendar causes
no observable array iteration when getting the calendar fields.
features: [Temporal]
---*/

const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function arrayIterator() {
throw new Test262Error("Array should not be iterated");
}

const instance = new Temporal.Calendar("iso8601");
const arg = { year: 2000, month: 5, day: 2, calendar: "iso8601" };
instance.dayOfWeek(arg);

Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.calendar.prototype.dayofyear
description: >
Calling the method with a property bag argument with a builtin calendar causes
no observable array iteration when getting the calendar fields.
features: [Temporal]
---*/

const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function arrayIterator() {
throw new Test262Error("Array should not be iterated");
}

const instance = new Temporal.Calendar("iso8601");
const arg = { year: 2000, month: 5, day: 2, calendar: "iso8601" };
instance.dayOfYear(arg);

Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.calendar.prototype.daysinmonth
description: >
Calling the method with a property bag argument with a builtin calendar causes
no observable array iteration when getting the calendar fields.
features: [Temporal]
---*/

const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function arrayIterator() {
throw new Test262Error("Array should not be iterated");
}

const instance = new Temporal.Calendar("iso8601");
const arg = { year: 2000, month: 5, day: 2, calendar: "iso8601" };
instance.daysInMonth(arg);

Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.calendar.prototype.daysinweek
description: >
Calling the method with a property bag argument with a builtin calendar causes
no observable array iteration when getting the calendar fields.
features: [Temporal]
---*/

const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function arrayIterator() {
throw new Test262Error("Array should not be iterated");
}

const instance = new Temporal.Calendar("iso8601");
const arg = { year: 2000, month: 5, day: 2, calendar: "iso8601" };
instance.daysInWeek(arg);

Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.calendar.prototype.daysinyear
description: >
Calling the method with a property bag argument with a builtin calendar causes
no observable array iteration when getting the calendar fields.
features: [Temporal]
---*/

const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function arrayIterator() {
throw new Test262Error("Array should not be iterated");
}

const instance = new Temporal.Calendar("iso8601");
const arg = { year: 2000, month: 5, day: 2, calendar: "iso8601" };
instance.daysInYear(arg);

Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.calendar.prototype.inleapyear
description: >
Calling the method with a property bag argument with a builtin calendar causes
no observable array iteration when getting the calendar fields.
features: [Temporal]
---*/

const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function arrayIterator() {
throw new Test262Error("Array should not be iterated");
}

const instance = new Temporal.Calendar("iso8601");
const arg = { year: 2000, month: 5, day: 2, calendar: "iso8601" };
instance.inLeapYear(arg);

Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.calendar.prototype.month
description: >
Calling the method with a property bag argument with a builtin calendar causes
no observable array iteration when getting the calendar fields.
features: [Temporal]
---*/

const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function arrayIterator() {
throw new Test262Error("Array should not be iterated");
}

const instance = new Temporal.Calendar("iso8601");
const arg = { year: 2000, month: 5, day: 2, calendar: "iso8601" };
instance.month(arg);

Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.calendar.prototype.monthcode
description: >
Calling the method with a property bag argument with a builtin calendar causes
no observable array iteration when getting the calendar fields.
features: [Temporal]
---*/

const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function arrayIterator() {
throw new Test262Error("Array should not be iterated");
}

const instance = new Temporal.Calendar("iso8601");
const arg = { year: 2000, month: 5, day: 2, calendar: "iso8601" };
instance.monthCode(arg);

Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.calendar.prototype.monthsinyear
description: >
Calling the method with a property bag argument with a builtin calendar causes
no observable array iteration when getting the calendar fields.
features: [Temporal]
---*/

const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function arrayIterator() {
throw new Test262Error("Array should not be iterated");
}

const instance = new Temporal.Calendar("iso8601");
const arg = { year: 2000, month: 5, day: 2, calendar: "iso8601" };
instance.monthsInYear(arg);

Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.calendar.prototype.weekofyear
description: >
Calling the method with a property bag argument with a builtin calendar causes
no observable array iteration when getting the calendar fields.
features: [Temporal]
---*/

const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function arrayIterator() {
throw new Test262Error("Array should not be iterated");
}

const instance = new Temporal.Calendar("iso8601");
const arg = { year: 2000, month: 5, day: 2, calendar: "iso8601" };
instance.weekOfYear(arg);

Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.calendar.prototype.year
description: >
Calling the method with a property bag argument with a builtin calendar causes
no observable array iteration when getting the calendar fields.
features: [Temporal]
---*/

const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function arrayIterator() {
throw new Test262Error("Array should not be iterated");
}

const instance = new Temporal.Calendar("iso8601");
const arg = { year: 2000, month: 5, day: 2, calendar: "iso8601" };
instance.year(arg);

Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.calendar.prototype.yearofweek
description: >
Calling the method with a property bag argument with a builtin calendar causes
no observable array iteration when getting the calendar fields.
features: [Temporal]
---*/

const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function arrayIterator() {
throw new Test262Error("Array should not be iterated");
}

const instance = new Temporal.Calendar("iso8601");
const arg = { year: 2000, month: 5, day: 2, calendar: "iso8601" };
instance.yearOfWeek(arg);

Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ const timeZone = TemporalHelpers.oneShiftTimeZone(new Temporal.Instant(0n), 3600
const relativeTo = new Temporal.ZonedDateTime(0n, timeZone, calendar);

const duration1 = new Temporal.Duration(0, 0, 1);
const duration2 = new Temporal.Duration(0, 0, 1);
const duration2 = new Temporal.Duration(0, 0, 1, 1);
Temporal.Duration.compare(duration1, duration2, { relativeTo });
assert.sameValue(calendar.dateAddCallCount, 4);
// one call in CalculateOffsetShift for each duration argument, plus one in
// UnbalanceDurationRelative for each duration argument
assert.sameValue(calendar.dateAddCallCount, 2);
// one call for each duration argument to add it to relativeTo
Loading