From 4a3231ca7f96ee8acf8427e1589e4456b844293f Mon Sep 17 00:00:00 2001 From: "David P. Caldwell" Date: Wed, 18 Sep 2024 22:15:35 -0400 Subject: [PATCH] Improve jrunscript io definitions Also: * fix broken documentation link for jsh loader --- jrunscript/jsh/_.fifty.ts | 2 +- loader/jrunscript/io.fifty.ts | 9 ++++++++- loader/jrunscript/io.js | 12 ++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/jrunscript/jsh/_.fifty.ts b/jrunscript/jsh/_.fifty.ts index 75caf12e0..d12c591b7 100644 --- a/jrunscript/jsh/_.fifty.ts +++ b/jrunscript/jsh/_.fifty.ts @@ -109,7 +109,7 @@ namespace slime.jsh { * of a script. It has two implementations: a Rhino implementation (`inonit.script.jsh.Rhino`) and a Nashorn implementation * (`inonit.script.jsh.Nashorn`); the entry point is chosen and executed by the launcher subsystem. * - * It is documented at {@link slime.jsh.loader.internal}. + * It is documented at {@link slime.jsh.internal.loader}. * * ## Development Tools * diff --git a/loader/jrunscript/io.fifty.ts b/loader/jrunscript/io.fifty.ts index ae74bee3f..ba67a9537 100644 --- a/loader/jrunscript/io.fifty.ts +++ b/loader/jrunscript/io.fifty.ts @@ -7,12 +7,19 @@ namespace slime.jrunscript.runtime.io { type byte = number + export namespace input { + export interface ReaderConfiguration { + charset: string + LINE_SEPARATOR: string + } + } + /** * A stream from which bytes may be read. */ export interface InputStream { /** A character input stream that reads this stream. */ - character: (mode?: any) => Reader + character: (mode?: input.ReaderConfiguration) => Reader /** * Closes the underlying stream. diff --git a/loader/jrunscript/io.js b/loader/jrunscript/io.js index 5f78bacb0..aab4f46d6 100644 --- a/loader/jrunscript/io.js +++ b/loader/jrunscript/io.js @@ -21,9 +21,17 @@ var _java = $context._streams; function InputStream(peer) { + /** + * + * @param { slime.jrunscript.runtime.io.input.ReaderConfiguration } [mode] + * @returns + */ var character = function(mode) { - if (!mode) mode = {}; - if (!mode.charset) mode.charset = Packages.java.nio.charset.Charset.defaultCharset().name(); + if (!mode) mode = { + charset: void(0), + LINE_SEPARATOR: void(0) + }; + if (!mode.charset) mode.charset = String(Packages.java.nio.charset.Charset.defaultCharset().name()); var separator = mode.LINE_SEPARATOR; // TODO No unit test for this method currently; does it work? return Reader(new Packages.java.io.InputStreamReader(peer,mode.charset), {LINE_SEPARATOR: separator});