Modified: trunk/Source/_javascript_Core/ChangeLog (194589 => 194590)
--- trunk/Source/_javascript_Core/ChangeLog 2016-01-05 17:58:45 UTC (rev 194589)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-01-05 19:03:07 UTC (rev 194590)
@@ -1,3 +1,32 @@
+2015-12-24 Mark Lam <[email protected]>
+
+ Add validation of JSC options to catch typos.
+ https://bugs.webkit.org/show_bug.cgi?id=152549
+
+ Reviewed by Benjamin Poulain.
+
+ 1. If a JSC_xxx option is found and xxx is not a valid option, we will now log
+ an error message.
+ 2. The jsc app is commonly used as follows:
+
+ $ jsc [jsc options] [scripts]
+
+ Previously, we'll continue to parse for [jsc options] after [scripts] is seen.
+ We won't do this anymore. Any --xxx jsc options must precede the [scripts]
+ arguments.
+
+ 3. If a --xxx jsc option is specified, but xxx is not a valid option, we will
+ now log an error message.
+
+ 4. Added JSC_validateOptions, which if set to true will cause the VM to crash if
+ an invalid option was seen during options parsing.
+
+ * jsc.cpp:
+ (CommandLine::parseArguments):
+ * runtime/Options.cpp:
+ (JSC::Options::initialize):
+ * runtime/Options.h:
+
2016-01-04 Keith Miller <[email protected]>
Turn off Internal Function inlining in the DFG for super calls.
Modified: trunk/Source/_javascript_Core/jsc.cpp (194589 => 194590)
--- trunk/Source/_javascript_Core/jsc.cpp 2016-01-05 17:58:45 UTC (rev 194589)
+++ trunk/Source/_javascript_Core/jsc.cpp 2016-01-05 19:03:07 UTC (rev 194590)
@@ -1889,80 +1889,94 @@
bool needToDumpOptions = false;
bool needToExit = false;
+ bool doneWithJSCOptions = false;
+ bool hasBadJSCOptions = false;
for (; i < argc; ++i) {
const char* arg = argv[i];
- if (!strcmp(arg, "-f")) {
- if (++i == argc)
- printUsageStatement();
- m_scripts.append(Script(true, argv[i]));
- continue;
- }
- if (!strcmp(arg, "-e")) {
- if (++i == argc)
- printUsageStatement();
- m_scripts.append(Script(false, argv[i]));
- continue;
- }
- if (!strcmp(arg, "-i")) {
- m_interactive = true;
- continue;
- }
- if (!strcmp(arg, "-d")) {
- m_dump = true;
- continue;
- }
- if (!strcmp(arg, "-p")) {
- if (++i == argc)
- printUsageStatement();
- m_profile = true;
- m_profilerOutput = argv[i];
- continue;
- }
- if (!strcmp(arg, "-m")) {
- m_module = true;
- continue;
- }
- if (!strcmp(arg, "-s")) {
+
+ if (!doneWithJSCOptions) {
+ if (!strcmp(arg, "-f")) {
+ if (++i == argc)
+ printUsageStatement();
+ m_scripts.append(Script(true, argv[i]));
+ continue;
+ }
+ if (!strcmp(arg, "-e")) {
+ if (++i == argc)
+ printUsageStatement();
+ m_scripts.append(Script(false, argv[i]));
+ continue;
+ }
+ if (!strcmp(arg, "-i")) {
+ m_interactive = true;
+ continue;
+ }
+ if (!strcmp(arg, "-d")) {
+ m_dump = true;
+ continue;
+ }
+ if (!strcmp(arg, "-p")) {
+ if (++i == argc)
+ printUsageStatement();
+ m_profile = true;
+ m_profilerOutput = argv[i];
+ continue;
+ }
+ if (!strcmp(arg, "-m")) {
+ m_module = true;
+ continue;
+ }
+ if (!strcmp(arg, "-s")) {
#if HAVE(SIGNAL_H)
- signal(SIGILL, _exit);
- signal(SIGFPE, _exit);
- signal(SIGBUS, _exit);
- signal(SIGSEGV, _exit);
+ signal(SIGILL, _exit);
+ signal(SIGFPE, _exit);
+ signal(SIGBUS, _exit);
+ signal(SIGSEGV, _exit);
#endif
- continue;
- }
- if (!strcmp(arg, "-x")) {
- m_exitCode = true;
- continue;
- }
- if (!strcmp(arg, "--")) {
- ++i;
- break;
- }
- if (!strcmp(arg, "-h") || !strcmp(arg, "--help"))
- printUsageStatement(true);
+ continue;
+ }
+ if (!strcmp(arg, "-x")) {
+ m_exitCode = true;
+ continue;
+ }
+ if (!strcmp(arg, "--")) {
+ ++i;
+ break;
+ }
+ if (!strcmp(arg, "-h") || !strcmp(arg, "--help"))
+ printUsageStatement(true);
- if (!strcmp(arg, "--options")) {
- needToDumpOptions = true;
- needToExit = true;
- continue;
- }
- if (!strcmp(arg, "--dumpOptions")) {
- needToDumpOptions = true;
- continue;
- }
+ if (!strcmp(arg, "--options")) {
+ needToDumpOptions = true;
+ needToExit = true;
+ continue;
+ }
+ if (!strcmp(arg, "--dumpOptions")) {
+ needToDumpOptions = true;
+ continue;
+ }
- // See if the -- option is a JSC VM option.
- if (strstr(arg, "--") == arg && JSC::Options::setOption(&arg[2])) {
- // The arg was recognized as a VM option and has been parsed.
- continue; // Just continue with the next arg.
- }
+ // See if the -- option is a JSC VM option.
+ if (strstr(arg, "--") == arg) {
+ if (!JSC::Options::setOption(&arg[2])) {
+ hasBadJSCOptions = true;
+ dataLog("ERROR: invalid option: ", arg, "\n");
+ }
+ continue;
+ }
+ doneWithJSCOptions = true;
+
+ } // !doneWithJSCOptions
+
// This arg is not recognized by the VM nor by jsc. Pass it on to the
// script.
m_scripts.append(Script(true, argv[i]));
}
+ if (hasBadJSCOptions && JSC::Options::validateOptions())
+ CRASH();
+
if (m_scripts.isEmpty())
m_interactive = true;
Modified: trunk/Source/_javascript_Core/runtime/Options.cpp (194589 => 194590)
--- trunk/Source/_javascript_Core/runtime/Options.cpp 2016-01-05 17:58:45 UTC (rev 194589)
+++ trunk/Source/_javascript_Core/runtime/Options.cpp 2016-01-05 19:03:07 UTC (rev 194590)
@@ -39,6 +39,10 @@
#include <wtf/StringExtras.h>
#include <wtf/text/StringBuilder.h>
+#if PLATFORM(COCOA)
+#include <crt_externs.h>
+#endif
+
#if OS(WINDOWS)
#include "MacroAssemblerX86.h"
#endif
@@ -361,10 +365,25 @@
// Allow environment vars to override options if applicable.
// The evn var should be the name of the option prefixed with
// "JSC_".
+#if PLATFORM(COCOA)
+ bool hasBadOptions = false;
+ for (char** envp = *_NSGetEnviron(); *envp; envp++) {
+ const char* env = *envp;
+ if (!strncmp("JSC_", env, 4)) {
+ if (!Options::setOption(&env[4])) {
+ dataLog("ERROR: invalid option: ", *envp, "\n");
+ hasBadOptions = true;
+ }
+ }
+ }
+ if (hasBadOptions && Options::validateOptions())
+ CRASH();
+#else // PLATFORM(COCOA)
#define FOR_EACH_OPTION(type_, name_, defaultValue_, description_) \
overrideOptionWithHeuristic(name_(), "JSC_" #name_);
JSC_OPTIONS(FOR_EACH_OPTION)
#undef FOR_EACH_OPTION
+#endif // PLATFORM(COCOA)
#if 0
; // Deconfuse editors that do auto indentation
Modified: trunk/Source/_javascript_Core/runtime/Options.h (194589 => 194590)
--- trunk/Source/_javascript_Core/runtime/Options.h 2016-01-05 17:58:45 UTC (rev 194589)
+++ trunk/Source/_javascript_Core/runtime/Options.h 2016-01-05 19:03:07 UTC (rev 194590)
@@ -102,6 +102,7 @@
typedef const char* optionString;
#define JSC_OPTIONS(v) \
+ v(bool, validateOptions, false, "crashes if mis-typed JSC options were passed to the VM") \
v(unsigned, dumpOptions, 0, "dumps JSC options (0 = None, 1 = Overridden only, 2 = All, 3 = Verbose)") \
\
v(bool, useLLInt, true, "allows the LLINT to be used if true") \