Created attachment 460636 [details] [diff] [review] Fix arguments array when -i is given, implement -- % ~/moz/obj-opt/js/src/js -i x y z js> arguments ["y", "z"] % ~/moz/obj-opt/js/src/js -e 'print(arguments);' -i x y z y,z I understand why. It's expecting to eat one argument as the filename of a script to run: % ~/moz/obj-opt/js/src/js test.js x y z x,y,z % ./js - x y z js> print(arguments) x,y,z so it's really the -i argument that's confusing things. Also, there's currently no way to pass options starting with a dash to the JS script, unless using a #! line. It really ought to accept '--' as meaning 'end of shell options; everything else should be given to the script'.
The original issue is now gone, since cdleary rewrote the argument processing. But the sample command lines I gave now do something I wouldn't expect: the -i option eats a single argument, which is treated as the filename of a script. This is not what I would expect; I would expect -i to take no arguments, but to force running in shell mode whether or not any code was given to run directly (either via -e SCRIPT or with a filename.) If you disagree, feel free to mark this as INVALID. (And of course, this is low priority in any case; I'm just going through the list I bugs I've filed and cleaning them up.) Whether -i is positional or not, I don't much care. If it was positional, you could do things like |./js myscript.js -i final-analysis.js| and have it run myscript.js, let you mess around at the shell console, and then run a final script that dumps out stats just before terminating. But perhaps it's more confusing. So I don't care.
I think you're going to have to provide more examples (or a patch) for me to understand. -i is a boolean option, and so doesn't eat any arguments, we just detect its presence. |./js -i| works just fine. The first non-option argv to js is a script to run (after |-e|s and |-f|s) and all arguments subsequent to that first non-option argv are simply placed into the |arguments| binding on the shell global. I think most other schemes will make it hard to pass certain types of argv through to the shell when it's used in |#!/usr/bin/env js| form.
Oh. Never mind, you are right. I was implicitly assuming that -i meant "don't look for a script on the command line" without realizing that I was assuming it. But -i does exactly what its help message says. Sorry!