-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporal: Return early from Duration.compare if internal slots equal
- Loading branch information
Showing
9 changed files
with
77 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
test/built-ins/Temporal/Duration/compare/instances-identical.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// 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.duration.compare | ||
description: > | ||
Shortcut return with no observable user code calls when two Temporal.Duration | ||
have identical internal slots | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const duration1 = new Temporal.Duration(0, 0, 0, 5, 5, 5, 5, 5, 5, 5); | ||
const duration2 = new Temporal.Duration(0, 0, 0, 5, 5, 5, 5, 5, 5, 5); | ||
assert.sameValue(Temporal.Duration.compare(duration1, duration2), 0, "identical Duration instances should be equal"); | ||
|
||
const dateDuration1 = new Temporal.Duration(5, 5, 5, 5, 5, 5, 5, 5, 5, 5); | ||
const dateDuration2 = new Temporal.Duration(5, 5, 5, 5, 5, 5, 5, 5, 5, 5); | ||
assert.sameValue( | ||
Temporal.Duration.compare(dateDuration1, dateDuration2), | ||
0, | ||
"relativeTo is not required if two distinct Duration instances are identical" | ||
); | ||
|
||
const calendar = TemporalHelpers.calendarThrowEverything(); | ||
const relativeTo = new Temporal.PlainDate(2000, 1, 1, calendar); | ||
assert.sameValue( | ||
Temporal.Duration.compare(dateDuration1, dateDuration2, { relativeTo }), | ||
0, | ||
"no calendar methods are called if two distinct Duration instances are identical" | ||
); | ||
|
||
const dateDuration3 = new Temporal.Duration(5, 5, 5, 5, 4, 65, 5, 5, 5, 5); | ||
assert.throws( | ||
RangeError, | ||
() => Temporal.Duration.compare(dateDuration1, dateDuration3), | ||
"relativeTo is required if two Duration instances are the same length but not identical" | ||
); | ||
|
||
assert.throws( | ||
Test262Error, | ||
() => Temporal.Duration.compare(dateDuration1, dateDuration3, { relativeTo }), | ||
"calendar methods are called if two Duration instances are the same length but not identical" | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters