From ac1a0004a2e4e774b3026cb225ee653970561893 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Sun, 29 Mar 2020 23:40:57 +0000
Subject: [PATCH] Revert the last commit (mostly): don't treat array arguments
 to js.exec() specially, just pass them on to the script as-is. Included a
 JSDOC note about the use of js.exec.apply() to pass a variable number of
 arguments (ala execv).

Thanks Tracker1 for the pointer to 'spread' which led me to function.apply()
and the JS-standard method of achieving the result I needed with this
enhancement.

I still think that a script that calls exit() is unlikely to expect non-string
arguments in the first place, but if we don't need special case behavior, it's
better not to add it and keep the behavior consistent with load() and
require(). That was the decision of the executive board anyway. :-|
---
 src/sbbs3/js_internal.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/src/sbbs3/js_internal.c b/src/sbbs3/js_internal.c
index 17f5e49337..df797c2047 100644
--- a/src/sbbs3/js_internal.c
+++ b/src/sbbs3/js_internal.c
@@ -402,22 +402,6 @@ js_execfile(JSContext *cx, uintN argc, jsval *arglist)
 
 	uintN nargc = 0;
 	for(i=arg; i<argc; i++) {
-		if(JSVAL_IS_OBJECT(argv[i]) && !JSVAL_IS_NULL(argv[i])) {
-			JSObject* objarg = JSVAL_TO_OBJECT(argv[i]);
-			if(JS_IsArrayObject(cx, objarg)) {		/* argument is an array (e.g. of strings) */
-				jsuint array_length = 0;
-				if(JS_GetArrayLength(cx, objarg, &array_length) && array_length) {
-					for(jsuint n = 0; n < array_length; n++) {
-						if(JS_GetElement(cx, objarg, n, &val)) {
-							JS_SetElement(cx, nargv, nargc, &val);
-							nargc++;
-						}
-					}
-					continue;
-				}
-
-			}
-		}
 		JS_SetElement(cx, nargv, nargc, &argv[i]);
 		nargc++;
 	}
@@ -737,9 +721,7 @@ static jsSyncMethodSpec js_functions[] = {
 	"<tt>on_exit()</tt> handlers will be evaluated in scripts scope when the script exists. <br>"
 	"NOTE: to get a child of the current scope, you need to create an object in the current scope. "
 	"An anonymous object can be created using '<tt>new function(){}</tt>'. <br>"
-	"NOTE: array-type arguments are treated specially: each element of the array is passed "
-	"as a separate argument (e.g. string) to the script in <tt>argv[]</tt>.  "
-	"This allows one script to generate a variable-length list of arguments to be passed to another.")
+	"NOTE: Use <tt>js.exec.apply()</tt> if you need to pass a variable number of arguments to the executed script.")
 	,31702
 	},
 	{0}
-- 
GitLab