Bug 675269: shell arguments bound to global |arguments|. (r=dvander)
authorChris Leary <cdleary@mozilla.com>
Mon, 15 Aug 2011 13:57:53 -0700
changeset 75330 edead6fe5c9514e39cff0fc5b5bd9bef54406760
parent 75329 c36563ee6447afd04561b1ba9f30e740c43261b8
child 75331 44f89f14c84a7dd624bc9fe4e0e82557c87afc35
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
reviewersdvander
bugs675269
milestone8.0a1
Bug 675269: shell arguments bound to global |arguments|. (r=dvander)
js/src/shell/js.cpp
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -5025,17 +5025,24 @@ NewGlobalObject(JSContext *cx, Compartme
 
 static bool
 BindScriptArgs(JSContext *cx, JSObject *obj, OptionParser *op)
 {
     MultiStringRange msr = op->getMultiStringArg("scriptArgs");
     JSObject *scriptArgs = JS_NewArrayObject(cx, 0, NULL);
     if (!scriptArgs)
         return false;
-    if (!JS_DefineProperty(cx, obj, "scriptArgs", OBJECT_TO_JSVAL(scriptArgs), NULL, NULL, 0))
+
+    /* 
+     * Script arguments are bound as a normal |arguments| property on the
+     * global object. It has no special significance, like |arguments| in
+     * function scope does -- this identifier is used de-facto across shell
+     * implementations, see bug 675269.
+     */
+    if (!JS_DefineProperty(cx, obj, "arguments", OBJECT_TO_JSVAL(scriptArgs), NULL, NULL, 0))
         return false;
 
     for (size_t i = 0; !msr.empty(); msr.popFront(), ++i) {
         const char *scriptArg = msr.front();
         JSString *str = JS_NewStringCopyZ(cx, scriptArg);
         if (!str ||
             !JS_DefineElement(cx, scriptArgs, i, STRING_TO_JSVAL(str), NULL, NULL,
                               JSPROP_ENUMERATE)) {
@@ -5345,17 +5352,17 @@ main(int argc, char **argv, char **envp)
                                "N indicates \"zealousness\":\n"
                                "  0: no additional GCs\n"
                                "  1: additional GCs at common danger points\n"
                                "  2: GC every F allocations (default: 100)\n"
                                "If C is 1, compartmental GCs are performed; otherwise, full")
 #endif
         || !op.addOptionalStringArg("script", "A script to execute (after all options)")
         || !op.addOptionalMultiStringArg("scriptArgs",
-                                         "String arguments to bind as |scriptArgs| in the "
+                                         "String arguments to bind as |arguments| in the "
                                          "shell's global")) {
         return EXIT_FAILURE;
     }
 
     switch (op.parseArgs(argc, argv)) {
       case OptionParser::ParseHelp:
         return EXIT_SUCCESS;
       case OptionParser::ParseError: