Allow regular expressions to be used when selecting a process name in JSC config...
authormsaboff@apple.com <msaboff@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 12 Mar 2017 06:27:49 +0000 (06:27 +0000)
committermsaboff@apple.com <msaboff@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 12 Mar 2017 06:27:49 +0000 (06:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=169495

Reviewed by Saam Barati.

Only added regular expression selectors for unix like platforms.

* runtime/ConfigFile.cpp:
(JSC::ConfigFileScanner::tryConsumeRegExPattern):
(JSC::ConfigFile::parse):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213768 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/ConfigFile.cpp

index 96761c8..444c725 100644 (file)
@@ -1,3 +1,16 @@
+2017-03-11  Michael Saboff  <msaboff@apple.com>
+
+        Allow regular expressions to be used when selecting a process name in JSC config file
+        https://bugs.webkit.org/show_bug.cgi?id=169495
+
+        Reviewed by Saam Barati.
+
+        Only added regular expression selectors for unix like platforms.
+
+        * runtime/ConfigFile.cpp:
+        (JSC::ConfigFileScanner::tryConsumeRegExPattern):
+        (JSC::ConfigFile::parse):
+
 2017-03-11  Jon Lee  <jonlee@apple.com>
 
         WebGPU prototype - Front-End
index 444e787..ba6986a 100644 (file)
@@ -37,6 +37,7 @@
 #include <wtf/text/StringBuilder.h>
 
 #if OS(UNIX) || OS(DARWIN)
+#include <regex.h>
 #include <unistd.h>
 #endif
 
@@ -136,6 +137,32 @@ public:
         return nullptr;
     }
 
+    char* tryConsumeRegExPattern(bool& ignoreCase)
+    {
+        if (!fillBufferIfNeeded())
+            return nullptr;
+
+        if (*m_srcPtr != '/')
+            return nullptr;
+
+        char* stringStart = m_srcPtr + 1;
+
+        char* stringEnd = strchr(stringStart, '/');
+        if (stringEnd) {
+            *stringEnd = '\0';
+            m_srcPtr = stringEnd + 1;
+            if (*m_srcPtr == 'i') {
+                ignoreCase = true;
+                m_srcPtr++;
+            } else
+                ignoreCase = false;
+
+            return stringStart;
+        }
+
+        return nullptr;
+    }
+    
     char* tryConsumeUpto(bool& foundChar, char c)
     {
         if (!fillBufferIfNeeded())
@@ -339,12 +366,30 @@ void ConfigFile::parse()
     };
 
     auto parsePredicate = [&](bool& predicateMatches, const char* matchValue) {
-        char* predicateValue = nullptr;
-        if (scanner.tryConsume("==")
-            && (predicateValue = scanner.tryConsumeString()) && matchValue) {
+        if (scanner.tryConsume("==")) {
+            char* predicateValue = nullptr;
+            if ((predicateValue = scanner.tryConsumeString()) && matchValue) {
                 predicateMatches = !strcmp(predicateValue, matchValue);
                 return true;
+            }
+        }
+#if OS(UNIX) || OS(DARWIN)
+        else if (scanner.tryConsume("=~")) {
+            char* predicateRegExString = nullptr;
+            bool ignoreCase { false };
+            if ((predicateRegExString = scanner.tryConsumeRegExPattern(ignoreCase)) && matchValue) {
+                regex_t predicateRegEx;
+                int regexFlags = REG_EXTENDED;
+                if (ignoreCase)
+                    regexFlags |= REG_ICASE;
+                if (regcomp(&predicateRegEx, predicateRegExString, regexFlags))
+                    return false;
+
+                predicateMatches = !regexec(&predicateRegEx, matchValue, 0, nullptr, 0);
+                return true;
+            }
         }
+#endif
 
         return false;
     };