diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2024-04-29 19:55:51 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-29 19:55:51 +0900 |
commit | 0b454056a8f65061717cdaf7d93f50a8ecf7e14b (patch) | |
tree | 80abb5659b68ce399205e128e2b8093fe4ad2de6 /ext/node/polyfills/internal/streams/destroy.mjs | |
parent | b8444066ea83433c8a3597407a9fb6b9e9e36085 (diff) |
refactor: remove dead code in node stream polyfill (#23597)
Diffstat (limited to 'ext/node/polyfills/internal/streams/destroy.mjs')
-rw-r--r-- | ext/node/polyfills/internal/streams/destroy.mjs | 140 |
1 files changed, 3 insertions, 137 deletions
diff --git a/ext/node/polyfills/internal/streams/destroy.mjs b/ext/node/polyfills/internal/streams/destroy.mjs index 74e6687db..06c4a2ed8 100644 --- a/ext/node/polyfills/internal/streams/destroy.mjs +++ b/ext/node/polyfills/internal/streams/destroy.mjs @@ -2,14 +2,10 @@ // Copyright Joyent and Node contributors. All rights reserved. MIT license. // deno-lint-ignore-file -import { - aggregateTwoErrors, - ERR_MULTIPLE_CALLBACK, -} from "ext:deno_node/internal/errors.ts"; +import { aggregateTwoErrors } from "ext:deno_node/internal/errors.ts"; import * as process from "ext:deno_node/_process/process.ts"; const kDestroy = Symbol("kDestroy"); -const kConstruct = Symbol("kConstruct"); function checkError(err, w, r) { if (err) { @@ -155,37 +151,6 @@ function emitErrorNT(self, err) { self.emit("error", err); } -function undestroy() { - const r = this._readableState; - const w = this._writableState; - - if (r) { - r.constructed = true; - r.closed = false; - r.closeEmitted = false; - r.destroyed = false; - r.errored = null; - r.errorEmitted = false; - r.reading = false; - r.ended = false; - r.endEmitted = false; - } - - if (w) { - w.constructed = true; - w.destroyed = false; - w.closed = false; - w.closeEmitted = false; - w.errored = null; - w.errorEmitted = false; - w.ended = false; - w.ending = false; - w.finalCalled = false; - w.prefinished = false; - w.finished = false; - } -} - function errorOrDestroy(stream, err, sync) { // We have tests that rely on errors being emitted // in the same tick, so changing this is semver major. @@ -220,104 +185,5 @@ function errorOrDestroy(stream, err, sync) { } } -function construct(stream, cb) { - if (typeof stream._construct !== "function") { - return; - } - - const r = stream._readableState; - const w = stream._writableState; - - if (r) { - r.constructed = false; - } - if (w) { - w.constructed = false; - } - - stream.once(kConstruct, cb); - - if (stream.listenerCount(kConstruct) > 1) { - // Duplex - return; - } - - process.nextTick(constructNT, stream); -} - -function constructNT(stream) { - let called = false; - - function onConstruct(err) { - if (called) { - errorOrDestroy(stream, err ?? new ERR_MULTIPLE_CALLBACK()); - return; - } - called = true; - - const r = stream._readableState; - const w = stream._writableState; - const s = w || r; - - if (r) { - r.constructed = true; - } - if (w) { - w.constructed = true; - } - - if (s.destroyed) { - stream.emit(kDestroy, err); - } else if (err) { - errorOrDestroy(stream, err, true); - } else { - process.nextTick(emitConstructNT, stream); - } - } - - try { - const result = stream._construct(onConstruct); - if (result != null) { - const then = result.then; - if (typeof then === "function") { - then.call( - result, - function () { - process.nextTick(onConstruct, null); - }, - function (err) { - process.nextTick(onConstruct, err); - }, - ); - } - } - } catch (err) { - onConstruct(err); - } -} - -function emitConstructNT(stream) { - stream.emit(kConstruct); -} - -function isRequest(stream) { - return stream && stream.setHeader && typeof stream.abort === "function"; -} - -// Normalize destroy for legacy. -function destroyer(stream, err) { - if (!stream) return; - if (isRequest(stream)) return stream.abort(); - if (isRequest(stream.req)) return stream.req.abort(); - if (typeof stream.destroy === "function") return stream.destroy(err); - if (typeof stream.close === "function") return stream.close(); -} - -export default { - construct, - destroyer, - destroy, - undestroy, - errorOrDestroy, -}; -export { construct, destroy, destroyer, errorOrDestroy, undestroy }; +export default { destroy, errorOrDestroy }; +export { destroy, errorOrDestroy }; |