mirror of
https://github.com/tc39/test262.git
synced 2025-07-21 13:04:39 +02:00
Update staging/sm
This commit is contained in:
parent
c85603ff11
commit
a37cb9c206
@ -4,7 +4,7 @@ allow_unused: True
|
||||
---*/
|
||||
|
||||
function ISOFields(monthDay) {
|
||||
let re = /^(?<year>\d{4,6})-(?<month>\d{2})-(?<day>\d{2})\[u-ca=(?<calendar>[\w\-]+)\]$/;
|
||||
let re = /^(?<year>-?\d{4,6})-(?<month>\d{2})-(?<day>\d{2})\[u-ca=(?<calendar>[\w\-]+)\]$/;
|
||||
|
||||
let str = monthDay.toString({calendarName: "always"});
|
||||
let match = str.match(re);
|
||||
|
@ -1,23 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: |
|
||||
Property descriptor of AsyncIterator.
|
||||
|
||||
AsyncIterator is not enabled unconditionally
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
const propDesc = Reflect.getOwnPropertyDescriptor(this, 'AsyncIterator');
|
||||
assert.sameValue(propDesc.value, AsyncIterator);
|
||||
assert.sameValue(propDesc.writable, true);
|
||||
assert.sameValue(propDesc.enumerable, false);
|
||||
assert.sameValue(propDesc.configurable, true);
|
||||
|
@ -1,20 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: |
|
||||
AsyncIterator constructor can be subclassed.
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
class TestIterator extends AsyncIterator {
|
||||
}
|
||||
|
||||
assert.sameValue(new TestIterator() instanceof AsyncIterator, true);
|
||||
|
@ -1,17 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: |
|
||||
AsyncIterator constructor throws when called directly.
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
assertThrowsInstanceOf(() => new AsyncIterator(), TypeError);
|
||||
|
@ -1,19 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: |
|
||||
AsyncIterator constructor throws when called without new.
|
||||
|
||||
AsyncIterator is not enabled unconditionally
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
assertThrowsInstanceOf(() => AsyncIterator(), TypeError);
|
||||
|
@ -1,19 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: |
|
||||
The AsyncIterator constructor is a built-in function.
|
||||
|
||||
AsyncIterator is not enabled unconditionally
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
assert.sameValue(typeof AsyncIterator, 'function');
|
||||
|
@ -1,23 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: |
|
||||
The "length" property of AsyncIterator
|
||||
|
||||
AsyncIterator is not enabled unconditionally
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
const propDesc = Reflect.getOwnPropertyDescriptor(AsyncIterator, 'length');
|
||||
assert.sameValue(propDesc.value, 0);
|
||||
assert.sameValue(propDesc.writable, false);
|
||||
assert.sameValue(propDesc.enumerable, false);
|
||||
assert.sameValue(propDesc.configurable, true);
|
||||
|
@ -1,23 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: |
|
||||
The "name" property of AsyncIterator
|
||||
|
||||
AsyncIterator is not enabled unconditionally
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
const propDesc = Reflect.getOwnPropertyDescriptor(AsyncIterator, 'name');
|
||||
assert.sameValue(propDesc.value, 'AsyncIterator');
|
||||
assert.sameValue(propDesc.writable, false);
|
||||
assert.sameValue(propDesc.enumerable, false);
|
||||
assert.sameValue(propDesc.configurable, true);
|
||||
|
@ -1,24 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: |
|
||||
The prototype of the AsyncIterator constructor is the intrinsic object %FunctionPrototype%.
|
||||
|
||||
AsyncIterator is not enabled unconditionally
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
assert.sameValue(Object.getPrototypeOf(AsyncIterator), Function.prototype);
|
||||
|
||||
const propDesc = Reflect.getOwnPropertyDescriptor(AsyncIterator, 'prototype');
|
||||
assert.sameValue(propDesc.writable, false);
|
||||
assert.sameValue(propDesc.enumerable, false);
|
||||
assert.sameValue(propDesc.configurable, false);
|
||||
|
@ -1,34 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
async function* gen() {
|
||||
yield 1;
|
||||
yield 2;
|
||||
yield 3;
|
||||
}
|
||||
|
||||
let iter = gen().asIndexedPairs();
|
||||
|
||||
for (const v of [[0, 1], [1, 2], [2, 3]]) {
|
||||
iter.next().then(
|
||||
result => {
|
||||
assert.sameValue(result.done, false);
|
||||
assert.sameValue(result.value[0], v[0]);
|
||||
assert.sameValue(result.value[1], v[1]);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
iter.next().then(({done}) => assert.sameValue(done, true));
|
||||
|
@ -1,26 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
%AsyncIterator.prototype%.asIndexedPairs length value and descriptor.
|
||||
info: |
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
//
|
||||
|
||||
assert.sameValue(AsyncIterator.prototype.asIndexedPairs.length, 0);
|
||||
|
||||
const propertyDescriptor = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype.asIndexedPairs, 'length');
|
||||
assert.sameValue(propertyDescriptor.value, 0);
|
||||
assert.sameValue(propertyDescriptor.enumerable, false);
|
||||
assert.sameValue(propertyDescriptor.writable, false);
|
||||
assert.sameValue(propertyDescriptor.configurable, true);
|
||||
|
@ -1,25 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
%AsyncIterator.prototype%.asIndexedPairs.name value and descriptor.
|
||||
info: |
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
assert.sameValue(AsyncIterator.prototype.asIndexedPairs.name, 'asIndexedPairs');
|
||||
|
||||
const propertyDescriptor = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype.asIndexedPairs, 'name');
|
||||
assert.sameValue(propertyDescriptor.value, 'asIndexedPairs');
|
||||
assert.sameValue(propertyDescriptor.enumerable, false);
|
||||
assert.sameValue(propertyDescriptor.writable, false);
|
||||
assert.sameValue(propertyDescriptor.configurable, true);
|
||||
|
@ -1,75 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
class TestError extends Error {}
|
||||
|
||||
class TestIterator extends AsyncIterator {
|
||||
async next() {
|
||||
return {done: false, value: 'value'};
|
||||
}
|
||||
|
||||
closed = false;
|
||||
async return(value) {
|
||||
this.closed = true;
|
||||
return {done: true, value};
|
||||
}
|
||||
}
|
||||
|
||||
function checkIterResult({done, value}, expectedDone, expectedValue) {
|
||||
assert.sameValue(done, expectedDone);
|
||||
assert.sameValue(Array.isArray(value) ? value[1] : value, expectedValue);
|
||||
}
|
||||
|
||||
const otherGlobal = createNewGlobal({newCompartment: true});
|
||||
|
||||
const methods = [
|
||||
["map", x => x],
|
||||
["filter", x => true],
|
||||
["take", Infinity],
|
||||
["drop", 0],
|
||||
["asIndexedPairs", undefined],
|
||||
["flatMap", async function*(x) { yield x; }],
|
||||
];
|
||||
|
||||
const {next: otherNext, return: otherReturn, throw: otherThrow} =
|
||||
Object.getPrototypeOf(otherGlobal.eval("(async function*() {})().map(x => x)"));
|
||||
|
||||
(async () => {
|
||||
for (const [method, arg] of methods) {
|
||||
const iterator = new TestIterator();
|
||||
const helper = iterator[method](arg);
|
||||
checkIterResult(await otherNext.call(helper), false, 'value');
|
||||
}
|
||||
|
||||
for (const [method, arg] of methods) {
|
||||
const iterator = new TestIterator();
|
||||
const helper = iterator[method](arg);
|
||||
assert.sameValue(iterator.closed, false);
|
||||
checkIterResult(await otherReturn.call(helper), true, undefined);
|
||||
assert.sameValue(iterator.closed, true);
|
||||
}
|
||||
|
||||
for (const [method, arg] of methods) {
|
||||
const iterator = new TestIterator();
|
||||
const helper = iterator[method](arg);
|
||||
try {
|
||||
await otherThrow.call(helper, new TestError());
|
||||
assert.sameValue(true, false, 'Expected exception');
|
||||
} catch (exc) {
|
||||
assert.sameValue(exc instanceof TestError, true);
|
||||
}
|
||||
checkIterResult(await helper.next(), true, undefined);
|
||||
}
|
||||
})();
|
||||
|
@ -1,56 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
%AsyncIterator.prototype% methods work even if the global Symbol has been clobbered.
|
||||
info: |
|
||||
Iterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- Symbol.asyncIterator
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
//
|
||||
//
|
||||
|
||||
Symbol = undefined;
|
||||
assertThrowsInstanceOf(() => Symbol.asyncIterator, TypeError);
|
||||
|
||||
async function* gen(value) {
|
||||
yield value;
|
||||
}
|
||||
|
||||
const lazyMethods = [
|
||||
iter => iter.map(x => x),
|
||||
iter => iter.filter(x => x),
|
||||
iter => iter.take(1),
|
||||
iter => iter.drop(0),
|
||||
iter => iter.asIndexedPairs(),
|
||||
iter => iter.flatMap(gen),
|
||||
];
|
||||
|
||||
const strictMethods = [
|
||||
iter => iter.reduce((_, x) => x, undefined),
|
||||
iter => iter.toArray(),
|
||||
iter => iter.forEach(() => undefined),
|
||||
iter => iter.some(x => true),
|
||||
iter => iter.every(x => true),
|
||||
iter => iter.find(x => true),
|
||||
];
|
||||
|
||||
(async () => {
|
||||
for (const method of lazyMethods) {
|
||||
const {value} = await method(gen('value')).next();
|
||||
assert.sameValue(Array.isArray(value) ? value[1] : value, 'value');
|
||||
}
|
||||
|
||||
for (const method of strictMethods) {
|
||||
await method(gen('value'));
|
||||
}
|
||||
})();
|
||||
|
@ -1,43 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
%AsyncIterator.prototype%.drop returns if the iterator is done.
|
||||
info: |
|
||||
Iterator Helpers proposal 2.1.6.5 1. Repeat, while remaining > 0,
|
||||
...
|
||||
b. Let next be ? Await(? IteratorStep(iterated)).
|
||||
c. If ? IteratorComplete(next) is true, return undefined.
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class TestIterator extends AsyncIterator {
|
||||
counter = 0;
|
||||
async next() {
|
||||
return {done: ++this.counter >= 2, value: undefined};
|
||||
}
|
||||
}
|
||||
|
||||
(async () => {
|
||||
let iter = [1, 2].values().drop(3);
|
||||
let result = await iter.next();
|
||||
assert.sameValue(result.value, undefined);
|
||||
assert.sameValue(result.done, true);
|
||||
|
||||
iter = new TestIterator();
|
||||
let dropped = iter.drop(10);
|
||||
result = await dropped.next();
|
||||
assert.sameValue(result.value, undefined);
|
||||
assert.sameValue(result.done, true);
|
||||
assert.sameValue(iter.counter, 2);
|
||||
})();
|
||||
|
@ -1,33 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
async function* gen() {
|
||||
yield 1;
|
||||
yield 2;
|
||||
yield 3;
|
||||
}
|
||||
|
||||
let iter = gen().drop(1);
|
||||
|
||||
for (const v of [2, 3]) {
|
||||
iter.next().then(
|
||||
({done, value}) => {
|
||||
assert.sameValue(done, false);
|
||||
assert.sameValue(value, v);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
iter.next().then(({done}) => assert.sameValue(done, true));
|
||||
|
@ -1,24 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
%AsyncIterator.prototype%.drop length value and descriptor.
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
//
|
||||
|
||||
assert.sameValue(AsyncIterator.prototype.drop.length, 1);
|
||||
|
||||
const propertyDescriptor = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype.drop, 'length');
|
||||
assert.sameValue(propertyDescriptor.value, 1);
|
||||
assert.sameValue(propertyDescriptor.enumerable, false);
|
||||
assert.sameValue(propertyDescriptor.writable, false);
|
||||
assert.sameValue(propertyDescriptor.configurable, true);
|
||||
|
@ -1,25 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
%AsyncIterator.prototype%.drop.name value and descriptor.
|
||||
info: |
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
assert.sameValue(AsyncIterator.prototype.drop.name, 'drop');
|
||||
|
||||
const propertyDescriptor = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype.drop, 'name');
|
||||
assert.sameValue(propertyDescriptor.value, 'drop');
|
||||
assert.sameValue(propertyDescriptor.enumerable, false);
|
||||
assert.sameValue(propertyDescriptor.writable, false);
|
||||
assert.sameValue(propertyDescriptor.configurable, true);
|
||||
|
@ -1,30 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
let x = {a: () => true};
|
||||
|
||||
async function* gen() {
|
||||
yield x.a();
|
||||
yield x.a();
|
||||
}
|
||||
|
||||
gen().every(() => true).then(
|
||||
() => assert.sameValue(true, false, 'expected error'),
|
||||
err => assert.sameValue(err instanceof Error, true),
|
||||
);
|
||||
|
||||
x.a = () => {
|
||||
throw Error();
|
||||
};
|
||||
|
@ -1,40 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
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.every(1).then(() => assert.sameValue(true, false, 'expected error'), err => assert.sameValue(err instanceof TypeError, true));
|
||||
|
||||
assert.sameValue(
|
||||
log.join('\n'),
|
||||
`get: every
|
||||
get: next`
|
||||
);
|
||||
|
@ -1,40 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
features:
|
||||
- IsHTMLDDA
|
||||
- async-iteration
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
async function* gen(value) {
|
||||
yield value;
|
||||
}
|
||||
const fn = x => x;
|
||||
function check(value, expected) {
|
||||
gen(value).every(fn).then(result => assert.sameValue(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);
|
||||
|
@ -1,20 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
const propDesc = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype, 'every');
|
||||
assert.sameValue(typeof propDesc.value, 'function');
|
||||
assert.sameValue(propDesc.writable, true);
|
||||
assert.sameValue(propDesc.enumerable, false);
|
||||
assert.sameValue(propDesc.configurable, true);
|
||||
|
@ -1,31 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
const otherGlobal = createNewGlobal({newCompartment: true});
|
||||
assert.sameValue(TypeError !== otherGlobal.TypeError, true);
|
||||
|
||||
async function *gen() {}
|
||||
|
||||
gen().every().then(() => assert.sameValue(true, false, 'expected error'), err => {
|
||||
assert.sameValue(err instanceof TypeError, true);
|
||||
});
|
||||
|
||||
otherGlobal.AsyncIterator.prototype.every.call(gen()).then(() => assert.sameValue(true, false, 'expected error'), err => {
|
||||
assert.sameValue(
|
||||
err instanceof otherGlobal.TypeError,
|
||||
true,
|
||||
'TypeError comes from the realm of the method.',
|
||||
);
|
||||
});
|
||||
|
@ -1,36 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
async function *gen() {
|
||||
yield 1;
|
||||
}
|
||||
|
||||
function check(fn) {
|
||||
gen().every(fn).then(() => {
|
||||
throw new Error('every should have thrown');
|
||||
},
|
||||
(err) => {
|
||||
assert.sameValue(err instanceof TypeError, true);
|
||||
});
|
||||
}
|
||||
|
||||
check();
|
||||
check(undefined);
|
||||
check(null);
|
||||
check(0);
|
||||
check(false);
|
||||
check('');
|
||||
check(Symbol(''));
|
||||
check({});
|
||||
|
@ -1,34 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
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();
|
||||
|
||||
assert.sameValue(iter.closed, false);
|
||||
iter.every(fn).then(() => assert.sameValue(true, false, 'expected error'), err => {
|
||||
assert.sameValue(err instanceof Error, true);
|
||||
assert.sameValue(iter.closed, true);
|
||||
});
|
||||
|
@ -1,34 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
const log = [];
|
||||
async function* gen(n) {
|
||||
log.push(`${n}`);
|
||||
yield 1;
|
||||
log.push(`${n}`);
|
||||
yield 2;
|
||||
}
|
||||
|
||||
Promise.all([gen(1).every(() => true), gen(2).every(() => true)]).then(
|
||||
() => {
|
||||
assert.sameValue(
|
||||
log.join(' '),
|
||||
'1 2 1 2',
|
||||
);
|
||||
},
|
||||
err => {
|
||||
throw err;
|
||||
}
|
||||
);
|
||||
|
@ -1,23 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: |
|
||||
The `length` property of AsyncIterator.prototype.every.
|
||||
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 }.
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
esid: pending
|
||||
---*/
|
||||
const propDesc = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype.every, 'length');
|
||||
assert.sameValue(propDesc.value, 1);
|
||||
assert.sameValue(propDesc.writable, false);
|
||||
assert.sameValue(propDesc.enumerable, false);
|
||||
assert.sameValue(propDesc.configurable, true);
|
||||
|
@ -1,19 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: |
|
||||
`name` property of AsyncIterator.prototype.every.
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
esid: pending
|
||||
---*/
|
||||
const propDesc = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype.every, 'name');
|
||||
assert.sameValue(propDesc.value, 'every');
|
||||
assert.sameValue(propDesc.writable, false);
|
||||
assert.sameValue(propDesc.enumerable, false);
|
||||
assert.sameValue(propDesc.configurable, true);
|
||||
|
@ -1,34 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
class TestIterator extends AsyncIterator {
|
||||
next() {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
closed = false;
|
||||
return() {
|
||||
this.closed = true;
|
||||
}
|
||||
}
|
||||
|
||||
const fn = () => {};
|
||||
const iter = new TestIterator();
|
||||
|
||||
assert.sameValue(iter.closed, false);
|
||||
iter.every(fn).then(() => assert.sameValue(true, false, 'expected error'), err => {
|
||||
assert.sameValue(err instanceof Error, true);
|
||||
assert.sameValue(iter.closed, false);
|
||||
});
|
||||
|
@ -1,56 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
//
|
||||
// This test checks that %AsyncIterator.prototype%.every only gets the `next` method off of the
|
||||
// iterator once, and never accesses the @@asyncIterator 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.every(x => x % 2 == 0).then(value => {
|
||||
assert.sameValue(value, false)
|
||||
|
||||
assert.sameValue(
|
||||
log.join('\n'),
|
||||
`get: every
|
||||
get: next
|
||||
get: value
|
||||
set: value
|
||||
getOwnPropertyDescriptor: value
|
||||
defineProperty: value
|
||||
get: value
|
||||
set: value
|
||||
getOwnPropertyDescriptor: value
|
||||
defineProperty: value
|
||||
get: return`
|
||||
);
|
||||
});
|
||||
|
@ -1,26 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
async function* gen() {
|
||||
yield 1;
|
||||
yield 3;
|
||||
yield 5;
|
||||
}
|
||||
const fn = x => x % 2 == 1;
|
||||
|
||||
gen().every(fn).then(result => assert.sameValue(result, true));
|
||||
|
||||
async function* empty() {}
|
||||
empty().every(x => x).then(result => assert.sameValue(result, true));
|
||||
|
@ -1,31 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
async function* gen() {
|
||||
yield 1;
|
||||
yield 2;
|
||||
yield 3;
|
||||
}
|
||||
|
||||
const log = [];
|
||||
const fn = value => {
|
||||
log.push(value.toString());
|
||||
return value % 2 == 1;
|
||||
};
|
||||
|
||||
gen().every(fn).then(result => {
|
||||
assert.sameValue(result, false);
|
||||
assert.sameValue(log.join(','), '1,2');
|
||||
});
|
||||
|
@ -1,32 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
const fn = x => x;
|
||||
|
||||
function check(x) {
|
||||
AsyncIterator.prototype.every.call(x, fn).then(
|
||||
() => {
|
||||
throw new Error('check should have been rejected');
|
||||
},
|
||||
err => {
|
||||
assert.sameValue(err instanceof TypeError, true);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
check();
|
||||
check(undefined);
|
||||
check({});
|
||||
check({next: 0});
|
||||
|
@ -1,38 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
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();
|
||||
assert.sameValue(iterator.closed, false, 'iterator starts unclosed');
|
||||
iterator.every(x => x).then(() => assert.sameValue(true, false, 'expected error'), err => {
|
||||
assert.sameValue(err instanceof TestError, true);
|
||||
assert.sameValue(iterator.closed, false, 'iterator remains unclosed');
|
||||
});
|
||||
|
@ -1,36 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
features:
|
||||
- IsHTMLDDA
|
||||
- async-iteration
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
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)) {
|
||||
assert.sameValue(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}) => {
|
||||
assert.sameValue(done, true);
|
||||
assert.sameValue(value, undefined);
|
||||
}
|
||||
);
|
||||
|
@ -1,33 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
async function* gen() {
|
||||
yield 1;
|
||||
yield 2;
|
||||
yield 3;
|
||||
}
|
||||
|
||||
let iter = gen().filter(x => x % 2);
|
||||
|
||||
for (const v of [1, 3]) {
|
||||
iter.next().then(
|
||||
({done, value}) => {
|
||||
assert.sameValue(done, false);
|
||||
assert.sameValue(value, v);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
iter.next().then(({done}) => assert.sameValue(done, true));
|
||||
|
@ -1,26 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
%AsyncIterator.prototype%.filter length value and descriptor.
|
||||
info: |
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
//
|
||||
|
||||
assert.sameValue(AsyncIterator.prototype.filter.length, 1);
|
||||
|
||||
const propertyDescriptor = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype.filter, 'length');
|
||||
assert.sameValue(propertyDescriptor.value, 1);
|
||||
assert.sameValue(propertyDescriptor.enumerable, false);
|
||||
assert.sameValue(propertyDescriptor.writable, false);
|
||||
assert.sameValue(propertyDescriptor.configurable, true);
|
||||
|
@ -1,24 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
%AsyncIterator.prototype%.filter.name value and descriptor.
|
||||
info: |
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
assert.sameValue(AsyncIterator.prototype.filter.name, 'filter');
|
||||
|
||||
const propertyDescriptor = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype.filter, 'name');
|
||||
assert.sameValue(propertyDescriptor.value, 'filter');
|
||||
assert.sameValue(propertyDescriptor.enumerable, false);
|
||||
assert.sameValue(propertyDescriptor.writable, false);
|
||||
assert.sameValue(propertyDescriptor.configurable, true);
|
||||
|
@ -1,30 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
let x = {a: () => true};
|
||||
|
||||
async function* gen() {
|
||||
yield x.a();
|
||||
yield x.a();
|
||||
}
|
||||
|
||||
gen().find(() => {}).then(
|
||||
() => assert.sameValue(true, false, 'expected error'),
|
||||
err => assert.sameValue(err instanceof Error, true),
|
||||
);
|
||||
|
||||
x.a = () => {
|
||||
throw Error();
|
||||
};
|
||||
|
@ -1,38 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
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});
|
||||
}
|
||||
}
|
||||
|
||||
const iter = new Proxy(new TestIterator(), handlerProxy);
|
||||
iter.find(1).then(() => assert.sameValue(true, false, 'expected error'), err => {
|
||||
assert.sameValue(err instanceof TypeError, true);
|
||||
assert.sameValue(
|
||||
log.join('\n'),
|
||||
`get: find
|
||||
get: next`
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -1,46 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
features:
|
||||
- IsHTMLDDA
|
||||
- async-iteration
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
async function* gen(value) {
|
||||
yield value;
|
||||
}
|
||||
const fn = x => x;
|
||||
function check(value, expected) {
|
||||
gen(value).find(fn).then(result => assert.sameValue(result, expected));
|
||||
}
|
||||
|
||||
check(true, true);
|
||||
check(1, 1);
|
||||
check('test', 'test');
|
||||
|
||||
check(false, undefined);
|
||||
check(0, undefined);
|
||||
check('', undefined);
|
||||
check(null, undefined);
|
||||
check(undefined, undefined);
|
||||
check(NaN, undefined);
|
||||
check(-0, undefined);
|
||||
check(0n, undefined);
|
||||
check(Promise.resolve(false), undefined);
|
||||
|
||||
let array = [];
|
||||
check(array, array);
|
||||
|
||||
let object = {};
|
||||
check(object, object);
|
||||
|
||||
const htmlDDA = createIsHTMLDDA();
|
||||
check(htmlDDA, undefined);
|
||||
|
@ -1,21 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: |
|
||||
Descriptor property of AsyncIterator.prototype.find
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
const propDesc = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype, 'find');
|
||||
assert.sameValue(typeof propDesc.value, 'function');
|
||||
assert.sameValue(propDesc.writable, true);
|
||||
assert.sameValue(propDesc.enumerable, false);
|
||||
assert.sameValue(propDesc.configurable, true);
|
||||
|
@ -1,31 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
const otherGlobal = createNewGlobal({newCompartment: true});
|
||||
assert.sameValue(TypeError !== otherGlobal.TypeError, true);
|
||||
|
||||
async function *gen() {}
|
||||
|
||||
gen().find().then(() => assert.sameValue(true, false, 'expected error'), err => {
|
||||
assert.sameValue(err instanceof TypeError, true);
|
||||
});
|
||||
|
||||
otherGlobal.AsyncIterator.prototype.find.call(gen()).then(() => assert.sameValue(true, false, 'expected error'), err => {
|
||||
assert.sameValue(
|
||||
err instanceof otherGlobal.TypeError,
|
||||
true,
|
||||
'TypeError comes from the realm of the method.',
|
||||
);
|
||||
});
|
||||
|
@ -1,36 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
async function *gen() {
|
||||
yield 1;
|
||||
}
|
||||
|
||||
function check(fn) {
|
||||
gen().every(fn).then(() => {
|
||||
throw new Error('every should have thrown');
|
||||
},
|
||||
(err) => {
|
||||
assert.sameValue(err instanceof TypeError, true);
|
||||
});
|
||||
}
|
||||
|
||||
check();
|
||||
check(undefined);
|
||||
check(null);
|
||||
check(0);
|
||||
check(false);
|
||||
check('');
|
||||
check(Symbol(''));
|
||||
check({});
|
||||
|
@ -1,36 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
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();
|
||||
|
||||
assert.sameValue(iter.closed, false);
|
||||
iter.find(fn).then(() => {
|
||||
throw new Error('promise should be rejected');
|
||||
}, err => {
|
||||
assert.sameValue(err instanceof Error, true);
|
||||
assert.sameValue(iter.closed, true);
|
||||
});
|
||||
|
@ -1,34 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
const log = [];
|
||||
async function* gen(n) {
|
||||
log.push(`${n}`);
|
||||
yield 1;
|
||||
log.push(`${n}`);
|
||||
yield 2;
|
||||
}
|
||||
|
||||
Promise.all([gen(1).find(() => {}), gen(2).find(() => {})]).then(
|
||||
() => {
|
||||
assert.sameValue(
|
||||
log.join(' '),
|
||||
'1 2 1 2',
|
||||
);
|
||||
},
|
||||
err => {
|
||||
throw err;
|
||||
}
|
||||
);
|
||||
|
@ -1,23 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: |
|
||||
The `length` property of AsyncIterator.prototype.find.
|
||||
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 }.
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
esid: pending
|
||||
---*/
|
||||
const propDesc = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype.find, 'length');
|
||||
assert.sameValue(propDesc.value, 1);
|
||||
assert.sameValue(propDesc.writable, false);
|
||||
assert.sameValue(propDesc.enumerable, false);
|
||||
assert.sameValue(propDesc.configurable, true);
|
||||
|
@ -1,19 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: |
|
||||
`name` property of AsyncIterator.prototype.find.
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
esid: pending
|
||||
---*/
|
||||
const propDesc = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype.find, 'name');
|
||||
assert.sameValue(propDesc.value, 'find');
|
||||
assert.sameValue(propDesc.writable, false);
|
||||
assert.sameValue(propDesc.enumerable, false);
|
||||
assert.sameValue(propDesc.configurable, true);
|
||||
|
@ -1,34 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
class TestIterator extends AsyncIterator {
|
||||
next() {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
closed = false;
|
||||
return() {
|
||||
this.closed = true;
|
||||
}
|
||||
}
|
||||
|
||||
const fn = x => x;
|
||||
const iter = new TestIterator();
|
||||
|
||||
assert.sameValue(iter.closed, false);
|
||||
iter.find(fn).then(() => assert.sameValue(true, false, 'expected error'), err => {
|
||||
assert.sameValue(err instanceof Error, true);
|
||||
assert.sameValue(iter.closed, false);
|
||||
});
|
||||
|
@ -1,56 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
//
|
||||
// This test checks that %Iterator.prototype%.find 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.find(x => x % 2 == 1).then(value => {
|
||||
assert.sameValue(value, 1);
|
||||
|
||||
assert.sameValue(
|
||||
log.join('\n'),
|
||||
`get: find
|
||||
get: next
|
||||
get: value
|
||||
set: value
|
||||
getOwnPropertyDescriptor: value
|
||||
defineProperty: value
|
||||
get: value
|
||||
set: value
|
||||
getOwnPropertyDescriptor: value
|
||||
defineProperty: value
|
||||
get: return`
|
||||
);
|
||||
});
|
||||
|
@ -1,26 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
async function* gen() {
|
||||
yield 1;
|
||||
yield 3;
|
||||
yield 5;
|
||||
}
|
||||
const fn = x => x % 2 == 0;
|
||||
|
||||
gen().find(fn).then(result => assert.sameValue(result, undefined));
|
||||
|
||||
async function* empty() {}
|
||||
empty().find(x => x).then(result => assert.sameValue(result, undefined));
|
||||
|
@ -1,31 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
async function* gen() {
|
||||
yield 1;
|
||||
yield 2;
|
||||
yield 3;
|
||||
}
|
||||
|
||||
const log = [];
|
||||
const fn = (value) => {
|
||||
log.push(value.toString());
|
||||
return value % 2 == 0;
|
||||
};
|
||||
|
||||
gen().find(fn).then(result => {
|
||||
assert.sameValue(result, 2);
|
||||
assert.sameValue(log.join(','), '1,2');
|
||||
});
|
||||
|
@ -1,30 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
const fn = x => x;
|
||||
|
||||
function check(x) {
|
||||
AsyncIterator.prototype.find.call(x, fn).then(
|
||||
() => assert.sameValue(true, false, 'expected error'),
|
||||
err => {
|
||||
assert.sameValue(err instanceof TypeError, true);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
check();
|
||||
check(undefined);
|
||||
check({});
|
||||
check({next: 0});
|
||||
|
@ -1,38 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
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();
|
||||
assert.sameValue(iterator.closed, false, 'iterator starts unclosed');
|
||||
iterator.find(x => x).then(() => assert.sameValue(true, false, 'expected error'), err => {
|
||||
assert.sameValue(err instanceof TestError, true);
|
||||
assert.sameValue(iterator.closed, false, 'iterator remains unclosed');
|
||||
});
|
||||
|
@ -1,59 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
%AsyncIterator.prototype%.flatMap closes the iterator when innerComplete throws.
|
||||
info: |
|
||||
Iterator Helpers proposal 2.1.6.7 1. Repeat,
|
||||
...
|
||||
k. Repeat, while innerAlive is true,
|
||||
...
|
||||
v. Let innerComplete be IteratorComplete(innerNext).
|
||||
vi. IfAbruptCloseAsyncIterator(innerComplete, iterated).
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class TestIterator extends AsyncIterator {
|
||||
async next() {
|
||||
return {done: false, value: 0};
|
||||
}
|
||||
|
||||
closed = false;
|
||||
async return() {
|
||||
this.closed = true;
|
||||
return {done: true};
|
||||
}
|
||||
}
|
||||
|
||||
class TestError extends Error {}
|
||||
class InnerIterator extends AsyncIterator {
|
||||
async next() {
|
||||
return {
|
||||
get done() {
|
||||
throw new TestError();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const iter = new TestIterator();
|
||||
const mapped = iter.flatMap(x => new InnerIterator());
|
||||
|
||||
assert.sameValue(iter.closed, false);
|
||||
mapped.next().then(
|
||||
_ => assert.sameValue(true, false, 'Expected reject.'),
|
||||
err => {
|
||||
assert.sameValue(err instanceof TestError, true);
|
||||
assert.sameValue(iter.closed, true);
|
||||
}
|
||||
);
|
||||
|
@ -1,54 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
%AsyncIterator.prototype%.flatMap closes the iterator when IteratorNext throws.
|
||||
info: |
|
||||
Iterator Helpers proposal 2.1.6.7 1. Repeat,
|
||||
...
|
||||
k. Repeat, while innerAlive is true,
|
||||
i. Let innerNextPromise be IteratorNext(innerIterator).
|
||||
ii. IfAbruptCloseAsyncIterator(innerNextPromise, iterated).
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class TestIterator extends AsyncIterator {
|
||||
async next() {
|
||||
return {done: false, value: 0};
|
||||
}
|
||||
|
||||
closed = false;
|
||||
async return(value) {
|
||||
this.closed = true;
|
||||
return {done: true, value};
|
||||
}
|
||||
}
|
||||
|
||||
class TestError extends Error {}
|
||||
class InnerIterator extends AsyncIterator {
|
||||
async next() {
|
||||
throw new TestError();
|
||||
}
|
||||
}
|
||||
|
||||
const iter = new TestIterator();
|
||||
const mapped = iter.flatMap(x => new InnerIterator());
|
||||
|
||||
assert.sameValue(iter.closed, false);
|
||||
mapped.next().then(
|
||||
_ => assert.sameValue(true, false, 'Expected reject.'),
|
||||
err => {
|
||||
assert.sameValue(err instanceof TestError, true);
|
||||
assert.sameValue(iter.closed, true);
|
||||
}
|
||||
);
|
||||
|
@ -1,61 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
%AsyncIterator.prototype%.flatMap closes the iterator when innerValue throws.
|
||||
info: |
|
||||
Iterator Helpers proposal 2.1.6.7 1. Repeat,
|
||||
...
|
||||
k. Repeat, while innerAlive is true,
|
||||
...
|
||||
viii. Else,
|
||||
1. Let innerValue be IteratorValue(innerNext).
|
||||
2. IfAbruptCloseAsyncIterator(innerValue, iterated).
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class TestIterator extends AsyncIterator {
|
||||
async next() {
|
||||
return {done: false, value: 0};
|
||||
}
|
||||
|
||||
closed = false;
|
||||
async return() {
|
||||
this.closed = true;
|
||||
return {done: true};
|
||||
}
|
||||
}
|
||||
|
||||
class TestError extends Error {}
|
||||
class InnerIterator extends AsyncIterator {
|
||||
async next() {
|
||||
return {
|
||||
done: false,
|
||||
get value() {
|
||||
throw new TestError();
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const iter = new TestIterator();
|
||||
const mapped = iter.flatMap(x => new InnerIterator());
|
||||
|
||||
assert.sameValue(iter.closed, false);
|
||||
mapped.next().then(
|
||||
_ => assert.sameValue(true, false, 'Expected reject.'),
|
||||
err => {
|
||||
assert.sameValue(err instanceof TestError, true);
|
||||
assert.sameValue(iter.closed, true);
|
||||
}
|
||||
);
|
||||
|
@ -1,38 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
async function* gen() {
|
||||
yield 1;
|
||||
yield 2;
|
||||
yield 3;
|
||||
}
|
||||
|
||||
async function* inner(x) {
|
||||
yield x;
|
||||
yield x + 1;
|
||||
}
|
||||
|
||||
let iter = gen().flatMap(x => inner(x));
|
||||
|
||||
for (const v of [1, 2, 2, 3, 3, 4]) {
|
||||
iter.next().then(
|
||||
({done, value}) => {
|
||||
assert.sameValue(done, false);
|
||||
assert.sameValue(value, v);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
iter.next().then(({done}) => assert.sameValue(done, true));
|
||||
|
@ -1,48 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
%AsyncIterator.prototype%.flatMap skips empty inner iterables.
|
||||
info: |
|
||||
Iterator Helpers proposal 2.1.6.7 1. Repeat,
|
||||
...
|
||||
k. Repeat, while innerAlive is true,
|
||||
...
|
||||
v. Let innerComplete be IteratorComplete(innerNext).
|
||||
...
|
||||
vii. If innerComplete is true, set innerAlive to false.
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
async function* gen(values) {
|
||||
yield* values;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
let iter = gen([0, 1, 2, 3]).flatMap(x => x % 2 ? gen([]) : gen([x]));
|
||||
|
||||
for (const expected of [0, 2]) {
|
||||
const result = await iter.next();
|
||||
assert.sameValue(result.value, expected);
|
||||
assert.sameValue(result.done, false);
|
||||
}
|
||||
|
||||
let result = await iter.next();
|
||||
assert.sameValue(result.value, undefined);
|
||||
assert.sameValue(result.done, true);
|
||||
|
||||
iter = gen([0, 1, 2, 3]).flatMap(x => gen([]));
|
||||
result = await iter.next();
|
||||
assert.sameValue(result.value, undefined);
|
||||
assert.sameValue(result.done, true);
|
||||
})();
|
||||
|
@ -1,41 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
%AsyncIterator.prototype%.flatMap innerIterator can be a generator.
|
||||
info: |
|
||||
Iterator Helpers proposal 2.1.6.7
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
async function* gen() {
|
||||
yield 1;
|
||||
yield 2;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const iter = gen().flatMap(async function*(x) {
|
||||
yield x;
|
||||
yield* [x + 1, x + 2];
|
||||
});
|
||||
|
||||
for (const expected of [1, 2, 3, 2, 3, 4]) {
|
||||
const result = await iter.next();
|
||||
assert.sameValue(result.value, expected);
|
||||
assert.sameValue(result.done, false);
|
||||
}
|
||||
|
||||
const result = await iter.next();
|
||||
assert.sameValue(result.value, undefined);
|
||||
assert.sameValue(result.done, true);
|
||||
})();
|
||||
|
@ -1,26 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
%AsyncIterator.prototype%.flatMap length value and descriptor.
|
||||
info: |
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
//
|
||||
|
||||
assert.sameValue(AsyncIterator.prototype.flatMap.length, 1);
|
||||
|
||||
const propertyDescriptor = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype.flatMap, 'length');
|
||||
assert.sameValue(propertyDescriptor.value, 1);
|
||||
assert.sameValue(propertyDescriptor.enumerable, false);
|
||||
assert.sameValue(propertyDescriptor.writable, false);
|
||||
assert.sameValue(propertyDescriptor.configurable, true);
|
||||
|
@ -1,24 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
%AsyncIterator.prototype%.flatMap.name value and descriptor.
|
||||
info: |
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
assert.sameValue(AsyncIterator.prototype.flatMap.name, 'flatMap');
|
||||
|
||||
const propertyDescriptor = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype.flatMap, 'name');
|
||||
assert.sameValue(propertyDescriptor.value, 'flatMap');
|
||||
assert.sameValue(propertyDescriptor.enumerable, false);
|
||||
assert.sameValue(propertyDescriptor.writable, false);
|
||||
assert.sameValue(propertyDescriptor.configurable, true);
|
||||
|
@ -1,74 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
%AsyncIterator.prototype%.flatMap closes the iterator and throws when mapped isn't iterable.
|
||||
info: |
|
||||
Iterator Helpers proposal 2.1.6.7 1. Repeat,
|
||||
...
|
||||
h. Let innerIterator be GetIterator(mapped, async).
|
||||
i. IfAbruptCloseAsyncIterator(innerIterator, iterated).
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class NotIterable {
|
||||
async next() {
|
||||
return {done: true};
|
||||
}
|
||||
}
|
||||
|
||||
class InvalidIterable {
|
||||
[Symbol.asyncIterator]() {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
class TestIterator extends AsyncIterator {
|
||||
async next() {
|
||||
return {done: false, value: 0};
|
||||
}
|
||||
|
||||
closed = false;
|
||||
async return(value) {
|
||||
this.closed = true;
|
||||
return {done: true, value};
|
||||
}
|
||||
}
|
||||
|
||||
const nonIterables = [
|
||||
new NotIterable(),
|
||||
new InvalidIterable(),
|
||||
undefined,
|
||||
null,
|
||||
0,
|
||||
false,
|
||||
Symbol(''),
|
||||
0n,
|
||||
{},
|
||||
];
|
||||
|
||||
(async () => {
|
||||
for (const value of nonIterables) {
|
||||
const iter = new TestIterator();
|
||||
const mapped = iter.flatMap(x => value);
|
||||
|
||||
assert.sameValue(iter.closed, false);
|
||||
try {
|
||||
await mapped.next();
|
||||
assert.sameValue(true, false, 'Expected reject');
|
||||
} catch (exc) {
|
||||
assert.sameValue(exc instanceof TypeError, true);
|
||||
}
|
||||
assert.sameValue(iter.closed, true);
|
||||
}
|
||||
})();
|
||||
|
@ -1,30 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
let x = {a: () => true};
|
||||
|
||||
async function* gen() {
|
||||
yield x.a();
|
||||
yield x.a();
|
||||
}
|
||||
|
||||
gen().forEach(() => {}).then(
|
||||
() => assert.sameValue(true, false, 'expected error'),
|
||||
err => assert.sameValue(err instanceof Error, true),
|
||||
);
|
||||
|
||||
x.a = () => {
|
||||
throw Error();
|
||||
};
|
||||
|
@ -1,37 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
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});
|
||||
}
|
||||
}
|
||||
|
||||
const iter = new Proxy(new TestIterator(), handlerProxy);
|
||||
iter.forEach(1).then(() => assert.sameValue(true, false, 'expected error'), err => {
|
||||
assert.sameValue(err instanceof TypeError, true);
|
||||
assert.sameValue(
|
||||
log.join('\n'),
|
||||
`get: forEach
|
||||
get: next`
|
||||
);
|
||||
});
|
||||
|
@ -1,21 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: |
|
||||
Descriptor property of AsyncIterator.prototype.forEach
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
const propDesc = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype, 'forEach');
|
||||
assert.sameValue(typeof propDesc.value, 'function');
|
||||
assert.sameValue(propDesc.writable, true);
|
||||
assert.sameValue(propDesc.enumerable, false);
|
||||
assert.sameValue(propDesc.configurable, true);
|
||||
|
@ -1,31 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
const otherGlobal = createNewGlobal({newCompartment: true});
|
||||
assert.sameValue(TypeError !== otherGlobal.TypeError, true);
|
||||
|
||||
async function *gen() {}
|
||||
|
||||
gen().forEach().then(() => assert.sameValue(true, false, 'expected error'), err => {
|
||||
assert.sameValue(err instanceof TypeError, true);
|
||||
});
|
||||
|
||||
otherGlobal.AsyncIterator.prototype.forEach.call(gen()).then(() => assert.sameValue(true, false, 'expected error'), err => {
|
||||
assert.sameValue(
|
||||
err instanceof otherGlobal.TypeError,
|
||||
true,
|
||||
'TypeError comes from the realm of the method.',
|
||||
);
|
||||
});
|
||||
|
@ -1,34 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
async function *gen() {}
|
||||
|
||||
function check(fn) {
|
||||
gen().forEach(fn).then(() => {
|
||||
throw new Error('every should have thrown');
|
||||
},
|
||||
(err) => {
|
||||
assert.sameValue(err instanceof TypeError, true);
|
||||
});
|
||||
}
|
||||
|
||||
check();
|
||||
check(undefined);
|
||||
check(null);
|
||||
check(0);
|
||||
check(false);
|
||||
check('');
|
||||
check(Symbol(''));
|
||||
check({});
|
||||
|
@ -1,34 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
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();
|
||||
|
||||
assert.sameValue(iter.closed, false);
|
||||
iter.forEach(fn).then(() => assert.sameValue(true, false, 'expected error'), err => {
|
||||
assert.sameValue(err instanceof Error, true);
|
||||
assert.sameValue(iter.closed, true);
|
||||
});
|
||||
|
@ -1,34 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
const log = [];
|
||||
async function* gen(n) {
|
||||
log.push(`${n}`);
|
||||
yield 1;
|
||||
log.push(`${n}`);
|
||||
yield 2;
|
||||
}
|
||||
|
||||
Promise.all([gen(1).forEach(() => {}), gen(2).forEach(() => {})]).then(
|
||||
() => {
|
||||
assert.sameValue(
|
||||
log.join(' '),
|
||||
'1 2 1 2',
|
||||
);
|
||||
},
|
||||
err => {
|
||||
throw err;
|
||||
}
|
||||
);
|
||||
|
@ -1,23 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: |
|
||||
The `length` property of AsyncIterator.prototype.forEach.
|
||||
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 }.
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
esid: pending
|
||||
---*/
|
||||
const propDesc = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype.forEach, 'length');
|
||||
assert.sameValue(propDesc.value, 1);
|
||||
assert.sameValue(propDesc.writable, false);
|
||||
assert.sameValue(propDesc.enumerable, false);
|
||||
assert.sameValue(propDesc.configurable, true);
|
||||
|
@ -1,19 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: |
|
||||
`name` property of AsyncIterator.prototype.forEach.
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
esid: pending
|
||||
---*/
|
||||
const propDesc = Reflect.getOwnPropertyDescriptor(AsyncIterator.prototype.forEach, 'name');
|
||||
assert.sameValue(propDesc.value, 'forEach');
|
||||
assert.sameValue(propDesc.writable, false);
|
||||
assert.sameValue(propDesc.enumerable, false);
|
||||
assert.sameValue(propDesc.configurable, true);
|
||||
|
@ -1,34 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
class TestIterator extends AsyncIterator {
|
||||
next() {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
closed = false;
|
||||
return() {
|
||||
this.closed = true;
|
||||
}
|
||||
}
|
||||
|
||||
const fn = () => {};
|
||||
const iter = new TestIterator();
|
||||
|
||||
assert.sameValue(iter.closed, false);
|
||||
iter.forEach(fn).then(() => assert.sameValue(true, false, 'expected error'), err => {
|
||||
assert.sameValue(err instanceof Error, true);
|
||||
assert.sameValue(iter.closed, false);
|
||||
});
|
||||
|
@ -1,54 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
//
|
||||
// This test checks that %Iterator.prototype%.forEach 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.forEach(x => x).then(() => {
|
||||
assert.sameValue(
|
||||
log.join('\n'),
|
||||
`get: forEach
|
||||
get: next
|
||||
get: value
|
||||
set: value
|
||||
getOwnPropertyDescriptor: value
|
||||
defineProperty: value
|
||||
get: value
|
||||
set: value
|
||||
getOwnPropertyDescriptor: value
|
||||
defineProperty: value
|
||||
get: value`
|
||||
);
|
||||
});
|
||||
|
@ -1,29 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
const fn = x => x;
|
||||
function check(x) {
|
||||
AsyncIterator.prototype.forEach.call(x, fn).then(
|
||||
() => assert.sameValue(true, false, 'expected error'),
|
||||
err => {
|
||||
assert.sameValue(err instanceof TypeError, true);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
check();
|
||||
check(undefined);
|
||||
check({});
|
||||
check({next: 0});
|
||||
|
@ -1,38 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
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();
|
||||
assert.sameValue(iterator.closed, false, 'iterator starts unclosed');
|
||||
iterator.forEach(x => x).then(() => assert.sameValue(true, false, 'expected error'), err => {
|
||||
assert.sameValue(err instanceof TestError, true);
|
||||
assert.sameValue(iterator.closed, false, 'iterator remains unclosed');
|
||||
});
|
||||
|
@ -1,45 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
const asyncGeneratorProto = Object.getPrototypeOf(
|
||||
Object.getPrototypeOf(
|
||||
(async function *() {})()
|
||||
)
|
||||
);
|
||||
|
||||
const methods = [
|
||||
iter => iter.map(x => x),
|
||||
iter => iter.filter(x => x),
|
||||
iter => iter.take(1),
|
||||
iter => iter.drop(0),
|
||||
iter => iter.asIndexedPairs(),
|
||||
iter => iter.flatMap(x => (async function*() {})()),
|
||||
];
|
||||
|
||||
for (const method of methods) {
|
||||
const iteratorHelper = method((async function*() {})());
|
||||
asyncGeneratorProto.next.call(iteratorHelper).then(
|
||||
_ => assert.sameValue(true, false, 'Expected reject'),
|
||||
err => assert.sameValue(err instanceof TypeError, true),
|
||||
);
|
||||
asyncGeneratorProto.return.call(iteratorHelper).then(
|
||||
_ => assert.sameValue(true, false, 'Expected reject'),
|
||||
err => assert.sameValue(err instanceof TypeError, true),
|
||||
);
|
||||
asyncGeneratorProto.throw.call(iteratorHelper).then(
|
||||
_ => assert.sameValue(true, false, 'Expected reject'),
|
||||
err => assert.sameValue(err instanceof TypeError, true),
|
||||
);
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
async function *gen() { yield 'value'; }
|
||||
|
||||
const asyncIteratorHelperProto = Object.getPrototypeOf(gen().map(x => x));
|
||||
|
||||
assertThrowsInstanceOf(() => asyncIteratorHelperProto.next.call(gen()), TypeError);
|
||||
assertThrowsInstanceOf(() => asyncIteratorHelperProto.return.call(gen()), TypeError);
|
||||
assertThrowsInstanceOf(() => asyncIteratorHelperProto.throw.call(gen()), TypeError);
|
||||
|
@ -1,46 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
async function* gen(values) {
|
||||
yield* values;
|
||||
}
|
||||
|
||||
const otherAsyncIteratorProto = createNewGlobal({newCompartment: true}).AsyncIterator.prototype;
|
||||
|
||||
const methods = [
|
||||
["map", x => x],
|
||||
["filter", x => true],
|
||||
["take", Infinity],
|
||||
["drop", 0],
|
||||
["asIndexedPairs", undefined],
|
||||
["flatMap", x => gen([x])],
|
||||
];
|
||||
|
||||
(async () => {
|
||||
for (const [method, arg] of methods) {
|
||||
const iterator = gen([1, 2, 3]);
|
||||
const helper = otherAsyncIteratorProto[method].call(iterator, arg);
|
||||
|
||||
for (const expected of [1, 2, 3]) {
|
||||
const {done, value} = await helper.next();
|
||||
assert.sameValue(done, false);
|
||||
assert.sameValue(Array.isArray(value) ? value[1] : value, expected);
|
||||
}
|
||||
|
||||
const {done, value} = await helper.next();
|
||||
assert.sameValue(done, true);
|
||||
assert.sameValue(value, undefined);
|
||||
}
|
||||
})();
|
||||
|
@ -1,47 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
Lazy %AsyncIterator.prototype% methods handle empty iterators.
|
||||
info: |
|
||||
Iterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class EmptyIterator extends AsyncIterator {
|
||||
async next() {
|
||||
return {done: true};
|
||||
}
|
||||
}
|
||||
|
||||
async function* gen() {}
|
||||
|
||||
const methods = [
|
||||
iter => iter.map(x => x),
|
||||
iter => iter.filter(x => x),
|
||||
iter => iter.take(1),
|
||||
iter => iter.drop(0),
|
||||
iter => iter.asIndexedPairs(),
|
||||
iter => iter.flatMap(x => gen()),
|
||||
];
|
||||
|
||||
for (const method of methods) {
|
||||
for (const iterator of [new EmptyIterator(), gen()]) {
|
||||
method(iterator).next().then(
|
||||
({done, value}) => {
|
||||
assert.sameValue(done, true);
|
||||
assert.sameValue(value, undefined);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,64 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
Lazy %AsyncIterator.prototype% method calls can be interleaved.
|
||||
info: |
|
||||
Iterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class TestIterator extends AsyncIterator {
|
||||
value = 0;
|
||||
async next() {
|
||||
return {done: false, value: this.value++};
|
||||
}
|
||||
}
|
||||
|
||||
function unwrapResult(value) {
|
||||
// Unwrap the asIndexedPair return values.
|
||||
while (Array.isArray(value)) {
|
||||
value = value[1];
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function check({done, value}, expectedDone, expectedValue) {
|
||||
assert.sameValue(done, expectedDone);
|
||||
assert.sameValue(unwrapResult(value), expectedValue);
|
||||
}
|
||||
|
||||
const methods = [
|
||||
['map', x => x],
|
||||
['filter', x => true],
|
||||
['take', Infinity],
|
||||
['drop', 0],
|
||||
['asIndexedPairs', undefined],
|
||||
['flatMap', async function*(x) { yield x; }],
|
||||
];
|
||||
|
||||
(async () => {
|
||||
for (const [firstMethod, firstArg] of methods) {
|
||||
for (const [secondMethod, secondArg] of methods) {
|
||||
const iterator = new TestIterator();
|
||||
|
||||
const firstHelper = iterator[firstMethod](firstArg);
|
||||
const secondHelper = iterator[secondMethod](secondArg);
|
||||
|
||||
check(await firstHelper.next(), false, 0);
|
||||
check(await secondHelper.next(), false, 1);
|
||||
check(await firstHelper.next(), false, 2);
|
||||
check(await secondHelper.next(), false, 3);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
@ -1,53 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
Lazy %AsyncIterator.prototype% methods close the iterator if callback throws.
|
||||
info: |
|
||||
AsyncIterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class TestError extends Error {}
|
||||
class TestAsyncIterator extends AsyncIterator {
|
||||
async next() {
|
||||
return {done: false, value: 1};
|
||||
}
|
||||
|
||||
closed = false;
|
||||
async return() {
|
||||
this.closed = true;
|
||||
return {done: true};
|
||||
}
|
||||
}
|
||||
|
||||
function fn() {
|
||||
throw new TestError();
|
||||
}
|
||||
const methods = [
|
||||
iter => iter.map(fn),
|
||||
iter => iter.filter(fn),
|
||||
iter => iter.flatMap(fn),
|
||||
];
|
||||
|
||||
for (const method of methods) {
|
||||
const iter = new TestAsyncIterator();
|
||||
assert.sameValue(iter.closed, false);
|
||||
method(iter).next().then(
|
||||
_ => assert.sameValue(true, false, 'Expected reject'),
|
||||
err => {
|
||||
assert.sameValue(err instanceof TestError, true);
|
||||
assert.sameValue(iter.closed, true);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
Lazy %AsyncIterator.prototype% methods close the iterator if `yield` throws.
|
||||
info: |
|
||||
AsyncIterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class TestError extends Error {}
|
||||
class TestAsyncIterator extends AsyncIterator {
|
||||
async next() {
|
||||
return {done: false, value: 1};
|
||||
}
|
||||
|
||||
closed = false;
|
||||
async return(value) {
|
||||
this.closed = true;
|
||||
return {done: true, value};
|
||||
}
|
||||
}
|
||||
|
||||
async function* gen(x) { yield x; }
|
||||
const methods = [
|
||||
iter => iter.map(x => x),
|
||||
iter => iter.filter(x => true),
|
||||
iter => iter.take(1),
|
||||
iter => iter.drop(0),
|
||||
iter => iter.asIndexedPairs(),
|
||||
iter => iter.flatMap(gen),
|
||||
];
|
||||
|
||||
for (const method of methods) {
|
||||
const iterator = new TestAsyncIterator();
|
||||
const iteratorHelper = method(iterator);
|
||||
|
||||
assert.sameValue(iterator.closed, false);
|
||||
iteratorHelper.next().then(
|
||||
_ => iteratorHelper.throw(new TestError()).then(
|
||||
_ => assert.sameValue(true, false, 'Expected reject'),
|
||||
err => {
|
||||
assert.sameValue(err instanceof TestError, true);
|
||||
assert.sameValue(iterator.closed, true);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -1,61 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
Lazy %AsyncIterator.prototype% methods don't close the iterator if getting `then` throws.
|
||||
info: |
|
||||
AsyncIterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class TestError extends Error {}
|
||||
|
||||
class TestIterator extends AsyncIterator {
|
||||
next() {
|
||||
return {
|
||||
get then() {
|
||||
throw new TestError();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
closed = false;
|
||||
async return(value) {
|
||||
this.closed = true;
|
||||
return {done: true, value};
|
||||
}
|
||||
}
|
||||
|
||||
const methods = [
|
||||
["map", x => x],
|
||||
["filter", x => true],
|
||||
["take", Infinity],
|
||||
["drop", 0],
|
||||
["asIndexedPairs", undefined],
|
||||
["flatMap", async function*(x) { yield x; }],
|
||||
];
|
||||
|
||||
(async () => {
|
||||
for (const [method, arg] of methods) {
|
||||
const iterator = new TestIterator();
|
||||
assert.sameValue(iterator.closed, false);
|
||||
|
||||
try {
|
||||
await iterator[method](arg).next();
|
||||
assert.sameValue(true, false, 'Expected exception');
|
||||
} catch(err) {
|
||||
assert.sameValue(err instanceof TestError, true);
|
||||
}
|
||||
assert.sameValue(iterator.closed, false);
|
||||
}
|
||||
})();
|
||||
|
@ -1,58 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
Lazy %AsyncIterator.prototype% methods don't close the iterator if executor of Promise returned by `.next` throws.
|
||||
info: |
|
||||
AsyncIterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class TestError extends Error {}
|
||||
class TestIterator extends AsyncIterator {
|
||||
next() {
|
||||
return new Promise((resolve, reject) => {
|
||||
throw new TestError();
|
||||
});
|
||||
}
|
||||
|
||||
closed = false;
|
||||
async return(value) {
|
||||
this.closed = true;
|
||||
return {done: true, value};
|
||||
}
|
||||
}
|
||||
|
||||
const methods = [
|
||||
["map", x => x],
|
||||
["filter", x => true],
|
||||
["take", Infinity],
|
||||
["drop", 0],
|
||||
["asIndexedPairs", undefined],
|
||||
["flatMap", async function*(x) { yield x; }],
|
||||
];
|
||||
|
||||
(async () => {
|
||||
for (const [method, arg] of methods) {
|
||||
const iterator = new TestIterator();
|
||||
assert.sameValue(iterator.closed, false);
|
||||
|
||||
try {
|
||||
await iterator[method](arg).next();
|
||||
assert.sameValue(true, false, 'Expected exception');
|
||||
} catch(err) {
|
||||
assert.sameValue(err instanceof TestError, true);
|
||||
}
|
||||
assert.sameValue(iterator.closed, false);
|
||||
}
|
||||
})();
|
||||
|
@ -1,56 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
Lazy %AsyncIterator.prototype% methods don't close the iterator if `.next` returns a rejected Promise.
|
||||
info: |
|
||||
AsyncIterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class TestError extends Error {}
|
||||
class TestIterator extends AsyncIterator {
|
||||
next() {
|
||||
return Promise.reject(new TestError());
|
||||
}
|
||||
|
||||
closed = false;
|
||||
async return(value) {
|
||||
this.closed = true;
|
||||
return {done: true, value};
|
||||
}
|
||||
}
|
||||
|
||||
const methods = [
|
||||
["map", x => x],
|
||||
["filter", x => true],
|
||||
["take", Infinity],
|
||||
["drop", 0],
|
||||
["asIndexedPairs", undefined],
|
||||
["flatMap", async function*(x) { yield x; }],
|
||||
];
|
||||
|
||||
(async () => {
|
||||
for (const [method, arg] of methods) {
|
||||
const iterator = new TestIterator();
|
||||
assert.sameValue(iterator.closed, false);
|
||||
|
||||
try {
|
||||
await iterator[method](arg).next();
|
||||
assert.sameValue(true, false, 'Expected exception');
|
||||
} catch(err) {
|
||||
assert.sameValue(err instanceof TestError, true);
|
||||
}
|
||||
assert.sameValue(iterator.closed, false);
|
||||
}
|
||||
})();
|
||||
|
@ -1,61 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
Lazy %AsyncIterator.prototype% methods don't close the iterator if `then` returned by `next` throws.
|
||||
info: |
|
||||
AsyncIterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class TestError extends Error {}
|
||||
|
||||
class TestIterator extends AsyncIterator {
|
||||
next() {
|
||||
return {
|
||||
then() {
|
||||
throw new TestError();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
closed = false;
|
||||
async return(value) {
|
||||
this.closed = true;
|
||||
return {done: true, value};
|
||||
}
|
||||
}
|
||||
|
||||
const methods = [
|
||||
["map", x => x],
|
||||
["filter", x => true],
|
||||
["take", Infinity],
|
||||
["drop", 0],
|
||||
["asIndexedPairs", undefined],
|
||||
["flatMap", async function*(x) { yield x; }],
|
||||
];
|
||||
|
||||
(async () => {
|
||||
for (const [method, arg] of methods) {
|
||||
const iterator = new TestIterator();
|
||||
assert.sameValue(iterator.closed, false);
|
||||
|
||||
try {
|
||||
await iterator[method](arg).next();
|
||||
assert.sameValue(true, false, 'Expected exception');
|
||||
} catch(err) {
|
||||
assert.sameValue(err instanceof TestError, true);
|
||||
}
|
||||
assert.sameValue(iterator.closed, false);
|
||||
}
|
||||
})();
|
||||
|
@ -1,54 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
Lazy %AsyncIterator.prototype% methods don't close the iterator if `.next` call throws.
|
||||
info: |
|
||||
AsyncIterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class TestError extends Error {}
|
||||
class TestAsyncIterator extends AsyncIterator {
|
||||
next() {
|
||||
throw new TestError();
|
||||
}
|
||||
|
||||
closed = false;
|
||||
async return(value) {
|
||||
this.closed = true;
|
||||
return {done: true, value};
|
||||
}
|
||||
}
|
||||
|
||||
async function* gen(x) { yield x; }
|
||||
const methods = [
|
||||
iter => iter.map(x => x),
|
||||
iter => iter.filter(x => x),
|
||||
iter => iter.take(1),
|
||||
iter => iter.drop(0),
|
||||
iter => iter.asIndexedPairs(),
|
||||
iter => iter.flatMap(gen),
|
||||
];
|
||||
|
||||
for (const method of methods) {
|
||||
const iterator = new TestAsyncIterator();
|
||||
assert.sameValue(iterator.closed, false);
|
||||
method(iterator).next().then(
|
||||
_ => assert.sameValue(true, false, 'Expected reject'),
|
||||
err => {
|
||||
assert.sameValue(err instanceof TestError, true);
|
||||
assert.sameValue(iterator.closed, false);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -1,59 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
Lazy %AsyncIterator.prototype% methods don't close the iterator if `value` throws.
|
||||
info: |
|
||||
AsyncIterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class TestError extends Error {}
|
||||
class TestAsyncIterator extends AsyncIterator {
|
||||
async next() {
|
||||
return {
|
||||
get value() {
|
||||
throw new TestError();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
closed = false;
|
||||
async return(value) {
|
||||
this.closed = true;
|
||||
return {done: true, value};
|
||||
}
|
||||
}
|
||||
|
||||
const iterator = new TestAsyncIterator();
|
||||
|
||||
async function* gen(x) { yield x; }
|
||||
const methods = [
|
||||
iter => iter.map(x => x),
|
||||
iter => iter.filter(x => x),
|
||||
iter => iter.take(1),
|
||||
iter => iter.drop(0),
|
||||
iter => iter.asIndexedPairs(),
|
||||
iter => iter.flatMap(gen),
|
||||
];
|
||||
|
||||
for (const method of methods) {
|
||||
assert.sameValue(iterator.closed, false);
|
||||
method(iterator).next().then(
|
||||
_ => assert.sameValue(true, false, 'Expected reject'),
|
||||
err => {
|
||||
assert.sameValue(err instanceof TestError, true);
|
||||
assert.sameValue(iterator.closed, false);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
class TestIterator extends AsyncIterator {
|
||||
async next() {
|
||||
return {done: true, value: 'value'};
|
||||
}
|
||||
}
|
||||
|
||||
async function* gen(x) { yield x; }
|
||||
|
||||
const methods = [
|
||||
iter => iter.map(x => x),
|
||||
iter => iter.filter(x => true),
|
||||
iter => iter.take(1),
|
||||
iter => iter.drop(0),
|
||||
iter => iter.asIndexedPairs(),
|
||||
iter => iter.flatMap(gen),
|
||||
];
|
||||
|
||||
(async () => {
|
||||
for (const method of methods) {
|
||||
const iterator = method(new TestIterator());
|
||||
const {done, value} = await iterator.next();
|
||||
assert.sameValue(done, true);
|
||||
assert.sameValue(value, undefined);
|
||||
}
|
||||
})();
|
||||
|
@ -1,69 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
Calling `.return()` on a lazy %AsyncIterator.prototype% method multiple times closes the source iterator once.
|
||||
info: |
|
||||
Iterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class TestIterator extends AsyncIterator {
|
||||
async next() {
|
||||
return {done: false, value: 1};
|
||||
}
|
||||
|
||||
closeCount = 0;
|
||||
async return(value) {
|
||||
this.closeCount++;
|
||||
return {done: true, value};
|
||||
}
|
||||
}
|
||||
|
||||
async function* gen(x) { yield x; }
|
||||
|
||||
const methods = [
|
||||
iter => iter.map(x => x),
|
||||
iter => iter.filter(x => x),
|
||||
iter => iter.take(1),
|
||||
iter => iter.drop(0),
|
||||
iter => iter.asIndexedPairs(),
|
||||
iter => iter.flatMap(gen),
|
||||
];
|
||||
|
||||
(async () => {
|
||||
// Call `return` after stepping the iterator once:
|
||||
for (const method of methods) {
|
||||
const iter = new TestIterator();
|
||||
const iterHelper = method(iter);
|
||||
|
||||
await iterHelper.next();
|
||||
assert.sameValue(iter.closeCount, 0);
|
||||
await iterHelper.return();
|
||||
assert.sameValue(iter.closeCount, 1);
|
||||
await iterHelper.return();
|
||||
assert.sameValue(iter.closeCount, 1);
|
||||
}
|
||||
|
||||
// Call `return` before stepping the iterator:
|
||||
for (const method of methods) {
|
||||
const iter = new TestIterator();
|
||||
const iterHelper = method(iter);
|
||||
|
||||
assert.sameValue(iter.closeCount, 0);
|
||||
await iterHelper.return();
|
||||
assert.sameValue(iter.closeCount, 1);
|
||||
await iterHelper.return();
|
||||
assert.sameValue(iter.closeCount, 1);
|
||||
}
|
||||
})();
|
||||
|
@ -1,95 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
Calling `throw` on a lazy %AsyncIterator.prototype% method multiple times closes the source iterator once.
|
||||
info: |
|
||||
Iterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class TestError extends Error {}
|
||||
|
||||
class TestIterator extends AsyncIterator {
|
||||
async next() {
|
||||
return {done: false, value: 1};
|
||||
}
|
||||
|
||||
closeCount = 0;
|
||||
async return(value) {
|
||||
this.closeCount++;
|
||||
return {done: true, value};
|
||||
}
|
||||
}
|
||||
|
||||
async function* gen(x) { yield x; }
|
||||
|
||||
const methods = [
|
||||
iter => iter.map(x => x),
|
||||
iter => iter.filter(x => true),
|
||||
iter => iter.take(Infinity),
|
||||
iter => iter.drop(0),
|
||||
iter => iter.asIndexedPairs(),
|
||||
iter => iter.flatMap(gen),
|
||||
];
|
||||
|
||||
(async () => {
|
||||
// Call `throw` after stepping the iterator once:
|
||||
for (const method of methods) {
|
||||
const iter = new TestIterator();
|
||||
const iterHelper = method(iter);
|
||||
|
||||
await iterHelper.next()
|
||||
assert.sameValue(iter.closeCount, 0);
|
||||
|
||||
try {
|
||||
await iterHelper.throw(new TestError());
|
||||
assert.sameValue(true, false, 'Expected reject');
|
||||
} catch (exc) {
|
||||
assert.sameValue(exc instanceof TestError, true);
|
||||
}
|
||||
assert.sameValue(iter.closeCount, 1);
|
||||
|
||||
try {
|
||||
await iterHelper.throw(new TestError());
|
||||
assert.sameValue(true, false, 'Expected reject');
|
||||
} catch (exc) {
|
||||
assert.sameValue(exc instanceof TestError, true);
|
||||
}
|
||||
assert.sameValue(iter.closeCount, 1);
|
||||
}
|
||||
|
||||
// Call `throw` before stepping the iterator:
|
||||
for (const method of methods) {
|
||||
const iter = new TestIterator();
|
||||
const iterHelper = method(iter);
|
||||
|
||||
assert.sameValue(iter.closeCount, 0);
|
||||
|
||||
try {
|
||||
await iterHelper.throw(new TestError());
|
||||
assert.sameValue(true, false, 'Expected reject');
|
||||
} catch (exc) {
|
||||
assert.sameValue(exc instanceof TestError, true);
|
||||
}
|
||||
assert.sameValue(iter.closeCount, 1);
|
||||
|
||||
try {
|
||||
await iterHelper.throw(new TestError());
|
||||
assert.sameValue(true, false, 'Expected reject');
|
||||
} catch (exc) {
|
||||
assert.sameValue(exc instanceof TestError, true);
|
||||
}
|
||||
assert.sameValue(iter.closeCount, 1);
|
||||
}
|
||||
})();
|
||||
|
@ -1,54 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
%AsyncIterator.prototype% methods ignore iterator mutation if already done.
|
||||
info: |
|
||||
Iterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
//
|
||||
//
|
||||
|
||||
class TestIterator extends AsyncIterator {
|
||||
values = [1, 2];
|
||||
async next() {
|
||||
if (this.values.length == 0)
|
||||
return {done: true};
|
||||
return {done: false, value: this.values.shift()};
|
||||
}
|
||||
}
|
||||
|
||||
function check({done, value}, expectedDone, expectedValue) {
|
||||
assert.sameValue(done, expectedDone);
|
||||
assert.sameValue(Array.isArray(value) ? value[1] : value, expectedValue);
|
||||
}
|
||||
|
||||
const methods = [
|
||||
['map', x => x],
|
||||
['filter', x => true],
|
||||
['take', Infinity],
|
||||
['drop', 0],
|
||||
['asIndexedPairs', undefined],
|
||||
['flatMap', async function*(x) { yield x; }],
|
||||
];
|
||||
|
||||
for (const [method, arg] of methods) {
|
||||
(async () => {
|
||||
const iter = new TestIterator();
|
||||
const iterHelper = iter[method](arg);
|
||||
check(await iterHelper.next(), false, 1);
|
||||
check(await iterHelper.next(), false, 2);
|
||||
check(await iterHelper.next(), true, undefined);
|
||||
iter.values.push(3);
|
||||
check(await iterHelper.next(), true, undefined);
|
||||
})();
|
||||
}
|
||||
|
@ -1,54 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
%AsyncIterator.prototype% methods work properly if the iterator has been mutated.
|
||||
info: |
|
||||
Iterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
//
|
||||
//
|
||||
|
||||
class TestIterator extends AsyncIterator {
|
||||
values = [1, 2];
|
||||
async next() {
|
||||
if (this.values.length == 0)
|
||||
return {done: true};
|
||||
return {done: false, value: this.values.shift()};
|
||||
}
|
||||
}
|
||||
|
||||
function check({done, value}, expectedDone, expectedValue) {
|
||||
assert.sameValue(done, expectedDone);
|
||||
assert.sameValue(Array.isArray(value) ? value[1] : value, expectedValue);
|
||||
}
|
||||
|
||||
const methods = [
|
||||
['map', x => x],
|
||||
['filter', x => true],
|
||||
['take', Infinity],
|
||||
['drop', 0],
|
||||
['asIndexedPairs', undefined],
|
||||
['flatMap', async function*(x) { yield x; }],
|
||||
];
|
||||
|
||||
for (const [method, arg] of methods) {
|
||||
(async () => {
|
||||
const iter = new TestIterator();
|
||||
const iterHelper = iter[method](arg);
|
||||
check(await iterHelper.next(), false, 1);
|
||||
check(await iterHelper.next(), false, 2);
|
||||
iter.values.push(3);
|
||||
check(await iterHelper.next(), false, 3);
|
||||
check(await iterHelper.next(), true, undefined);
|
||||
})();
|
||||
}
|
||||
|
@ -1,53 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
Lazy %AsyncIterator.prototype% methods don't close the iterator if `next` returns rejected promise.
|
||||
info: |
|
||||
AsyncIterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class TestIterator extends AsyncIterator {
|
||||
next() {
|
||||
return Promise.reject('rejection');
|
||||
}
|
||||
|
||||
closed = false;
|
||||
async return(value) {
|
||||
this.closed = true;
|
||||
return {done: true, value};
|
||||
}
|
||||
}
|
||||
|
||||
async function* gen(x) { yield x; }
|
||||
const methods = [
|
||||
iter => iter.map(x => x),
|
||||
iter => iter.filter(x => x),
|
||||
iter => iter.take(1),
|
||||
iter => iter.drop(0),
|
||||
iter => iter.asIndexedPairs(),
|
||||
iter => iter.flatMap(gen),
|
||||
];
|
||||
|
||||
for (const method of methods) {
|
||||
const iterator = new TestIterator();
|
||||
assert.sameValue(iterator.closed, false);
|
||||
method(iterator).next().then(
|
||||
_ => assert.sameValue(true, false, 'Expected reject'),
|
||||
err => {
|
||||
assert.sameValue(err, 'rejection');
|
||||
assert.sameValue(iterator.closed, false);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -1,42 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
class TestAsyncIterator extends AsyncIterator {
|
||||
async next(value) {
|
||||
return {done: false, value};
|
||||
}
|
||||
}
|
||||
|
||||
const methods = [
|
||||
iter => iter.map(x => x),
|
||||
iter => iter.filter(x => true),
|
||||
iter => iter.take(2),
|
||||
iter => iter.drop(0),
|
||||
iter => iter.asIndexedPairs(),
|
||||
];
|
||||
|
||||
for (const method of methods) {
|
||||
const iterator = new TestAsyncIterator();
|
||||
const iteratorHelper = method(iterator);
|
||||
iteratorHelper.next().then(
|
||||
_ => iteratorHelper.next('last value').then(
|
||||
({done, value}) => {
|
||||
assert.sameValue(done, false);
|
||||
// Unwrap the return value from asIndexedPairs.
|
||||
assert.sameValue(Array.isArray(value) ? value[1] : value, 'last value');
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -1,47 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
features:
|
||||
- async-iteration
|
||||
description: |
|
||||
pending
|
||||
esid: pending
|
||||
---*/
|
||||
|
||||
class TestAsyncIterator extends AsyncIterator {
|
||||
async next(value) {
|
||||
return {done: false, value};
|
||||
}
|
||||
}
|
||||
|
||||
const methods = [
|
||||
iter => iter.map(x => x),
|
||||
iter => iter.filter(x => true),
|
||||
iter => iter.take(2),
|
||||
iter => iter.drop(0),
|
||||
iter => iter.asIndexedPairs(),
|
||||
];
|
||||
|
||||
for (const outerMethod of methods) {
|
||||
for (const innerMethod of methods) {
|
||||
const iterator = new TestAsyncIterator();
|
||||
const iteratorChain = outerMethod(innerMethod(iterator));
|
||||
iteratorChain.next().then(
|
||||
_ => iteratorChain.next('last value').then(
|
||||
({done, value}) => {
|
||||
assert.sameValue(done, false);
|
||||
// Unwrap the asIndexedPair return values.
|
||||
while (Array.isArray(value)) {
|
||||
value = value[1];
|
||||
}
|
||||
assert.sameValue(value, 'last value');
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,73 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
Lazy %AsyncIterator.prototype% methods access specified properties only.
|
||||
info: |
|
||||
Iterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
//
|
||||
|
||||
let log;
|
||||
const handlerProxy = new Proxy({}, {
|
||||
get: (target, key, receiver) => (...args) => {
|
||||
log.push(`${key}: ${args.filter(x => typeof x != 'object').map(x => x.toString())}`);
|
||||
return Reflect[key](...args);
|
||||
},
|
||||
});
|
||||
|
||||
class TestIterator extends AsyncIterator {
|
||||
value = 0;
|
||||
async next() {
|
||||
if (this.value < 1)
|
||||
return new Proxy({done: false, value: this.value++}, handlerProxy);
|
||||
return new Proxy({done: true, value: undefined}, handlerProxy);
|
||||
}
|
||||
}
|
||||
|
||||
const methods = [
|
||||
['map', x => x],
|
||||
['filter', x => true],
|
||||
['take', 4],
|
||||
['drop', 0],
|
||||
['asIndexedPairs', undefined],
|
||||
['flatMap', async function*(x) { yield x; }],
|
||||
];
|
||||
|
||||
(async () => {
|
||||
for (const [method, argument] of methods) {
|
||||
log = [];
|
||||
const iteratorProxy = new Proxy(new TestIterator(), handlerProxy);
|
||||
const iteratorHelper = iteratorProxy[method](argument);
|
||||
|
||||
await iteratorHelper.next();
|
||||
await iteratorHelper.next();
|
||||
const {done} = await iteratorHelper.next();
|
||||
assert.sameValue(done, true);
|
||||
assert.sameValue(
|
||||
log.join('\n'),
|
||||
`get: ${method}
|
||||
get: next
|
||||
get: value
|
||||
get: value
|
||||
set: value,1
|
||||
getOwnPropertyDescriptor: value
|
||||
defineProperty: value
|
||||
get: then
|
||||
get: done
|
||||
get: value
|
||||
get: value
|
||||
get: then
|
||||
get: done`
|
||||
);
|
||||
}
|
||||
})();
|
||||
|
@ -1,68 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
Calling `return` on a lazy %AsyncIterator.prototype% method closes the source iterator.
|
||||
info: |
|
||||
Iterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
class TestIterator extends AsyncIterator {
|
||||
async next() {
|
||||
return {done: false, value: 1};
|
||||
}
|
||||
|
||||
closed = false;
|
||||
async return(value) {
|
||||
this.closed = true;
|
||||
return {done: true, value};
|
||||
}
|
||||
}
|
||||
|
||||
async function* gen(x) { yield x; }
|
||||
|
||||
const methods = [
|
||||
iter => iter.map(x => x),
|
||||
iter => iter.filter(x => x),
|
||||
iter => iter.take(1),
|
||||
iter => iter.drop(0),
|
||||
iter => iter.asIndexedPairs(),
|
||||
iter => iter.flatMap(gen),
|
||||
];
|
||||
|
||||
for (const method of methods) {
|
||||
const iter = new TestIterator();
|
||||
const iterHelper = method(iter);
|
||||
|
||||
iterHelper.next().then(() => {
|
||||
assert.sameValue(iter.closed, false);
|
||||
iterHelper.return(0).then(({done, value}) => {
|
||||
assert.sameValue(iter.closed, true);
|
||||
assert.sameValue(done, true);
|
||||
assert.sameValue(value, 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
for (const method of methods) {
|
||||
const iter = new TestIterator();
|
||||
const iterHelper = method(iter);
|
||||
|
||||
assert.sameValue(iter.closed, false);
|
||||
iterHelper.return(0).then(({done, value}) => {
|
||||
assert.sameValue(iter.closed, true);
|
||||
assert.sameValue(done, true);
|
||||
assert.sameValue(value, 0);
|
||||
});
|
||||
}
|
||||
|
@ -1,47 +0,0 @@
|
||||
// Copyright (C) 2024 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
Lazy Iterator Helper methods return new iterator result objects.
|
||||
info: |
|
||||
Iterator Helpers proposal 2.1.6
|
||||
features:
|
||||
- async-iteration
|
||||
- iterator-helpers
|
||||
includes: [sm/non262-shell.js, sm/non262.js]
|
||||
flags:
|
||||
- noStrict
|
||||
---*/
|
||||
|
||||
//
|
||||
//
|
||||
const iterResult = {done: false, value: 1, testProperty: 'test'};
|
||||
class TestIterator extends AsyncIterator {
|
||||
async next() {
|
||||
return iterResult;
|
||||
}
|
||||
}
|
||||
|
||||
async function* gen(x) { yield x; }
|
||||
|
||||
const methods = [
|
||||
iter => iter.map(x => x),
|
||||
iter => iter.filter(x => true),
|
||||
iter => iter.take(1),
|
||||
iter => iter.drop(0),
|
||||
iter => iter.asIndexedPairs(),
|
||||
iter => iter.flatMap(gen),
|
||||
];
|
||||
|
||||
// Call `return` before stepping the iterator:
|
||||
for (const method of methods) {
|
||||
const iter = new TestIterator();
|
||||
const iterHelper = method(iter);
|
||||
iterHelper.next().then(result => {
|
||||
assert.sameValue(result == iterResult, false);
|
||||
assert.sameValue(result.testProperty, undefined);
|
||||
});
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user