Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: port more test262 tests #41974

Merged
merged 1 commit into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/internal/streams/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ function asIndexedPairs(options = undefined) {
}.call(this);
}

async function some(fn, options) {
async function some(fn, options = undefined) {
// eslint-disable-next-line no-unused-vars
for await (const unused of filter.call(this, fn, options)) {
return true;
}
return false;
}

async function every(fn, options) {
async function every(fn, options = undefined) {
if (typeof fn !== 'function') {
throw new ERR_INVALID_ARG_TYPE(
'fn', ['Function', 'AsyncFunction'], fn);
Expand Down
7 changes: 5 additions & 2 deletions lib/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ for (const key of ObjectKeys(streamReturningOperators)) {
value: fn,
enumerable: false,
configurable: true,
writable: false,
writable: true,
});
}
for (const key of ObjectKeys(promiseReturningOperators)) {
const op = promiseReturningOperators[key];
function fn(...args) {
if (new.target) {
throw ERR_ILLEGAL_CONSTRUCTOR();
}
return ReflectApply(op, this, args);
}
ObjectDefineProperty(fn, 'name', { value: op.name });
Expand All @@ -83,7 +86,7 @@ for (const key of ObjectKeys(promiseReturningOperators)) {
value: fn,
enumerable: false,
configurable: true,
writable: false,
writable: true,
});
}
Stream.Writable = require('internal/streams/writable');
Expand Down
59 changes: 56 additions & 3 deletions test/parallel/test-stream-iterator-helpers-test262-tests.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../common/index.mjs';
import { mustCall } from '../common/index.mjs';
import { Readable } from 'stream';
import assert from 'assert';

Expand Down Expand Up @@ -68,7 +68,7 @@ import assert from 'assert';
);
assert.strictEqual(descriptor.enumerable, false);
assert.strictEqual(descriptor.configurable, true);
assert.strictEqual(descriptor.writable, false);
assert.strictEqual(descriptor.writable, true);
}
{
// drop/length
Expand All @@ -79,7 +79,7 @@ import assert from 'assert';
);
assert.strictEqual(descriptor.enumerable, false);
assert.strictEqual(descriptor.configurable, true);
assert.strictEqual(descriptor.writable, false);
assert.strictEqual(descriptor.writable, true);
// drop/limit-equals-total
const iterator = Readable.from([1, 2]).drop(2);
const result = await iterator[Symbol.asyncIterator]().next();
Expand Down Expand Up @@ -111,5 +111,58 @@ import assert from 'assert';
// drop/proto
const proto = Object.getPrototypeOf(Readable.prototype.drop);
assert.strictEqual(proto, Function.prototype);
}
{
// every/abrupt-iterator-close
const stream = Readable.from([1, 2, 3]);
const e = new Error();
await assert.rejects(stream.every(mustCall(() => {
throw e;
}, 1)), e);
}
{
// every/callable-fn
await assert.rejects(Readable.from([1, 2]).every({}), TypeError);
}
{
// every/callable
Readable.prototype.every.call(Readable.from([]), () => {});
// eslint-disable-next-line array-callback-return
Readable.from([]).every(() => {});
assert.throws(() => {
const r = Readable.from([]);
new r.every(() => {});
}, TypeError);
}

{
// every/false
const iterator = Readable.from([1, 2, 3]);
const result = await iterator.every((v) => v === 1);
assert.strictEqual(result, false);
}
{
// every/every
const iterator = Readable.from([1, 2, 3]);
const result = await iterator.every((v) => true);
assert.strictEqual(result, true);
}

{
// every/is-function
assert.strictEqual(typeof Readable.prototype.every, 'function');
}
{
// every/length
assert.strictEqual(Readable.prototype.every.length, 1);
// every/name
assert.strictEqual(Readable.prototype.every.name, 'every');
// every/propdesc
const descriptor = Object.getOwnPropertyDescriptor(
Readable.prototype,
'every'
);
assert.strictEqual(descriptor.enumerable, false);
assert.strictEqual(descriptor.configurable, true);
assert.strictEqual(descriptor.writable, true);
}