Ignore:
Timestamp:
Sep 7, 2017, 4:13:38 PM (8 years ago)
Author:
[email protected]
Message:

Add support for RegExp named capture groups
https://bugs.webkit.org/show_bug.cgi?id=176435

Reviewed by Filip Pizlo.

Source/JavaScriptCore:

Added parsing for both naming a captured parenthesis as well and using a named group in
a back reference. Also added support for using named groups with String.prototype.replace().

This patch does not throw Syntax Errors as described in the current spec text for the two
cases of malformed back references in String.prototype.replace() as I believe that it
is inconsistent with the current semantics for handling of other malformed replacement
tokens. I filed an issue for the requested change to the proposed spec and also filed
a FIXME bug https://bugs.webkit.org/show_bug.cgi?id=176434.

This patch does not implement strength reduction in the optimizing JITs for named capture
groups. Filed https://bugs.webkit.org/show_bug.cgi?id=176464.

  • dfg/DFGAbstractInterpreterInlines.h:

(JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):

  • dfg/DFGStrengthReductionPhase.cpp:

(JSC::DFG::StrengthReductionPhase::handleNode):

  • runtime/CommonIdentifiers.h:
  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::haveABadTime):

  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::regExpMatchesArrayWithGroupsStructure const):

  • runtime/RegExp.cpp:

(JSC::RegExp::finishCreation):

  • runtime/RegExp.h:
  • runtime/RegExpMatchesArray.cpp:

(JSC::createStructureImpl):
(JSC::createRegExpMatchesArrayWithGroupsStructure):
(JSC::createRegExpMatchesArrayWithGroupsSlowPutStructure):

  • runtime/RegExpMatchesArray.h:

(JSC::createRegExpMatchesArray):

  • runtime/StringPrototype.cpp:

(JSC::substituteBackreferencesSlow):
(JSC::replaceUsingRegExpSearch):

  • yarr/YarrParser.h:

(JSC::Yarr::Parser::CharacterClassParserDelegate::atomNamedBackReference):
(JSC::Yarr::Parser::parseEscape):
(JSC::Yarr::Parser::parseParenthesesBegin):
(JSC::Yarr::Parser::tryConsumeUnicodeEscape):
(JSC::Yarr::Parser::tryConsumeIdentifierCharacter):
(JSC::Yarr::Parser::isIdentifierStart):
(JSC::Yarr::Parser::isIdentifierPart):
(JSC::Yarr::Parser::tryConsumeGroupName):

  • yarr/YarrPattern.cpp:

(JSC::Yarr::YarrPatternConstructor::atomParenthesesSubpatternBegin):
(JSC::Yarr::YarrPatternConstructor::atomNamedBackReference):
(JSC::Yarr::YarrPattern::errorMessage):

  • yarr/YarrPattern.h:

(JSC::Yarr::YarrPattern::reset):

  • yarr/YarrSyntaxChecker.cpp:

(JSC::Yarr::SyntaxChecker::atomParenthesesSubpatternBegin):
(JSC::Yarr::SyntaxChecker::atomNamedBackReference):

Source/WebCore:

Implemented stub routines to support named capture groups. These are no-ops
just like for number capture group.

No new tests as this is covered by existing tests.

  • contentextensions/URLFilterParser.cpp:

(WebCore::ContentExtensions::PatternParser::atomNamedBackReference):
(WebCore::ContentExtensions::PatternParser::atomParenthesesSubpatternBegin):

LayoutTests:

New regression tests.

  • js/regexp-named-capture-groups-expected.txt: Added.
  • js/regexp-named-capture-groups.html: Added.
  • js/script-tests/regexp-named-capture-groups.js: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/RegExp.cpp

    r221160 r221769  
    234234    if (!isValid())
    235235        m_state = ParseError;
    236     else
     236    else {
    237237        m_numSubpatterns = pattern.m_numSubpatterns;
     238        m_captureGroupNames.swap(pattern.m_captureGroupNames);
     239        m_namedGroupToParenIndex.swap(pattern.m_namedGroupToParenIndex);
     240    }
    238241}
    239242
Note: See TracChangeset for help on using the changeset viewer.