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

Revert stream primordials #37168

Closed
wants to merge 2 commits into from
Closed
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
16 changes: 6 additions & 10 deletions lib/internal/streams/buffer_list.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';

const {
StringPrototypeSlice,
SymbolIterator,
TypedArrayPrototypeSet,
Uint8Array,
} = primordials;

Expand Down Expand Up @@ -69,7 +67,7 @@ module.exports = class BufferList {
let p = this.head;
let i = 0;
while (p) {
TypedArrayPrototypeSet(ret, p.data, i);
ret.set(p.data, i);
i += p.data.length;
p = p.next;
}
Expand Down Expand Up @@ -122,9 +120,9 @@ module.exports = class BufferList {
else
this.head = this.tail = null;
} else {
ret += StringPrototypeSlice(str, 0, n);
ret += str.slice(0, n);
this.head = p;
p.data = StringPrototypeSlice(str, n);
p.data = str.slice(n);
}
break;
}
Expand All @@ -143,20 +141,18 @@ module.exports = class BufferList {
do {
const buf = p.data;
if (n > buf.length) {
TypedArrayPrototypeSet(ret, buf, retLen - n);
ret.set(buf, retLen - n);
n -= buf.length;
} else {
if (n === buf.length) {
TypedArrayPrototypeSet(ret, buf, retLen - n);
ret.set(buf, retLen - n);
++c;
if (p.next)
this.head = p.next;
else
this.head = this.tail = null;
} else {
TypedArrayPrototypeSet(ret,
new Uint8Array(buf.buffer, buf.byteOffset, n),
retLen - n);
ret.set(new Uint8Array(buf.buffer, buf.byteOffset, n), retLen - n);
this.head = p;
p.data = buf.slice(n);
}
Expand Down
11 changes: 3 additions & 8 deletions lib/internal/streams/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
const {
ERR_MULTIPLE_CALLBACK
} = require('internal/errors').codes;
const {
FunctionPrototypeCall,
Symbol,
} = primordials;
const { Symbol } = primordials;

const kDestroy = Symbol('kDestroy');
const kConstruct = Symbol('kConstruct');
Expand Down Expand Up @@ -96,8 +93,7 @@ function _destroy(self, err, cb) {
try {
const then = result.then;
if (typeof then === 'function') {
FunctionPrototypeCall(
then,
then.call(
result,
function() {
if (called)
Expand Down Expand Up @@ -315,8 +311,7 @@ function constructNT(stream) {
try {
const then = result.then;
if (typeof then === 'function') {
FunctionPrototypeCall(
then,
then.call(
result,
function() {
// If the callback was invoked, do nothing further.
Expand Down
20 changes: 7 additions & 13 deletions lib/internal/streams/end-of-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

'use strict';

const {
FunctionPrototype,
FunctionPrototypeCall,
} = primordials;
const {
ERR_STREAM_PREMATURE_CLOSE
} = require('internal/errors').codes;
Expand Down Expand Up @@ -57,7 +53,7 @@ function isWritableFinished(stream) {
return wState.finished || (wState.ended && wState.length === 0);
}

const nop = FunctionPrototype;
function nop() {}

function isReadableEnded(stream) {
if (stream.readableEnded) return true;
Expand Down Expand Up @@ -114,7 +110,7 @@ function eos(stream, options, callback) {
if (stream.destroyed) willEmitClose = false;

if (willEmitClose && (!stream.readable || readable)) return;
if (!readable || readableEnded) FunctionPrototypeCall(callback, stream);
if (!readable || readableEnded) callback.call(stream);
};

let readableEnded = stream.readableEnded ||
Expand All @@ -127,25 +123,23 @@ function eos(stream, options, callback) {
if (stream.destroyed) willEmitClose = false;

if (willEmitClose && (!stream.writable || writable)) return;
if (!writable || writableFinished) FunctionPrototypeCall(callback, stream);
if (!writable || writableFinished) callback.call(stream);
};

const onerror = (err) => {
FunctionPrototypeCall(callback, stream, err);
callback.call(stream, err);
};

const onclose = () => {
if (readable && !readableEnded) {
if (!isReadableEnded(stream))
return FunctionPrototypeCall(callback, stream,
new ERR_STREAM_PREMATURE_CLOSE());
return callback.call(stream, new ERR_STREAM_PREMATURE_CLOSE());
}
if (writable && !writableFinished) {
if (!isWritableFinished(stream))
return FunctionPrototypeCall(callback, stream,
new ERR_STREAM_PREMATURE_CLOSE());
return callback.call(stream, new ERR_STREAM_PREMATURE_CLOSE());
}
FunctionPrototypeCall(callback, stream);
callback.call(stream);
};

const onrequest = () => {
Expand Down
4 changes: 1 addition & 3 deletions lib/internal/streams/from.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const {
PromisePrototypeThen,
SymbolAsyncIterator,
SymbolIterator
} = primordials;
Expand Down Expand Up @@ -56,8 +55,7 @@ function from(Readable, iterable, opts) {
readable._destroy = function(error, cb) {
if (needToClose) {
needToClose = false;
PromisePrototypeThen(
close(),
close().then(
() => process.nextTick(cb, error),
(e) => process.nextTick(cb, error || e),
);
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/streams/lazy_transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
'use strict';

const {
FunctionPrototypeCall,
ObjectDefineProperties,
ObjectDefineProperty,
ObjectSetPrototypeOf,
Expand All @@ -26,7 +25,7 @@ ObjectSetPrototypeOf(LazyTransform, stream.Transform);

function makeGetter(name) {
return function() {
FunctionPrototypeCall(stream.Transform, this, this._options);
stream.Transform.call(this, this._options);
this._writableState.decodeStrings = false;

if (!this._options || !this._options.defaultEncoding) {
Expand Down
6 changes: 2 additions & 4 deletions lib/internal/streams/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

const {
ArrayIsArray,
ArrayPrototypeUnshift,
FunctionPrototypeCall,
ObjectSetPrototypeOf,
} = primordials;

const EE = require('events');

function Stream(opts) {
FunctionPrototypeCall(EE, this, opts);
EE.call(this, opts);
}
ObjectSetPrototypeOf(Stream.prototype, EE.prototype);
ObjectSetPrototypeOf(Stream, EE);
Expand Down Expand Up @@ -108,7 +106,7 @@ function prependListener(emitter, event, fn) {
if (!emitter._events || !emitter._events[event])
emitter.on(event, fn);
else if (ArrayIsArray(emitter._events[event]))
ArrayPrototypeUnshift(emitter._events[event], fn);
emitter._events[event].unshift(fn);
else
emitter._events[event] = [fn, emitter._events[event]];
}
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/streams/passthrough.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
'use strict';

const {
FunctionPrototypeCall,
ObjectSetPrototypeOf,
} = primordials;

Expand All @@ -40,7 +39,7 @@ function PassThrough(options) {
if (!(this instanceof PassThrough))
return new PassThrough(options);

FunctionPrototypeCall(Transform, this, options);
Transform.call(this, options);
}

PassThrough.prototype._transform = function(chunk, encoding, cb) {
Expand Down
14 changes: 5 additions & 9 deletions lib/internal/streams/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

const {
ArrayIsArray,
ArrayPrototypePop,
ArrayPrototypePush,
ArrayPrototypeShift,
FunctionPrototypeCall,
ReflectApply,
SymbolAsyncIterator,
SymbolIterator,
Expand Down Expand Up @@ -79,7 +75,7 @@ function popCallback(streams) {
// a single stream. Therefore optimize for the average case instead of
// checking for length === 0 as well.
validateCallback(streams[streams.length - 1]);
return ArrayPrototypePop(streams);
return streams.pop();
}

function isReadable(obj) {
Expand Down Expand Up @@ -118,7 +114,7 @@ async function* fromReadable(val) {
Readable = require('internal/streams/readable');
}

yield* FunctionPrototypeCall(Readable.prototype[SymbolAsyncIterator], val);
yield* Readable.prototype[SymbolAsyncIterator].call(val);
}

async function pump(iterable, writable, finish) {
Expand Down Expand Up @@ -175,7 +171,7 @@ function pipeline(...streams) {
}

while (destroys.length) {
ArrayPrototypeShift(destroys)(error);
destroys.shift()(error);
}

if (final) {
Expand All @@ -191,7 +187,7 @@ function pipeline(...streams) {

if (isStream(stream)) {
finishCount++;
ArrayPrototypePush(destroys, destroyer(stream, reading, writing, finish));
destroys.push(destroyer(stream, reading, writing, finish));
}

if (i === 0) {
Expand Down Expand Up @@ -254,7 +250,7 @@ function pipeline(...streams) {
ret = pt;

finishCount++;
ArrayPrototypePush(destroys, destroyer(ret, false, true, finish));
destroys.push(destroyer(ret, false, true, finish));
}
} else if (isStream(stream)) {
if (isReadable(ret)) {
Expand Down
Loading