Ignore:
Timestamp:
Jan 5, 2016, 11:03:07 AM (9 years ago)
Author:
[email protected]
Message:

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.

  1. If a --xxx jsc option is specified, but xxx is not a valid option, we will now log an error message.
  1. 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:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/jsc.cpp

    r194017 r194590  
    18901890    bool needToExit = false;
    18911891
     1892    bool doneWithJSCOptions = false;
     1893    bool hasBadJSCOptions = false;
    18921894    for (; i < argc; ++i) {
    18931895        const char* arg = argv[i];
    1894         if (!strcmp(arg, "-f")) {
    1895             if (++i == argc)
    1896                 printUsageStatement();
    1897             m_scripts.append(Script(true, argv[i]));
    1898             continue;
    1899         }
    1900         if (!strcmp(arg, "-e")) {
    1901             if (++i == argc)
    1902                 printUsageStatement();
    1903             m_scripts.append(Script(false, argv[i]));
    1904             continue;
    1905         }
    1906         if (!strcmp(arg, "-i")) {
    1907             m_interactive = true;
    1908             continue;
    1909         }
    1910         if (!strcmp(arg, "-d")) {
    1911             m_dump = true;
    1912             continue;
    1913         }
    1914         if (!strcmp(arg, "-p")) {
    1915             if (++i == argc)
    1916                 printUsageStatement();
    1917             m_profile = true;
    1918             m_profilerOutput = argv[i];
    1919             continue;
    1920         }
    1921         if (!strcmp(arg, "-m")) {
    1922             m_module = true;
    1923             continue;
    1924         }
    1925         if (!strcmp(arg, "-s")) {
     1896
     1897        if (!doneWithJSCOptions) {
     1898            if (!strcmp(arg, "-f")) {
     1899                if (++i == argc)
     1900                    printUsageStatement();
     1901                m_scripts.append(Script(true, argv[i]));
     1902                continue;
     1903            }
     1904            if (!strcmp(arg, "-e")) {
     1905                if (++i == argc)
     1906                    printUsageStatement();
     1907                m_scripts.append(Script(false, argv[i]));
     1908                continue;
     1909            }
     1910            if (!strcmp(arg, "-i")) {
     1911                m_interactive = true;
     1912                continue;
     1913            }
     1914            if (!strcmp(arg, "-d")) {
     1915                m_dump = true;
     1916                continue;
     1917            }
     1918            if (!strcmp(arg, "-p")) {
     1919                if (++i == argc)
     1920                    printUsageStatement();
     1921                m_profile = true;
     1922                m_profilerOutput = argv[i];
     1923                continue;
     1924            }
     1925            if (!strcmp(arg, "-m")) {
     1926                m_module = true;
     1927                continue;
     1928            }
     1929            if (!strcmp(arg, "-s")) {
    19261930#if HAVE(SIGNAL_H)
    1927             signal(SIGILL, _exit);
    1928             signal(SIGFPE, _exit);
    1929             signal(SIGBUS, _exit);
    1930             signal(SIGSEGV, _exit);
    1931 #endif
    1932             continue;
    1933         }
    1934         if (!strcmp(arg, "-x")) {
    1935             m_exitCode = true;
    1936             continue;
    1937         }
    1938         if (!strcmp(arg, "--")) {
    1939             ++i;
    1940             break;
    1941         }
    1942         if (!strcmp(arg, "-h") || !strcmp(arg, "--help"))
    1943             printUsageStatement(true);
    1944 
    1945         if (!strcmp(arg, "--options")) {
    1946             needToDumpOptions = true;
    1947             needToExit = true;
    1948             continue;
    1949         }
    1950         if (!strcmp(arg, "--dumpOptions")) {
    1951             needToDumpOptions = true;
    1952             continue;
    1953         }
    1954 
    1955         // See if the -- option is a JSC VM option.
    1956         if (strstr(arg, "--") == arg && JSC::Options::setOption(&arg[2])) {
    1957             // The arg was recognized as a VM option and has been parsed.
    1958             continue; // Just continue with the next arg.
    1959         }
     1931                signal(SIGILL, _exit);
     1932                signal(SIGFPE, _exit);
     1933                signal(SIGBUS, _exit);
     1934                signal(SIGSEGV, _exit);
     1935#endif
     1936                continue;
     1937            }
     1938            if (!strcmp(arg, "-x")) {
     1939                m_exitCode = true;
     1940                continue;
     1941            }
     1942            if (!strcmp(arg, "--")) {
     1943                ++i;
     1944                break;
     1945            }
     1946            if (!strcmp(arg, "-h") || !strcmp(arg, "--help"))
     1947                printUsageStatement(true);
     1948
     1949            if (!strcmp(arg, "--options")) {
     1950                needToDumpOptions = true;
     1951                needToExit = true;
     1952                continue;
     1953            }
     1954            if (!strcmp(arg, "--dumpOptions")) {
     1955                needToDumpOptions = true;
     1956                continue;
     1957            }
     1958
     1959            // See if the -- option is a JSC VM option.
     1960            if (strstr(arg, "--") == arg) {
     1961                if (!JSC::Options::setOption(&arg[2])) {
     1962                    hasBadJSCOptions = true;
     1963                    dataLog("ERROR: invalid option: ", arg, "\n");
     1964                }
     1965                continue;
     1966            }
     1967
     1968            doneWithJSCOptions = true;
     1969
     1970        } // !doneWithJSCOptions
    19601971
    19611972        // This arg is not recognized by the VM nor by jsc. Pass it on to the
     
    19631974        m_scripts.append(Script(true, argv[i]));
    19641975    }
     1976
     1977    if (hasBadJSCOptions && JSC::Options::validateOptions())
     1978        CRASH();
    19651979
    19661980    if (m_scripts.isEmpty())
Note: See TracChangeset for help on using the changeset viewer.