Invalid flags in a RegExp literal should be an early SyntaxError
https://bugs.webkit.org/show_bug.cgi?id=195514
Reviewed by Darin Adler.
JSTests:
- test262/expectations.yaml:
Mark 4 test cases as passing.
- stress/regexp-syntax-error-invalid-flags.js:
- stress/regress-161995.js: Removed.
Update existing test, merging in an older test for the same behavior.
Source/JavaScriptCore:
Currently we're throwing a *runtime* SyntaxError; this should occur at parse time.
12.2.8.1 Static Semantics: Early Errors
PrimaryExpression : RegularExpressionLiteral
- It is a Syntax Error if BodyText of RegularExpressionLiteral cannot be recognized
using the goal symbol Pattern of the ECMAScript RegExp grammar specified in 21.2.1.
- It is a Syntax Error if FlagText of RegularExpressionLiteral contains any code points
other than "g", "i", "m", "s", "u", or "y", or if it contains the same code point more than once.
In fixing this, let's also move flag handling from runtime/ to yarr/.
- yarr/YarrSyntaxChecker.cpp:
(JSC::Yarr::checkSyntax):
Check flags before checking pattern.
- CMakeLists.txt:
- JavaScriptCore.xcodeproj/project.pbxproj:
- Sources.txt:
- bytecompiler/NodesCodegen.cpp:
(JSC::RegExpNode::emitBytecode):
- inspector/ContentSearchUtilities.cpp:
(Inspector::ContentSearchUtilities::findMagicComment):
- runtime/CachedTypes.cpp:
- runtime/RegExp.cpp:
(JSC::RegExp::RegExp):
(JSC::RegExp::createWithoutCaching):
(JSC::RegExp::create):
(JSC::regExpFlags): Deleted.
- runtime/RegExp.h:
- runtime/RegExpCache.cpp:
(JSC::RegExpCache::lookupOrCreate):
(JSC::RegExpCache::ensureEmptyRegExpSlow):
- runtime/RegExpCache.h:
- runtime/RegExpConstructor.cpp:
(JSC::toFlags):
(JSC::regExpCreate):
(JSC::constructRegExp):
(JSC::RegExpKey::RegExpKey):
(WTF::HashTraits<JSC::RegExpKey>::constructDeletedValue):
(WTF::HashTraits<JSC::RegExpKey>::isDeletedValue):
(): Deleted.
- runtime/RegExpPrototype.cpp:
(JSC::regExpProtoFuncCompile):
(parseRegExpLine):
- yarr/RegularExpression.cpp:
(JSC::Yarr::RegularExpression::Private::compile):
- yarr/YarrFlags.cpp: Added.
(JSC::Yarr::parseFlags):
- yarr/YarrFlags.h: Added.
- yarr/YarrInterpreter.h:
(JSC::Yarr::BytecodePattern::ignoreCase const):
(JSC::Yarr::BytecodePattern::multiline const):
(JSC::Yarr::BytecodePattern::sticky const):
(JSC::Yarr::BytecodePattern::unicode const):
(JSC::Yarr::BytecodePattern::dotAll const):
(JSC::Yarr::YarrPattern::compile):
(JSC::Yarr::YarrPattern::YarrPattern):
(JSC::Yarr::YarrPattern::dumpPattern):
(JSC::Yarr::YarrPattern::global const):
(JSC::Yarr::YarrPattern::ignoreCase const):
(JSC::Yarr::YarrPattern::multiline const):
(JSC::Yarr::YarrPattern::sticky const):
(JSC::Yarr::YarrPattern::unicode const):
(JSC::Yarr::YarrPattern::dotAll const):
Move flag handling to Yarr and modernize API.
Source/WebCore:
- bindings/js/SerializedScriptValue.cpp:
(WebCore::CloneDeserializer::readTerminal):
Consume YarrFlags.