Commit ac1a0004 authored by rswindell's avatar rswindell
Browse files

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

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. :-|
parent ebc73c17
......@@ -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);
JS_SetElement(cx, nargv, nargc, &argv[i]);
......@@ -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.")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment