Ignore:
Timestamp:
May 16, 2011, 2:08:07 AM (14 years ago)
Author:
[email protected]
Message:

https://bugs.webkit.org/show_bug.cgi?id=60866
Evaluation order broken for empty alternatives in subpatterns

Rubber stamped by Geoff Garen.

Source/JavaScriptCore:

Reverting https://bugs.webkit.org/show_bug.cgi?id=51395

  • yarr/YarrPattern.cpp:

(JSC::Yarr::YarrPatternConstructor::atomParenthesesEnd):

LayoutTests:

Reverted https://bugs.webkit.org/show_bug.cgi?id=51395, and added
test cases for /(|a)/ and /(a|)/, to test the evaluation order of
subpattern matches with empty alternatives.

  • fast/regex/parentheses-expected.txt:
  • fast/regex/script-tests/parentheses.js:
  • fast/regex/script-tests/slow.js:
  • fast/regex/slow-expected.txt:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/yarr/YarrPattern.cpp

    r80217 r86547  
    492492        unsigned numParenAlternatives = parenthesesDisjunction->m_alternatives.size();
    493493        unsigned numBOLAnchoredAlts = 0;
    494         bool containsEmptyAlternative = false;
    495494
    496495        for (unsigned i = 0; i < numParenAlternatives; i++) {
    497             if (!parenthesesDisjunction->m_alternatives[i]->m_terms.size() && numParenAlternatives > 1) {
    498                 PatternAlternative* altToRemove = parenthesesDisjunction->m_alternatives[i];
    499                 parenthesesDisjunction->m_alternatives.remove(i);
    500                 delete altToRemove;
    501                 --numParenAlternatives;
    502 
    503                 containsEmptyAlternative = true;
    504                 continue;
    505             }
    506 
    507496            // Bubble up BOL flags
    508497            if (parenthesesDisjunction->m_alternatives[i]->m_startsWithBOL)
     
    519508        lastTerm.parentheses.lastSubpatternId = m_pattern.m_numSubpatterns;
    520509        m_invertParentheticalAssertion = false;
    521 
    522         if (containsEmptyAlternative) {
    523             // Backup and remove the current disjunction's alternatives.
    524             Vector<PatternAlternative*> alternatives;
    525             alternatives.append(parenthesesDisjunction->m_alternatives);
    526             parenthesesDisjunction->m_alternatives.clear();
    527             PatternAlternative* alternative = parenthesesDisjunction->addNewAlternative();
    528 
    529             // Insert a new non-capturing parentheses.
    530             unsigned subpatternId = m_pattern.m_numSubpatterns + 1;
    531             PatternDisjunction* newDisjunction = new PatternDisjunction(alternative);
    532             m_pattern.m_disjunctions.append(newDisjunction);
    533             alternative->m_terms.append(PatternTerm(PatternTerm::TypeParenthesesSubpattern, subpatternId, newDisjunction, false, false));
    534             newDisjunction->m_alternatives.append(alternatives);
    535 
    536             // Set the quantifier of the new parentheses to '?' and set the inherited properties.
    537             PatternTerm& disjunctionTerm = alternative->lastTerm();
    538             disjunctionTerm.quantify(1, QuantifierGreedy);
    539             disjunctionTerm.parentheses.lastSubpatternId = m_pattern.m_numSubpatterns;
    540             alternative->m_containsBOL = m_alternative->m_containsBOL;
    541             alternative->m_startsWithBOL = m_alternative->m_startsWithBOL;
    542         }
    543510    }
    544511
Note: See TracChangeset for help on using the changeset viewer.