From 3f9ae40666ed75ba4eece02fa54c8609e36a084c Mon Sep 17 00:00:00 2001 From: Frank Yung-Fong Tang Date: Thu, 9 Sep 2021 02:44:34 -0700 Subject: [PATCH 01/15] Sync test of Temporal.Calendar.p*.fields to 1750 https://github.com/tc39/proposal-temporal/pull --- .../Calendar/prototype/fields/long-input.js | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js b/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js index 03c7314d7de..47142dcf818 100644 --- a/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js +++ b/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js @@ -10,22 +10,34 @@ info: | ## 12.4.21 Temporal.Calendar.prototype.fields ( fields ) 1. Let calendar be the this value. 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. Let fieldNames be ? IterableToListOfType(fields, « String »). - 5. Return ! CreateArrayFromList(fieldNames). + 4. Let iteratorRecord be ? Getiterator(fields, sync). + 5. Let fieldNames be a new empty List. + 6. Let next be true. + 7. Repeat, while next is not false, + 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 + 1. Let completion be ThrowCompletion(a newly created RangeError object). + 2. Return ? IteratorClose(iteratorRecord, completion). features: [Symbol, Symbol.iterator, Temporal, computed-property-names, generators] -includes: [compareArray.js] ---*/ let cal = new Temporal.Calendar("iso8601") +let i = 0; const fields = { *[Symbol.iterator]() { - let i = 0; + // The first three are valid values + yield "year"; + i++; + yield "month"; + i++; + yield "monthCode"; + // The third one are wrong while (i++ < 1000001) { yield "garbage " + i; } } } -assert( - compareArray(cal.fields(fields), Array.from(fields)), - 'compareArray(cal.fields(fields), Array.from(fields)) must return true' -); +assert.throws( RangeError, () => cal.fields(fields), "Garbage content"); +// stop after the third one. +assert.sameValue(3, i); From f5267acaf1fad1365b43c7e71e6ab95cd7dc965a Mon Sep 17 00:00:00 2001 From: Frank Yung-Fong Tang Date: Thu, 9 Sep 2021 02:46:25 -0700 Subject: [PATCH 02/15] add more test --- .../prototype/fields/repeated-throw.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js diff --git a/test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js b/test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js new file mode 100644 index 00000000000..4003f53216c --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js @@ -0,0 +1,39 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.fields +description: > + Temporal.Calendar.prototype.fields will take iterable of any size and any string + and return Array of the same content. +info: | + ## 12.4.21 Temporal.Calendar.prototype.fields ( fields ) + 1. Let calendar be the this value. + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). + 4. Let iteratorRecord be ? Getiterator(fields, sync). + 5. Let fieldNames be a new empty List. + 6. Let next be true. + 7. Repeat, while next is not false, + a. Set next to ? IteratorStep(iteratorRecord). + b. If next is not false, then + i. Let nextValue be ? IteratorValue(next). + iii. If fieldNames contains nextValue, 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] +---*/ +let cal = new Temporal.Calendar("iso8601") +let i = 0; +const fields = { + *[Symbol.iterator]() { + yield "month"; + i++ + yield "year"; + i++ + yield "year"; + i++ + } +} +assert.throws( + RangeError, () => cal.fields(fields), "repeated valid value should throw"); +assert.sameValue(i, 2, "Should stop at 2"); From c3eb263c5b88ea22fca3130660000ac18e9ccd61 Mon Sep 17 00:00:00 2001 From: Frank Yung-Fong Tang Date: Thu, 9 Sep 2021 02:47:23 -0700 Subject: [PATCH 03/15] add more tests for T*.Calendar.p*.fields --- .../Calendar/prototype/fields/reverse.js | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/built-ins/Temporal/Calendar/prototype/fields/reverse.js diff --git a/test/built-ins/Temporal/Calendar/prototype/fields/reverse.js b/test/built-ins/Temporal/Calendar/prototype/fields/reverse.js new file mode 100644 index 00000000000..d79fe4ff202 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/fields/reverse.js @@ -0,0 +1,42 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.fields +description: > + Temporal.Calendar.prototype.fields will take iterable of any size and any string + and return Array of the same content. +info: | + ## 12.4.21 Temporal.Calendar.prototype.fields ( fields ) + 1. Let calendar be the this value. + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). + 4. Let iteratorRecord be ? Getiterator(fields, sync). + 5. Let fieldNames be a new empty List. + 6. Let next be true. + 7. Repeat, while next is not false, + 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 + 1. Let completion be ThrowCompletion(a newly created RangeError object). + 2. Return ? IteratorClose(iteratorRecord, completion). +features: [Symbol, Symbol.iterator, Temporal, computed-property-names, generators] +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"; + yield "year"; + } +} +assert(compareArray(cal.fields(fields), Array.from(fields)), + 'valid fields should return true even if they are in reversed order of the spec'); From 0056eed86facf124799c2ae9c0608a9c8d9b487a Mon Sep 17 00:00:00 2001 From: Frank Yung-Fong Tang Date: Fri, 10 Sep 2021 14:01:00 -0700 Subject: [PATCH 04/15] Update test/built-ins/Temporal/Calendar/prototype/fields/long-input.js Co-authored-by: Ms2ger --- test/built-ins/Temporal/Calendar/prototype/fields/long-input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js b/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js index 47142dcf818..b51dd37461a 100644 --- a/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js +++ b/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js @@ -38,6 +38,6 @@ const fields = { } } } -assert.throws( RangeError, () => cal.fields(fields), "Garbage content"); +assert.throws(RangeError, () => cal.fields(fields), "Garbage content"); // stop after the third one. assert.sameValue(3, i); From b346dd19c7af1a4ba35c2819bc78a2e6923fdcac Mon Sep 17 00:00:00 2001 From: Frank Yung-Fong Tang Date: Fri, 10 Sep 2021 14:01:07 -0700 Subject: [PATCH 05/15] Update test/built-ins/Temporal/Calendar/prototype/fields/long-input.js Co-authored-by: Ms2ger --- test/built-ins/Temporal/Calendar/prototype/fields/long-input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js b/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js index b51dd37461a..70977d831ac 100644 --- a/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js +++ b/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js @@ -40,4 +40,4 @@ const fields = { } assert.throws(RangeError, () => cal.fields(fields), "Garbage content"); // stop after the third one. -assert.sameValue(3, i); +assert.sameValue(i, 3); From f187c6f60d3359d1aa7ec14d076ed06cd3690602 Mon Sep 17 00:00:00 2001 From: Frank Yung-Fong Tang Date: Fri, 10 Sep 2021 14:01:18 -0700 Subject: [PATCH 06/15] Update test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js Co-authored-by: Ms2ger --- .../Temporal/Calendar/prototype/fields/repeated-throw.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js b/test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js index 4003f53216c..ca34cecbcc2 100644 --- a/test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js +++ b/test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js @@ -27,11 +27,11 @@ let i = 0; const fields = { *[Symbol.iterator]() { yield "month"; - i++ + i++; yield "year"; - i++ + i++; yield "year"; - i++ + i++; } } assert.throws( From 228277a925a8d2a04f7172254d90c547b2808ecb Mon Sep 17 00:00:00 2001 From: Frank Yung-Fong Tang Date: Fri, 10 Sep 2021 14:01:39 -0700 Subject: [PATCH 07/15] Update test/built-ins/Temporal/Calendar/prototype/fields/reverse.js Co-authored-by: Ms2ger --- test/built-ins/Temporal/Calendar/prototype/fields/reverse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/built-ins/Temporal/Calendar/prototype/fields/reverse.js b/test/built-ins/Temporal/Calendar/prototype/fields/reverse.js index d79fe4ff202..bc64674e1e4 100644 --- a/test/built-ins/Temporal/Calendar/prototype/fields/reverse.js +++ b/test/built-ins/Temporal/Calendar/prototype/fields/reverse.js @@ -38,5 +38,5 @@ const fields = { yield "year"; } } -assert(compareArray(cal.fields(fields), Array.from(fields)), +assert.compareArray(cal.fields(fields), Array.from(fields), 'valid fields should return true even if they are in reversed order of the spec'); From 2d06f7b17ecb98a0ca06bf82f224134e2b1a258c Mon Sep 17 00:00:00 2001 From: Frank Yung-Fong Tang Date: Fri, 10 Sep 2021 14:01:50 -0700 Subject: [PATCH 08/15] Update test/built-ins/Temporal/Calendar/prototype/fields/reverse.js Co-authored-by: Ms2ger --- test/built-ins/Temporal/Calendar/prototype/fields/reverse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/built-ins/Temporal/Calendar/prototype/fields/reverse.js b/test/built-ins/Temporal/Calendar/prototype/fields/reverse.js index bc64674e1e4..5373a2cdbd3 100644 --- a/test/built-ins/Temporal/Calendar/prototype/fields/reverse.js +++ b/test/built-ins/Temporal/Calendar/prototype/fields/reverse.js @@ -39,4 +39,4 @@ const fields = { } } assert.compareArray(cal.fields(fields), Array.from(fields), - 'valid fields should return true even if they are in reversed order of the spec'); + 'valid fields should be supported even if they are in reversed order of the spec'); From cbcf56f1f7c16e99948670dba69ead9eeae4ac67 Mon Sep 17 00:00:00 2001 From: Frank Yung-Fong Tang Date: Fri, 10 Sep 2021 14:03:35 -0700 Subject: [PATCH 09/15] Remove loop --- .../Temporal/Calendar/prototype/fields/long-input.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js b/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js index 70977d831ac..62ff0849c55 100644 --- a/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js +++ b/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js @@ -32,10 +32,9 @@ const fields = { yield "month"; i++; yield "monthCode"; + i++; // The third one are wrong - while (i++ < 1000001) { - yield "garbage " + i; - } + yield "garbage"; } } assert.throws(RangeError, () => cal.fields(fields), "Garbage content"); From e4c1f025277361232c1ebd8b42d85a71ef96e421 Mon Sep 17 00:00:00 2001 From: Frank Yung-Fong Tang Date: Mon, 13 Sep 2021 15:08:13 -0700 Subject: [PATCH 10/15] Update test/built-ins/Temporal/Calendar/prototype/fields/long-input.js Co-authored-by: Ms2ger --- test/built-ins/Temporal/Calendar/prototype/fields/long-input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js b/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js index 62ff0849c55..5225463f3db 100644 --- a/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js +++ b/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js @@ -33,7 +33,7 @@ const fields = { i++; yield "monthCode"; i++; - // The third one are wrong + // The fourth one is wrong yield "garbage"; } } From 53efc94750217724ed311758c1e02aad95807db4 Mon Sep 17 00:00:00 2001 From: Frank Yung-Fong Tang Date: Mon, 13 Sep 2021 16:47:02 -0700 Subject: [PATCH 11/15] Update long-input.js --- .../Temporal/Calendar/prototype/fields/long-input.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js b/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js index 5225463f3db..c4d36b42413 100644 --- a/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js +++ b/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js @@ -4,8 +4,8 @@ /*--- esid: sec-temporal.calendar.prototype.fields description: > - Temporal.Calendar.prototype.fields will take iterable of any size and any string - and return Array of the same content. + Temporal.Calendar.prototype.fields will throw when its input iterable yields an + invalid field. info: | ## 12.4.21 Temporal.Calendar.prototype.fields ( fields ) 1. Let calendar be the this value. From 948b61de8c305e1a4486c7b25e7e600d71e9c7d6 Mon Sep 17 00:00:00 2001 From: Frank Yung-Fong Tang Date: Mon, 13 Sep 2021 16:47:31 -0700 Subject: [PATCH 12/15] Update repeated-throw.js --- .../Temporal/Calendar/prototype/fields/repeated-throw.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js b/test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js index ca34cecbcc2..adf22e2f87e 100644 --- a/test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js +++ b/test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js @@ -4,8 +4,8 @@ /*--- esid: sec-temporal.calendar.prototype.fields description: > - Temporal.Calendar.prototype.fields will take iterable of any size and any string - and return Array of the same content. + Temporal.Calendar.prototype.fields will throw if its input iterable yields + the same value twice. info: | ## 12.4.21 Temporal.Calendar.prototype.fields ( fields ) 1. Let calendar be the this value. From e012f28961b51a94e0cb8ad3a064cacec6957d05 Mon Sep 17 00:00:00 2001 From: Frank Yung-Fong Tang Date: Mon, 13 Sep 2021 16:48:56 -0700 Subject: [PATCH 13/15] Update reverse.js --- test/built-ins/Temporal/Calendar/prototype/fields/reverse.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/built-ins/Temporal/Calendar/prototype/fields/reverse.js b/test/built-ins/Temporal/Calendar/prototype/fields/reverse.js index 5373a2cdbd3..e0e099ac8c0 100644 --- a/test/built-ins/Temporal/Calendar/prototype/fields/reverse.js +++ b/test/built-ins/Temporal/Calendar/prototype/fields/reverse.js @@ -4,8 +4,8 @@ /*--- esid: sec-temporal.calendar.prototype.fields description: > - Temporal.Calendar.prototype.fields will take iterable of any size and any string - and return Array of the same content. + Temporal.Calendar.prototype.fields will return the iterable in array if all + input are valid regardless of it's order. info: | ## 12.4.21 Temporal.Calendar.prototype.fields ( fields ) 1. Let calendar be the this value. From 28751c0996950bd4204a3653d3c9a49e58a139c4 Mon Sep 17 00:00:00 2001 From: Frank Yung-Fong Tang Date: Wed, 15 Sep 2021 11:34:18 -0700 Subject: [PATCH 14/15] ensure the implementation check the content make sure the validation does not happen after the looping the generator --- .../Temporal/Calendar/prototype/fields/long-input.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js b/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js index c4d36b42413..9ed52dc9f71 100644 --- a/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js +++ b/test/built-ins/Temporal/Calendar/prototype/fields/long-input.js @@ -33,8 +33,13 @@ const fields = { i++; yield "monthCode"; i++; - // The fourth one is wrong + // The fourth one is wrong and should throw after the next line. yield "garbage"; + // The following three lines should not be reached if the implemention + // correctly check the previous line. + i++; + yield "hour"; + i++; } } assert.throws(RangeError, () => cal.fields(fields), "Garbage content"); From 1650eda3cec415717f9c93400f893f7b7cc7cc64 Mon Sep 17 00:00:00 2001 From: Frank Yung-Fong Tang Date: Wed, 15 Sep 2021 15:07:34 -0700 Subject: [PATCH 15/15] add test to check all valid field value --- .../Calendar/prototype/fields/repeated-throw.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js b/test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js index adf22e2f87e..97d9ba22d4d 100644 --- a/test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js +++ b/test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js @@ -37,3 +37,20 @@ const fields = { 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) => { + i = 0; + const fields2 = { + *[Symbol.iterator]() { + yield f; + i++; + yield f; + i++; + } + } + assert.throws( + RangeError, () => cal.fields(fields2), "repeated valid value should throw"); + assert.sameValue(i, 1, "Should stop at 1"); +});