Skip to content

Commit

Permalink
Rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Dec 31, 2024
1 parent 567da2e commit 563e161
Show file tree
Hide file tree
Showing 21 changed files with 330 additions and 293 deletions.
8 changes: 5 additions & 3 deletions lib/internal/streams/end-of-stream.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Ported from /~https://github.com/mafintosh/end-of-stream with
// permission from the author, Mathias Buus (@mafintosh).

'use strict'

/* replacement start */

const process = require('process/')

/* replacement end */
// Ported from /~https://github.com/mafintosh/end-of-stream with
// permission from the author, Mathias Buus (@mafintosh).

;('use strict')
const { AbortError, codes } = require('../../ours/errors')
const { ERR_INVALID_ARG_TYPE, ERR_STREAM_PREMATURE_CLOSE } = codes
const { kEmptyObject, once } = require('../../ours/util')
Expand Down
14 changes: 8 additions & 6 deletions lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* replacement start */

const process = require('process/')

/* replacement end */
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
Expand All @@ -24,7 +19,14 @@ const process = require('process/')
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

;('use strict')
'use strict'

/* replacement start */

const process = require('process/')

/* replacement end */

const {
ArrayPrototypeIndexOf,
NumberIsInteger,
Expand Down
2 changes: 0 additions & 2 deletions lib/internal/streams/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function isReadableNodeStream(obj, strict = false) {
) // Writable has .pipe.
)
}

function isWritableNodeStream(obj) {
var _obj$_writableState
return !!(
Expand All @@ -45,7 +44,6 @@ function isWritableNodeStream(obj) {
) // Duplex
)
}

function isDuplexNodeStream(obj) {
return !!(
obj &&
Expand Down
14 changes: 8 additions & 6 deletions lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* replacement start */

const process = require('process/')

/* replacement end */
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
Expand All @@ -28,7 +23,14 @@ const process = require('process/')
// Implement an async ._write(chunk, encoding, cb), and it'll handle all
// the drain event emission and buffering.

;('use strict')
'use strict'

/* replacement start */

const process = require('process/')

/* replacement end */

const {
ArrayPrototypeSlice,
Error,
Expand Down
3 changes: 2 additions & 1 deletion lib/ours/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ E(
received = addNumericalSeparator(String(input))
} else if (typeof input === 'bigint') {
received = String(input)
if (input > 2n ** 32n || input < -(2n ** 32n)) {
const limit = BigInt(2) ** BigInt(32)
if (input > limit || input < -limit) {
received = addNumericalSeparator(received)
}
received += 'n'
Expand Down
2 changes: 1 addition & 1 deletion lib/ours/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ module.exports = {
TypedArrayPrototypeSet(self, buf, len) {
return self.set(buf, len)
},
Boolean: Boolean,
Boolean,
Uint8Array
}
7 changes: 6 additions & 1 deletion lib/ours/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict'

const bufferModule = require('buffer')
const {
codes: { ERR_INVALID_ARG_TYPE }
} = require('./errors')
const { kResistStopPropagation, SymbolDispose } = require('./primordials')
const AbortSignal = globalThis.AbortSignal || require('abort-controller').AbortSignal
const AbortController = globalThis.AbortController || require('abort-controller').AbortController
Expand All @@ -24,7 +27,9 @@ const validateAbortSignal = (signal, name) => {
}
}
const validateFunction = (value, name) => {
if (typeof value !== 'function') throw new ERR_INVALID_ARG_TYPE(name, 'Function', value)
if (typeof value !== 'function') {
throw new ERR_INVALID_ARG_TYPE(name, 'Function', value)
}
}

// This is a simplified version of AggregateError
Expand Down
14 changes: 8 additions & 6 deletions lib/stream.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* replacement start */

const { Buffer } = require('buffer')

/* replacement end */
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
Expand All @@ -24,7 +19,14 @@ const { Buffer } = require('buffer')
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

;('use strict')
'use strict'

/* replacement start */

const { Buffer } = require('buffer')

/* replacement end */

const { ObjectDefineProperty, ObjectKeys, ReflectApply } = require('./ours/primordials')
const {
promisify: { custom: customPromisify }
Expand Down
1 change: 0 additions & 1 deletion test/browser/test-stream2-readable-wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ module.exports = function (test) {
old.emit('data', item)
// console.log('after emit', chunks, flowing);
}

if (chunks <= 0) {
oldEnded = true
// console.log('old end', chunks, flowing);
Expand Down
18 changes: 3 additions & 15 deletions test/common/fixtures.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
import fixtures from './fixtures.js';
import fixtures from './fixtures.js'

const {
fixturesDir,
path,
fileURL,
readSync,
readKey,
} = fixtures;
const { fixturesDir, path, fileURL, readSync, readKey } = fixtures

export {
fixturesDir,
path,
fileURL,
readSync,
readKey,
};
export { fixturesDir, path, fileURL, readSync, readKey }
1 change: 0 additions & 1 deletion test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,6 @@ const common = {
get enoughTestMem() {
return require('os').totalmem() > 0x70000000 /* 1.75 Gb */
},

get hasFipsCrypto() {
return hasCrypto && require('crypto').getFips()
},
Expand Down
16 changes: 8 additions & 8 deletions test/common/index.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createRequire } from 'module';
import { createRequire } from 'module'

const require = createRequire(import.meta.url);
const common = require('./index.js');
const require = createRequire(import.meta.url)
const common = require('./index.js')

const {
allowGlobals,
Expand Down Expand Up @@ -50,10 +50,10 @@ const {
skipIfDumbTerminal,
skipIfEslintMissing,
skipIfInspectorDisabled,
spawnPromisified,
} = common;
spawnPromisified
} = common

const getPort = () => common.PORT;
const getPort = () => common.PORT

export {
allowGlobals,
Expand Down Expand Up @@ -104,5 +104,5 @@ export {
skipIfDumbTerminal,
skipIfEslintMissing,
skipIfInspectorDisabled,
spawnPromisified,
};
spawnPromisified
}
100 changes: 59 additions & 41 deletions test/parallel/test-stream-asIndexedPairs.mjs
Original file line number Diff line number Diff line change
@@ -1,64 +1,82 @@
import '../common/index.mjs';
import { Readable }from '../../lib/ours/index.js';
import { deepStrictEqual, rejects, throws } from 'assert';
import tap from 'tap';
import '../common/index.mjs'
import { Readable } from '../../lib/ours/index.js'
import { deepStrictEqual, rejects, throws } from 'assert'
import tap from 'tap'

{
// asIndexedPairs with a synchronous stream
const pairs = await Readable.from([1, 2, 3]).asIndexedPairs().toArray();
deepStrictEqual(pairs, [[0, 1], [1, 2], [2, 3]]);
const empty = await Readable.from([]).asIndexedPairs().toArray();
deepStrictEqual(empty, []);
const pairs = await Readable.from([1, 2, 3]).asIndexedPairs().toArray()
deepStrictEqual(pairs, [
[0, 1],
[1, 2],
[2, 3]
])
const empty = await Readable.from([]).asIndexedPairs().toArray()
deepStrictEqual(empty, [])
}

{
// asIndexedPairs works an asynchronous streams
const asyncFrom = (...args) => Readable.from(...args).map(async (x) => x);
const pairs = await asyncFrom([1, 2, 3]).asIndexedPairs().toArray();
deepStrictEqual(pairs, [[0, 1], [1, 2], [2, 3]]);
const empty = await asyncFrom([]).asIndexedPairs().toArray();
deepStrictEqual(empty, []);
const asyncFrom = (...args) => Readable.from(...args).map(async (x) => x)
const pairs = await asyncFrom([1, 2, 3]).asIndexedPairs().toArray()
deepStrictEqual(pairs, [
[0, 1],
[1, 2],
[2, 3]
])
const empty = await asyncFrom([]).asIndexedPairs().toArray()
deepStrictEqual(empty, [])
}

{
// Does not enumerate an infinite stream
const infinite = () => Readable.from(async function* () {
while (true) yield 1;
}());
const pairs = await infinite().asIndexedPairs().take(3).toArray();
deepStrictEqual(pairs, [[0, 1], [1, 1], [2, 1]]);
const empty = await infinite().asIndexedPairs().take(0).toArray();
deepStrictEqual(empty, []);
const infinite = () =>
Readable.from(
(async function* () {
while (true) yield 1
})()
)
const pairs = await infinite().asIndexedPairs().take(3).toArray()
deepStrictEqual(pairs, [
[0, 1],
[1, 1],
[2, 1]
])
const empty = await infinite().asIndexedPairs().take(0).toArray()
deepStrictEqual(empty, [])
}

{
// AbortSignal
await rejects(async () => {
const ac = new AbortController();
const { signal } = ac;
const p = Readable.from([1, 2, 3]).asIndexedPairs({ signal }).toArray();
ac.abort();
await p;
}, { name: 'AbortError' });
await rejects(
async () => {
const ac = new AbortController()
const { signal } = ac
const p = Readable.from([1, 2, 3]).asIndexedPairs({ signal }).toArray()
ac.abort()
await p
},
{ name: 'AbortError' }
)

await rejects(async () => {
const signal = AbortSignal.abort();
await Readable.from([1, 2, 3]).asIndexedPairs({ signal }).toArray();
}, /AbortError/);
const signal = AbortSignal.abort()
await Readable.from([1, 2, 3]).asIndexedPairs({ signal }).toArray()
}, /AbortError/)
}

{
// Error cases
throws(() => Readable.from([1]).asIndexedPairs(1), /ERR_INVALID_ARG_TYPE/);
throws(() => Readable.from([1]).asIndexedPairs({ signal: true }), /ERR_INVALID_ARG_TYPE/);
throws(() => Readable.from([1]).asIndexedPairs(1), /ERR_INVALID_ARG_TYPE/)
throws(() => Readable.from([1]).asIndexedPairs({ signal: true }), /ERR_INVALID_ARG_TYPE/)
}

/* replacement start */
process.on('beforeExit', (code) => {
if(code === 0) {
tap.pass('test succeeded');
} else {
tap.fail(`test failed - exited code ${code}`);
}
});
/* replacement end */
/* replacement start */
process.on('beforeExit', (code) => {
if (code === 0) {
tap.pass('test succeeded')
} else {
tap.fail(`test failed - exited code ${code}`)
}
})
/* replacement end */
Loading

0 comments on commit 563e161

Please sign in to comment.