From eaf17fb9d0f9f117623aa575f7281c3052346eee Mon Sep 17 00:00:00 2001 From: "Nicolas B. Pierron" Date: Mon, 19 Nov 2012 17:52:35 -0800 Subject: [PATCH] Bug 810062 - Toggle JSOPTIONs before the compartment creation. r=bhackett --- js/xpconnect/idl/xpccomponents.idl | 2 +- js/xpconnect/shell/xpcshell.cpp | 58 +++++++++++++++++++++++------- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/js/xpconnect/idl/xpccomponents.idl b/js/xpconnect/idl/xpccomponents.idl index b6997c992088..e8036f760d0f 100644 --- a/js/xpconnect/idl/xpccomponents.idl +++ b/js/xpconnect/idl/xpccomponents.idl @@ -377,7 +377,7 @@ interface nsIXPCComponents_Utils : nsISupports [implicit_jscontext] attribute boolean strict_mode; - + [implicit_jscontext] attribute boolean ion; diff --git a/js/xpconnect/shell/xpcshell.cpp b/js/xpconnect/shell/xpcshell.cpp index f76826058ebb..f4ce36132b39 100644 --- a/js/xpconnect/shell/xpcshell.cpp +++ b/js/xpconnect/shell/xpcshell.cpp @@ -1124,12 +1124,48 @@ static int usage(void) { fprintf(gErrFile, "%s\n", JS_GetImplementationVersion()); - fprintf(gErrFile, "usage: xpcshell [-g gredir] [-a appdir] [-r manifest]... [-PsSwWxCij] [-v version] [-f scriptfile] [-e script] [scriptfile] [scriptarg...]\n"); + fprintf(gErrFile, "usage: xpcshell [-g gredir] [-a appdir] [-r manifest]... [-PsSwWxCijmIn] [-v version] [-f scriptfile] [-e script] [scriptfile] [scriptarg...]\n"); return 2; } extern JSClass global_class; +static void +ProcessArgsForCompartment(JSContext *cx, char **argv, int argc) +{ + for (int i = 0; i < argc; i++) { + if (argv[i][0] != '-' || argv[i][1] == '\0') + break; + + switch (argv[i][1]) { + case 'v': + case 'f': + case 'e': + if (++i == argc) + return; + break; + case 'S': + JS_ToggleOptions(cx, JSOPTION_WERROR); + case 's': + JS_ToggleOptions(cx, JSOPTION_STRICT); + break; + case 'x': + JS_ToggleOptions(cx, JSOPTION_MOAR_XML); + break; + case 'm': + JS_ToggleOptions(cx, JSOPTION_METHODJIT); + break; + case 'I': + JS_ToggleOptions(cx, JSOPTION_COMPILE_N_GO); + JS_ToggleOptions(cx, JSOPTION_ION); + break; + case 'n': + JS_ToggleOptions(cx, JSOPTION_TYPE_INFERENCE); + break; + } + } +} + static int ProcessArgs(JSContext *cx, JSObject *obj, char **argv, int argc) { @@ -1210,13 +1246,7 @@ ProcessArgs(JSContext *cx, JSObject *obj, char **argv, int argc) case 'w': reportWarnings = true; break; - case 'S': - JS_ToggleOptions(cx, JSOPTION_WERROR); - case 's': - JS_ToggleOptions(cx, JSOPTION_STRICT); - break; case 'x': - JS_ToggleOptions(cx, JSOPTION_MOAR_XML); break; case 'd': xpc_ActivateDebugMode(); @@ -1254,11 +1284,12 @@ ProcessArgs(JSContext *cx, JSObject *obj, char **argv, int argc) compileOnly = true; isInteractive = false; break; + case 'S': + case 's': case 'm': - JS_ToggleOptions(cx, JSOPTION_METHODJIT); - break; + case 'I': case 'n': - JS_ToggleOptions(cx, JSOPTION_TYPE_INFERENCE); + // These options are processed in ProcessArgsForCompartment. break; default: return usage(); @@ -1775,6 +1806,10 @@ main(int argc, char **argv, char **envp) return 1; } + argc--; + argv++; + ProcessArgsForCompartment(cx, argv, argc); + JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_ALLOW_XML); xpc_LocalizeContext(cx); @@ -1887,9 +1922,6 @@ main(int argc, char **argv, char **envp) JS_DefineProperty(cx, glob, "__LOCATION__", JSVAL_VOID, GetLocationProperty, NULL, 0); - argc--; - argv++; - result = ProcessArgs(cx, glob, argv, argc);