haikuwebkit/LayoutTests/js/regexp-named-capture-groups...

89 lines
6.2 KiB
Plaintext
Raw Permalink Normal View History

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. Canonical link: https://commits.webkit.org/193122@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-07 23:13:38 +00:00
Test for of RegExp named capture groups
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS re1.toString() is "\/(?<month>\\d{2})\\/(?<day>\\d{2})\\/(?<year>\\d{4})\/"
PASS execResult1[0] is "01/02/2001"
PASS execResult1.groups.month is "01"
PASS execResult1.groups.day is "02"
PASS execResult1.groups.year is "2001"
PASS Object.getOwnPropertyNames(execResult1).sort() is ["0","1","2","3","groups","index","input","length"]
PASS Object.getOwnPropertyNames(execResult1.groups).sort() is ["day","month","year"]
PASS matchResult1[0] is "01/02/2001"
PASS matchResult1.groups.month is "01"
PASS matchResult1.groups.day is "02"
PASS matchResult1.groups.year is "2001"
[JSC] Implement RegExp Match Indices proposal https://bugs.webkit.org/show_bug.cgi?id=202475 Reviewed by Yusuke Suzuki. JSTests: Updated tests. * es6/Proxy_internal_get_calls_RegExp.prototype.flags.js: * stress/static-getter-in-names.js: * test262/config.yaml: Source/JavaScriptCore: This implements the latest version of the RegExp match indices proposal (https://github.com/tc39/proposal-regexp-match-indices). It includes a new 'd' flag to RegExp's to trigger the population of the 'indices' property tree in a Matches result from RegExp.exec() and related methods. This change is performance neutral on JetStream2. * 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::fireWatchpointAndMakeAllArrayStructuresSlowPut): (JSC::JSGlobalObject::visitChildren): * runtime/JSGlobalObject.h: (JSC::JSGlobalObject::regExpMatchesArrayWithIndicesStructure const): (JSC::JSGlobalObject::regExpMatchesIndicesArrayStructure const): * runtime/RegExp.cpp: (JSC::RegExpFunctionalTestCollector::outputOneTest): (JSC::regexpToSourceString): * runtime/RegExp.h: * runtime/RegExpMatchesArray.cpp: (JSC::createEmptyRegExpMatchesArray): (JSC::createStructureWithIndicesImpl): (JSC::createIndicesStructureImpl): (JSC::createRegExpMatchesArrayWithIndicesStructure): (JSC::createRegExpMatchesIndicesArrayStructure): (JSC::createRegExpMatchesArrayWithIndicesSlowPutStructure): (JSC::createRegExpMatchesIndicesArraySlowPutStructure): * runtime/RegExpMatchesArray.h: (JSC::createRegExpMatchesArray): * runtime/RegExpPrototype.cpp: (JSC::RegExpPrototype::finishCreation): (JSC::flagsString): (JSC::JSC_DEFINE_HOST_FUNCTION): * yarr/YarrFlags.cpp: (JSC::Yarr::parseFlags): * yarr/YarrFlags.h: * yarr/YarrInterpreter.h: (JSC::Yarr::BytecodePattern::hasIndices const): * yarr/YarrPattern.h: (JSC::Yarr::YarrPattern::hasIndices const): LayoutTests: Updated tests. * js/Object-getOwnPropertyNames-expected.txt: * js/regexp-named-capture-groups-expected.txt: * js/script-tests/Object-getOwnPropertyNames.js: * js/script-tests/regexp-named-capture-groups.js: Canonical link: https://commits.webkit.org/234284@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273086 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-18 19:14:34 +00:00
PASS matchResult1.indices.groups.month is [0,2]
PASS matchResult1.indices.groups.day is [3,5]
PASS matchResult1.indices.groups.year is [6,10]
PASS Object.getOwnPropertyNames(matchResult1).sort() is ["0","1","2","3","groups","index","indices","input","length"]
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. Canonical link: https://commits.webkit.org/193122@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-07 23:13:38 +00:00
PASS Object.getOwnPropertyNames(matchResult1.groups).sort() is ["day","month","year"]
[JSC] Implement RegExp Match Indices proposal https://bugs.webkit.org/show_bug.cgi?id=202475 Reviewed by Yusuke Suzuki. JSTests: Updated tests. * es6/Proxy_internal_get_calls_RegExp.prototype.flags.js: * stress/static-getter-in-names.js: * test262/config.yaml: Source/JavaScriptCore: This implements the latest version of the RegExp match indices proposal (https://github.com/tc39/proposal-regexp-match-indices). It includes a new 'd' flag to RegExp's to trigger the population of the 'indices' property tree in a Matches result from RegExp.exec() and related methods. This change is performance neutral on JetStream2. * 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::fireWatchpointAndMakeAllArrayStructuresSlowPut): (JSC::JSGlobalObject::visitChildren): * runtime/JSGlobalObject.h: (JSC::JSGlobalObject::regExpMatchesArrayWithIndicesStructure const): (JSC::JSGlobalObject::regExpMatchesIndicesArrayStructure const): * runtime/RegExp.cpp: (JSC::RegExpFunctionalTestCollector::outputOneTest): (JSC::regexpToSourceString): * runtime/RegExp.h: * runtime/RegExpMatchesArray.cpp: (JSC::createEmptyRegExpMatchesArray): (JSC::createStructureWithIndicesImpl): (JSC::createIndicesStructureImpl): (JSC::createRegExpMatchesArrayWithIndicesStructure): (JSC::createRegExpMatchesIndicesArrayStructure): (JSC::createRegExpMatchesArrayWithIndicesSlowPutStructure): (JSC::createRegExpMatchesIndicesArraySlowPutStructure): * runtime/RegExpMatchesArray.h: (JSC::createRegExpMatchesArray): * runtime/RegExpPrototype.cpp: (JSC::RegExpPrototype::finishCreation): (JSC::flagsString): (JSC::JSC_DEFINE_HOST_FUNCTION): * yarr/YarrFlags.cpp: (JSC::Yarr::parseFlags): * yarr/YarrFlags.h: * yarr/YarrInterpreter.h: (JSC::Yarr::BytecodePattern::hasIndices const): * yarr/YarrPattern.h: (JSC::Yarr::YarrPattern::hasIndices const): LayoutTests: Updated tests. * js/Object-getOwnPropertyNames-expected.txt: * js/regexp-named-capture-groups-expected.txt: * js/script-tests/Object-getOwnPropertyNames.js: * js/script-tests/regexp-named-capture-groups.js: Canonical link: https://commits.webkit.org/234284@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273086 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-18 19:14:34 +00:00
PASS Object.getOwnPropertyNames(matchResult1.indices.groups).sort() is ["day","month","year"]
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. Canonical link: https://commits.webkit.org/193122@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-07 23:13:38 +00:00
PASS matchResult2a[0] is "John W. Smith"
PASS matchResult2a[1] is "John"
PASS matchResult2a[2] is "W."
PASS matchResult2a[3] is "Smith"
[JSC] Implement RegExp Match Indices proposal https://bugs.webkit.org/show_bug.cgi?id=202475 Reviewed by Yusuke Suzuki. JSTests: Updated tests. * es6/Proxy_internal_get_calls_RegExp.prototype.flags.js: * stress/static-getter-in-names.js: * test262/config.yaml: Source/JavaScriptCore: This implements the latest version of the RegExp match indices proposal (https://github.com/tc39/proposal-regexp-match-indices). It includes a new 'd' flag to RegExp's to trigger the population of the 'indices' property tree in a Matches result from RegExp.exec() and related methods. This change is performance neutral on JetStream2. * 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::fireWatchpointAndMakeAllArrayStructuresSlowPut): (JSC::JSGlobalObject::visitChildren): * runtime/JSGlobalObject.h: (JSC::JSGlobalObject::regExpMatchesArrayWithIndicesStructure const): (JSC::JSGlobalObject::regExpMatchesIndicesArrayStructure const): * runtime/RegExp.cpp: (JSC::RegExpFunctionalTestCollector::outputOneTest): (JSC::regexpToSourceString): * runtime/RegExp.h: * runtime/RegExpMatchesArray.cpp: (JSC::createEmptyRegExpMatchesArray): (JSC::createStructureWithIndicesImpl): (JSC::createIndicesStructureImpl): (JSC::createRegExpMatchesArrayWithIndicesStructure): (JSC::createRegExpMatchesIndicesArrayStructure): (JSC::createRegExpMatchesArrayWithIndicesSlowPutStructure): (JSC::createRegExpMatchesIndicesArraySlowPutStructure): * runtime/RegExpMatchesArray.h: (JSC::createRegExpMatchesArray): * runtime/RegExpPrototype.cpp: (JSC::RegExpPrototype::finishCreation): (JSC::flagsString): (JSC::JSC_DEFINE_HOST_FUNCTION): * yarr/YarrFlags.cpp: (JSC::Yarr::parseFlags): * yarr/YarrFlags.h: * yarr/YarrInterpreter.h: (JSC::Yarr::BytecodePattern::hasIndices const): * yarr/YarrPattern.h: (JSC::Yarr::YarrPattern::hasIndices const): LayoutTests: Updated tests. * js/Object-getOwnPropertyNames-expected.txt: * js/regexp-named-capture-groups-expected.txt: * js/script-tests/Object-getOwnPropertyNames.js: * js/script-tests/regexp-named-capture-groups.js: Canonical link: https://commits.webkit.org/234284@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273086 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-18 19:14:34 +00:00
PASS matchResult2a.indices[1] is [0,4]
PASS matchResult2a.indices[2] is [5,7]
PASS matchResult2a.indices[3] is [8,13]
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. Canonical link: https://commits.webkit.org/193122@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-07 23:13:38 +00:00
PASS matchResult2a[1] is matchResult2a.groups.first_name
PASS matchResult2a[2] is matchResult2a.groups.middle_initial
PASS matchResult2a[3] is matchResult2a.groups.last_name
[JSC] Implement RegExp Match Indices proposal https://bugs.webkit.org/show_bug.cgi?id=202475 Reviewed by Yusuke Suzuki. JSTests: Updated tests. * es6/Proxy_internal_get_calls_RegExp.prototype.flags.js: * stress/static-getter-in-names.js: * test262/config.yaml: Source/JavaScriptCore: This implements the latest version of the RegExp match indices proposal (https://github.com/tc39/proposal-regexp-match-indices). It includes a new 'd' flag to RegExp's to trigger the population of the 'indices' property tree in a Matches result from RegExp.exec() and related methods. This change is performance neutral on JetStream2. * 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::fireWatchpointAndMakeAllArrayStructuresSlowPut): (JSC::JSGlobalObject::visitChildren): * runtime/JSGlobalObject.h: (JSC::JSGlobalObject::regExpMatchesArrayWithIndicesStructure const): (JSC::JSGlobalObject::regExpMatchesIndicesArrayStructure const): * runtime/RegExp.cpp: (JSC::RegExpFunctionalTestCollector::outputOneTest): (JSC::regexpToSourceString): * runtime/RegExp.h: * runtime/RegExpMatchesArray.cpp: (JSC::createEmptyRegExpMatchesArray): (JSC::createStructureWithIndicesImpl): (JSC::createIndicesStructureImpl): (JSC::createRegExpMatchesArrayWithIndicesStructure): (JSC::createRegExpMatchesIndicesArrayStructure): (JSC::createRegExpMatchesArrayWithIndicesSlowPutStructure): (JSC::createRegExpMatchesIndicesArraySlowPutStructure): * runtime/RegExpMatchesArray.h: (JSC::createRegExpMatchesArray): * runtime/RegExpPrototype.cpp: (JSC::RegExpPrototype::finishCreation): (JSC::flagsString): (JSC::JSC_DEFINE_HOST_FUNCTION): * yarr/YarrFlags.cpp: (JSC::Yarr::parseFlags): * yarr/YarrFlags.h: * yarr/YarrInterpreter.h: (JSC::Yarr::BytecodePattern::hasIndices const): * yarr/YarrPattern.h: (JSC::Yarr::YarrPattern::hasIndices const): LayoutTests: Updated tests. * js/Object-getOwnPropertyNames-expected.txt: * js/regexp-named-capture-groups-expected.txt: * js/script-tests/Object-getOwnPropertyNames.js: * js/script-tests/regexp-named-capture-groups.js: Canonical link: https://commits.webkit.org/234284@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273086 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-18 19:14:34 +00:00
PASS Object.getOwnPropertyNames(matchResult1).sort() is ["0","1","2","3","groups","index","indices","input","length"]
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. Canonical link: https://commits.webkit.org/193122@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-07 23:13:38 +00:00
PASS matchResult2b[0] is "Sally Brown"
PASS matchResult2b[1] is "Sally"
PASS matchResult2b[2] is undefined.
PASS matchResult2b[3] is "Brown"
[JSC] Implement RegExp Match Indices proposal https://bugs.webkit.org/show_bug.cgi?id=202475 Reviewed by Yusuke Suzuki. JSTests: Updated tests. * es6/Proxy_internal_get_calls_RegExp.prototype.flags.js: * stress/static-getter-in-names.js: * test262/config.yaml: Source/JavaScriptCore: This implements the latest version of the RegExp match indices proposal (https://github.com/tc39/proposal-regexp-match-indices). It includes a new 'd' flag to RegExp's to trigger the population of the 'indices' property tree in a Matches result from RegExp.exec() and related methods. This change is performance neutral on JetStream2. * 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::fireWatchpointAndMakeAllArrayStructuresSlowPut): (JSC::JSGlobalObject::visitChildren): * runtime/JSGlobalObject.h: (JSC::JSGlobalObject::regExpMatchesArrayWithIndicesStructure const): (JSC::JSGlobalObject::regExpMatchesIndicesArrayStructure const): * runtime/RegExp.cpp: (JSC::RegExpFunctionalTestCollector::outputOneTest): (JSC::regexpToSourceString): * runtime/RegExp.h: * runtime/RegExpMatchesArray.cpp: (JSC::createEmptyRegExpMatchesArray): (JSC::createStructureWithIndicesImpl): (JSC::createIndicesStructureImpl): (JSC::createRegExpMatchesArrayWithIndicesStructure): (JSC::createRegExpMatchesIndicesArrayStructure): (JSC::createRegExpMatchesArrayWithIndicesSlowPutStructure): (JSC::createRegExpMatchesIndicesArraySlowPutStructure): * runtime/RegExpMatchesArray.h: (JSC::createRegExpMatchesArray): * runtime/RegExpPrototype.cpp: (JSC::RegExpPrototype::finishCreation): (JSC::flagsString): (JSC::JSC_DEFINE_HOST_FUNCTION): * yarr/YarrFlags.cpp: (JSC::Yarr::parseFlags): * yarr/YarrFlags.h: * yarr/YarrInterpreter.h: (JSC::Yarr::BytecodePattern::hasIndices const): * yarr/YarrPattern.h: (JSC::Yarr::YarrPattern::hasIndices const): LayoutTests: Updated tests. * js/Object-getOwnPropertyNames-expected.txt: * js/regexp-named-capture-groups-expected.txt: * js/script-tests/Object-getOwnPropertyNames.js: * js/script-tests/regexp-named-capture-groups.js: Canonical link: https://commits.webkit.org/234284@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273086 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-18 19:14:34 +00:00
PASS matchResult2b.indices[1] is [0,5]
PASS matchResult2b.indices[2] is undefined.
PASS matchResult2b.indices[3] is [6,11]
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. Canonical link: https://commits.webkit.org/193122@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-07 23:13:38 +00:00
PASS matchResult2b[1] is matchResult2b.groups.first_name
PASS matchResult2b[2] is matchResult2b.groups.middle_initial
PASS matchResult2b[3] is matchResult2b.groups.last_name
[JSC] Implement RegExp Match Indices proposal https://bugs.webkit.org/show_bug.cgi?id=202475 Reviewed by Yusuke Suzuki. JSTests: Updated tests. * es6/Proxy_internal_get_calls_RegExp.prototype.flags.js: * stress/static-getter-in-names.js: * test262/config.yaml: Source/JavaScriptCore: This implements the latest version of the RegExp match indices proposal (https://github.com/tc39/proposal-regexp-match-indices). It includes a new 'd' flag to RegExp's to trigger the population of the 'indices' property tree in a Matches result from RegExp.exec() and related methods. This change is performance neutral on JetStream2. * 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::fireWatchpointAndMakeAllArrayStructuresSlowPut): (JSC::JSGlobalObject::visitChildren): * runtime/JSGlobalObject.h: (JSC::JSGlobalObject::regExpMatchesArrayWithIndicesStructure const): (JSC::JSGlobalObject::regExpMatchesIndicesArrayStructure const): * runtime/RegExp.cpp: (JSC::RegExpFunctionalTestCollector::outputOneTest): (JSC::regexpToSourceString): * runtime/RegExp.h: * runtime/RegExpMatchesArray.cpp: (JSC::createEmptyRegExpMatchesArray): (JSC::createStructureWithIndicesImpl): (JSC::createIndicesStructureImpl): (JSC::createRegExpMatchesArrayWithIndicesStructure): (JSC::createRegExpMatchesIndicesArrayStructure): (JSC::createRegExpMatchesArrayWithIndicesSlowPutStructure): (JSC::createRegExpMatchesIndicesArraySlowPutStructure): * runtime/RegExpMatchesArray.h: (JSC::createRegExpMatchesArray): * runtime/RegExpPrototype.cpp: (JSC::RegExpPrototype::finishCreation): (JSC::flagsString): (JSC::JSC_DEFINE_HOST_FUNCTION): * yarr/YarrFlags.cpp: (JSC::Yarr::parseFlags): * yarr/YarrFlags.h: * yarr/YarrInterpreter.h: (JSC::Yarr::BytecodePattern::hasIndices const): * yarr/YarrPattern.h: (JSC::Yarr::YarrPattern::hasIndices const): LayoutTests: Updated tests. * js/Object-getOwnPropertyNames-expected.txt: * js/regexp-named-capture-groups-expected.txt: * js/script-tests/Object-getOwnPropertyNames.js: * js/script-tests/regexp-named-capture-groups.js: Canonical link: https://commits.webkit.org/234284@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273086 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-18 19:14:34 +00:00
PASS Object.getOwnPropertyNames(matchResult1).sort() is ["0","1","2","3","groups","index","indices","input","length"]
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. Canonical link: https://commits.webkit.org/193122@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-07 23:13:38 +00:00
PASS re3.toString() is "\/^(?<part1>.*):(?<part2>.*):\\k<part2>:\\k<part1>$\/"
PASS re3.test("a:b:b:a") is true
PASS re3.test("a:a:a:a") is true
PASS re3.test("a:b:c:a") is false
PASS first is "1"
PASS second is "2"
PASS result4 is "14.02.2010"
PASS "third edition".match(/(?<auf\u200clage>\w+) edition/).groups.auf\u200clage is "third"
PASS "fourth edition".match(/(?<auf\u200dlage>\w+) edition/).groups.auf\u200dlage is "fourth"
PASS "10/20/1930".replace(/(?<month>\d{2})\/(?<day>\d{2})\/(?<year>\d{4})/, "$<day>-$<month>-$<year>") is "20-10-1930"
PASS "10/20/1930".replace(/(?<month>\d{2})\/(?<day>\d{2})\/(?<year>\d{4})/, "$2-$<month>-$<year>") is "20-10-1930"
PASS "10/20/1930".replace(/(?<month>\d{2})\/(?<day>\d{2})\/(?<year>\d{4})/, "$<day>-$1-$<year>") is "20-10-1930"
PASS "10/20/1930".replace(/(?<month>\d{2})\/(?<day>\d{2})\/(?<year>\d{4})/, "$<day>-$<month>-$3") is "20-10-1930"
PASS "Replace just THIS in this string".replace(/THIS/, "$<THAT>") is "Replace just $<THAT> in this string"
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. Canonical link: https://commits.webkit.org/193122@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-07 23:13:38 +00:00
PASS "Give me a \'k\'!".match(/Give me a \'\k\'/)[0] is "Give me a \'k\'"
PASS "Give me \'k2\'!".match(/Give me \'\k2\'/)[0] is "Give me \'k2\'"
PASS "Give me a \'kat\'!".match(/Give me a \'\kat\'/)[0] is "Give me a \'kat\'"
PASS "Give me a \'k\'!".match(/Give me a \'\k\'/u)[0] threw exception SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern.
PASS "Give me \'k2\'!".match(/Give me \'\k2\'/u)[0] threw exception SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern.
PASS "Give me a \'kat\'!".match(/Give me a \'\kat\'/u)[0] threw exception SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern.
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. Canonical link: https://commits.webkit.org/193122@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-07 23:13:38 +00:00
PASS "10/20/1930".replace(/(?<month>\d{2})\/(?<day>\d{2})\/(?<year>\d{4})/, "$<day>-$<mouth>-$<year>") is "20--1930"
PASS "10/20/1930".replace(/(?<month>\d{2})\/(?<day>\d{2})\/(?<year>\d{4})/, "$<day>-$<month>-$<year") is "20-10-$<year"
PASS let r = new RegExp("/(?<groupName1>abc)|(?<groupName1>def)/") threw exception SyntaxError: Invalid regular expression: duplicate group specifier name.
PASS let r = new RegExp("/(?< groupName1>abc)/") threw exception SyntaxError: Invalid regular expression: invalid group specifier name.
PASS let r = new RegExp("/(?<g=oupName1>abc)/") threw exception SyntaxError: Invalid regular expression: invalid group specifier name.
PASS let r = new RegExp("/(?<𐆐groupName1>abc)/u") threw exception SyntaxError: Invalid regular expression: invalid group specifier name.
PASS let r = new RegExp("/(?<g𐆛oupName1>abc)/u") threw exception SyntaxError: Invalid regular expression: invalid group specifier name.
PASS let r = new RegExp("/(?<groupName1>abc)/u") threw exception SyntaxError: Invalid regular expression: invalid group specifier name.
PASS let r = new RegExp("/(?<groupName1>abc)/u") threw exception SyntaxError: Invalid regular expression: invalid group specifier name.
Add support in named capture group identifiers for direct surrogate pairs https://bugs.webkit.org/show_bug.cgi?id=178174 Reviewed by Darin Adler and Michael Saboff. JSTests: * test262/expectations.yaml: Mark 2 test cases as passing. Source/JavaScriptCore: This change: a) Adds support for unescaped astral symbols in RegExp identifier names [1], aligning JSC with V8. b) Rewords InvalidUnicodeEscape error code to be used for \uXXXX escapes in Unicode patterns and named groups/references instead of InvalidIdentityEscape, matching error messages in V8 and SpiderMonkey. c) Adds hasError() checks after tryConsumeGroupName() so errors generated in tryConsumeIdentifierCharacter() would not get overriden. d) Removes code duplication by using tryConsumeUnicodeEscape() for parsing \u in parseEscape(); cleans up parsing \u{} escapes a bit, preferring ASSERTs over hasError() checks. [1]: https://tc39.es/ecma262/#prod-RegExpIdentifierName * yarr/YarrErrorCode.cpp: (JSC::Yarr::errorMessage): (JSC::Yarr::errorToThrow): * yarr/YarrErrorCode.h: * yarr/YarrParser.h: (JSC::Yarr::Parser::parseEscape): (JSC::Yarr::Parser::parseParenthesesBegin): (JSC::Yarr::Parser::tryConsumeUnicodeEscape): (JSC::Yarr::Parser::tryConsumeIdentifierCharacter): LayoutTests: Adjusted tests for error messages changes and added coverage for messages of syntax errors due to invalid \u escapes inside named groups/references. * js/regexp-named-capture-groups-expected.txt: * js/regexp-unicode-expected.txt: * js/regress-158080-expected.txt: * js/script-tests/regexp-named-capture-groups.js: * js/script-tests/regexp-unicode.js: Canonical link: https://commits.webkit.org/222707@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@259262 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-03-31 01:27:10 +00:00
PASS /(?<\u>.)/u threw exception SyntaxError: Invalid regular expression: invalid Unicode \u escape.
PASS /\k<\uzzz>/u threw exception SyntaxError: Invalid regular expression: invalid Unicode \u escape.
PASS /(?<\u{>.)/u threw exception SyntaxError: Invalid regular expression: invalid Unicode code point \u{} escape.
PASS /\k<\u{0>/u threw exception SyntaxError: Invalid regular expression: invalid Unicode code point \u{} escape.
Test262 failure with Named Capture Groups - using a reference before the group is defined https://bugs.webkit.org/show_bug.cgi?id=189407 Reviewed by Alex Christensen. JSTests: Re-enabled previously failing test. * test262.yaml: * test262/expectations.yaml: Source/JavaScriptCore: Added code to save the named forward references we see during parsing and validating that they are all present when parsing the RegExp is complete. If there are unnamed references, we reparse with some variation of behavior. Just like for numeric references, the behavior is different depending on whether or not the unicode (u flag) is present. For non-unicode patterns, we treat the \k<...> as a literal pattern. For a unicode pattern we throw an exception. Did some refactoring, renaming YarrPattern::reset() and YarrPatternConstructor::reset() resetForReparsing() as that is the only use for those methods. Also changed all the delegate methods that take a String to take a const String& to eliminate copy churn. * yarr/YarrParser.h: (JSC::Yarr::Parser::CharacterClassParserDelegate::atomNamedBackReference): (JSC::Yarr::Parser::CharacterClassParserDelegate::isValidNamedForwardReference): (JSC::Yarr::Parser::CharacterClassParserDelegate::atomNamedForwardReference): (JSC::Yarr::Parser::parseEscape): * yarr/YarrPattern.cpp: (JSC::Yarr::YarrPatternConstructor::resetForReparsing): (JSC::Yarr::YarrPatternConstructor::saveUnmatchedNamedForwardReferences): (JSC::Yarr::YarrPatternConstructor::atomNamedBackReference): (JSC::Yarr::YarrPatternConstructor::isValidNamedForwardReference): (JSC::Yarr::YarrPatternConstructor::atomNamedForwardReference): (JSC::Yarr::YarrPattern::compile): (JSC::Yarr::YarrPatternConstructor::reset): Deleted. * yarr/YarrPattern.h: (JSC::Yarr::YarrPattern::resetForReparsing): (JSC::Yarr::YarrPattern::containsIllegalNamedForwardReferences): (JSC::Yarr::YarrPattern::reset): Deleted. * yarr/YarrSyntaxChecker.cpp: (JSC::Yarr::SyntaxChecker::atomNamedBackReference): (JSC::Yarr::SyntaxChecker::isValidNamedForwardReference): (JSC::Yarr::SyntaxChecker::atomNamedForwardReference): Source/WebCore: Created new delegate stubs for RegExp parsing. These are not needed for the URL filtering use cases. Also changed all the delegate methods that take a String to take const String& to eliminate copy churn. Updated TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp. * contentextensions/URLFilterParser.cpp: (WebCore::ContentExtensions::PatternParser::atomNamedBackReference): (WebCore::ContentExtensions::PatternParser::isValidNamedForwardReference): (WebCore::ContentExtensions::PatternParser::atomNamedForwardReference): (WebCore::ContentExtensions::URLFilterParser::statusString): * contentextensions/URLFilterParser.h: Tools: Updated test. * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp: (TestWebKitAPI::TEST_F): LayoutTests: Updated tests. * js/regexp-named-capture-groups-expected.txt: * js/script-tests/regexp-named-capture-groups.js: Canonical link: https://commits.webkit.org/204468@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235882 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-09-11 04:53:56 +00:00
PASS "XzzXzz".match(/\k<z>X(?<z>z*)X\k<z>/) is ["XzzXzz", "zz"]
PASS "XzzXzz".match(/\k<z>X(?<z>z*)X\k<z>/u) is ["XzzXzz", "zz"]
PASS "1122332211".match(/\k<ones>\k<twos>\k<threes>(?<ones>1*)(?<twos>2*)(?<threes>3*)\k<threes>\k<twos>\k<ones>/) is ["1122332211", "11", "22", "3"]
PASS "1122332211".match(/\k<ones>\k<twos>\k<threes>(?<ones>1*)(?<twos>2*)(?<threes>3*)\k<threes>\k<twos>\k<ones>/u) is ["1122332211", "11", "22", "3"]
PASS "\k<z>XzzX".match(/\k<z>X(z*)X/) is ["k<z>XzzX", "zz"]
Invalid numeric and named references should be early syntax errors https://bugs.webkit.org/show_bug.cgi?id=178175 Reviewed by Ross Kirsling. JSTests: * test262/expectations.yaml: Mark 44 test cases as passing. Source/JavaScriptCore: This patch: 1. Fixes named reference parsing in parseEscape(), making /\k/u throw SyntaxError per spec [1]. 2. Reworks containsIllegalNamedForwardReferences(), making dangling (e.g. /\k<a>(?<b>.)/) and incomplete (e.g. /\k<(?<a>.)/) named references throw SyntaxError if the non-Unicode pattern contains a named group [2]. 3. Moves reparsing logic from YarrPattern to YarrParser, ensuring syntax errors due to illegal references (named & numeric) are thrown at parse time; drops isValidNamedForwardReference() from Delegate, refactors saveUnmatchedNamedForwardReferences(), and overall improves cohesion of illegal references logic. [1]: https://tc39.es/ecma262/#prod-IdentityEscape [2]: https://tc39.es/ecma262/#sec-regexpinitialize (step 7.b) * yarr/YarrErrorCode.cpp: (JSC::Yarr::errorMessage): (JSC::Yarr::errorToThrow): * yarr/YarrErrorCode.h: * yarr/YarrParser.h: (JSC::Yarr::Parser::CharacterClassParserDelegate::atomNamedBackReference): (JSC::Yarr::Parser::Parser): (JSC::Yarr::Parser::parseEscape): (JSC::Yarr::Parser::parseParenthesesBegin): (JSC::Yarr::Parser::parse): (JSC::Yarr::Parser::handleIllegalReferences): (JSC::Yarr::Parser::containsIllegalNamedForwardReference): (JSC::Yarr::Parser::resetForReparsing): (JSC::Yarr::parse): (JSC::Yarr::Parser::CharacterClassParserDelegate::isValidNamedForwardReference): Deleted. * yarr/YarrPattern.cpp: (JSC::Yarr::YarrPatternConstructor::atomBackReference): (JSC::Yarr::YarrPatternConstructor::atomNamedForwardReference): (JSC::Yarr::YarrPattern::compile): (JSC::Yarr::YarrPatternConstructor::saveUnmatchedNamedForwardReferences): Deleted. (JSC::Yarr::YarrPatternConstructor::isValidNamedForwardReference): Deleted. * yarr/YarrPattern.h: (JSC::Yarr::YarrPattern::resetForReparsing): (JSC::Yarr::YarrPattern::containsIllegalBackReference): Deleted. (JSC::Yarr::YarrPattern::containsIllegalNamedForwardReferences): Deleted. * yarr/YarrSyntaxChecker.cpp: (JSC::Yarr::SyntaxChecker::atomNamedBackReference): (JSC::Yarr::SyntaxChecker::resetForReparsing): (JSC::Yarr::SyntaxChecker::isValidNamedForwardReference): Deleted. Source/WebCore: Accounts for changes of YarrParser's Delegate interface, no behavioral changes. resetForReparsing() is never called because we disable numeric backrefences and named forward references (see arguments of Yarr::parse() call). Test: TestWebKitAPI.ContentExtensionTest.ParsingFailures * contentextensions/URLFilterParser.cpp: (WebCore::ContentExtensions::PatternParser::resetForReparsing): (WebCore::ContentExtensions::URLFilterParser::addPattern): (WebCore::ContentExtensions::PatternParser::isValidNamedForwardReference): Deleted. Tools: Removes FIXME as YarrParser is correct not to throw errors as it is parsing in non-Unicode mode. Also adds a few named groups tests. * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp: LayoutTests: * js/regexp-named-capture-groups-expected.txt: * js/script-tests/regexp-named-capture-groups.js: Canonical link: https://commits.webkit.org/222504@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@259026 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-03-26 01:24:05 +00:00
PASS "\k<z>XzzX".match(/\k<z>X(z*)X/u) threw exception SyntaxError: Invalid regular expression: invalid \k<> named backreference.
PASS /\k<xxx(?<a>y)(/ threw exception SyntaxError: Invalid regular expression: invalid \k<> named backreference.
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. Canonical link: https://commits.webkit.org/193122@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-07 23:13:38 +00:00
PASS successfullyParsed is true
TEST COMPLETE