-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy objects received from user code before passing them into user co…
…de again The intention of this is that any getters installed on an object received from user code are called once each, in a defined order. Requires a few fixes to make the polyfill match the spec text. See: #1426
- Loading branch information
Showing
19 changed files
with
343 additions
and
19 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
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
30 changes: 30 additions & 0 deletions
30
polyfill/test/PlainDate/prototype/with/copies-merge-fields-object.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,30 @@ | ||
// 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.prototype.with | ||
description: The object returned from mergeFields() is copied before being passed to dateFromFields(). | ||
info: | | ||
sec-temporal.plaindate.prototype.with steps 13–15: | ||
13. Set _fields_ to ? CalendarMergeFields(_calendar_, _fields_, _partialDate_). | ||
14. Set _fields_ to ? PrepareTemporalFields(_fields_, _fieldNames_, «»). | ||
15. Return ? DateFromFields(_calendar_, _fields_, _options_). | ||
includes: [compareArray.js, temporalHelpers.js] | ||
---*/ | ||
|
||
const expected = [ | ||
"get day", | ||
"valueOf day", | ||
"get month", | ||
"valueOf month", | ||
"get monthCode", | ||
"toString monthCode", | ||
"get year", | ||
"valueOf year", | ||
]; | ||
|
||
const calendar = TemporalHelpers.calendarMergeFieldsGetters(); | ||
const date = new Temporal.PlainDate(2021, 3, 31, calendar); | ||
date.with({ year: 2022 }); | ||
|
||
assert.compareArray(calendar.mergeFieldsReturnOperations, expected, "getters called on mergeFields return"); |
44 changes: 44 additions & 0 deletions
44
polyfill/test/PlainDateTime/prototype/with/copies-merge-fields-object.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) 2021 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.plaindatetime.prototype.with | ||
description: The object returned from mergeFields() is copied before being passed to dateFromFields(). | ||
info: | | ||
sec-temporal.plaindatetime.prototype.with steps 13–15: | ||
13. Set _fields_ to ? CalendarMergeFields(_calendar_, _fields_, _partialDate_). | ||
14. Set _fields_ to ? PrepareTemporalFields(_fields_, _fieldNames_, «»). | ||
15. Let _result_ be ? InterpretTemporalDateTimeFields(_calendar_, _fields_, _options_). | ||
sec-temporal-interprettemporaldatetimefields step 2: | ||
2. Let _temporalDate_ be ? DateFromFields(_calendar_, _fields_, _options_). | ||
includes: [compareArray.js, temporalHelpers.js] | ||
---*/ | ||
|
||
const expected = [ | ||
"get day", | ||
"valueOf day", | ||
"get hour", | ||
"valueOf hour", | ||
"get microsecond", | ||
"valueOf microsecond", | ||
"get millisecond", | ||
"valueOf millisecond", | ||
"get minute", | ||
"valueOf minute", | ||
"get month", | ||
"valueOf month", | ||
"get monthCode", | ||
"toString monthCode", | ||
"get nanosecond", | ||
"valueOf nanosecond", | ||
"get second", | ||
"valueOf second", | ||
"get year", | ||
"valueOf year", | ||
]; | ||
|
||
const calendar = TemporalHelpers.calendarMergeFieldsGetters(); | ||
const datetime = new Temporal.PlainDateTime(2021, 3, 31, 12, 34, 56, 987, 654, 321, calendar); | ||
datetime.with({ year: 2022 }); | ||
|
||
assert.compareArray(calendar.mergeFieldsReturnOperations, expected, "getters called on mergeFields return"); |
27 changes: 27 additions & 0 deletions
27
polyfill/test/PlainMonthDay/prototype/toPlainDate/copies-merge-fields-object.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,27 @@ | ||
// 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.plainmonthday.prototype.toplaindate | ||
description: The object returned from mergeFields() is copied before being passed to monthDayFromFields(). | ||
info: | | ||
sec-temporal.plainmonthday.prototype.toplaindate steps 9 and 11: | ||
9. Let _mergedFields_ be ? CalendarMergeFields(_calendar_, _fields_, _inputFields_). | ||
11. Set _mergedFields_ to ? PrepareTemporalFields(_mergedFields_, _mergedFieldNames_, «»). | ||
includes: [compareArray.js, temporalHelpers.js] | ||
---*/ | ||
|
||
const expected = [ | ||
"get day", | ||
"valueOf day", | ||
"get monthCode", | ||
"toString monthCode", | ||
"get year", | ||
"valueOf year", | ||
]; | ||
|
||
const calendar = TemporalHelpers.calendarMergeFieldsGetters(); | ||
const monthday = new Temporal.PlainMonthDay(3, 31, calendar); | ||
monthday.toPlainDate({ year: 2000 }); | ||
|
||
assert.compareArray(calendar.mergeFieldsReturnOperations, expected, "getters called on mergeFields return"); |
28 changes: 28 additions & 0 deletions
28
polyfill/test/PlainMonthDay/prototype/with/copies-merge-fields-object.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,28 @@ | ||
// 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.plainmonthday.prototype.with | ||
description: The object returned from mergeFields() is copied before being passed to monthDayFromFields(). | ||
info: | | ||
sec-temporal.plainmonthday.prototype.with steps 13–15: | ||
13. Set _fields_ to ? CalendarMergeFields(_calendar_, _fields_, _partialMonthDay_). | ||
14. Set _fields_ to ? PrepareTemporalFields(_fields_, _fieldNames_, «»). | ||
15. Return ? MonthDayFromFields(_calendar_, _fields_, _options_). | ||
includes: [compareArray.js, temporalHelpers.js] | ||
---*/ | ||
|
||
const expected = [ | ||
"get day", | ||
"valueOf day", | ||
"get month", // PlainMonthDay.month property does not exist, no valueOf | ||
"get monthCode", | ||
"toString monthCode", | ||
"get year", // undefined, no valueOf | ||
]; | ||
|
||
const calendar = TemporalHelpers.calendarMergeFieldsGetters(); | ||
const monthday = new Temporal.PlainMonthDay(3, 31, calendar); | ||
monthday.with({ day: 1 }); | ||
|
||
assert.compareArray(calendar.mergeFieldsReturnOperations, expected, "getters called on mergeFields return"); |
27 changes: 27 additions & 0 deletions
27
polyfill/test/PlainYearMonth/prototype/toPlainDate/copies-merge-fields-object.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,27 @@ | ||
// 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.plainyearmonth.prototype.toplaindate | ||
description: The object returned from mergeFields() is copied before being passed to monthDayFromFields(). | ||
info: | | ||
sec-temporal.plainyearmonth.prototype.toplaindate steps 9 and 11: | ||
9. Let _mergedFields_ be ? CalendarMergeFields(_calendar_, _fields_, _inputFields_). | ||
11. Set _mergedFields_ to ? PrepareTemporalFields(_mergedFields_, _mergedFieldNames_, «»). | ||
includes: [compareArray.js, temporalHelpers.js] | ||
---*/ | ||
|
||
const expected = [ | ||
"get monthCode", | ||
"toString monthCode", | ||
"get year", | ||
"valueOf year", | ||
"get day", // first receiver fields, then input fields | ||
"valueOf day", | ||
]; | ||
|
||
const calendar = TemporalHelpers.calendarMergeFieldsGetters(); | ||
const yearmonth = new Temporal.PlainYearMonth(2000, 5, calendar); | ||
yearmonth.toPlainDate({ day: 2 }); | ||
|
||
assert.compareArray(calendar.mergeFieldsReturnOperations, expected, "getters called on mergeFields return"); |
28 changes: 28 additions & 0 deletions
28
polyfill/test/PlainYearMonth/prototype/with/copies-merge-fields-object.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,28 @@ | ||
// 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.plainyearmonth.prototype.with | ||
description: The object returned from mergeFields() is copied before being passed to monthDayFromFields(). | ||
info: | | ||
sec-temporal.plainyearmonth.prototype.with steps 13–15: | ||
13. Set _fields_ to ? CalendarMergeFields(_calendar_, _fields_, _partialYearMonth_). | ||
14. Set _fields_ to ? PrepareTemporalFields(_fields_, _fieldNames_, «»). | ||
15. Return ? YearMonthFromFields(_calendar_, _fields_, _options_). | ||
includes: [compareArray.js, temporalHelpers.js] | ||
---*/ | ||
|
||
const expected = [ | ||
"get month", | ||
"valueOf month", | ||
"get monthCode", | ||
"toString monthCode", | ||
"get year", | ||
"valueOf year", | ||
]; | ||
|
||
const calendar = TemporalHelpers.calendarMergeFieldsGetters(); | ||
const yearmonth = new Temporal.PlainYearMonth(2000, 5, calendar); | ||
yearmonth.with({ year: 2004 }); | ||
|
||
assert.compareArray(calendar.mergeFieldsReturnOperations, expected, "getters called on mergeFields return"); |
47 changes: 47 additions & 0 deletions
47
polyfill/test/ZonedDateTime/prototype/with/copies-merge-fields-object.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,47 @@ | ||
// 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.plaindatetime.prototype.with | ||
description: The object returned from mergeFields() is copied before being passed to dateFromFields(). | ||
info: | | ||
sec-temporal.plaindatetime.prototype.with steps 18–19 and 23: | ||
18. Set _fields_ to ? CalendarMergeFields(_calendar_, _fields_, _partialDate_). | ||
19. Set _fields_ to ? PrepareTemporalFields(_fields_, _fieldNames_, « *"timeZone"* »). | ||
23. Let _dateTimeResult_ be ? InterpretTemporalDateTimeFields(_calendar_, _fields_, _options_). | ||
sec-temporal-interprettemporaldatetimefields step 2: | ||
2. Let _temporalDate_ be ? DateFromFields(_calendar_, _fields_, _options_). | ||
includes: [compareArray.js, temporalHelpers.js] | ||
---*/ | ||
|
||
const expected = [ | ||
"get day", | ||
"valueOf day", | ||
"get hour", | ||
"valueOf hour", | ||
"get microsecond", | ||
"valueOf microsecond", | ||
"get millisecond", | ||
"valueOf millisecond", | ||
"get minute", | ||
"valueOf minute", | ||
"get month", | ||
"valueOf month", | ||
"get monthCode", | ||
"toString monthCode", | ||
"get nanosecond", | ||
"valueOf nanosecond", | ||
"get second", | ||
"valueOf second", | ||
"get year", | ||
"valueOf year", | ||
"get offset", | ||
"toString offset", | ||
"get timeZone", | ||
]; | ||
|
||
const calendar = TemporalHelpers.calendarMergeFieldsGetters(); | ||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar); | ||
datetime.with({ year: 2022 }); | ||
|
||
assert.compareArray(calendar.mergeFieldsReturnOperations, expected, "getters called on mergeFields return"); |
Oops, something went wrong.