The default bug view has changed. See this FAQ.

restore |arguments| in javascript shell

RESOLVED FIXED in mozilla8

Status

()

Core
JavaScript Engine
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: azakai, Assigned: cdleary)

Tracking

unspecified
mozilla8
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [inbound])

Attachments

(1 attachment)

(Reporter)

Description

6 years ago
We used to expose the commandline arguments as |arguments| in the js shell, but recently stopped doing so. However, at least the v8 shell does this, perhaps in order to emulate our original behavior. Would be nice to restore |arguments| so projects using multiple js shells don't need to check for |scriptArgs| as well as |arguments|.
(Reporter)

Updated

6 years ago
Assignee: general → cdleary
(Reporter)

Comment 1

6 years ago
Another issue (tell me if you want a separate bug): It is no longer possible to pass arguments into JS that start with '-'. For example, this will work

  js test.js arg1

(arg1 is passed to the script) but this will fail

  js test.js -arg1

(the js engine gives an error about an unknown arg). This used to work though.

v8 requires that arguments to the js engine and arguments to the js script be separated by '--' (like getopt does), so

  js test.js -- -arg1

would work there, and there is no ambiguity to figure out. Maybe that makes sense to do as well?
(In reply to comment #1)
> v8 requires that arguments to the js engine and arguments to the js script
> be separated by '--' (like getopt does), so
> 
>   js test.js -- -arg1

Does that work when the shell is used in the shebang line? That was a use case for the existing form raised in the newsgroup.
(Reporter)

Comment 3

6 years ago
I seem to get errors with any parameters (-- or otherwise) in the shebang line with v8,

> #!/home/alon/Dev/v8/d8 test.js foo

gives me

> Error reading 'test.js foo'

so not sure what the use case is there.
(In reply to comment #3)
> I seem to get errors with any parameters (-- or otherwise) in the shebang
> line with v8,

Parameters aren't place in the shebang line -- the shebang line indicates an interpreter to the operating system, and I think the subsequent parameters are passed as arguments to the interpreter process.

<<EOF
#!/usr/bin/env js

print(uneval(scriptArgs))
EOF

$ ./foo.js these are some args
["these", "are", "some", "args"
(Reporter)

Comment 5

6 years ago
I can't seem to get things to work in the shebang line - I never messed with this stuff before. But I don't understand the background, I guess, why would re-allowing parameters that start with "-" be a problem for shebang?
Created attachment 553221 [details] [diff] [review]
scriptArgs becomes arguments again
Attachment #553221 - Flags: review?(dvander)
Attachment #553221 - Flags: review?(dvander) → review+
Whiteboard: [inbound]
http://hg.mozilla.org/mozilla-central/rev/edead6fe5c95
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla8
You need to log in before you can comment on or make changes to this bug.