summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/AsyncIterator/prototype/some
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/non262/AsyncIterator/prototype/some')
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/some/async-writes.js20
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/some/check-fn-after-getting-iterator.js31
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/some/coerce-result-to-boolean.js29
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/some/descriptor.js13
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/some/error-from-correct-realm.js21
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/some/fn-not-callable-throws.js28
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/some/fn-throws-close-iterator.js24
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/some/interleaving-calls.js24
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/some/length.js17
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/some/name.js13
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/some/next-throws-iterator-not-closed.js23
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/some/proxy.js46
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/some/return-false-if-none-match.js16
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/some/short-circuit-on-true.js20
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/some/this-not-iterator-throws.js19
-rw-r--r--js/src/tests/non262/AsyncIterator/prototype/some/value-throws-iterator-not-closed.js28
16 files changed, 372 insertions, 0 deletions
diff --git a/js/src/tests/non262/AsyncIterator/prototype/some/async-writes.js b/js/src/tests/non262/AsyncIterator/prototype/some/async-writes.js
new file mode 100644
index 0000000000..384bf2e115
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/some/async-writes.js
@@ -0,0 +1,20 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+
+let x = {a: () => true};
+
+async function* gen() {
+ yield x.a();
+ yield x.a();
+}
+
+gen().some(() => {}).then(
+ () => assertEq(true, false, 'expected error'),
+ err => assertEq(err instanceof Error, true),
+);
+
+x.a = () => {
+ throw Error();
+};
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/AsyncIterator/prototype/some/check-fn-after-getting-iterator.js b/js/src/tests/non262/AsyncIterator/prototype/some/check-fn-after-getting-iterator.js
new file mode 100644
index 0000000000..41dd30bee0
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/some/check-fn-after-getting-iterator.js
@@ -0,0 +1,31 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+const log = [];
+const handlerProxy = new Proxy({}, {
+ get: (target, key, receiver) => (...args) => {
+ log.push(`${key}: ${args[1]?.toString()}`);
+ return Reflect[key](...args);
+ },
+});
+
+class TestIterator extends AsyncIterator {
+ next() {
+ return Promise.resolve({done: true});
+ }
+}
+
+async function* gen() {
+ yield 1;
+}
+
+const iter = new Proxy(new TestIterator(), handlerProxy);
+iter.some(1).then(() => assertEq(true, false, 'expected error'), err => assertEq(err instanceof TypeError, true));
+
+assertEq(
+ log.join('\n'),
+ `get: some
+get: next`
+);
+
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/AsyncIterator/prototype/some/coerce-result-to-boolean.js b/js/src/tests/non262/AsyncIterator/prototype/some/coerce-result-to-boolean.js
new file mode 100644
index 0000000000..8b56511040
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/some/coerce-result-to-boolean.js
@@ -0,0 +1,29 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+
+async function* gen(value) {
+ yield value;
+}
+const fn = x => x;
+function check(value, expected) {
+ gen(value).some(fn).then(result => assertEq(result, expected));
+}
+
+check(true, true);
+check(1, true);
+check([], true);
+check({}, true);
+check('test', true);
+
+check(false, false);
+check(0, false);
+check('', false);
+check(null, false);
+check(undefined, false);
+check(NaN, false);
+check(-0, false);
+check(0n, false);
+check(createIsHTMLDDA(), false);
+check(Promise.resolve(false), false);
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/AsyncIterator/prototype/some/descriptor.js b/js/src/tests/non262/AsyncIterator/prototype/some/descriptor.js
new file mode 100644
index 0000000000..d9f5ef8fb7
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/some/descriptor.js
@@ -0,0 +1,13 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+/*---
+ Descriptor property of AsyncIterator.prototype.some
+---*/
+
+const propDesc = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype, 'some');
+assertEq(typeof propDesc.value, 'function');
+assertEq(propDesc.writable, true);
+assertEq(propDesc.enumerable, false);
+assertEq(propDesc.configurable, true);
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/AsyncIterator/prototype/some/error-from-correct-realm.js b/js/src/tests/non262/AsyncIterator/prototype/some/error-from-correct-realm.js
new file mode 100644
index 0000000000..bb4b637c1a
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/some/error-from-correct-realm.js
@@ -0,0 +1,21 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+
+const otherGlobal = newGlobal({newCompartment: true});
+assertEq(TypeError !== otherGlobal.TypeError, true);
+
+async function *gen() {}
+
+gen().some().then(() => assertEq(true, false, 'expected error'), err => {
+ assertEq(err instanceof TypeError, true);
+});
+
+otherGlobal.AsyncIterator.prototype.some.call(gen()).then(() => assertEq(true, false, 'expected error'), err => {
+ assertEq(
+ err instanceof otherGlobal.TypeError,
+ true,
+ 'TypeError comes from the realm of the method.',
+ );
+});
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/AsyncIterator/prototype/some/fn-not-callable-throws.js b/js/src/tests/non262/AsyncIterator/prototype/some/fn-not-callable-throws.js
new file mode 100644
index 0000000000..74a11ceebf
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/some/fn-not-callable-throws.js
@@ -0,0 +1,28 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+
+async function *gen() {
+ yield 1;
+}
+
+function check(fn) {
+ gen().some(fn).then(
+ () => {
+ throw new Error('every should have thrown');
+ },
+ err => {
+ assertEq(err instanceof TypeError, true);
+ }
+ );
+}
+
+check();
+check(undefined);
+check(null);
+check(0);
+check(false);
+check('');
+check(Symbol(''));
+check({});
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/AsyncIterator/prototype/some/fn-throws-close-iterator.js b/js/src/tests/non262/AsyncIterator/prototype/some/fn-throws-close-iterator.js
new file mode 100644
index 0000000000..bdf5119f57
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/some/fn-throws-close-iterator.js
@@ -0,0 +1,24 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+
+class TestIterator extends AsyncIterator {
+ next() {
+ return Promise.resolve({ done: this.closed });
+ }
+
+ closed = false;
+ return() {
+ this.closed = true;
+ }
+}
+
+const fn = () => { throw new Error(); };
+const iter = new TestIterator();
+
+assertEq(iter.closed, false);
+iter.some(fn).then(() => assertEq(true, false, 'expected error'), err => {
+ assertEq(err instanceof Error, true);
+ assertEq(iter.closed, true);
+});
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/AsyncIterator/prototype/some/interleaving-calls.js b/js/src/tests/non262/AsyncIterator/prototype/some/interleaving-calls.js
new file mode 100644
index 0000000000..d5882b9532
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/some/interleaving-calls.js
@@ -0,0 +1,24 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+
+const log = [];
+async function* gen(n) {
+ log.push(`${n}`);
+ yield 1;
+ log.push(`${n}`);
+ yield 2;
+}
+
+Promise.all([gen(1).some(() => {}), gen(2).some(() => {})]).then(
+ () => {
+ assertEq(
+ log.join(' '),
+ '1 2 1 2',
+ );
+ },
+ err => {
+ throw err;
+ }
+);
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/AsyncIterator/prototype/some/length.js b/js/src/tests/non262/AsyncIterator/prototype/some/length.js
new file mode 100644
index 0000000000..ce86dc8b2f
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/some/length.js
@@ -0,0 +1,17 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+/*---
+ The `length` property of AsyncIterator.prototype.some.
+info: |
+ ES7 section 17: Unless otherwise specified, the length property of a built-in
+ Function object has the attributes { [[Writable]]: false, [[Enumerable]]:
+ false, [[Configurable]]: true }.
+---*/
+
+const propDesc = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype.some, 'length');
+assertEq(propDesc.value, 1);
+assertEq(propDesc.writable, false);
+assertEq(propDesc.enumerable, false);
+assertEq(propDesc.configurable, true);
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/AsyncIterator/prototype/some/name.js b/js/src/tests/non262/AsyncIterator/prototype/some/name.js
new file mode 100644
index 0000000000..f2e84a139c
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/some/name.js
@@ -0,0 +1,13 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+/*---
+ `name` property of AsyncIterator.prototype.some.
+---*/
+
+const propDesc = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype.some, 'name');
+assertEq(propDesc.value, 'some');
+assertEq(propDesc.writable, false);
+assertEq(propDesc.enumerable, false);
+assertEq(propDesc.configurable, true);
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/AsyncIterator/prototype/some/next-throws-iterator-not-closed.js b/js/src/tests/non262/AsyncIterator/prototype/some/next-throws-iterator-not-closed.js
new file mode 100644
index 0000000000..89574e0f8e
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/some/next-throws-iterator-not-closed.js
@@ -0,0 +1,23 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+
+class TestIterator extends AsyncIterator {
+ next() {
+ throw new Error();
+ }
+
+ closed = false;
+ return() {
+ this.closed = true;
+ }
+}
+
+const fn = () => {};
+const iter = new TestIterator();
+
+assertEq(iter.closed, false);
+iter.some(fn).then(() => assertEq(true, false, 'expected error'), err => {
+ assertEq(err instanceof Error, true);
+ assertEq(iter.closed, false);
+});
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/AsyncIterator/prototype/some/proxy.js b/js/src/tests/non262/AsyncIterator/prototype/some/proxy.js
new file mode 100644
index 0000000000..6ae089ae38
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/some/proxy.js
@@ -0,0 +1,46 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+//
+// This test checks that %Iterator.prototype%.some only gets the `next` method off of the
+// iterator once, and never accesses the @@iterator property.
+const log = [];
+const handlerProxy = new Proxy({}, {
+ get: (target, key, receiver) => (...args) => {
+ log.push(`${key}: ${args[1]?.toString()}`);
+ return Reflect[key](...args);
+ },
+});
+
+class Counter extends AsyncIterator {
+ value = 0;
+ next() {
+ const value = this.value;
+ if (value < 2) {
+ this.value = value + 1;
+ return Promise.resolve({done: false, value});
+ }
+ return Promise.resolve({done: true});
+ }
+}
+
+const iter = new Proxy(new Counter(), handlerProxy);
+iter.some(x => x % 2 == 1).then(value => {
+ assertEq(value, true);
+
+ assertEq(
+ log.join('\n'),
+ `get: some
+get: next
+get: value
+set: value
+getOwnPropertyDescriptor: value
+defineProperty: value
+get: value
+set: value
+getOwnPropertyDescriptor: value
+defineProperty: value
+get: return`
+ );
+});
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/AsyncIterator/prototype/some/return-false-if-none-match.js b/js/src/tests/non262/AsyncIterator/prototype/some/return-false-if-none-match.js
new file mode 100644
index 0000000000..118436d70b
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/some/return-false-if-none-match.js
@@ -0,0 +1,16 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+
+async function* gen() {
+ yield 1;
+ yield 3;
+ yield 5;
+}
+const fn = x => x % 2 == 0;
+
+gen().some(fn).then(result => assertEq(result, false));
+
+async function* empty() {}
+empty().some(x => x).then(result => assertEq(result, false));
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/AsyncIterator/prototype/some/short-circuit-on-true.js b/js/src/tests/non262/AsyncIterator/prototype/some/short-circuit-on-true.js
new file mode 100644
index 0000000000..3d7250b9a2
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/some/short-circuit-on-true.js
@@ -0,0 +1,20 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+
+async function* gen() {
+ yield 1;
+ yield 2;
+ yield 3;
+}
+const log = [];
+const fn = (value) => {
+ log.push(value.toString());
+ return value % 2 == 0;
+};
+
+gen().some(fn).then(result => {
+ assertEq(result, true);
+ assertEq(log.join(','), '1,2');
+});
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/AsyncIterator/prototype/some/this-not-iterator-throws.js b/js/src/tests/non262/AsyncIterator/prototype/some/this-not-iterator-throws.js
new file mode 100644
index 0000000000..1233fc371c
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/some/this-not-iterator-throws.js
@@ -0,0 +1,19 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+
+const fn = x => x;
+function check(x) {
+ AsyncIterator.prototype.some.call(x, fn).then(
+ () => assertEq(true, false, 'expected error'),
+ err => {
+ assertEq(err instanceof TypeError, true);
+ }
+ );
+}
+
+check();
+check(undefined);
+check({});
+check({next: 0});
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/AsyncIterator/prototype/some/value-throws-iterator-not-closed.js b/js/src/tests/non262/AsyncIterator/prototype/some/value-throws-iterator-not-closed.js
new file mode 100644
index 0000000000..f7a344eea4
--- /dev/null
+++ b/js/src/tests/non262/AsyncIterator/prototype/some/value-throws-iterator-not-closed.js
@@ -0,0 +1,28 @@
+// |reftest| skip-if(!this.hasOwnProperty('AsyncIterator'))
+
+class TestError extends Error {}
+class TestIterator extends AsyncIterator {
+ next() {
+ return Promise.resolve({
+ done: false,
+ get value() {
+ throw new TestError();
+ }
+ });
+ }
+
+ closed = false;
+ return() {
+ closed = true;
+ }
+}
+
+const iterator = new TestIterator();
+assertEq(iterator.closed, false, 'iterator starts unclosed');
+iterator.some(x => x).then(() => assertEq(true, false, 'expected error'), err => {
+ assertEq(err instanceof TestError, true);
+ assertEq(iterator.closed, false, 'iterator remains unclosed');
+});
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);