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 1 #3894

Merged
merged 6 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ features: [Temporal]

const calendar = new Temporal.Calendar("iso8601");
assert.throws(RangeError, () => calendar.fields(["day", "month", "day"]));
assert.throws(RangeError, () => calendar.fields(["year", "month", "monthCode", "day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond", "year"]));
assert.throws(RangeError, () => calendar.fields(["year", "month", "monthCode", "day", "year"]));

const manyFields = {
count: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

/*---
esid: sec-temporal.calendar.prototype.fields
description: Calendar.prototype.fields rejects input field names that are not singular names of temporal units
description: >
Calendar.prototype.fields rejects input field names that are not singular
names of Temporal date units
ptomato marked this conversation as resolved.
Show resolved Hide resolved
info: |
sec-temporal.calendar.prototype.fields step 7.b.ii:
7. Repeat, while next is not false,
Expand All @@ -14,7 +16,7 @@ info: |
1. Let completion be ThrowCompletion(a newly created TypeError object).
2. Return ? IteratorClose(iteratorRecord, completion).
sec-temporal.calendar.prototype.fields step 7.b.iv:
iv. If _nextValue_ is not one of *"year"*, *"month"*, *"monthCode"*, *"day"*, *"hour"*, *"minute"*, *"second"*, *"millisecond"*, *"microsecond"*, *"nanosecond"*, then
iv. If _nextValue_ is not one of *"year"*, *"month"*, *"monthCode"*, or *"day"*, then
1. Let _completion_ be ThrowCompletion(a newly created *RangeError* object).
2. Return ? IteratorClose(_iteratorRecord_, _completion_).

Expand All @@ -30,6 +32,12 @@ assert.throws(TypeError, () => calendar.fields([null]));
assert.throws(TypeError, () => calendar.fields([{}]));
assert.throws(TypeError, () => calendar.fields([undefined]));
assert.throws(TypeError, () => calendar.fields(["day", 1]));
assert.throws(RangeError, () => calendar.fields(["hour"]));
assert.throws(RangeError, () => calendar.fields(["minute"]));
assert.throws(RangeError, () => calendar.fields(["second"]));
assert.throws(RangeError, () => calendar.fields(["millisecond"]));
assert.throws(RangeError, () => calendar.fields(["microsecond"]));
assert.throws(RangeError, () => calendar.fields(["nanosecond"]));
assert.throws(RangeError, () => calendar.fields(["month", "days"]));
assert.throws(RangeError, () => calendar.fields(["days"]));
assert.throws(RangeError, () => calendar.fields(["people"]));
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ info: |
a. Set next to ? IteratorStep(iteratorRecord).
b. If next is not false, then
i. Let nextValue be ? IteratorValue(next).
iv. If nextValue is not one of "year", "month", "monthCode", "day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond", then
iv. If nextValue is not one of "year", "month", "monthCode", or "day", then
1. Let completion be ThrowCompletion(a newly created RangeError object).
2. Return ? IteratorClose(iteratorRecord, completion).
features: [Symbol, Symbol.iterator, Temporal, computed-property-names, generators]
Expand All @@ -38,7 +38,7 @@ const fields = {
// The following three lines should not be reached if the implemention
// correctly check the previous line.
i++;
yield "hour";
yield "day";
i++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/*---
esid: sec-temporal.calendar.prototype.fields
description: >
Temporal.Calendar.prototype.fields will throw if its input iterable yields
Temporal.Calendar.prototype.fields will throw if its input iterable yields
the same value twice.
info: |
## 12.4.21 Temporal.Calendar.prototype.fields ( fields )
Expand Down Expand Up @@ -38,9 +38,8 @@ assert.throws(
RangeError, () => cal.fields(fields), "repeated valid value should throw");
assert.sameValue(i, 2, "Should stop at 2");

// Test all valid value will throw while repeate
[ "nanosecond", "microsecond", "millisecond", "second",
"minute", "hour", "day", "monthCode", "month", "year" ].forEach((f) => {
// Test all valid values will throw when repeated
[ "day", "monthCode", "month", "year" ].forEach((f) => {
i = 0;
const fields2 = {
*[Symbol.iterator]() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ info: |
a. Set next to ? IteratorStep(iteratorRecord).
b. If next is not false, then
i. Let nextValue be ? IteratorValue(next).
iv. If nextValue is not one of "year", "month", "monthCode", "day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond", then
iv. If nextValue is not one of "year", "month", "monthCode", or "day", then
1. Let completion be ThrowCompletion(a newly created RangeError object).
2. Return ? IteratorClose(iteratorRecord, completion).
features: [Symbol, Symbol.iterator, Temporal, computed-property-names, generators]
Expand All @@ -26,12 +26,6 @@ includes: [compareArray.js]
let cal = new Temporal.Calendar("iso8601")
const fields = {
*[Symbol.iterator]() {
yield "nanosecond";
yield "microsecond";
yield "millisecond";
yield "second";
yield "minute";
yield "hour";
yield "day";
yield "monthCode";
yield "month";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ features: [Temporal]

const expected = [
"day",
"hour",
"microsecond",
"millisecond",
"minute",
"month",
"monthCode",
"nanosecond",
"second",
"year",
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ features: [Temporal]

const expected = [
"day",
"hour",
"microsecond",
"millisecond",
"minute",
"month",
"monthCode",
"nanosecond",
"second",
"year",
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ features: [Temporal]

const expected = [
"day",
"hour",
"microsecond",
"millisecond",
"minute",
"month",
"monthCode",
"nanosecond",
"second",
"year",
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ features: [Temporal]

const expected = [
"day",
"hour",
"microsecond",
"millisecond",
"minute",
"month",
"monthCode",
"nanosecond",
"second",
"year",
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ features: [Temporal]

const expected = [
"day",
"hour",
"microsecond",
"millisecond",
"minute",
"month",
"monthCode",
"nanosecond",
"second",
"year",
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ const expected = [
"has options.timeZone.id",
"get options.timeZone.getOffsetNanosecondsFor",
"call options.timeZone.getOffsetNanosecondsFor",
"get options.timeZone.getOffsetNanosecondsFor",
"call options.timeZone.getOffsetNanosecondsFor",
];
const actual = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

/*---
esid: sec-temporal.instant.prototype.tostring
description: Passing a TimeZone to options calls getOffsetNanosecondsFor twice, but not toString
description: >
Passing a TimeZone to options calls getOffsetNanosecondsFor, but not toString
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
Expand All @@ -15,8 +16,6 @@ const expected = [
"has timeZone.id",
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
];

const instant = Temporal.Instant.from("1975-02-02T14:25:36.123456Z");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.plaindate.from
description: overflow property is extracted with string argument.
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/

const expected = [
"ownKeys options",
"getOwnPropertyDescriptor options.overflow",
"get options.overflow",
"get options.overflow.toString",
"call options.overflow.toString",
];

let actual = [];
const options = TemporalHelpers.propertyBagObserver(actual, { overflow: "constrain" }, "options");

const result = Temporal.PlainDate.from("2021-05-17", options);
assert.compareArray(actual, expected, "Successful call");
TemporalHelpers.assertPlainDate(result, 2021, 5, "M05", 17);

actual.splice(0); // empty it for the next check
const failureExpected = [
"ownKeys options",
"getOwnPropertyDescriptor options.overflow",
"get options.overflow",
];

assert.throws(TypeError, () => Temporal.PlainDate.from(7, options));
assert.compareArray(actual, failureExpected, "Failing call");
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,18 @@
/*---
esid: sec-temporal.plaindate.from
description: overflow property is extracted with ISO-invalid string argument.
info: |
1. Perform ? ToTemporalOverflow(_options_).

1. If ! IsValidISODate(year, month, day) is false, throw a RangeError exception.
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/

const expected = [
"get overflow",
"get overflow.toString",
"call overflow.toString",
"ownKeys options",
"getOwnPropertyDescriptor options.overflow",
"get options.overflow",
];

let actual = [];
const object = {
get overflow() {
actual.push("get overflow");
return TemporalHelpers.toPrimitiveObserver(actual, "constrain", "overflow");
}
};
const options = TemporalHelpers.propertyBagObserver(actual, { overflow: "constrain" }, "options");

assert.throws(RangeError, () => Temporal.PlainDate.from("2020-13-34", object));
assert.throws(RangeError, () => Temporal.PlainDate.from("2020-13-34", options));
assert.compareArray(actual, expected);

This file was deleted.

11 changes: 9 additions & 2 deletions test/built-ins/Temporal/PlainDate/from/order-of-operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ features: [Temporal]
---*/

const expected = [
"ownKeys options",
"getOwnPropertyDescriptor options.overflow",
"get options.overflow",
"getOwnPropertyDescriptor options.extra",
"get options.extra",
"get fields.calendar",
"has fields.calendar.dateAdd",
"has fields.calendar.dateFromFields",
Expand Down Expand Up @@ -48,7 +53,6 @@ const expected = [
"get fields.calendar.dateFromFields",
"call fields.calendar.dateFromFields",
// inside Calendar.p.dateFromFields
"get options.overflow",
"get options.overflow.toString",
"call options.overflow.toString",
];
Expand All @@ -63,7 +67,10 @@ const fields = TemporalHelpers.propertyBagObserver(actual, {
calendar,
}, "fields");

const options = TemporalHelpers.propertyBagObserver(actual, { overflow: "constrain" }, "options");
const options = TemporalHelpers.propertyBagObserver(actual, {
overflow: "constrain",
extra: "property",
}, "options");

const result = Temporal.PlainDate.from(fields, options);
assert.compareArray(actual, expected, "order of operations");
8 changes: 6 additions & 2 deletions test/built-ins/Temporal/PlainDate/prototype/with/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ features: [Temporal]
---*/

const result = new Temporal.PlainDate(1920, 5, 3);
const options = {};
const options = {
extra: "property",
};
let calls = 0;
class CustomCalendar extends Temporal.Calendar {
constructor() {
Expand All @@ -22,7 +24,9 @@ class CustomCalendar extends Temporal.Calendar {
assert.sameValue(args[0].month, 11, "First argument: month");
assert.sameValue(args[0].monthCode, "M11", "First argument: monthCode");
assert.sameValue(args[0].year, 43, "First argument: year");
assert.sameValue(args[1], options, "Second argument");
assert.notSameValue(args[1], options, "Second argument is a copy of options");
assert.sameValue(args[1].extra, "property", "All properties are copied");
assert.sameValue(Object.getPrototypeOf(args[1]), null, "Copy has null prototype");
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ const expected = [
// RejectObjectWithCalendarOrTimeZone
"get fields.calendar",
"get fields.timeZone",
// CopyDataProperties
"ownKeys options",
"getOwnPropertyDescriptor options.overflow",
"get options.overflow",
"getOwnPropertyDescriptor options.extra",
"get options.extra",
// CalendarFields
"get this.calendar.fields",
"call this.calendar.fields",
Expand Down Expand Up @@ -44,7 +50,6 @@ const expected = [
"get this.calendar.dateFromFields",
"call this.calendar.dateFromFields",
// inside Calendar.p.dateFromFields
"get options.overflow",
"get options.overflow.toString",
"call options.overflow.toString",
];
Expand All @@ -64,6 +69,7 @@ const fields = TemporalHelpers.propertyBagObserver(actual, {

const options = TemporalHelpers.propertyBagObserver(actual, {
overflow: "constrain",
extra: "property",
}, "options");

instance.with(fields, options);
Expand Down
Loading