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/JSGlobalObject.h

    r221601 r221769  
    337337    WriteBarrier<Structure> m_iteratorResultObjectStructure;
    338338    WriteBarrier<Structure> m_regExpMatchesArrayStructure;
     339    WriteBarrier<Structure> m_regExpMatchesArrayWithGroupsStructure;
    339340    WriteBarrier<Structure> m_moduleRecordStructure;
    340341    WriteBarrier<Structure> m_moduleNamespaceObjectStructure;
     
    646647    Structure* iteratorResultObjectStructure() const { return m_iteratorResultObjectStructure.get(); }
    647648    Structure* regExpMatchesArrayStructure() const { return m_regExpMatchesArrayStructure.get(); }
     649    Structure* regExpMatchesArrayWithGroupsStructure() const { return m_regExpMatchesArrayWithGroupsStructure.get(); }
    648650    Structure* moduleRecordStructure() const { return m_moduleRecordStructure.get(); }
    649651    Structure* moduleNamespaceObjectStructure() const { return m_moduleNamespaceObjectStructure.get(); }
Note: See TracChangeset for help on using the changeset viewer.