Changeset 194606 in webkit


Ignore:
Timestamp:
Jan 5, 2016 2:04:59 PM (8 years ago)
Author:
mark.lam@apple.com
Message:

Re-landing: 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. If a --xxx jsc option is specified, but xxx is not a valid option, we will now log an error message.
  3. Added JSC_validateOptions, which if set to true will cause the VM to crash if an invalid option was seen during options parsing.

In this version for re-landing, I removed the change where I disallowed -- options
after the script name. Apparently, we have some test harnesses that do append the
-- options after the script name.

  • jsc.cpp:

(CommandLine::parseArguments):

  • runtime/Options.cpp:

(JSC::Options::initialize):

  • runtime/Options.h:
Location:
trunk/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r194604 r194606  
     12015-12-24  Mark Lam  <mark.lam@apple.com>
     2
     3        Re-landing: Add validation of JSC options to catch typos.
     4        https://bugs.webkit.org/show_bug.cgi?id=152549
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        1. If a JSC_xxx option is found and xxx is not a valid option, we will now log
     9           an error message.
     10        2. If a --xxx jsc option is specified, but xxx is not a valid option, we will
     11           now log an error message.
     12        3. Added JSC_validateOptions, which if set to true will cause the VM to crash if
     13           an invalid option was seen during options parsing.
     14
     15        In this version for re-landing, I removed the change where I disallowed -- options
     16        after the script name.  Apparently, we have some test harnesses that do append the
     17        -- options after the script name.
     18
     19        * jsc.cpp:
     20        (CommandLine::parseArguments):
     21        * runtime/Options.cpp:
     22        (JSC::Options::initialize):
     23        * runtime/Options.h:
     24
    1252016-01-05  Filip Pizlo  <fpizlo@apple.com>
    226
  • trunk/Source/JavaScriptCore/jsc.cpp

    r194599 r194606  
    18901890    bool needToExit = false;
    18911891
     1892    bool hasBadJSCOptions = false;
    18921893    for (; i < argc; ++i) {
    18931894        const char* arg = argv[i];
     
    19541955
    19551956        // 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.
     1957        if (strstr(arg, "--") == arg) {
     1958            if (!JSC::Options::setOption(&arg[2])) {
     1959                hasBadJSCOptions = true;
     1960                dataLog("ERROR: invalid option: ", arg, "\n");
     1961            }
     1962            continue;
    19591963        }
    19601964
     
    19631967        m_scripts.append(Script(true, argv[i]));
    19641968    }
     1969
     1970    if (hasBadJSCOptions && JSC::Options::validateOptions())
     1971        CRASH();
    19651972
    19661973    if (m_scripts.isEmpty())
  • trunk/Source/JavaScriptCore/runtime/Options.cpp

    r194599 r194606  
    4040#include <wtf/text/StringBuilder.h>
    4141
     42#if PLATFORM(COCOA)
     43#include <crt_externs.h>
     44#endif
     45
    4246#if OS(WINDOWS)
    4347#include "MacroAssemblerX86.h"
     
    377381            // The evn var should be the name of the option prefixed with
    378382            // "JSC_".
     383#if PLATFORM(COCOA)
     384            bool hasBadOptions = false;
     385            for (char** envp = *_NSGetEnviron(); *envp; envp++) {
     386                const char* env = *envp;
     387                if (!strncmp("JSC_", env, 4)) {
     388                    if (!Options::setOption(&env[4])) {
     389                        dataLog("ERROR: invalid option: ", *envp, "\n");
     390                        hasBadOptions = true;
     391                    }
     392                }
     393            }
     394            if (hasBadOptions && Options::validateOptions())
     395                CRASH();
     396#else // PLATFORM(COCOA)
    379397#define FOR_EACH_OPTION(type_, name_, defaultValue_, description_)      \
    380398            overrideOptionWithHeuristic(name_(), "JSC_" #name_);
    381399            JSC_OPTIONS(FOR_EACH_OPTION)
    382400#undef FOR_EACH_OPTION
     401#endif // PLATFORM(COCOA)
    383402
    384403#define FOR_EACH_OPTION(aliasedName_, unaliasedName_, equivalence_) \
  • trunk/Source/JavaScriptCore/runtime/Options.h

    r194599 r194606  
    103103
    104104#define JSC_OPTIONS(v) \
     105    v(bool, validateOptions, false, "crashes if mis-typed JSC options were passed to the VM") \
    105106    v(unsigned, dumpOptions, 0, "dumps JSC options (0 = None, 1 = Overridden only, 2 = All, 3 = Verbose)") \
    106107    \
Note: See TracChangeset for help on using the changeset viewer.