summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Iterator/prototype/filter
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--js/src/tests/non262/Iterator/prototype/filter/coerce-result-to-boolean.js16
-rw-r--r--js/src/tests/non262/Iterator/prototype/filter/filter.js14
-rw-r--r--js/src/tests/non262/Iterator/prototype/filter/length.js22
-rw-r--r--js/src/tests/non262/Iterator/prototype/filter/name.js19
4 files changed, 71 insertions, 0 deletions
diff --git a/js/src/tests/non262/Iterator/prototype/filter/coerce-result-to-boolean.js b/js/src/tests/non262/Iterator/prototype/filter/coerce-result-to-boolean.js
new file mode 100644
index 0000000000..a3d16bcdfa
--- /dev/null
+++ b/js/src/tests/non262/Iterator/prototype/filter/coerce-result-to-boolean.js
@@ -0,0 +1,16 @@
+// |reftest| skip-if(!this.hasOwnProperty('Iterator')) -- Iterator is not enabled unconditionally
+
+// All truthy values are kept.
+const truthyValues = [true, 1, [], {}, 'test'];
+for (const value of [...truthyValues].values().filter(x => x)) {
+ assertEq(truthyValues.shift(), value);
+}
+
+// All falsy values are filtered out.
+const falsyValues = [false, 0, '', null, undefined, NaN, -0, 0n, createIsHTMLDDA()];
+const result = falsyValues.values().filter(x => x).next();
+assertEq(result.done, true);
+assertEq(result.value, undefined);
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/Iterator/prototype/filter/filter.js b/js/src/tests/non262/Iterator/prototype/filter/filter.js
new file mode 100644
index 0000000000..1d148cb82b
--- /dev/null
+++ b/js/src/tests/non262/Iterator/prototype/filter/filter.js
@@ -0,0 +1,14 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+
+let iter = [1, 2, 3].values().filter(x => x % 2);
+
+for (const v of [1, 3]) {
+ let result = iter.next();
+ assertEq(result.done, false);
+ assertEq(result.value, v);
+}
+
+assertEq(iter.next().done, true);
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/Iterator/prototype/filter/length.js b/js/src/tests/non262/Iterator/prototype/filter/length.js
new file mode 100644
index 0000000000..c1fad91b1d
--- /dev/null
+++ b/js/src/tests/non262/Iterator/prototype/filter/length.js
@@ -0,0 +1,22 @@
+// |reftest| skip-if(!this.hasOwnProperty('Iterator'))
+//
+
+/*---
+esid: pending
+description: %Iterator.prototype%.filter length value and descriptor.
+info: >
+ 17 ECMAScript Standard Built-in Objects
+includes: [propertyHelper.js]
+features: [Symbol.iterator]
+---*/
+
+assertEq(Iterator.prototype.filter.length, 1);
+
+const propertyDescriptor = Reflect.getOwnPropertyDescriptor(Iterator.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/Iterator/prototype/filter/name.js b/js/src/tests/non262/Iterator/prototype/filter/name.js
new file mode 100644
index 0000000000..b278220225
--- /dev/null
+++ b/js/src/tests/non262/Iterator/prototype/filter/name.js
@@ -0,0 +1,19 @@
+// |reftest| skip-if(!this.hasOwnProperty('Iterator'))
+/*---
+esid: pending
+description: %Iterator.prototype%.filter.name value and descriptor.
+info: >
+ 17 ECMAScript Standard Built-in Objects
+features: [iterator-helpers]
+---*/
+
+assertEq(Iterator.prototype.filter.name, 'filter');
+
+const propertyDescriptor = Reflect.getOwnPropertyDescriptor(Iterator.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);