From b703b609779c87f6961abdc69df69b5fdde63777 Mon Sep 17 00:00:00 2001 From: jelveh Date: Wed, 21 May 2025 19:40:50 -0700 Subject: [PATCH] omg this is getting out of hand --- src/puter-js/src/clitest.js | 1 - src/puter-js/src/index.js | 28 +++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) delete mode 100644 src/puter-js/src/clitest.js diff --git a/src/puter-js/src/clitest.js b/src/puter-js/src/clitest.js deleted file mode 100644 index 10ce2935c..000000000 --- a/src/puter-js/src/clitest.js +++ /dev/null @@ -1 +0,0 @@ -import puter from './index.js'; diff --git a/src/puter-js/src/index.js b/src/puter-js/src/index.js index 25d4281fe..2e2275021 100644 --- a/src/puter-js/src/index.js +++ b/src/puter-js/src/index.js @@ -529,12 +529,34 @@ export default window.puter = (function() { container = document.getElementById("--puter-printbox"); } + // Copy args to avoid modifying the original array + let processedArgs = [...args]; + // Check if the last argument is an options object - const options = typeof args[args.length - 1] === 'object' && args[args.length - 1] !== null ? args.pop() : { newline: false }; + const lastArg = processedArgs.length > 0 ? processedArgs[processedArgs.length - 1] : null; + let options = { newline: false }; + + if (lastArg && typeof lastArg === 'object' && lastArg !== null && + !Array.isArray(lastArg) && + Object.getPrototypeOf(lastArg) === Object.prototype && + typeof lastArg.toString === 'undefined') { + options = processedArgs.pop(); + } // Process each argument - for(let arg of args) { - container.innerText += arg; + for(let arg of processedArgs) { + // If arg has custom toString, use it + if (arg && typeof arg === 'object' && typeof arg.toString === 'function') { + const stringValue = arg.toString(); + if (typeof stringValue === 'string') { + container.innerText += stringValue; + } else { + container.innerText += String(arg); + } + } else { + container.innerText += arg; + } + if (options.newline) { container.innerText += '\n'; }