summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/AsyncIterator/prototype/filter
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/non262/AsyncIterator/prototype/filter')
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/filter/coerce-result-to-boolean.js25
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/filter/filter.js24
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/filter/length.js21
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/filter/name.js19
4 files changed, 89 insertions, 0 deletions
diff --git a/js/src/tests/non262/AsyncIterator/prototype/filter/coerce-result-to-boolean.js b/js/src/tests/non262/AsyncIterator/prototype/filter/coerce-result-to-boolean.js
new file mode 100644
index 0000000000..23e3a317eb
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/filter/coerce-result-to-boolean.js
@@ -0,0 +1,25 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+
+async function* gen(iterable) {
+ yield* iterable;
+}
+
+// All truthy values are kept.
+const truthyValues = [true, 1, [], {}, 'test'];
+(async () => {
+ for await (const value of gen([...truthyValues]).filter(x => x)) {
+ assertEq(truthyValues.shift(), value);
+ }
+})();
+
+// All falsy values are filtered out.
+const falsyValues = [false, 0, '', null, undefined, NaN, -0, 0n, createIsHTMLDDA()];
+gen(falsyValues).filter(x => x).next().then(
+ ({done, value}) => {
+ assertEq(done, true);
+ assertEq(value, undefined);
+ }
+);
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/AsyncIterator/prototype/filter/filter.js b/js/src/tests/non262/AsyncIterator/prototype/filter/filter.js
new file mode 100644
index 0000000000..060e9853f2
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/filter/filter.js
@@ -0,0 +1,24 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+
+async function* gen() {
+ yield 1;
+ yield 2;
+ yield 3;
+}
+
+let iter = gen().filter(x => x % 2);
+
+for (const v of [1, 3]) {
+ console.log(iter);
+ iter.next().then(
+ ({done, value}) => {
+ assertEq(done, false);
+ assertEq(value, v);
+ }
+ );
+}
+
+iter.next().then(({done}) => assertEq(done, true));
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/AsyncIterator/prototype/filter/length.js b/js/src/tests/non262/AsyncIterator/prototype/filter/length.js
new file mode 100644
index 0000000000..7ca14621ff
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/filter/length.js
@@ -0,0 +1,21 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+//
+
+/*---
+esid: pending
+description: %AsyncIterator.prototype%.filter length value and descriptor.
+info: >
+ 17 ECMAScript Standard Built-in Objects
+features: [iterator-helpers]
+---*/
+
+assertEq(AsyncIterator.prototype.filter.length, 1);
+
+const propertyDescriptor = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype.filter, 'length');
+assertEq(propertyDescriptor.value, 1);
+assertEq(propertyDescriptor.enumerable, false);
+assertEq(propertyDescriptor.writable, false);
+assertEq(propertyDescriptor.configurable, true);
+
+if (typeof reportCompare == 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/AsyncIterator/prototype/filter/name.js b/js/src/tests/non262/AsyncIterator/prototype/filter/name.js
new file mode 100644
index 0000000000..1a8e030e9a
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/filter/name.js
@@ -0,0 +1,19 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+/*---
+esid: pending
+description: %AsyncIterator.prototype%.filter.name value and descriptor.
+info: >
+ 17 ECMAScript Standard Built-in Objects
+features: [iterator-helpers]
+---*/
+
+assertEq(AsyncIterator.prototype.filter.name, 'filter');
+
+const propertyDescriptor = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype.filter, 'name');
+assertEq(propertyDescriptor.value, 'filter');
+assertEq(propertyDescriptor.enumerable, false);
+assertEq(propertyDescriptor.writable, false);
+assertEq(propertyDescriptor.configurable, true);
+
+if (typeof reportCompare == 'function')
+ reportCompare(0, 0);