Skip to content

Commit 85ae4c0

Browse files
ptomatoMs2ger
authored andcommitted
Temporal: Add tests for optional properties in property bags
These tests confirm that Temporal-object-like property bags have the correct default values for their optional properties. This provides coverage for a V8 bug: https://issues.chromium.org/issues/446728405
1 parent e723219 commit 85ae4c0

File tree

38 files changed

+1192
-0
lines changed

38 files changed

+1192
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (C) 2025 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.duration.prototype.compare
6+
description: >
7+
A property bag missing optional properties is equivalent to a property bag
8+
with all the optional properties having their default values
9+
features: [Temporal]
10+
---*/
11+
12+
const oneProperty = {
13+
hours: 1,
14+
};
15+
const allProperties = {
16+
years: 0,
17+
months: 0,
18+
weeks: 0,
19+
days: 0,
20+
hours: 1,
21+
minutes: 0,
22+
seconds: 0,
23+
milliseconds: 0,
24+
microseconds: 0,
25+
nanoseconds: 0,
26+
};
27+
const resultWithout = Temporal.Duration.compare(oneProperty, oneProperty);
28+
const resultWith = Temporal.Duration.compare(allProperties, allProperties);
29+
assert.sameValue(resultWithout, resultWith, "results should be the same with and without optional properties");
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (C) 2025 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.duration.prototype.compare
6+
description: >
7+
A property bag missing optional properties is equivalent to a property bag
8+
with all the optional properties having their default values
9+
features: [Temporal]
10+
---*/
11+
12+
const duration1 = new Temporal.Duration(1);
13+
const duration2 = new Temporal.Duration(0, 1);
14+
15+
let relativeTo = {
16+
year: 2021,
17+
month: 10,
18+
day: 28,
19+
timeZone: "UTC",
20+
};
21+
const resultWithout = Temporal.Duration.compare(duration1, duration2, { relativeTo });
22+
relativeTo = {
23+
year: 2021,
24+
month: 10,
25+
day: 28,
26+
hour: 0,
27+
minute: 0,
28+
second: 0,
29+
millisecond: 0,
30+
microsecond: 0,
31+
nanosecond: 0,
32+
offset: "+00:00",
33+
timeZone: "UTC",
34+
calendar: "iso8601",
35+
};
36+
const resultWith = Temporal.Duration.compare(duration1, duration2, { relativeTo });
37+
assert.sameValue(resultWithout, resultWith, "results should be the same with and without optional properties");
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (C) 2025 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.duration.prototype.from
6+
description: >
7+
A property bag missing optional properties is equivalent to a property bag
8+
with all the optional properties having their default values
9+
includes: [temporalHelpers.js]
10+
features: [Temporal]
11+
---*/
12+
13+
const oneProperty = {
14+
hours: 1,
15+
};
16+
const allProperties = {
17+
years: 0,
18+
months: 0,
19+
weeks: 0,
20+
days: 0,
21+
hours: 1,
22+
minutes: 0,
23+
seconds: 0,
24+
milliseconds: 0,
25+
microseconds: 0,
26+
nanoseconds: 0,
27+
};
28+
const resultWithout = Temporal.Duration.from(oneProperty);
29+
const resultWith = Temporal.Duration.from(allProperties);
30+
TemporalHelpers.assertDurationsEqual(resultWithout, resultWith, "results should be the same with and without optional properties");
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (C) 2025 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.duration.prototype.add
6+
description: >
7+
A property bag missing optional properties is equivalent to a property bag
8+
with all the optional properties having their default values
9+
includes: [temporalHelpers.js]
10+
features: [Temporal]
11+
---*/
12+
13+
const instance = new Temporal.Duration();
14+
15+
const oneProperty = {
16+
hours: 1,
17+
};
18+
const allProperties = {
19+
years: 0,
20+
months: 0,
21+
weeks: 0,
22+
days: 0,
23+
hours: 1,
24+
minutes: 0,
25+
seconds: 0,
26+
milliseconds: 0,
27+
microseconds: 0,
28+
nanoseconds: 0,
29+
};
30+
const resultWithout = instance.add(oneProperty);
31+
const resultWith = instance.add(allProperties);
32+
TemporalHelpers.assertDurationsEqual(resultWithout, resultWith, "results should be the same with and without optional properties");
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 2025 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.duration.prototype.round
6+
description: >
7+
A property bag missing optional properties is equivalent to a property bag
8+
with all the optional properties having their default values
9+
includes: [temporalHelpers.js]
10+
features: [Temporal]
11+
---*/
12+
13+
const timeZone = "UTC";
14+
const instance = new Temporal.Duration(1, 0, 0, 0, 24);
15+
16+
let relativeTo = {
17+
year: 2021,
18+
month: 10,
19+
day: 28,
20+
timeZone,
21+
};
22+
const resultWithout = instance.round({ largestUnit: "years", relativeTo });
23+
relativeTo = {
24+
year: 2021,
25+
month: 10,
26+
day: 28,
27+
hour: 0,
28+
minute: 0,
29+
second: 0,
30+
millisecond: 0,
31+
microsecond: 0,
32+
nanosecond: 0,
33+
offset: "+00:00",
34+
timeZone,
35+
calendar: "iso8601",
36+
};
37+
const resultWith = instance.round({ largestUnit: "years", relativeTo });
38+
TemporalHelpers.assertDurationsEqual(resultWithout, resultWith, "results should be the same with and without optional properties");
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (C) 2025 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.duration.prototype.subtract
6+
description: >
7+
A property bag missing optional properties is equivalent to a property bag
8+
with all the optional properties having their default values
9+
includes: [temporalHelpers.js]
10+
features: [Temporal]
11+
---*/
12+
13+
const instance = new Temporal.Duration();
14+
15+
const oneProperty = {
16+
hours: 1,
17+
};
18+
const allProperties = {
19+
years: 0,
20+
months: 0,
21+
weeks: 0,
22+
days: 0,
23+
hours: 1,
24+
minutes: 0,
25+
seconds: 0,
26+
milliseconds: 0,
27+
microseconds: 0,
28+
nanoseconds: 0,
29+
};
30+
const resultWithout = instance.subtract(oneProperty);
31+
const resultWith = instance.subtract(allProperties);
32+
TemporalHelpers.assertDurationsEqual(resultWithout, resultWith, "results should be the same with and without optional properties");
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (C) 2025 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.duration.prototype.total
6+
description: >
7+
A property bag missing optional properties is equivalent to a property bag
8+
with all the optional properties having their default values
9+
features: [Temporal]
10+
---*/
11+
12+
const timeZone = "UTC";
13+
const instance = new Temporal.Duration(1, 0, 0, 0, 24);
14+
15+
let relativeTo = {
16+
year: 2021,
17+
month: 10,
18+
day: 28,
19+
timeZone,
20+
};
21+
const resultWithout = instance.total({ unit: "days", relativeTo });
22+
relativeTo = {
23+
year: 2021,
24+
month: 10,
25+
day: 28,
26+
hour: 0,
27+
minute: 0,
28+
second: 0,
29+
millisecond: 0,
30+
microsecond: 0,
31+
nanosecond: 0,
32+
offset: "+00:00",
33+
timeZone,
34+
calendar: "iso8601",
35+
};
36+
const resultWith = instance.total({ unit: "days", relativeTo });
37+
assert.sameValue(resultWithout, resultWith, "results should be the same with and without optional properties");
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (C) 2025 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.instant.prototype.add
6+
description: >
7+
A property bag missing optional properties is equivalent to a property bag
8+
with all the optional properties having their default values
9+
features: [Temporal]
10+
---*/
11+
12+
const instance = new Temporal.Instant(0n);
13+
14+
const oneProperty = {
15+
hours: 1,
16+
};
17+
const allProperties = {
18+
years: 0,
19+
months: 0,
20+
weeks: 0,
21+
days: 0,
22+
hours: 1,
23+
minutes: 0,
24+
seconds: 0,
25+
milliseconds: 0,
26+
microseconds: 0,
27+
nanoseconds: 0,
28+
};
29+
const resultWithout = instance.add(oneProperty);
30+
const resultWith = instance.add(allProperties);
31+
assert(resultWithout.equals(resultWith), "results should be the same with and without optional properties");
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (C) 2025 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.instant.prototype.subtract
6+
description: >
7+
A property bag missing optional properties is equivalent to a property bag
8+
with all the optional properties having their default values
9+
features: [Temporal]
10+
---*/
11+
12+
const instance = new Temporal.Instant(0n);
13+
14+
const oneProperty = {
15+
hours: 1,
16+
};
17+
const allProperties = {
18+
years: 0,
19+
months: 0,
20+
weeks: 0,
21+
days: 0,
22+
hours: 1,
23+
minutes: 0,
24+
seconds: 0,
25+
milliseconds: 0,
26+
microseconds: 0,
27+
nanoseconds: 0,
28+
};
29+
const resultWithout = instance.subtract(oneProperty);
30+
const resultWith = instance.subtract(allProperties);
31+
assert(resultWithout.equals(resultWith), "results should be the same with and without optional properties");
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (C) 2025 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.plaindate.prototype.add
6+
description: >
7+
A property bag missing optional properties is equivalent to a property bag
8+
with all the optional properties having their default values
9+
features: [Temporal]
10+
---*/
11+
12+
const instance = new Temporal.PlainDate(1970, 1, 1);
13+
14+
const oneProperty = {
15+
hours: 1,
16+
};
17+
const allProperties = {
18+
years: 0,
19+
months: 0,
20+
weeks: 0,
21+
days: 0,
22+
hours: 1,
23+
minutes: 0,
24+
seconds: 0,
25+
milliseconds: 0,
26+
microseconds: 0,
27+
nanoseconds: 0,
28+
};
29+
const resultWithout = instance.add(oneProperty);
30+
const resultWith = instance.add(allProperties);
31+
assert(resultWithout.equals(resultWith), "results should be the same with and without optional properties");

0 commit comments

Comments
 (0)