From 93019be80ea5edbfa5062a7d2fc6c58a42c453fc Mon Sep 17 00:00:00 2001 From: pbb Date: Thu, 25 Feb 2021 17:26:07 +0100 Subject: [PATCH 1/2] fix: manage object type on format --- index.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 24c2d90..2b985eb 100644 --- a/index.js +++ b/index.js @@ -88,7 +88,10 @@ TransportStream.prototype._write = function _write(info, enc, callback) { // We trap(and re-throw) any errors generated by the user-provided format, but also // guarantee that the streams callback is invoked so that we can continue flowing. try { - transformed = this.format.transform(Object.assign({}, info), this.format.options); + transformed = this.format.transform( + cloneObj(info), + this.format.options + ); } catch (err) { errState = err; } @@ -142,7 +145,7 @@ TransportStream.prototype._writev = function _writev(chunks, callback) { // guarantee that the streams callback is invoked so that we can continue flowing. try { transformed = this.format.transform( - Object.assign({}, chunks[i].chunk), + cloneObj(chunks[i].chunk), this.format.options ); } catch (err) { @@ -201,6 +204,18 @@ TransportStream.prototype._accept = function _accept(write) { return false; }; +function cloneObj(obj) { + const clonedObj = {}; + + Object.getOwnPropertyNames(obj).forEach((propName) => { + Object.defineProperty(clonedObj, propName, Object.getOwnPropertyDescriptor(obj, propName)); + }); + + Object.setPrototypeOf(clonedObj, Object.getPrototypeOf(obj)); + + return clonedObj; +} + /** * _nop is short for "No operation" * @returns {Boolean} Intentionally false. From 357aa2336dcfb060cd4b4ec27dd1b06bc77718b0 Mon Sep 17 00:00:00 2001 From: pbb Date: Thu, 25 Feb 2021 18:09:23 +0100 Subject: [PATCH 2/2] fix: copy symbol --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 2b985eb..bca6854 100644 --- a/index.js +++ b/index.js @@ -207,7 +207,7 @@ TransportStream.prototype._accept = function _accept(write) { function cloneObj(obj) { const clonedObj = {}; - Object.getOwnPropertyNames(obj).forEach((propName) => { + Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertySymbols(obj)).forEach((propName) => { Object.defineProperty(clonedObj, propName, Object.getOwnPropertyDescriptor(obj, propName)); });