| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f08b83b commit a48edf4
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1332,7 +1332,7 @@ Readable.prototype.wrap = function(stream) { | |||
| 1332 | 1332 | ||
| 1333 | 1333 | // Proxy all the other methods. Important when wrapping filters and duplexes. | |
| 1334 | 1334 | const streamKeys = ObjectKeys(stream); | |
| 1335 | - for (let j = 1; j < streamKeys.length; j++) { | ||
| 1335 | + for (let j = 0; j < streamKeys.length; j++) { | ||
| 1336 | 1336 | const i = streamKeys[j]; | |
| 1337 | 1337 | if (this[i] === undefined && typeof stream[i] === 'function') { | |
| 1338 | 1338 | this[i] = stream[i].bind(stream); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,40 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const { Readable } = require('stream'); | ||
| 5 | + | ||
| 6 | + // Readable.prototype.wrap() proxies the methods of the wrapped old-style | ||
| 7 | + // stream onto the new Readable. Regression test for an off-by-one that made | ||
| 8 | + // the proxy loop start at index 1, silently skipping the first own-enumerable | ||
| 9 | + // key returned by Object.keys() — so a method happening to sit at that first | ||
| 10 | + // position was never proxied. | ||
| 11 | + | ||
| 12 | + // A minimal old-style stream whose *first* own-enumerable key is a method. | ||
| 13 | + // `Object.keys()` preserves insertion order for string keys, so `firstMethod` | ||
| 14 | + // is `streamKeys[0]` — exactly the slot the bug skipped. | ||
| 15 | + const source = { | ||
| 16 | + firstMethod() { return `first:${this === source}`; }, | ||
| 17 | + secondMethod() { return `second:${this === source}`; }, | ||
| 18 | + on() { return this; }, | ||
| 19 | + pause() {}, | ||
| 20 | + resume() {}, | ||
| 21 | + }; | ||
| 22 | + | ||
| 23 | + assert.strictEqual(Object.keys(source)[0], 'firstMethod'); | ||
| 24 | + | ||
| 25 | + const wrapped = new Readable().wrap(source); | ||
| 26 | + | ||
| 27 | + // The method at the first key must be proxied (was `undefined` before the fix). | ||
| 28 | + assert.strictEqual(typeof wrapped.firstMethod, 'function'); | ||
| 29 | + assert.strictEqual(typeof wrapped.secondMethod, 'function'); | ||
| 30 | + | ||
| 31 | + // Proxied methods stay bound to the original stream. | ||
| 32 | + assert.strictEqual(wrapped.firstMethod(), 'first:true'); | ||
| 33 | + assert.strictEqual(wrapped.secondMethod(), 'second:true'); | ||
| 34 | + | ||
| 35 | + // Existing Readable methods must not be clobbered by the proxying. | ||
| 36 | + assert.strictEqual(wrapped.pause, Readable.prototype.pause); | ||
| 37 | + assert.strictEqual(wrapped.resume, Readable.prototype.resume); | ||
| 38 | + | ||
| 39 | + wrapped.on('end', common.mustNotCall()); | ||
| 40 | + wrapped.destroy(); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments