[YARR] Yarr should return ErrorCode instead of error messages (const char*)
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Dec 2017 19:16:21 +0000 (19:16 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Dec 2017 19:16:21 +0000 (19:16 +0000)
commitda33ed22197075e1aa7890078bf319dfabe25eea
treeabd827414378cb808fca95abe62fc57a1b11fe85
parent756ed000c5341c7743ec3fa948443d8885596453
[YARR] Yarr should return ErrorCode instead of error messages (const char*)
https://bugs.webkit.org/show_bug.cgi?id=180966

Reviewed by Mark Lam.

Source/JavaScriptCore:

Currently, Yarr returns const char*` for an error message when needed.
But it is easier to handle error status if Yarr returns an error code
instead of `const char*`.

In this patch, we introduce Yarr::ErrorCode. Yarr returns it instead of
`const char*`. `std::expected<void, Yarr::ErrorCode>` would be appropriate
for the Yarr API interface. But it requires substantial changes removing
ErrorCode::NoError, so this patch just uses the current Yarr::ErrorCode as
a first step.

* JavaScriptCore.xcodeproj/project.pbxproj:
* Sources.txt:
* inspector/ContentSearchUtilities.cpp:
(Inspector::ContentSearchUtilities::findMagicComment):
* parser/ASTBuilder.h:
(JSC::ASTBuilder::createRegExp):
* parser/Parser.cpp:
(JSC::Parser<LexerType>::parsePrimaryExpression):
* parser/SyntaxChecker.h:
(JSC::SyntaxChecker::createRegExp):
* runtime/RegExp.cpp:
(JSC::RegExp::RegExp):
(JSC::RegExp::byteCodeCompileIfNecessary):
(JSC::RegExp::compile):
(JSC::RegExp::compileMatchOnly):
* runtime/RegExp.h:
* yarr/RegularExpression.cpp:
(JSC::Yarr::RegularExpression::Private::Private):
(JSC::Yarr::RegularExpression::Private::compile):
* yarr/YarrErrorCode.cpp: Added.
(JSC::Yarr::errorMessage):
* yarr/YarrErrorCode.h: Copied from Source/JavaScriptCore/yarr/YarrSyntaxChecker.h.
(JSC::Yarr::hasError):
* yarr/YarrParser.h:
(JSC::Yarr::Parser::CharacterClassParserDelegate::CharacterClassParserDelegate):
(JSC::Yarr::Parser::CharacterClassParserDelegate::atomPatternCharacter):
(JSC::Yarr::Parser::Parser):
(JSC::Yarr::Parser::isIdentityEscapeAnError):
(JSC::Yarr::Parser::parseEscape):
(JSC::Yarr::Parser::parseCharacterClass):
(JSC::Yarr::Parser::parseParenthesesBegin):
(JSC::Yarr::Parser::parseParenthesesEnd):
(JSC::Yarr::Parser::parseQuantifier):
(JSC::Yarr::Parser::parseTokens):
(JSC::Yarr::Parser::parse):
(JSC::Yarr::Parser::tryConsumeUnicodeEscape):
(JSC::Yarr::Parser::tryConsumeUnicodePropertyExpression):
(JSC::Yarr::parse):
* yarr/YarrPattern.cpp:
(JSC::Yarr::YarrPatternConstructor::YarrPatternConstructor):
(JSC::Yarr::YarrPatternConstructor::setupDisjunctionOffsets):
(JSC::Yarr::YarrPatternConstructor::setupOffsets):
(JSC::Yarr::YarrPattern::compile):
(JSC::Yarr::YarrPattern::YarrPattern):
(JSC::Yarr::YarrPattern::errorMessage): Deleted.
* yarr/YarrPattern.h:
(JSC::Yarr::YarrPattern::reset):
* yarr/YarrSyntaxChecker.cpp:
(JSC::Yarr::checkSyntax):
* yarr/YarrSyntaxChecker.h:

Source/WebCore:

Remove unnecessary String creation.

No behavior change.

* contentextensions/URLFilterParser.cpp:
(WebCore::ContentExtensions::URLFilterParser::addPattern):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226128 268f45cc-cd09-0410-ab3c-d52691b4dbfc
19 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/Sources.txt
Source/JavaScriptCore/inspector/ContentSearchUtilities.cpp
Source/JavaScriptCore/parser/ASTBuilder.h
Source/JavaScriptCore/parser/Parser.cpp
Source/JavaScriptCore/parser/SyntaxChecker.h
Source/JavaScriptCore/runtime/RegExp.cpp
Source/JavaScriptCore/runtime/RegExp.h
Source/JavaScriptCore/yarr/RegularExpression.cpp
Source/JavaScriptCore/yarr/YarrErrorCode.cpp [new file with mode: 0644]
Source/JavaScriptCore/yarr/YarrErrorCode.h [new file with mode: 0644]
Source/JavaScriptCore/yarr/YarrParser.h
Source/JavaScriptCore/yarr/YarrPattern.cpp
Source/JavaScriptCore/yarr/YarrPattern.h
Source/JavaScriptCore/yarr/YarrSyntaxChecker.cpp
Source/JavaScriptCore/yarr/YarrSyntaxChecker.h
Source/WebCore/ChangeLog
Source/WebCore/contentextensions/URLFilterParser.cpp