If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

js shell -i argument requires a script




JavaScript Engine
7 years ago
6 years ago


(Reporter: sfink, Assigned: cdleary)



Firefox Tracking Flags

(Not tracked)



(1 obsolete attachment)



7 years ago
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 

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                  

% ./js - x y z   
js> print(arguments)

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'.


7 years ago
Assignee: general → sphink

Comment 1

6 years ago
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.
Assignee: sphink → cdleary
Summary: Command-line arguments off by one when running js shell with -i → js shell -i argument requires a script


6 years ago
Attachment #460636 - Attachment is obsolete: true
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.

Comment 3

6 years ago
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!
Last Resolved: 6 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.