From 235d104418b041f312b588dd9715a6fa8988a547 Mon Sep 17 00:00:00 2001
From: echicken <echicken@bbs.electronicchicken.com>
Date: Thu, 8 Oct 2020 00:19:48 -0400
Subject: [PATCH] Don't shit pants if 'cwd' isn't a thing or a string. Added
 xjs_eval(filename, str) - notionally for evaluating XJS without immediate
 write - if str, returns the evaluated script as a string - if !str, returns
 the filename that the script was dumped to - was a fun idea, but doesn't play
 well with other scripts - best used with simple and self-contained xjs

---
 exec/load/xjs.js | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/exec/load/xjs.js b/exec/load/xjs.js
index a1244befc2..46f05e92e3 100644
--- a/exec/load/xjs.js
+++ b/exec/load/xjs.js
@@ -1,5 +1,5 @@
 function xjs_compile(filename) {
-	if(cwd != '') {
+	if(typeof cwd == 'string' && cwd != '') {
 		if(filename.search(/^((\/)|([A-Za-z]:[\/\\]))/)==-1)
 			filename=cwd+filename;
 	}
@@ -91,3 +91,29 @@ function xjs_compile(filename) {
 	}
 	return(ssjs_filename);
 }
+
+function xjs_eval(filename, str) {
+	const ssjs = xjs_compile(filename);
+	const f = new File(filename + '.html');
+	if (!f.open('w+', false)) {
+		log(LOG_ERR, "!ERROR " + f.error + " creating " + f.name);
+		return '';
+	}
+	function write(s) {
+		f.write(s);
+	}
+	function writeln(s) {
+		f.writeln(s);
+	}
+	load(ssjs);
+	if (str) {
+		f.rewind();
+		const ret = f.read();
+		f.close();
+		f.remove();
+		return ret;
+	} else {
+		f.close();
+		return filename + '.html';
+	}
+}
\ No newline at end of file
-- 
GitLab