-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporal: Copy options object in {Plain,Zoned}DateTime.{from,p.with}
- Loading branch information
Showing
14 changed files
with
229 additions
and
49 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
test/built-ins/Temporal/PlainDateTime/from/observable-get-overflow-argument-primitive.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,34 @@ | ||
// 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.plaindatetime.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: "reject" }, "options"); | ||
|
||
const result = Temporal.PlainDateTime.from("2021-05-17T12:34:56", options); | ||
assert.compareArray(actual, expected, "Successful call"); | ||
TemporalHelpers.assertPlainDateTime(result, 2021, 5, "M05", 17, 12, 34, 56, 0, 0, 0); | ||
|
||
actual.splice(0); // empty it for the next check | ||
const failureExpected = [ | ||
"ownKeys options", | ||
"getOwnPropertyDescriptor options.overflow", | ||
"get options.overflow", | ||
]; | ||
|
||
assert.throws(TypeError, () => Temporal.PlainDateTime.from(7, options)); | ||
assert.compareArray(actual, failureExpected, "Failing call"); |
21 changes: 21 additions & 0 deletions
21
.../built-ins/Temporal/PlainDateTime/from/observable-get-overflow-argument-string-invalid.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,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.plaindatetime.from | ||
description: overflow property is extracted with ISO-invalid string argument. | ||
includes: [compareArray.js, temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const expected = [ | ||
"ownKeys options", | ||
"getOwnPropertyDescriptor options.overflow", | ||
"get options.overflow", | ||
]; | ||
|
||
let actual = []; | ||
const options = TemporalHelpers.propertyBagObserver(actual, { overflow: "reject" }, "options"); | ||
|
||
assert.throws(RangeError, () => Temporal.PlainDateTime.from("2020-13-34T25:60:60", options)); | ||
assert.compareArray(actual, expected); |
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
49 changes: 49 additions & 0 deletions
49
test/built-ins/Temporal/ZonedDateTime/from/observable-get-overflow-argument-primitive.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,49 @@ | ||
// 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.zoneddatetime.from | ||
description: options properties are extracted with string argument. | ||
includes: [compareArray.js, temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const expected = [ | ||
"ownKeys options", | ||
"getOwnPropertyDescriptor options.disambiguation", | ||
"get options.disambiguation", | ||
"getOwnPropertyDescriptor options.offset", | ||
"get options.offset", | ||
"getOwnPropertyDescriptor options.overflow", | ||
"get options.overflow", | ||
"get options.disambiguation.toString", | ||
"call options.disambiguation.toString", | ||
"get options.offset.toString", | ||
"call options.offset.toString", | ||
"get options.overflow.toString", | ||
"call options.overflow.toString", | ||
]; | ||
|
||
let actual = []; | ||
const options = TemporalHelpers.propertyBagObserver(actual, { | ||
disambiguation: "compatible", | ||
offset: "ignore", | ||
overflow: "reject", | ||
}, "options"); | ||
|
||
const result = Temporal.ZonedDateTime.from("2001-09-09T01:46:40+00:00[UTC]", options); | ||
assert.compareArray(actual, expected, "Successful call"); | ||
assert.sameValue(result.epochNanoseconds, 1_000_000_000_000_000_000n); | ||
|
||
actual.splice(0); // empty it for the next check | ||
const failureExpected = [ | ||
"ownKeys options", | ||
"getOwnPropertyDescriptor options.disambiguation", | ||
"get options.disambiguation", | ||
"getOwnPropertyDescriptor options.offset", | ||
"get options.offset", | ||
"getOwnPropertyDescriptor options.overflow", | ||
"get options.overflow", | ||
]; | ||
assert.throws(TypeError, () => Temporal.ZonedDateTime.from(7, options)); | ||
assert.compareArray(actual, failureExpected, "Failing call"); |
29 changes: 29 additions & 0 deletions
29
.../built-ins/Temporal/ZonedDateTime/from/observable-get-overflow-argument-string-invalid.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,29 @@ | ||
// 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.zoneddatetime.from | ||
description: options properties are extracted with ISO-invalid string argument. | ||
includes: [compareArray.js, temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const expected = [ | ||
"ownKeys options", | ||
"getOwnPropertyDescriptor options.disambiguation", | ||
"get options.disambiguation", | ||
"getOwnPropertyDescriptor options.offset", | ||
"get options.offset", | ||
"getOwnPropertyDescriptor options.overflow", | ||
"get options.overflow", | ||
]; | ||
|
||
let actual = []; | ||
const options = TemporalHelpers.propertyBagObserver(actual, { | ||
disambiguation: "compatible", | ||
offset: "ignore", | ||
overflow: "reject", | ||
}, "options"); | ||
|
||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-13-34T25:60:60+99:99[UTC]", options)); | ||
assert.compareArray(actual, expected); |
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
32 changes: 32 additions & 0 deletions
32
test/built-ins/Temporal/ZonedDateTime/prototype/with/calendar-options.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,32 @@ | ||
// 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.zoneddatetime.prototype.with | ||
description: > | ||
The options argument is copied and the copy is passed to | ||
Calendar#dateFromFields. | ||
features: [Temporal] | ||
---*/ | ||
|
||
const options = { | ||
extra: "property", | ||
}; | ||
let calledDateFromFields = 0; | ||
class Calendar extends Temporal.Calendar { | ||
constructor() { | ||
super("iso8601"); | ||
} | ||
dateFromFields(fields, optionsArg) { | ||
++calledDateFromFields; | ||
assert.notSameValue(optionsArg, options, "should pass copied options object"); | ||
assert.sameValue(optionsArg.extra, "property", "should copy all properties from options object"); | ||
assert.sameValue(Object.getPrototypeOf(optionsArg), null, "Copy has null prototype"); | ||
return super.dateFromFields(fields, optionsArg); | ||
} | ||
}; | ||
const calendar = new Calendar(); | ||
const datetime = new Temporal.ZonedDateTime(0n, "UTC", calendar); | ||
const result = datetime.with({ year: 1971 }, options); | ||
assert.sameValue(result.epochNanoseconds, 365n * 86400_000_000_000n, "year changed from 1970 to 1971") | ||
assert.sameValue(calledDateFromFields, 1, "should have called overridden dateFromFields once"); |
Oops, something went wrong.