From 0c79192a63688c25755bac1c94fac99127618a1a Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Wed, 21 Jan 2026 17:35:38 +0900 Subject: [PATCH 1/3] Add custom dispose to UseObject and update pipe-ipc Enhanced UseObject to accept a custom dispose function, improving resource management flexibility. Updated pipe-ipc.js to utilize this feature, preventing unintended disposal in repositionObject and ensuring correct stream handling. Bumped module version to 0.1.25. --- app.js | 19 +++++++++++-------- lib/pipe-ipc.js | 18 ++++++++++++------ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app.js b/app.js index ceee604..5e9a276 100644 --- a/app.js +++ b/app.js @@ -188,18 +188,21 @@ if (typeof CreateObject === "undefined") { } if (typeof UseObject === "undefined") { - var UseObject = function(progId, callback) { - var _dispose = function(obj) { - try { - obj.Close(); - } catch (e) { /* ignore */ } - }; + var UseObject = function(progId, callback, dispose) { + if (typeof dispose !== "function") { + dispose = function(obj) { + try { + obj.Close(); + } catch (e) { /* ignore */ } + }; + } var obj = CreateObject(progId); try { - return callback(obj); + return (typeof callback === "function" ? + callback(obj) : null); } finally { - _dispose(obj); + dispose(obj); obj = null; } } diff --git a/lib/pipe-ipc.js b/lib/pipe-ipc.js index 693c24a..40fbb88 100644 --- a/lib/pipe-ipc.js +++ b/lib/pipe-ipc.js @@ -161,18 +161,21 @@ function Converter() { this.repositionObject = function(stream, position) { position = (position !== "number" ? 0 : position); + + var _dispose = function() {}; // prevent dispose after repositionObject return UseObject("ADODB.Stream", function(newStream) { newStream.Type = adTypeBinary; newStream.Mode = adModeReadWrite; newStream.Open(); + stream.Position = position; stream.CopyTo(newStream); stream.Flush(); stream.Close(); + return newStream; - }); - + }, _dispose); }; } @@ -413,9 +416,12 @@ function PipeIPC() { stream.Charset = charset; stream.Open(); stream.WriteText(str); - stream = (new Converter()).repositionObject(stream, 3); - stream.SaveToFile(dst, adSaveCreateOverWrite); - stream.Close(); + + var newStream = (new Converter()).repositionObject(stream, 3); + newStream.SaveToFile(dst, adSaveCreateOverWrite); + newStream.Close(); + + // will be auto dispose by UseObject }); // Set a result @@ -565,7 +571,7 @@ exports.adSaveCreateNotExist = adSaveCreateNotExist; exports.adSaveCreateOverWrite = adSaveCreateOverWrite; exports.adModeReadWrite = adModeReadWrite; -exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.24"; +exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.25"; exports.AUTHOR = "gnh1201@catswords.re.kr"; exports.global = global; exports.require = require; From 3fbcd71bc5fe62d6e0f5f0d39875d56b49e6dc48 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Wed, 21 Jan 2026 17:44:17 +0900 Subject: [PATCH 2/3] Fix type checks and update version in pipe-ipc.js Corrects type checking for callback and position parameters in app.js and pipe-ipc.js, ensuring proper function behavior. Also updates the version string in pipe-ipc.js to 0.1.26. --- app.js | 7 +++++-- lib/pipe-ipc.js | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 5e9a276..c95b39b 100644 --- a/app.js +++ b/app.js @@ -189,6 +189,10 @@ if (typeof CreateObject === "undefined") { if (typeof UseObject === "undefined") { var UseObject = function(progId, callback, dispose) { + if (typeof callback !== "function") { + return null; + } + if (typeof dispose !== "function") { dispose = function(obj) { try { @@ -199,8 +203,7 @@ if (typeof UseObject === "undefined") { var obj = CreateObject(progId); try { - return (typeof callback === "function" ? - callback(obj) : null); + return callback(obj); } finally { dispose(obj); obj = null; diff --git a/lib/pipe-ipc.js b/lib/pipe-ipc.js index 40fbb88..779635b 100644 --- a/lib/pipe-ipc.js +++ b/lib/pipe-ipc.js @@ -160,7 +160,7 @@ function Converter() { }; this.repositionObject = function(stream, position) { - position = (position !== "number" ? 0 : position); + position = (typeof position !== "number" ? 0 : position); var _dispose = function() {}; // prevent dispose after repositionObject @@ -571,7 +571,7 @@ exports.adSaveCreateNotExist = adSaveCreateNotExist; exports.adSaveCreateOverWrite = adSaveCreateOverWrite; exports.adModeReadWrite = adModeReadWrite; -exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.25"; +exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.26"; exports.AUTHOR = "gnh1201@catswords.re.kr"; exports.global = global; exports.require = require; From 8d27e1fd02c0b9efe18bbec3d50fb5f78bc3d657 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Wed, 21 Jan 2026 17:51:26 +0900 Subject: [PATCH 3/3] Add fallback to UseObject error handling The UseObject function now accepts an optional fallback callback, which is invoked if the main callback throws an error. This improves error handling and allows custom recovery logic. --- app.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index c95b39b..e8c9c01 100644 --- a/app.js +++ b/app.js @@ -188,7 +188,7 @@ if (typeof CreateObject === "undefined") { } if (typeof UseObject === "undefined") { - var UseObject = function(progId, callback, dispose) { + var UseObject = function(progId, callback, dispose, fallback) { if (typeof callback !== "function") { return null; } @@ -204,6 +204,9 @@ if (typeof UseObject === "undefined") { var obj = CreateObject(progId); try { return callback(obj); + } catch (e) { + return (typeof fallback === "function" ? + fallback(obj, e) : null); } finally { dispose(obj); obj = null;