Last Comment Bug 675269 - restore |arguments| in javascript shell
: restore |arguments| in javascript shell
Status: RESOLVED FIXED
[inbound]
:
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: unspecified
: All All
: -- normal (vote)
: mozilla8
Assigned To: Chris Leary [:cdleary] (not checking bugmail)
:
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-07-29 11:10 PDT by Alon Zakai (:azakai)
Modified: 2011-08-16 04:01 PDT (History)
2 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
scriptArgs becomes arguments again (2.23 KB, patch)
2011-08-15 11:13 PDT, Chris Leary [:cdleary] (not checking bugmail)
dvander: review+
Details | Diff | Splinter Review

Description Alon Zakai (:azakai) 2011-07-29 11:10:53 PDT
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|.
Comment 1 Alon Zakai (:azakai) 2011-07-29 14:56:05 PDT
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?
Comment 2 Chris Leary [:cdleary] (not checking bugmail) 2011-07-29 18:25:41 PDT
(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.
Comment 3 Alon Zakai (:azakai) 2011-07-29 18:59:23 PDT
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.
Comment 4 Chris Leary [:cdleary] (not checking bugmail) 2011-07-29 20:24:46 PDT
(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"
Comment 5 Alon Zakai (:azakai) 2011-08-12 12:09:08 PDT
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?
Comment 6 Chris Leary [:cdleary] (not checking bugmail) 2011-08-15 11:13:57 PDT
Created attachment 553221 [details] [diff] [review]
scriptArgs becomes arguments again
Comment 7 Kyle Huey [:khuey] (khuey@mozilla.com) 2011-08-16 04:01:11 PDT
http://hg.mozilla.org/mozilla-central/rev/edead6fe5c95

Note You need to log in before you can comment on or make changes to this bug.